Robot's source code

Dependencies:   mbed

Committer:
Jagang
Date:
Thu May 07 14:18:07 2015 +0000
Revision:
122:3d059ad76dd7
Parent:
121:0cc17ba879cb
Parent:
120:06643cbec98a
Child:
123:55e5e9acc541
merge

Who changed what in which revision?

UserRevisionLine numberNew 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 109:53918ba98306 267 if(objectifs[objAct]->isDone()) // Pas la peine de le faire, il est déjà fait ;)
Jagang 109:53918ba98306 268 continue;
Jagang 117:f8c147141a0c 269 if(!objectifs[objAct]->isActive()) // Pas la peine de le faire, il n'est pas actif
Jagang 109:53918ba98306 270 continue;
Jagang 119:c45efcd706d9 271 int retourAStar = terrain.AStar(odometry.getX(), odometry.getY(), objectifs[objAct]->getX(), objectifs[objAct]->getY(), 10);
Jagang 119:c45efcd706d9 272 if(retourAStar == 1) // L'objectif est atteignable !!
Jagang 119:c45efcd706d9 273 {
Jagang 119:c45efcd706d9 274 newObj = true;
Jagang 119:c45efcd706d9 275 for(unsigned int i=0;i<terrain.path.size();i++)
Jagang 119:c45efcd706d9 276 logger.printf("%d : %.3f %.3f\r\n",i,terrain.path[i].x,terrain.path[i].y);
Jagang 119:c45efcd706d9 277 break;
Jagang 119:c45efcd706d9 278 }
Jagang 119:c45efcd706d9 279
Jagang 119:c45efcd706d9 280 if(retourAStar == 3) // Overload memoire
Jagang 119:c45efcd706d9 281 retourAStar = terrain.AStar(odometry.getX(), odometry.getY(), objectifs[objAct]->getX(), objectifs[objAct]->getY(), 25);
Jagang 119:c45efcd706d9 282
Jagang 117:f8c147141a0c 283 if(retourAStar == 1) // L'objectif est atteignable !!
Jagang 117:f8c147141a0c 284 {
Jagang 117:f8c147141a0c 285 newObj = true;
Jagang 117:f8c147141a0c 286 break;
Jagang 117:f8c147141a0c 287 }
Jagang 109:53918ba98306 288
Jagang 117:f8c147141a0c 289 if(retourAStar == 3) // Overload memoire
Jagang 119:c45efcd706d9 290 retourAStar = terrain.AStar(odometry.getX(), odometry.getY(), objectifs[objAct]->getX(), objectifs[objAct]->getY(), 50);
Jagang 117:f8c147141a0c 291
Jagang 117:f8c147141a0c 292 if(retourAStar == 1) // L'objectif est atteignable !!
Jagang 109:53918ba98306 293 {
Jagang 109:53918ba98306 294 newObj = true;
Jagang 109:53918ba98306 295 break;
Jagang 109:53918ba98306 296 }
Jagang 109:53918ba98306 297 }
Jagang 109:53918ba98306 298
Jagang 117:f8c147141a0c 299 logger.printf("[done]\r\n");
Jagang 117:f8c147141a0c 300
Jagang 109:53918ba98306 301 if(newObj)
Jagang 109:53918ba98306 302 {
Jagang 120:06643cbec98a 303 logger.printf("-> Objectif : %d\r\n",objectifs[objAct]->getId());
Jagang 117:f8c147141a0c 304
Jagang 117:f8c147141a0c 305
Jagang 117:f8c147141a0c 306 // Déplacement vers le nouvel objectif //
Jagang 120:06643cbec98a 307
Jagang 117:f8c147141a0c 308 for(int i=1;i<terrain.path.size()-1;i++)
Jagang 114:be06d518b4a7 309 {
Jagang 114:be06d518b4a7 310 logger.printf("%d\t%.3f\t%.3f\r\n",i,terrain.path[i].x,terrain.path[i].y);
Jagang 114:be06d518b4a7 311 asserv.setGoal(terrain.path[i].x,terrain.path[i].y);
Jagang 114:be06d518b4a7 312 while(!asserv.isArrived())wait(0.1);
Jagang 114:be06d518b4a7 313 }
Jagang 114:be06d518b4a7 314 asserv.setGoal(objectifs[objAct]->getX(),objectifs[objAct]->getY(),objectifs[objAct]->getTheta());
Jagang 114:be06d518b4a7 315 while(!asserv.isArrived())wait(0.1);
Jagang 109:53918ba98306 316
Jagang 120:06643cbec98a 317
Jagang 120:06643cbec98a 318 // Execution de l'objectif //
Jagang 120:06643cbec98a 319
Jagang 117:f8c147141a0c 320 logger.printf("Execution de l'objectif....");
Jagang 120:06643cbec98a 321
Jagang 114:be06d518b4a7 322 objectifs[objAct]->run();
Jagang 117:f8c147141a0c 323 logger.printf("[done]\r\n");
Jagang 109:53918ba98306 324 }
Jagang 109:53918ba98306 325 else
Jagang 109:53918ba98306 326 {
Jagang 117:f8c147141a0c 327 logger.printf("-> Nothind to be done ... :( \r\n");
Jagang 109:53918ba98306 328 wait(1);
Jagang 109:53918ba98306 329 }
Jagang 109:53918ba98306 330 }
Jagang 109:53918ba98306 331
Jagang 114:be06d518b4a7 332 #endif
Jagang 114:be06d518b4a7 333
Jagang 71:95d76c181b22 334 #ifdef PLAN_A
Jagang 109:53918ba98306 335 asserv.setGoal(300.0f,200.0f,0.0f);
Near32 89:d05001d85a02 336 logger.printf("GOAL SET... RUNNING!\r\n");
Jagang 71:95d76c181b22 337
Jagang 74:88be86f83d17 338 char state = 0;
Jagang 74:88be86f83d17 339
Jagang 93:4d5664e9188a 340 while(continuer)
Jagang 71:95d76c181b22 341 {
Near32 107:a6e498b5706c 342 //#define test
Near32 107:a6e498b5706c 343 #ifndef test
Jagang 111:c8a1129691da 344 if(state == 0 && asserv.isArrived())
Near32 107:a6e498b5706c 345 {
Near32 107:a6e498b5706c 346 state = 1;
Near32 107:a6e498b5706c 347 logger.printf("Arrive en 0,0 !!!!!\r\n");
Near32 107:a6e498b5706c 348 motorR.setSpeed(0.0f);
Near32 107:a6e498b5706c 349 motorL.setSpeed(0.0f);
Near32 107:a6e498b5706c 350 wait(5);
Jagang 111:c8a1129691da 351 asserv.setGoal(0.0f,0.0f,0.0f);
Near32 107:a6e498b5706c 352 }
Jagang 111:c8a1129691da 353 else if(state == 1 && asserv.isArrived())
Near32 107:a6e498b5706c 354 {
Near32 107:a6e498b5706c 355 state = 0;
Near32 107:a6e498b5706c 356 logger.printf("Arrive en 0,200 !!!!!\r\n");
Near32 107:a6e498b5706c 357 motorR.setSpeed(0.0f);
Near32 107:a6e498b5706c 358 motorL.setSpeed(0.0f);
Near32 107:a6e498b5706c 359 wait(5);
Jagang 111:c8a1129691da 360 asserv.setGoal(0.0f,0.0f,0.0f);
Near32 107:a6e498b5706c 361 }
Near32 107:a6e498b5706c 362 #endif
Jagang 92:b403f2724252 363 #ifdef test
Jagang 109:53918ba98306 364 if(state == 0 && asserv.isArrivedRho())
Jagang 92:b403f2724252 365 {
Jagang 92:b403f2724252 366 state = 1;
Jagang 92:b403f2724252 367 logger.printf("Arrive en 0,0 !!!!!\r\n");
Near32 98:2ec4e17dfc92 368 motorR.setSpeed(0.0f);
Near32 98:2ec4e17dfc92 369 motorL.setSpeed(0.0f);
Jagang 92:b403f2724252 370 wait(5);
Jagang 109:53918ba98306 371 asserv.setGoal(300.0f,200.0f,0.0f);
Jagang 92:b403f2724252 372 }
Jagang 109:53918ba98306 373 else if(state == 1 && asserv.isArrivedRho())
Jagang 92:b403f2724252 374 {
Jagang 92:b403f2724252 375 state = 2;
Jagang 92:b403f2724252 376 logger.printf("Arrive en 200,200 !!!!!\r\n");
Near32 98:2ec4e17dfc92 377 motorR.setSpeed(0.0f);
Near32 98:2ec4e17dfc92 378 motorL.setSpeed(0.0f);
Jagang 92:b403f2724252 379 wait(5);
Jagang 109:53918ba98306 380 asserv.setGoal(0.0f,300.0f,0.0f);
Jagang 92:b403f2724252 381 }
Jagang 109:53918ba98306 382 else if(state == 2 && asserv.isArrivedRho())
Jagang 92:b403f2724252 383 {
Jagang 92:b403f2724252 384 state = 0;
Jagang 92:b403f2724252 385 logger.printf("Arrive en 0,200 !!!!!\r\n");
Near32 98:2ec4e17dfc92 386 motorR.setSpeed(0.0f);
Near32 98:2ec4e17dfc92 387 motorL.setSpeed(0.0f);
Jagang 92:b403f2724252 388 wait(5);
Jagang 109:53918ba98306 389 asserv.setGoal(0.0f,0.0f,0.0f);
Jagang 92:b403f2724252 390 }
Jagang 92:b403f2724252 391 #endif
Jagang 71:95d76c181b22 392 }
Jagang 71:95d76c181b22 393 #else
sype 121:0cc17ba879cb 394 asserv.setGoal(1,5);
sype 121:0cc17ba879cb 395 logger.printf("Attente\r\n");
sype 121:0cc17ba879cb 396 while(!asserv.isArrived())wait(0.1);
sype 121:0cc17ba879cb 397 logger.printf("Arrivé\r\n");
sype 121:0cc17ba879cb 398 asserv.setGoal(1,10);
sype 121:0cc17ba879cb 399 logger.printf("Attente\r\n");
sype 121:0cc17ba879cb 400 while(!asserv.isArrived())wait(0.1);
sype 121:0cc17ba879cb 401 logger.printf("Arrivé\r\n");
sype 121:0cc17ba879cb 402 asserv.setGoal(1,15);
sype 108:890094ee202a 403 logger.printf("Attente\r\n");
sype 108:890094ee202a 404 while(!asserv.isArrived())wait(0.1);
sype 108:890094ee202a 405 logger.printf("Arrivé\r\n");
sype 121:0cc17ba879cb 406 asserv.setGoal(1,20);
sype 121:0cc17ba879cb 407 logger.printf("Attente\r\n");
sype 121:0cc17ba879cb 408 while(!asserv.isArrived())wait(0.1);
sype 121:0cc17ba879cb 409 logger.printf("Arrivé\r\n");
sype 121:0cc17ba879cb 410 asserv.setGoal(1,25);
sype 121:0cc17ba879cb 411 logger.printf("Attente\r\n");
sype 121:0cc17ba879cb 412 while(!asserv.isArrived())wait(0.1);
sype 121:0cc17ba879cb 413 logger.printf("Arrivé\r\n");
sype 121:0cc17ba879cb 414 asserv.setGoal(1,30);
sype 121:0cc17ba879cb 415 logger.printf("Attente\r\n");
sype 121:0cc17ba879cb 416 while(!asserv.isArrived())wait(0.1);
sype 121:0cc17ba879cb 417 logger.printf("Arrivé\r\n");
sype 121:0cc17ba879cb 418 asserv.setGoal(0,0,PI/2);
sype 121:0cc17ba879cb 419 logger.printf("Attente\r\n");
sype 121:0cc17ba879cb 420 while(!asserv.isArrived())wait(0.1);
sype 121:0cc17ba879cb 421 logger.printf("Arrivé\r\n");
sype 121:0cc17ba879cb 422 while(1);
sype 121:0cc17ba879cb 423 /*logger.printf("Arrivé\r\n");
sype 108:890094ee202a 424 wait(1);
sype 108:890094ee202a 425 asserv.setGoal(-300,300,0);
sype 108:890094ee202a 426 while(!asserv.isArrived())wait(0.1);
sype 108:890094ee202a 427 wait(1);
sype 108:890094ee202a 428 asserv.setGoal(-300,-1,0);
sype 108:890094ee202a 429 while(!asserv.isArrived())wait(0.1);
sype 108:890094ee202a 430 wait(1);
sype 108:890094ee202a 431 asserv.setGoal(-300,-300,0);
sype 108:890094ee202a 432 while(!asserv.isArrived())wait(0.1);
sype 108:890094ee202a 433 wait(1);
sype 108:890094ee202a 434 asserv.setGoal(1,-300,0);
sype 108:890094ee202a 435 while(!asserv.isArrived())wait(0.1);
sype 108:890094ee202a 436 wait(1);
sype 108:890094ee202a 437 asserv.setGoal(300,-300,0);
sype 108:890094ee202a 438 while(!asserv.isArrived())wait(0.1);
sype 108:890094ee202a 439 wait(1);
sype 121:0cc17ba879cb 440 asserv.setGoal(0,0,0);*/
Jagang 71:95d76c181b22 441 #endif
Near32 43:87bdce65341f 442 }
Jagang 93:4d5664e9188a 443
Jagang 93:4d5664e9188a 444 void update()
Jagang 93:4d5664e9188a 445 {
Jagang 93:4d5664e9188a 446 float dt = t.read();
Jagang 93:4d5664e9188a 447 t.reset();
Jagang 93:4d5664e9188a 448
Jagang 93:4d5664e9188a 449 odometry.update(dt);
Jagang 109:53918ba98306 450 asserv.update(dt);
Jagang 93:4d5664e9188a 451
Jagang 93:4d5664e9188a 452 #ifdef PLAN_A
Jagang 93:4d5664e9188a 453 float phi_r = (float)instanceAsserv.getPhiR();
Jagang 93:4d5664e9188a 454 float phi_l = (float)instanceAsserv.getPhiL();
Jagang 93:4d5664e9188a 455 float phi_max = (float)instanceAsserv.getPhiMax();
Jagang 93:4d5664e9188a 456
Jagang 93:4d5664e9188a 457 motorR.setSpeed(0.08+(phi_r/phi_max));
Jagang 93:4d5664e9188a 458 motorL.setSpeed(0.08+(phi_l/phi_max));
Jagang 93:4d5664e9188a 459 #endif
Jagang 93:4d5664e9188a 460 }
Jagang 93:4d5664e9188a 461