17 #include <sensor_msgs/Range.h> 18 #include <vl53l1x/MeasurementData.h> 24 #define STR(x) xSTR(x) 26 #define CHECK_STATUS(func) { \ 27 VL53L1_Error status = func; \ 28 if (status != VL53L1_ERROR_NONE) { \ 29 ROS_WARN("VL53L1X: Error %d on %s", status, STR(func)); \ 33 int main(
int argc,
char **argv)
38 sensor_msgs::Range range;
39 vl53l1x::MeasurementData data;
40 range.radiation_type = sensor_msgs::Range::INFRARED;
45 int mode, i2c_bus, i2c_address;
46 double poll_rate, timing_budget, offset;
47 bool ignore_range_status;
52 nh_priv.
param(
"mode", mode, 3);
53 nh_priv.
param(
"i2c_bus", i2c_bus, 1);
54 nh_priv.
param(
"i2c_address", i2c_address, 0x29);
55 nh_priv.
param(
"poll_rate", poll_rate, 100.0);
56 nh_priv.
param(
"ignore_range_status", ignore_range_status,
false);
57 nh_priv.
param(
"timing_budget", timing_budget, 0.1);
58 nh_priv.
param(
"offset", offset, 0.0);
59 nh_priv.
param<std::string>(
"frame_id", range.header.frame_id,
"");
60 nh_priv.
param(
"field_of_view", range.field_of_view, 0.471239f);
61 nh_priv.
param(
"min_range", range.min_range, 0.0f);
62 nh_priv.
param(
"max_range", range.max_range, 4.0f);
63 nh_priv.
getParam(
"pass_statuses", pass_statuses);
65 if (timing_budget < 0.02 || timing_budget > 1) {
66 ROS_FATAL(
"Error: timing_budget should be within 0.02 and 1 s (%g is set)", timing_budget);
71 double inter_measurement_period = timing_budget + 0.004;
99 if (nh_priv.
getParam(
"min_signal", min_signal)) {
104 if (nh_priv.
getParam(
"max_sigma", max_sigma)) {
109 for (
int i = 0; i < 100; i++) {
113 inter_measurement_period += 0.001;
119 ROS_FATAL(
"VL53L1X: Can't start measurement: error %d", dev_error);
145 data.header.stamp = range.header.stamp;
151 data_pub.publish(data);
154 if (!ignore_range_status &&
155 std::find(pass_statuses.begin(), pass_statuses.end(), measurement_data.
RangeStatus) == pass_statuses.end()) {
158 ROS_DEBUG(
"Range measurement status is not valid: %s", range_status);
VL53L1_Error VL53L1_StopMeasurement(VL53L1_DEV Dev)
Stop device measurement.
char Name[VL53L1_DEVINFO_STRLEN]
Defines the parameters of the Get Device Info Functions.
char Type[VL53L1_DEVINFO_STRLEN]
#define VL53L1_RANGESTATUS_RANGE_VALID
VL53L1_Error VL53L1_GetMeasurementDataReady(VL53L1_DEV Dev, uint8_t *pMeasurementDataReady)
Return Measurement Data Ready.
#define CHECK_STATUS(func)
uint16_t EffectiveSpadRtnCount
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE
uint8_t ProductRevisionMinor
FixPoint1616_t SignalRateRtnMegaCps
int main(int argc, char **argv)
#define VL53L1_ERROR_NONE
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
VL53L1_Error VL53L1_DataInit(VL53L1_DEV Dev)
One time device initialization.
VL53L1_Error VL53L1_get_range_status_string(uint8_t RangeStatus, char *pRangeStatusString)
Generates a string for the input device range status code.
VL53L1_Error VL53L1_WaitDeviceBooted(VL53L1_DEV Dev)
Wait for device booted after chip enable (hardware standby) This function can be run only when VL53L1...
#define VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL
VL53L1_Error VL53L1_SetMeasurementTimingBudgetMicroSeconds(VL53L1_DEV Dev, uint32_t MeasurementTimingBudgetMicroSeconds)
Set Ranging Timing Budget in microseconds.
VL53L1_Error VL53L1_SetPresetMode(VL53L1_DEV Dev, VL53L1_PresetModes PresetMode)
Set a new Preset Mode.
bool getParam(const std::string &key, std::string &s) const
VL53L1_Error VL53L1_SetLimitCheckValue(VL53L1_DEV Dev, uint16_t LimitCheckId, FixPoint1616_t LimitCheckValue)
Set a specific limit check value.
#define VL53L1_ERROR_INVALID_PARAMS
FixPoint1616_t SigmaMilliMeter
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void i2c_setup(uint8_t bus, uint8_t addr)
VL53L1_Error VL53L1_SetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev, uint32_t InterMeasurementPeriodMilliSeconds)
VL53L1_Error VL53L1_software_reset(VL53L1_DEV Dev)
Performs device software reset and then waits for the firmware to finish booting. ...
#define VL53L1_DEVINFO_STRLEN
#define VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE
VL53L1_Error VL53L1_ClearInterruptAndStartMeasurement(VL53L1_DEV Dev)
Clear the Interrupt flag and start new measurement *.
VL53L1_Error VL53L1_StaticInit(VL53L1_DEV Dev)
Do basic device init (and eventually patch loading) This function will change the VL53L1_State from V...
#define VL53L1_RANGESTATUS_RANGE_VALID_MERGED_PULSE
VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev)
Start device measurement.
Single Range measurement data.
#define VL53L1_PRESETMODE_AUTONOMOUS
VL53L1_Error VL53L1_GetDeviceInfo(VL53L1_DEV Dev, VL53L1_DeviceInfo_t *pVL53L1_DeviceInfo)
Reads the Device information for given Device.
ROSCPP_DECL void shutdown()
uint8_t ProductRevisionMajor
VL53L1_Error VL53L1_SetDistanceMode(VL53L1_DEV Dev, VL53L1_DistanceModes DistanceMode)
Set the distance mode.
ROSCPP_DECL void spinOnce()
VL53L1_Error VL53L1_GetRangingMeasurementData(VL53L1_DEV Dev, VL53L1_RangingMeasurementData_t *pRangingMeasurementData)
Retrieve the measurements from device for a given setup.
FixPoint1616_t AmbientRateRtnMegaCps
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
char ProductId[VL53L1_DEVINFO_STRLEN]