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.
Revision 1:b96e529849d1, committed 2021-12-14
- Comitter:
- villemejane
- Date:
- Tue Dec 14 15:03:53 2021 +0000
- Parent:
- 0:4762540bcced
- Child:
- 2:68d03c147aff
- Commit message:
- nRF24 L01 - RF communication module
Changed in this revision
--- a/main.cpp Thu Sep 23 12:33:38 2021 +0000
+++ b/main.cpp Tue Dec 14 15:03:53 2021 +0000
@@ -10,56 +10,17 @@
/****************************************************************************/
#include "mbed.h"
+#include "voiture_auto.h"
+#include "rplidar.h"
#include "MOD24_NRF.h"
-#define TRANSFER_SIZE 8
-
-nRF24L01P my_mod(PC_12, PC_11, PC_10, PH_1, PH_0, PD_2);
-// MOSI, MISO, SCK, CSN, CE, IRQ
-
-Serial pc(USBTX, USBRX);
-DigitalIn my_bp(USER_BUTTON);
-
-char k;
-char dataToSend[TRANSFER_SIZE] = {0xAA, 0x01, 0x10, 0xF0,0xAA, 0x01, 0x10, 0xF0};
-char dataReceived[TRANSFER_SIZE] = {0};
-char rxDataCnt;
+#include "nRF24.h"
int main() {
- pc.printf("Test\r\n");
- my_mod.setRfFrequency(2400);
- wait_ms(100);
- my_mod.powerUp();
-
- // Display the (default) setup of the nRF24L01+ chip
- pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_mod.getRfFrequency() );
- pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_mod.getRfOutputPower() );
- pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_mod.getAirDataRate() );
-
- pc.printf( "Transfers are grouped into %d characters\r\n", TRANSFER_SIZE );
-
- my_mod.setTransferSize( TRANSFER_SIZE );
-
- my_mod.setReceiveMode();
- my_mod.enable();
+ debug_pc.printf("Test\r\n");
+ initVoiture();
+ initNRF24();
while(1) {
- if ( my_mod.readable() ) {
-
- // ...read the data into the receive buffer
- rxDataCnt = my_mod.read( NRF24L01P_PIPE_P0, dataReceived, TRANSFER_SIZE);
-
- // Display the receive buffer contents via the host serial link
- pc.printf("\tD = ");
- for ( int i = 0; i < rxDataCnt; i++ ) {
- pc.printf(" %x \t", dataReceived[i]);
- }
- pc.printf("\r\n");
- }
- if(my_bp == 0){
- my_mod.setRfFrequency(2400);
- my_mod.write( NRF24L01P_PIPE_P0, dataToSend, TRANSFER_SIZE );
- pc.printf( "SENDED\r\n");
- wait_ms(100);
- }
+ testNRF24();
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nRF24.lib Tue Dec 14 15:03:53 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/IOGS_France/code/nRF24/#659c6ffdd56c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rplidar.lib Tue Dec 14 15:03:53 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/IOGS_France/code/rplidar/#9803ade33ac3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/voiture_auto.cpp Tue Dec 14 15:03:53 2021 +0000
@@ -0,0 +1,104 @@
+/****************************************************************************/
+/* Autonomous Vehicle / based on RC vehicle Lancia Delta */
+/****************************************************************************/
+/* LEnsE / Julien VILLEMEJANE / Institut d'Optique Graduate School */
+/****************************************************************************/
+/* Library - voiture_auto.cpp file */
+/****************************************************************************/
+/* Tested on Nucleo-L476RG / 4th nov 2021 */
+/****************************************************************************/
+
+#include "mbed.h"
+#include "voiture_auto.h"
+
+/* Entrées - Sorties */
+// Chassis
+PwmOut direction(PB_13); // Servomoteur de direction
+PwmOut moteur(PC_9); // Motorisation / ESC
+AnalogIn pot_dir(PC_5);
+// Capteurs
+AnalogIn capt1(PC_2);
+AnalogIn capt2(PC_3);
+AnalogIn capt3(PC_0);
+AnalogIn capt4(PC_1);
+AnalogIn capt5(PB_0);
+AnalogIn capt6(PA_4);
+
+/* Variables globales */
+int angle_roues, vitesse;
+char data = 'd';
+float distance_c[6] = {0};
+
+/* Initialisation de la voiture */
+void initVoiture(void){
+ // Initialisation moteur et direction
+ direction.period_ms(20); //période de réception du servomoteur
+ direction.pulsewidth_us(1300); //première commande du servomoteur -> tout droit
+ moteur.period_ms(20); //période de réception du moteur
+ moteur.pulsewidth_us(1500); // 1500 -> point mort
+ wait_us(2000000);
+}
+
+/* Test Direction */
+void testDirection(void){
+ for(angle_roues = 1100; angle_roues < 1500; angle_roues+=10){
+ direction.pulsewidth_us(angle_roues);
+ wait_us(100000);
+ }
+ angle_roues = 1300;
+ direction.pulsewidth_us(angle_roues);
+}
+
+/* Réglage Direction */
+void setDirection(void){
+ // TO DO
+}
+
+/* Test Vitesse */
+void testVitesse(void){
+ // Marche Avant progressive
+ for(vitesse = 1500; vitesse < 1600; vitesse+=10){
+ moteur.pulsewidth_us(vitesse);
+ wait_us(100000);
+ }
+ wait_us(1000000);
+ // Arrêt
+ vitesse = 1500;
+ moteur.pulsewidth_us(vitesse);
+ wait_us(100000);
+ // Marche arrière - insdispensable / voir régulateur vitesse
+ vitesse = 1400;
+ moteur.pulsewidth_us(vitesse);
+ wait_us(100000);
+ // Arrêt - insdispensable
+ vitesse = 1500;
+ moteur.pulsewidth_us(vitesse);
+ wait_us(100000);
+ // Marche arrière progressive
+ for(vitesse = 1500; vitesse > 1400; vitesse-=10){
+ moteur.pulsewidth_us(vitesse);
+ wait_us(100000);
+ }
+ wait_us(1000000);
+ // Arrêt
+ vitesse = 1500;
+ moteur.pulsewidth_us(vitesse);
+}
+
+/* Récupération des données des capteurs */
+void collectData(void){
+ distance_c[0] = capt1.read()*3.3;
+ distance_c[1] = capt2.read()*3.3;
+ distance_c[2] = capt3.read()*3.3;
+ distance_c[3] = capt4.read()*3.3;
+ distance_c[4] = capt5.read()*3.3;
+ distance_c[5] = capt6.read()*3.3;
+}
+
+/* Affichage des données des capteurs */
+void printData(void){
+ for(int i = 0; i < 6; i++){
+ debug_pc.printf("\tD%d = %lf\r\n", i, distance_c[i]);
+ }
+ debug_pc.printf("\r\n");
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/voiture_auto.h Tue Dec 14 15:03:53 2021 +0000 @@ -0,0 +1,52 @@ +/****************************************************************************/ +/* Autonomous Vehicle / based on RC vehicle Lancia Delta */ +/****************************************************************************/ +/* LEnsE / Julien VILLEMEJANE / Institut d'Optique Graduate School */ +/****************************************************************************/ +/* Library - voiture_auto.h file */ +/****************************************************************************/ +/* Tested on Nucleo-L476RG / 4th nov 2021 */ +/****************************************************************************/ + +#ifndef VOITURE_AUTO_H_INCLUDED +#define VOITURE_AUTO_H_INCLUDED + +#include "mbed.h" + +/* Entrées - Sorties */ +// Debuggage +extern DigitalOut debug_out; +extern Serial debug_pc; +extern InterruptIn bp_int; +// Chassis +extern PwmOut direction; // Servomoteur de direction +extern PwmOut moteur; // Motorisation / ESC +extern AnalogIn pot_dir; +// Capteurs +extern AnalogIn capt1; +extern AnalogIn capt2; +extern AnalogIn capt3; +extern AnalogIn capt4; +extern AnalogIn capt5; +extern AnalogIn capt6; + + +/* Variables globales */ +extern int angle_roues, vitesse; +extern char data; +extern float distance_c[6]; + +/* Initialisation de la voiture */ +void initVoiture(void); +/* Test Direction */ +void testDirection(void); +/* Test Vitesse */ +void testVitesse(void); +/* Réglage Direction */ +void setDirection(void); // A faire sur nouvelle carte avec potentiomètre +/* Fonction de récupération des données */ +void collectData(void); +/* Affichage des données des capteurs */ +void printData(void); + +#endif \ No newline at end of file