|
@@ -16,7 +16,13 @@
|
|
|
*/
|
|
|
|
|
|
// Define a stepper and the pins it will use
|
|
|
-AccelStepper stepper(1, 8, 7);
|
|
|
+const int NUM_OF_STEPPERS = 2 ;
|
|
|
+AccelStepper steppers[NUM_OF_STEPPERS] = {AccelStepper(1, 8, 7), AccelStepper(1, 10, 9)}; ;
|
|
|
+
|
|
|
+// Mechanical values
|
|
|
+long int STEPS_PER_TURN = 200 ; // stepper motor
|
|
|
+int MICROSTEPPING = 8 ; //stepper driver
|
|
|
+int REDUCTION_RATIO = 70 ; // mechanical reduction ration to real camera rotation
|
|
|
|
|
|
// microswitch pins
|
|
|
int switchLow = A5;
|
|
@@ -24,45 +30,65 @@ int switchLow = A5;
|
|
|
long int speedLimit[2] = { 50 , 10000000 } ;// sets an absolute minimum/maximum speed limit
|
|
|
long int accLimit[2] = { 100, 200000} ;
|
|
|
|
|
|
-long int moveTo_Stepper(long int stepto ) {
|
|
|
- stepper.moveTo(stepto);
|
|
|
-// while (!stepper.distanceToGo()==0)
|
|
|
-// stepper.run();
|
|
|
-// stepper.moveTo( constrain( stepto , originPos * stepToCm, maxPos * stepToCm ) );
|
|
|
- return stepper.distanceToGo();
|
|
|
+//////////// UTILITIES ///////////////
|
|
|
+
|
|
|
+
|
|
|
+long int camRot2steps (float camRot ) {
|
|
|
+ return (long int) STEPS_PER_TURN * MICROSTEPPING * REDUCTION_RATIO *camRot ;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//////////// ACCELSTEPPER /////////////
|
|
|
+
|
|
|
+void stop_Steppers (void) {
|
|
|
+ for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
|
|
|
+ steppers[i].stop();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+long int moveTo_Stepper(int stepperIndex, long int stepto ) {
|
|
|
+ steppers[stepperIndex].moveTo(stepto);
|
|
|
+// while (!steppers[stepperIndex].distanceToGo()==0)
|
|
|
+// steppers[stepperIndex].run();
|
|
|
+// steppers[stepperIndex].moveTo( constrain( stepto , originPos * stepToCm, maxPos * stepToCm ) );
|
|
|
+ return steppers[stepperIndex].distanceToGo();
|
|
|
}
|
|
|
//float moveToCm_Stepper(float cmto ) {
|
|
|
// stepper.moveTo(constrain( cmto * stepToCm , originPos, maxPos ));
|
|
|
// return stepper.distanceToGo()/stepToCm;
|
|
|
//}
|
|
|
//
|
|
|
-long int move_Stepper(long int stepRelative ) {
|
|
|
- stepper.move(stepRelative);
|
|
|
- return stepper.distanceToGo();
|
|
|
+long int move_Stepper(int stepperIndex, long int stepRelative ) {
|
|
|
+ steppers[stepperIndex].move(stepRelative);
|
|
|
+ return steppers[stepperIndex].distanceToGo();
|
|
|
}
|
|
|
//float moveCm_Stepper(float cmRelative ) {
|
|
|
// stepper.move(cmRelative * stepToCm );
|
|
|
// return stepper.distanceToGo()/stepToCm;
|
|
|
//}
|
|
|
//
|
|
|
-long int maxSpeed_Stepper(long int maxspeed){
|
|
|
- stepper.setMaxSpeed( constrain (maxspeed, speedLimit[0], speedLimit[1] ) );
|
|
|
- return stepper.maxSpeed();
|
|
|
+long int maxSpeed_Stepper(int stepperIndex, long int maxspeed){
|
|
|
+ steppers[stepperIndex].setMaxSpeed( constrain (maxspeed, speedLimit[0], speedLimit[1] ) );
|
|
|
+ return steppers[stepperIndex].maxSpeed();
|
|
|
}
|
|
|
|
|
|
-long int setSpeed_Stepper(long int maxspeed){
|
|
|
- stepper.setSpeed( constrain (maxspeed, speedLimit[0], speedLimit[1] ) );
|
|
|
- return stepper.maxSpeed();
|
|
|
+long int setSpeed_Stepper(int stepperIndex, long int maxspeed){
|
|
|
+ steppers[stepperIndex].setSpeed( constrain (maxspeed, speedLimit[0], speedLimit[1] ) );
|
|
|
+ return steppers[stepperIndex].maxSpeed();
|
|
|
}
|
|
|
|
|
|
-long int acceleration_Stepper( long int acc ){
|
|
|
- stepper.setAcceleration(acc + 1); // prevent 0 step/s²
|
|
|
+long int acceleration_Stepper(int stepperIndex, long int acc ){
|
|
|
+ steppers[stepperIndex].setAcceleration(acc + 1); // prevent 0 step/s²
|
|
|
return acc;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
//////////////// CALIBRATION ////////////////////////
|
|
|
|
|
|
-float init_Stepper(){
|
|
|
+float init_steppers(){
|
|
|
// //run at constant speed until hitting switchLow
|
|
|
// stepper.setSpeed(-1*speedLimit[1]);
|
|
|
// while(digitalRead(switchLow)) {
|
|
@@ -91,12 +117,14 @@ float init_Stepper(){
|
|
|
}
|
|
|
|
|
|
///////////////////// SETUP ///////////////////////////
|
|
|
-void setup_Stepper(){
|
|
|
+void setup_steppers(){
|
|
|
pinMode (switchLow, INPUT_PULLUP);
|
|
|
// pinMode (switchHigh, INPUT_PULLUP);
|
|
|
// stepper.moveTo(rand() % 200000);
|
|
|
- stepper.setMaxSpeed( 20000);
|
|
|
- stepper.setSpeed(10000);
|
|
|
+ for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
|
|
|
+ steppers[i].setMaxSpeed( 20000);
|
|
|
+ steppers[i].setSpeed(10000);
|
|
|
+ }
|
|
|
// while (!stepper.distanceToGo()==0)
|
|
|
// stepper.run();
|
|
|
// stepper.moveTo(0);
|
|
@@ -110,10 +138,15 @@ void setup_Stepper(){
|
|
|
|
|
|
///////////////////// LOOP ///////////////////////////
|
|
|
|
|
|
-bool update_Stepper() {
|
|
|
+bool update_steppers() {
|
|
|
+
|
|
|
+ for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
|
|
|
+ steppers[i].run();
|
|
|
+ }
|
|
|
|
|
|
// bool updated = 1 ;
|
|
|
- stepper.run();
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// if (!digitalRead(switchLow)) {
|
|
|
// stepper.setCurrentPosition(0);
|