Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@23:bb1535360a98, 2019-06-06 (annotated)
- Committer:
- Wael_H
- Date:
- Thu Jun 06 11:43:01 2019 +0000
- Revision:
- 23:bb1535360a98
- Parent:
- 20:a1b5d032b422
- Child:
- 24:314b1f6607c5
verion de la classe Robot avec gestion du bras
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wael_H | 2:8971078b1ccf | 1 | #include "mbed.h" |
Wael_H | 5:34048faec367 | 2 | #include "CAN_asser.h" |
Wael_H | 10:efa507ba2b35 | 3 | #include "Robot.h" |
Wael_H | 10:efa507ba2b35 | 4 | |
Wael_H | 23:bb1535360a98 | 5 | void automate_testLasers(Robot&); |
Wael_H | 23:bb1535360a98 | 6 | void automate_testABalle(Robot&); |
Wael_H | 23:bb1535360a98 | 7 | void automate_deplacement(Robot&); |
Wael_H | 23:bb1535360a98 | 8 | void automate_vitesse(Robot&); |
Wael_H | 23:bb1535360a98 | 9 | |
Wael_H | 23:bb1535360a98 | 10 | typedef enum{TURN_FAST, CORRECT_GAUCHE, CORRECT_DROITE, GO_STRAIGHT} type_etat_deplacement; |
Wael_H | 23:bb1535360a98 | 11 | type_etat_deplacement etat_deplacement = TURN_FAST; |
Wael_H | 23:bb1535360a98 | 12 | |
Wael_H | 8:94ecfe411d02 | 13 | |
Wael_H | 2:8971078b1ccf | 14 | int main(void) |
Wael_H | 2:8971078b1ccf | 15 | { |
Wael_H | 10:efa507ba2b35 | 16 | Robot robot; |
theolp | 17:aae5361ddddf | 17 | |
Wael_H | 23:bb1535360a98 | 18 | robot.setSpeed(80,450); // vitesse de rotation de recherche de la balle |
Wael_H | 23:bb1535360a98 | 19 | robot.gobe(25); |
Wael_H | 15:3d4543a6c100 | 20 | |
Wael_H | 23:bb1535360a98 | 21 | double pos_servo_ballon = 0.045; |
theolp | 20:a1b5d032b422 | 22 | |
Wael_H | 15:3d4543a6c100 | 23 | while(1) |
Wael_H | 23:bb1535360a98 | 24 | if(!Robot::Jack) |
theolp | 17:aae5361ddddf | 25 | { |
Wael_H | 23:bb1535360a98 | 26 | if(robot.leveBras()) |
Wael_H | 23:bb1535360a98 | 27 | robot.exploseBallon(); |
Wael_H | 23:bb1535360a98 | 28 | //automate_testABalle(robot); |
theolp | 17:aae5361ddddf | 29 | |
Wael_H | 23:bb1535360a98 | 30 | /*automate_testLasers(robot); |
Wael_H | 23:bb1535360a98 | 31 | |
Wael_H | 23:bb1535360a98 | 32 | if(!robot.aBalle()) |
Wael_H | 23:bb1535360a98 | 33 | automate_deplacement(robot); |
Wael_H | 23:bb1535360a98 | 34 | |
Wael_H | 23:bb1535360a98 | 35 | automate_vitesse(robot);*/ |
theolp | 17:aae5361ddddf | 36 | } |
Wael_H | 15:3d4543a6c100 | 37 | } |
Wael_H | 15:3d4543a6c100 | 38 | |
Wael_H | 23:bb1535360a98 | 39 | |
Wael_H | 23:bb1535360a98 | 40 | void automate_testLasers(Robot& robot) |
Wael_H | 23:bb1535360a98 | 41 | { |
Wael_H | 23:bb1535360a98 | 42 | static const int diffMurBalle = 20; |
Wael_H | 23:bb1535360a98 | 43 | static float past_gauche, past_droit, actual_gauche, actual_droit; |
Wael_H | 23:bb1535360a98 | 44 | static float distBalle; |
Wael_H | 23:bb1535360a98 | 45 | |
Wael_H | 23:bb1535360a98 | 46 | actual_gauche = robot.getDist(Laser::Gauche); |
Wael_H | 23:bb1535360a98 | 47 | actual_droit = robot.getDist(Laser::Droit); |
Wael_H | 23:bb1535360a98 | 48 | |
Wael_H | 23:bb1535360a98 | 49 | switch(etat_deplacement) |
Wael_H | 23:bb1535360a98 | 50 | { |
Wael_H | 23:bb1535360a98 | 51 | case TURN_FAST: |
Wael_H | 23:bb1535360a98 | 52 | if(actual_droit < past_droit - diffMurBalle) |
Wael_H | 23:bb1535360a98 | 53 | { |
Wael_H | 23:bb1535360a98 | 54 | distBalle = actual_droit; |
Wael_H | 23:bb1535360a98 | 55 | robot.stop(); |
Wael_H | 23:bb1535360a98 | 56 | etat_deplacement = CORRECT_GAUCHE; |
Wael_H | 23:bb1535360a98 | 57 | } |
Wael_H | 23:bb1535360a98 | 58 | break; |
Wael_H | 23:bb1535360a98 | 59 | } |
Wael_H | 23:bb1535360a98 | 60 | |
Wael_H | 23:bb1535360a98 | 61 | |
Wael_H | 23:bb1535360a98 | 62 | past_gauche = actual_gauche; |
Wael_H | 23:bb1535360a98 | 63 | past_droit = actual_droit; |
Wael_H | 23:bb1535360a98 | 64 | } |
Wael_H | 23:bb1535360a98 | 65 | |
Wael_H | 23:bb1535360a98 | 66 | void automate_testABalle(Robot& robot) |
Wael_H | 15:3d4543a6c100 | 67 | { |
Wael_H | 23:bb1535360a98 | 68 | typedef enum {ATTENTE,ABALLE} type_etat; |
Wael_H | 23:bb1535360a98 | 69 | static type_etat etat = ATTENTE; |
Wael_H | 23:bb1535360a98 | 70 | |
Wael_H | 23:bb1535360a98 | 71 | static Timer T_ejecte; |
Wael_H | 7:753e901d441b | 72 | |
Wael_H | 7:753e901d441b | 73 | switch(etat) |
Wael_H | 9:2113adf37c66 | 74 | { |
Wael_H | 23:bb1535360a98 | 75 | case ATTENTE: |
Wael_H | 23:bb1535360a98 | 76 | if(robot.aBalle()) |
Wael_H | 23:bb1535360a98 | 77 | { |
Wael_H | 23:bb1535360a98 | 78 | robot.stop(); |
Wael_H | 23:bb1535360a98 | 79 | robot.exploseBallon(); |
Wael_H | 23:bb1535360a98 | 80 | etat = ABALLE; |
Wael_H | 23:bb1535360a98 | 81 | robot.setSpeed(80,500); //vitesse de rotation vers le terrain ennemi |
Wael_H | 23:bb1535360a98 | 82 | } |
Wael_H | 23:bb1535360a98 | 83 | else if( T_ejecte.read() >= 1.0f ) |
Wael_H | 23:bb1535360a98 | 84 | { |
Wael_H | 23:bb1535360a98 | 85 | robot.gobe(25); |
Wael_H | 23:bb1535360a98 | 86 | T_ejecte.stop(); |
Wael_H | 23:bb1535360a98 | 87 | T_ejecte.reset(); |
Wael_H | 23:bb1535360a98 | 88 | } |
Wael_H | 13:9c62e263f245 | 89 | break; |
Wael_H | 13:9c62e263f245 | 90 | |
Wael_H | 23:bb1535360a98 | 91 | case ABALLE: |
Wael_H | 23:bb1535360a98 | 92 | if(robot.tourne(1800)) |
Wael_H | 23:bb1535360a98 | 93 | robot.ejecte(70); |
Wael_H | 23:bb1535360a98 | 94 | |
Wael_H | 23:bb1535360a98 | 95 | if(!robot.aBalle()) |
Wael_H | 23:bb1535360a98 | 96 | { |
Wael_H | 23:bb1535360a98 | 97 | robot.arreteDisquette(); |
Wael_H | 23:bb1535360a98 | 98 | T_ejecte.start(); |
Wael_H | 23:bb1535360a98 | 99 | etat = ATTENTE; |
Wael_H | 23:bb1535360a98 | 100 | etat_deplacement = TURN_FAST; |
Wael_H | 23:bb1535360a98 | 101 | } |
Wael_H | 13:9c62e263f245 | 102 | break; |
Wael_H | 13:9c62e263f245 | 103 | } |
Wael_H | 13:9c62e263f245 | 104 | } |
Wael_H | 23:bb1535360a98 | 105 | |
Wael_H | 23:bb1535360a98 | 106 | void automate_deplacement(Robot& robot) |
Wael_H | 23:bb1535360a98 | 107 | { |
Wael_H | 23:bb1535360a98 | 108 | switch(etat_deplacement) |
Wael_H | 23:bb1535360a98 | 109 | { |
Wael_H | 23:bb1535360a98 | 110 | case TURN_FAST: |
Wael_H | 23:bb1535360a98 | 111 | robot.tourne(); |
Wael_H | 23:bb1535360a98 | 112 | break; |
Wael_H | 23:bb1535360a98 | 113 | |
Wael_H | 23:bb1535360a98 | 114 | case CORRECT_GAUCHE: |
Wael_H | 23:bb1535360a98 | 115 | robot.tourne(-450); |
Wael_H | 23:bb1535360a98 | 116 | break; |
Wael_H | 23:bb1535360a98 | 117 | |
Wael_H | 23:bb1535360a98 | 118 | case CORRECT_DROITE: |
Wael_H | 23:bb1535360a98 | 119 | robot.tourne(450); |
Wael_H | 23:bb1535360a98 | 120 | |
Wael_H | 23:bb1535360a98 | 121 | case GO_STRAIGHT: |
Wael_H | 23:bb1535360a98 | 122 | robot.avance(); |
Wael_H | 23:bb1535360a98 | 123 | break; |
Wael_H | 23:bb1535360a98 | 124 | } |
Wael_H | 23:bb1535360a98 | 125 | } |
Wael_H | 23:bb1535360a98 | 126 | |
Wael_H | 23:bb1535360a98 | 127 | void automate_vitesse(Robot& robot) |
Wael_H | 23:bb1535360a98 | 128 | { |
Wael_H | 23:bb1535360a98 | 129 | switch(etat_deplacement) |
Wael_H | 23:bb1535360a98 | 130 | { |
Wael_H | 23:bb1535360a98 | 131 | case TURN_FAST: |
Wael_H | 23:bb1535360a98 | 132 | robot.setSpeed(80,450); |
Wael_H | 23:bb1535360a98 | 133 | break; |
Wael_H | 23:bb1535360a98 | 134 | |
Wael_H | 23:bb1535360a98 | 135 | case CORRECT_GAUCHE: |
Wael_H | 23:bb1535360a98 | 136 | robot.setSpeed(50,300); |
Wael_H | 23:bb1535360a98 | 137 | break; |
Wael_H | 23:bb1535360a98 | 138 | |
Wael_H | 23:bb1535360a98 | 139 | case CORRECT_DROITE: |
Wael_H | 23:bb1535360a98 | 140 | robot.setSpeed(50,300); |
Wael_H | 23:bb1535360a98 | 141 | break; |
Wael_H | 23:bb1535360a98 | 142 | |
Wael_H | 23:bb1535360a98 | 143 | case GO_STRAIGHT: |
Wael_H | 23:bb1535360a98 | 144 | robot.setSpeed(80,400); |
Wael_H | 23:bb1535360a98 | 145 | break; |
Wael_H | 23:bb1535360a98 | 146 | } |
Wael_H | 23:bb1535360a98 | 147 | } |