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,
"profiles": {
"mcopy": {

2
app/package-lock.json generated
View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -42,6 +42,8 @@
#define FEED_EMITTER 18
#define FEED_RECEIVER A9
#define SERVO_PIN 14
AccelStepper takeup(AccelStepper::DRIVER, TAKEUP_STEP_PIN, TAKEUP_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,
FEED_SETTINGS_A, FEED_SETTINGS_B,
TAKEUP_EMITTER, TAKEUP_RECEIVER,
FEED_EMITTER, FEED_RECEIVER);
FEED_EMITTER, FEED_RECEIVER,
SERVO_PIN);
void setup () {
pins();
@ -75,6 +78,7 @@ void setup () {
delay(42);
digitalWrite(LED_FWD, LOW);
digitalWrite(LED_BWD, LOW);
//projector.home();
}
@ -83,9 +87,9 @@ void loop () {
cmdChar = mcopy.loop();
cmd(cmdChar);
if (digitalRead(BUTTON) == LOW) {
projector_frame();
//projector_frame();
}
projector.loop();
//projector.loop();
}
void pins () {

4
package-lock.json generated
View File

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

View File

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

View File

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