Code to let Gr20's BioRobotics2017 robot come to live.
Dependencies: FastPWM MODSERIAL QEI mbed
ui.h@2:df0c6af898ac, 2017-11-12 (annotated)
- Committer:
- megrootens
- Date:
- Sun Nov 12 14:06:23 2017 +0000
- Revision:
- 2:df0c6af898ac
- Parent:
- 0:caa8ee3bd882
- Child:
- 5:088917beb5e4
this works, only controller needs to be updated since I broke the moving average filtered one....;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
megrootens | 0:caa8ee3bd882 | 1 | #include "MODSERIAL.h" |
megrootens | 0:caa8ee3bd882 | 2 | |
megrootens | 0:caa8ee3bd882 | 3 | #define LED_ON 0 |
megrootens | 0:caa8ee3bd882 | 4 | |
megrootens | 0:caa8ee3bd882 | 5 | /** |
megrootens | 0:caa8ee3bd882 | 6 | * User interface |
megrootens | 2:df0c6af898ac | 7 | * |
megrootens | 2:df0c6af898ac | 8 | * Implementation can be found in main.cpp |
megrootens | 0:caa8ee3bd882 | 9 | */ |
megrootens | 0:caa8ee3bd882 | 10 | namespace ui |
megrootens | 0:caa8ee3bd882 | 11 | { |
megrootens | 2:df0c6af898ac | 12 | // Sample time |
megrootens | 2:df0c6af898ac | 13 | const double kSampleTime = 0.5; |
megrootens | 0:caa8ee3bd882 | 14 | |
megrootens | 2:df0c6af898ac | 15 | // UI states |
megrootens | 0:caa8ee3bd882 | 16 | enum State { |
megrootens | 0:caa8ee3bd882 | 17 | IGNORE, |
megrootens | 0:caa8ee3bd882 | 18 | STATE_SWITCHING, |
megrootens | 0:caa8ee3bd882 | 19 | ROBOT_CONTROL |
megrootens | 0:caa8ee3bd882 | 20 | }; |
megrootens | 0:caa8ee3bd882 | 21 | |
megrootens | 2:df0c6af898ac | 22 | // UI state description |
megrootens | 0:caa8ee3bd882 | 23 | const char *StateNames[] = { |
megrootens | 0:caa8ee3bd882 | 24 | "Ignore user input", |
megrootens | 0:caa8ee3bd882 | 25 | "State switching", |
megrootens | 0:caa8ee3bd882 | 26 | "Control robot" |
megrootens | 0:caa8ee3bd882 | 27 | }; |
megrootens | 0:caa8ee3bd882 | 28 | |
megrootens | 2:df0c6af898ac | 29 | // Change state |
megrootens | 0:caa8ee3bd882 | 30 | void SwitchState(State new_state); |
megrootens | 0:caa8ee3bd882 | 31 | |
megrootens | 2:df0c6af898ac | 32 | // Current state |
megrootens | 0:caa8ee3bd882 | 33 | State state = IGNORE; |
megrootens | 0:caa8ee3bd882 | 34 | |
megrootens | 2:df0c6af898ac | 35 | // LEDs and Serial |
megrootens | 0:caa8ee3bd882 | 36 | DigitalOut rgb_led[] {LED_RED, LED_GREEN, LED_BLUE}; |
megrootens | 0:caa8ee3bd882 | 37 | MODSERIAL serial(USBTX,USBRX); |
megrootens | 0:caa8ee3bd882 | 38 | |
megrootens | 2:df0c6af898ac | 39 | // Interrupt switches |
megrootens | 0:caa8ee3bd882 | 40 | void InterruptSwitch2(); |
megrootens | 0:caa8ee3bd882 | 41 | void InterruptSwitch3(); |
megrootens | 0:caa8ee3bd882 | 42 | |
megrootens | 2:df0c6af898ac | 43 | // Display robot status through LEDs |
megrootens | 0:caa8ee3bd882 | 44 | void StatusDisplay(); |
megrootens | 2:df0c6af898ac | 45 | } |