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
Diff: main.cpp
- Revision:
- 3:9c63fc5f157e
- Parent:
- 2:d70795e4e0bf
- Child:
- 4:5ce2c8864908
--- a/main.cpp Wed Oct 31 11:21:16 2018 +0000 +++ b/main.cpp Wed Oct 31 11:51:03 2018 +0000 @@ -22,11 +22,78 @@ 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() { +int main() +{ // ============================== PC-COMMUNICATION ============================= bool externalPC = true; if (externalPC) {