![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
wheelchair code for driver assitance
Fork of wheelchairalexa by
Diff: main.cpp
- Revision:
- 12:0e5a0571b497
- Parent:
- 11:75f0f13ff6c1
--- a/main.cpp Thu Aug 16 16:42:45 2018 +0000 +++ b/main.cpp Fri Aug 17 03:10:39 2018 +0000 @@ -3,14 +3,17 @@ AnalogIn x(A0); AnalogIn y(A1); -DigitalOut off(D0); -DigitalOut on(D1); +DigitalOut on(D12); +DigitalOut off(D11); DigitalOut up(D2); DigitalOut down(D3); bool manual = false; +bool leftBound = false; +bool rightBound = false; +bool straightBound = false; -Serial pc(USBTX, USBRX, 57600); +Serial pc(USBTX, USBRX, 9600); Timer t; Wheelchair smart(xDir,yDir, &pc, &t); @@ -18,62 +21,39 @@ int main(void) { - pc.printf("hello\n"); + smart.stop(); while(1) { - if( pc.readable()) { - char c = pc.getc(); - pc.printf("hello\n"); - if( c == 'w') { - pc.printf("up \n"); - smart.forward(); - } - - else if( c == 'a') { - pc.printf("left \n"); - smart.left(); - } - - else if( c == 'd') { - pc.printf("right \n"); - smart.right(); - } - - else if( c == 's') { - pc.printf("down \n"); - smart.backward(); - } - - else if( c == 'r') { - smart.turn_right(90); - } - - else if( c == 'l') { - smart.turn_left(90); - } - - else if( c == 't') { - char buffer[256]; - pc.printf ("Enter a long number: "); - fgets (buffer, 256, stdin); - int angle = atoi (buffer); - - if(angle == 0) { - pc.printf("invalid input try again\n"); - } - else { - smart.turn(angle); - } - - } - - else if( c == 'm') { pc.printf("turning on joystick\n"); manual = true; t.reset(); while(manual) { - smart.move(x,y); + smart.move(x,y,leftBound,rightBound,straightBound); if( pc.readable()) { char d = pc.getc(); + if( d == 'l') { + leftBound = true; + } + + if (d == 'e') { + leftBound = false; + } + + if( d == 'f') { + straightBound = true; + } + + if (d == 'o') { + straightBound = false; + } + + if( d == 'r') { + rightBound = true; + } + + if( d == 'i') { + rightBound = false; + } + if( d == 'm') { pc.printf("turning off joystick\n"); manual = false; @@ -82,17 +62,8 @@ } } - else { - pc.printf("none \n"); - smart.stop(); - } - } - - else { - smart.stop(); - } - wait(process); - } - + wait(process); } + +