programme ines avce xbee

Dependencies:   MMA8451Q mbed xbee_lib

Fork of Programme_course by Freescale_Cachan

Files at this revision

API Documentation at this revision

Comitter:
inesmas3
Date:
Fri Mar 17 14:18:13 2017 +0000
Parent:
1:4a9196bcf97a
Commit message:
Programme ines avce le xbee

Changed in this revision

Mlib.cpp Show annotated file Show diff for this revision Revisions of this file
Mlib.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
shield.cpp Show annotated file Show diff for this revision Revisions of this file
traitement_image.cpp Show annotated file Show diff for this revision Revisions of this file
xbee_lib.lib Show annotated file Show diff for this revision Revisions of this file
xbeemoi.cpp Show annotated file Show diff for this revision Revisions of this file
xbeemoi.h Show annotated file Show diff for this revision Revisions of this file
--- a/Mlib.cpp	Wed Feb 08 15:16:04 2017 +0000
+++ b/Mlib.cpp	Fri Mar 17 14:18:13 2017 +0000
@@ -8,10 +8,10 @@
         led6=0;
         led7=0;
     
-        pc.printf("bosse: %d , X: %1.2f , ajustement : %hi\n ",bosse,middle_3F(last_three),ajust_vit_bosse);
+        //pc.printf("bosse: %d , X: %1.2f , ajustement : %hi\n ",bosse,middle_3F(last_three),ajust_vit_bosse);
         
         
-        last_three[2] = last_three[1]; // les 3 dernieres valeurs de X sont stockées daans un tableau
+        last_three[2] = last_three[1]; // les 3 dernieres valeurs de X sont stockées dans un tableau
         last_three[1] = last_three[0];
         last_three[0] = acc.getAccX();
         
@@ -57,7 +57,7 @@
         {
             bosse=0;
             ajust_vit_bosse=0;
-            }
+        }
     }
 }
 
--- a/Mlib.h	Wed Feb 08 15:16:04 2017 +0000
+++ b/Mlib.h	Fri Mar 17 14:18:13 2017 +0000
@@ -6,6 +6,7 @@
 #include "mbed.h"
 #include "MMA8451Q.h"
 #include "motor.h"
+#include "xbee.h"
 
 #define MMA8451_I2C_ADRESS (0x1d<<1)
 
@@ -23,8 +24,17 @@
 #define CORRECTION_VIRAGE 1
 #define MAX_BATTERY 1.3
 #define SEUIL_NB_DERRIVEE 25
-#define KD 400
-#define KI 3
+//#define KD 600  //valeur de base 400
+//#define KI 3
+
+/* Constantes de prépro relatives à Xbee*/
+
+#define NB_CARAC 4
+#define VIT1 101
+#define KD1 102
+#define KP1 103
+#define KI1 104
+
 
 #define BOSSE_ACTIVE S2
 
@@ -58,7 +68,12 @@
 /**/    char Moyenne2(char *tab, int nb);           /**/
 /**/    void menu();                                /**/
 /**/    void init_bary();                           /**/
-/**/    void fin_course();                          /**/   
+/**/    void fin_course();                          /**/ 
+/*****  XBEE***/
+        int Xbee_receive();
+        void Xbee_send(int data);
+        void Xbee_init();  
+        int Get_values_Xbee();
 /******************************************************/
 
 /****************CAMERA****************/
@@ -81,8 +96,11 @@
 extern DigitalOut led2;
 extern DigitalOut led3;
 extern DigitalOut led4;
-extern DigitalIn S1; // switch 1
-extern DigitalIn S2; // switch 2
+extern DigitalOut led5;
+extern DigitalOut led6;
+extern DigitalOut led7;
+extern DigitalIn S1;
+extern DigitalIn S2;
 extern DigitalIn S3;
 extern DigitalIn S4;
 extern AnalogIn pot1;
@@ -108,18 +126,21 @@
 /*************AUTRES_VAR***************/
 extern Ticker t_cyc; 
 extern Serial pc;
+extern Serial dataXB;
 extern Timer t_debut;
 extern Timer t_ligne;
 extern Timer timer;
 extern int begin;
 extern int VIT;
 extern int KP;
+extern int KD;
+extern int KI;
 extern int ligne_droite;
 
+/**xbee*/
+extern xbee xbee1; //Initalise xbee_lib varName(rx,tx,reset)
+extern DigitalOut rst1;
 
-extern DigitalOut led5;
-extern DigitalOut led6;
-extern DigitalOut led7;
 
 
 
--- a/main.cpp	Wed Feb 08 15:16:04 2017 +0000
+++ b/main.cpp	Fri Mar 17 14:18:13 2017 +0000
@@ -13,6 +13,8 @@
 DigitalOut led6(PTB19);
 DigitalOut led7(PTD1);
 
+DigitalOut rst1(D3);
+
 AnalogIn pot1 (PTB3);
 AnalogIn pot2 (PTB2);
 
@@ -24,7 +26,6 @@
 Timer timer;
 int ralentire = 0;
 
-
 int tempsInte = MAX_INTE;
 unsigned char cam_data[128];
 int baricentre = 0;
@@ -40,6 +41,8 @@
 int somme_derivee = 0;
 int VIT = 0;
 int KP = 80;
+int KD=0;
+int KI=0;
 int seuil_der = 0;
 int ajust_vitesse = 0;
 int ajust_vit_bosse = 0;
@@ -61,6 +64,8 @@
 Ticker t_finInte;
 
 Serial pc(USBTX, USBRX);
