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
Diff: main.cpp
- Revision:
- 11:cde87eaf3f0f
- Parent:
- 10:d2907773f9a3
- Child:
- 12:0849b16c2672
diff -r d2907773f9a3 -r cde87eaf3f0f main.cpp --- a/main.cpp Fri Dec 04 09:38:25 2015 +0000 +++ b/main.cpp Fri Dec 04 22:53:53 2015 +0000 @@ -4,9 +4,6 @@ // set things Serial pc(SERIAL_TX, SERIAL_RX); Ticker Systicker; -Timer timer; -Ticker action_ticker; -Ticker algorithm_ticker; PwmOut right_forward(PB_10); PwmOut right_reverse(PA_6); @@ -110,8 +107,9 @@ //time to make a 90 degree turn and move forward one cell length, repectively //should be replaced with encoder counts -volatile int max_turn_count = 800; -volatile int cell_length_count = 800; +const int lmax_turn_count = 620; //I think we need different constants for left/right +const int rmax_turn_count = 0; +const int cell_length_count = 800; volatile int forward_counter = 0; @@ -262,10 +260,10 @@ void stop() { - left_forward = 1; - left_reverse = 1; - right_forward = 1; - right_reverse = 1; + left_forward = 0; + left_reverse = 0; + right_forward = 0; + right_reverse = 0; } void turn() { @@ -278,7 +276,7 @@ int left_pulses; int right_pulses; - while ( turn_counter < max_turn_count ) + while ( turn_counter < lmax_turn_count ) { left_pulses = l_enco.getPulses(); right_pulses = r_enco.getPulses(); @@ -302,6 +300,7 @@ default: // invalid state. did not set a turn direction. mouse_state = STOPPED; + break; } } @@ -331,29 +330,6 @@ } } - -void algorithm() { //moved to systick - //encoder_reset(); -// mouse_state = TURNING; -// turn_direction = LEFT; - //action_ticker.attach_us(&turn, 1000); - - /*if (opening_left_ahead || opening_right_ahead) { - action_ticker.attach_us(&move_cell, 1000); - } - if (opening_left) { - mouse_state = TURNING; - turn_direction = LEFT; - action_ticker.attach_us(&turn, 1000); - } - if (opening_right) { - mouse_state = TURNING; - turn_direction = RIGHT; - action_ticker.attach_us(&turn, 1000); - }*/ - -} - void setup() { eRS = 0; @@ -371,8 +347,6 @@ wait(2); Systicker.attach_us(&systick, 1000); - //action_ticker.attach_us(&turn, 1000); - //algorithm_ticker.attach_us(&algorithm, 1000); let's try to stick with one ticker } int main() {