uhbduhbv

Dependencies:   BNO055_fusion mbed

Fork of DEMO3 by Edwin Cho

Committer:
12104404
Date:
Thu Mar 24 07:20:51 2016 +0000
Revision:
15:7729da55873a
Parent:
14:4839989ae907
Child:
16:d6f15a13c3aa
how to combine x y control

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 15:7729da55873a 15 LOCALIZE loc(i2c1, i2c2, p26, p20, p19, p18, p17);
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 6:0602a9e8118b 20 bool flag=false;
12104404 6:0602a9e8118b 21
12104404 6:0602a9e8118b 22 void send();
12104404 15:7729da55873a 23 //void setAngle(int angle);
12104404 10:cf44f4387bc7 24 int wrap(int a);
12104404 6:0602a9e8118b 25
12104404 0:96d6eb224379 26 int main()
12104404 0:96d6eb224379 27 {
12104404 6:0602a9e8118b 28 wdt.kick(5);
12104404 0:96d6eb224379 29 pc.baud(9600);
12104404 6:0602a9e8118b 30 //pc.printf("Initialized Localization: %d\n",loc.init());
12104404 8:b36be08c44f8 31 t.attach(&send,1);
12104404 0:96d6eb224379 32 while(1) {
12104404 15:7729da55873a 33 motion.setAngle(0,0,5,ANGLE_TURN);
12104404 7:d6dca30f7959 34 //loc.get_angle(&xya);
12104404 8:b36be08c44f8 35 loc.get_xy(&xya);
12104404 8:b36be08c44f8 36 //pc.printf("X: %3d\tY: %3d\tP: %3d\n",xya.x,xya.y,xya.a);
12104404 15:7729da55873a 37 //setAngle(0);
12104404 6:0602a9e8118b 38 wdt.kick();
12104404 0:96d6eb224379 39 }
12104404 0:96d6eb224379 40 }
12104404 6:0602a9e8118b 41
12104404 6:0602a9e8118b 42 void send()
12104404 6:0602a9e8118b 43 {
12104404 8:b36be08c44f8 44 pc.printf("%c%c%c%c\n",(char)xya.x,(char)xya.y,xya.a/10,xya.a%10);
12104404 6:0602a9e8118b 45 }
12104404 15:7729da55873a 46 /*
12104404 10:cf44f4387bc7 47 void setAngle(int angle)
12104404 6:0602a9e8118b 48 {
12104404 6:0602a9e8118b 49 float s = 0;
12104404 10:cf44f4387bc7 50 int diff = 0;
12104404 10:cf44f4387bc7 51 diff = 180-wrap(angle);
12104404 11:9518f8285906 52 if(abs(wrap(xya.a+diff)-180)<=5)
12104404 10:cf44f4387bc7 53 s=SPEED_TURN_MIN;
12104404 10:cf44f4387bc7 54 else
12104404 12:3b26fcc7da7e 55 s=((SPEED_TURN_MAX-SPEED_TURN_MIN)*abs(wrap(xya.a+diff)-180)/180)+SPEED_TURN_MIN;
12104404 10:cf44f4387bc7 56 motor1F=s;
12104404 10:cf44f4387bc7 57 motor1B=s;
12104404 10:cf44f4387bc7 58 motor2F=s;
12104404 10:cf44f4387bc7 59 motor2B=s;
12104404 10:cf44f4387bc7 60 if(wrap(xya.a+diff)>180+2) {
12104404 10:cf44f4387bc7 61 dir1=1;
12104404 10:cf44f4387bc7 62 dir2=0;
12104404 10:cf44f4387bc7 63 } else if(wrap(xya.a+diff)<180-2) {
12104404 10:cf44f4387bc7 64 dir1=0;
12104404 10:cf44f4387bc7 65 dir2=1;
12104404 10:cf44f4387bc7 66 } else {
12104404 10:cf44f4387bc7 67 motor1F=0;
12104404 10:cf44f4387bc7 68 motor1B=0;
12104404 10:cf44f4387bc7 69 motor2F=0;
12104404 10:cf44f4387bc7 70 motor2B=0;
12104404 6:0602a9e8118b 71 }
12104404 15:7729da55873a 72 }*/
12104404 10:cf44f4387bc7 73
12104404 10:cf44f4387bc7 74 int wrap(int a)
12104404 10:cf44f4387bc7 75 {
12104404 10:cf44f4387bc7 76 return a%360;
12104404 10:cf44f4387bc7 77 }