Add servo functionality for rack and pinion motion. Need to fix home feature.

This commit is contained in:
Matt McWilliams 2023-10-09 09:59:19 -04:00
parent 91ce2dd450
commit af3843a8ef
10 changed files with 37 additions and 13 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.48", "version": "1.8.49",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.8.48", "version": "1.8.49",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.8.48", "version": "1.8.49",
"description": "GUI for the mcopy small gauge film optical printer platform", "description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.48", "version": "1.8.49",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -6,7 +6,8 @@ McopyProjector::McopyProjector (AccelStepper takeup, AccelStepper feed,
uint8_t takeupSettingA, uint8_t takeupSettingB, uint8_t takeupSettingA, uint8_t takeupSettingB,
uint8_t feedSettingA, uint8_t feedSettingB, uint8_t feedSettingA, uint8_t feedSettingB,
uint8_t takeupEmitter, uint8_t takeupReceiver, uint8_t takeupEmitter, uint8_t takeupReceiver,
uint8_t feedEmitter, uint8_t feedReceiver) { uint8_t feedEmitter, uint8_t feedReceiver,
uint8_t servoPin) {
_takeup = takeup; _takeup = takeup;
_feed = feed; _feed = feed;
@ -18,6 +19,7 @@ McopyProjector::McopyProjector (AccelStepper takeup, AccelStepper feed,
_takeupReceiver = takeupReceiver; _takeupReceiver = takeupReceiver;
_feedEmitter = feedEmitter; _feedEmitter = feedEmitter;
_feedReceiver = feedReceiver; _feedReceiver = feedReceiver;
_servoPin = servoPin;
} }
void McopyProjector::begin () { void McopyProjector::begin () {
@ -40,6 +42,9 @@ void McopyProjector::begin () {
//keep at 1 for now //keep at 1 for now
setStepperMode(1); setStepperMode(1);
_servo.attach(_servoPin);
_servo.write(_servoHome);
} }
void McopyProjector::setDirection (bool dir) { void McopyProjector::setDirection (bool dir) {
@ -64,6 +69,9 @@ void McopyProjector::frame (bool dir) {
_running = true; _running = true;
_servo.write(_servoAway);
delay(20);
while (running) { while (running) {
if (_takeup.distanceToGo() == 0 && _feed.distanceToGo() == 0) { if (_takeup.distanceToGo() == 0 && _feed.distanceToGo() == 0) {
running = false; running = false;
@ -75,6 +83,9 @@ void McopyProjector::frame (bool dir) {
} }
} }
delay(20);
_servo.write(_servoHome);
_running = false; _running = false;
} }

View File

@ -3,6 +3,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <AccelStepper.h> #include <AccelStepper.h>
#include <Servo.h>
/** /**
* D2 X Step * D2 X Step
@ -28,11 +29,16 @@ class McopyProjector {
AccelStepper _takeup; AccelStepper _takeup;
AccelStepper _feed; AccelStepper _feed;
Servo _servo;
const uint16_t _motorSteps = 200; //full steps const uint16_t _motorSteps = 200; //full steps
const uint8_t _frames = 8; const uint8_t _frames = 8;
const uint16_t _stepsPerFrame = 25; //round(_motorSteps / _frames); const uint16_t _stepsPerFrame = 25; //round(_motorSteps / _frames);
const float _speed = 2000.0; const float _speed = 2000.0;
const uint8_t _servoHome = 90;
const uint8_t _servoAway = 60;
volatile uint8_t _mode = 1; volatile uint8_t _mode = 1;
int64_t _posTakeup = 0; int64_t _posTakeup = 0;
@ -50,6 +56,8 @@ class McopyProjector {
uint8_t _feedEmitter; uint8_t _feedEmitter;
uint8_t _feedReceiver; uint8_t _feedReceiver;
uint8_t _servoPin;
long _feedSamples[200]; long _feedSamples[200];
long _takeupSamples[200]; long _takeupSamples[200];
@ -70,7 +78,8 @@ class McopyProjector {
uint8_t takeupSettingA, uint8_t takeupSettingB, uint8_t takeupSettingA, uint8_t takeupSettingB,
uint8_t feedSettingA, uint8_t feedSettingB, uint8_t feedSettingA, uint8_t feedSettingB,
uint8_t takeupEmitter, uint8_t takeupReceiver, uint8_t takeupEmitter, uint8_t takeupReceiver,
uint8_t feedEmitter, uint8_t feedReceiver); uint8_t feedEmitter, uint8_t feedReceiver,
uint8_t servoPin);
void begin(); void begin();
//0 = takeup, 1 = feed //0 = takeup, 1 = feed
void adjust(uint8_t motor, int64_t steps); void adjust(uint8_t motor, int64_t steps);

View File

@ -42,6 +42,8 @@
#define FEED_EMITTER 18 #define FEED_EMITTER 18
#define FEED_RECEIVER A9 #define FEED_RECEIVER A9
#define SERVO_PIN 14
AccelStepper takeup(AccelStepper::DRIVER, TAKEUP_STEP_PIN, TAKEUP_DIR_PIN); AccelStepper takeup(AccelStepper::DRIVER, TAKEUP_STEP_PIN, TAKEUP_DIR_PIN);
AccelStepper feed(AccelStepper::DRIVER, FEED_STEP_PIN, FEED_DIR_PIN); AccelStepper feed(AccelStepper::DRIVER, FEED_STEP_PIN, FEED_DIR_PIN);
@ -64,7 +66,8 @@ McopyProjector projector(takeup, feed,
TAKEUP_SETTINGS_A, TAKEUP_SETTINGS_B, TAKEUP_SETTINGS_A, TAKEUP_SETTINGS_B,
FEED_SETTINGS_A, FEED_SETTINGS_B, FEED_SETTINGS_A, FEED_SETTINGS_B,
TAKEUP_EMITTER, TAKEUP_RECEIVER, TAKEUP_EMITTER, TAKEUP_RECEIVER,
FEED_EMITTER, FEED_RECEIVER); FEED_EMITTER, FEED_RECEIVER,
SERVO_PIN);
void setup () { void setup () {
pins(); pins();
@ -75,6 +78,7 @@ void setup () {
delay(42); delay(42);
digitalWrite(LED_FWD, LOW); digitalWrite(LED_FWD, LOW);
digitalWrite(LED_BWD, LOW); digitalWrite(LED_BWD, LOW);
//projector.home(); //projector.home();
} }
@ -83,9 +87,9 @@ void loop () {
cmdChar = mcopy.loop(); cmdChar = mcopy.loop();
cmd(cmdChar); cmd(cmdChar);
if (digitalRead(BUTTON) == LOW) { if (digitalRead(BUTTON) == LOW) {
projector_frame(); //projector_frame();
} }
projector.loop(); //projector.loop();
} }
void pins () { void pins () {

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.8.48", "version": "1.8.49",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mcopy", "name": "mcopy",
"version": "1.8.48", "version": "1.8.49",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"arduino": "file:app/lib/arduino", "arduino": "file:app/lib/arduino",

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.8.48", "version": "1.8.49",
"description": "Small gauge film optical printer platform", "description": "Small gauge film optical printer platform",
"main": "build.js", "main": "build.js",
"directories": { "directories": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.48", "version": "1.8.49",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {