Time is good

Dependencies:   RoboClaw mbed

Fork of Robot2016_2-0 by ARES

Committer:
IceTeam
Date:
Fri May 06 15:25:21 2016 +0000
Revision:
92:f09f55aa992b
Parent:
91:65fb6b9f3932
Child:
93:c0b040954eac
Rajout de ControlleurPince & StepperMotor;

Who changed what in which revision?

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