v7

Dependents:   robot_final

Committer:
aure
Date:
Thu Mar 23 12:47:04 2017 +0000
Revision:
10:d88127a08e44
Parent:
9:aff70d8f388a
jgjgj

Who changed what in which revision?

UserRevisionLine numberNew 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 6:9d4190ab2739 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 5:152295068384 14 /* for(int i=0; i<4; i++){
fab16 5:152295068384 15 this->tabObstacle[i]=false;
fab16 5:152295068384 16 }*/
fab16 5:152295068384 17
fab16 1:b3c45f39e86e 18 }
fab16 1:b3c45f39e86e 19
fab16 1:b3c45f39e86e 20 Robot::~Robot(){
fab16 1:b3c45f39e86e 21 // TODO fermer connexion bluetooth
fab16 1:b3c45f39e86e 22 }
fab16 1:b3c45f39e86e 23
fab16 2:c17925c0ce25 24 Affichage Robot::getAffichage(){
fab16 2:c17925c0ce25 25 return affichage;
fab16 2:c17925c0ce25 26 }
fab16 2:c17925c0ce25 27
fab16 2:c17925c0ce25 28 LED Robot::getLed(){
fab16 2:c17925c0ce25 29 return led;
fab16 2:c17925c0ce25 30 }
fab16 2:c17925c0ce25 31
fab16 2:c17925c0ce25 32 Deplacement Robot::getDeplacement(){
fab16 2:c17925c0ce25 33 return deplacement;
fab16 2:c17925c0ce25 34 }
fab16 3:3f75a7741b8f 35
fab16 3:3f75a7741b8f 36 Pattern Robot::getPattern(){
fab16 3:3f75a7741b8f 37 return pattern;
fab16 3:3f75a7741b8f 38 }
fab16 3:3f75a7741b8f 39
aure 10:d88127a08e44 40 void Robot::action(char idAction,char mode,char vitesse){
aure 10:d88127a08e44 41 float temps;
fab16 9:aff70d8f388a 42
aure 10:d88127a08e44 43 if(mode=='m'){
aure 10:d88127a08e44 44 temps =0.1;
fab16 9:aff70d8f388a 45 }
fab16 9:aff70d8f388a 46 else{
fab16 9:aff70d8f388a 47 temps = 2;
fab16 9:aff70d8f388a 48 }
fab16 9:aff70d8f388a 49
aure 10:d88127a08e44 50 switch(vitesse)
aure 10:d88127a08e44 51 {
aure 10:d88127a08e44 52 case '1':deplacement.setVitesse(0.1);
aure 10:d88127a08e44 53 break;
aure 10:d88127a08e44 54 case '2':deplacement.setVitesse(0.25);
aure 10:d88127a08e44 55 break;
aure 10:d88127a08e44 56 case '3':deplacement.setVitesse(0.5);
aure 10:d88127a08e44 57 break;
aure 10:d88127a08e44 58 case '4':deplacement.setVitesse(0.75);
aure 10:d88127a08e44 59 break;
aure 10:d88127a08e44 60 case '5':deplacement.setVitesse(1);
aure 10:d88127a08e44 61 break;
aure 10:d88127a08e44 62 default:deplacement.setVitesse(0.1);
aure 10:d88127a08e44 63 break;
aure 10:d88127a08e44 64
aure 10:d88127a08e44 65 }
aure 10:d88127a08e44 66
fab16 3:3f75a7741b8f 67 switch(idAction){
fab16 3:3f75a7741b8f 68
fab16 3:3f75a7741b8f 69 // deplacement simple
fab16 7:fa09588320d0 70 case 'a' :
fab16 3:3f75a7741b8f 71 {
fab16 5:152295068384 72 if(obstacle==false){
fab16 9:aff70d8f388a 73 this->deplacement.avancer(temps);
fab16 5:152295068384 74 break;
fab16 5:152295068384 75 }
fab16 3:3f75a7741b8f 76 }
fab16 3:3f75a7741b8f 77
fab16 7:fa09588320d0 78 case 'b' :
fab16 3:3f75a7741b8f 79 {
fab16 9:aff70d8f388a 80 this->deplacement.droite(temps);
fab16 3:3f75a7741b8f 81 break;
fab16 3:3f75a7741b8f 82 }
fab16 3:3f75a7741b8f 83
fab16 7:fa09588320d0 84 case 'c' :
fab16 3:3f75a7741b8f 85 {
fab16 9:aff70d8f388a 86 this->deplacement.reculer(temps);
fab16 3:3f75a7741b8f 87 break;
fab16 3:3f75a7741b8f 88 }
fab16 3:3f75a7741b8f 89
fab16 7:fa09588320d0 90 case 'd' :
fab16 3:3f75a7741b8f 91 {
fab16 9:aff70d8f388a 92 this->deplacement.gauche(temps);
fab16 3:3f75a7741b8f 93 break;
fab16 3:3f75a7741b8f 94 }
fab16 3:3f75a7741b8f 95
fab16 7:fa09588320d0 96 case 'e':
fab16 3:3f75a7741b8f 97 {
fab16 3:3f75a7741b8f 98 this->deplacement.tourner_gauche();
fab16 3:3f75a7741b8f 99 break;
fab16 3:3f75a7741b8f 100 }
fab16 3:3f75a7741b8f 101
fab16 7:fa09588320d0 102 case 'f' :
fab16 3:3f75a7741b8f 103 {
fab16 3:3f75a7741b8f 104 this->deplacement.tourner_droite();
fab16 3:3f75a7741b8f 105 break;
fab16 3:3f75a7741b8f 106 }
fab16 3:3f75a7741b8f 107
fab16 3:3f75a7741b8f 108 // pattern
fab16 3:3f75a7741b8f 109
fab16 7:fa09588320d0 110 case 'g' :
fab16 3:3f75a7741b8f 111 {
fab16 5:152295068384 112 if(obstacle==false){
fab16 5:152295068384 113 this->pattern.carre();
fab16 5:152295068384 114 break;
fab16 5:152295068384 115 }
fab16 3:3f75a7741b8f 116 }
fab16 3:3f75a7741b8f 117
fab16 7:fa09588320d0 118 case 'h' :
fab16 3:3f75a7741b8f 119 {
fab16 5:152295068384 120 if(obstacle==false){
fab16 5:152295068384 121 this->pattern.triangle();
fab16 5:152295068384 122 break;
fab16 5:152295068384 123 }
fab16 3:3f75a7741b8f 124 }
fab16 3:3f75a7741b8f 125
fab16 8:9d0e8da27044 126 case 'i' :
fab16 8:9d0e8da27044 127 {
fab16 8:9d0e8da27044 128 this->pattern.rectangle();
fab16 8:9d0e8da27044 129 break;
fab16 8:9d0e8da27044 130 }
fab16 8:9d0e8da27044 131
fab16 3:3f75a7741b8f 132 // led
fab16 8:9d0e8da27044 133 case 'j' :
fab16 3:3f75a7741b8f 134 {
fab16 3:3f75a7741b8f 135 this->led.K1000(1);
fab16 3:3f75a7741b8f 136 break;
fab16 3:3f75a7741b8f 137 }
fab16 3:3f75a7741b8f 138
fab16 8:9d0e8da27044 139 case 'k' :
fab16 3:3f75a7741b8f 140 {
fab16 3:3f75a7741b8f 141 this->led.K2000(1);
fab16 3:3f75a7741b8f 142 break;
fab16 3:3f75a7741b8f 143 }
fab16 3:3f75a7741b8f 144
fab16 8:9d0e8da27044 145 case 'l' :
fab16 3:3f75a7741b8f 146 {
fab16 3:3f75a7741b8f 147 this->led.K3000(1);
fab16 3:3f75a7741b8f 148 break;
fab16 3:3f75a7741b8f 149 }
fab16 3:3f75a7741b8f 150
fab16 8:9d0e8da27044 151 case 'm' :
fab16 3:3f75a7741b8f 152 {
fab16 3:3f75a7741b8f 153 this->led.K4000(1);
fab16 3:3f75a7741b8f 154 break;
fab16 3:3f75a7741b8f 155 }
fab16 3:3f75a7741b8f 156
fab16 8:9d0e8da27044 157 case 'n' :
fab16 3:3f75a7741b8f 158 {
fab16 3:3f75a7741b8f 159 this->led.LED_desynchrone(1);
fab16 3:3f75a7741b8f 160 break;
fab16 3:3f75a7741b8f 161 }
fab16 3:3f75a7741b8f 162
fab16 8:9d0e8da27044 163 case 'o' :
fab16 3:3f75a7741b8f 164 {
fab16 3:3f75a7741b8f 165 this->led.LED_Blinking(DigitalOut (LED1),1);
fab16 3:3f75a7741b8f 166 break;
fab16 3:3f75a7741b8f 167 }
fab16 3:3f75a7741b8f 168
fab16 8:9d0e8da27044 169 case 'p' :
fab16 3:3f75a7741b8f 170 {
fab16 3:3f75a7741b8f 171 this->led.LED_Blinking(DigitalOut (LED2),1);
fab16 3:3f75a7741b8f 172 break;
fab16 3:3f75a7741b8f 173 }
fab16 3:3f75a7741b8f 174
fab16 8:9d0e8da27044 175 case 'q' :
fab16 3:3f75a7741b8f 176 {
fab16 3:3f75a7741b8f 177 this->led.LED_Blinking(DigitalOut (LED3),1);
fab16 3:3f75a7741b8f 178 break;
fab16 3:3f75a7741b8f 179 }
fab16 3:3f75a7741b8f 180
fab16 8:9d0e8da27044 181 case 'r' :
fab16 3:3f75a7741b8f 182 {
fab16 3:3f75a7741b8f 183 this->led.LED_Blinking(DigitalOut (LED4),1);
fab16 3:3f75a7741b8f 184 break;
fab16 3:3f75a7741b8f 185 }
fab16 3:3f75a7741b8f 186
fab16 3:3f75a7741b8f 187
fab16 3:3f75a7741b8f 188 // affichage
fab16 3:3f75a7741b8f 189
fab16 8:9d0e8da27044 190 case 's' :
fab16 3:3f75a7741b8f 191 {
fab16 3:3f75a7741b8f 192 this->affichage.bonjour();
fab16 3:3f75a7741b8f 193 break;
fab16 3:3f75a7741b8f 194 }
fab16 3:3f75a7741b8f 195 }
fab16 3:3f75a7741b8f 196
fab16 3:3f75a7741b8f 197 }
fab16 3:3f75a7741b8f 198
fab16 4:c8ae1b606d51 199 void Robot::utiliserUltrason(){
fab16 4:c8ae1b606d51 200 affichage.effacerTout();
fab16 4:c8ae1b606d51 201 float result = srf.read();
fab16 4:c8ae1b606d51 202 //m3piR.printf("%.1f",result);
fab16 4:c8ae1b606d51 203 affichage.affichageUltrason(result);
fab16 5:152295068384 204
fab16 5:152295068384 205 if(result <= 8){
fab16 5:152295068384 206 obstacle = true;
fab16 5:152295068384 207 }
fab16 5:152295068384 208 else{
fab16 5:152295068384 209 obstacle = false;
fab16 5:152295068384 210 }
fab16 5:152295068384 211
fab16 5:152295068384 212 affichage.afficherObstacle(obstacle);
fab16 6:9d4190ab2739 213
fab16 5:152295068384 214 }
fab16 5:152295068384 215
fab16 5:152295068384 216 void Robot::afficherObstacle(){
fab16 5:152295068384 217 affichage.afficherObstacle(obstacle);
fab16 3:3f75a7741b8f 218 }
fab16 4:c8ae1b606d51 219
fab16 5:152295068384 220 void Robot::scanneEnvironement(){
fab16 5:152295068384 221
fab16 5:152295068384 222 for(int i=1; i<4; i++){
fab16 5:152295068384 223
fab16 5:152295068384 224 utiliserUltrason();
fab16 5:152295068384 225
fab16 5:152295068384 226 if(obstacle==true){
fab16 5:152295068384 227 tabObstacle[i]=true;
fab16 5:152295068384 228 }
fab16 5:152295068384 229 else{
fab16 5:152295068384 230 tabObstacle[i]=false;
fab16 5:152295068384 231 }
fab16 5:152295068384 232
fab16 5:152295068384 233 obstacle=false;
fab16 5:152295068384 234 wait(1);
fab16 5:152295068384 235 deplacement.quartRotation();
fab16 5:152295068384 236 wait(2);
fab16 5:152295068384 237 }
fab16 5:152295068384 238 deplacement.quartRotation();
fab16 6:9d4190ab2739 239
fab16 5:152295068384 240 }