State machine

Dependencies:   mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter

Revision:
30:a45bbfa6bd22
Parent:
29:77fee8a01529
Child:
32:b63b5837bcb1
--- a/main.cpp	Thu Nov 01 12:55:46 2018 +0000
+++ b/main.cpp	Thu Nov 01 13:01:54 2018 +0000
@@ -107,14 +107,18 @@
     if (!main_is_calibrated) {
         main_is_calibrated = calibrate_motor(main_motor, main_last_angle, main_iterations_not_moving);
         if (main_is_calibrated) {
-            main_motor.define_current_angle_as_x_radians(0.785398); // 45 degrees.
+            double calibration_angle = 0.785398; // 45 degrees.
+            main_motor.define_current_angle_as_x_radians(calibration_angle);
+            main_motor.set_target_angle(calibration_angle - 0.1); // Give the arm some breathing space.
             led_green = 0;
         }
     }
     if (!sec_is_calibrated) {
         sec_is_calibrated = calibrate_motor(sec_motor, sec_last_angle, sec_iterations_not_moving);
         if (sec_is_calibrated) {
+            double calibration_angle = -0.733038; // -42 degrees.
             sec_motor.define_current_angle_as_x_radians(-0.733038); // -42 degrees.
+            main_motor.set_target_angle(calibration_angle + 0.1); // Give the arm some breathing space.
             led_blue = 0;
         }
     }
@@ -268,6 +272,7 @@
         // Update the display.
         led_red = 0;
         led_green = 1;
+        led_blue = 1;
         screen.clear_display();
         screen.display_state_name("STOP");
     }