![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
coucou bob
Revision 0:e9a025a937b4, committed 2018-12-17
- Comitter:
- pirottealex
- Date:
- Mon Dec 17 16:50:36 2018 +0000
- Commit message:
- robot play azur festival
Changed in this revision
diff -r 000000000000 -r e9a025a937b4 fct.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fct.cpp Mon Dec 17 16:50:36 2018 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "fct.h" + + +void vitmoteur(float VitG, float VitD) +{ + if(VitG<0) { + VitG=-1*VitG; + cmdI2C=cmdI2C&0xfe; //passe le moteur gauche en marche arriere 00000001 + } else { + cmdI2C=cmdI2C|0x01; // marche avant 11110111 mot gauche + } + if(VitD<0) { + VitD=-1*VitD; + cmdI2C=cmdI2C&0xfd; //passe le moteur gauche en marche arriere 00000100 + } else { + cmdI2C=cmdI2C|0x02;//marche avant 11111011 mot droit + } + monI2C.write(ADR_PCF,&cmdI2C,1); + MotG.pulsewidth(((100-VitG)/100.0)*PERIOD); + MotD.pulsewidth(((100-VitD)/100.0)*PERIOD); +} + + +void init(void) +{ + + MotG.period(PERIOD); + MotD.period(PERIOD); + vitmoteur(0,0); +} + + + \ No newline at end of file
diff -r 000000000000 -r e9a025a937b4 fct.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fct.h Mon Dec 17 16:50:36 2018 +0000 @@ -0,0 +1,31 @@ +#ifndef FCT_H +#define FCT_H + + +extern char cmdI2C ;// CS vbat x x x SensG SensD CS_G CD_D, sens moteur positif CS à 0. +extern PwmOut MotD; +extern PwmOut MotG; + +//GLOBALES + + +extern I2C monI2C; + + + + +//CONSTANTES +#define ADR_PCF 0x70 +#define PERIOD 0.0001 +#define V_max 30 +#define V_recherche 18 +#define K 0.1 +#define V_moy 25 + + +//PROTOTYPES +void vitmoteur(float,float); +void init(void); + + +#endif
diff -r 000000000000 -r e9a025a937b4 globals.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/globals.cpp Mon Dec 17 16:50:36 2018 +0000 @@ -0,0 +1,8 @@ +#include "mbed.h" +char cmdI2C=0xF3 ;// CS vbat x x x SensG SensD CS_G CD_D, sens moteur positif CS à 0. +PwmOut MotD(p25); +PwmOut MotG(p22); + +I2C monI2C(p9,p10); + +
diff -r 000000000000 -r e9a025a937b4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 17 16:50:36 2018 +0000 @@ -0,0 +1,131 @@ +#include "mbed.h" +#include "fct.h" +#define TIC_POSITION 0.0005 +#define PERIOD_SERVO 0.01999 + +Serial pc(USBTX, USBRX); // tx, rx - Liaison série +Serial device(p28, p27); // tx, rx - Liaison série +DigitalOut Servo(p21); + +char c; +char msg[15]; +int count=0; +char *token; +int MG, MD, bout1,bout2,bp; +Ticker tic1; +Timer t_servo; +int POSITION; +float KVIT=1; +void servo_position( void) +{ + float t = t_servo.read(); + if(t>=PERIOD_SERVO) + { + t_servo.reset(); + } + if(t>=0.001+(POSITION /100000.0)) + { + Servo.write(0); + } + else + { + Servo.write(1); + } +} + + +int main() +{ + + init(); + pc.baud(19200); + device.baud(2400); + device.format(8,SerialBase::None,2); + vitmoteur(0,0); + t_servo.start(); + tic1.attach(&servo_position,TIC_POSITION); + while(1) { + + if(bout1==1) + { + POSITION=-35; + } + else + { + POSITION=80; + } + if(bout2==1) + { + KVIT=1.5; + } + else + { + KVIT=1; + } + if(device.readable()) + { + c=device.getc(); + if(c=='*') + { + msg[count] = c; + if(count>=7) + { + + pc.printf("msg = %s\n\r",msg); + + token = strtok(msg," *"); + //printf("token = %s\n\r",token); + MG= atoi(token); + //printf("MG=%d\n\r",MG); + + token = strtok(NULL, " *"); + //printf("token = %s\n\r",token); + MD= atoi(token); + //printf("MD=%d\n\r",MD); + + token = strtok(NULL, " *"); + //printf("token = %s\n\r",token); + bout1= atoi(token); + //printf("bout1=%d\n\r",bout1); + + token = strtok(NULL, " *"); + //printf("token = %s\n\r",token); + bout2= atoi(token); + //printf("bout2=%d\n\r",bout2); + + vitmoteur(MG*KVIT,MD*KVIT); + + for (int i=0; i<15; i++) + { + msg[i]=0; + } + count=0; + } + else + { + for (int i=0; i<15; i++) + { + msg[i]=0; + } + count=0; + //vitmoteur(0,0); + } + } + else + { + + msg[count] = c; + //pc.printf("%c\n\r",c); + //pc.putc(device.getc()); + count=count+1; + + if(count>13) { + for (int i=0; i<15; i++) { + msg[i]=0; + } + count=0; + } + } + } + } +}
diff -r 000000000000 -r e9a025a937b4 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Dec 17 16:50:36 2018 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27 \ No newline at end of file