State machine

Dependencies:   mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter

Revision:
19:53b9729fbab5
Parent:
16:9c5ef6fe6780
Child:
20:af1a6cd7469b
--- a/main.cpp	Wed Oct 31 14:17:03 2018 +0000
+++ b/main.cpp	Wed Oct 31 16:19:28 2018 +0000
@@ -122,7 +122,7 @@
     }
     
     if (main_is_calibrated && sec_is_calibrated) {
-        current_state = calib_bicep1;
+        current_state = homing;
     }
 }
 
@@ -163,8 +163,11 @@
         screen.display_state_name("Homing");
     }
     
+    main_motor.set_target_angle(PI*0.5);
+    sec_motor.set_target_angle(0);
+    
     if (ud_button.has_just_been_pressed()) {
-        current_state = operation;
+        current_state = calib_bicep1;
     }
 }
 
@@ -183,6 +186,7 @@
         screen.display_left_right_arrow(control_goes_right);
     }
     
+    /*
     double main_target = ((potmeter1.read() * 2) - 1) * PI;
     main_motor.set_target_angle(main_target);
     double sec_target = ((potmeter2.read() * 2) - 1) * PI;
@@ -196,6 +200,7 @@
         control_goes_right = !control_goes_right;
         screen.display_left_right_arrow(control_goes_right);
     }
+    */
 }
 
 void do_state_failure()
@@ -278,8 +283,12 @@
     // One of the motors is reversed in the electronics.
     // This is fixed in the motor controll board, so we have to account
     // for it in software.
-    main_motor.set_extra_reduction_ratio(main_gear_ratio);
-    sec_motor.set_extra_reduction_ratio(-sec_gear_ratio);
+    main_motor.set_extra_reduction_ratio(-main_gear_ratio);
+    sec_motor.set_extra_reduction_ratio(sec_gear_ratio);
+    
+    // Set the maximum pwm fraction for both motors.
+    main_motor.set_max_pwm_fraction(0.5);
+    sec_motor.set_max_pwm_fraction(0.5);
     
     // Start the motor controller at the desired frequency.
     main_motor.start(pid_period);