46 I2C(
"LL40LS", nullptr, bus, address, 100000),
47 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id()))
78 const uint8_t cmd[2] = { reg, val };
79 return transfer(&cmd[0], 2,
nullptr, 0);
85 if (send !=
nullptr && send_len > 0) {
86 int ret = transfer(send, send_len,
nullptr, 0);
93 if (recv !=
nullptr && recv_len > 0) {
94 return transfer(
nullptr, 0, recv, recv_len);
112 for (uint8_t i = 0; i <
sizeof(addresses); i++) {
114 set_device_address(addresses[i]);
128 _unit_id = (uint16_t)((id_high << 8) | id_low) & 0xFFFF;
148 PX4_INFO(
"probe success - id: %u",
_unit_id);
156 PX4_DEBUG(
"probe failed unit_id=0x%02x hw_version=0x%02x sw_version=0x%02x",
182 PX4_DEBUG(
"i2c::transfer returned %d", ret);
223 PX4_INFO(
"Error: ll40ls reset failure. Exiting!\n");
247 PX4_INFO(
"registers");
251 for (uint8_t reg = 0; reg <= 0x67; reg++) {
256 printf(
"%02x:XX ", (
unsigned)reg);
259 printf(
"%02x:%02x ", (
unsigned)reg, (
unsigned)val);
262 if (reg % 16 == 15) {
285 if (ret < 0 || (val[0] & 0x80)) {
292 PX4_DEBUG(
"error reading from sensor: %d", ret);
307 uint16_t distance_cm = (val[0] << 8) | val[1];
308 const float distance_m = float(distance_cm) * 1e-2
f;
310 if (distance_cm == 0) {
347 PX4_INFO(
"signal strength read failed");
349 DEVICE_DEBUG(
"error reading signal strength from sensor: %d", ret);
364 uint8_t ll40ls_signal_strength = val[0];
366 uint8_t signal_min = 0;
367 uint8_t signal_max = 0;
368 uint8_t signal_value = 0;
374 signal_value = ll40ls_signal_strength;
389 PX4_INFO(
"peak strength read failed");
391 DEVICE_DEBUG(
"error reading peak strength from sensor: %d", ret);
406 uint8_t ll40ls_peak_strength = val[0];
415 signal_value = ll40ls_peak_strength;
421 uint8_t signal_quality = 100 *
math::max(signal_value - signal_min, 0) / (signal_max - signal_min);
455 PX4_DEBUG(
"collection error");
483 PX4_DEBUG(
"measure error");
void set_max_distance(const float distance)
static constexpr uint32_t LL40LS_CONVERSION_INTERVAL
static constexpr uint8_t LL40LS_MSRREG_RESET
static constexpr uint8_t LL40LS_SW_VERSION
static constexpr uint8_t LL40LS_BASEADDR_OLD
LidarLiteI2C(const int bus, const uint8_t rotation=distance_sensor_s::ROTATION_DOWNWARD_FACING, const int address=LL40LS_BASEADDR)
int write_reg(const uint8_t reg, const uint8_t &val)
int lidar_transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
LidarLite specific transfer function.
static constexpr uint8_t LL40LS_MEASURE_REG
PX4Rangefinder _px4_rangefinder
static constexpr int LL40LS_SIGNAL_STRENGTH_MAX_V3HP
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
static constexpr uint8_t LL40LS_UNIT_ID_HIGH
static constexpr uint8_t LL40LS_SIG_COUNT_VAL_MAX
void update(const hrt_abstime timestamp, const float distance, const int8_t quality=-1)
void perf_count(perf_counter_t handle)
Count a performance event.
static constexpr float LL40LS_MAX_DISTANCE_V2
void init()
Activates/configures the hardware registers.
uint32_t get_measure_interval() const
int reset_sensor() override
Reset the sensor to power on defaults plus additional configurations.
uint64_t _acquire_time_usec
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
static hrt_abstime hrt_elapsed_time(const hrt_abstime *then)
Compute the delta between a timestamp taken in the past and now.
perf_counter_t _sensor_zero_resets
static constexpr uint8_t LL40LS_AUTO_INCREMENT
static constexpr uint8_t LL40LS_SIG_COUNT_VAL_DEFAULT
void perf_end(perf_counter_t handle)
End a performance event.
static constexpr int LL40LS_PEAK_STRENGTH_LOW
perf_counter_t _sample_perf
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
static constexpr uint8_t LL40LS_UNIT_ID_LOW
static constexpr int LL40LS_SIGNAL_STRENGTH_LOW
void print_registers() override
Print sensor registers to console for debugging.
static constexpr uint8_t LL40LS_SIGNAL_STRENGTH_REG
int read_reg(const uint8_t reg, uint8_t &val)
static constexpr uint8_t LL40LS_BASEADDR
static constexpr int LL40LS_PEAK_STRENGTH_HIGH
void stop() override
Stop the automatic measurement state machine.
perf_counter_t _sensor_resets
static constexpr int LL40LS_SIGNAL_STRENGTH_MIN_V3HP
static constexpr uint8_t LL40LS_SIG_COUNT_VAL_REG
static constexpr uint8_t LL40LS_HW_VERSION
constexpr _Tp max(_Tp a, _Tp b)
static constexpr uint8_t LL40LS_PEAK_STRENGTH_REG
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
static constexpr uint8_t LL40LS_DISTHIGH_REG
static constexpr uint8_t LL40LS_MSRREG_ACQUIRE
void start() override
Initialise the automatic measurement state machine and start it.
static constexpr float LL40LS_MIN_DISTANCE
perf_counter_t _comms_errors
static constexpr uint32_t LL40LS_CONVERSION_TIMEOUT
void perf_begin(perf_counter_t handle)
Begin a performance event.
#define DEVICE_DEBUG(FMT,...)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).