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: SRF08 Servo mbed
Revision 7:7d3c6326cbc3, committed 2017-06-26
- Comitter:
- Remi95
- Date:
- Mon Jun 26 09:58:11 2017 +0000
- Parent:
- 6:d61052f4ab1e
- Child:
- 8:ea8db9aacdfb
- Commit message:
- trkl;
Changed in this revision
--- a/CAR.cpp Mon Jun 26 06:36:03 2017 +0000
+++ b/CAR.cpp Mon Jun 26 09:58:11 2017 +0000
@@ -7,7 +7,7 @@
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
-DigitalOut S2 (p11);
+//DigitalOut S2 (p11);
//Serial bt(p13,p14);
Serial sbt(p9, p10); // tx, rx
@@ -73,7 +73,7 @@
{
emiss(0,Vit);
emiss(5,Vit);
- wait(0.125);
+ wait(0.250);
emiss(0,0);
emiss(5,0);
}
@@ -81,7 +81,7 @@
{
emiss(1,Vit);
emiss(4,Vit);
- wait(0.125);
+ wait(0.250); //0.125
emiss(1,0);
emiss(4,0);
}
--- a/SRF08.lib Mon Jun 26 06:36:03 2017 +0000 +++ b/SRF08.lib Mon Jun 26 09:58:11 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/brentdekker/code/SRF08/#a11bd4ea3c18 +http://developer.mbed.org/users/chris/code/SRF08/#ba04e9cd48fc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Mon Jun 26 09:58:11 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/simon/code/Servo/#29a602377f1a
--- a/main.cpp Mon Jun 26 06:36:03 2017 +0000
+++ b/main.cpp Mon Jun 26 09:58:11 2017 +0000
@@ -1,55 +1,132 @@
#include "mbed.h"
#include "CAR.h"
#include "SRF08.h"
+#include "Servo.h"
+DigitalOut S2 (p11);
+AnalogIn opt (p15);
Serial bth(p13,p14);
-SRF08 capteur_US(p28,p27,0x0E);
+//Serial sbt(p9, p10); // tx, rx
+SRF08 srf08(p28, p27, 0xE0);
+//Servo myservo(p26);
+
+float aMes[]= {0,0,0};
+PwmOut servo(p26);
+int iState = 1;
+bool bState =0;
+
+char Adress = 128;
+char action;
CAR robot(p9,p10);
//CAR robot;
-void act(char action) {
- switch(action) {
- case 'a':
- bth.printf("avancer\n\r");
- robot.avancer(70);
- break;
- case 's':
- bth.printf("stop\n\r");
- robot.arreter();
- break;
- case 'u':
- bth.printf("arret\n\r");
- robot.arreter();
+void act()
+{
+ action=bth.getc();
+ switch(action) {
+ case 'a':
+ bth.printf("avancer\n\r");
+ robot.avancer(70);
+ break;
+ case 's':
+ bth.printf("stop\n\r");
+ robot.arreter();
+ break;
+ case 'u':
+ bth.printf("arret\n\r");
+ robot.arreter();
+ break;
+ case 'r':
+ bth.printf("reculer\n\r");
+ robot.reculer(70);
+ break;
+ case 'd':
+ bth.printf("droite\n\r");
+ robot.tourner_droite(70);
+ break;
+ case 'g':
+ bth.printf("gauche\n\r");
+ robot.tourner_gauche(70);
+ break;
+ case 'h':
+ bth.printf("demi tour horaire\n\r");
+ robot.demi_tour_droite(100);
+ break;
+ case'l':
+ bth.printf("demi tour left\n\r");
+ robot.demi_tour_gauche(100);
+ break;
+ case not 'o':
+ bState = 0;
+ case 'o':
+ bState = !bState;
+ if (not bState) {
+ bth.printf("stop\n\r");
+ robot.arreter();
+ }
+ break;
+ }
+ action='0';
+}
+
+
+////////////////////////////////////////////
+
+int main()
+{
+ S2=0;
+ int visu;
+ bth.baud(57600);
+ bth.attach(&act);
+
+ servo.period(0.02);
+ while(1) {
+ bState = 1;
+ if (bState) {
+ switch (iState) {
+
+ case 0:
+
+ if (srf08.read() <60 and srf08.read() >0 ) {
+ iState = 1;
+ bth.printf("stop\n\r");
+ robot.arreter();
+ } else {
+ servo.write(0.08);
+ bth.printf("avancer\n\r");
+ robot.avancer(50);
+ }
break;
- case 'r':
- bth.printf("reculer\n\r");
- robot.reculer(70);
- break;
- case 'd':
- bth.printf("droite\n\r");
- robot.tourner_droite(70);
- break;
- case 'g':
- bth.printf("gauche\n\r");
- robot.tourner_gauche(70);
- break;
- case 'h':
- bth.printf("demi tour horaire\n\r");
- robot.demi_tour_droite(100);
- break;
- case'l':
- bth.printf("demi tour left\n\r");
- robot.demi_tour_gauche(100);
+
+ case 1 :
+ servo.write(0.05);
+ wait (0.2);
+ aMes[1] = srf08.read();
+
+ servo.write(0.1);
+ wait (0.2);
+ aMes[2]= srf08.read();
+
+ servo.write(0.08);
+
+ if (aMes[1] <100 and aMes[1] >0) {
+ action = 'g';
+ bth.printf("gauche\n\r");
+ robot.tourner_gauche(70);
+ } else if (aMes[2] <100 and aMes[2] >0) {
+ bth.printf("droite\n\r");
+ robot.tourner_droite(70);
+ } else {
+ bth.printf("demi tour horaire\n\r");
+ robot.demi_tour_droite(100);
+ }
+ iState = 0;
break;
}
- action='0';
}
-int main(void)
-{
- //S2=0;
- // CAR(p9,p10);
-
- while(1) {
-
+ visu=opt.read_u16();
+ visu=422006/(visu-3475);
+ bth.printf("Measured range : %.2f cm\n",srf08.read());
}
-}
+}
+