2016-12-15 20:53:30 -04:00
|
|
|
#pragma once
|
|
|
|
|
2019-11-10 22:47:38 -04:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#ifndef AP_RANGEFINDER_TRI2C_ENABLED
|
|
|
|
#define AP_RANGEFINDER_TRI2C_ENABLED AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_RANGEFINDER_TRI2C_ENABLED
|
|
|
|
|
2016-12-15 20:53:30 -04:00
|
|
|
#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;
|
|
|
|
};
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#endif // AP_RANGEFINDER_TRI2C_ENABLED
|