|
@@ -8,43 +8,69 @@ bool debug = true ;
|
|
|
int enablePin = 22 ;
|
|
|
Stepper motor(15, 14);
|
|
|
RotateControl controller;
|
|
|
-int stepper_maxSpeed = 5000 ;
|
|
|
-int stepper_maxAcc = 10000;
|
|
|
+bool stepper_mode = false ;
|
|
|
+
|
|
|
+int MSTEPPING = 16 ;
|
|
|
+
|
|
|
+int stepper_maxSpeed = 900*MSTEPPING ;
|
|
|
+int stepper_maxAcc = 1200*MSTEPPING;
|
|
|
+int current_speed ;
|
|
|
|
|
|
int STEPS_PER_TURN = 200 ;
|
|
|
-int MSTEPPING = 1 ;
|
|
|
float MOTOR_RATIO = 99.05 ;
|
|
|
float BELT_RATIO = 5.217391304 ;
|
|
|
float STEPS_2_ROT = STEPS_PER_TURN * MSTEPPING * MOTOR_RATIO * BELT_RATIO ;
|
|
|
+//stepper calibs
|
|
|
+//1908400 steps (@mstep 8) per turn
|
|
|
+// -> 238550 steps for one turn, plus mstepping
|
|
|
+float CALIB_STEPS_2_ROT = 238550 * MSTEPPING ;
|
|
|
|
|
|
+int SECONDS_PER_DAY = 86400 ;
|
|
|
+int speed_3turns1day = 3 * CALIB_STEPS_2_ROT / SECONDS_PER_DAY ; //132,528 @ms16
|
|
|
|
|
|
-int stepper_speeds[4] = {8000, 4000, 1000, 100 } ;
|
|
|
+
|
|
|
+
|
|
|
+int stepper_speeds[4] = {MSTEPPING*900, 10000, 1000, 100 } ;
|
|
|
|
|
|
|
|
|
|
|
|
//Pins declaration
|
|
|
int btn_run_pin = 7 ;
|
|
|
-Atm_bit toggle;
|
|
|
-int btn_speed_pin[4] = {9, 10, 11, 12} ;
|
|
|
+int btn_speed_pin[4] = {12, 11, 10, 9} ;
|
|
|
int led_run_pin = 6 ;
|
|
|
|
|
|
|
|
|
//Automaton
|
|
|
Atm_button btn_run;
|
|
|
Atm_button btn_speed[4];
|
|
|
-int current_speed ;
|
|
|
+int mode ;
|
|
|
Atm_led led_run;
|
|
|
|
|
|
|
|
|
/////////////// CALLBACKS //////////////////
|
|
|
|
|
|
void button_change( int idx, int v, int up ){
|
|
|
- Serial.print("Speed ");
|
|
|
- Serial.print(idx);
|
|
|
- Serial.print(" selected : ");
|
|
|
- Serial.println(stepper_speeds[idx]);
|
|
|
- current_speed = stepper_speeds[idx] ;
|
|
|
- motor.setMaxSpeed(current_speed);
|
|
|
+ mode = idx ;
|
|
|
+ Serial.print("Mode ");
|
|
|
+ Serial.print(mode);
|
|
|
+ Serial.print("- speed ");
|
|
|
+ Serial.println(stepper_speeds[mode]);
|
|
|
+}
|
|
|
+
|
|
|
+void run_mode( int idx, int v, int up ){
|
|
|
+ if(idx){
|
|
|
+ current_speed = stepper_speeds[mode];
|
|
|
+ controller.emergencyStop();
|
|
|
+ motor.setMaxSpeed(current_speed);
|
|
|
+ stepper_mode = true ;
|
|
|
+ led_run.trigger(led_run.EVT_BLINK);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ stepper_mode = false ;
|
|
|
+ led_run.trigger(led_run.EVT_OFF);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -52,6 +78,7 @@ void button_change( int idx, int v, int up ){
|
|
|
|
|
|
void setup()
|
|
|
{
|
|
|
+ delay(2000);
|
|
|
Serial.begin(115200);
|
|
|
Serial.println("Started");
|
|
|
|
|
@@ -68,18 +95,17 @@ void setup()
|
|
|
// Serial.println("toggle run");
|
|
|
// led_run.trigger(led_run.EVT_TOGGLE);
|
|
|
// } )
|
|
|
- .onPress( toggle, toggle.EVT_TOGGLE );
|
|
|
+ .onPress( run_mode, 1 )
|
|
|
+ .onRelease(run_mode, 0);
|
|
|
|
|
|
led_run.begin(led_run_pin);
|
|
|
|
|
|
- toggle.begin() // Bit machine stores the toggle state
|
|
|
- .onChange( true, led_run, led_run.EVT_ON ) // And turns the led on and off
|
|
|
- .onChange( false, led_run, led_run.EVT_OFF );;
|
|
|
|
|
|
|
|
|
for(int i=0; i<4; i++) {
|
|
|
btn_speed[i].begin(btn_speed_pin[i])
|
|
|
- .onPress(button_change, i);
|
|
|
+ .onPress(button_change, i)
|
|
|
+ .onRelease(button_change, 0);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -95,8 +121,8 @@ void setup()
|
|
|
//Motor setup
|
|
|
pinMode(enablePin, OUTPUT);
|
|
|
digitalWrite(enablePin, LOW);
|
|
|
- motor.setMaxSpeed(8000);
|
|
|
- motor.setAcceleration(1000);
|
|
|
+ motor.setMaxSpeed(stepper_maxSpeed);
|
|
|
+ motor.setAcceleration(stepper_maxAcc);
|
|
|
}
|
|
|
|
|
|
///////////////////// LOOP /////////////////////
|
|
@@ -104,5 +130,6 @@ void setup()
|
|
|
void loop()
|
|
|
{
|
|
|
automaton.run();
|
|
|
- controller.rotateAsync(motor);
|
|
|
+ if(stepper_mode){controller.rotateAsync(motor);}
|
|
|
+ else{controller.stopAsync();}
|
|
|
}
|