Time is good

Dependencies:   RoboClaw mbed

Fork of Robot2016_2-0 by ARES

Committer:
IceTeam
Date:
Fri May 06 15:18:09 2016 +0000
Revision:
95:adb71eafef57
Parent:
91:65fb6b9f3932
Petit bug fix dans le temps du dernier GotoDist;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IceTeam 81:e7b03e81b025 1 #include "entete.h"
IceTeam 85:38cbf5fd22e1 2 #include "AX12/AX12.h"
sype 41:b5a2fbc20beb 3
IceTeam 83:714fa414b2bf 4 DigitalIn CAMP(PA_15);
IceTeam 83:714fa414b2bf 5 DigitalIn START(PB_7);
IceTeam 83:714fa414b2bf 6 DigitalOut LEDR(PC_2);
IceTeam 83:714fa414b2bf 7 DigitalOut LEDV(PC_3);
IceTeam 84:b54822c913b0 8 DigitalIn button(USER_BUTTON);
IceTeam 83:714fa414b2bf 9 int SCouleur = VERT;
IceTeam 83:714fa414b2bf 10
IceTeam 80:cd4960dfa47e 11 BusOut drapeau (PC_8, PC_6, PC_5);
sype 46:5658af4e5149 12 RoboClaw roboclaw(ADR, 460800, PA_11, PA_12);
IceTeam 80:cd4960dfa47e 13 AnalogIn Rcapt1(PA_4);
IceTeam 80:cd4960dfa47e 14 int RvalRcapt1 = 0;
IceTeam 80:cd4960dfa47e 15 AnalogIn Rcapt2(PB_0);
IceTeam 80:cd4960dfa47e 16 int RvalRcapt2 = 0;
IceTeam 80:cd4960dfa47e 17 AnalogIn Rcapt3(PC_1);
IceTeam 80:cd4960dfa47e 18 int RvalRcapt3 = 0;
IceTeam 80:cd4960dfa47e 19 int Ravance = 1;
IceTeam 81:e7b03e81b025 20 DigitalIn start(PB_7);
IceTeam 88:e4de39dd3e2e 21 AX12 umbrella(PA_9, PA_10, 2, 250000);
IceTeam 90:78d2c1527c95 22 float R_SEUIL_SHARP = 1;
IceTeam 80:cd4960dfa47e 23
sype 43:d5aaff7d2bec 24 /* Debut du programme */
sype 0:ad9600df4a70 25 int main(void)
sype 10:ae3178aa94e9 26 {
IceTeam 91:65fb6b9f3932 27 roboclaw.ForwardM1(0);
IceTeam 91:65fb6b9f3932 28 roboclaw.ForwardM2(0);
IceTeam 80:cd4960dfa47e 29 Ticker ticker;
IceTeam 86:0c5e9ac3d8d8 30 Timeout end;
IceTeam 80:cd4960dfa47e 31 ticker.attach(&Sharps, 0.01);
IceTeam 86:0c5e9ac3d8d8 32
IceTeam 85:38cbf5fd22e1 33 umbrella.setMode(0);
IceTeam 85:38cbf5fd22e1 34 umbrella.setMaxTorque(200);
IceTeam 86:0c5e9ac3d8d8 35 umbrella.setGoal(150);
IceTeam 88:e4de39dd3e2e 36 wait(1);
IceTeam 90:78d2c1527c95 37 umbrella.setGoal(160);
IceTeam 88:e4de39dd3e2e 38 wait(1);
IceTeam 90:78d2c1527c95 39 umbrella.setGoal(150);
IceTeam 90:78d2c1527c95 40 wait(1);
IceTeam 90:78d2c1527c95 41 umbrella.setMaxTorque(0);
IceTeam 88:e4de39dd3e2e 42
IceTeam 91:65fb6b9f3932 43 while(START == 1)
IceTeam 91:65fb6b9f3932 44 {
IceTeam 91:65fb6b9f3932 45 LEDR = 1;
IceTeam 91:65fb6b9f3932 46 LEDV = 1;
IceTeam 91:65fb6b9f3932 47 wait(0.5);
IceTeam 91:65fb6b9f3932 48 LEDR = 0;
IceTeam 91:65fb6b9f3932 49 LEDV = 0;
IceTeam 91:65fb6b9f3932 50 wait(0.5);
IceTeam 91:65fb6b9f3932 51 }
IceTeam 91:65fb6b9f3932 52
IceTeam 91:65fb6b9f3932 53 wait(1);
IceTeam 83:714fa414b2bf 54 depart();
IceTeam 91:65fb6b9f3932 55
IceTeam 83:714fa414b2bf 56 if (SCouleur == VERT) {
IceTeam 91:65fb6b9f3932 57 end.attach(&endFonc, 90);
IceTeam 90:78d2c1527c95 58 GotoDist(9.0);
IceTeam 90:78d2c1527c95 59 GotoArr(9.2);
IceTeam 90:78d2c1527c95 60 R_SEUIL_SHARP = 0.25;
IceTeam 90:78d2c1527c95 61 GotoDist(2.5);
IceTeam 91:65fb6b9f3932 62 GotoThet(-3.04);
IceTeam 91:65fb6b9f3932 63 R_SEUIL_SHARP = 0.35;
IceTeam 91:65fb6b9f3932 64 GotoDist(5.5);
IceTeam 90:78d2c1527c95 65 R_SEUIL_SHARP = 1;
IceTeam 91:65fb6b9f3932 66 GotoDist(4.5);
IceTeam 91:65fb6b9f3932 67 GotoArr(3);
IceTeam 91:65fb6b9f3932 68 R_SEUIL_SHARP = 0.35;
IceTeam 91:65fb6b9f3932 69 GotoThet(3.04);
IceTeam 90:78d2c1527c95 70 GotoDist(3.5);
IceTeam 91:65fb6b9f3932 71 GotoThet(-3.04);
IceTeam 91:65fb6b9f3932 72 R_SEUIL_SHARP = 1;
IceTeam 95:adb71eafef57 73 GotoDist(4.5);
IceTeam 83:714fa414b2bf 74 }
IceTeam 86:0c5e9ac3d8d8 75 else if (SCouleur == VIOLET) {
IceTeam 91:65fb6b9f3932 76 end.attach(&endFonc, 90);
IceTeam 90:78d2c1527c95 77 GotoDist(9.0);
IceTeam 90:78d2c1527c95 78 GotoArr(9.2);
IceTeam 90:78d2c1527c95 79 R_SEUIL_SHARP = 0.25;
IceTeam 90:78d2c1527c95 80 GotoDist(2.5);
IceTeam 91:65fb6b9f3932 81 GotoThet(3.04);
IceTeam 91:65fb6b9f3932 82 R_SEUIL_SHARP = 0.35;
IceTeam 91:65fb6b9f3932 83 GotoDist(5.5);
IceTeam 90:78d2c1527c95 84 R_SEUIL_SHARP = 1;
IceTeam 91:65fb6b9f3932 85 GotoDist(4.5);
IceTeam 91:65fb6b9f3932 86 GotoArr(4);
IceTeam 91:65fb6b9f3932 87 R_SEUIL_SHARP = 0.35;
IceTeam 91:65fb6b9f3932 88 GotoThet(-3.04);
IceTeam 90:78d2c1527c95 89 GotoDist(3.5);
IceTeam 91:65fb6b9f3932 90 GotoThet(3.04);
IceTeam 91:65fb6b9f3932 91 R_SEUIL_SHARP = 1;
IceTeam 95:adb71eafef57 92 GotoDist(4.5);
IceTeam 83:714fa414b2bf 93 }
IceTeam 88:e4de39dd3e2e 94 else if (SCouleur == NOIR) {
IceTeam 84:b54822c913b0 95 TestDist3(2,2);
IceTeam 84:b54822c913b0 96 TestThet3(1,1);
IceTeam 83:714fa414b2bf 97 }
IceTeam 83:714fa414b2bf 98
sype 77:f19cc7f81f2a 99 while(1);
sype 2:abdf8c6823a1 100 }
IceTeam 80:cd4960dfa47e 101
IceTeam 80:cd4960dfa47e 102 void Sharps() {
IceTeam 80:cd4960dfa47e 103 if (Rcapt1.read() > R_SEUIL_SHARP) RvalRcapt1++;
IceTeam 80:cd4960dfa47e 104 else RvalRcapt1--;
IceTeam 80:cd4960dfa47e 105 RvalRcapt1 = RvalRcapt1 > 10 ? 10 : RvalRcapt1;
IceTeam 80:cd4960dfa47e 106 RvalRcapt1 = RvalRcapt1 < 0 ? 0 : RvalRcapt1;
IceTeam 80:cd4960dfa47e 107
IceTeam 80:cd4960dfa47e 108 if (Rcapt2.read() > R_SEUIL_SHARP) RvalRcapt2++;
IceTeam 80:cd4960dfa47e 109 else RvalRcapt2--;
IceTeam 80:cd4960dfa47e 110 RvalRcapt2 = RvalRcapt2 > 10 ? 10 : RvalRcapt2;
IceTeam 80:cd4960dfa47e 111 RvalRcapt2 = RvalRcapt2 < 0 ? 0 : RvalRcapt2;
IceTeam 80:cd4960dfa47e 112
IceTeam 80:cd4960dfa47e 113 if (Rcapt3.read() > R_SEUIL_SHARP) RvalRcapt3++;
IceTeam 80:cd4960dfa47e 114 else RvalRcapt3--;
IceTeam 80:cd4960dfa47e 115 RvalRcapt3 = RvalRcapt3 > 10 ? 10 : RvalRcapt3;
IceTeam 80:cd4960dfa47e 116 RvalRcapt3 = RvalRcapt3 < 0 ? 0 : RvalRcapt3;
IceTeam 80:cd4960dfa47e 117
IceTeam 90:78d2c1527c95 118 if ((RvalRcapt1 >= 5 || RvalRcapt2 >= 5 || RvalRcapt3 >= 5))
IceTeam 80:cd4960dfa47e 119 Ravance = 0;
IceTeam 80:cd4960dfa47e 120 else
IceTeam 80:cd4960dfa47e 121 Ravance = 1;
IceTeam 80:cd4960dfa47e 122
IceTeam 80:cd4960dfa47e 123 if (Ravance == 0)
IceTeam 80:cd4960dfa47e 124 drapeau = 1;
IceTeam 80:cd4960dfa47e 125 else
IceTeam 80:cd4960dfa47e 126 drapeau = 2;
IceTeam 81:e7b03e81b025 127 }
IceTeam 81:e7b03e81b025 128
IceTeam 86:0c5e9ac3d8d8 129 void endFonc () {
IceTeam 88:e4de39dd3e2e 130 roboclaw.ForwardM1(0);
IceTeam 88:e4de39dd3e2e 131 roboclaw.ForwardM2(0);
IceTeam 88:e4de39dd3e2e 132 wait(1);
IceTeam 90:78d2c1527c95 133 umbrella.setMaxTorque(400);
IceTeam 90:78d2c1527c95 134 wait(1);
IceTeam 88:e4de39dd3e2e 135 umbrella.setGoal(300);
IceTeam 88:e4de39dd3e2e 136 while(1);
IceTeam 81:e7b03e81b025 137 }