![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
added
Dependencies: BNO055_fusion PowerControl mbed
Fork of TEAM_G_FLOW_RIDA by
main.cpp@18:f9012e93edb8, 2016-03-29 (annotated)
- Committer:
- 12104404
- Date:
- Tue Mar 29 02:12:08 2016 +0000
- Revision:
- 18:f9012e93edb8
- Parent:
- 17:2f89826b5679
- Child:
- 19:2dd81b864e14
ROBOT CLEANS THE PATH;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
12104404 | 0:96d6eb224379 | 1 | #include "LOCALIZE.h" |
12104404 | 6:0602a9e8118b | 2 | #include "LOCOMOTION.h" |
12104404 | 6:0602a9e8118b | 3 | #include "WATCHDOG.h" |
12104404 | 0:96d6eb224379 | 4 | |
12104404 | 6:0602a9e8118b | 5 | #define SPEED_FB_MIN 0.15 |
12104404 | 6:0602a9e8118b | 6 | #define SPEED_FB_MAX 0.50 |
12104404 | 6:0602a9e8118b | 7 | |
12104404 | 8:b36be08c44f8 | 8 | Serial pc(p13, p14); |
12104404 | 8:b36be08c44f8 | 9 | //Serial pc(USBTX, USBRX); |
12104404 | 6:0602a9e8118b | 10 | |
12104404 | 6:0602a9e8118b | 11 | Watchdog wdt; |
12104404 | 0:96d6eb224379 | 12 | |
12104404 | 0:96d6eb224379 | 13 | I2C i2c1(p28, p27); |
12104404 | 0:96d6eb224379 | 14 | I2C i2c2(p9, p10); |
12104404 | 16:d6f15a13c3aa | 15 | LOCALIZE loc(i2c1, i2c2, p26, p8, p7, p6, p5); |
12104404 | 0:96d6eb224379 | 16 | LOCALIZE_xya xya; |
12104404 | 15:7729da55873a | 17 | LOCOMOTION motion(p21, p22, p23, p24, p15, p16); |
12104404 | 6:0602a9e8118b | 18 | |
12104404 | 6:0602a9e8118b | 19 | Ticker t; |
12104404 | 17:2f89826b5679 | 20 | Ticker tTarget; |
12104404 | 6:0602a9e8118b | 21 | bool flag=false; |
12104404 | 17:2f89826b5679 | 22 | int target=20; |
12104404 | 17:2f89826b5679 | 23 | int angle_error=2; |
12104404 | 17:2f89826b5679 | 24 | bool xGood=false; |
12104404 | 18:f9012e93edb8 | 25 | int angleTarget=0; |
12104404 | 6:0602a9e8118b | 26 | |
12104404 | 17:2f89826b5679 | 27 | void setTarget(); |
12104404 | 6:0602a9e8118b | 28 | void send(); |
12104404 | 15:7729da55873a | 29 | //void setAngle(int angle); |
12104404 | 10:cf44f4387bc7 | 30 | int wrap(int a); |
12104404 | 6:0602a9e8118b | 31 | |
12104404 | 0:96d6eb224379 | 32 | int main() |
12104404 | 0:96d6eb224379 | 33 | { |
12104404 | 6:0602a9e8118b | 34 | wdt.kick(5); |
12104404 | 0:96d6eb224379 | 35 | pc.baud(9600); |
12104404 | 6:0602a9e8118b | 36 | //pc.printf("Initialized Localization: %d\n",loc.init()); |
12104404 | 8:b36be08c44f8 | 37 | t.attach(&send,1); |
12104404 | 18:f9012e93edb8 | 38 | //tTarget.attach(&setTarget,7); |
12104404 | 0:96d6eb224379 | 39 | while(1) { |
12104404 | 7:d6dca30f7959 | 40 | //loc.get_angle(&xya); |
12104404 | 8:b36be08c44f8 | 41 | loc.get_xy(&xya); |
12104404 | 18:f9012e93edb8 | 42 | if(motion.setAngle(angleTarget,xya.a,angle_error,ANGLE_TURN)) { |
12104404 | 18:f9012e93edb8 | 43 | xGood = motion.setXPos(target,xya.x,2,angleTarget); |
12104404 | 18:f9012e93edb8 | 44 | if(motion.setYPos(130,xya.y,2,angleTarget)) { |
12104404 | 17:2f89826b5679 | 45 | angle_error=2; |
12104404 | 18:f9012e93edb8 | 46 | } else if(xGood) { |
12104404 | 18:f9012e93edb8 | 47 | target=target==20?80:20; |
12104404 | 18:f9012e93edb8 | 48 | angleTarget=angleTarget==0?180:0; |
12104404 | 18:f9012e93edb8 | 49 | angle_error=2; |
12104404 | 18:f9012e93edb8 | 50 | } else |
12104404 | 17:2f89826b5679 | 51 | angle_error=10; |
12104404 | 17:2f89826b5679 | 52 | } |
12104404 | 8:b36be08c44f8 | 53 | //pc.printf("X: %3d\tY: %3d\tP: %3d\n",xya.x,xya.y,xya.a); |
12104404 | 6:0602a9e8118b | 54 | wdt.kick(); |
12104404 | 0:96d6eb224379 | 55 | } |
12104404 | 0:96d6eb224379 | 56 | } |
12104404 | 6:0602a9e8118b | 57 | |
12104404 | 6:0602a9e8118b | 58 | void send() |
12104404 | 6:0602a9e8118b | 59 | { |
12104404 | 8:b36be08c44f8 | 60 | pc.printf("%c%c%c%c\n",(char)xya.x,(char)xya.y,xya.a/10,xya.a%10); |
12104404 | 6:0602a9e8118b | 61 | } |
12104404 | 17:2f89826b5679 | 62 | |
12104404 | 17:2f89826b5679 | 63 | void setTarget() |
12104404 | 6:0602a9e8118b | 64 | { |
12104404 | 17:2f89826b5679 | 65 | target=target==20?80:20; |
12104404 | 17:2f89826b5679 | 66 | } |