State machine
Dependencies: mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter
Diff: main.cpp
- Revision:
- 9:27d00b64076e
- Parent:
- 8:9090ab7c19a8
- Child:
- 10:b165ccd11afd
diff -r 9090ab7c19a8 -r 27d00b64076e main.cpp --- a/main.cpp Wed Oct 31 06:13:38 2018 +0000 +++ b/main.cpp Wed Oct 31 08:17:35 2018 +0000 @@ -40,6 +40,7 @@ DigitalOut led_red(LED_RED); DigitalOut led_green(LED_GREEN); +DigitalOut led_blue(LED_BLUE); // The last arguent is the reset pin. // The screen doesn't use it, but the library requires it @@ -62,7 +63,7 @@ screen.display(); } - if (ud_button.is_pressed()) { + if (ud_button.has_just_been_pressed()) { current_state = calib_motor; } } @@ -77,6 +78,10 @@ screen.clear_display(); screen.display_state_name("Motor calibration"); } + + if (ud_button.has_just_been_pressed()) { + current_state = calib_bicep1; + } } void do_state_calib_bicep1() @@ -87,6 +92,10 @@ screen.clear_display(); screen.display_state_name("EMG 1 calibration"); } + + if (ud_button.has_just_been_pressed()) { + current_state = calib_bicep2; + } } void do_state_calib_bicep2() @@ -97,6 +106,10 @@ screen.clear_display(); screen.display_state_name("EMG 2 calibration"); } + + if (ud_button.has_just_been_pressed()) { + current_state = homing; + } } void do_state_homing() @@ -107,6 +120,10 @@ screen.clear_display(); screen.display_state_name("Homing"); } + + if (ud_button.has_just_been_pressed()) { + current_state = operation; + } } void do_state_operation() @@ -117,6 +134,10 @@ screen.clear_display(); screen.display_state_name("Normal operation"); } + + if (ud_button.has_just_been_pressed()) { + current_state = homing; + } } void do_state_failure() @@ -188,6 +209,8 @@ int main() { led_red = 1; + led_green = 1; + led_blue = 1; motor1.set_pid_k_values(Kp, Ki, Kd); motor2.set_pid_k_values(Kp, Ki, Kd); @@ -206,6 +229,14 @@ while (true) { main_loop(); + + // Button debugging. + if (ud_button.has_just_been_pressed() || lr_button.has_just_been_pressed() || p_button.has_just_been_pressed()) { + led_blue = 0; + } else { + led_blue = 1; + } + wait(main_loop_wait_time); } } \ No newline at end of file