2020-05-17 03:41:50 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
|
|
|
#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;
|
|
|
|
};
|