2020-05-17 03:41:50 -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_HC_SR04_ENABLED
|
|
|
|
|
2023-07-06 01:25:14 -03:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
|
|
|
|
2020-05-17 03:41:50 -03:00
|
|
|
#include "AP_RangeFinder_Params.h"
|
|
|
|
|
|
|
|
class AP_RangeFinder_HC_SR04 : public AP_RangeFinder_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
AP_RangeFinder_HC_SR04(RangeFinder::RangeFinder_State &_state, AP_RangeFinder_Params &_params);
|
|
|
|
|
|
|
|
// static detection function
|
|
|
|
static bool detect(AP_RangeFinder_Params &_params);
|
|
|
|
|
|
|
|
// update state
|
|
|
|
void update(void) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
|
|
|
return MAV_DISTANCE_SENSOR_ULTRASOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-09-01 02:25:44 -03:00
|
|
|
bool check_pins();
|
|
|
|
bool check_echo_pin();
|
2020-05-17 03:41:50 -03:00
|
|
|
void check_trigger_pin();
|
|
|
|
|
|
|
|
int8_t trigger_pin;
|
|
|
|
uint32_t last_reading_ms; // system time of last read (used for health reporting)
|
2021-10-18 02:45:33 -03:00
|
|
|
float last_distance_m; // last distance reported (used to prevent glitches in measurement)
|
|
|
|
uint8_t glitch_count; // glitch counter
|
2020-05-17 03:41:50 -03:00
|
|
|
|
2020-09-01 02:25:44 -03:00
|
|
|
AP_HAL::PWMSource pwm_source;
|
2020-05-17 03:41:50 -03:00
|
|
|
|
|
|
|
uint32_t last_ping_ms;
|
|
|
|
};
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#endif // AP_RANGEFINDER_HC_SR04_ENABLED
|