2016-05-04 00:02:44 -03:00
|
|
|
#pragma once
|
|
|
|
|
2023-07-06 01:25:14 -03:00
|
|
|
#include "AP_RangeFinder_config.h"
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#if AP_RANGEFINDER_MAVLINK_ENABLED
|
|
|
|
|
2023-07-06 01:25:14 -03:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
|
|
|
|
2016-05-04 00:02:44 -03:00
|
|
|
// Data timeout
|
2016-05-03 23:55:05 -03:00
|
|
|
#define AP_RANGEFINDER_MAVLINK_TIMEOUT_MS 500
|
2016-05-04 00:02:44 -03:00
|
|
|
|
2016-05-03 23:55:05 -03:00
|
|
|
class AP_RangeFinder_MAVLink : public AP_RangeFinder_Backend
|
2016-05-04 00:02:44 -03:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2022-06-22 08:03:22 -03:00
|
|
|
|
2016-05-04 00:02:44 -03:00
|
|
|
// constructor
|
2020-12-04 20:52:42 -04:00
|
|
|
using AP_RangeFinder_Backend::AP_RangeFinder_Backend;
|
2016-05-04 00:02:44 -03:00
|
|
|
|
2020-12-04 20:52:42 -04:00
|
|
|
// Assume that if the user set the RANGEFINDER_TYPE parameter to MAVLink,
|
|
|
|
// there is an attached MAVLink rangefinder
|
|
|
|
static bool detect() { return true; }
|
2016-05-04 00:02:44 -03:00
|
|
|
|
|
|
|
// update state
|
2018-11-07 07:01:51 -04:00
|
|
|
void update(void) override;
|
2016-05-04 00:02:44 -03:00
|
|
|
|
|
|
|
// Get update from mavlink
|
2019-04-30 07:22:49 -03:00
|
|
|
void handle_msg(const mavlink_message_t &msg) override;
|
2016-05-04 00:02:44 -03:00
|
|
|
|
2020-12-25 04:38:49 -04:00
|
|
|
int16_t max_distance_cm() const override;
|
|
|
|
int16_t min_distance_cm() const override;
|
2020-12-05 02:49:18 -04:00
|
|
|
|
2023-08-14 17:21:56 -03:00
|
|
|
// Get the reading confidence
|
|
|
|
// 100 is best quality, 0 is worst
|
|
|
|
WARN_IF_UNUSED bool get_signal_quality_pct(int8_t &quality_pct) const override;
|
|
|
|
|
2017-08-08 04:32:53 -03:00
|
|
|
protected:
|
|
|
|
|
|
|
|
MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
|
|
|
return sensor_type;
|
|
|
|
}
|
|
|
|
|
2016-05-04 00:02:44 -03:00
|
|
|
private:
|
2020-12-05 02:49:18 -04:00
|
|
|
|
|
|
|
// stored data from packet:
|
2016-05-03 23:55:05 -03:00
|
|
|
uint16_t distance_cm;
|
2020-12-05 02:49:18 -04:00
|
|
|
uint16_t _max_distance_cm;
|
|
|
|
uint16_t _min_distance_cm;
|
2023-08-14 17:21:56 -03:00
|
|
|
int8_t signal_quality;
|
2016-05-04 00:02:44 -03:00
|
|
|
|
|
|
|
// start a reading
|
|
|
|
static bool start_reading(void);
|
|
|
|
static bool get_reading(uint16_t &reading_cm);
|
2017-08-08 04:32:53 -03:00
|
|
|
|
|
|
|
MAV_DISTANCE_SENSOR sensor_type = MAV_DISTANCE_SENSOR_UNKNOWN;
|
2016-05-04 00:02:44 -03:00
|
|
|
};
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#endif
|