+xbee xbee1(D1,D0,D3); //Initalise xbee_lib varName(rx,tx,reset)
+Serial dataXB(D1,D0);
 
 
 void cycle()
@@ -76,8 +81,9 @@
 
     init_bary();
 
-    Get_pot_value();
-    
+    //Get_pot_value();
+    Get_values_Xbee();
+    pc.printf("VIT=%d KD=%d KP=%d KI=%d \n", VIT,KP,KD,KI);
     t_cyc.attach_us(&cycle, FRQ_CYC);//interruption cycle
     
     clk_active = 0;//L'horloge est désactivée
@@ -85,7 +91,7 @@
     
     timer.start();
 
-   angle_servo_moteur(0);//on met les roues droite pour commencer
+   angle_servo_moteur(0);//on met les roues droites pour commencer
 }
 
 void arret()
@@ -101,15 +107,18 @@
 
 
 int main() {
+  
+  Xbee_init();
+  
+     
+Init_car();
+   
     
-/*while(1)
-{ Gestion_bosse();
-wait(0.1);}*/
-    Init_car();
     
     while(!BP1)//tant que l'on appuie pas sur BP1
     {
         menu();
+        
     }
     while(BP1);//on attends le relachement de BP1
 
@@ -126,9 +135,12 @@
     PWM_motor(MOTEUR_B, VIT);
     
     while(1) {//boucle principale
+    
+        
         if(BP1)
         {
             arret();
+            
         }
         if(flag == 1)//début du cycle
         {
@@ -138,6 +150,8 @@
             
             F_GetData();
             
+            Xbee_receive();
+             
             //***************Traitement Image*******************
             
             T_image();
--- a/shield.cpp	Wed Feb 08 15:16:04 2017 +0000
+++ b/shield.cpp	Fri Mar 17 14:18:13 2017 +0000
@@ -11,7 +11,7 @@
     
     pc.printf("%hi\n", ajust_vit_bosse);
     
-    while(bosse==1) {PWM_motor(100,100);} // acceleration à diminuer pour la competition
+    while(bosse==1) {PWM_motor(90,90);} // acceleration à diminuer pour la competition
     
     while(bosse==3) {PWM_motor(30,30);}
     
@@ -63,9 +63,10 @@
     VIT = 0, KP = 0;
     for(int i = 0; i < 10; i++)
     {
-       VIT += ((pot1.read()+1)*(25.0));
+       //VIT += ((pot1.read()+1)*(25.0));
         KP += ((pot2.read()+1)*100); 
     }
-    VIT /= 10;
-    pc.printf("VIT=%d\nKP=%d\n",VIT,KP); 
+    //VIT /= 10;
+   // pc.printf("VIT=%d\nKP=%d\n",VIT,KP); 
 }
+
--- a/traitement_image.cpp	Wed Feb 08 15:16:04 2017 +0000
+++ b/traitement_image.cpp	Fri Mar 17 14:18:13 2017 +0000
@@ -71,7 +71,7 @@
         baricentre = (mem_b - mem_a);    
         //baricentre = -baricentre;
     }
-} 
+    }
 
 void F_BalanceBlancs()
 {
@@ -105,7 +105,7 @@
     last_bari = bari_bis;
     
     led4 = ralentire;
-    if(S3)//gestion des lignes droite
+    if(S3)//gestion des lignes droites
     {
         if(abs(new_bari) < 15 && ligne_droite < 10 && ralentire == 0)
         {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbee_lib.lib	Fri Mar 17 14:18:13 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tristanjph/code/xbee_lib/#ede20c047d8b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbeemoi.cpp	Fri Mar 17 14:18:13 2017 +0000
@@ -0,0 +1,79 @@
+/////////////////////* Fichier des fonctions Xbee adaptées à la course 2017 *//////////////////////////
+
+#include "Mlib.h"
+
+
+void Xbee_init()
+{
+
+    // reset the xbees (at least 200ns)
+    rst1 = 0;
+    wait_ms(1);
+    rst1 = 1;
+    wait_ms(1);
+}
+
+int Xbee_receive()
+{
+    int data3=0;
+    char receiveData[NB_CARAC];
+
+    xbee1.RecieveData(receiveData,NB_CARAC);
+
+    data3=atoi(receiveData);
+    pc.printf("Recu:%s,%d \n",receiveData,data3);
+
+    return data3;
+}
+
+void Xbee_send(int data)
+{
+    char data0=0;
+    data0=char(data);
+
+    xbee1.SendData(&data0);
+}
+
+/* fonction qui permet d'initialiser les valeurs de VIT KP KI et KD via Xbee*/
+
+int Get_values_Xbee()
+{
+    int param =0;
+
+    pc.printf("en attente\n");
+
+    param= Xbee_receive();
+
+    switch(param) {
+
+        case VIT1:
+            pc.printf("en attente de la valeur de VIT\n");
+            if(Xbee_receive()!=0) {
+                VIT=Xbee_receive();
+                pc.printf("OK!!\n");
+            }
+
+        case KP1:
+            pc.printf("en attente de la valeur de KP\n");
+            if(Xbee_receive()!=0) {
+                KP=Xbee_receive();
+                pc.printf("OK!!\n");
+            }
+
+        case KD1:
+            pc.printf("en attente de la valeur de KD\n");
+            if(Xbee_receive()!=0) {
+                KD=Xbee_receive();
+                pc.printf("OK!!\n");
+            }
+
+        case KI1:
+            pc.printf("en attente de la valeur de KI\n");
+            if(Xbee_receive()!=0) {
+                KI=Xbee_receive();
+                pc.printf("OK!!\n");
+            }
+
+    }
+
+}
\ No newline at end of file