2016-12-15 20:53:30 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "RangeFinder.h"
|
|
|
|
#include "RangeFinder_Backend.h"
|
|
|
|
#include <AP_HAL/I2CDevice.h>
|
|
|
|
|
2017-07-28 09:46:52 -03:00
|
|
|
class AP_RangeFinder_TeraRangerI2C : public AP_RangeFinder_Backend
|
2016-12-15 20:53:30 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// static detection function
|
2017-07-28 09:20:10 -03:00
|
|
|
static AP_RangeFinder_Backend *detect(RangeFinder::RangeFinder_State &_state,
|
2019-02-03 22:21:58 -04:00
|
|
|
AP_RangeFinder_Params &_params,
|
2017-07-28 09:20:10 -03:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> i2c_dev);
|
2016-12-15 20:53:30 -04:00
|
|
|
|
|
|
|
// update state
|
2018-11-07 07:01:51 -04:00
|
|
|
void update(void) override;
|
2016-12-15 20:53:30 -04:00
|
|
|
|
2017-08-08 04:32:53 -03:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
|
|
|
return MAV_DISTANCE_SENSOR_LASER;
|
|
|
|
}
|
|
|
|
|
2016-12-15 20:53:30 -04:00
|
|
|
private:
|
|
|
|
// constructor
|
2017-07-28 09:20:10 -03:00
|
|
|
AP_RangeFinder_TeraRangerI2C(RangeFinder::RangeFinder_State &_state,
|
2018-07-04 11:22:17 -03:00
|
|
|
AP_RangeFinder_Params &_params,
|
2017-07-28 09:20:10 -03:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> i2c_dev);
|
2016-12-15 20:53:30 -04:00
|
|
|
|
|
|
|
bool measure(void);
|
2018-08-03 11:41:15 -03:00
|
|
|
bool collect_raw(uint16_t &raw_distance);
|
2018-08-03 11:42:20 -03:00
|
|
|
bool process_raw_measure(uint16_t raw_distance, uint16_t &distance_cm);
|
2018-08-03 11:41:15 -03:00
|
|
|
|
|
|
|
bool init(void);
|
2016-12-15 20:53:30 -04:00
|
|
|
void timer(void);
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32_t sum;
|
|
|
|
uint32_t count;
|
|
|
|
} accum;
|
|
|
|
};
|