2016-02-17 21:25:44 -04:00
|
|
|
#pragma once
|
2015-09-07 02:32:06 -03:00
|
|
|
|
2023-07-06 01:25:14 -03:00
|
|
|
#include "AP_RangeFinder_config.h"
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#if AP_RANGEFINDER_LIGHTWARE_SERIAL_ENABLED
|
|
|
|
|
2023-07-06 01:25:14 -03:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend_Serial.h"
|
|
|
|
|
2019-11-01 03:12:26 -03:00
|
|
|
class AP_RangeFinder_LightWareSerial : public AP_RangeFinder_Backend_Serial
|
2015-09-07 02:32:06 -03:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2022-06-22 08:03:22 -03:00
|
|
|
static AP_RangeFinder_Backend_Serial *create(
|
|
|
|
RangeFinder::RangeFinder_State &_state,
|
|
|
|
AP_RangeFinder_Params &_params) {
|
|
|
|
return new AP_RangeFinder_LightWareSerial(_state, _params);
|
|
|
|
}
|
2015-09-07 02:32:06 -03:00
|
|
|
|
2017-08-08 04:32:53 -03:00
|
|
|
protected:
|
|
|
|
|
2022-06-22 08:03:22 -03:00
|
|
|
using AP_RangeFinder_Backend_Serial::AP_RangeFinder_Backend_Serial;
|
|
|
|
|
2020-01-13 01:48:07 -04:00
|
|
|
MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
2017-08-08 04:32:53 -03:00
|
|
|
return MAV_DISTANCE_SENSOR_LASER;
|
|
|
|
}
|
|
|
|
|
2023-08-18 12:24:47 -03:00
|
|
|
bool get_signal_quality_pct(int8_t &quality_pct) const override {
|
2021-11-18 20:03:14 -04:00
|
|
|
quality_pct = no_signal ? 0 : 100;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-07 02:32:06 -03:00
|
|
|
private:
|
|
|
|
// get a reading
|
2021-10-18 02:45:33 -03:00
|
|
|
bool get_reading(float &reading_m) override;
|
2021-11-17 17:21:48 -04:00
|
|
|
bool is_lost_signal_distance(int16_t distance_cm, int16_t distance_cm_max);
|
2015-09-07 02:32:06 -03:00
|
|
|
|
2020-06-29 08:16:54 -03:00
|
|
|
char linebuf[10]; // legacy protocol buffer
|
2020-06-30 09:06:46 -03:00
|
|
|
uint8_t linebuf_len; // legacy protocol buffer length
|
2020-06-29 08:16:54 -03:00
|
|
|
uint32_t last_init_ms; // init time used to switch lw20 to serial mode
|
|
|
|
uint8_t high_byte; // binary protocol high byte
|
|
|
|
bool high_byte_received; // true if high byte has been received
|
|
|
|
|
|
|
|
// automatic protocol decision variables
|
|
|
|
enum class ProtocolState {
|
2020-07-01 02:51:45 -03:00
|
|
|
UNKNOWN, // the protocol used is not yet known
|
|
|
|
LEGACY, // legacy protocol, distances are sent as strings
|
|
|
|
BINARY // binary protocol, distances are sent using two bytes
|
2020-06-29 08:16:54 -03:00
|
|
|
} protocol_state;
|
|
|
|
uint8_t legacy_valid_count;
|
|
|
|
uint8_t binary_valid_count;
|
2021-11-18 20:03:14 -04:00
|
|
|
|
|
|
|
bool no_signal = false;
|
2015-09-07 02:32:06 -03:00
|
|
|
};
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#endif // AP_RANGEFINDER_LIGHTWARE_SERIAL_ENABLED
|