Sample ranging application, using X_Nucleo_53L3A2 expansion board and supporting Satellite boards, to ranging from each sensor, using interrupts. Targetting MbedOS v6.10.
Dependencies: X_NUCLEO_53L3A2
main.cpp@0:c77591fc308d, 2020-10-13 (annotated)
- Committer:
- charlesmn
- Date:
- Tue Oct 13 18:39:10 2020 +0000
- Revision:
- 0:c77591fc308d
- Child:
- 2:86876e590f28
Example program of of interrupt driven collection of data from up to 3 VL53L3 sensors returning range data and outputting it to serial port at 115200 baud.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:c77591fc308d | 1 | /* |
charlesmn | 0:c77591fc308d | 2 | * This VL53L1X Expansion board test application performs range measurements |
charlesmn | 0:c77591fc308d | 3 | * using the onboard embedded centre sensor, in singleshot, polling mode. |
charlesmn | 0:c77591fc308d | 4 | * Measured ranges are ouput on the Serial Port, running at 9600 baud. |
charlesmn | 0:c77591fc308d | 5 | * |
charlesmn | 0:c77591fc308d | 6 | * The User Blue button stops the current measurement and entire program, |
charlesmn | 0:c77591fc308d | 7 | * releasing all resources. |
charlesmn | 0:c77591fc308d | 8 | * |
charlesmn | 0:c77591fc308d | 9 | * The Reset button can be used to restart the program. |
charlesmn | 0:c77591fc308d | 10 | */ |
charlesmn | 0:c77591fc308d | 11 | //Main_interrupt_ranging.h |
charlesmn | 0:c77591fc308d | 12 | |
charlesmn | 0:c77591fc308d | 13 | #include <stdio.h> |
charlesmn | 0:c77591fc308d | 14 | |
charlesmn | 0:c77591fc308d | 15 | #include "mbed.h" |
charlesmn | 0:c77591fc308d | 16 | #include "XNucleo53L1A1.h" |
charlesmn | 0:c77591fc308d | 17 | #include "vl53L1x_I2c.h" |
charlesmn | 0:c77591fc308d | 18 | #include <time.h> |
charlesmn | 0:c77591fc308d | 19 | |
charlesmn | 0:c77591fc308d | 20 | |
charlesmn | 0:c77591fc308d | 21 | #define VL53L1_I2C_SDA D14 |
charlesmn | 0:c77591fc308d | 22 | #define VL53L1_I2C_SCL D15 |
charlesmn | 0:c77591fc308d | 23 | |
charlesmn | 0:c77591fc308d | 24 | #define MEASUREMENTTIMING 55 |
charlesmn | 0:c77591fc308d | 25 | |
charlesmn | 0:c77591fc308d | 26 | static XNucleo53L1A1 *board=NULL; |
charlesmn | 0:c77591fc308d | 27 | Serial pc(SERIAL_TX, SERIAL_RX); |
charlesmn | 0:c77591fc308d | 28 | |
charlesmn | 0:c77591fc308d | 29 | static int int_centre_result = 0; |
charlesmn | 0:c77591fc308d | 30 | static int int_left_result = 0; |
charlesmn | 0:c77591fc308d | 31 | static int int_right_result = 0; |
charlesmn | 0:c77591fc308d | 32 | |
charlesmn | 0:c77591fc308d | 33 | |
charlesmn | 0:c77591fc308d | 34 | class WaitForMeasurement { |
charlesmn | 0:c77591fc308d | 35 | public: |
charlesmn | 0:c77591fc308d | 36 | |
charlesmn | 0:c77591fc308d | 37 | |
charlesmn | 0:c77591fc308d | 38 | // this class services the interrupts from the ToF sensors. |
charlesmn | 0:c77591fc308d | 39 | // There is a limited amount you can do in an interrupt routine; printfs,mutexes break them among other things. |
charlesmn | 0:c77591fc308d | 40 | // We keep things simple by only raising a flag so all the real work is done outside the interrupt. |
charlesmn | 0:c77591fc308d | 41 | // This is designed around MBED V2 which doesn't have the RTOS features that would make this work nicely e.g. semaphores/queues. |
charlesmn | 0:c77591fc308d | 42 | WaitForMeasurement(): _interrupt(A1) |
charlesmn | 0:c77591fc308d | 43 | { |
charlesmn | 0:c77591fc308d | 44 | } |
charlesmn | 0:c77591fc308d | 45 | |
charlesmn | 0:c77591fc308d | 46 | |
charlesmn | 0:c77591fc308d | 47 | // constructor - Sensor is not used and can be removed |
charlesmn | 0:c77591fc308d | 48 | WaitForMeasurement(PinName pin,VL53LX_DEV Dev) : _interrupt(pin) // create the InterruptIn on the pin specified to Counter |
charlesmn | 0:c77591fc308d | 49 | { |
charlesmn | 0:c77591fc308d | 50 | Devlocal = Dev; |
charlesmn | 0:c77591fc308d | 51 | _interrupt.rise(callback(this, &WaitForMeasurement::got_interrupt)); // attach increment function of this counter instance |
charlesmn | 0:c77591fc308d | 52 | |
charlesmn | 0:c77591fc308d | 53 | } |
charlesmn | 0:c77591fc308d | 54 | |
charlesmn | 0:c77591fc308d | 55 | void process_right_interrupt() |
charlesmn | 0:c77591fc308d | 56 | { |
charlesmn | 0:c77591fc308d | 57 | printf("processing right interrupt\n"); |
charlesmn | 0:c77591fc308d | 58 | } |
charlesmn | 0:c77591fc308d | 59 | |
charlesmn | 0:c77591fc308d | 60 | // function is called every time an interupt is seen. A flag is raised which allows the main routine to service the interupt. |
charlesmn | 0:c77591fc308d | 61 | void got_interrupt() |
charlesmn | 0:c77591fc308d | 62 | { |
charlesmn | 0:c77591fc308d | 63 | |
charlesmn | 0:c77591fc308d | 64 | _count++; |
charlesmn | 0:c77591fc308d | 65 | |
charlesmn | 0:c77591fc308d | 66 | if (Devlocal->I2cDevAddr == NEW_SENSOR_CENTRE_ADDRESS) |
charlesmn | 0:c77591fc308d | 67 | int_centre_result = 1; //flag to main that interrupt happened |
charlesmn | 0:c77591fc308d | 68 | if (Devlocal->I2cDevAddr == NEW_SENSOR_LEFT_ADDRESS) |
charlesmn | 0:c77591fc308d | 69 | int_left_result = 1; //flag to main that interrupt happened |
charlesmn | 0:c77591fc308d | 70 | if (Devlocal->I2cDevAddr == NEW_SENSOR_RIGHT_ADDRESS) |
charlesmn | 0:c77591fc308d | 71 | { |
charlesmn | 0:c77591fc308d | 72 | int_right_result = 1; //flag to main that interrupt happened |
charlesmn | 0:c77591fc308d | 73 | } |
charlesmn | 0:c77591fc308d | 74 | } |
charlesmn | 0:c77591fc308d | 75 | |
charlesmn | 0:c77591fc308d | 76 | |
charlesmn | 0:c77591fc308d | 77 | //destructor |
charlesmn | 0:c77591fc308d | 78 | ~WaitForMeasurement() |
charlesmn | 0:c77591fc308d | 79 | { |
charlesmn | 0:c77591fc308d | 80 | printf("destruction \n"); |
charlesmn | 0:c77591fc308d | 81 | } |
charlesmn | 0:c77591fc308d | 82 | |
charlesmn | 0:c77591fc308d | 83 | private: |
charlesmn | 0:c77591fc308d | 84 | InterruptIn _interrupt; |
charlesmn | 0:c77591fc308d | 85 | volatile int _count; |
charlesmn | 0:c77591fc308d | 86 | VL53LX_DEV Devlocal; |
charlesmn | 0:c77591fc308d | 87 | int status; |
charlesmn | 0:c77591fc308d | 88 | |
charlesmn | 0:c77591fc308d | 89 | }; |
charlesmn | 0:c77591fc308d | 90 | |
charlesmn | 0:c77591fc308d | 91 | |
charlesmn | 0:c77591fc308d | 92 | |
charlesmn | 0:c77591fc308d | 93 | VL53LX_Dev_t devCentre; |
charlesmn | 0:c77591fc308d | 94 | VL53LX_Dev_t devLeft; |
charlesmn | 0:c77591fc308d | 95 | VL53LX_Dev_t devRight; |
charlesmn | 0:c77591fc308d | 96 | VL53LX_DEV Dev = &devCentre; |
charlesmn | 0:c77591fc308d | 97 | |
charlesmn | 0:c77591fc308d | 98 | |
charlesmn | 0:c77591fc308d | 99 | |
charlesmn | 0:c77591fc308d | 100 | |
charlesmn | 0:c77591fc308d | 101 | |
charlesmn | 0:c77591fc308d | 102 | /*=================================== Main ================================== |
charlesmn | 0:c77591fc308d | 103 | =============================================================================*/ |
charlesmn | 0:c77591fc308d | 104 | int main() |
charlesmn | 0:c77591fc308d | 105 | { |
charlesmn | 0:c77591fc308d | 106 | int status; |
charlesmn | 0:c77591fc308d | 107 | VL53LX * Sensor; |
charlesmn | 0:c77591fc308d | 108 | uint16_t wordData; |
charlesmn | 0:c77591fc308d | 109 | uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right |
charlesmn | 0:c77591fc308d | 110 | |
charlesmn | 0:c77591fc308d | 111 | |
charlesmn | 0:c77591fc308d | 112 | WaitForMeasurement* int2; |
charlesmn | 0:c77591fc308d | 113 | WaitForMeasurement* int1; |
charlesmn | 0:c77591fc308d | 114 | WaitForMeasurement* int3; |
charlesmn | 0:c77591fc308d | 115 | |
charlesmn | 0:c77591fc308d | 116 | pc.baud(115200); // baud rate is important as printf statements take a lot of time |
charlesmn | 0:c77591fc308d | 117 | |
charlesmn | 0:c77591fc308d | 118 | printf("Hello world!\r\n"); |
charlesmn | 0:c77591fc308d | 119 | |
charlesmn | 0:c77591fc308d | 120 | vl53L1X_DevI2C *dev_I2C = new vl53L1X_DevI2C(VL53L1_I2C_SDA, VL53L1_I2C_SCL); |
charlesmn | 0:c77591fc308d | 121 | |
charlesmn | 0:c77591fc308d | 122 | // printf("I2C device created! %d %d\r\n",dev_I2C,*dev_I2C); |
charlesmn | 0:c77591fc308d | 123 | |
charlesmn | 0:c77591fc308d | 124 | /* creates the 53L1A1 expansion board singleton obj */ |
charlesmn | 0:c77591fc308d | 125 | board = XNucleo53L1A1::instance(dev_I2C, A2, D8, D2); |
charlesmn | 0:c77591fc308d | 126 | printf("board created!\r\n"); |
charlesmn | 0:c77591fc308d | 127 | |
charlesmn | 0:c77591fc308d | 128 | /* init the 53L1A1 expansion board with default values */ |
charlesmn | 0:c77591fc308d | 129 | status = board->init_board(); |
charlesmn | 0:c77591fc308d | 130 | if (status) { |
charlesmn | 0:c77591fc308d | 131 | printf("Failed to init board!\r\n"); |
charlesmn | 0:c77591fc308d | 132 | return 0; |
charlesmn | 0:c77591fc308d | 133 | } |
charlesmn | 0:c77591fc308d | 134 | |
charlesmn | 0:c77591fc308d | 135 | |
charlesmn | 0:c77591fc308d | 136 | printf("board initiated! - %d\r\n", status); |
charlesmn | 0:c77591fc308d | 137 | |
charlesmn | 0:c77591fc308d | 138 | for (ToFSensor=0;ToFSensor<3;ToFSensor++){ |
charlesmn | 0:c77591fc308d | 139 | wait_ms(15); |
charlesmn | 0:c77591fc308d | 140 | switch(ToFSensor){ |
charlesmn | 0:c77591fc308d | 141 | case 0: |
charlesmn | 0:c77591fc308d | 142 | if (board->sensor_centre== NULL ) continue; |
charlesmn | 0:c77591fc308d | 143 | Dev=&devCentre; |
charlesmn | 0:c77591fc308d | 144 | Sensor=board->sensor_centre; |
charlesmn | 0:c77591fc308d | 145 | Dev->I2cDevAddr = NEW_SENSOR_CENTRE_ADDRESS; |
charlesmn | 0:c77591fc308d | 146 | printf("configuring centre channel \n"); |
charlesmn | 0:c77591fc308d | 147 | break; |
charlesmn | 0:c77591fc308d | 148 | case 1: |
charlesmn | 0:c77591fc308d | 149 | if (board->sensor_left== NULL ) continue; |
charlesmn | 0:c77591fc308d | 150 | Dev=&devLeft; |
charlesmn | 0:c77591fc308d | 151 | Sensor=board->sensor_left; |
charlesmn | 0:c77591fc308d | 152 | Dev->I2cDevAddr = NEW_SENSOR_LEFT_ADDRESS; |
charlesmn | 0:c77591fc308d | 153 | printf("configuring left channel \n"); |
charlesmn | 0:c77591fc308d | 154 | break; |
charlesmn | 0:c77591fc308d | 155 | case 2: |
charlesmn | 0:c77591fc308d | 156 | if (board->sensor_right== NULL ) continue; |
charlesmn | 0:c77591fc308d | 157 | Dev=&devRight; |
charlesmn | 0:c77591fc308d | 158 | Sensor=board->sensor_right; |
charlesmn | 0:c77591fc308d | 159 | Dev->I2cDevAddr = NEW_SENSOR_RIGHT_ADDRESS; |
charlesmn | 0:c77591fc308d | 160 | printf("configuring right channel \n"); |
charlesmn | 0:c77591fc308d | 161 | break; |
charlesmn | 0:c77591fc308d | 162 | default: |
charlesmn | 0:c77591fc308d | 163 | printf(" error in switch, invalid ToF sensor \n"); |
charlesmn | 0:c77591fc308d | 164 | } |
charlesmn | 0:c77591fc308d | 165 | |
charlesmn | 0:c77591fc308d | 166 | // configure the sensors |
charlesmn | 0:c77591fc308d | 167 | Dev->comms_speed_khz = 400; |
charlesmn | 0:c77591fc308d | 168 | |
charlesmn | 0:c77591fc308d | 169 | Dev->comms_type = 1; |
charlesmn | 0:c77591fc308d | 170 | |
charlesmn | 0:c77591fc308d | 171 | Sensor->VL53LX_RdWord(Dev, 0x01, &wordData); |
charlesmn | 0:c77591fc308d | 172 | printf("VL53L1X: %02X %d\n\r", wordData,Dev->I2cDevAddr); |
charlesmn | 0:c77591fc308d | 173 | /* Device Initialization and setting */ |
charlesmn | 0:c77591fc308d | 174 | |
charlesmn | 0:c77591fc308d | 175 | status = Sensor->VL53LX_DataInit(); |
charlesmn | 0:c77591fc308d | 176 | status = Sensor->VL53LX_SetDistanceMode(VL53LX_DISTANCEMODE_LONG); |
charlesmn | 0:c77591fc308d | 177 | status = Sensor->VL53LX_SetMeasurementTimingBudgetMicroSeconds( MEASUREMENTTIMING * 1000); |
charlesmn | 0:c77591fc308d | 178 | status = Sensor->VL53LX_SmudgeCorrectionEnable(VL53LX_SMUDGE_CORRECTION_SINGLE); |
charlesmn | 0:c77591fc308d | 179 | status = Sensor->VL53LX_SetXTalkCompensationEnable(1); |
charlesmn | 0:c77591fc308d | 180 | |
charlesmn | 0:c77591fc308d | 181 | |
charlesmn | 0:c77591fc308d | 182 | } |
charlesmn | 0:c77591fc308d | 183 | |
charlesmn | 0:c77591fc308d | 184 | if (board->sensor_centre!= NULL ) |
charlesmn | 0:c77591fc308d | 185 | { |
charlesmn | 0:c77591fc308d | 186 | printf("starting interrupt centre\n"); |
charlesmn | 0:c77591fc308d | 187 | Sensor=board->sensor_centre; |
charlesmn | 0:c77591fc308d | 188 | devCentre.I2cDevAddr = NEW_SENSOR_CENTRE_ADDRESS; |
charlesmn | 0:c77591fc308d | 189 | int1 = new WaitForMeasurement(A2,&devCentre); |
charlesmn | 0:c77591fc308d | 190 | status = Sensor->VL53LX_StartMeasurement(); |
charlesmn | 0:c77591fc308d | 191 | printf("VL53L1_StartMeasurement %d \n",status); |
charlesmn | 0:c77591fc308d | 192 | status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 193 | } |
charlesmn | 0:c77591fc308d | 194 | |
charlesmn | 0:c77591fc308d | 195 | |
charlesmn | 0:c77591fc308d | 196 | if (board->sensor_left!= NULL ) |
charlesmn | 0:c77591fc308d | 197 | { |
charlesmn | 0:c77591fc308d | 198 | printf("starting interrupt left\n"); |
charlesmn | 0:c77591fc308d | 199 | Sensor=board->sensor_left; |
charlesmn | 0:c77591fc308d | 200 | devLeft.I2cDevAddr = NEW_SENSOR_LEFT_ADDRESS; |
charlesmn | 0:c77591fc308d | 201 | int2 = new WaitForMeasurement(D8,&devLeft); |
charlesmn | 0:c77591fc308d | 202 | status = Sensor->VL53LX_StartMeasurement(); |
charlesmn | 0:c77591fc308d | 203 | printf("VL53L1_StartMeasurement %d \n",status); |
charlesmn | 0:c77591fc308d | 204 | status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 205 | } |
charlesmn | 0:c77591fc308d | 206 | |
charlesmn | 0:c77591fc308d | 207 | if (board->sensor_right!= NULL ) |
charlesmn | 0:c77591fc308d | 208 | { |
charlesmn | 0:c77591fc308d | 209 | printf("starting interrupt right\n"); |
charlesmn | 0:c77591fc308d | 210 | Sensor=board->sensor_right; |
charlesmn | 0:c77591fc308d | 211 | devRight.I2cDevAddr = NEW_SENSOR_RIGHT_ADDRESS; |
charlesmn | 0:c77591fc308d | 212 | int3 = new WaitForMeasurement(D2,&devRight); |
charlesmn | 0:c77591fc308d | 213 | status = Sensor->VL53LX_StartMeasurement(); |
charlesmn | 0:c77591fc308d | 214 | printf("VL53L1_StartMeasurement %d \n",status); |
charlesmn | 0:c77591fc308d | 215 | status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 216 | } |
charlesmn | 0:c77591fc308d | 217 | |
charlesmn | 0:c77591fc308d | 218 | |
charlesmn | 0:c77591fc308d | 219 | // loop waiting for interrupts to happen. This is signaled by int_centre_result,int_left_result or int_right_result |
charlesmn | 0:c77591fc308d | 220 | // being non zero. The are set back to zero when processing is completed |
charlesmn | 0:c77591fc308d | 221 | while (1) |
charlesmn | 0:c77591fc308d | 222 | { |
charlesmn | 0:c77591fc308d | 223 | |
charlesmn | 0:c77591fc308d | 224 | VL53LX_MultiRangingData_t MultiRangingData; |
charlesmn | 0:c77591fc308d | 225 | VL53LX_MultiRangingData_t *pMultiRangingData = &MultiRangingData; |
charlesmn | 0:c77591fc308d | 226 | |
charlesmn | 0:c77591fc308d | 227 | wait_ms( 1 * 10); |
charlesmn | 0:c77591fc308d | 228 | // printf("interruptcount %d \n",interruptcount); |
charlesmn | 0:c77591fc308d | 229 | if (int_centre_result != 0) |
charlesmn | 0:c77591fc308d | 230 | { |
charlesmn | 0:c77591fc308d | 231 | int_centre_result = 0; |
charlesmn | 0:c77591fc308d | 232 | // printf("int_centre_result \n"); |
charlesmn | 0:c77591fc308d | 233 | status = board->sensor_centre->VL53LX_GetMultiRangingData( pMultiRangingData); |
charlesmn | 0:c77591fc308d | 234 | int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; |
charlesmn | 0:c77591fc308d | 235 | // printf("int_centre_result %d %d \n",no_of_object_found,status); |
charlesmn | 0:c77591fc308d | 236 | if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) |
charlesmn | 0:c77591fc308d | 237 | { |
charlesmn | 0:c77591fc308d | 238 | for(int j=0;j<no_of_object_found;j++){ |
charlesmn | 0:c77591fc308d | 239 | if (pMultiRangingData->RangeData[j].RangeStatus == 0) |
charlesmn | 0:c77591fc308d | 240 | { |
charlesmn | 0:c77591fc308d | 241 | printf("centre\t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", |
charlesmn | 0:c77591fc308d | 242 | pMultiRangingData->RangeData[j].RangeStatus, |
charlesmn | 0:c77591fc308d | 243 | pMultiRangingData->RangeData[j].RangeMilliMeter, |
charlesmn | 0:c77591fc308d | 244 | pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0, |
charlesmn | 0:c77591fc308d | 245 | pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0); |
charlesmn | 0:c77591fc308d | 246 | } |
charlesmn | 0:c77591fc308d | 247 | } |
charlesmn | 0:c77591fc308d | 248 | } |
charlesmn | 0:c77591fc308d | 249 | int_centre_result = 0; |
charlesmn | 0:c77591fc308d | 250 | wait_ms( MEASUREMENTTIMING ); |
charlesmn | 0:c77591fc308d | 251 | status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 252 | } |
charlesmn | 0:c77591fc308d | 253 | |
charlesmn | 0:c77591fc308d | 254 | |
charlesmn | 0:c77591fc308d | 255 | if (int_left_result != 0) |
charlesmn | 0:c77591fc308d | 256 | { |
charlesmn | 0:c77591fc308d | 257 | int_left_result = 0; |
charlesmn | 0:c77591fc308d | 258 | // printf("int_left_result \n"); |
charlesmn | 0:c77591fc308d | 259 | status = board->sensor_left->VL53LX_GetMultiRangingData( pMultiRangingData); |
charlesmn | 0:c77591fc308d | 260 | // printf("int_left_result status %d \n",status); |
charlesmn | 0:c77591fc308d | 261 | if ( status == 0) |
charlesmn | 0:c77591fc308d | 262 | { |
charlesmn | 0:c77591fc308d | 263 | int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; |
charlesmn | 0:c77591fc308d | 264 | // printf("int_left_result %d %d \n",no_of_object_found,status); |
charlesmn | 0:c77591fc308d | 265 | if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) |
charlesmn | 0:c77591fc308d | 266 | { |
charlesmn | 0:c77591fc308d | 267 | for(int j=0;j<no_of_object_found;j++){ |
charlesmn | 0:c77591fc308d | 268 | if (pMultiRangingData->RangeData[j].RangeStatus == 0) |
charlesmn | 0:c77591fc308d | 269 | { |
charlesmn | 0:c77591fc308d | 270 | |
charlesmn | 0:c77591fc308d | 271 | printf("left \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", |
charlesmn | 0:c77591fc308d | 272 | pMultiRangingData->RangeData[j].RangeStatus, |
charlesmn | 0:c77591fc308d | 273 | pMultiRangingData->RangeData[j].RangeMilliMeter, |
charlesmn | 0:c77591fc308d | 274 | pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0, |
charlesmn | 0:c77591fc308d | 275 | pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0); |
charlesmn | 0:c77591fc308d | 276 | } |
charlesmn | 0:c77591fc308d | 277 | } |
charlesmn | 0:c77591fc308d | 278 | } |
charlesmn | 0:c77591fc308d | 279 | } |
charlesmn | 0:c77591fc308d | 280 | wait_ms( MEASUREMENTTIMING ); |
charlesmn | 0:c77591fc308d | 281 | status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 282 | |
charlesmn | 0:c77591fc308d | 283 | } |
charlesmn | 0:c77591fc308d | 284 | |
charlesmn | 0:c77591fc308d | 285 | |
charlesmn | 0:c77591fc308d | 286 | if (int_right_result != 0) |
charlesmn | 0:c77591fc308d | 287 | { |
charlesmn | 0:c77591fc308d | 288 | // clear interrupt flag |
charlesmn | 0:c77591fc308d | 289 | int_right_result = 0; |
charlesmn | 0:c77591fc308d | 290 | // printf("int_right_result \n"); |
charlesmn | 0:c77591fc308d | 291 | status = board->sensor_right->VL53LX_GetMultiRangingData( pMultiRangingData); |
charlesmn | 0:c77591fc308d | 292 | if ( status == 0) |
charlesmn | 0:c77591fc308d | 293 | { |
charlesmn | 0:c77591fc308d | 294 | // printf("int_right_result status %d \n",status); |
charlesmn | 0:c77591fc308d | 295 | // if valid result print it |
charlesmn | 0:c77591fc308d | 296 | int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; |
charlesmn | 0:c77591fc308d | 297 | // printf("int_right_result %d %d \n",no_of_object_found,status); |
charlesmn | 0:c77591fc308d | 298 | if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) |
charlesmn | 0:c77591fc308d | 299 | { |
charlesmn | 0:c77591fc308d | 300 | for(int j=0;j<no_of_object_found;j++){ |
charlesmn | 0:c77591fc308d | 301 | if (pMultiRangingData->RangeData[j].RangeStatus == 0) |
charlesmn | 0:c77591fc308d | 302 | { |
charlesmn | 0:c77591fc308d | 303 | // if(j!=0)printf("\n 0 "); |
charlesmn | 0:c77591fc308d | 304 | printf("right \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", |
charlesmn | 0:c77591fc308d | 305 | pMultiRangingData->RangeData[j].RangeStatus, |
charlesmn | 0:c77591fc308d | 306 | pMultiRangingData->RangeData[j].RangeMilliMeter, |
charlesmn | 0:c77591fc308d | 307 | pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0, |
charlesmn | 0:c77591fc308d | 308 | pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0); |
charlesmn | 0:c77591fc308d | 309 | } |
charlesmn | 0:c77591fc308d | 310 | } |
charlesmn | 0:c77591fc308d | 311 | } |
charlesmn | 0:c77591fc308d | 312 | } |
charlesmn | 0:c77591fc308d | 313 | wait_ms( MEASUREMENTTIMING ); |
charlesmn | 0:c77591fc308d | 314 | // clear theinterrupt and wait for another result |
charlesmn | 0:c77591fc308d | 315 | status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 316 | |
charlesmn | 0:c77591fc308d | 317 | } |
charlesmn | 0:c77591fc308d | 318 | /* |
charlesmn | 0:c77591fc308d | 319 | if ( interruptcount > 10000) |
charlesmn | 0:c77591fc308d | 320 | { |
charlesmn | 0:c77591fc308d | 321 | printf("interruptcount exceeded \n"); |
charlesmn | 0:c77591fc308d | 322 | int_left_result = 0; |
charlesmn | 0:c77591fc308d | 323 | int_centre_result = 0; |
charlesmn | 0:c77591fc308d | 324 | int_right_result = 0; |
charlesmn | 0:c77591fc308d | 325 | if (board->sensor_centre!= NULL ) |
charlesmn | 0:c77591fc308d | 326 | status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 327 | if (board->sensor_left!= NULL ) |
charlesmn | 0:c77591fc308d | 328 | status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 329 | if (board->sensor_right!= NULL ) |
charlesmn | 0:c77591fc308d | 330 | status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 331 | interruptcount = 0; |
charlesmn | 0:c77591fc308d | 332 | } |
charlesmn | 0:c77591fc308d | 333 | */ |
charlesmn | 0:c77591fc308d | 334 | |
charlesmn | 0:c77591fc308d | 335 | } |
charlesmn | 0:c77591fc308d | 336 | printf("terminated"); |
charlesmn | 0:c77591fc308d | 337 | } |
charlesmn | 0:c77591fc308d | 338 |