2017-02-09 07:30:04 -04:00
|
|
|
#pragma once
|
|
|
|
|
2023-04-05 09:25:54 -03:00
|
|
|
#include "AP_Proximity_config.h"
|
|
|
|
|
|
|
|
#if AP_PROXIMITY_RANGEFINDER_ENABLED
|
2017-02-09 07:30:04 -04:00
|
|
|
|
2023-04-05 09:25:54 -03:00
|
|
|
#include "AP_Proximity_Backend.h"
|
2021-03-25 04:32:09 -03:00
|
|
|
|
2018-05-11 16:29:11 -03:00
|
|
|
#define PROXIMITY_RANGEFIDER_TIMEOUT_MS 200 // requests timeout after 0.2 seconds
|
2017-02-09 07:30:04 -04:00
|
|
|
|
|
|
|
class AP_Proximity_RangeFinder : public AP_Proximity_Backend
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor
|
2019-09-27 06:33:18 -03:00
|
|
|
using AP_Proximity_Backend::AP_Proximity_Backend;
|
2017-02-09 07:30:04 -04:00
|
|
|
|
|
|
|
// update state
|
2018-11-07 07:01:30 -04:00
|
|
|
void update(void) override;
|
2017-02-09 07:30:04 -04:00
|
|
|
|
|
|
|
// get maximum and minimum distances (in meters) of sensor
|
2018-11-07 07:01:30 -04:00
|
|
|
float distance_max() const override { return _distance_max; }
|
|
|
|
float distance_min() const override { return _distance_min; }
|
2017-02-09 07:30:04 -04:00
|
|
|
|
|
|
|
// get distance upwards in meters. returns true on success
|
2018-11-07 07:01:30 -04:00
|
|
|
bool get_upward_distance(float &distance) const override;
|
2017-02-09 07:30:04 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// horizontal distance support
|
|
|
|
uint32_t _last_update_ms; // system time of last RangeFinder reading
|
|
|
|
float _distance_max; // max range of sensor in meters
|
|
|
|
float _distance_min; // min range of sensor in meters
|
|
|
|
|
|
|
|
// upward distance support
|
|
|
|
uint32_t _last_upward_update_ms; // system time of last update distance
|
2019-09-27 06:33:18 -03:00
|
|
|
float _distance_upward = -1; // upward distance in meters, negative if the last reading was out of range
|
2017-02-09 07:30:04 -04:00
|
|
|
};
|
2021-03-25 04:32:09 -03:00
|
|
|
|
2023-04-05 09:25:54 -03:00
|
|
|
#endif // AP_PROXIMITY_RANGEFINDER_ENABLED
|