/*
Name: Teensy_7VL53L1X_I2C_Slave_V1.ino
Created: 4/12/2023 3:40:21 PM
Author: FRANKNEWXPS15\Frank
Notes:
04/12/23 Copied from Teensy_7VL53L10X_I2C_Slave_V4 and revised to use
VL53L1X sensors instead of VL53L0X, and the Pololu VL53L1X library
instead of the VL53L0X one
04/21/23 code ported from VL53L1X_Pololu_V1.ino
*/
#pragma region EARLIER_VERSIONS
/*
Name: Teensy_7VL53L1X_I2C_Slave_V4.ino
Created: 4/3/2022 1:04:28 PM
Author: FRANKNEWXPS15\Frank
Notes:
04/03/22 This version adds a linear distance correction algorithm to each VL53L1X
11/17/22 changed measurement budget from 20 to 50mSec for right-side sensors only
11/20/22 changed measurement budget from 20 to 50mSec for left-side and rear sensors
12/14/22 changed measurement budget back to 30mSec from 50mSec for all sensors
*/
/*
Name: Teensy_7VL53L1X_I2C_Slave_V3.ino
Created: 1/24/2021 4:03:35 PM
Author: FRANKNEWXPS15\Frank
This is the 'final' version of the Teensy 3.5 project to manage all
seven VL53L1X lidar distance sensors, three on left, three on right,
and now including a rear distance sensor. As of this date it was an
identical copy of the TeensyHexVL53L1XHighSpeedDemo project, just
renamed for clarity
01/23/22 - revised to work properly with Teensy 3.5 main processor
*/
/*
Name: TeensyHexVL53L1XHighSpeedDemo.ino
Created: 10/1/2020 3:49:01 PM
Author: FRANKNEWXPS15\Frank
This demo program combines the code from my Teensy_VL53L1X_I2C_Slave_V2
project with the VL53L1X 'high speed' code from the Pololu support
forum post at https://forum.pololu.com/t/high-speed-with-vl53l0x/16585/3
*/
/*
Name: Teensy_VL53L1X_I2C_Slave_V2.ino
Created: 8/4/2020 7:42:22 PM
Author: FRANKNEWXPS15\Frank
This project merges KurtE's multi-wire capable version of Pololu's VL53L1X library
with my previous Teensy_VL53L1X_I2C_Slave project, which used the Adafruit VL53L1X
library. This (hopefully) will be the version uploaded to the Teensy on the 2nd
deck of Wall-E2 and which controls the left & right 3-VL53L1X sensor arrays
01/17/22: Copied VL53L1X.h/cpp from C:\Users\paynt\Documents\Arduino\Libraries\vl53l0x-arduino-multi_wire
so I won't have to guess which library folder these files came from
01/17/22: if you have a local file.h same as a library\xx\file.h, then if VMicro's 'deep search'option
is enabled, must use #include "file.h" instead of #include <file.h>. This is the reason for using
#include "VL53L1X.h" and #include "I2C_Anything.h" below
01/17/22 the local version of "I2C_Anything.h" uses '#include <i2c_t3.h>' vice <Wire.h> for multiple
I2C buss availability.
01/18/22 removed I2C_Anything.h & VL53L1X.h from project folder so can use library versions
01/22/22 added #ifdef NO_VL53L1X and assoc #ifndef blocks for debug
*/
#pragma endregion EARLIER_VERSIONS
#include <Wire.h> //01/18/22 Wire.h has multiple I2C bus access capability
#include <VL53L1X.h>
#include <I2C_Anything.h>
#include "elapsedMillis.h"
#pragma region DEFINES
//#define NO_VL53L1X
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) //added 01/26/23 to extract pgm filename from full path
#pragma endregion DEFINES
enum VL53L1X_REQUEST
{
VL53L1X_READYCHECK, //added 11/10/20 to prevent bad reads during Teensy setup()
VL53L1X_CENTERS_ONLY,
VL53L1X_RIGHT,
VL53L1X_LEFT,
VL53L1X_ALL, //added 08/05/20, chg 'BOTH' to 'ALL' 10/31/20
VL53L1X_REAR_ONLY //added 10/24/20
};
#pragma region GLOBALS
volatile uint8_t request_type;
const int SETUP_DURATION_OUTPUT_PIN = 33;
const int REQUEST_EVENT_DURATION_OUTPUT_PIN = 34;
bool bTeensyReady = false;
//const int MSEC_BETWEEN_LED_TOGGLES = 100;
const int MSEC_BETWEEN_LED_TOGGLES = 300;//02/21/22 chg so can visually detect live I2C xfrs
elapsedMillis mSecBetweenLEDToggle;
//right side array
uint16_t RF_Dist_mm;
uint16_t RC_Dist_mm;
uint16_t RR_Dist_mm;
//left side array & rear
uint16_t LF_Dist_mm;
uint16_t LC_Dist_mm;
uint16_t LR_Dist_mm;
uint16_t Rear_Dist_mm;
//02/20/22 back to using float for steer values
float RightSteeringVal;
float LeftSteeringVal;
const int SLAVE_ADDRESS = 0x20; //(32Dec) just a guess for now
const int DEFAULT_VL53L1X_ADDR = 0x29;
//XSHUT required for I2C address init
//right side array
const int RF_XSHUT_PIN = 23;
const int RC_XSHUT_PIN = 22;
const int RR_XSHUT_PIN = 21;
//left side array
const int LF_XSHUT_PIN = 5;
const int LC_XSHUT_PIN = 6;
const int LR_XSHUT_PIN = 7;
const int Rear_XSHUT_PIN = 8;
//const int MAX_LIDAR_RANGE_MM = 1000; //make it obvious when nearest object is out of range
const int MAX_LIDAR_RANGE_MM = 3000; //VL53L1X can go out past 3m
//04/15/23 The Pololu VL53L1X library uses a parameterless constructor
// and a subsequent 'setBus()' function to change the I2C bus
//right side array
VL53L1X lidar_RF;
VL53L1X lidar_RC;
VL53L1X lidar_RR;
//left side array
VL53L1X lidar_LF;
VL53L1X lidar_LC;
VL53L1X lidar_LR;
//Rear sensor
VL53L1X lidar_Rear;
#pragma endregion GLOBALS
void setup()
{
bTeensyReady = false; //11/10/20 prevent bad data reads by main controller
Serial.begin(115200);
// wait until serial port opens
delay(3000);
Wire.begin(SLAVE_ADDRESS); //set Teensy Wire0 port up as slave
Wire.onRequest(requestEvent); //ISR for I2C requests from master (Mega 2560)
Wire.onReceive(receiveEvent); //ISR for I2C data from master (Mega 2560)
//initialize Wire1 & Wire2 to talk to the two arrays, plus the rear sensor
Wire1.begin();
Wire2.begin();
//__FILENAME__ dynamically filled with program name
Serial.printf("%lu: Starting setup() for %s\n", millis(), __FILENAME__);
#pragma region PIN_INITIALIZATION
pinMode(SETUP_DURATION_OUTPUT_PIN, OUTPUT);
pinMode(REQUEST_EVENT_DURATION_OUTPUT_PIN, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(SETUP_DURATION_OUTPUT_PIN, HIGH);
//right-side XSHUT control pins
pinMode(RF_XSHUT_PIN, OUTPUT);
pinMode(RC_XSHUT_PIN, OUTPUT);
pinMode(RR_XSHUT_PIN, OUTPUT);
//left-side XSHUT control pins
pinMode(LF_XSHUT_PIN, OUTPUT);
pinMode(LC_XSHUT_PIN, OUTPUT);
pinMode(LR_XSHUT_PIN, OUTPUT);
pinMode(Rear_XSHUT_PIN, OUTPUT);
#pragma endregion PIN_INITIALIZATION
#pragma region VL53L1X_INIT
//04/15/23 The Pololu VL53L1X library uses a parameterless constructor
// and a subsequent 'setBus()' function to change the I2C bus
//left side array I2C SLC2/SDA2 pins 3/4
lidar_LF.setBus(&Wire2);
lidar_LC.setBus(&Wire2);
lidar_LR.setBus(&Wire2);
lidar_Rear.setBus(&Wire2);
//right side array I2C SLC1/SDA1 pins 37/38
lidar_RF.setBus(&Wire1);
lidar_RC.setBus(&Wire1);
lidar_RR.setBus(&Wire1);
//Put all sensors in reset mode by pulling XSHUT low
digitalWrite(RF_XSHUT_PIN, LOW);
digitalWrite(RC_XSHUT_PIN, LOW);
digitalWrite(RR_XSHUT_PIN, LOW);
digitalWrite(LF_XSHUT_PIN, LOW);
digitalWrite(LC_XSHUT_PIN, LOW);
digitalWrite(LR_XSHUT_PIN, LOW);
digitalWrite(Rear_XSHUT_PIN, LOW);
//now bring lidar_RF only out of reset and set it's address
//input w/o pullups sets line to high impedance so XSHUT pullup to 3.3V takes over
pinMode(RF_XSHUT_PIN, INPUT);
delay(10);
if (!lidar_RF.init())
{
Serial.println("Failed to detect and initialize lidar_RF!");
while (1) {}
}
//from Pololu forum post
lidar_RF.setMeasurementTimingBudget(30000); //11/20/22
//lidar_RF.setMeasurementTimingBudget(50000); //11/17/22
lidar_RF.startContinuous(50);
lidar_RF.setAddress(DEFAULT_VL53L1X_ADDR + 1);
Serial.printf("lidar_RF address is 0x%x\n", lidar_RF.getAddress());
//now bring lidar_RC only out of reset, initialize it, and set its address
//input w/o pullups sets line to high impedance so XSHUT pullup to 3.3V takes over
pinMode(RC_XSHUT_PIN, INPUT);
delay(10);
if (!lidar_RC.init())
{
Serial.println("Failed to detect and initialize lidar_RC!");
while (1) {}
}
//from Pololu forum post
lidar_RC.setMeasurementTimingBudget(30000); //11/20/22
//lidar_RC.setMeasurementTimingBudget(50000); //11/17/22
lidar_RC.startContinuous(50);
lidar_RC.setAddress(DEFAULT_VL53L1X_ADDR + 2);
Serial.printf("lidar_RC address is 0x%x\n", lidar_RC.getAddress());
//now bring lidar_RR only out of reset, initialize it, and set its address
//input w/o pullups sets line to high impedance so XSHUT pullup to 3.3V takes over
pinMode(RR_XSHUT_PIN, INPUT);
delay(10);
if (!lidar_RR.init())
{
Serial.println("Failed to detect and initialize lidar_RR!");
while (1) {}
}
//from Pololu forum post
lidar_RR.setMeasurementTimingBudget(30000); //11/20/22
//lidar_RR.setMeasurementTimingBudget(50000); //11/17/22
lidar_RR.startContinuous(50);
lidar_RR.setAddress(DEFAULT_VL53L1X_ADDR + 3);
Serial.printf("lidar_RR address is 0x%x\n", lidar_RR.getAddress());
//now bring lidar_LF only out of reset, initialize it, and set its address
//input w/o pullups sets line to high impedance so XSHUT pullup to 3.3V takes over
//pinMode(LF_XSHUT_PIN, INPUT);
digitalWrite(LF_XSHUT_PIN, HIGH);
//Serial.printf("lidar_LF LF_XSHUT_PIN now reads %d\n", digitalRead(LF_XSHUT_PIN));
delay(10);
if (!lidar_LF.init())
{
Serial.println("Failed to detect and initialize lidar_LF!");
//while (1) {}
}
//from Pololu forum post
lidar_LF.setMeasurementTimingBudget(30000);
//lidar_LF.setMeasurementTimingBudget(50000); //11/20/22
lidar_LF.startContinuous(50);
lidar_LF.setAddress(DEFAULT_VL53L1X_ADDR + 4);
Serial.printf("lidar_LF address is 0x%x\n", lidar_LF.getAddress());
//now bring lidar_LC only out of reset, initialize it, and set its address
//input w/o pullups sets line to high impedance so XSHUT pullup to 3.3V takes over
pinMode(LC_XSHUT_PIN, INPUT);
delay(10);
if (!lidar_LC.init())
{
Serial.println("Failed to detect and initialize lidar_LC!");
while (1) {}
}
//from Pololu forum post
lidar_LC.setMeasurementTimingBudget(30000);
//lidar_LC.setMeasurementTimingBudget(50000); //11/20/22
lidar_LC.startContinuous(50);
lidar_LC.setAddress(DEFAULT_VL53L1X_ADDR + 5);
Serial.printf("lidar_LC address is 0x%x\n", lidar_LC.getAddress());
//now bring lidar_LR only out of reset, initialize it, and set its address
//input w/o pullups sets line to high impedance so XSHUT pullup to 3.3V takes over
pinMode(LR_XSHUT_PIN, INPUT);
if (!lidar_LR.init())
{
Serial.println("Failed to detect and initialize lidar_LR!");
while (1) {}
}
//from Pololu forum post
lidar_LR.setMeasurementTimingBudget(30000);
//lidar_LR.setMeasurementTimingBudget(50000); //11/20/22
lidar_LR.startContinuous(50);
lidar_LR.setAddress(DEFAULT_VL53L1X_ADDR + 6);
Serial.printf("lidar_LR address is 0x%x\n", lidar_LR.getAddress());
//added 10/23/20 for rear sensor
//now bring lidar_Rear only out of reset, initialize it, and set its address
//input w/o pullups sets line to high impedance so XSHUT pullup to 3.3V takes over
pinMode(Rear_XSHUT_PIN, INPUT);
if (!lidar_Rear.init())
{
Serial.println("Failed to detect and initialize lidar_Rear!");
//while (1) {}
}
//from Pololu forum post
lidar_Rear.setMeasurementTimingBudget(30000);
//lidar_Rear.setMeasurementTimingBudget(50000); //11/20/22
lidar_Rear.startContinuous(50);
lidar_Rear.setAddress(DEFAULT_VL53L1X_ADDR + 7);
Serial.printf("lidar_Rear address is 0x%x\n", lidar_Rear.getAddress());
#pragma endregion VL53L1X_INIT
digitalWrite(SETUP_DURATION_OUTPUT_PIN, LOW);
bTeensyReady = true; //11/10/20 added to prevent bad data reads by main controller
mSecBetweenLEDToggle = 0;
Serial.printf("Msec\tLFront\tLCtr\tLRear\tRFront\tRCtr\tRRear\tRear\tLSteer\tRSteer\n");
}
void loop()
{
//04/03/22 now using a per-unit correction algorithm
RF_Dist_mm = lidar_RF_Correction(lidar_RF.readRangeContinuousMillimeters());
RC_Dist_mm = lidar_RC_Correction(lidar_RC.readRangeContinuousMillimeters());
RR_Dist_mm = lidar_RR_Correction(lidar_RR.readRangeContinuousMillimeters());
RightSteeringVal = (RF_Dist_mm - RR_Dist_mm) / 100.f; //rev 06/21/20 see PPalace post
//from Pololu forum post
//LF_Dist_mm = lidar_LF.readRangeContinuousMillimeters();
//LC_Dist_mm = lidar_LC.readRangeContinuousMillimeters();
//LR_Dist_mm = lidar_LR.readRangeContinuousMillimeters();
//04/03/22 now using a per-unit correction algorithm
LF_Dist_mm = lidar_LF_Correction(lidar_LF.readRangeContinuousMillimeters());
LC_Dist_mm = lidar_LC_Correction(lidar_LC.readRangeContinuousMillimeters());
LR_Dist_mm = lidar_LR_Correction(lidar_LR.readRangeContinuousMillimeters());
LeftSteeringVal = (LF_Dist_mm - LR_Dist_mm) / 100.f; //rev 06/21/20 see PPalace post
//added 10/23/20 for rear sensor
//Rear_Dist_mm = lidar_Rear.readRangeContinuousMillimeters();
Rear_Dist_mm = lidar_Rear_Correction(lidar_Rear.readRangeContinuousMillimeters());
if (mSecBetweenLEDToggle <= MSEC_BETWEEN_LED_TOGGLES)
{
mSecBetweenLEDToggle -= MSEC_BETWEEN_LED_TOGGLES;
//digitalToggle(LED_BUILTIN);
Serial.printf("%lu\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%2.2f\t%2.2f\n",
millis(), LF_Dist_mm, LC_Dist_mm, LR_Dist_mm, RF_Dist_mm, RC_Dist_mm, RR_Dist_mm, Rear_Dist_mm,
LeftSteeringVal, RightSteeringVal);
}
}
void requestEvent()
{
//Purpose: Send requested sensor data to the Mega controller via main I2C bus
//Inputs:
// request_type = uint8_t value denoting type of data requested (from receiveEvent())
// 0 = left & right center distances only
// 1 = right side front, center and rear distances, plus steering value
// 2 = left side front, center and rear distances, plus steering value
// 3 = both side front, center and rear distances, plus both steering values
//Outputs:
// Requested data sent to master
//Notes:
// 08/05/20 added VL53L1X_ALL request type to get both sides at once
// 10/24/20 added VL53L1X_REAR_ONLY request type
// 11/09/20 added write to pin for O'scope monitoring
//DEBUG!!
//int data_size = 0;
//DEBUG!!
//DEBUG!!
//Serial.printf("RequestEvent() with request_type = %d: VL53L0X Front/Center/Rear distances = %d, %d, %d\n",
// request_type, RF_Dist_mm, RC_Dist_mm, RR_Dist_mm);
//DEBUG!!
//digitalWrite(LED_BUILTIN, HIGH);//added 01/22/22
digitalWrite(REQUEST_EVENT_DURATION_OUTPUT_PIN, HIGH);
digitalToggle(LED_BUILTIN);//2/21/22 added for visual indication of I2C activity
switch (request_type)
{
case VL53L1X_READYCHECK: //added 11/10/20 to prevent bad reads during Teensy setup()
Serial.printf("in VL53L1X_READYCHECK case at %lu with bTeensyReady = %d\n", millis(), bTeensyReady);
I2C_writeAnything(bTeensyReady);
break;
case VL53L1X_CENTERS_ONLY:
//DEBUG!!
//data_size = 2*sizeof(uint16_t);
//Serial.printf("Sending %d bytes LC_Dist_mm = %d, RC_Dist_mm = %d to master\n", data_size, LC_Dist_mm, RC_Dist_mm);
//DEBUG!!
I2C_writeAnything(RC_Dist_mm);
I2C_writeAnything(LC_Dist_mm);
break;
case VL53L1X_RIGHT:
//DEBUG!!
//data_size = 3 * sizeof(uint16_t) + sizeof(float);
//Serial.printf("Sending %d bytes RF/RC/RR/RS vals = %d, %d, %d, %3.2f to master\n",
// data_size, RF_Dist_mm, RC_Dist_mm, RR_Dist_mm, RightSteeringVal);
//DEBUG!!
I2C_writeAnything(RF_Dist_mm);
I2C_writeAnything(RC_Dist_mm);
I2C_writeAnything(RR_Dist_mm);
I2C_writeAnything(RightSteeringVal);
break;
case VL53L1X_LEFT:
//DEBUG!!
//data_size = 3 * sizeof(uint16_t) + sizeof(float);
//Serial.printf("Sending %d bytes LF/LC/LR/LS vals = %d, %d, %d, %3.2f to master\n",
// data_size, LF_Dist_mm, LC_Dist_mm, LR_Dist_mm, LeftSteeringVal);
//DEBUG!!
I2C_writeAnything(LF_Dist_mm);
I2C_writeAnything(LC_Dist_mm);
I2C_writeAnything(LR_Dist_mm);
I2C_writeAnything(LeftSteeringVal);
break;
case VL53L1X_ALL:
//Serial.printf("In VL53L1X_ALL case\n");
//added 08/05/20 to get data from both sides at once
//10/31/20 chg to VL53L1X_ALL & report all 7 sensor values
//DEBUG!!
//data_size = 3 * sizeof(uint16_t) + sizeof(float);
//data_size = 7 * sizeof(uint16_t) + 2 * sizeof(float);
//Serial.printf("Sending %d bytes to master\n", data_size);
//Serial.printf("%d bytes: %d\t%d\t%d\t%3.2f\t%d\t%d\t%d\t%d\t%3.2f\n",
// data_size, LF_Dist_mm, LC_Dist_mm, LR_Dist_mm, LeftSteeringVal,
// RF_Dist_mm, RC_Dist_mm, RR_Dist_mm, Rear_Dist_mm, RightSteeringVal);
//DEBUG!!
//DEBUG!!
//data_size = 3 * sizeof(uint16_t) + sizeof(float);
//Serial.printf("Sending %d bytes LF/LC/LR/LS vals = %d, %d, %d, %3.2f to master\n",
// data_size, LF_Dist_mm, LC_Dist_mm, LR_Dist_mm, LeftSteeringVal);
//DEBUG!!
//left side
I2C_writeAnything(LF_Dist_mm);
I2C_writeAnything(LC_Dist_mm);
I2C_writeAnything(LR_Dist_mm);
I2C_writeAnything(LeftSteeringVal);
//DEBUG!!
//data_size = 3 * sizeof(uint16_t) + sizeof(float);
//data_size = 4 * sizeof(uint16_t) + sizeof(float);
//Serial.printf("Sending %d bytes RF/RC/RR/R/RS vals = %d, %d, %d, %d, %3.2f to master\n",
// data_size, RF_Dist_mm, RC_Dist_mm, RR_Dist_mm, Rear_Dist_mm, RightSteeringVal);
//DEBUG!!
//right side
I2C_writeAnything(RF_Dist_mm);
I2C_writeAnything(RC_Dist_mm);
I2C_writeAnything(RR_Dist_mm);
I2C_writeAnything(Rear_Dist_mm);
I2C_writeAnything(RightSteeringVal);
break;
case VL53L1X_REAR_ONLY:
//DEBUG!!
//data_size = sizeof(uint16_t);
//Serial.printf("Sending %d bytes Rear_Dist_mm = %d to master\n", data_size, Rear_Dist_mm);
//DEBUG!!
I2C_writeAnything(Rear_Dist_mm);
break;
default:
break;
}
digitalToggle(LED_BUILTIN);//2/21/22 added for visual indication of I2C activity
digitalWrite(REQUEST_EVENT_DURATION_OUTPUT_PIN, LOW);
//digitalWrite(LED_BUILTIN, LOW);//added 01/22/22
}
void receiveEvent(int numBytes)
{
//Purpose: capture data request type from Mega I2C master
//Inputs:
// numBytes = int value denoting number of bytes received from master
//Outputs:
// uint8_t request_type filled with request type value from master
//DEBUG!!
//Serial.printf("receiveEvent(%d)\n", numBytes);
//DEBUG!!
I2C_readAnything(request_type);
//DEBUG!!
//Serial.printf("receiveEvent: Got %d from master\n", request_type);
//DEBUG!!
}
uint16_t lidar_LF_Correction(uint16_t raw_dist)
{
//Purpose: Correct for linear error in left front VL53L0X
//Provenance: Created 04/03/22 gfp
//Inputs:
// raw_dist = uint16_t value denoting raw measurement in mm
//Outputs:
// returns raw_dist (mm) corrected for linear distance measurement error
//Notes:
// correction = =(raw + 0.4)/1.125
// 04/05/22 bugfix. Raw dist here are MM, but above formula assumed CM - fixed below
// correction = =(raw(mm) + 4)/1.125
//uint16_t corrVal = (uint16_t)((float)raw_dist + 0.4f) / 1.125f;
//uint16_t corrVal = (uint16_t)((float)raw_dist + 4.f) / 1.125f;
//uint16_t corrVal = raw_dist;
uint16_t corrVal = (uint16_t)((float)raw_dist - 5.478f) / 1.0918f;//11/20/22
//DEBUG!!
//Serial.printf("LF: raw = %d, corr = %d\n", raw_dist, corrVal);
//DEBUG!!
return corrVal;
}
uint16_t lidar_LC_Correction(uint16_t raw_dist)
{
//Purpose: Correct for linear error in left center VL53L0X
//Provenance: Created 04/03/22 gfp
//Inputs:
// raw_dist = uint16_t value denoting raw measurement in mm
//Outputs:
// returns raw_dist corrected for linear distance measurement error
//Notes:
// correction = ==(raw - 0.6333)/1.03
// 04/05/22 bugfix. Raw dist here are MM, but above formula assumed CM - fixed below
// correction = =(raw(mm) - 6.333)/1.03
//uint16_t corrVal = (uint16_t)((float)raw_dist - 0.6333f) / 1.03f;
//uint16_t corrVal = (uint16_t)((float)raw_dist - 6.333f) / 1.03f;
//uint16_t corrVal = raw_dist;
uint16_t corrVal = (uint16_t)((float)raw_dist - 19.89f) / 0.9913f;//11/20/22
//DEBUG!!
//Serial.printf("LC: raw = %d, corr = %d\n", raw_dist, corrVal);
//DEBUG!!
return corrVal;
}
uint16_t lidar_LR_Correction(uint16_t raw_dist)
{
//Purpose: Correct for linear error in left rear VL53L0X
//Provenance: Created 04/03/22 gfp
//Inputs:
// raw_dist = uint16_t value denoting raw measurement in mm
//Outputs:
// returns raw_dist corrected for linear distance measurement error
//Notes:
// correction = =raw - 2.0667
// 04/05/22 bugfix. Raw dist here are MM, but above formula assumed CM - fixed below
// correction = = raw(mm) - 20.667
//uint16_t corrVal = (uint16_t)((float)raw_dist - 2.0667f);
//uint16_t corrVal = (uint16_t)((float)raw_dist - 20.667f);
//uint16_t corrVal = raw_dist;
uint16_t corrVal = (uint16_t)((float)raw_dist + 9.676f) / 1.1616;
//DEBUG!!
//Serial.printf("LR: raw = %d, corr = %d\n", raw_dist, corrVal);
//DEBUG!!
return corrVal;
}
uint16_t lidar_RF_Correction(uint16_t raw_dist)
{
//Purpose: Correct for linear error in right front VL53L0X
//Provenance: Created 04/03/22 gfp
//Inputs:
// raw_dist = uint16_t value denoting raw measurement in mm
//Outputs:
// returns raw_dist corrected for linear distance measurement error in mm
//Notes:
// correction = =(raw + 0.96)/1.045
// 04/05/22 bugfix. Raw dist here are MM, but above formula assumed CM - fixed below
// correction = =(raw(mm) + 9.6f)/1.03f
//uint16_t corrVal = (uint16_t)((float)raw_dist + 0.96f) / 1.045f;
//uint16_t corrVal = (uint16_t)((float)raw_dist + 9.6f) / 1.045f;
//uint16_t corrVal = raw_dist; //11/18/22
uint16_t corrVal = (uint16_t)((float)raw_dist - 4.297f) / 1.0808f;
//DEBUG!!
//Serial.printf("RF: raw = %d, corr = %d\n", raw_dist, corrVal);
//DEBUG!!
return corrVal;
}
uint16_t lidar_RC_Correction(uint16_t raw_dist)
{
//Purpose: Correct for linear error in right center VL53L0X
//Provenance: Created 04/03/22 gfp
//Inputs:
// raw_dist = uint16_t value denoting raw measurement in mm
//Outputs:
// returns raw_dist corrected for linear distance measurement error
//Notes:
// correction = =(raw - 3.2)/1.08
// 04/05/22 bugfix. Raw dist here are MM, but above formula assumed CM - fixed below
// correction = =(raw(mm) - 3.2)/1.08
//uint16_t corrVal = (uint16_t)((float)raw_dist - 3.2f) / 1.08f;
//uint16_t corrVal = (uint16_t)((float)raw_dist - 32.f) / 1.08f;
//uint16_t corrVal = raw_dist;
uint16_t corrVal = (uint16_t)((float)raw_dist - 50.603f) / 1.0438f;
//DEBUG!!
//Serial.printf("RC: raw = %d, corr = %d\n", raw_dist, corrVal);
//DEBUG!!
return corrVal;
}
uint16_t lidar_RR_Correction(uint16_t raw_dist)
{
//Purpose: Correct for linear error in right rear VL53L0X
//Provenance: Created 04/03/22 gfp
//Inputs:
// raw_dist = uint16_t value denoting raw measurement in mm
//Outputs:
// returns raw_dist corrected for linear distance measurement error
//Notes:
// correction = =(raw - 3.1)/1.12
// 04/05/22 bugfix. Raw dist here are MM, but above formula assumed CM - fixed below
// correction = =(raw(mm) - 31)/1.12
//uint16_t corrVal = (uint16_t)((float)raw_dist - 3.1f) / 1.12f;
//uint16_t corrVal = (uint16_t)((float)raw_dist - 31.f) / 1.12f;
//uint16_t corrVal = raw_dist;
uint16_t corrVal = (uint16_t)((float)raw_dist - 56.746f) / 1.0353;
//DEBUG!!
//Serial.printf("RR: raw = %d, corr = %d\n", raw_dist, corrVal);
//DEBUG!!
return corrVal;
}
uint16_t lidar_Rear_Correction(uint16_t raw_dist)
{
//Purpose: Correct for linear error in rear VL53L0X
//Provenance: Created 04/03/22 gfp
//Inputs:
// raw_dist = uint16_t value denoting raw measurement in mm
//Outputs:
// returns raw_dist corrected for linear distance measurement error
//Notes:
// correction = ==(raw - 1.1)/1.09
// 04/05/22 bugfix. Raw dist here are MM, but above formula assumed CM - fixed below
// correction = =(raw(mm) - 11)/1.09
//uint16_t corrVal = (uint16_t)((float)raw_dist - 1.1f) / 1.09f;
uint16_t corrVal = (uint16_t)((float)raw_dist - 11.f) / 1.09f;
//DEBUG!!
//Serial.printf("Rear: raw = %d, corr = %d\n", raw_dist, corrVal);
//DEBUG!!
return corrVal;
}