SOFT564Z Group 3 / Mbed 2 deprecated SOFT564Z_Group_3v46666

Dependencies:   mbed Servo ros_lib_kinetic

Revision:
1:9bc7f95c3c7d
Parent:
0:6021ec1b1449
Child:
2:6197e1cf2cd1
--- a/main.cpp	Tue Oct 22 11:56:57 2019 +0000
+++ b/main.cpp	Thu Oct 24 13:35:54 2019 +0000
@@ -6,63 +6,60 @@
 #include "TOF.h"
 
 Serial pc(SERIAL_TX, SERIAL_RX, 9600);    // set-up serial to pc
-cAdafruit_VL6180X VL6180X;                  //Define TOF sensor class
+
+//TOF chip shutdown signals
+DigitalOut TOF1(PC_8);
+DigitalOut TOF3(PC_10);
+DigitalOut TOF5(PC_12);
+DigitalOut TOF7(PG_2);
+
+cAdafruit_VL6180X VL6180X(TOF1,TOF3,TOF5,TOF7);  //Define TOF sensor class and initialise devices
 
-DigitalOut CS1(PC_8);
-DigitalOut CS2(PC_9);
+/*--------------------------------------------------------------------------------
+Function name: ServiceTOF
+Input Parameters: address - address of target TOF sensor
+Output Parameters: range - distance measurement in mm
+Description: performs measurement routine on a given sensor
+----------------------------------------------------------------------------------*/
+uint8_t serviceTOF(uint8_t address){
+        
+        uint8_t range = 0;
+        
+        // poll the VL6180X till new sample ready
+        VL6180X.Poll_Range(address);
 
+        // read range result
+        range = VL6180X.Read_Range(address);
+        
+        // clear the interrupt on VL6180X
+        VL6180X.Clear_Interrupts(address);
+        
+        return range;
+}
+
+
+/*--------------------------------------------------------------------------------
+Function name: main
+Input Parameters: N/A
+Output Parameters: N/A
+Description: Main programming loop
+----------------------------------------------------------------------------------*/
 int main()
 {
-    int range1, range2;
+    uint8_t TOFRange[4]; //Array to store TOF measurements 0-sensor1, 1-sensor3, 2-sensor5, 3-sensor7
     
-    CS1 = 0;
-    CS2 = 0;
-    wait(0.01);
-
-    CS1 = 1;
-    wait(0.01);
-    VL6180X.Setup(DEFAULT_ADDRESS, ADDRESS1);
-    VL6180X.Init(ADDRESS1);
-    VL6180X.Start_Range(ADDRESS1);
-    
-    CS2 = 1;
-    wait(0.01);
-    VL6180X.Setup(DEFAULT_ADDRESS, ADDRESS2);
-    VL6180X.Init(ADDRESS2);
-    VL6180X.Start_Range(ADDRESS2);
-    
-    
-    
-    pc.printf("INITIALISED\n\r");
-
     while(1) {
         
-        // poll the VL6180X till new sample ready
-        VL6180X.Poll_Range(ADDRESS1);
-        pc.printf("POLL1");
-
-        // read range result
-        range1 = VL6180X.Read_Range(ADDRESS1);
-        pc.printf("READ RANGE1");
-        
-        // clear the interrupt on VL6180X
-        VL6180X.Clear_Interrupts(ADDRESS1);
-        pc.printf("READRANGE1");
+        //Perform TOF measurements
+        TOFRange[0] = serviceTOF(ADDR1);
+        TOFRange[1] = serviceTOF(ADDR2);
+        TOFRange[2] = serviceTOF(ADDR3);
+        TOFRange[3] = serviceTOF(ADDR4);
+                
+        //Send range to pc by serial
+        pc.printf("TOF1:%d TOF3: %d TOF5: %d TOF7: %d\r\n", TOFRange[0], TOFRange[1], TOFRange[2],TOFRange[3]);
         
-        // poll the VL6180X till new sample ready
-        VL6180X.Poll_Range(ADDRESS2);
-        pc.printf("POLL2");
-
-        // read range result
-        range2 = VL6180X.Read_Range(ADDRESS2);
-        pc.printf("READ RANGE2");
-        
-        // clear the interrupt on VL6180X
-        VL6180X.Clear_Interrupts(ADDRESS2);
-        pc.printf("READRANGE2");
-        
-        // send range to pc by serial
-        pc.printf("SENSOR1:%d SENSOR2: %d\r\n", range1, range2);
+        //Short delay
         wait(0.1);
     }
 }
\ No newline at end of file