uhbduhbv

Dependencies:   BNO055_fusion mbed

Fork of DEMO3 by Edwin Cho

Committer:
alaurens
Date:
Tue Mar 29 21:58:26 2016 +0000
Revision:
19:5832e34b7533
Parent:
18:f9012e93edb8
everything is beautiful

Who changed what in which revision?

UserRevisionLine numberNew 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;
alaurens 19:5832e34b7533 25 bool yGood=false;
alaurens 19:5832e34b7533 26 bool angleGood=false;
alaurens 19:5832e34b7533 27
12104404 18:f9012e93edb8 28 int angleTarget=0;
alaurens 19:5832e34b7533 29 int yTarget=30;
12104404 17:2f89826b5679 30 void setTarget();
12104404 6:0602a9e8118b 31 void send();
12104404 15:7729da55873a 32 //void setAngle(int angle);
12104404 10:cf44f4387bc7 33 int wrap(int a);
12104404 6:0602a9e8118b 34
12104404 0:96d6eb224379 35 int main()
12104404 0:96d6eb224379 36 {
12104404 6:0602a9e8118b 37 wdt.kick(5);
12104404 0:96d6eb224379 38 pc.baud(9600);
12104404 6:0602a9e8118b 39 //pc.printf("Initialized Localization: %d\n",loc.init());
12104404 8:b36be08c44f8 40 t.attach(&send,1);
12104404 18:f9012e93edb8 41 //tTarget.attach(&setTarget,7);
12104404 0:96d6eb224379 42 while(1) {
12104404 7:d6dca30f7959 43 //loc.get_angle(&xya);
12104404 8:b36be08c44f8 44 loc.get_xy(&xya);
alaurens 19:5832e34b7533 45 motion.check_xya(&xGood,&yGood,&angleGood,target,angleTarget,yTarget,angle_error)
12104404 18:f9012e93edb8 46 if(motion.setAngle(angleTarget,xya.a,angle_error,ANGLE_TURN)) {
12104404 18:f9012e93edb8 47 xGood = motion.setXPos(target,xya.x,2,angleTarget);
12104404 18:f9012e93edb8 48 if(motion.setYPos(130,xya.y,2,angleTarget)) {
12104404 17:2f89826b5679 49 angle_error=2;
12104404 18:f9012e93edb8 50 } else if(xGood) {
12104404 18:f9012e93edb8 51 target=target==20?80:20;
12104404 18:f9012e93edb8 52 angleTarget=angleTarget==0?180:0;
12104404 18:f9012e93edb8 53 angle_error=2;
12104404 18:f9012e93edb8 54 } else
12104404 17:2f89826b5679 55 angle_error=10;
12104404 17:2f89826b5679 56 }
12104404 8:b36be08c44f8 57 //pc.printf("X: %3d\tY: %3d\tP: %3d\n",xya.x,xya.y,xya.a);
12104404 6:0602a9e8118b 58 wdt.kick();
12104404 0:96d6eb224379 59 }
12104404 0:96d6eb224379 60 }
12104404 6:0602a9e8118b 61
12104404 6:0602a9e8118b 62 void send()
12104404 6:0602a9e8118b 63 {
12104404 8:b36be08c44f8 64 pc.printf("%c%c%c%c\n",(char)xya.x,(char)xya.y,xya.a/10,xya.a%10);
12104404 6:0602a9e8118b 65 }
12104404 17:2f89826b5679 66
12104404 17:2f89826b5679 67 void setTarget()
12104404 6:0602a9e8118b 68 {
12104404 17:2f89826b5679 69 target=target==20?80:20;
12104404 17:2f89826b5679 70 }