Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-os nRF24L01P
Diff: main.cpp
- Revision:
- 12:1378fba9c916
- Parent:
- 10:0312e23ba3a1
- Child:
- 13:50de0cf096d1
diff -r 5f2289e0d0e8 -r 1378fba9c916 main.cpp --- a/main.cpp Fri Mar 11 09:50:01 2022 +0000 +++ b/main.cpp Thu Jun 02 17:00:35 2022 +0000 @@ -16,35 +16,42 @@ #include "float.h" #include "MX12.h" #include "stdio.h" +#include "DRIBBLE.h" BufferedSerial pc_serie(USBTX,USBRX,115200); nRF24L01P my_nrf24l01p(D11, D12, D13, D9, D2, D1); // mosi, miso, sck, csn, ce, irq DigitalOut maled2(LED2); +DigitalOut charge(D0); +DigitalOut tir(D3); +DigitalOut dd(D15); + +Thread reception_thread; +Thread tir_thread; +Thread dribble_thread; -int main() -{ +#define TRANSFER_SIZE 14 -#define TRANSFER_SIZE 12 - - char chaine[50]; + char chaine[150]; char tampon; char* reception8; + + int16_t Vavance, Vlat,Wz,idcharge,idtir,dribble,idrobot; + int i; int16_t reception16[TRANSFER_SIZE/2]; - reception8 = (char*) reception16; - int16_t Vavance, Vlat,Wz; - int i; + +void reception() +{ my_nrf24l01p.powerUp(); - my_nrf24l01p.setRfFrequency(2420); + my_nrf24l01p.setRfFrequency(2424); my_nrf24l01p.setAirDataRate(1000); my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); my_nrf24l01p.setReceiveMode(); my_nrf24l01p.setCrcWidth(0); my_nrf24l01p.setRxAddress(); - my_nrf24l01p.enable(); - + my_nrf24l01p.enable(); pc_serie.write("Je suis le robot de Eve", strlen("Je suis le robot de Eve")); @@ -53,7 +60,6 @@ while (1) { - if (my_nrf24l01p.readable()) { maled2 = !maled2; my_nrf24l01p.read( NRF24L01P_PIPE_P0, reception8, TRANSFER_SIZE ); @@ -61,19 +67,54 @@ tampon = reception8[i+1]; reception8[i+1] = reception8 [i]; reception8[i]= tampon; - } - + } + idrobot = reception16[6]; + if (idrobot==1){ + Vavance = reception16[0]; Vlat = reception16[1]; Wz = reception16[2]; + idcharge = reception16[3]; + idtir = reception16[4]; + dribble = reception16[5]; - sprintf(chaine," Vav = %d, Vlat = %d, Wz = %d\n\r",(int)Vavance, (int)Vlat, (int)Wz); + //alors là c'est juste un test mais il y a quasi aucune chance que ça marche + sprintf(chaine," Vav = %d, Vlat = %d, Wz = %d, dribble= %d, idtir= %d, idcharge= %d, idrobot= %d \n\r",(int)Vavance, (int)Vlat, (int)Wz, (int)dribble, (int)idtir, (int)idcharge, (int)idrobot); pc_serie.write(chaine, strlen(chaine)); - servo_bus.cmd_moteur(Vavance/1000.0, Vlat/1000.0, Wz); - + + servo_bus.cmd_moteur(Vavance/1000.0, Vlat/1000.0, Wz/1000.0); + //a bouger + //charge=(idcharge!=0); + charge=(idcharge==1); + ThisThread::sleep_for(10ms); + charge=0; + //dd.SetSpeed(dribble); + //tir=1; + } } } } +void Dribble(){ + while(1){ + dd=(dribble!=0); + }} +void Tir(){ + while(1){ + if (idtir!=0){ + tir = 1 ; + ThisThread::sleep_for(idtir); + tir = 0 ; + } + tir=0;} +} + +int main(){ + +reception8 = (char*) reception16; +reception_thread.start(reception); +dribble_thread.start(Dribble); +tir_thread.start(Tir); +} \ No newline at end of file