DERPS

Dependencies:   BMP280 BNO055_fusion PowerControl mbed

Fork of STRAIGHT_DRIVE_NO_SEP by Antoine Laurens

Committer:
12104404
Date:
Tue Mar 29 01:11:09 2016 +0000
Revision:
17:2f89826b5679
Parent:
16:d6f15a13c3aa
Child:
18:f9012e93edb8
working

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