2018-06-15 06:08:01 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Proximity.h"
|
2021-03-25 04:32:09 -03:00
|
|
|
|
|
|
|
#if HAL_PROXIMITY_ENABLED
|
2019-12-04 00:57:16 -04:00
|
|
|
#include "AP_Proximity_Backend_Serial.h"
|
2018-06-15 06:08:01 -03:00
|
|
|
|
|
|
|
#define PROXIMITY_TRTOWER_TIMEOUT_MS 300 // requests timeout after 0.3 seconds
|
|
|
|
|
2019-12-04 00:57:16 -04:00
|
|
|
class AP_Proximity_TeraRangerTowerEvo : public AP_Proximity_Backend_Serial {
|
2018-06-15 06:08:01 -03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-12-04 00:57:16 -04:00
|
|
|
using AP_Proximity_Backend_Serial::AP_Proximity_Backend_Serial;
|
2018-06-15 06:08:01 -03:00
|
|
|
|
|
|
|
// update state
|
2018-11-07 07:01:30 -04:00
|
|
|
void update(void) override;
|
2018-06-15 06:08:01 -03:00
|
|
|
|
|
|
|
// get maximum and minimum distances (in meters) of sensor
|
2018-11-07 07:01:30 -04:00
|
|
|
float distance_max() const override;
|
|
|
|
float distance_min() const override;
|
2018-06-15 06:08:01 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// check and process replies from sensor
|
|
|
|
void initialise_modes();
|
|
|
|
bool read_sensor_data();
|
|
|
|
void update_sector_data(int16_t angle_deg, uint16_t distance_cm);
|
|
|
|
void set_mode(const uint8_t *c, int length);
|
|
|
|
|
|
|
|
enum InitState {
|
|
|
|
InitState_Printout = 0,
|
|
|
|
InitState_Sequence,
|
|
|
|
InitState_Rate,
|
|
|
|
InitState_StreamStart,
|
|
|
|
InitState_Finished
|
|
|
|
};
|
|
|
|
|
|
|
|
// reply related variables
|
2018-06-15 07:15:58 -03:00
|
|
|
uint8_t buffer[21]; // buffer where to store data from serial
|
2018-06-15 06:08:01 -03:00
|
|
|
uint8_t buffer_count;
|
|
|
|
|
|
|
|
// request related variables
|
|
|
|
uint32_t _last_distance_received_ms; // system time of last distance measurement received from sensor
|
|
|
|
uint32_t _last_request_sent_ms; // system time of last command set
|
2018-06-20 07:31:29 -03:00
|
|
|
const uint16_t _mode_request_delay = 1000;
|
2018-06-15 06:08:01 -03:00
|
|
|
enum InitState _current_init_state = InitState_Printout;
|
|
|
|
|
|
|
|
// tower evo operating modes
|
|
|
|
|
|
|
|
const uint8_t BINARY_MODE[4] = {(uint8_t)0x00, (uint8_t)0x11, (uint8_t)0x02, (uint8_t)0x4C};
|
|
|
|
const uint8_t TOWER_MODE[4] = {(uint8_t)0x00, (uint8_t)0x31, (uint8_t)0x03, (uint8_t)0xE5};
|
2020-09-29 22:28:21 -03:00
|
|
|
// const uint8_t SEQUENCE_MODE[4] = {(uint8_t)0x00, (uint8_t)0x31, (uint8_t)0x02, (uint8_t)0xE2};
|
2018-06-15 06:08:01 -03:00
|
|
|
const uint8_t ACTIVATE_STREAM[5] = {(uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x02, (uint8_t)0x01, (uint8_t)0xDF};
|
2020-09-29 22:28:21 -03:00
|
|
|
// const uint8_t REFRESH_50_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x02, (uint8_t)0xC3};
|
2018-06-15 06:08:01 -03:00
|
|
|
const uint8_t REFRESH_100_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x03, (uint8_t)0xC4};
|
2020-09-29 22:28:21 -03:00
|
|
|
// const uint8_t REFRESH_250_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x04, (uint8_t)0xD1};
|
|
|
|
// const uint8_t REFRESH_500_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x05, (uint8_t)0xD6};
|
|
|
|
// const uint8_t REFRESH_600_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x06, (uint8_t)0xDF};
|
2018-06-15 06:08:01 -03:00
|
|
|
};
|
2021-03-25 04:32:09 -03:00
|
|
|
|
|
|
|
#endif // HAL_PROXIMITY_ENABLED
|