Robot fou

Dependencies:   SRF05 mbed

Files at this revision

API Documentation at this revision

Comitter:
Mattei
Date:
Fri Jun 01 08:27:06 2018 +0000
Commit message:
v2;

Changed in this revision

SRF05.lib Show annotated file Show diff for this revision Revisions of this file
func.cpp Show annotated file Show diff for this revision Revisions of this file
func.h Show annotated file Show diff for this revision Revisions of this file
globals.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8b7645cd8a39 SRF05.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SRF05.lib	Fri Jun 01 08:27:06 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/SRF05/#e758665e072c
diff -r 000000000000 -r 8b7645cd8a39 func.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/func.cpp	Fri Jun 01 08:27:06 2018 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+#include "func.h"
+#include "time.h"
+
+int etat=0;
+
+float distance=32;
+int vitrand1=(rand()%60)+20;
+int vitrand2=(rand()%60)+20;
+int cligne=rand()%15;
+int td12=0;
+
+
+void vite(void){
+    MotD.pulsewidth_us(vitrand1);
+    MotG.pulsewidth_us(vitrand2);
+    vitrand1=(rand()%50)+30;
+    vitrand2=(rand()%50)+30;
+}
+
+void attend(void){
+    if(vitrand1>vitrand2){
+        wait(40*1/vitrand1);
+    }
+    else wait(40*1/vitrand2);
+}
+
+void clignote(void){
+    cligne=rand()%15;
+    leds.write(cligne);
+}
+
+void fou(void){
+    distance=srf.read();
+    switch(etat){
+            case 0 : if(distance > 45){ etat = 1; }; break;
+            case 1 : if(distance < 45){ etat = 0; }; break;
+        }
+        
+    switch(etat){
+            case 0 : t2.detach();
+                     td12=0;
+                     SensG.write(1);
+                     SensD.write(0);
+                     MotD.pulsewidth_us(50);
+                     MotG.pulsewidth_us(50);
+                     attend();
+                     break;
+            case 1 : if(td12==0){SensD.write(0); SensG.write(0); t2.attach(&vite,0.5); td12=1;} break;
+        }
+       /* printf("sensrand = %d\n\r",sensrand);
+        printf("vitrand = %d\n\r",vitrand);
+        */
+        
+        printf("Tension Batterie:%g\n\r",(Vbat.read()*13300*3.3)/3300);
+        //wait(1);
+        wait_ms(30);
+}
\ No newline at end of file
diff -r 000000000000 -r 8b7645cd8a39 func.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/func.h	Fri Jun 01 08:27:06 2018 +0000
@@ -0,0 +1,22 @@
+#ifndef func_h
+#define func_h
+
+#include "SRF05.h"
+
+extern SRF05 srf;
+extern DigitalOut SensD;
+extern DigitalOut SensG;
+extern PwmOut MotD;
+extern PwmOut MotG;
+//extern Ticker t1;
+extern Ticker t2;
+extern BusOut leds;
+extern AnalogIn Vbat;
+
+void clignote(void);
+void attend(void);
+void fou(void);
+//void sens(void);
+void vite(void);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 8b7645cd8a39 globals.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/globals.cpp	Fri Jun 01 08:27:06 2018 +0000
@@ -0,0 +1,16 @@
+#include "mbed.h"
+#include "SRF05.h"
+
+
+//Affectation broches capteur distance
+SRF05 srf(p27, p28);
+
+//Affectation broches moteurs
+DigitalOut SensD(p11);
+DigitalOut SensG(p12);
+BusOut leds(LED1,LED2,LED3,LED4);
+PwmOut MotD(p22);
+PwmOut MotG(p23);
+AnalogIn Vbat(p15);
+//Ticker t1;
+Ticker t2;
\ No newline at end of file
diff -r 000000000000 -r 8b7645cd8a39 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 01 08:27:06 2018 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+#include "func.h"
+#include "time.h"
+
+
+int main() {
+    srand(time(NULL));
+    MotD.period_us(100);
+    MotG.period_us(100);
+    SensD.write(0);
+    SensG.write(0);
+    t2.attach(&vite,1.0);
+    while(1) {
+        clignote();
+        fou();
+    }
+}
diff -r 000000000000 -r 8b7645cd8a39 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 01 08:27:06 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee
\ No newline at end of file