Time is good

Dependencies:   RoboClaw mbed

Fork of Robot2016_2-0 by ARES

Committer:
IceTeam
Date:
Thu May 05 16:01:55 2016 +0000
Revision:
80:cd4960dfa47e
Parent:
79:b11b50108ae5
Child:
81:e7b03e81b025
Yo !;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IceTeam 79:b11b50108ae5 1 #include "RoboClaw/RoboClaw.h"
IceTeam 79:b11b50108ae5 2 #include "mbed.h"
sype 41:b5a2fbc20beb 3
IceTeam 79:b11b50108ae5 4 #define ADR 0x80
IceTeam 79:b11b50108ae5 5 #define accel_angle 12000
IceTeam 79:b11b50108ae5 6 #define vitesse_angle 10000
IceTeam 79:b11b50108ae5 7 #define deccel_angle 12000
sype 41:b5a2fbc20beb 8
IceTeam 79:b11b50108ae5 9 #define accel_dista 12000
IceTeam 79:b11b50108ae5 10 #define vitesse_dista 12000
IceTeam 79:b11b50108ae5 11 #define deccel_dista 12000
sype 41:b5a2fbc20beb 12
IceTeam 80:cd4960dfa47e 13 void Sharps();
IceTeam 80:cd4960dfa47e 14 BusOut drapeau (PC_8, PC_6, PC_5);
IceTeam 80:cd4960dfa47e 15
sype 46:5658af4e5149 16 RoboClaw roboclaw(ADR, 460800, PA_11, PA_12);
IceTeam 80:cd4960dfa47e 17 AnalogIn Rcapt1(PA_4);
IceTeam 80:cd4960dfa47e 18 int RvalRcapt1 = 0;
IceTeam 80:cd4960dfa47e 19 AnalogIn Rcapt2(PB_0);
IceTeam 80:cd4960dfa47e 20 int RvalRcapt2 = 0;
IceTeam 80:cd4960dfa47e 21 AnalogIn Rcapt3(PC_1);
IceTeam 80:cd4960dfa47e 22 int RvalRcapt3 = 0;
sype 0:ad9600df4a70 23
IceTeam 80:cd4960dfa47e 24 int Ravance = 1;
IceTeam 80:cd4960dfa47e 25 #define R_SEUIL_SHARP 0.3
IceTeam 80:cd4960dfa47e 26
IceTeam 80:cd4960dfa47e 27 void GotoDist(float timer) {
IceTeam 80:cd4960dfa47e 28 Timer t;
IceTeam 80:cd4960dfa47e 29 t.reset();
IceTeam 80:cd4960dfa47e 30 roboclaw.SpeedAccelM1M2(accel_dista, vitesse_dista, vitesse_dista);
IceTeam 80:cd4960dfa47e 31 t.start();
IceTeam 80:cd4960dfa47e 32
IceTeam 80:cd4960dfa47e 33 while (t.read() < timer) {
IceTeam 80:cd4960dfa47e 34 if (Ravance != 1) {
IceTeam 80:cd4960dfa47e 35 roboclaw.ForwardM1(0);
IceTeam 80:cd4960dfa47e 36 roboclaw.ForwardM2(0);
IceTeam 80:cd4960dfa47e 37 t.stop();
IceTeam 80:cd4960dfa47e 38 while (Ravance != 1);
IceTeam 80:cd4960dfa47e 39 t.start();
IceTeam 80:cd4960dfa47e 40 }
IceTeam 80:cd4960dfa47e 41 }
IceTeam 80:cd4960dfa47e 42
IceTeam 80:cd4960dfa47e 43 roboclaw.ForwardM1(0);
IceTeam 80:cd4960dfa47e 44 roboclaw.ForwardM2(0);
IceTeam 80:cd4960dfa47e 45 t.stop();
IceTeam 80:cd4960dfa47e 46 t.reset();
IceTeam 80:cd4960dfa47e 47 }
IceTeam 80:cd4960dfa47e 48
IceTeam 80:cd4960dfa47e 49 void GotoThet (float timer) {
IceTeam 80:cd4960dfa47e 50 Timer t;
IceTeam 80:cd4960dfa47e 51 t.reset();
IceTeam 80:cd4960dfa47e 52 t.start();
IceTeam 80:cd4960dfa47e 53 roboclaw.SpeedAccelM1M2(accel_dista, vitesse_dista, -vitesse_dista);
IceTeam 80:cd4960dfa47e 54
IceTeam 80:cd4960dfa47e 55 while (t.read() < timer) {
IceTeam 80:cd4960dfa47e 56 if (Ravance != 1) {
IceTeam 80:cd4960dfa47e 57 roboclaw.ForwardM1(0);
IceTeam 80:cd4960dfa47e 58 roboclaw.ForwardM2(0);
IceTeam 80:cd4960dfa47e 59 t.stop();
IceTeam 80:cd4960dfa47e 60 while (Ravance != 1);
IceTeam 80:cd4960dfa47e 61 t.start();
IceTeam 80:cd4960dfa47e 62 }
IceTeam 80:cd4960dfa47e 63 }
IceTeam 80:cd4960dfa47e 64
IceTeam 80:cd4960dfa47e 65 roboclaw.ForwardM1(0);
IceTeam 80:cd4960dfa47e 66 roboclaw.ForwardM2(0);
IceTeam 80:cd4960dfa47e 67
IceTeam 80:cd4960dfa47e 68 t.stop();
IceTeam 80:cd4960dfa47e 69 t.reset();
IceTeam 80:cd4960dfa47e 70 }
sype 43:d5aaff7d2bec 71 /* Debut du programme */
sype 0:ad9600df4a70 72 int main(void)
sype 10:ae3178aa94e9 73 {
IceTeam 80:cd4960dfa47e 74 Ticker ticker;
IceTeam 80:cd4960dfa47e 75 ticker.attach(&Sharps, 0.01);
IceTeam 80:cd4960dfa47e 76
IceTeam 80:cd4960dfa47e 77 GotoDist(7);
IceTeam 80:cd4960dfa47e 78 GotoThet(7);
IceTeam 80:cd4960dfa47e 79
sype 77:f19cc7f81f2a 80 while(1);
sype 2:abdf8c6823a1 81 }
IceTeam 80:cd4960dfa47e 82
IceTeam 80:cd4960dfa47e 83 void Sharps() {
IceTeam 80:cd4960dfa47e 84 if (Rcapt1.read() > R_SEUIL_SHARP) RvalRcapt1++;
IceTeam 80:cd4960dfa47e 85 else RvalRcapt1--;
IceTeam 80:cd4960dfa47e 86 RvalRcapt1 = RvalRcapt1 > 10 ? 10 : RvalRcapt1;
IceTeam 80:cd4960dfa47e 87 RvalRcapt1 = RvalRcapt1 < 0 ? 0 : RvalRcapt1;
IceTeam 80:cd4960dfa47e 88
IceTeam 80:cd4960dfa47e 89 if (Rcapt2.read() > R_SEUIL_SHARP) RvalRcapt2++;
IceTeam 80:cd4960dfa47e 90 else RvalRcapt2--;
IceTeam 80:cd4960dfa47e 91 RvalRcapt2 = RvalRcapt2 > 10 ? 10 : RvalRcapt2;
IceTeam 80:cd4960dfa47e 92 RvalRcapt2 = RvalRcapt2 < 0 ? 0 : RvalRcapt2;
IceTeam 80:cd4960dfa47e 93
IceTeam 80:cd4960dfa47e 94 if (Rcapt3.read() > R_SEUIL_SHARP) RvalRcapt3++;
IceTeam 80:cd4960dfa47e 95 else RvalRcapt3--;
IceTeam 80:cd4960dfa47e 96 RvalRcapt3 = RvalRcapt3 > 10 ? 10 : RvalRcapt3;
IceTeam 80:cd4960dfa47e 97 RvalRcapt3 = RvalRcapt3 < 0 ? 0 : RvalRcapt3;
IceTeam 80:cd4960dfa47e 98
IceTeam 80:cd4960dfa47e 99 if (RvalRcapt1 >= 5 || RvalRcapt2 >= 5 || RvalRcapt3 >= 5)
IceTeam 80:cd4960dfa47e 100 Ravance = 0;
IceTeam 80:cd4960dfa47e 101 else
IceTeam 80:cd4960dfa47e 102 Ravance = 1;
IceTeam 80:cd4960dfa47e 103
IceTeam 80:cd4960dfa47e 104 if (Ravance == 0)
IceTeam 80:cd4960dfa47e 105 drapeau = 1;
IceTeam 80:cd4960dfa47e 106 else
IceTeam 80:cd4960dfa47e 107 drapeau = 2;
IceTeam 80:cd4960dfa47e 108 }