Lidar Ares
Dependencies: mbed AX12 VL53L0X
Revision 1:57e02cddb330, committed 2021-04-06
- Comitter:
- Nanaud
- Date:
- Tue Apr 06 13:30:24 2021 +0000
- Parent:
- 0:0127fb93e2d1
- Commit message:
- Lidar Ares
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AX12.lib Tue Apr 06 13:30:24 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/jplunkett/code/AX12/#5b9ce05ad2e0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VL53L0X.lib Tue Apr 06 13:30:24 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/joelvonrotz/code/VL53L0X/#ccc67c76fecb
--- a/ares_vl53l0x.cpp Tue Feb 23 21:56:26 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -#include "ares_vl53l0x.h" - -/* Constructeur */ -VL53L0X::VL53L0X() -{ - status = VL53L0X_ERROR_NONE; - i2c_address = 0x29; -} - -/* Init */ -uint8_t VL53L0X::Init() -{ - mySensor.I2cDevAddr = 0x29; - mySensor.comms_type = 1; - mySensor.comms_speed_khz = 400; - - int addr = VL53L0X_scan(); - printf("VL53L0X Device address: %i\r\n", addr); - mySensor.I2cDevAddr = addr; - - /* DataInit : Device initialization*/ - if(VL53L0X_ERROR_NONE != (status = VL53L0X_DataInit(&mySensor))) { - printf("last status = %d\r\n",status); - return 1; - } - - /* StaticInit */ - if(VL53L0X_ERROR_NONE != (status = VL53L0X_StaticInit(&mySensor))) { - printf("last status = %d\r\n",status); - return 1; - } - - return 0; -} - -/* Calibration */ -uint8_t VL53L0X::Calibration() -{ - /* Reference SPADs */ - uint32_t refSpadCount = 0; - uint8_t isApertureSpads = 0; - - if(VL53L0X_ERROR_NONE != (status = VL53L0X_PerformRefSpadManagement(&mySensor, &refSpadCount, &isApertureSpads))) { - printf("last status = %d\r\n",status); - return 1; - } - - /* Ref calibration */ - - uint8_t VhvSettings = 0; - uint8_t PhaseCal = 0; - - if(VL53L0X_ERROR_NONE != (status = VL53L0X_PerformRefCalibration(&mySensor, &VhvSettings, &PhaseCal))) { - printf("last status = %d\r\n",status); - return 1; - } - - /* Offset calibration */ - - /* ... */ - - /* Cross-talk correction */ - - if(VL53L0X_ERROR_NONE != (status = VL53L0X_SetXTalkCompensationRateMegaCps(&mySensor, 0))) { - printf("last status = %d\r\n",status); - return 1; - } - - /* Device mode */ - - if(VL53L0X_ERROR_NONE != (status = VL53L0X_SetDeviceMode(&mySensor,VL53L0X_DEVICEMODE_CONTINUOUS_RANGING))) { - printf("last status = %d\r\n",status); - return 1; - } - - return 0; -} - -/* Start measurement */ -uint8_t VL53L0X::StartMeasurement() -{ - VL53L0X_StartMeasurement(&mySensor); - return 0; -} - -/* Get measurement */ -uint16_t VL53L0X::GetMeasurement() -{ - VL53L0X_RangingMeasurementData_t rangingMeasurementData; - VL53L0X_RangingMeasurementData_t *pRangingMeasurementData = &rangingMeasurementData; - - uint8_t MeasurementDataReady; - uint8_t *pMeasurementDataReady = &MeasurementDataReady; - - do { - VL53L0X_GetMeasurementDataReady(&mySensor, pMeasurementDataReady); - } while(MeasurementDataReady == 0); - - if(VL53L0X_ERROR_NONE != (status = VL53L0X_GetRangingMeasurementData(&mySensor, pRangingMeasurementData))) { - printf("last status = %d\r\n",status); - return 9999; - } - - printf("pRangingMeasurementData->RangeMilliMeter = %d\r\n",pRangingMeasurementData->RangeMilliMeter); - printf("pRangingMeasurementData->RangeStatus = %d\r\n", pRangingMeasurementData->RangeStatus); - - return pRangingMeasurementData->RangeMilliMeter; -}
--- a/ares_vl53l0x.h Tue Feb 23 21:56:26 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#ifndef ARES_VL53L0X_H -#define ARES_VL53L0X_H - -#include "mbed.h" -#include "vl53l0x_api.h" -#include "vl53l0x_platform.h" -#include "vl53l0x_i2c_platform.h" - -class VL53L0X -{ -public: - VL53L0X(); - - uint8_t Init(); - uint8_t Calibration(); - uint8_t StartMeasurement(); - uint16_t GetMeasurement(); - -private: - VL53L0X_Dev_t mySensor; - uint8_t status; - uint8_t i2c_address; -}; - -#endif \ No newline at end of file
--- a/main.cpp Tue Feb 23 21:56:26 2021 +0000 +++ b/main.cpp Tue Apr 06 13:30:24 2021 +0000 @@ -1,30 +1,61 @@ -#include "mbed.h" -#include "ares_vl53l0x.h" +#include "main.h" -Serial pc(USBTX,USBRX); -VL53L0X Sensor_1; +/* VL53L0X */ +I2C i2c(D4, D5); +VL53L0X vl_sensors[2] = {(&i2c),(&i2c)}; +BusOut vl_shutdown(D12,D13); + +/* PC */ +Serial pc(USBTX, USBRX, 9600); +Serial ihm(PA_9, PA_10, 9600); -int main() +int main(void) { - pc.printf("MY_LIB_VL53L0X_FROM_API\r\n\n"); + pc.printf("23-03-21_Sensors_and_serial\n\r"); + + /* Init VL53L0X */ + uint8_t expander_shutdown_mask = 1; - if(Sensor_1.Init()) { - pc.printf("Erreur Sensor_1.Init()\r\n"); - while(1); + for(uint8_t i = 0; i < 2 ; i++) { + vl_shutdown = expander_shutdown_mask; + expander_shutdown_mask = (expander_shutdown_mask << 1) + 1; + vl_sensors[i].init(); + vl_sensors[i].setDeviceAddress(0x40 + i); + vl_sensors[i].setModeContinuous(); + vl_sensors[i].startContinuous(); } - else pc.printf("Sensor_1 initialize\r\n"); + + //uint16_t results[2]; + float results[2] = {0}; + + /* Init AX-12 */ + AX12 myax12(PA_2, PA_3, 2, 250000); // ID = 2 pour le prototype de Lidar - if(Sensor_1.Calibration()) { - pc.printf("Erreur Sensor_1.Calibration()\r\n"); - while(1); + while(1) { + for(float k = AX12_POS_MIN; k <= AX12_POS_MAX; k=k+AX12_POS_JUMP) { + for(int i = 0; i < 2 ; i++) { + //wait(AX12_TIME_JUMP); + results[i] = (float)vl_sensors[i].getRangeMillimeters(); + } + + myax12.SetGoal(k); // go to 0 degrees + //pc.printf("k: %f 1: %fmm 2: %fmm \n\r", k, results[0], results[1]); + ihm.printf("%f %f %f\n",k,results[0],results[1]); + wait(AX12_TIME_JUMP); + } + + for(float k = AX12_POS_MAX; k >= AX12_POS_MIN; k=k-AX12_POS_JUMP) { + for(int i = 0; i < 2 ; i++) { + //wait(AX12_TIME_JUMP); + results[i] = (float)vl_sensors[i].getRangeMillimeters(); + } + + myax12.SetGoal(k); // go to 0 degrees + //pc.printf("k: %f 1: %fmm 2: %fmm \n\r", k, results[0], results[1]); + ihm.printf("%f %f %f\n",k,results[0],results[1]); + wait(AX12_TIME_JUMP); + } } - else pc.printf("Sensor_1 calibrated\r\n"); - - Sensor_1.StartMeasurement(); +} - while (1) { - Sensor_1.GetMeasurement(); - wait(0.1); - //pc.printf("%d\r\n",Sensor_1.GetMeasurement()); - } -} \ No newline at end of file +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Tue Apr 06 13:30:24 2021 +0000 @@ -0,0 +1,17 @@ +#ifndef ARES21_LIDAR +#define ARES21_LIDAR + +/* #include */ +#include "mbed.h" +#include "VL53L0X.h" +#include "AX12.h" + +/* #define AX-12 */ +//#define AX12 1 +#define AX12_POS_MIN 0 +#define AX12_POS_MAX 120 +#define AX12_POS_JUMP 20 +#define AX12_POS_MID 60 +#define AX12_TIME_JUMP 0.1 + +#endif
--- a/vl53l0x_api.lib Tue Feb 23 21:56:26 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/mjarvisal/code/vl53l0x_api/#857ea9cf5361