Stepper firmware is working. Needed extra tape around coupling connector to add friction to connection and now it keeps.
This commit is contained in:
parent
fcb77232ec
commit
ee1e9c9feb
|
@ -1,75 +1,115 @@
|
||||||
|
|
||||||
#include <AccelStepper.h>
|
|
||||||
#include <Adafruit_MotorShield.h>
|
#include <Adafruit_MotorShield.h>
|
||||||
|
|
||||||
volatile boolean DEBUG = true;
|
volatile boolean debug_state = true;
|
||||||
|
volatile boolean cam_dir = true;
|
||||||
|
|
||||||
|
const int fullRotation = 600;
|
||||||
|
const int openRotationForward = 300;
|
||||||
|
const int openRotationBackward = 300;
|
||||||
|
|
||||||
|
//CAMERA COMMANDS
|
||||||
|
const char cmd_camera = 'c';
|
||||||
|
const char cmd_cam_forward = 'e';
|
||||||
|
const char cmd_cam_backward = 'f';
|
||||||
|
|
||||||
|
const char cmd_debug = 'd';
|
||||||
|
const char cmd_connect = 'i';
|
||||||
|
volatile char cmd_char = 'z';
|
||||||
|
const char cmd_mcopy_identifier = 'm';
|
||||||
|
const char cmd_cam_identifier = 'k';
|
||||||
|
|
||||||
|
const int serialDelay = 5;
|
||||||
|
|
||||||
Adafruit_MotorShield AFMStop(0x60);
|
|
||||||
// Create the motor shield object with the default I2C address
|
|
||||||
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
||||||
//Set up for a 200step motor (NEMA 17)
|
//Set up for a 200step motor (NEMA 17)
|
||||||
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
|
Adafruit_StepperMotor *stepper = AFMS.getStepper(200, 1);
|
||||||
|
|
||||||
void forwardstep() {
|
|
||||||
myMotor->onestep(FORWARD, DOUBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void backwardstep() {
|
|
||||||
myMotor->onestep(BACKWARD, DOUBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set up AccelStepper
|
|
||||||
AccelStepper stepper(forwardstep, backwardstep);
|
|
||||||
|
|
||||||
void setupMotor () {
|
void setupMotor () {
|
||||||
TWBR = ((F_CPU /400000l) - 16) / 2; // Change the i2c clock to 400KHz
|
//TWBR = ((F_CPU /400000l) - 16) / 2; // Change the i2c clock to 400KHz
|
||||||
|
|
||||||
if (!AFMS.begin()) { // default frequency 1.6KHz
|
if (!AFMS.begin()) { // default frequency 1.6KHz
|
||||||
Serial.println("Could not find Motor Shield. Check wiring.");
|
log("Could not find Motor Shield. Check wiring.");
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
Serial.println("Motor Shield found.");
|
|
||||||
//myMotor->setSpeed(600);
|
log("Motor Shield found.");
|
||||||
//stepper.setMaxSpeed(600.0);
|
stepper->setSpeed(600);
|
||||||
//stepper.setSpeed(600.0);
|
|
||||||
//stepper.setAcceleration(500.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(57600);
|
Serial.begin(57600);
|
||||||
setupMotor();
|
setupMotor();
|
||||||
|
|
||||||
//stepper.setMaxSpeed(600.0);
|
|
||||||
//stepper.move(600);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
if (Serial.available()) {
|
||||||
//Serial.println("Microstep steps");
|
// read the most recent byte
|
||||||
//myMotor->step(200, FORWARD, MICROSTEP);
|
cmd_char = (char)Serial.read();
|
||||||
|
}
|
||||||
//myMotor->step(round(200 / 8), FORWARD, SINGLE); //109ms @ speed 600
|
if (cmd_char != 'z') {
|
||||||
//myMotor->step(round(200 / 8), FORWARD, SINGLE); //172ms @ speed 100
|
cmd(cmd_char);
|
||||||
|
cmd_char = 'z';
|
||||||
//myMotor->step(round(200 / 8), FORWARD, MICROSTEP); //1557ms @ speed 600
|
}
|
||||||
//myMotor->step(round(200 / 8), FORWARD, MICROSTEP); //1621ms @ speed 100
|
}
|
||||||
|
|
||||||
//myMotor->step(200, FORWARD, SINGLE); //873ms @ speed 600
|
void cmd (char val) {
|
||||||
//myMotor->step(200, FORWARD, SINGLE); //1377ms @ speed 100
|
if (val == cmd_debug) {
|
||||||
|
debug();
|
||||||
//myMotor->step(200, FORWARD, MICROSTEP); //12466ms @ speed 600
|
} else if (val == cmd_connect) {
|
||||||
//myMotor->step(200, FORWARD, MICROSTEP); //12967ms @ speed 100
|
connect();
|
||||||
|
} else if (val == cmd_mcopy_identifier) {
|
||||||
//if (stepper.distanceToGo() != 0) {
|
identify();
|
||||||
long startTime = millis();
|
} else if (val == cmd_cam_forward) {
|
||||||
//stepper.runToNewPosition(0);
|
setDir(true); //explicit
|
||||||
//stepper.runToNewPosition(600);
|
} else if (val == cmd_cam_backward) {
|
||||||
myMotor->step(600, FORWARD, DOUBLE);
|
setDir(false);
|
||||||
//myMotor->step(600, FORWARD, SINGLE);
|
} else if (val == cmd_camera) {
|
||||||
stepper.run();
|
cam();
|
||||||
long stopTime = millis();
|
}
|
||||||
Serial.print(stopTime - startTime);
|
}
|
||||||
Serial.println("ms");
|
|
||||||
delay(1000);
|
void debug () {
|
||||||
//}
|
debug_state = true;
|
||||||
|
Serial.println(cmd_debug);
|
||||||
|
log("debugging enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
void connect () {
|
||||||
|
Serial.println(cmd_connect);
|
||||||
|
log("connect()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void identify () {
|
||||||
|
Serial.println(cmd_cam_identifier);
|
||||||
|
log("identify()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDir (boolean dir) {
|
||||||
|
cam_dir = dir;
|
||||||
|
if (cam_dir) {
|
||||||
|
Serial.println(cmd_cam_forward);
|
||||||
|
log("setDir = true");
|
||||||
|
} else {
|
||||||
|
Serial.println(cmd_cam_backward);
|
||||||
|
log("setDir -> false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cam () {
|
||||||
|
long startTime = millis();
|
||||||
|
if (cam_dir) {
|
||||||
|
stepper->step(fullRotation, FORWARD, DOUBLE);
|
||||||
|
Serial.println(cmd_cam_forward);
|
||||||
|
log("cam -> forward");
|
||||||
|
} else {
|
||||||
|
stepper->step(fullRotation, BACKWARD, DOUBLE);
|
||||||
|
Serial.println(cmd_cam_backward);
|
||||||
|
log("cam -> backward");
|
||||||
|
}
|
||||||
|
log(String(millis() - startTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
void log (String msg) {
|
||||||
|
if (debug_state) {
|
||||||
|
Serial.println(msg);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -227,7 +227,7 @@ module animationMotorCap () {
|
||||||
|
|
||||||
module driveCoupling () {
|
module driveCoupling () {
|
||||||
D = 15.5;
|
D = 15.5;
|
||||||
H = 41;
|
H = 41-3;
|
||||||
Divot = 2.75;
|
Divot = 2.75;
|
||||||
difference() {
|
difference() {
|
||||||
union() {
|
union() {
|
||||||
|
|
Loading…
Reference in New Issue