v7
Robot.cpp@4:c8ae1b606d51, 2017-03-02 (annotated)
- Committer:
- fab16
- Date:
- Thu Mar 02 12:30:14 2017 +0000
- Revision:
- 4:c8ae1b606d51
- Parent:
- 3:3f75a7741b8f
- Child:
- 5:152295068384
robot v3;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fab16 | 0:3cb651f7347b | 1 | #include "Robot.h" |
fab16 | 3:3f75a7741b8f | 2 | #include "m3pi.h" |
fab16 | 3:3f75a7741b8f | 3 | |
fab16 | 4:c8ae1b606d51 | 4 | m3pi m3piR; |
fab16 | 4:c8ae1b606d51 | 5 | SRF05 srf(p21,p22); |
fab16 | 0:3cb651f7347b | 6 | |
fab16 | 1:b3c45f39e86e | 7 | Robot::Robot(){ |
fab16 | 2:c17925c0ce25 | 8 | obstacle = false; |
fab16 | 2:c17925c0ce25 | 9 | Affichage affichage; |
fab16 | 2:c17925c0ce25 | 10 | LED led; |
fab16 | 2:c17925c0ce25 | 11 | Deplacement deplacement; |
fab16 | 3:3f75a7741b8f | 12 | Pattern pattern; |
fab16 | 4:c8ae1b606d51 | 13 | |
fab16 | 1:b3c45f39e86e | 14 | } |
fab16 | 1:b3c45f39e86e | 15 | |
fab16 | 1:b3c45f39e86e | 16 | Robot::~Robot(){ |
fab16 | 1:b3c45f39e86e | 17 | // TODO fermer connexion bluetooth |
fab16 | 1:b3c45f39e86e | 18 | } |
fab16 | 1:b3c45f39e86e | 19 | |
fab16 | 2:c17925c0ce25 | 20 | Affichage Robot::getAffichage(){ |
fab16 | 2:c17925c0ce25 | 21 | return affichage; |
fab16 | 2:c17925c0ce25 | 22 | } |
fab16 | 2:c17925c0ce25 | 23 | |
fab16 | 2:c17925c0ce25 | 24 | LED Robot::getLed(){ |
fab16 | 2:c17925c0ce25 | 25 | return led; |
fab16 | 2:c17925c0ce25 | 26 | } |
fab16 | 2:c17925c0ce25 | 27 | |
fab16 | 2:c17925c0ce25 | 28 | Deplacement Robot::getDeplacement(){ |
fab16 | 2:c17925c0ce25 | 29 | return deplacement; |
fab16 | 2:c17925c0ce25 | 30 | } |
fab16 | 3:3f75a7741b8f | 31 | |
fab16 | 3:3f75a7741b8f | 32 | Pattern Robot::getPattern(){ |
fab16 | 3:3f75a7741b8f | 33 | return pattern; |
fab16 | 3:3f75a7741b8f | 34 | } |
fab16 | 3:3f75a7741b8f | 35 | |
fab16 | 3:3f75a7741b8f | 36 | void Robot::action(int idAction){ |
fab16 | 3:3f75a7741b8f | 37 | |
fab16 | 3:3f75a7741b8f | 38 | switch(idAction){ |
fab16 | 3:3f75a7741b8f | 39 | |
fab16 | 3:3f75a7741b8f | 40 | // deplacement simple |
fab16 | 3:3f75a7741b8f | 41 | case 0 : |
fab16 | 3:3f75a7741b8f | 42 | { |
fab16 | 3:3f75a7741b8f | 43 | this->deplacement.avancer(); |
fab16 | 3:3f75a7741b8f | 44 | break; |
fab16 | 3:3f75a7741b8f | 45 | } |
fab16 | 3:3f75a7741b8f | 46 | |
fab16 | 3:3f75a7741b8f | 47 | case 1 : |
fab16 | 3:3f75a7741b8f | 48 | { |
fab16 | 3:3f75a7741b8f | 49 | this->deplacement.droite(); |
fab16 | 3:3f75a7741b8f | 50 | break; |
fab16 | 3:3f75a7741b8f | 51 | } |
fab16 | 3:3f75a7741b8f | 52 | |
fab16 | 3:3f75a7741b8f | 53 | case 2 : |
fab16 | 3:3f75a7741b8f | 54 | { |
fab16 | 3:3f75a7741b8f | 55 | this->deplacement.reculer(); |
fab16 | 3:3f75a7741b8f | 56 | break; |
fab16 | 3:3f75a7741b8f | 57 | } |
fab16 | 3:3f75a7741b8f | 58 | |
fab16 | 3:3f75a7741b8f | 59 | case 3 : |
fab16 | 3:3f75a7741b8f | 60 | { |
fab16 | 3:3f75a7741b8f | 61 | this->deplacement.gauche(); |
fab16 | 3:3f75a7741b8f | 62 | break; |
fab16 | 3:3f75a7741b8f | 63 | } |
fab16 | 3:3f75a7741b8f | 64 | |
fab16 | 3:3f75a7741b8f | 65 | case 4 : |
fab16 | 3:3f75a7741b8f | 66 | { |
fab16 | 3:3f75a7741b8f | 67 | this->deplacement.tourner_gauche(); |
fab16 | 3:3f75a7741b8f | 68 | break; |
fab16 | 3:3f75a7741b8f | 69 | } |
fab16 | 3:3f75a7741b8f | 70 | |
fab16 | 3:3f75a7741b8f | 71 | case 5 : |
fab16 | 3:3f75a7741b8f | 72 | { |
fab16 | 3:3f75a7741b8f | 73 | this->deplacement.tourner_droite(); |
fab16 | 3:3f75a7741b8f | 74 | break; |
fab16 | 3:3f75a7741b8f | 75 | } |
fab16 | 3:3f75a7741b8f | 76 | |
fab16 | 3:3f75a7741b8f | 77 | // pattern |
fab16 | 3:3f75a7741b8f | 78 | |
fab16 | 3:3f75a7741b8f | 79 | case 6 : |
fab16 | 3:3f75a7741b8f | 80 | { |
fab16 | 3:3f75a7741b8f | 81 | this->pattern.carre(); |
fab16 | 3:3f75a7741b8f | 82 | break; |
fab16 | 3:3f75a7741b8f | 83 | } |
fab16 | 3:3f75a7741b8f | 84 | |
fab16 | 3:3f75a7741b8f | 85 | case 7 : |
fab16 | 3:3f75a7741b8f | 86 | { |
fab16 | 3:3f75a7741b8f | 87 | this->pattern.triangle(); |
fab16 | 3:3f75a7741b8f | 88 | break; |
fab16 | 3:3f75a7741b8f | 89 | } |
fab16 | 3:3f75a7741b8f | 90 | |
fab16 | 3:3f75a7741b8f | 91 | // led |
fab16 | 3:3f75a7741b8f | 92 | case 8 : |
fab16 | 3:3f75a7741b8f | 93 | { |
fab16 | 3:3f75a7741b8f | 94 | this->led.K1000(1); |
fab16 | 3:3f75a7741b8f | 95 | break; |
fab16 | 3:3f75a7741b8f | 96 | } |
fab16 | 3:3f75a7741b8f | 97 | |
fab16 | 3:3f75a7741b8f | 98 | case 9 : |
fab16 | 3:3f75a7741b8f | 99 | { |
fab16 | 3:3f75a7741b8f | 100 | this->led.K2000(1); |
fab16 | 3:3f75a7741b8f | 101 | break; |
fab16 | 3:3f75a7741b8f | 102 | } |
fab16 | 3:3f75a7741b8f | 103 | |
fab16 | 3:3f75a7741b8f | 104 | case 10 : |
fab16 | 3:3f75a7741b8f | 105 | { |
fab16 | 3:3f75a7741b8f | 106 | this->led.K3000(1); |
fab16 | 3:3f75a7741b8f | 107 | break; |
fab16 | 3:3f75a7741b8f | 108 | } |
fab16 | 3:3f75a7741b8f | 109 | |
fab16 | 3:3f75a7741b8f | 110 | case 11 : |
fab16 | 3:3f75a7741b8f | 111 | { |
fab16 | 3:3f75a7741b8f | 112 | this->led.K4000(1); |
fab16 | 3:3f75a7741b8f | 113 | break; |
fab16 | 3:3f75a7741b8f | 114 | } |
fab16 | 3:3f75a7741b8f | 115 | |
fab16 | 3:3f75a7741b8f | 116 | case 12 : |
fab16 | 3:3f75a7741b8f | 117 | { |
fab16 | 3:3f75a7741b8f | 118 | this->led.LED_desynchrone(1); |
fab16 | 3:3f75a7741b8f | 119 | break; |
fab16 | 3:3f75a7741b8f | 120 | } |
fab16 | 3:3f75a7741b8f | 121 | |
fab16 | 3:3f75a7741b8f | 122 | case 13 : |
fab16 | 3:3f75a7741b8f | 123 | { |
fab16 | 3:3f75a7741b8f | 124 | this->led.LED_Blinking(DigitalOut (LED1),1); |
fab16 | 3:3f75a7741b8f | 125 | break; |
fab16 | 3:3f75a7741b8f | 126 | } |
fab16 | 3:3f75a7741b8f | 127 | |
fab16 | 3:3f75a7741b8f | 128 | case 14 : |
fab16 | 3:3f75a7741b8f | 129 | { |
fab16 | 3:3f75a7741b8f | 130 | this->led.LED_Blinking(DigitalOut (LED2),1); |
fab16 | 3:3f75a7741b8f | 131 | break; |
fab16 | 3:3f75a7741b8f | 132 | } |
fab16 | 3:3f75a7741b8f | 133 | |
fab16 | 3:3f75a7741b8f | 134 | case 15 : |
fab16 | 3:3f75a7741b8f | 135 | { |
fab16 | 3:3f75a7741b8f | 136 | this->led.LED_Blinking(DigitalOut (LED3),1); |
fab16 | 3:3f75a7741b8f | 137 | break; |
fab16 | 3:3f75a7741b8f | 138 | } |
fab16 | 3:3f75a7741b8f | 139 | |
fab16 | 3:3f75a7741b8f | 140 | case 16 : |
fab16 | 3:3f75a7741b8f | 141 | { |
fab16 | 3:3f75a7741b8f | 142 | this->led.LED_Blinking(DigitalOut (LED4),1); |
fab16 | 3:3f75a7741b8f | 143 | break; |
fab16 | 3:3f75a7741b8f | 144 | } |
fab16 | 3:3f75a7741b8f | 145 | |
fab16 | 3:3f75a7741b8f | 146 | |
fab16 | 3:3f75a7741b8f | 147 | // affichage |
fab16 | 3:3f75a7741b8f | 148 | |
fab16 | 3:3f75a7741b8f | 149 | case 17 : |
fab16 | 3:3f75a7741b8f | 150 | { |
fab16 | 3:3f75a7741b8f | 151 | this->affichage.bonjour(); |
fab16 | 3:3f75a7741b8f | 152 | break; |
fab16 | 3:3f75a7741b8f | 153 | } |
fab16 | 3:3f75a7741b8f | 154 | } |
fab16 | 3:3f75a7741b8f | 155 | |
fab16 | 3:3f75a7741b8f | 156 | } |
fab16 | 3:3f75a7741b8f | 157 | |
fab16 | 4:c8ae1b606d51 | 158 | void Robot::utiliserUltrason(){ |
fab16 | 4:c8ae1b606d51 | 159 | affichage.effacerTout(); |
fab16 | 4:c8ae1b606d51 | 160 | float result = srf.read(); |
fab16 | 4:c8ae1b606d51 | 161 | //m3piR.printf("%.1f",result); |
fab16 | 4:c8ae1b606d51 | 162 | affichage.affichageUltrason(result); |
fab16 | 3:3f75a7741b8f | 163 | } |
fab16 | 4:c8ae1b606d51 | 164 | |
fab16 | 3:3f75a7741b8f | 165 | |
fab16 | 2:c17925c0ce25 | 166 |