Lidar Ares

Dependencies:   mbed AX12 VL53L0X

Revision:
1:57e02cddb330
Parent:
0:0127fb93e2d1
--- 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
+