ll40ls: correct a write_reg issue (#12604)

* deprecate a goto statement
 * migrate to uniform initialization in LidarLite base class.
This commit is contained in:
Mark Sauder
2019-08-01 21:41:05 -06:00
committed by Daniel Agar
parent 8609be28a7
commit e0c85c8831
3 changed files with 20 additions and 31 deletions
@@ -42,12 +42,7 @@
#include "LidarLite.h" #include "LidarLite.h"
LidarLite::LidarLite(uint8_t rotation) : LidarLite::LidarLite(uint8_t rotation) :
_px4_rangefinder(0 /* device id not yet used */, ORB_PRIO_DEFAULT, rotation), _px4_rangefinder(0 /* device id not yet used */, ORB_PRIO_DEFAULT, rotation)
_sample_perf(perf_alloc(PC_ELAPSED, "ll40ls: read")),
_sample_interval_perf(perf_alloc(PC_ELAPSED, "ll40ls: interval")),
_comms_errors(perf_alloc(PC_COUNT, "ll40ls: comms errors")),
_sensor_resets(perf_alloc(PC_COUNT, "ll40ls: resets")),
_sensor_zero_resets(perf_alloc(PC_COUNT, "ll40ls: zero resets"))
{ {
_px4_rangefinder.set_min_distance(LL40LS_MIN_DISTANCE); _px4_rangefinder.set_min_distance(LL40LS_MIN_DISTANCE);
_px4_rangefinder.set_max_distance(LL40LS_MAX_DISTANCE_V3); _px4_rangefinder.set_max_distance(LL40LS_MAX_DISTANCE_V3);
+9 -10
View File
@@ -66,14 +66,12 @@ public:
virtual void stop() = 0; virtual void stop() = 0;
/** /**
* @brief * @brief Diagnostics - print some basic information about the driver.
* Diagnostics - print some basic information about the driver.
*/ */
void print_info(); void print_info();
/** /**
* @brief * @brief print registers to console
* print registers to console
*/ */
virtual void print_registers() {}; virtual void print_registers() {};
@@ -81,18 +79,19 @@ protected:
uint32_t get_measure_interval() const { return _measure_interval; } uint32_t get_measure_interval() const { return _measure_interval; }
virtual int measure() = 0;
virtual int collect() = 0; virtual int collect() = 0;
virtual int measure() = 0;
virtual int reset_sensor() { return PX4_ERROR; }; virtual int reset_sensor() { return PX4_ERROR; };
PX4Rangefinder _px4_rangefinder; PX4Rangefinder _px4_rangefinder;
perf_counter_t _sample_perf; perf_counter_t _comms_errors{perf_alloc(PC_COUNT, "ll40ls: comms errors")};
perf_counter_t _sample_interval_perf; perf_counter_t _sample_interval_perf{perf_alloc(PC_ELAPSED, "ll40ls: interval")};
perf_counter_t _comms_errors; perf_counter_t _sample_perf{perf_alloc(PC_ELAPSED, "ll40ls: read")};
perf_counter_t _sensor_resets; perf_counter_t _sensor_resets{perf_alloc(PC_COUNT, "ll40ls: resets")};
perf_counter_t _sensor_zero_resets; perf_counter_t _sensor_zero_resets{perf_alloc(PC_COUNT, "ll40ls: zero resets")};
private: private:
@@ -137,7 +137,8 @@ LidarLiteI2C::probe()
if (read_reg(LL40LS_UNIT_ID_HIGH, id_high) == OK && if (read_reg(LL40LS_UNIT_ID_HIGH, id_high) == OK &&
read_reg(LL40LS_UNIT_ID_LOW, id_low) == OK) { read_reg(LL40LS_UNIT_ID_LOW, id_low) == OK) {
_unit_id = (uint16_t)((id_high << 8) | id_low) & 0xFFFF; _unit_id = (uint16_t)((id_high << 8) | id_low) & 0xFFFF;
goto ok; _retries = 3;
return reset_sensor();
} }
PX4_DEBUG("probe failed unit_id=0x%02x", (unsigned)_unit_id); PX4_DEBUG("probe failed unit_id=0x%02x", (unsigned)_unit_id);
@@ -149,22 +150,17 @@ LidarLiteI2C::probe()
*/ */
if (read_reg(LL40LS_HW_VERSION, _hw_version) == OK && _hw_version > 0 && if (read_reg(LL40LS_HW_VERSION, _hw_version) == OK && _hw_version > 0 &&
read_reg(LL40LS_SW_VERSION, _sw_version) == OK && _sw_version > 0) { read_reg(LL40LS_SW_VERSION, _sw_version) == OK && _sw_version > 0) {
_px4_rangefinder.set_max_distance(LL40LS_MAX_DISTANCE_V1); _px4_rangefinder.set_max_distance(LL40LS_MAX_DISTANCE_V1);
goto ok; _retries = 3;
return reset_sensor();
} }
PX4_DEBUG("probe failed hw_version=0x%02x sw_version=0x%02x", (unsigned)_hw_version, (unsigned)_sw_version); PX4_DEBUG("probe failed hw_version=0x%02x sw_version=0x%02x", (unsigned)_hw_version, (unsigned)_sw_version);
} }
} }
// not found on any address // not found on any address
return -EIO; return -EIO;
ok:
_retries = 3;
return reset_sensor();
} }
int int
@@ -180,8 +176,7 @@ LidarLiteI2C::measure()
/* /*
* Send the command to begin a measurement. * Send the command to begin a measurement.
*/ */
const uint8_t cmd[2] = { LL40LS_MEASURE_REG, LL40LS_MSRREG_ACQUIRE }; int ret = write_reg(LL40LS_MEASURE_REG, LL40LS_MSRREG_ACQUIRE);
int ret = lidar_transfer(cmd, sizeof(cmd), nullptr, 0);
if (OK != ret) { if (OK != ret) {
perf_count(_comms_errors); perf_count(_comms_errors);