Romain Ame
/
Timer71pt
Fork de Timer après le match à 61 points
Fork of Timer by
main.cpp@84:b54822c913b0, 2016-05-06 (annotated)
- Committer:
- IceTeam
- Date:
- Fri May 06 07:43:02 2016 +0000
- Revision:
- 84:b54822c913b0
- Parent:
- 83:714fa414b2bf
- Child:
- 85:38cbf5fd22e1
Plateforme test Ok ! Choix des couleurs Ok ! et testey
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IceTeam | 81:e7b03e81b025 | 1 | #include "entete.h" |
sype | 41:b5a2fbc20beb | 2 | |
IceTeam | 83:714fa414b2bf | 3 | DigitalIn CAMP(PA_15); |
IceTeam | 83:714fa414b2bf | 4 | DigitalIn START(PB_7); |
IceTeam | 83:714fa414b2bf | 5 | DigitalOut LEDR(PC_2); |
IceTeam | 83:714fa414b2bf | 6 | DigitalOut LEDV(PC_3); |
IceTeam | 84:b54822c913b0 | 7 | DigitalIn button(USER_BUTTON); |
IceTeam | 83:714fa414b2bf | 8 | int SCouleur = VERT; |
IceTeam | 83:714fa414b2bf | 9 | |
IceTeam | 80:cd4960dfa47e | 10 | BusOut drapeau (PC_8, PC_6, PC_5); |
sype | 46:5658af4e5149 | 11 | RoboClaw roboclaw(ADR, 460800, PA_11, PA_12); |
IceTeam | 80:cd4960dfa47e | 12 | AnalogIn Rcapt1(PA_4); |
IceTeam | 80:cd4960dfa47e | 13 | int RvalRcapt1 = 0; |
IceTeam | 80:cd4960dfa47e | 14 | AnalogIn Rcapt2(PB_0); |
IceTeam | 80:cd4960dfa47e | 15 | int RvalRcapt2 = 0; |
IceTeam | 80:cd4960dfa47e | 16 | AnalogIn Rcapt3(PC_1); |
IceTeam | 80:cd4960dfa47e | 17 | int RvalRcapt3 = 0; |
IceTeam | 80:cd4960dfa47e | 18 | int Ravance = 1; |
IceTeam | 81:e7b03e81b025 | 19 | DigitalIn start(PB_7); |
IceTeam | 80:cd4960dfa47e | 20 | |
sype | 43:d5aaff7d2bec | 21 | /* Debut du programme */ |
sype | 0:ad9600df4a70 | 22 | int main(void) |
sype | 10:ae3178aa94e9 | 23 | { |
IceTeam | 80:cd4960dfa47e | 24 | Ticker ticker; |
IceTeam | 80:cd4960dfa47e | 25 | ticker.attach(&Sharps, 0.01); |
IceTeam | 83:714fa414b2bf | 26 | depart(); |
IceTeam | 83:714fa414b2bf | 27 | if (SCouleur == VERT) { |
IceTeam | 83:714fa414b2bf | 28 | GotoDist(5.5); |
IceTeam | 83:714fa414b2bf | 29 | } |
IceTeam | 83:714fa414b2bf | 30 | else if (SCouleur == VIOLET) { |
IceTeam | 83:714fa414b2bf | 31 | ; |
IceTeam | 83:714fa414b2bf | 32 | } |
IceTeam | 83:714fa414b2bf | 33 | else { |
IceTeam | 84:b54822c913b0 | 34 | TestDist3(2,2); |
IceTeam | 84:b54822c913b0 | 35 | TestThet3(1,1); |
IceTeam | 83:714fa414b2bf | 36 | } |
IceTeam | 83:714fa414b2bf | 37 | |
sype | 77:f19cc7f81f2a | 38 | while(1); |
sype | 2:abdf8c6823a1 | 39 | } |
IceTeam | 80:cd4960dfa47e | 40 | |
IceTeam | 80:cd4960dfa47e | 41 | void Sharps() { |
IceTeam | 80:cd4960dfa47e | 42 | if (Rcapt1.read() > R_SEUIL_SHARP) RvalRcapt1++; |
IceTeam | 80:cd4960dfa47e | 43 | else RvalRcapt1--; |
IceTeam | 80:cd4960dfa47e | 44 | RvalRcapt1 = RvalRcapt1 > 10 ? 10 : RvalRcapt1; |
IceTeam | 80:cd4960dfa47e | 45 | RvalRcapt1 = RvalRcapt1 < 0 ? 0 : RvalRcapt1; |
IceTeam | 80:cd4960dfa47e | 46 | |
IceTeam | 80:cd4960dfa47e | 47 | if (Rcapt2.read() > R_SEUIL_SHARP) RvalRcapt2++; |
IceTeam | 80:cd4960dfa47e | 48 | else RvalRcapt2--; |
IceTeam | 80:cd4960dfa47e | 49 | RvalRcapt2 = RvalRcapt2 > 10 ? 10 : RvalRcapt2; |
IceTeam | 80:cd4960dfa47e | 50 | RvalRcapt2 = RvalRcapt2 < 0 ? 0 : RvalRcapt2; |
IceTeam | 80:cd4960dfa47e | 51 | |
IceTeam | 80:cd4960dfa47e | 52 | if (Rcapt3.read() > R_SEUIL_SHARP) RvalRcapt3++; |
IceTeam | 80:cd4960dfa47e | 53 | else RvalRcapt3--; |
IceTeam | 80:cd4960dfa47e | 54 | RvalRcapt3 = RvalRcapt3 > 10 ? 10 : RvalRcapt3; |
IceTeam | 80:cd4960dfa47e | 55 | RvalRcapt3 = RvalRcapt3 < 0 ? 0 : RvalRcapt3; |
IceTeam | 80:cd4960dfa47e | 56 | |
IceTeam | 80:cd4960dfa47e | 57 | if (RvalRcapt1 >= 5 || RvalRcapt2 >= 5 || RvalRcapt3 >= 5) |
IceTeam | 80:cd4960dfa47e | 58 | Ravance = 0; |
IceTeam | 80:cd4960dfa47e | 59 | else |
IceTeam | 80:cd4960dfa47e | 60 | Ravance = 1; |
IceTeam | 80:cd4960dfa47e | 61 | |
IceTeam | 80:cd4960dfa47e | 62 | if (Ravance == 0) |
IceTeam | 80:cd4960dfa47e | 63 | drapeau = 1; |
IceTeam | 80:cd4960dfa47e | 64 | else |
IceTeam | 80:cd4960dfa47e | 65 | drapeau = 2; |
IceTeam | 81:e7b03e81b025 | 66 | } |
IceTeam | 81:e7b03e81b025 | 67 | |
IceTeam | 81:e7b03e81b025 | 68 | void GotoDist(float timer) { |
IceTeam | 81:e7b03e81b025 | 69 | Timer t; |
IceTeam | 81:e7b03e81b025 | 70 | |
IceTeam | 81:e7b03e81b025 | 71 | roboclaw.SpeedAccelM1(accel_dista, vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 72 | roboclaw.SpeedAccelM2(accel_dista, vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 73 | |
IceTeam | 81:e7b03e81b025 | 74 | t.reset(); |
IceTeam | 81:e7b03e81b025 | 75 | t.start(); |
IceTeam | 81:e7b03e81b025 | 76 | |
IceTeam | 81:e7b03e81b025 | 77 | while (t.read() < timer) { |
IceTeam | 81:e7b03e81b025 | 78 | if (Ravance != 1) { |
IceTeam | 81:e7b03e81b025 | 79 | roboclaw.ForwardM1(0); |
IceTeam | 81:e7b03e81b025 | 80 | roboclaw.ForwardM2(0); |
IceTeam | 81:e7b03e81b025 | 81 | t.stop(); |
IceTeam | 81:e7b03e81b025 | 82 | while (Ravance != 1); |
IceTeam | 81:e7b03e81b025 | 83 | roboclaw.SpeedAccelM1(accel_dista, vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 84 | roboclaw.SpeedAccelM2(accel_dista, vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 85 | t.start(); |
IceTeam | 81:e7b03e81b025 | 86 | } |
IceTeam | 81:e7b03e81b025 | 87 | } |
IceTeam | 81:e7b03e81b025 | 88 | |
IceTeam | 81:e7b03e81b025 | 89 | roboclaw.ForwardM1(0); |
IceTeam | 81:e7b03e81b025 | 90 | roboclaw.ForwardM2(0); |
IceTeam | 81:e7b03e81b025 | 91 | |
IceTeam | 81:e7b03e81b025 | 92 | t.stop(); |
IceTeam | 81:e7b03e81b025 | 93 | t.reset(); |
IceTeam | 81:e7b03e81b025 | 94 | |
IceTeam | 81:e7b03e81b025 | 95 | wait(waiting_time); |
IceTeam | 81:e7b03e81b025 | 96 | } |
IceTeam | 81:e7b03e81b025 | 97 | |
IceTeam | 81:e7b03e81b025 | 98 | void GotoThet (float timer, int signe) { |
IceTeam | 81:e7b03e81b025 | 99 | Timer t; |
IceTeam | 81:e7b03e81b025 | 100 | |
IceTeam | 81:e7b03e81b025 | 101 | if (signe < 0) { |
IceTeam | 81:e7b03e81b025 | 102 | roboclaw.SpeedAccelM1(accel_dista, vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 103 | roboclaw.SpeedAccelM2(-accel_dista, -vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 104 | } |
IceTeam | 81:e7b03e81b025 | 105 | else { |
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 | |
IceTeam | 81:e7b03e81b025 | 110 | t.reset(); |
IceTeam | 81:e7b03e81b025 | 111 | t.start(); |
IceTeam | 81:e7b03e81b025 | 112 | |
IceTeam | 81:e7b03e81b025 | 113 | while (t.read() < timer) { |
IceTeam | 81:e7b03e81b025 | 114 | if (Ravance != 1) { |
IceTeam | 81:e7b03e81b025 | 115 | roboclaw.ForwardM1(0); |
IceTeam | 81:e7b03e81b025 | 116 | roboclaw.ForwardM2(0); |
IceTeam | 81:e7b03e81b025 | 117 | t.stop(); |
IceTeam | 81:e7b03e81b025 | 118 | while (Ravance != 1); |
IceTeam | 81:e7b03e81b025 | 119 | t.start(); |
IceTeam | 81:e7b03e81b025 | 120 | } |
IceTeam | 81:e7b03e81b025 | 121 | if (signe < 0) { |
IceTeam | 81:e7b03e81b025 | 122 | roboclaw.SpeedAccelM1(accel_dista, vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 123 | roboclaw.SpeedAccelM2(-accel_dista, -vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 124 | } |
IceTeam | 81:e7b03e81b025 | 125 | else { |
IceTeam | 81:e7b03e81b025 | 126 | roboclaw.SpeedAccelM1(-accel_dista, -vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 127 | roboclaw.SpeedAccelM2(accel_dista, vitesse_dista); |
IceTeam | 81:e7b03e81b025 | 128 | } |
IceTeam | 81:e7b03e81b025 | 129 | } |
IceTeam | 81:e7b03e81b025 | 130 | |
IceTeam | 81:e7b03e81b025 | 131 | roboclaw.ForwardM1(0); |
IceTeam | 81:e7b03e81b025 | 132 | roboclaw.ForwardM2(0); |
IceTeam | 81:e7b03e81b025 | 133 | |
IceTeam | 81:e7b03e81b025 | 134 | t.stop(); |
IceTeam | 81:e7b03e81b025 | 135 | t.reset(); |
IceTeam | 81:e7b03e81b025 | 136 | |
IceTeam | 81:e7b03e81b025 | 137 | wait(waiting_time); |
IceTeam | 80:cd4960dfa47e | 138 | } |