Merge in 9 months of work on capper branch #71
|
@ -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
|
void cmd (char val) {
|
||||||
//myMotor->step(round(200 / 8), FORWARD, MICROSTEP); //1621ms @ speed 100
|
if (val == cmd_debug) {
|
||||||
|
debug();
|
||||||
|
} else if (val == cmd_connect) {
|
||||||
|
connect();
|
||||||
|
} else if (val == cmd_mcopy_identifier) {
|
||||||
|
identify();
|
||||||
|
} else if (val == cmd_cam_forward) {
|
||||||
|
setDir(true); //explicit
|
||||||
|
} else if (val == cmd_cam_backward) {
|
||||||
|
setDir(false);
|
||||||
|
} else if (val == cmd_camera) {
|
||||||
|
cam();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//myMotor->step(200, FORWARD, SINGLE); //873ms @ speed 600
|
void debug () {
|
||||||
//myMotor->step(200, FORWARD, SINGLE); //1377ms @ speed 100
|
debug_state = true;
|
||||||
|
Serial.println(cmd_debug);
|
||||||
|
log("debugging enabled");
|
||||||
|
}
|
||||||
|
|
||||||
//myMotor->step(200, FORWARD, MICROSTEP); //12466ms @ speed 600
|
void connect () {
|
||||||
//myMotor->step(200, FORWARD, MICROSTEP); //12967ms @ speed 100
|
Serial.println(cmd_connect);
|
||||||
|
log("connect()");
|
||||||
//if (stepper.distanceToGo() != 0) {
|
}
|
||||||
long startTime = millis();
|
|
||||||
//stepper.runToNewPosition(0);
|
void identify () {
|
||||||
//stepper.runToNewPosition(600);
|
Serial.println(cmd_cam_identifier);
|
||||||
myMotor->step(600, FORWARD, DOUBLE);
|
log("identify()");
|
||||||
//myMotor->step(600, FORWARD, SINGLE);
|
}
|
||||||
stepper.run();
|
|
||||||
long stopTime = millis();
|
void setDir (boolean dir) {
|
||||||
Serial.print(stopTime - startTime);
|
cam_dir = dir;
|
||||||
Serial.println("ms");
|
if (cam_dir) {
|
||||||
delay(1000);
|
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