Robot's source code
Dependencies: mbed
main.cpp@121:0cc17ba879cb, 2015-05-07 (annotated)
- Committer:
- sype
- Date:
- Thu May 07 14:13:58 2015 +0000
- Revision:
- 121:0cc17ba879cb
- Parent:
- 119:c45efcd706d9
- Child:
- 122:3d059ad76dd7
Asserv b 9/10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jagang | 0:41149573d577 | 1 | #include "mbed.h" |
Jagang | 39:09c04fd42c94 | 2 | |
Jagang | 39:09c04fd42c94 | 3 | #include "defines.h" |
Jagang | 39:09c04fd42c94 | 4 | |
Jagang | 0:41149573d577 | 5 | #include "QEI.h" |
Jagang | 23:228317fe0457 | 6 | #include "Map.h" |
Jagang | 109:53918ba98306 | 7 | |
Jagang | 109:53918ba98306 | 8 | #include "Objectif.h" |
Jagang | 109:53918ba98306 | 9 | #include "Obj_clap.h" |
Jagang | 117:f8c147141a0c | 10 | #include "Obj_pince.h" |
Jagang | 117:f8c147141a0c | 11 | #include "Obj_depot.h" |
Jagang | 109:53918ba98306 | 12 | |
Jagang | 109:53918ba98306 | 13 | |
Jagang | 39:09c04fd42c94 | 14 | #include "AX12.h" |
Jagang | 0:41149573d577 | 15 | |
Jagang | 71:95d76c181b22 | 16 | #ifdef PLAN_A |
Jagang | 71:95d76c181b22 | 17 | #include "Odometry.h" |
Jagang | 71:95d76c181b22 | 18 | #include "Asserv.h" |
Jagang | 71:95d76c181b22 | 19 | #else |
Jagang | 71:95d76c181b22 | 20 | #include "Odometry2.h" |
Jagang | 71:95d76c181b22 | 21 | #include "planB.h" |
Jagang | 71:95d76c181b22 | 22 | #endif |
Jagang | 71:95d76c181b22 | 23 | |
Near32 | 36:54f86bc6fd80 | 24 | #include "Motor.h" |
Jagang | 93:4d5664e9188a | 25 | |
Jagang | 93:4d5664e9188a | 26 | void update(); |
Jagang | 93:4d5664e9188a | 27 | |
Jagang | 93:4d5664e9188a | 28 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 29 | // Déclarations // |
Jagang | 93:4d5664e9188a | 30 | |
Jagang | 93:4d5664e9188a | 31 | // Decl. logger // |
Jagang | 93:4d5664e9188a | 32 | |
Jagang | 93:4d5664e9188a | 33 | Serial logger(OUT_TX, OUT_RX); // tx, rx |
Jagang | 93:4d5664e9188a | 34 | |
Jagang | 93:4d5664e9188a | 35 | // Decl. timer // |
Jagang | 93:4d5664e9188a | 36 | |
Jagang | 93:4d5664e9188a | 37 | Timer t; |
Jagang | 93:4d5664e9188a | 38 | Ticker ticker; |
Jagang | 93:4d5664e9188a | 39 | |
Jagang | 93:4d5664e9188a | 40 | // Decl. AX12 // |
Jagang | 93:4d5664e9188a | 41 | |
Jagang | 93:4d5664e9188a | 42 | AX12 ax12_pince(AX12_TX,AX12_RX,5,250000); |
Jagang | 93:4d5664e9188a | 43 | AX12 ax12_brasG(AX12_TX,AX12_RX,2,250000); |
Jagang | 93:4d5664e9188a | 44 | AX12 ax12_brasD(AX12_TX,AX12_RX,3,250000); |
Jagang | 93:4d5664e9188a | 45 | |
Jagang | 93:4d5664e9188a | 46 | // Decl. Moteurs // |
Jagang | 93:4d5664e9188a | 47 | |
Jagang | 93:4d5664e9188a | 48 | PwmOut pw1(PWM_MOT1); |
Jagang | 93:4d5664e9188a | 49 | DigitalOut dir1(DIR_MOT1); |
Jagang | 93:4d5664e9188a | 50 | PwmOut pw2(PWM_MOT2); |
Jagang | 93:4d5664e9188a | 51 | DigitalOut dir2(DIR_MOT2); |
Jagang | 93:4d5664e9188a | 52 | |
Jagang | 93:4d5664e9188a | 53 | Motor motorL(PWM_MOT1,DIR_MOT1); |
Jagang | 93:4d5664e9188a | 54 | Motor motorR(PWM_MOT2,DIR_MOT2); |
Jagang | 93:4d5664e9188a | 55 | |
Jagang | 93:4d5664e9188a | 56 | // Decl. Sharps // |
sype | 80:5399183aa39b | 57 | |
Jagang | 93:4d5664e9188a | 58 | AnalogIn sharp_devant(SHARP_D); |
Jagang | 93:4d5664e9188a | 59 | AnalogIn sharp_devant_droite(SHARP_DD); |
Jagang | 93:4d5664e9188a | 60 | AnalogIn sharp_devant_gauche(SHARP_DG); |
Jagang | 93:4d5664e9188a | 61 | AnalogIn sharp_arriere_gauche(SHARP_AG); |
Jagang | 93:4d5664e9188a | 62 | AnalogIn sharp_arriere_droite(SHARP_AD); |
Jagang | 93:4d5664e9188a | 63 | |
Jagang | 93:4d5664e9188a | 64 | // Decl. Boutons // |
Jagang | 93:4d5664e9188a | 65 | |
Jagang | 93:4d5664e9188a | 66 | DigitalIn bp(BP_DESSUS); |
Jagang | 93:4d5664e9188a | 67 | DigitalIn tirette(TIRETTE_DESSUS); |
Jagang | 93:4d5664e9188a | 68 | DigitalIn couleur(COULEUR_DESSUS); |
Jagang | 93:4d5664e9188a | 69 | |
Jagang | 93:4d5664e9188a | 70 | // Decl. Odometrie // |
Jagang | 21:5443f93819db | 71 | |
Jagang | 93:4d5664e9188a | 72 | #ifdef PLAN_A |
Jagang | 93:4d5664e9188a | 73 | QEI qei_right(PB_3,PA_10,NC,1024*4,QEI::X4_ENCODING); |
Jagang | 93:4d5664e9188a | 74 | QEI qei_left(PB_4,PB_5,NC,1024*4,QEI::X4_ENCODING); |
Jagang | 93:4d5664e9188a | 75 | |
Near32 | 107:a6e498b5706c | 76 | Odometry2 odometry(&qei_left,&qei_right,63.84/2.,63.65/2.,252); |
Jagang | 93:4d5664e9188a | 77 | #else |
Jagang | 93:4d5664e9188a | 78 | QEI qei_left(ODO_G_A,ODO_G_B,NC,1024*4,QEI::X4_ENCODING); |
Jagang | 93:4d5664e9188a | 79 | QEI qei_right(ODO_D_A,ODO_D_B,NC,1024*4,QEI::X4_ENCODING); |
Jagang | 93:4d5664e9188a | 80 | |
Jagang | 103:6a38cc0765f5 | 81 | Odometry2 odometry(&qei_left,&qei_right,63.84/2.,63.65/2.,252); |
Jagang | 93:4d5664e9188a | 82 | #endif |
Jagang | 93:4d5664e9188a | 83 | |
Jagang | 93:4d5664e9188a | 84 | // Decl. Asserv // |
Jagang | 93:4d5664e9188a | 85 | |
Jagang | 93:4d5664e9188a | 86 | #ifdef PLAN_A |
Jagang | 109:53918ba98306 | 87 | Asserv<float> asserv(&odometry); |
Jagang | 93:4d5664e9188a | 88 | #else |
Jagang | 93:4d5664e9188a | 89 | aserv_planB asserv(odometry,motorL,motorR); |
Jagang | 93:4d5664e9188a | 90 | #endif |
Jagang | 93:4d5664e9188a | 91 | |
Jagang | 109:53918ba98306 | 92 | // Decl. IA // |
Jagang | 109:53918ba98306 | 93 | |
Jagang | 109:53918ba98306 | 94 | Map terrain; |
Jagang | 109:53918ba98306 | 95 | std::vector<Objectif*> objectifs; |
Jagang | 109:53918ba98306 | 96 | char couleurRobot = COULEUR_JAUNE; |
Jagang | 109:53918ba98306 | 97 | |
Jagang | 93:4d5664e9188a | 98 | // Fin Decl. // |
Jagang | 93:4d5664e9188a | 99 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 100 | |
Jagang | 23:228317fe0457 | 101 | |
Jagang | 0:41149573d577 | 102 | int main() |
Jagang | 0:41149573d577 | 103 | { |
Jagang | 93:4d5664e9188a | 104 | #ifdef OUT_USB |
Jagang | 117:f8c147141a0c | 105 | logger.baud((int)921600); |
Jagang | 93:4d5664e9188a | 106 | #endif |
Jagang | 74:88be86f83d17 | 107 | |
Jagang | 93:4d5664e9188a | 108 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 109 | // Init // |
Near32 | 17:f360e21d3307 | 110 | |
Jagang | 93:4d5664e9188a | 111 | logger.printf("Initialisation............."); |
Jagang | 57:ab13f4e7a2b2 | 112 | |
Jagang | 93:4d5664e9188a | 113 | // Init. AX12 // |
Jagang | 39:09c04fd42c94 | 114 | |
Jagang | 93:4d5664e9188a | 115 | ax12_pince.setMode(0); |
Jagang | 93:4d5664e9188a | 116 | ax12_brasG.setMode(0); |
Jagang | 93:4d5664e9188a | 117 | ax12_brasD.setMode(0); |
Jagang | 54:e0e58c36658a | 118 | |
Jagang | 93:4d5664e9188a | 119 | // Init. Moteurs // |
Near32 | 24:3c0422e1ebd6 | 120 | |
Jagang | 93:4d5664e9188a | 121 | motorL.setSpeed(0); |
Jagang | 93:4d5664e9188a | 122 | motorR.setSpeed(0); |
Jagang | 93:4d5664e9188a | 123 | |
Jagang | 93:4d5664e9188a | 124 | // Init. Sharps // |
Jagang | 93:4d5664e9188a | 125 | |
Jagang | 93:4d5664e9188a | 126 | // Init. Boutons // |
Jagang | 93:4d5664e9188a | 127 | |
Jagang | 93:4d5664e9188a | 128 | // Init. Odometrie // |
Jagang | 93:4d5664e9188a | 129 | |
Jagang | 71:95d76c181b22 | 130 | #ifdef PLAN_A |
Jagang | 78:7c7cefbe1772 | 131 | odometry.setTheta(0); |
Jagang | 78:7c7cefbe1772 | 132 | odometry.setX(0); |
Jagang | 78:7c7cefbe1772 | 133 | odometry.setY(0); |
Jagang | 71:95d76c181b22 | 134 | #else |
Jagang | 71:95d76c181b22 | 135 | odometry.setTheta(PI/2); |
Jagang | 71:95d76c181b22 | 136 | odometry.setX(0); |
Jagang | 71:95d76c181b22 | 137 | odometry.setY(0); |
Jagang | 71:95d76c181b22 | 138 | #endif |
Jagang | 60:546d7b43333b | 139 | |
Jagang | 109:53918ba98306 | 140 | // Init. IA // |
Jagang | 109:53918ba98306 | 141 | |
Jagang | 109:53918ba98306 | 142 | terrain.build(); |
Jagang | 109:53918ba98306 | 143 | |
Jagang | 93:4d5664e9188a | 144 | logger.printf("[done]\r\n"); |
Jagang | 93:4d5664e9188a | 145 | |
Jagang | 93:4d5664e9188a | 146 | // Fin Init. // |
Jagang | 93:4d5664e9188a | 147 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 148 | |
Jagang | 93:4d5664e9188a | 149 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 150 | // MIP // |
Jagang | 93:4d5664e9188a | 151 | |
Jagang | 109:53918ba98306 | 152 | logger.printf("Appuyer sur le bouton pour mettre en position\r\n"); |
Jagang | 93:4d5664e9188a | 153 | |
Jagang | 93:4d5664e9188a | 154 | while(!bp); // On attend le top de mise en position |
Jagang | 93:4d5664e9188a | 155 | |
Jagang | 93:4d5664e9188a | 156 | logger.printf("MIP........................"); |
Jagang | 93:4d5664e9188a | 157 | |
Jagang | 110:7e71e5cd8197 | 158 | odometry.update(1); |
Jagang | 110:7e71e5cd8197 | 159 | |
sype | 121:0cc17ba879cb | 160 | /*odometry.setTheta(PI/2); |
Jagang | 110:7e71e5cd8197 | 161 | odometry.setX(1000); |
sype | 121:0cc17ba879cb | 162 | odometry.setY(400);*/ |
Jagang | 110:7e71e5cd8197 | 163 | |
Jagang | 93:4d5664e9188a | 164 | ax12_pince.setMaxTorque(MAX_TORQUE); |
Jagang | 93:4d5664e9188a | 165 | ax12_brasG.setMaxTorque(MAX_TORQUE); |
Jagang | 93:4d5664e9188a | 166 | ax12_brasD.setMaxTorque(MAX_TORQUE); |
Jagang | 39:09c04fd42c94 | 167 | |
Jagang | 93:4d5664e9188a | 168 | ax12_pince.setGoal(PINCE_FERMEE); |
Jagang | 93:4d5664e9188a | 169 | ax12_brasG.setGoal(BRASG_OUVERT); |
Jagang | 93:4d5664e9188a | 170 | ax12_brasD.setGoal(BRASD_OUVERT); |
Jagang | 103:6a38cc0765f5 | 171 | wait(0.5); |
Jagang | 93:4d5664e9188a | 172 | ax12_pince.setGoal(PINCE_OUVERTE); |
Jagang | 93:4d5664e9188a | 173 | ax12_brasG.setGoal(BRASG_FERME); |
Jagang | 93:4d5664e9188a | 174 | ax12_brasD.setGoal(BRASD_FERME); |
Jagang | 93:4d5664e9188a | 175 | wait(1.5); |
Jagang | 93:4d5664e9188a | 176 | ax12_pince.setMaxTorque(0); |
Jagang | 93:4d5664e9188a | 177 | ax12_brasG.setMaxTorque(0); |
Jagang | 93:4d5664e9188a | 178 | ax12_brasD.setMaxTorque(0); |
Jagang | 93:4d5664e9188a | 179 | |
Jagang | 93:4d5664e9188a | 180 | logger.printf("[done]\r\n"); |
Jagang | 93:4d5664e9188a | 181 | |
Jagang | 93:4d5664e9188a | 182 | // // |
Jagang | 93:4d5664e9188a | 183 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 184 | |
Jagang | 93:4d5664e9188a | 185 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 186 | // Asserv // |
Jagang | 93:4d5664e9188a | 187 | |
Jagang | 93:4d5664e9188a | 188 | logger.printf("Demarrage asserv..........."); |
Jagang | 93:4d5664e9188a | 189 | t.start(); |
Jagang | 93:4d5664e9188a | 190 | ticker.attach_us(&update,10000); //100Hz |
Jagang | 93:4d5664e9188a | 191 | logger.printf("[done]\r\n"); |
Jagang | 93:4d5664e9188a | 192 | |
Jagang | 93:4d5664e9188a | 193 | // // |
Jagang | 93:4d5664e9188a | 194 | // *--------------------------* // |
Jagang | 109:53918ba98306 | 195 | |
Jagang | 109:53918ba98306 | 196 | // *--------------------------* // |
Jagang | 109:53918ba98306 | 197 | // Tirrette + couleur // |
Jagang | 109:53918ba98306 | 198 | |
Jagang | 109:53918ba98306 | 199 | //while(tirette); // La tirrette |
Jagang | 109:53918ba98306 | 200 | |
Jagang | 109:53918ba98306 | 201 | if(couleur == COULEUR_JAUNE) |
Jagang | 109:53918ba98306 | 202 | { |
Jagang | 109:53918ba98306 | 203 | couleurRobot = COULEUR_JAUNE; |
Jagang | 117:f8c147141a0c | 204 | |
Jagang | 117:f8c147141a0c | 205 | odometry.setTheta(PI/2); |
Jagang | 117:f8c147141a0c | 206 | odometry.setX(1000); |
Jagang | 117:f8c147141a0c | 207 | odometry.setY(400); |
Jagang | 117:f8c147141a0c | 208 | |
Jagang | 117:f8c147141a0c | 209 | //objectifs.push_back(new Obj_clap(0, 0, 0, &ax12_brasG,&ax12_brasD)); |
Jagang | 119:c45efcd706d9 | 210 | objectifs.push_back( new Obj_pince(1750, 600, 1750, 450, -PI/2, &ax12_pince) ); |
Jagang | 117:f8c147141a0c | 211 | objectifs.back()->setId(IDO_PC1); |
Jagang | 117:f8c147141a0c | 212 | |
Jagang | 119:c45efcd706d9 | 213 | objectifs.push_back( new Obj_depot(1000, 400, -PI/2, &ax12_pince) ); |
Jagang | 119:c45efcd706d9 | 214 | objectifs.back()->setId(IDO_DEPOT); |
Jagang | 119:c45efcd706d9 | 215 | |
Jagang | 119:c45efcd706d9 | 216 | objectifs.push_back( new Obj_pince(800, 620, 800, 710, PI/2, &ax12_pince) ); |
Jagang | 119:c45efcd706d9 | 217 | objectifs.back()->setId(IDO_PC2); |
Jagang | 119:c45efcd706d9 | 218 | |
Jagang | 117:f8c147141a0c | 219 | objectifs.push_back( new Obj_depot(1000, 500, -PI/2, &ax12_pince) ); |
Jagang | 117:f8c147141a0c | 220 | objectifs.back()->setId(IDO_DEPOT); |
Jagang | 109:53918ba98306 | 221 | } |
Jagang | 109:53918ba98306 | 222 | else |
Jagang | 109:53918ba98306 | 223 | { |
Jagang | 109:53918ba98306 | 224 | couleurRobot = COULEUR_VERTE; |
Jagang | 109:53918ba98306 | 225 | } |
Jagang | 109:53918ba98306 | 226 | |
Jagang | 109:53918ba98306 | 227 | |
Jagang | 109:53918ba98306 | 228 | // // |
Jagang | 109:53918ba98306 | 229 | // *--------------------------* // |
Jagang | 93:4d5664e9188a | 230 | |
Jagang | 93:4d5664e9188a | 231 | bool continuer = true; |
Jagang | 71:95d76c181b22 | 232 | |
Jagang | 109:53918ba98306 | 233 | // *--------------------------* // |
Jagang | 109:53918ba98306 | 234 | // IA // |
Jagang | 109:53918ba98306 | 235 | |
Jagang | 119:c45efcd706d9 | 236 | /*while(1) |
Jagang | 119:c45efcd706d9 | 237 | { |
Jagang | 119:c45efcd706d9 | 238 | if(logger.readable()) |
Jagang | 119:c45efcd706d9 | 239 | { |
Jagang | 119:c45efcd706d9 | 240 | char c = logger.getc(); |
Jagang | 119:c45efcd706d9 | 241 | logger.printf("%c",c); |
Jagang | 119:c45efcd706d9 | 242 | if(c == 'a') |
Jagang | 119:c45efcd706d9 | 243 | { |
Jagang | 119:c45efcd706d9 | 244 | motorL.setSpeed(motorL.getSpeed()+0.05); |
Jagang | 119:c45efcd706d9 | 245 | motorR.setSpeed(motorR.getSpeed()+0.05); |
Jagang | 119:c45efcd706d9 | 246 | logger.printf("%.2f\r\n",motorL.getSpeed()); |
Jagang | 119:c45efcd706d9 | 247 | } |
Jagang | 119:c45efcd706d9 | 248 | if(c == 'z') |
Jagang | 119:c45efcd706d9 | 249 | { |
Jagang | 119:c45efcd706d9 | 250 | motorL.setSpeed(motorL.getSpeed()-0.05); |
Jagang | 119:c45efcd706d9 | 251 | motorR.setSpeed(motorR.getSpeed()-0.05); |
Jagang | 119:c45efcd706d9 | 252 | logger.printf("%.2f\r\n",motorL.getSpeed()); |
Jagang | 119:c45efcd706d9 | 253 | } |
Jagang | 119:c45efcd706d9 | 254 | } |
Jagang | 119:c45efcd706d9 | 255 | }*/ |
Jagang | 119:c45efcd706d9 | 256 | |
Jagang | 110:7e71e5cd8197 | 257 | #define IA |
Jagang | 110:7e71e5cd8197 | 258 | #ifdef IA |
Jagang | 109:53918ba98306 | 259 | |
Jagang | 109:53918ba98306 | 260 | while(continuer) |
Jagang | 109:53918ba98306 | 261 | { |
Jagang | 117:f8c147141a0c | 262 | logger.printf("Recherche d'objectif......."); |
Jagang | 109:53918ba98306 | 263 | int objAct = 0; |
Jagang | 109:53918ba98306 | 264 | bool newObj = false; |
Jagang | 109:53918ba98306 | 265 | for(objAct = 0 ; objAct < objectifs.size() ; objAct++) |
Jagang | 109:53918ba98306 | 266 | { |
Jagang | 117:f8c147141a0c | 267 | //logger.printf("Obj %d\r\n",objAct); |
Jagang | 109:53918ba98306 | 268 | if(objectifs[objAct]->isDone()) // Pas la peine de le faire, il est déjà fait ;) |
Jagang | 109:53918ba98306 | 269 | continue; |
Jagang | 117:f8c147141a0c | 270 | //logger.printf("Pas done\r\n"); |
Jagang | 117:f8c147141a0c | 271 | if(!objectifs[objAct]->isActive()) // Pas la peine de le faire, il n'est pas actif |
Jagang | 109:53918ba98306 | 272 | continue; |
Jagang | 117:f8c147141a0c | 273 | //logger.printf("Actif\r\n"); |
Jagang | 119:c45efcd706d9 | 274 | int retourAStar = terrain.AStar(odometry.getX(), odometry.getY(), objectifs[objAct]->getX(), objectifs[objAct]->getY(), 10); |
Jagang | 119:c45efcd706d9 | 275 | if(retourAStar == 1) // L'objectif est atteignable !! |
Jagang | 119:c45efcd706d9 | 276 | { |
Jagang | 119:c45efcd706d9 | 277 | newObj = true; |
Jagang | 119:c45efcd706d9 | 278 | for(unsigned int i=0;i<terrain.path.size();i++) |
Jagang | 119:c45efcd706d9 | 279 | logger.printf("%d : %.3f %.3f\r\n",i,terrain.path[i].x,terrain.path[i].y); |
Jagang | 119:c45efcd706d9 | 280 | break; |
Jagang | 119:c45efcd706d9 | 281 | } |
Jagang | 119:c45efcd706d9 | 282 | |
Jagang | 119:c45efcd706d9 | 283 | if(retourAStar == 3) // Overload memoire |
Jagang | 119:c45efcd706d9 | 284 | retourAStar = terrain.AStar(odometry.getX(), odometry.getY(), objectifs[objAct]->getX(), objectifs[objAct]->getY(), 25); |
Jagang | 119:c45efcd706d9 | 285 | |
Jagang | 117:f8c147141a0c | 286 | if(retourAStar == 1) // L'objectif est atteignable !! |
Jagang | 117:f8c147141a0c | 287 | { |
Jagang | 117:f8c147141a0c | 288 | newObj = true; |
Jagang | 117:f8c147141a0c | 289 | break; |
Jagang | 117:f8c147141a0c | 290 | } |
Jagang | 109:53918ba98306 | 291 | |
Jagang | 117:f8c147141a0c | 292 | if(retourAStar == 3) // Overload memoire |
Jagang | 119:c45efcd706d9 | 293 | retourAStar = terrain.AStar(odometry.getX(), odometry.getY(), objectifs[objAct]->getX(), objectifs[objAct]->getY(), 50); |
Jagang | 117:f8c147141a0c | 294 | |
Jagang | 117:f8c147141a0c | 295 | if(retourAStar == 1) // L'objectif est atteignable !! |
Jagang | 109:53918ba98306 | 296 | { |
Jagang | 109:53918ba98306 | 297 | newObj = true; |
Jagang | 109:53918ba98306 | 298 | break; |
Jagang | 109:53918ba98306 | 299 | } |
Jagang | 109:53918ba98306 | 300 | } |
Jagang | 109:53918ba98306 | 301 | |
Jagang | 117:f8c147141a0c | 302 | logger.printf("[done]\r\n"); |
Jagang | 117:f8c147141a0c | 303 | |
Jagang | 109:53918ba98306 | 304 | if(newObj) |
Jagang | 109:53918ba98306 | 305 | { |
Jagang | 117:f8c147141a0c | 306 | |
Jagang | 119:c45efcd706d9 | 307 | logger.printf("-> Objectif : %d %d\r\n",objectifs[objAct]->getId(),terrain.path.size()); |
Jagang | 117:f8c147141a0c | 308 | |
Jagang | 117:f8c147141a0c | 309 | // Déplacement vers le nouvel objectif // |
Jagang | 117:f8c147141a0c | 310 | for(int i=1;i<terrain.path.size()-1;i++) |
Jagang | 114:be06d518b4a7 | 311 | { |
Jagang | 114:be06d518b4a7 | 312 | logger.printf("%d\t%.3f\t%.3f\r\n",i,terrain.path[i].x,terrain.path[i].y); |
Jagang | 114:be06d518b4a7 | 313 | asserv.setGoal(terrain.path[i].x,terrain.path[i].y); |
Jagang | 114:be06d518b4a7 | 314 | while(!asserv.isArrived())wait(0.1); |
Jagang | 114:be06d518b4a7 | 315 | } |
Jagang | 114:be06d518b4a7 | 316 | asserv.setGoal(objectifs[objAct]->getX(),objectifs[objAct]->getY(),objectifs[objAct]->getTheta()); |
Jagang | 114:be06d518b4a7 | 317 | while(!asserv.isArrived())wait(0.1); |
Jagang | 109:53918ba98306 | 318 | |
Jagang | 117:f8c147141a0c | 319 | logger.printf("Execution de l'objectif...."); |
Jagang | 117:f8c147141a0c | 320 | // Exection de l'objectif // |
Jagang | 114:be06d518b4a7 | 321 | objectifs[objAct]->run(); |
Jagang | 117:f8c147141a0c | 322 | logger.printf("[done]\r\n"); |
Jagang | 109:53918ba98306 | 323 | } |
Jagang | 109:53918ba98306 | 324 | else |
Jagang | 109:53918ba98306 | 325 | { |
Jagang | 117:f8c147141a0c | 326 | logger.printf("-> Nothind to be done ... :( \r\n"); |
Jagang | 109:53918ba98306 | 327 | wait(1); |
Jagang | 109:53918ba98306 | 328 | } |
Jagang | 109:53918ba98306 | 329 | } |
Jagang | 109:53918ba98306 | 330 | |
Jagang | 114:be06d518b4a7 | 331 | #endif |
Jagang | 114:be06d518b4a7 | 332 | |
Jagang | 71:95d76c181b22 | 333 | #ifdef PLAN_A |
Jagang | 109:53918ba98306 | 334 | asserv.setGoal(300.0f,200.0f,0.0f); |
Near32 | 89:d05001d85a02 | 335 | logger.printf("GOAL SET... RUNNING!\r\n"); |
Jagang | 71:95d76c181b22 | 336 | |
Jagang | 74:88be86f83d17 | 337 | char state = 0; |
Jagang | 74:88be86f83d17 | 338 | |
Jagang | 93:4d5664e9188a | 339 | while(continuer) |
Jagang | 71:95d76c181b22 | 340 | { |
Near32 | 107:a6e498b5706c | 341 | //#define test |
Near32 | 107:a6e498b5706c | 342 | #ifndef test |
Jagang | 111:c8a1129691da | 343 | if(state == 0 && asserv.isArrived()) |
Near32 | 107:a6e498b5706c | 344 | { |
Near32 | 107:a6e498b5706c | 345 | state = 1; |
Near32 | 107:a6e498b5706c | 346 | logger.printf("Arrive en 0,0 !!!!!\r\n"); |
Near32 | 107:a6e498b5706c | 347 | motorR.setSpeed(0.0f); |
Near32 | 107:a6e498b5706c | 348 | motorL.setSpeed(0.0f); |
Near32 | 107:a6e498b5706c | 349 | wait(5); |
Jagang | 111:c8a1129691da | 350 | asserv.setGoal(0.0f,0.0f,0.0f); |
Near32 | 107:a6e498b5706c | 351 | } |
Jagang | 111:c8a1129691da | 352 | else if(state == 1 && asserv.isArrived()) |
Near32 | 107:a6e498b5706c | 353 | { |
Near32 | 107:a6e498b5706c | 354 | state = 0; |
Near32 | 107:a6e498b5706c | 355 | logger.printf("Arrive en 0,200 !!!!!\r\n"); |
Near32 | 107:a6e498b5706c | 356 | motorR.setSpeed(0.0f); |
Near32 | 107:a6e498b5706c | 357 | motorL.setSpeed(0.0f); |
Near32 | 107:a6e498b5706c | 358 | wait(5); |
Jagang | 111:c8a1129691da | 359 | asserv.setGoal(0.0f,0.0f,0.0f); |
Near32 | 107:a6e498b5706c | 360 | } |
Near32 | 107:a6e498b5706c | 361 | #endif |
Jagang | 92:b403f2724252 | 362 | #ifdef test |
Jagang | 109:53918ba98306 | 363 | if(state == 0 && asserv.isArrivedRho()) |
Jagang | 92:b403f2724252 | 364 | { |
Jagang | 92:b403f2724252 | 365 | state = 1; |
Jagang | 92:b403f2724252 | 366 | logger.printf("Arrive en 0,0 !!!!!\r\n"); |
Near32 | 98:2ec4e17dfc92 | 367 | motorR.setSpeed(0.0f); |
Near32 | 98:2ec4e17dfc92 | 368 | motorL.setSpeed(0.0f); |
Jagang | 92:b403f2724252 | 369 | wait(5); |
Jagang | 109:53918ba98306 | 370 | asserv.setGoal(300.0f,200.0f,0.0f); |
Jagang | 92:b403f2724252 | 371 | } |
Jagang | 109:53918ba98306 | 372 | else if(state == 1 && asserv.isArrivedRho()) |
Jagang | 92:b403f2724252 | 373 | { |
Jagang | 92:b403f2724252 | 374 | state = 2; |
Jagang | 92:b403f2724252 | 375 | logger.printf("Arrive en 200,200 !!!!!\r\n"); |
Near32 | 98:2ec4e17dfc92 | 376 | motorR.setSpeed(0.0f); |
Near32 | 98:2ec4e17dfc92 | 377 | motorL.setSpeed(0.0f); |
Jagang | 92:b403f2724252 | 378 | wait(5); |
Jagang | 109:53918ba98306 | 379 | asserv.setGoal(0.0f,300.0f,0.0f); |
Jagang | 92:b403f2724252 | 380 | } |
Jagang | 109:53918ba98306 | 381 | else if(state == 2 && asserv.isArrivedRho()) |
Jagang | 92:b403f2724252 | 382 | { |
Jagang | 92:b403f2724252 | 383 | state = 0; |
Jagang | 92:b403f2724252 | 384 | logger.printf("Arrive en 0,200 !!!!!\r\n"); |
Near32 | 98:2ec4e17dfc92 | 385 | motorR.setSpeed(0.0f); |
Near32 | 98:2ec4e17dfc92 | 386 | motorL.setSpeed(0.0f); |
Jagang | 92:b403f2724252 | 387 | wait(5); |
Jagang | 109:53918ba98306 | 388 | asserv.setGoal(0.0f,0.0f,0.0f); |
Jagang | 92:b403f2724252 | 389 | } |
Jagang | 92:b403f2724252 | 390 | #endif |
Jagang | 71:95d76c181b22 | 391 | } |
Jagang | 71:95d76c181b22 | 392 | #else |
sype | 121:0cc17ba879cb | 393 | asserv.setGoal(1,5); |
sype | 121:0cc17ba879cb | 394 | logger.printf("Attente\r\n"); |
sype | 121:0cc17ba879cb | 395 | while(!asserv.isArrived())wait(0.1); |
sype | 121:0cc17ba879cb | 396 | logger.printf("Arrivé\r\n"); |
sype | 121:0cc17ba879cb | 397 | asserv.setGoal(1,10); |
sype | 121:0cc17ba879cb | 398 | logger.printf("Attente\r\n"); |
sype | 121:0cc17ba879cb | 399 | while(!asserv.isArrived())wait(0.1); |
sype | 121:0cc17ba879cb | 400 | logger.printf("Arrivé\r\n"); |
sype | 121:0cc17ba879cb | 401 | asserv.setGoal(1,15); |
sype | 108:890094ee202a | 402 | logger.printf("Attente\r\n"); |
sype | 108:890094ee202a | 403 | while(!asserv.isArrived())wait(0.1); |
sype | 108:890094ee202a | 404 | logger.printf("Arrivé\r\n"); |
sype | 121:0cc17ba879cb | 405 | asserv.setGoal(1,20); |
sype | 121:0cc17ba879cb | 406 | logger.printf("Attente\r\n"); |
sype | 121:0cc17ba879cb | 407 | while(!asserv.isArrived())wait(0.1); |
sype | 121:0cc17ba879cb | 408 | logger.printf("Arrivé\r\n"); |
sype | 121:0cc17ba879cb | 409 | asserv.setGoal(1,25); |
sype | 121:0cc17ba879cb | 410 | logger.printf("Attente\r\n"); |
sype | 121:0cc17ba879cb | 411 | while(!asserv.isArrived())wait(0.1); |
sype | 121:0cc17ba879cb | 412 | logger.printf("Arrivé\r\n"); |
sype | 121:0cc17ba879cb | 413 | asserv.setGoal(1,30); |
sype | 121:0cc17ba879cb | 414 | logger.printf("Attente\r\n"); |
sype | 121:0cc17ba879cb | 415 | while(!asserv.isArrived())wait(0.1); |
sype | 121:0cc17ba879cb | 416 | logger.printf("Arrivé\r\n"); |
sype | 121:0cc17ba879cb | 417 | asserv.setGoal(0,0,PI/2); |
sype | 121:0cc17ba879cb | 418 | logger.printf("Attente\r\n"); |
sype | 121:0cc17ba879cb | 419 | while(!asserv.isArrived())wait(0.1); |
sype | 121:0cc17ba879cb | 420 | logger.printf("Arrivé\r\n"); |
sype | 121:0cc17ba879cb | 421 | while(1); |
sype | 121:0cc17ba879cb | 422 | /*logger.printf("Arrivé\r\n"); |
sype | 108:890094ee202a | 423 | wait(1); |
sype | 108:890094ee202a | 424 | asserv.setGoal(-300,300,0); |
sype | 108:890094ee202a | 425 | while(!asserv.isArrived())wait(0.1); |
sype | 108:890094ee202a | 426 | wait(1); |
sype | 108:890094ee202a | 427 | asserv.setGoal(-300,-1,0); |
sype | 108:890094ee202a | 428 | while(!asserv.isArrived())wait(0.1); |
sype | 108:890094ee202a | 429 | wait(1); |
sype | 108:890094ee202a | 430 | asserv.setGoal(-300,-300,0); |
sype | 108:890094ee202a | 431 | while(!asserv.isArrived())wait(0.1); |
sype | 108:890094ee202a | 432 | wait(1); |
sype | 108:890094ee202a | 433 | asserv.setGoal(1,-300,0); |
sype | 108:890094ee202a | 434 | while(!asserv.isArrived())wait(0.1); |
sype | 108:890094ee202a | 435 | wait(1); |
sype | 108:890094ee202a | 436 | asserv.setGoal(300,-300,0); |
sype | 108:890094ee202a | 437 | while(!asserv.isArrived())wait(0.1); |
sype | 108:890094ee202a | 438 | wait(1); |
sype | 121:0cc17ba879cb | 439 | asserv.setGoal(0,0,0);*/ |
Jagang | 71:95d76c181b22 | 440 | #endif |
Near32 | 43:87bdce65341f | 441 | } |
Jagang | 93:4d5664e9188a | 442 | |
Jagang | 93:4d5664e9188a | 443 | void update() |
Jagang | 93:4d5664e9188a | 444 | { |
Jagang | 93:4d5664e9188a | 445 | float dt = t.read(); |
Jagang | 93:4d5664e9188a | 446 | t.reset(); |
Jagang | 93:4d5664e9188a | 447 | |
Jagang | 93:4d5664e9188a | 448 | odometry.update(dt); |
Jagang | 109:53918ba98306 | 449 | asserv.update(dt); |
Jagang | 93:4d5664e9188a | 450 | |
Jagang | 93:4d5664e9188a | 451 | #ifdef PLAN_A |
Jagang | 93:4d5664e9188a | 452 | float phi_r = (float)instanceAsserv.getPhiR(); |
Jagang | 93:4d5664e9188a | 453 | float phi_l = (float)instanceAsserv.getPhiL(); |
Jagang | 93:4d5664e9188a | 454 | float phi_max = (float)instanceAsserv.getPhiMax(); |
Jagang | 93:4d5664e9188a | 455 | |
Jagang | 93:4d5664e9188a | 456 | motorR.setSpeed(0.08+(phi_r/phi_max)); |
Jagang | 93:4d5664e9188a | 457 | motorL.setSpeed(0.08+(phi_l/phi_max)); |
Jagang | 93:4d5664e9188a | 458 | #endif |
Jagang | 93:4d5664e9188a | 459 | } |
Jagang | 93:4d5664e9188a | 460 |