AP_Proximity_TeraRangerTowerEvo.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include "AP_Proximity.h"
  3. #include "AP_Proximity_Backend.h"
  4. #define PROXIMITY_TRTOWER_TIMEOUT_MS 300 // requests timeout after 0.3 seconds
  5. class AP_Proximity_TeraRangerTowerEvo : public AP_Proximity_Backend {
  6. public:
  7. // constructor
  8. AP_Proximity_TeraRangerTowerEvo(AP_Proximity &_frontend, AP_Proximity::Proximity_State &_state, AP_SerialManager &serial_manager);
  9. // static detection function
  10. static bool detect(AP_SerialManager &serial_manager);
  11. // update state
  12. void update(void) override;
  13. // get maximum and minimum distances (in meters) of sensor
  14. float distance_max() const override;
  15. float distance_min() const override;
  16. private:
  17. // check and process replies from sensor
  18. void initialise_modes();
  19. bool read_sensor_data();
  20. void update_sector_data(int16_t angle_deg, uint16_t distance_cm);
  21. void set_mode(const uint8_t *c, int length);
  22. enum InitState {
  23. InitState_Printout = 0,
  24. InitState_Sequence,
  25. InitState_Rate,
  26. InitState_StreamStart,
  27. InitState_Finished
  28. };
  29. // reply related variables
  30. AP_HAL::UARTDriver *uart = nullptr;
  31. uint8_t buffer[21]; // buffer where to store data from serial
  32. uint8_t buffer_count;
  33. // request related variables
  34. uint32_t _last_distance_received_ms; // system time of last distance measurement received from sensor
  35. uint32_t _last_request_sent_ms; // system time of last command set
  36. const uint16_t _mode_request_delay = 1000;
  37. enum InitState _current_init_state = InitState_Printout;
  38. // tower evo operating modes
  39. const uint8_t BINARY_MODE[4] = {(uint8_t)0x00, (uint8_t)0x11, (uint8_t)0x02, (uint8_t)0x4C};
  40. const uint8_t TOWER_MODE[4] = {(uint8_t)0x00, (uint8_t)0x31, (uint8_t)0x03, (uint8_t)0xE5};
  41. const uint8_t SEQUENCE_MODE[4] = {(uint8_t)0x00, (uint8_t)0x31, (uint8_t)0x02, (uint8_t)0xE2};
  42. const uint8_t ACTIVATE_STREAM[5] = {(uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x02, (uint8_t)0x01, (uint8_t)0xDF};
  43. const uint8_t REFRESH_50_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x02, (uint8_t)0xC3};
  44. const uint8_t REFRESH_100_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x03, (uint8_t)0xC4};
  45. const uint8_t REFRESH_250_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x04, (uint8_t)0xD1};
  46. const uint8_t REFRESH_500_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x05, (uint8_t)0xD6};
  47. const uint8_t REFRESH_600_HZ[5] = { (uint8_t)0x00, (uint8_t)0x52, (uint8_t)0x03, (uint8_t)0x06, (uint8_t)0xDF};
  48. };