v7

Dependents:   robot_final

Committer:
fab16
Date:
Thu Mar 16 13:29:05 2017 +0000
Revision:
6:9d4190ab2739
Parent:
5:152295068384
Child:
7:fa09588320d0
projet v1 fonctionnel sans bluethoot

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
fab16 3:3f75a7741b8f 40 void Robot::action(int idAction){
fab16 3:3f75a7741b8f 41
fab16 3:3f75a7741b8f 42 switch(idAction){
fab16 3:3f75a7741b8f 43
fab16 3:3f75a7741b8f 44 // deplacement simple
fab16 3:3f75a7741b8f 45 case 0 :
fab16 3:3f75a7741b8f 46 {
fab16 5:152295068384 47 if(obstacle==false){
fab16 5:152295068384 48 this->deplacement.avancer();
fab16 5:152295068384 49 break;
fab16 5:152295068384 50 }
fab16 3:3f75a7741b8f 51 }
fab16 3:3f75a7741b8f 52
fab16 3:3f75a7741b8f 53 case 1 :
fab16 3:3f75a7741b8f 54 {
fab16 3:3f75a7741b8f 55 this->deplacement.droite();
fab16 3:3f75a7741b8f 56 break;
fab16 3:3f75a7741b8f 57 }
fab16 3:3f75a7741b8f 58
fab16 3:3f75a7741b8f 59 case 2 :
fab16 3:3f75a7741b8f 60 {
fab16 3:3f75a7741b8f 61 this->deplacement.reculer();
fab16 3:3f75a7741b8f 62 break;
fab16 3:3f75a7741b8f 63 }
fab16 3:3f75a7741b8f 64
fab16 3:3f75a7741b8f 65 case 3 :
fab16 3:3f75a7741b8f 66 {
fab16 3:3f75a7741b8f 67 this->deplacement.gauche();
fab16 3:3f75a7741b8f 68 break;
fab16 3:3f75a7741b8f 69 }
fab16 3:3f75a7741b8f 70
fab16 3:3f75a7741b8f 71 case 4 :
fab16 3:3f75a7741b8f 72 {
fab16 3:3f75a7741b8f 73 this->deplacement.tourner_gauche();
fab16 3:3f75a7741b8f 74 break;
fab16 3:3f75a7741b8f 75 }
fab16 3:3f75a7741b8f 76
fab16 3:3f75a7741b8f 77 case 5 :
fab16 3:3f75a7741b8f 78 {
fab16 3:3f75a7741b8f 79 this->deplacement.tourner_droite();
fab16 3:3f75a7741b8f 80 break;
fab16 3:3f75a7741b8f 81 }
fab16 3:3f75a7741b8f 82
fab16 3:3f75a7741b8f 83 // pattern
fab16 3:3f75a7741b8f 84
fab16 3:3f75a7741b8f 85 case 6 :
fab16 3:3f75a7741b8f 86 {
fab16 5:152295068384 87 if(obstacle==false){
fab16 5:152295068384 88 this->pattern.carre();
fab16 5:152295068384 89 break;
fab16 5:152295068384 90 }
fab16 3:3f75a7741b8f 91 }
fab16 3:3f75a7741b8f 92
fab16 3:3f75a7741b8f 93 case 7 :
fab16 3:3f75a7741b8f 94 {
fab16 5:152295068384 95 if(obstacle==false){
fab16 5:152295068384 96 this->pattern.triangle();
fab16 5:152295068384 97 break;
fab16 5:152295068384 98 }
fab16 3:3f75a7741b8f 99 }
fab16 3:3f75a7741b8f 100
fab16 3:3f75a7741b8f 101 // led
fab16 3:3f75a7741b8f 102 case 8 :
fab16 3:3f75a7741b8f 103 {
fab16 3:3f75a7741b8f 104 this->led.K1000(1);
fab16 3:3f75a7741b8f 105 break;
fab16 3:3f75a7741b8f 106 }
fab16 3:3f75a7741b8f 107
fab16 3:3f75a7741b8f 108 case 9 :
fab16 3:3f75a7741b8f 109 {
fab16 3:3f75a7741b8f 110 this->led.K2000(1);
fab16 3:3f75a7741b8f 111 break;
fab16 3:3f75a7741b8f 112 }
fab16 3:3f75a7741b8f 113
fab16 3:3f75a7741b8f 114 case 10 :
fab16 3:3f75a7741b8f 115 {
fab16 3:3f75a7741b8f 116 this->led.K3000(1);
fab16 3:3f75a7741b8f 117 break;
fab16 3:3f75a7741b8f 118 }
fab16 3:3f75a7741b8f 119
fab16 3:3f75a7741b8f 120 case 11 :
fab16 3:3f75a7741b8f 121 {
fab16 3:3f75a7741b8f 122 this->led.K4000(1);
fab16 3:3f75a7741b8f 123 break;
fab16 3:3f75a7741b8f 124 }
fab16 3:3f75a7741b8f 125
fab16 3:3f75a7741b8f 126 case 12 :
fab16 3:3f75a7741b8f 127 {
fab16 3:3f75a7741b8f 128 this->led.LED_desynchrone(1);
fab16 3:3f75a7741b8f 129 break;
fab16 3:3f75a7741b8f 130 }
fab16 3:3f75a7741b8f 131
fab16 3:3f75a7741b8f 132 case 13 :
fab16 3:3f75a7741b8f 133 {
fab16 3:3f75a7741b8f 134 this->led.LED_Blinking(DigitalOut (LED1),1);
fab16 3:3f75a7741b8f 135 break;
fab16 3:3f75a7741b8f 136 }
fab16 3:3f75a7741b8f 137
fab16 3:3f75a7741b8f 138 case 14 :
fab16 3:3f75a7741b8f 139 {
fab16 3:3f75a7741b8f 140 this->led.LED_Blinking(DigitalOut (LED2),1);
fab16 3:3f75a7741b8f 141 break;
fab16 3:3f75a7741b8f 142 }
fab16 3:3f75a7741b8f 143
fab16 3:3f75a7741b8f 144 case 15 :
fab16 3:3f75a7741b8f 145 {
fab16 3:3f75a7741b8f 146 this->led.LED_Blinking(DigitalOut (LED3),1);
fab16 3:3f75a7741b8f 147 break;
fab16 3:3f75a7741b8f 148 }
fab16 3:3f75a7741b8f 149
fab16 3:3f75a7741b8f 150 case 16 :
fab16 3:3f75a7741b8f 151 {
fab16 3:3f75a7741b8f 152 this->led.LED_Blinking(DigitalOut (LED4),1);
fab16 3:3f75a7741b8f 153 break;
fab16 3:3f75a7741b8f 154 }
fab16 3:3f75a7741b8f 155
fab16 3:3f75a7741b8f 156
fab16 3:3f75a7741b8f 157 // affichage
fab16 3:3f75a7741b8f 158
fab16 3:3f75a7741b8f 159 case 17 :
fab16 3:3f75a7741b8f 160 {
fab16 3:3f75a7741b8f 161 this->affichage.bonjour();
fab16 3:3f75a7741b8f 162 break;
fab16 3:3f75a7741b8f 163 }
fab16 3:3f75a7741b8f 164 }
fab16 3:3f75a7741b8f 165
fab16 3:3f75a7741b8f 166 }
fab16 3:3f75a7741b8f 167
fab16 4:c8ae1b606d51 168 void Robot::utiliserUltrason(){
fab16 4:c8ae1b606d51 169 affichage.effacerTout();
fab16 4:c8ae1b606d51 170 float result = srf.read();
fab16 4:c8ae1b606d51 171 //m3piR.printf("%.1f",result);
fab16 4:c8ae1b606d51 172 affichage.affichageUltrason(result);
fab16 5:152295068384 173
fab16 5:152295068384 174 if(result <= 8){
fab16 5:152295068384 175 obstacle = true;
fab16 5:152295068384 176 }
fab16 5:152295068384 177 else{
fab16 5:152295068384 178 obstacle = false;
fab16 5:152295068384 179 }
fab16 5:152295068384 180
fab16 5:152295068384 181 affichage.afficherObstacle(obstacle);
fab16 6:9d4190ab2739 182
fab16 5:152295068384 183 }
fab16 5:152295068384 184
fab16 5:152295068384 185 void Robot::afficherObstacle(){
fab16 5:152295068384 186 affichage.afficherObstacle(obstacle);
fab16 3:3f75a7741b8f 187 }
fab16 4:c8ae1b606d51 188
fab16 5:152295068384 189 void Robot::scanneEnvironement(){
fab16 5:152295068384 190
fab16 5:152295068384 191 for(int i=1; i<4; i++){
fab16 5:152295068384 192
fab16 5:152295068384 193 utiliserUltrason();
fab16 5:152295068384 194
fab16 5:152295068384 195 if(obstacle==true){
fab16 5:152295068384 196 tabObstacle[i]=true;
fab16 5:152295068384 197 }
fab16 5:152295068384 198 else{
fab16 5:152295068384 199 tabObstacle[i]=false;
fab16 5:152295068384 200 }
fab16 5:152295068384 201
fab16 5:152295068384 202 obstacle=false;
fab16 5:152295068384 203 wait(1);
fab16 5:152295068384 204 deplacement.quartRotation();
fab16 5:152295068384 205 wait(2);
fab16 5:152295068384 206 }
fab16 5:152295068384 207 deplacement.quartRotation();
fab16 6:9d4190ab2739 208
fab16 5:152295068384 209 }