programme ines avce xbee

Dependencies:   MMA8451Q mbed xbee_lib

Fork of Programme_course by Freescale_Cachan

Committer:
inesmas3
Date:
Fri Mar 17 14:18:13 2017 +0000
Revision:
2:ddf9879f0e25
Programme ines avce le xbee

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inesmas3 2:ddf9879f0e25 1 /////////////////////* Fichier des fonctions Xbee adaptées à la course 2017 *//////////////////////////
inesmas3 2:ddf9879f0e25 2
inesmas3 2:ddf9879f0e25 3 #include "Mlib.h"
inesmas3 2:ddf9879f0e25 4
inesmas3 2:ddf9879f0e25 5
inesmas3 2:ddf9879f0e25 6 void Xbee_init()
inesmas3 2:ddf9879f0e25 7 {
inesmas3 2:ddf9879f0e25 8
inesmas3 2:ddf9879f0e25 9 // reset the xbees (at least 200ns)
inesmas3 2:ddf9879f0e25 10 rst1 = 0;
inesmas3 2:ddf9879f0e25 11 wait_ms(1);
inesmas3 2:ddf9879f0e25 12 rst1 = 1;
inesmas3 2:ddf9879f0e25 13 wait_ms(1);
inesmas3 2:ddf9879f0e25 14 }
inesmas3 2:ddf9879f0e25 15
inesmas3 2:ddf9879f0e25 16 int Xbee_receive()
inesmas3 2:ddf9879f0e25 17 {
inesmas3 2:ddf9879f0e25 18 int data3=0;
inesmas3 2:ddf9879f0e25 19 char receiveData[NB_CARAC];
inesmas3 2:ddf9879f0e25 20
inesmas3 2:ddf9879f0e25 21 xbee1.RecieveData(receiveData,NB_CARAC);
inesmas3 2:ddf9879f0e25 22
inesmas3 2:ddf9879f0e25 23 data3=atoi(receiveData);
inesmas3 2:ddf9879f0e25 24 pc.printf("Recu:%s,%d \n",receiveData,data3);
inesmas3 2:ddf9879f0e25 25
inesmas3 2:ddf9879f0e25 26 return data3;
inesmas3 2:ddf9879f0e25 27 }
inesmas3 2:ddf9879f0e25 28
inesmas3 2:ddf9879f0e25 29 void Xbee_send(int data)
inesmas3 2:ddf9879f0e25 30 {
inesmas3 2:ddf9879f0e25 31 char data0=0;
inesmas3 2:ddf9879f0e25 32 data0=char(data);
inesmas3 2:ddf9879f0e25 33
inesmas3 2:ddf9879f0e25 34 xbee1.SendData(&data0);
inesmas3 2:ddf9879f0e25 35 }
inesmas3 2:ddf9879f0e25 36
inesmas3 2:ddf9879f0e25 37 /* fonction qui permet d'initialiser les valeurs de VIT KP KI et KD via Xbee*/
inesmas3 2:ddf9879f0e25 38
inesmas3 2:ddf9879f0e25 39 int Get_values_Xbee()
inesmas3 2:ddf9879f0e25 40 {
inesmas3 2:ddf9879f0e25 41 int param =0;
inesmas3 2:ddf9879f0e25 42
inesmas3 2:ddf9879f0e25 43 pc.printf("en attente\n");
inesmas3 2:ddf9879f0e25 44
inesmas3 2:ddf9879f0e25 45 param= Xbee_receive();
inesmas3 2:ddf9879f0e25 46
inesmas3 2:ddf9879f0e25 47 switch(param) {
inesmas3 2:ddf9879f0e25 48
inesmas3 2:ddf9879f0e25 49 case VIT1:
inesmas3 2:ddf9879f0e25 50 pc.printf("en attente de la valeur de VIT\n");
inesmas3 2:ddf9879f0e25 51 if(Xbee_receive()!=0) {
inesmas3 2:ddf9879f0e25 52 VIT=Xbee_receive();
inesmas3 2:ddf9879f0e25 53 pc.printf("OK!!\n");
inesmas3 2:ddf9879f0e25 54 }
inesmas3 2:ddf9879f0e25 55
inesmas3 2:ddf9879f0e25 56 case KP1:
inesmas3 2:ddf9879f0e25 57 pc.printf("en attente de la valeur de KP\n");
inesmas3 2:ddf9879f0e25 58 if(Xbee_receive()!=0) {
inesmas3 2:ddf9879f0e25 59 KP=Xbee_receive();
inesmas3 2:ddf9879f0e25 60 pc.printf("OK!!\n");
inesmas3 2:ddf9879f0e25 61 }
inesmas3 2:ddf9879f0e25 62
inesmas3 2:ddf9879f0e25 63 case KD1:
inesmas3 2:ddf9879f0e25 64 pc.printf("en attente de la valeur de KD\n");
inesmas3 2:ddf9879f0e25 65 if(Xbee_receive()!=0) {
inesmas3 2:ddf9879f0e25 66 KD=Xbee_receive();
inesmas3 2:ddf9879f0e25 67 pc.printf("OK!!\n");
inesmas3 2:ddf9879f0e25 68 }
inesmas3 2:ddf9879f0e25 69
inesmas3 2:ddf9879f0e25 70 case KI1:
inesmas3 2:ddf9879f0e25 71 pc.printf("en attente de la valeur de KI\n");
inesmas3 2:ddf9879f0e25 72 if(Xbee_receive()!=0) {
inesmas3 2:ddf9879f0e25 73 KI=Xbee_receive();
inesmas3 2:ddf9879f0e25 74 pc.printf("OK!!\n");
inesmas3 2:ddf9879f0e25 75 }
inesmas3 2:ddf9879f0e25 76
inesmas3 2:ddf9879f0e25 77 }
inesmas3 2:ddf9879f0e25 78
inesmas3 2:ddf9879f0e25 79 }