![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
wheelchair code for alexa integration
Fork of wheelchaircontrol by
main.cpp@6:0cd57bdd8fbc, 2018-07-20 (annotated)
- Committer:
- ryanlin97
- Date:
- Fri Jul 20 17:54:43 2018 +0000
- Revision:
- 6:0cd57bdd8fbc
- Parent:
- 5:e0ccaab3959a
- Child:
- 7:5e38d43fbce3
using mpu9250 imu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryanlin97 | 0:fc0c4a184482 | 1 | #include "wheelchair.h" |
ryanlin97 | 0:fc0c4a184482 | 2 | |
ryanlin97 | 3:a5e71bfdb492 | 3 | AnalogIn x(A0); |
ryanlin97 | 3:a5e71bfdb492 | 4 | AnalogIn y(A1); |
ryanlin97 | 3:a5e71bfdb492 | 5 | |
ryanlin97 | 0:fc0c4a184482 | 6 | DigitalOut off(D0); |
ryanlin97 | 0:fc0c4a184482 | 7 | DigitalOut on(D1); |
ryanlin97 | 0:fc0c4a184482 | 8 | DigitalOut up(D2); |
ryanlin97 | 0:fc0c4a184482 | 9 | DigitalOut down(D3); |
ryanlin97 | 2:c2d049efc266 | 10 | |
ryanlin97 | 6:0cd57bdd8fbc | 11 | Serial pc(USBTX, USBRX); |
ryanlin97 | 6:0cd57bdd8fbc | 12 | |
ryanlin97 | 6:0cd57bdd8fbc | 13 | Wheelchair smart(xDir,yDir, &pc); |
ryanlin97 | 2:c2d049efc266 | 14 | |
ryanlin97 | 0:fc0c4a184482 | 15 | int main(void) |
ryanlin97 | 0:fc0c4a184482 | 16 | { |
ryanlin97 | 0:fc0c4a184482 | 17 | on = 1; |
ryanlin97 | 6:0cd57bdd8fbc | 18 | while(1) { |
ryanlin97 | 6:0cd57bdd8fbc | 19 | /* if( pc.readable()) { |
ryanlin97 | 6:0cd57bdd8fbc | 20 | char c = pc.getc(); |
ryanlin97 | 6:0cd57bdd8fbc | 21 | if( c == 'w') { |
ryanlin97 | 6:0cd57bdd8fbc | 22 | pc.printf("up \n"); |
ryanlin97 | 6:0cd57bdd8fbc | 23 | smart.forward(); |
ryanlin97 | 6:0cd57bdd8fbc | 24 | } |
ryanlin97 | 6:0cd57bdd8fbc | 25 | |
ryanlin97 | 6:0cd57bdd8fbc | 26 | else if( c == 'd') { |
ryanlin97 | 6:0cd57bdd8fbc | 27 | pc.printf("left \n"); |
ryanlin97 | 6:0cd57bdd8fbc | 28 | smart.left(); |
ryanlin97 | 6:0cd57bdd8fbc | 29 | } |
ryanlin97 | 6:0cd57bdd8fbc | 30 | |
ryanlin97 | 6:0cd57bdd8fbc | 31 | else if( c == 'a') { |
ryanlin97 | 6:0cd57bdd8fbc | 32 | pc.printf("right \n"); |
ryanlin97 | 6:0cd57bdd8fbc | 33 | smart.right(); |
ryanlin97 | 6:0cd57bdd8fbc | 34 | } |
ryanlin97 | 6:0cd57bdd8fbc | 35 | |
ryanlin97 | 6:0cd57bdd8fbc | 36 | else if( c == 's') { |
ryanlin97 | 6:0cd57bdd8fbc | 37 | pc.printf("down \n"); |
ryanlin97 | 6:0cd57bdd8fbc | 38 | smart.backward(); |
ryanlin97 | 6:0cd57bdd8fbc | 39 | } |
ryanlin97 | 6:0cd57bdd8fbc | 40 | |
ryanlin97 | 6:0cd57bdd8fbc | 41 | else { |
ryanlin97 | 6:0cd57bdd8fbc | 42 | pc.printf("none \n"); |
ryanlin97 | 6:0cd57bdd8fbc | 43 | smart.stop(); |
ryanlin97 | 6:0cd57bdd8fbc | 44 | if( c == 'o') { |
ryanlin97 | 6:0cd57bdd8fbc | 45 | pc.printf("turning on"); |
ryanlin97 | 6:0cd57bdd8fbc | 46 | on = 0; |
ryanlin97 | 6:0cd57bdd8fbc | 47 | wait(process); |
ryanlin97 | 6:0cd57bdd8fbc | 48 | on = 1; |
ryanlin97 | 6:0cd57bdd8fbc | 49 | } |
ryanlin97 | 6:0cd57bdd8fbc | 50 | |
ryanlin97 | 6:0cd57bdd8fbc | 51 | else if( c == 'k') { |
ryanlin97 | 6:0cd57bdd8fbc | 52 | off = 0; |
ryanlin97 | 6:0cd57bdd8fbc | 53 | wait(process); |
ryanlin97 | 6:0cd57bdd8fbc | 54 | off = 1; |
ryanlin97 | 6:0cd57bdd8fbc | 55 | } |
ryanlin97 | 6:0cd57bdd8fbc | 56 | |
ryanlin97 | 6:0cd57bdd8fbc | 57 | else if( c == 'u') { |
ryanlin97 | 6:0cd57bdd8fbc | 58 | up = 0; |
ryanlin97 | 6:0cd57bdd8fbc | 59 | wait(process); |
ryanlin97 | 6:0cd57bdd8fbc | 60 | up = 1; |
ryanlin97 | 6:0cd57bdd8fbc | 61 | } |
ryanlin97 | 6:0cd57bdd8fbc | 62 | |
ryanlin97 | 6:0cd57bdd8fbc | 63 | else if( c == 'p') { |
ryanlin97 | 6:0cd57bdd8fbc | 64 | down = 0; |
ryanlin97 | 6:0cd57bdd8fbc | 65 | wait(process); |
ryanlin97 | 6:0cd57bdd8fbc | 66 | down = 1; |
ryanlin97 | 6:0cd57bdd8fbc | 67 | } |
ryanlin97 | 6:0cd57bdd8fbc | 68 | } |
ryanlin97 | 6:0cd57bdd8fbc | 69 | } |
ryanlin97 | 6:0cd57bdd8fbc | 70 | |
ryanlin97 | 6:0cd57bdd8fbc | 71 | else { |
ryanlin97 | 6:0cd57bdd8fbc | 72 | pc.printf("Nothing pressed \n"); |
ryanlin97 | 6:0cd57bdd8fbc | 73 | smart.stop(); |
ryanlin97 | 6:0cd57bdd8fbc | 74 | } |
ryanlin97 | 6:0cd57bdd8fbc | 75 | */ |
ryanlin97 | 6:0cd57bdd8fbc | 76 | smart.move(x,y); |
ryanlin97 | 6:0cd57bdd8fbc | 77 | if( pc.readable()) { |
ryanlin97 | 6:0cd57bdd8fbc | 78 | char c = pc.getc(); |
ryanlin97 | 6:0cd57bdd8fbc | 79 | if( c == 'r') { |
ryanlin97 | 6:0cd57bdd8fbc | 80 | smart.turn_right(pc); |
ryanlin97 | 0:fc0c4a184482 | 81 | } |
ryanlin97 | 6:0cd57bdd8fbc | 82 | } |
ryanlin97 | 6:0cd57bdd8fbc | 83 | wait(process); |
ryanlin97 | 6:0cd57bdd8fbc | 84 | } |
ryanlin97 | 1:c0beadca1617 | 85 | |
ryanlin97 | 0:fc0c4a184482 | 86 | } |
ryanlin97 | 0:fc0c4a184482 | 87 |