Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: biquadFilter FastPWM MODSERIAL QEI mbed
main.cpp
- Committer:
- tverouden
- Date:
- 2018-10-31
- Revision:
- 3:9c63fc5f157e
- Parent:
- 2:d70795e4e0bf
- Child:
- 4:5ce2c8864908
File content as of revision 3:9c63fc5f157e:
// ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ PREPARATION ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ // Libraries #include "mbed.h" #include "BiQuad.h" #include "FastPWM.h" #include "HIDScope.h" #include "MODSERIAL.h" // Inputs & outputs DigitalOut redled(LED_RED,1); // red LED K64F DigitalOut greenled(LED_GREEN,1); // green LED K64F DigitalOut blueled(LED_BLUE,1); // blue LED K64F 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 // Define & initialise state machine enum states { waiting, calibratingMotors, calibratingEMGx, calibratingEMGy, homing, operating, flipping, failure, demo }; states currentState = waiting; // start in waiting mode bool changeState = true; // initialise the first state // ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ STATE MACHINE ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ void stateMachine(void) { switch (currentState) { // determine which state Odin is in // =============================== WAITING MODE ================================ case waiting: // ------------------------------ INITIALISATION ------------------------------- if (changeState) { // when entering the state if (externalPC) { // when external pc is connected pc.printf("waiting...\r\n"); // print current state } changeState = false; // stay in this state // Actions when entering state /* */ } // ---------------------------------- ACTION ----------------------------------- // Actions for each loop iteration // -------------------------------- TRANSITION --------------------------------- // Transition condition #1 if () { // Actions when leaving state currentState = ; // change to state changeState = true; // next loop, switch states } break; // end case // ========================== MOTOR CALIBRATION MODE =========================== case calibratingMotors: // ------------------------------ INITIALISATION ------------------------------- if (changeState) { // when entering the state if (externalPC) { // when external pc is connected pc.printf("calibrating motors...r\n"); // print current state } changeState = false; // stay in this state // Actions when entering state /* */ } // ---------------------------------- ACTION ----------------------------------- // Actions for each loop iteration // -------------------------------- TRANSITION --------------------------------- // Transition condition #1 if () { // Actions when leaving state currentState = ; // change to state changeState = true; // next loop, switch states } break; // end case // ================================= DEFAULT =================================== default: } } // ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ MAIN LOOP ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ int main() { // ============================== PC-COMMUNICATION ============================= bool externalPC = true; if (externalPC) { MODSERIAL pc(USBTX, USBRX); // communication with pc } // ==================================== LOOP =================================== while (true) { // loop forever } }