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
Classes/Robot.cpp@23:bb1535360a98, 2019-06-06 (annotated)
- Committer:
- Wael_H
- Date:
- Thu Jun 06 11:43:01 2019 +0000
- Revision:
- 23:bb1535360a98
- Parent:
- 21:9ff2eab240fb
- 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 | 10:efa507ba2b35 | 1 | #include "mbed.h" |
| Wael_H | 10:efa507ba2b35 | 2 | #include "Robot.h" |
| Wael_H | 10:efa507ba2b35 | 3 | #include "CAN_asser.h" |
| Wael_H | 10:efa507ba2b35 | 4 | |
| Wael_H | 10:efa507ba2b35 | 5 | #include "Deplacement.h" |
| Wael_H | 10:efa507ba2b35 | 6 | #include "Laser.h" |
| Wael_H | 10:efa507ba2b35 | 7 | #include "Rouleau.h" |
| Wael_H | 10:efa507ba2b35 | 8 | #include <string> |
| Wael_H | 10:efa507ba2b35 | 9 | |
| Wael_H | 10:efa507ba2b35 | 10 | using namespace std; |
| Wael_H | 10:efa507ba2b35 | 11 | |
| theolp | 20:a1b5d032b422 | 12 | //********** CNY70 **********// |
| theolp | 20:a1b5d032b422 | 13 | /* |
| theolp | 20:a1b5d032b422 | 14 | |
| theolp | 20:a1b5d032b422 | 15 | CNY70 de gauche branché sur CNY 0 : le plus à droite (peut changer) |
| theolp | 20:a1b5d032b422 | 16 | CNY70 de droite branché sur CNY 1 : deuxième en partant de la droite (peut changer) |
| theolp | 20:a1b5d032b422 | 17 | |
| theolp | 20:a1b5d032b422 | 18 | PINS: |
| theolp | 20:a1b5d032b422 | 19 | CNY 0 -> A2 |
| theolp | 20:a1b5d032b422 | 20 | CNY 1 -> A3 |
| theolp | 20:a1b5d032b422 | 21 | CNY 2 -> A4 |
| theolp | 20:a1b5d032b422 | 22 | CNY 3 -> A5 |
| theolp | 20:a1b5d032b422 | 23 | |
| theolp | 20:a1b5d032b422 | 24 | */ |
| theolp | 20:a1b5d032b422 | 25 | /**********************************/ |
| theolp | 20:a1b5d032b422 | 26 | |
| Wael_H | 19:dad67302af25 | 27 | DigitalIn Robot::Jack(PA_15); |
| Wael_H | 10:efa507ba2b35 | 28 | |
| theolp | 20:a1b5d032b422 | 29 | Robot::Robot() : laserG(Laser(PB_1)), laserD(Laser(PC_5)), laserA(Laser(PC_4)), |
| theolp | 20:a1b5d032b422 | 30 | rouleau(Rouleau(D5, D4, D6)), /*Pins order : PWM, Ejecte, Gobe*/ |
| theolp | 20:a1b5d032b422 | 31 | BPs(DigitalIn(PC_2, PullDown)), |
| Wael_H | 23:bb1535360a98 | 32 | CNY_G(AnalogIn(A2)), CNY_D(AnalogIn(A3)), //Infos plus haut pour les pins |
| Wael_H | 23:bb1535360a98 | 33 | Cerveau_Bras(PwmOut(PB_7)), Disquette(PwmOut(PB_6)) |
| Wael_H | 10:efa507ba2b35 | 34 | { |
| Wael_H | 10:efa507ba2b35 | 35 | can_init(); |
| Wael_H | 19:dad67302af25 | 36 | this->setPos(500,0,0); |
| Wael_H | 23:bb1535360a98 | 37 | |
| Wael_H | 23:bb1535360a98 | 38 | this->Cerveau_Bras.period_ms(20); |
| Wael_H | 23:bb1535360a98 | 39 | this->Cerveau_Bras = 0.045f; |
| Wael_H | 23:bb1535360a98 | 40 | |
| Wael_H | 23:bb1535360a98 | 41 | this->Disquette.period_ms(20); |
| Wael_H | 10:efa507ba2b35 | 42 | } |
| Wael_H | 10:efa507ba2b35 | 43 | |
| Wael_H | 10:efa507ba2b35 | 44 | bool Robot::aBalle() |
| Wael_H | 10:efa507ba2b35 | 45 | { |
| Wael_H | 10:efa507ba2b35 | 46 | return BPs.read(); |
| Wael_H | 10:efa507ba2b35 | 47 | } |
| Wael_H | 10:efa507ba2b35 | 48 | |
| Wael_H | 19:dad67302af25 | 49 | /// Fonctions Odometrie /// |
| Wael_H | 19:dad67302af25 | 50 | void Robot::setPos(unsigned short x, unsigned short y, signed short theta) const |
| Wael_H | 19:dad67302af25 | 51 | { |
| Wael_H | 19:dad67302af25 | 52 | SetOdometrie(ODOMETRIE_POSITION, y, x, theta); // Oui les x et les y sont inversés... |
| Wael_H | 19:dad67302af25 | 53 | } |
| Wael_H | 19:dad67302af25 | 54 | |
| Wael_H | 10:efa507ba2b35 | 55 | /// retourne l'adresse de la premiere case d'un tableau contenant dans l'ordre la position en x et en y et l'angle theta /// |
| theolp | 20:a1b5d032b422 | 56 | short Robot::pos(T_POS pos) |
| Wael_H | 10:efa507ba2b35 | 57 | { |
| theolp | 20:a1b5d032b422 | 58 | return this->deplacement.getPos(pos); |
| Wael_H | 16:05665faaa489 | 59 | } |
| Wael_H | 16:05665faaa489 | 60 | |
| Wael_H | 10:efa507ba2b35 | 61 | |
| Wael_H | 10:efa507ba2b35 | 62 | /// Toutes les fonctions de déplacement /// |
| Wael_H | 15:3d4543a6c100 | 63 | bool Robot::avance(signed short dist) |
| Wael_H | 10:efa507ba2b35 | 64 | { |
| Wael_H | 10:efa507ba2b35 | 65 | return deplacement.avance(dist); |
| Wael_H | 10:efa507ba2b35 | 66 | } |
| Wael_H | 10:efa507ba2b35 | 67 | |
| Wael_H | 15:3d4543a6c100 | 68 | bool Robot::tourne(signed short angle) |
| Wael_H | 10:efa507ba2b35 | 69 | { |
| Wael_H | 10:efa507ba2b35 | 70 | return deplacement.tourne(angle); |
| Wael_H | 10:efa507ba2b35 | 71 | } |
| Wael_H | 10:efa507ba2b35 | 72 | |
| Wael_H | 15:3d4543a6c100 | 73 | bool Robot::GoToXYT(unsigned short x, unsigned short y, unsigned short t, signed char sens) //sens = 0 par défaut |
| Wael_H | 10:efa507ba2b35 | 74 | { |
| Wael_H | 10:efa507ba2b35 | 75 | return deplacement.GoToXYT(x,y,t,sens); |
| Wael_H | 10:efa507ba2b35 | 76 | } |
| Wael_H | 10:efa507ba2b35 | 77 | |
| Wael_H | 15:3d4543a6c100 | 78 | void Robot::setSpeed(unsigned short vitesse, unsigned short acceleration) const |
| Wael_H | 10:efa507ba2b35 | 79 | { |
| Wael_H | 10:efa507ba2b35 | 80 | SendSpeed(vitesse,acceleration); |
| Wael_H | 10:efa507ba2b35 | 81 | } |
| Wael_H | 10:efa507ba2b35 | 82 | |
| Wael_H | 13:9c62e263f245 | 83 | void Robot::stop() |
| Wael_H | 13:9c62e263f245 | 84 | { |
| Wael_H | 13:9c62e263f245 | 85 | deplacement.stop(); |
| Wael_H | 13:9c62e263f245 | 86 | } |
| Wael_H | 13:9c62e263f245 | 87 | |
| Wael_H | 10:efa507ba2b35 | 88 | |
| Wael_H | 10:efa507ba2b35 | 89 | /// Fonction distance lasers /// |
| Wael_H | 13:9c62e263f245 | 90 | float Robot::getDist(int laserENUM, string unite) //="cm" par défaut |
| Wael_H | 10:efa507ba2b35 | 91 | { |
| Wael_H | 10:efa507ba2b35 | 92 | switch(laserENUM) { |
| Wael_H | 13:9c62e263f245 | 93 | case Laser::Gauche: |
| Wael_H | 10:efa507ba2b35 | 94 | return this->laserG.getDist(unite); |
| Wael_H | 10:efa507ba2b35 | 95 | |
| Wael_H | 13:9c62e263f245 | 96 | case Laser::Droit: |
| Wael_H | 10:efa507ba2b35 | 97 | return this->laserD.getDist(unite); |
| Wael_H | 10:efa507ba2b35 | 98 | |
| Wael_H | 13:9c62e263f245 | 99 | case Laser::Arriere: |
| Wael_H | 10:efa507ba2b35 | 100 | return this->laserA.getDist(unite); |
| Wael_H | 10:efa507ba2b35 | 101 | } |
| Wael_H | 10:efa507ba2b35 | 102 | |
| Wael_H | 10:efa507ba2b35 | 103 | return 0; |
| Wael_H | 10:efa507ba2b35 | 104 | } |
| Wael_H | 10:efa507ba2b35 | 105 | |
| theolp | 20:a1b5d032b422 | 106 | /// Fonction CNY surBlanc ou pas /// |
| theolp | 20:a1b5d032b422 | 107 | bool Robot::surBlanc( T_CNY cny ) |
| theolp | 20:a1b5d032b422 | 108 | { |
| theolp | 21:9ff2eab240fb | 109 | static const float SEUIL_CNY_G = 0.7f, |
| theolp | 21:9ff2eab240fb | 110 | SEUIL_CNY_D = 0.7f; |
| theolp | 21:9ff2eab240fb | 111 | |
| theolp | 20:a1b5d032b422 | 112 | if( cny == Robot::CNY_GAUCHE ) |
| theolp | 20:a1b5d032b422 | 113 | return ( this->CNY_G >= SEUIL_CNY_G ); |
| theolp | 20:a1b5d032b422 | 114 | |
| theolp | 20:a1b5d032b422 | 115 | else if( cny == Robot::CNY_DROIT ) |
| theolp | 20:a1b5d032b422 | 116 | return ( this->CNY_D >= SEUIL_CNY_D ); |
| theolp | 20:a1b5d032b422 | 117 | |
| theolp | 20:a1b5d032b422 | 118 | else return false; |
| theolp | 20:a1b5d032b422 | 119 | } |
| Wael_H | 10:efa507ba2b35 | 120 | |
| Wael_H | 10:efa507ba2b35 | 121 | /// Fonctions Rouleau /// |
| Wael_H | 10:efa507ba2b35 | 122 | void Robot::ejecte(int vitesse) // vitesse max = 100 |
| Wael_H | 10:efa507ba2b35 | 123 | { |
| Wael_H | 10:efa507ba2b35 | 124 | rouleau.ejecte(vitesse); |
| Wael_H | 10:efa507ba2b35 | 125 | } |
| Wael_H | 10:efa507ba2b35 | 126 | |
| Wael_H | 10:efa507ba2b35 | 127 | void Robot::gobe(int vitesse) // vitesse max = 100 |
| Wael_H | 10:efa507ba2b35 | 128 | { |
| Wael_H | 10:efa507ba2b35 | 129 | rouleau.gobe(vitesse); |
| Wael_H | 10:efa507ba2b35 | 130 | } |
| Wael_H | 10:efa507ba2b35 | 131 | |
| Wael_H | 10:efa507ba2b35 | 132 | void Robot::stopRouleau() |
| Wael_H | 10:efa507ba2b35 | 133 | { |
| Wael_H | 10:efa507ba2b35 | 134 | rouleau.stop(); |
| Wael_H | 10:efa507ba2b35 | 135 | } |
| Wael_H | 23:bb1535360a98 | 136 | |
| Wael_H | 23:bb1535360a98 | 137 | /// Bras /// |
| Wael_H | 23:bb1535360a98 | 138 | bool Robot::leveBras() |
| Wael_H | 23:bb1535360a98 | 139 | { |
| Wael_H | 23:bb1535360a98 | 140 | static double posCerveau; |
| Wael_H | 23:bb1535360a98 | 141 | posCerveau = this->Cerveau_Bras; |
| Wael_H | 23:bb1535360a98 | 142 | |
| Wael_H | 23:bb1535360a98 | 143 | if(posCerveau <= 0.091f) |
| Wael_H | 23:bb1535360a98 | 144 | { |
| Wael_H | 23:bb1535360a98 | 145 | posCerveau += 0.001f; |
| Wael_H | 23:bb1535360a98 | 146 | this->Cerveau_Bras = posCerveau; |
| Wael_H | 23:bb1535360a98 | 147 | return false; |
| Wael_H | 23:bb1535360a98 | 148 | } |
| Wael_H | 23:bb1535360a98 | 149 | else return true; |
| Wael_H | 23:bb1535360a98 | 150 | } |
| Wael_H | 23:bb1535360a98 | 151 | |
| Wael_H | 23:bb1535360a98 | 152 | bool Robot::baisseBras() |
| Wael_H | 23:bb1535360a98 | 153 | { |
| Wael_H | 23:bb1535360a98 | 154 | static double posCerveau; |
| Wael_H | 23:bb1535360a98 | 155 | posCerveau = this->Cerveau_Bras; |
| Wael_H | 23:bb1535360a98 | 156 | |
| Wael_H | 23:bb1535360a98 | 157 | if(posCerveau >= 0.045f) |
| Wael_H | 23:bb1535360a98 | 158 | { |
| Wael_H | 23:bb1535360a98 | 159 | posCerveau -= 0.001f; |
| Wael_H | 23:bb1535360a98 | 160 | this->Cerveau_Bras = posCerveau; |
| Wael_H | 23:bb1535360a98 | 161 | return false; |
| Wael_H | 23:bb1535360a98 | 162 | } |
| Wael_H | 23:bb1535360a98 | 163 | else return true; |
| Wael_H | 23:bb1535360a98 | 164 | } |
| Wael_H | 23:bb1535360a98 | 165 | |
| Wael_H | 23:bb1535360a98 | 166 | void Robot::exploseBallon() |
| Wael_H | 23:bb1535360a98 | 167 | { |
| Wael_H | 23:bb1535360a98 | 168 | this->Disquette.write(0.5); |
| Wael_H | 23:bb1535360a98 | 169 | } |
| Wael_H | 23:bb1535360a98 | 170 | |
| Wael_H | 23:bb1535360a98 | 171 | void Robot::arreteDisquette() |
| Wael_H | 23:bb1535360a98 | 172 | { |
| Wael_H | 23:bb1535360a98 | 173 | this->Disquette.write(0); |
| Wael_H | 23:bb1535360a98 | 174 | } |