![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TP_presa
Dependencies: SRF08 Servo mbed
Diff: main.cpp
- Revision:
- 3:0b19b5b7c3a4
- Parent:
- 2:6d12c2d70f19
- Child:
- 4:aafb0016ed84
diff -r 6d12c2d70f19 -r 0b19b5b7c3a4 main.cpp --- a/main.cpp Wed May 31 18:33:54 2017 +0000 +++ b/main.cpp Wed May 31 18:35:50 2017 +0000 @@ -16,7 +16,7 @@ DigitalOut myled4(LED4); DigitalOut S2 (p11); - +int iCoefVirage=0.44; void Led (bool l1,bool l2,bool l3,bool l4){ //Fonction pour aider au debug avec les led myled1=l1; @@ -35,6 +35,20 @@ emiss(0,Vit); emiss(4,Vit); } +void myVirageGauche (char Vit , char Ang){ + emiss(1,Vit); + emiss(4,Vit); + wait((Ang*iCoefVirage)/Vit); //Le coeficient 0.5 est a réler en fonction de la batterie et de la voiture. + emiss(1,0); + emiss(4,0); + } +void myVirageDroite (char Vit , char Ang){ + emiss(0,Vit); + emiss(5,Vit); + wait((Ang*iCoefVirage)/Vit); + emiss(1,0); + emiss(4,0); + } void avancer(char Vit) { int i=0; for(i; i<Vit ; i=i+(Vit/5));{ @@ -77,52 +91,20 @@ emiss(4,0); } void demi_tour_droite(char Vit) { - emiss(0,Vit); - emiss(5,Vit); - wait(0.75); - emiss(0,0); - emiss(5,0); +myVirageDroite(Vit,180); } void demi_tour_gauche(char Vit) { - emiss(1,Vit); - emiss(4,Vit); - wait(0.75); - emiss(1,0); - emiss(4,0); + myVirageGauche(Vit,180); } -void myVG (char Vit , char Ang){ - emiss(1,Vit); - emiss(4,Vit); - wait((Ang*0.44)/Vit); - emiss(1,0); - emiss(4,0); - } + int main (){ while (1){ - Led (1,0,0,0); + Led (1,1,1,0); S2=0; wait(1); - avancer(70); + demi_tour_droite(100); Led (1,1,0,0); wait(1); - arreter(70); - wait(0.5); - reculer(70); - Led (1,1,1,0); - wait(1); - arret_urgence(); - wait(0.5); - tourner_gauche(120); - Led (1,1,1,1); - wait(1); - tourner_droite(120); - Led (0,1,1,1); - wait(1); - demi_tour_gauche(120); - Led (0,0,1,1); - wait(1); - demi_tour_droite(120); - Led (0,0,0,1); - + demi_tour_gauche(70); } }