State machine with EMG functions and parameters
Dependencies: biquadFilter FastPWM HIDScope MODSERIAL mbed
Fork of StateMachine by
Diff: main.cpp
- Revision:
- 8:8cef1050ebd9
- Parent:
- 7:ef5966469621
- Child:
- 9:8a162a3505ed
--- a/main.cpp Wed Oct 31 17:15:52 2018 +0000 +++ b/main.cpp Wed Oct 31 21:23:23 2018 +0000 @@ -6,19 +6,29 @@ #include "HIDScope.h" #include "MODSERIAL.h" -// Inputs & outputs -DigitalOut ledRed(LED_RED,1); // red LED K64F -DigitalOut ledGreen(LED_GREEN,1); // green LED K64F -DigitalOut ledBlue(LED_BLUE,1); // blue LED K64F +// LEDs +DigitalOut ledRed(LED_RED,1); // red LED K64F +DigitalOut ledGreen(LED_GREEN,1); // green LED K64F +DigitalOut ledBlue(LED_BLUE,1); // blue LED K64F +// DigitalOut ledBio1(,1); // led 1 Biorobotics shield // LED pins +// DigitalOut ledBio2(,1); // led 2 Biorobotics shield + +Ticker blinkTimer; // LED ticker + +// Buttons/inputs InterruptIn buttonBio1(D0); // button 1 BioRobotics shield InterruptIn buttonBio2(D1); // button 2 BioRobotics shield InterruptIn buttonK64F(SW3); // button on K64F -InterruptIn emergencybutton(SW2); // emergency button on K64F +InterruptIn buttonEmergency(SW2); // emergency button on K64F +// Motor pins + + +// PC communication MODSERIAL pc(USBTX, USBRX); // communication with pc // Define & initialise state machine -enum states { waiting, calibratingMotors, calibratingEMG, +enum states { calibratingMotors, calibratingEMG, homing, operating, reading, failing, demoing }; states currentState = waiting; // start in waiting mode @@ -35,6 +45,11 @@ currentState = failing; // change to state changeState = true; // next loop, switch states } + +void blinkLED(DigitalOut led) // blinkTimer.attach(&blinkLED,0.5) aanroepen bij initialisation, bij verlaten state: +{ // blinkTimer.detach + led =! led; // toggle LED + // ============================ MOTOR FUNCTIONS ============================== @@ -65,7 +80,7 @@ // --------------------------- transition ---------------------------- // Transition condition #1: with a button press, enter motor // calibration mode - if (emergencybutton == true) { // Waarom drukken we op de noodknop om te beginnen? Lijkt me raar + if (buttonEmergency == true) { // Waarom drukken we op de noodknop om te beginnen? Lijkt me raar // Actions when leaving state // Is hier niet de resetknop voor bedoeld? /* */ @@ -300,9 +315,12 @@ int main() { -// ================================ EMERGENCY ================================ // Dit hoeft dus niet in de while loop? +// ================================ EMERGENCY ================================ //If the emergency button is pressed, stop program via failing state - emergencybutton.rise(stopProgram); // Automatische triggers voor failure mode? + buttonEmergency.rise(stopProgram); // Automatische triggers voor failure mode? + +// ================================ EMERGENCY ================================ + pc.baud(115200); // communication with terminal // Baud rate // ==================================== LOOP =================================== while (true) { // loop forever