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
main.cpp
- Committer:
- evedelegue
- Date:
- 2022-10-13
- Revision:
- 14:1b41c5adf46e
- Parent:
- 13:50de0cf096d1
File content as of revision 14:1b41c5adf46e:
/* RobotCup ENS Paris Saclay 2020-2021 Team FC Furious Code by Luc DERRIEN adapted by Eve Programme communication PC-Robot Point de vue : PC micro controleur : L475 envoi d'une chaine de caractère de taille TRANSFER_SIZE */ #include "mbed.h" #include "string.h" #include "nRF24L01P.h" #include "float.h" #include "MX12.h" #include "stdio.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; #define TRANSFER_SIZE 14 char chaine[150]; char tampon; char* reception8; int16_t Vavance, Vlat,Wz,idcharge,idtir,dribble,idrobot; int i; int16_t reception16[TRANSFER_SIZE/2]; void reception() { my_nrf24l01p.powerUp(); 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(); pc_serie.write("Je suis le robot de Eve", strlen("Je suis le robot de Eve")); maled2 = 1; MX12 servo_bus(PC_4, PC_5, 115200); while (1) { if (my_nrf24l01p.readable()) { maled2 = !maled2; my_nrf24l01p.read( NRF24L01P_PIPE_P0, reception8, TRANSFER_SIZE ); for (i=0 ; i<TRANSFER_SIZE;i+=2){ tampon = reception8[i+1]; reception8[i+1] = reception8 [i]; reception8[i]= tampon; } idrobot = reception16[6]; if (idrobot==0){ Vavance = reception16[0]; Vlat = reception16[1]; Wz = reception16[2]; idcharge = reception16[3]; idtir = reception16[4]; dribble = reception16[5]; dd=(dribble!=0); //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/1000.0); //a bouger //charge=(idcharge!=0); charge=(idcharge==1); ThisThread::sleep_for(10ms); charge=0; //dd.SetSpeed(dribble); //tir=1; } } } } void Dribble(){ } void Tir(){ while(1){ if (idtir!=0){ tir = 1 ; ThisThread::sleep_for(idtir); tir = 0 ; } tir=0;} } int main(){ dd=0; reception8 = (char*) reception16; reception_thread.start(reception); dribble_thread.start(Dribble); tir_thread.start(Tir); }