Andreu- Felix

Dependencies:   SRF08 mbed

Files at this revision

API Documentation at this revision

Comitter:
yannickrda
Date:
Mon Jul 03 10:13:36 2017 +0000
Commit message:
Final!!!

Changed in this revision

SRF08.lib Show annotated file Show diff for this revision Revisions of this file
commande.cpp Show annotated file Show diff for this revision Revisions of this file
commande.h 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 afd478f066b0 SRF08.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SRF08.lib	Mon Jul 03 10:13:36 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/chris/code/SRF08/#ba04e9cd48fc
diff -r 000000000000 -r afd478f066b0 commande.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/commande.cpp	Mon Jul 03 10:13:36 2017 +0000
@@ -0,0 +1,114 @@
+#include "mbed.h"
+#include "commande.h"
+
+#define adr 128
+using namespace std;
+
+
+DigitalOut S2(p11);
+Serial com_mot(p9,p10);
+
+void avancerG(char speed)
+{
+    com_mot.putc(adr);
+    com_mot.putc(1);
+    com_mot.putc(speed);
+    com_mot.putc((adr + 1 + speed) & 127); //checksum trame envoyée / reçue 
+}
+void avancerD(char speed)
+{
+    com_mot.putc(adr);
+    com_mot.putc(4);
+    com_mot.putc(speed);
+    com_mot.putc((adr + 4 + speed) & 127); //checksum trame envoyée / reçue 
+}
+void reculerG(char speed)
+{
+    com_mot.putc(adr);
+    com_mot.putc(0);
+    com_mot.putc(speed);
+    com_mot.putc((adr + 0 + speed) & 127); //checksum trame envoyée / reçue 
+}
+void reculerD(char speed)
+{
+    com_mot.putc(adr);
+    com_mot.putc(5);
+    com_mot.putc(speed);
+    com_mot.putc((adr + 5 + speed) & 127); //checksum trame envoyée / reçue 
+}
+//////////////Fonction Finale///////////////
+
+///////Marche avant////////
+void dem(char speed)
+{
+    int i;speed=speed*0.1;
+    for(i=0;i<100;i++)
+    {
+    avancerG(speed);wait(0.001);
+    avancerD(speed);speed++;
+    wait(0.01);
+    }
+    avancerG(speed);wait(0.001);
+    avancerD(speed);
+}
+void commande::avance(char speed)
+{
+    avancerG(speed);wait(0.001);
+    avancerD(speed);
+}
+
+//////Fonction avancer//////
+void commande::avancer(char speed)
+{
+    dem(speed);avance(speed);
+}
+//////////Marche arriere//////////
+void demar(char speed)
+{
+    int i;
+    speed=speed*0.1;
+    for(i=0;i<100;i++)
+    {
+    reculerG(speed);wait(0.001);
+    reculerD(speed);speed=speed++;
+    wait(0.01);
+    }
+}
+void commande::recu(char speed)
+{
+    reculerG(speed);wait(0.001);
+    reculerD(speed);
+}
+//////Fonction reculer//////
+void commande::reculer(char speed)
+{
+    demar(speed);recu(speed);
+}
+//////virage/////////////////
+void commande::tourner_droite(char speed)
+{
+    avancerG(speed);wait(0.001);
+    reculerD(speed);
+}
+void commande::tourner_gauche(char speed)
+{
+    avancerD(speed);wait(0.001);
+    reculerG(speed);
+}
+
+void commande::demi_tour(void)
+{
+    avancerD(50);wait(0.001);
+    reculerG(50);
+    wait(1.3);
+    avancerD(0);wait(0.001);
+    reculerG(0);
+}
+
+void commande::stop(void)
+{
+    avancerD(0);wait(0.001);
+    reculerG(0);
+}
+//////Fonction arret//////
+//void arreter(void)
diff -r 000000000000 -r afd478f066b0 commande.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/commande.h	Mon Jul 03 10:13:36 2017 +0000
@@ -0,0 +1,25 @@
+#ifndef DEF_COMMANDE
+#define DEF_COMMANDE
+
+#include <string>
+
+
+class commande
+{
+    public:
+    //commande();
+    void avancer(char speed);
+    void avance(char speed);
+    void reculer(char speed);
+    void recu(char speed);
+    void tourner_droite(char speed);
+    void tourner_gauche(char speed);
+    void demi_tour(void);
+    void stop(void);
+    
+    private:
+    char speed;
+       
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r afd478f066b0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 03 10:13:36 2017 +0000
@@ -0,0 +1,136 @@
+#include "mbed.h"
+#include "commande.h"
+#include <SRF08.h>
+#define adr 128
+
+//***************************************************
+//************** Déclaration des objets *************
+//***************************************************
+
+Serial bt(p13, p14);
+PwmOut pwm(p26); //objet
+Serial pc(USBTX,USBRX);
+SRF08 capt(p28,p27,0xE0);
+AnalogIn optique(p15);
+
+commande robot;
+
+//***************************************************
+//************** Prototypes fonctions ***************
+//***************************************************
+
+void PWM(void); // prototype fonction (cfr bas)
+void acqui(void);
+void autonomie(void);
+
+
+//***************************************************
+//**************** Variables Gobales ****************
+//***************************************************
+
+float pulse;
+int distance;
+unsigned c;
+float droite, gauche,devant,capteur;
+int right,left,straight,vu;
+
+//***************************************************
+//********************** MAIN ***********************
+//***************************************************
+
+int main()
+{
+    bt.baud(57600);
+    while(1)
+    {
+        autonomie();
+        /*while(1){
+        char choix = bt.getc();
+
+                if(choix=='0'){
+                    robot.avancer(50);bt.printf("avance\n");}
+                else if(choix=='1'){
+                    robot.reculer(50);bt.printf("recule\n");}
+                else if(choix=='2'){
+                    robot.tourner_gauche(60);bt.printf("gauche\n");} 
+                else if(choix=='3'){
+                    robot.tourner_droite(60);bt.printf("droite\n");} 
+                else if(choix=='4'){
+                    robot.stop();bt.printf("stop\n\r");}
+                else if(choix=='5')
+                    break;
+        }*/
+    }
+}
+
+//****************************************************
+//******************** Fonctions *********************
+//****************************************************
+
+
+/*void direction ( int x) //objectif faire le CHOIX de la meilleure direction
+{
+    if((straight < (left + 10)) && (straight < (right + 10))
+        {robot.avancer(50);bt.printf("avance\n");}
+    if((left > (right + 15)) && (left >= (straight + 15))){ // pourquoi le + XX ? parce que le capteur est trop sensible pour varier suivant l'unité choisie
+        robot.tourner_droite(60);bt.printf("droite\n"); // comparaison capteur relevé devant, à gauche et à droite, => la valeur la plus faible (= obstacle le + loin) l'emporte
+        robot.avancer(50);bt.printf("avance\n");}
+    if((right > (left + 15)) && (right >= (straight + 15))){
+        robot.tourner_gauche(60);bt.printf("gauche\n");
+        robot.avancer(50);bt.printf("avance\n");}
+}*/
+void autonomie()
+{
+    pwm.period_ms(20);  //définition da la largeur de l'impulsion: 20 ms
+    pulse=0.0715;
+    
+    while(1)
+    {
+            
+        pulse=0.0715;pwm.write(pulse);acqui(); //capteur centre
+        devant=vu; straight=capteur;
+        if(straight>50)
+            robot.avance(50);
+        while(devant<60  && straight<50)
+            {
+                robot.stop();
+                pulse=0.095;wait(0.03);pwm.write(pulse);acqui(); //capteur gauche
+                gauche=vu; left=capteur;
+                  
+                pulse=0.048;wait(0.03);pwm.write(pulse);acqui(); //dcapteur roite
+                droite=vu; right=capteur;
+                
+                if(gauche<droite)
+                    {
+                        robot.tourner_gauche(40);
+                        wait(0.6);
+                        robot.stop();
+                    }
+                else if(gauche>droite)
+                    {
+                        robot.tourner_droite(40);
+                        wait(0.6);
+                        robot.stop();
+                    }
+                pulse=0.0715;wait(0.03);pwm.write(pulse);acqui(); //capteur centre
+                devant=vu; straight=capteur; 
+            }
+    }   
+}
+/*
+        pulse=0.095;pwm.write(pulse);acqui(); //gauche
+        gauche=vu; left=capteur;
+        pulse=0.0715;pwm.write(pulse);acqui(); //centre
+        devant=vu; straight=capteur;
+        pulse=0.048;pwm.write(pulse);acqui(); //droite
+        droite=vu; right=capteur;*/
+
+void acqui()
+{
+        vu = optique.read_u16();
+        vu = 422006/(vu-3475);
+        capteur = capt.read();
+        bt.printf("Sonar : %f.2\n",capt.read());
+        bt.printf("Optique : %d\n",vu);
+        wait(0.1);
+}
diff -r 000000000000 -r afd478f066b0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jul 03 10:13:36 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/4eea097334d6
\ No newline at end of file