2017-03-09 19:38:28 -04:00
|
|
|
#pragma once
|
|
|
|
|
2019-11-10 22:47:38 -04:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
2017-03-09 19:38:28 -04:00
|
|
|
#include <AP_HAL/I2CDevice.h>
|
|
|
|
|
2022-03-12 06:37:29 -04:00
|
|
|
#ifndef AP_RANGEFINDER_VL53L0X_ENABLED
|
|
|
|
#define AP_RANGEFINDER_VL53L0X_ENABLED AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_RANGEFINDER_VL53L0X_ENABLED
|
|
|
|
|
2017-03-09 19:38:28 -04:00
|
|
|
class AP_RangeFinder_VL53L0X : public AP_RangeFinder_Backend
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
// static detection function
|
2018-07-04 11:22:17 -03:00
|
|
|
static AP_RangeFinder_Backend *detect(RangeFinder::RangeFinder_State &_state, AP_RangeFinder_Params &_params, AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
|
2017-03-09 19:38:28 -04:00
|
|
|
|
|
|
|
// update state
|
2018-11-07 07:01:51 -04:00
|
|
|
void update(void) override;
|
2017-03-09 19:38:28 -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;
|
|
|
|
}
|
|
|
|
|
2017-03-09 19:38:28 -04:00
|
|
|
private:
|
|
|
|
// constructor
|
2018-07-04 11:22:17 -03:00
|
|
|
AP_RangeFinder_VL53L0X(RangeFinder::RangeFinder_State &_state, AP_RangeFinder_Params &_params, AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
|
2017-03-09 19:38:28 -04:00
|
|
|
|
2018-07-26 19:15:55 -03:00
|
|
|
bool init();
|
2017-03-09 19:38:28 -04:00
|
|
|
void timer();
|
|
|
|
|
|
|
|
// check sensor ID
|
|
|
|
bool check_id(void);
|
|
|
|
|
|
|
|
// get a reading
|
|
|
|
bool get_reading(uint16_t &reading_cm);
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev;
|
|
|
|
|
|
|
|
uint8_t read_register(uint8_t reg);
|
|
|
|
uint16_t read_register16(uint8_t reg);
|
|
|
|
|
|
|
|
void write_register(uint8_t reg, uint8_t value);
|
|
|
|
void write_register16(uint8_t reg, uint16_t value);
|
|
|
|
|
|
|
|
struct SequenceStepEnables {
|
|
|
|
bool tcc:1, msrc:1, dss:1, pre_range:1, final_range:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SequenceStepTimeouts {
|
|
|
|
uint16_t pre_range_vcsel_period_pclks, final_range_vcsel_period_pclks;
|
|
|
|
|
|
|
|
uint16_t msrc_dss_tcc_mclks, pre_range_mclks, final_range_mclks;
|
|
|
|
uint32_t msrc_dss_tcc_us, pre_range_us, final_range_us;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RegData {
|
|
|
|
uint8_t reg;
|
|
|
|
uint8_t value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const RegData tuning_data[];
|
|
|
|
|
|
|
|
enum vcselPeriodType { VcselPeriodPreRange, VcselPeriodFinalRange };
|
|
|
|
|
|
|
|
bool get_SPAD_info(uint8_t * count, bool *type_is_aperture);
|
|
|
|
void getSequenceStepEnables(SequenceStepEnables * enables);
|
|
|
|
uint32_t getMeasurementTimingBudget(void);
|
|
|
|
void getSequenceStepTimeouts(SequenceStepEnables const * enables, SequenceStepTimeouts * timeouts);
|
|
|
|
uint8_t getVcselPulsePeriod(vcselPeriodType type);
|
|
|
|
uint32_t timeoutMclksToMicroseconds(uint16_t timeout_period_mclks, uint8_t vcsel_period_pclks);
|
|
|
|
uint16_t decodeTimeout(uint16_t reg_val);
|
|
|
|
bool setMeasurementTimingBudget(uint32_t budget_us);
|
|
|
|
uint32_t timeoutMicrosecondsToMclks(uint32_t timeout_period_us, uint8_t vcsel_period_pclks);
|
|
|
|
uint16_t encodeTimeout(uint16_t timeout_mclks);
|
|
|
|
bool performSingleRefCalibration(uint8_t vhv_init_byte);
|
|
|
|
void start_continuous(void);
|
|
|
|
|
|
|
|
uint8_t stop_variable;
|
|
|
|
uint32_t measurement_timing_budget_us;
|
|
|
|
uint32_t start_ms;
|
|
|
|
|
|
|
|
uint32_t sum_mm;
|
|
|
|
uint32_t counter;
|
|
|
|
};
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#endif // AP_RANGEFINDER_VL53L0X_ENABLED
|