Time is good

Dependencies:   RoboClaw mbed

Fork of Robot2016_2-0 by ARES

Committer:
IceTeam
Date:
Fri May 06 07:08:44 2016 +0000
Revision:
82:07e13071dd7b
Parent:
81:e7b03e81b025
Child:
83:714fa414b2bf
Maj;

Who changed what in which revision?

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