this code is completely restructured, but should do the same thing. did not want to directly commit, since it may not work at all. compiles though.
Dependencies: AVEncoder mbed-src-AV
Fork of Test by
main.cpp
- Committer:
- jimmery
- Date:
- 2015-12-15
- Revision:
- 13:5f08195456a4
- Parent:
- 12:0849b16c2672
File content as of revision 13:5f08195456a4:
#include "mbed.h" #include "pid.h" #include "sensors.h" #include "mouse.h" Ticker Systicker; Mouse m; void systick() { m.scan(); // get the IR values. // these values are useful regardless of what mouse_state we are in. switch (m.mouse_state) { case STOPPED: m.offsetCalc(); m.pid_reset(); m.sensor_reset(); break; case FORWARD: if ( m.forward_wall_detected() ) { m.mouse_state = STOPPED; m.turn_direction = LEFT; return; } m.run_pid(); // TODO we need to start saving walls and stuff. break; default: // don't do anything. break; } } void setup() { Mouse m; Systicker.attach_us(&systick, 1000); wait(2); } int main() { setup(); while(1) { switch (m.mouse_state) { case STOPPED: m.stop(); wait(1); if ( m.turn_direction == INVALID ) { m.mouse_state = FORWARD; } else { m.mouse_state = TURNING; } break; case FORWARD: // left_forward = left_speed / left_max_speed; // left_reverse = 0; // right_forward = right_speed / right_max_speed; // right_reverse = 0; break; case TURNING: m.turn(); m.mouse_state = STOPPED; m.turn_direction = INVALID; break; case MOVECELL: m.move_cell(); m.mouse_state = STOPPED; break; default: // idk lmao. show some error message? break; } } }