35 #define RP_DEBUG_LEVEL 0 39 #define Debug(level, fmt, args ...) do { if (level <= RP_DEBUG_LEVEL) { gcs().send_text(MAV_SEVERITY_INFO, fmt, ## args); } } while (0) 41 #define Debug(level, fmt, args ...) 44 #define COMM_ACTIVITY_TIMEOUT_MS 200 45 #define RESET_RPA2_WAIT_MS 8 46 #define RESYNC_TIMEOUT 5000 52 #define RPLIDAR_PREAMBLE 0xA5 53 #define RPLIDAR_CMD_STOP 0x25 54 #define RPLIDAR_CMD_SCAN 0x20 55 #define RPLIDAR_CMD_FORCE_SCAN 0x21 56 #define RPLIDAR_CMD_RESET 0x40 59 #define RPLIDAR_CMD_GET_DEVICE_INFO 0x50 60 #define RPLIDAR_CMD_GET_DEVICE_HEALTH 0x52 63 #define RPLIDAR_CMD_EXPRESS_SCAN 0x82 78 if (
_uart !=
nullptr) {
95 if (
_uart ==
nullptr) {
112 Debug(1,
"LIDAR NO DATA");
139 Debug(1,
"LIDAR initialised");
148 if (
_uart ==
nullptr) {
154 Debug(1,
"LIDAR reset");
166 if (ignore_area_count == 0) {
172 for (uint8_t i=0; i<ignore_area_count; i++) {
175 uint16_t ign_area_angle;
176 uint8_t ign_area_width;
180 int16_t start_angle, end_angle;
183 int16_t degrees_to_fill =
wrap_360(end_angle - start_angle);
187 uint16_t sector_size;
188 if (degrees_to_fill >= 90) {
191 }
else if (degrees_to_fill > 45) {
193 sector_size = degrees_to_fill / 2.0f;
196 sector_size = degrees_to_fill;
203 start_angle += sector_size;
205 degrees_to_fill -= sector_size;
223 if (
_uart ==
nullptr) {
229 Debug(1,
"LIDAR SCAN MODE ACTIVATED");
236 if (
_uart ==
nullptr) {
247 if (
_uart ==
nullptr) {
253 while (nbytes-- > 0) {
256 Debug(2,
"UART READ %x <%c>", c, c);
274 Debug(1,
"GOT RPLIDAR INFORMATION");
292 Debug(2,
"RESPONDING");
299 Debug(2,
"LIDAR DESCRIPTOR CATCHED");
313 Debug(1,
" OUT OF SYNC");
315 if ((c & 0x03) == 0x01) {
325 Debug(3,
"READ PAYLOAD");
330 Debug(2,
"LIDAR MEASUREMENT CATCHED");
337 Debug(1,
"state: HEALTH");
341 Debug(1,
"state: UNKNOWN");
356 Debug(1,
"UNKNOWN LIDAR STATE");
370 static_assert(
sizeof(
payload.
sensor_scan) == 5,
"Unexpected payload.sensor_scan data structure size");
372 Debug(2,
"Measurement response detected");
379 static_assert(
sizeof(
payload.
sensor_health) == 3,
"Unexpected payload.sensor_health data structure size");
386 Debug(1,
"Invalid response descriptor");
399 #if RP_DEBUG_LEVEL >= 2 401 Debug(2,
" D%02.2f A%03.1f Q%02d", distance_m, angle_deg, quality);
430 Debug(1,
"Invalid Payload");
438 Debug(1,
"LIDAR Error");
444 Debug(1,
"Unknown LIDAR packet");
void send_request_for_health()
static AP_SerialManager serial_manager
bool _distance_valid[PROXIMITY_SECTORS_MAX]
float distance_max() const
uint32_t _last_distance_received_ms
system time of last distance measurement received from sensor
_sensor_health sensor_health
union AP_Proximity_RPLidarA2::PACKED payload
float _angle[PROXIMITY_SECTORS_MAX]
void parse_response_data()
virtual void begin(uint32_t baud)=0
AP_HAL::UARTDriver * _uart
Interface definition for the various Ground Control System.
uint8_t status
status definition: 0 good, 1 warning, 2 error
#define Debug(level, fmt, args ...)
uint16_t _sector_middle_deg[PROXIMITY_SECTORS_MAX]
uint8_t quality
Related the reflected laser pulse strength.
uint16_t angle_q6
Actual heading = angle_q6/64.0 Degree.
uint8_t startbit
on the first revolution 1 else 0
void set_status(AP_Proximity::Proximity_Status status)
float distance_min() const
uint32_t find_baudrate(enum SerialProtocol protocol, uint8_t instance) const
bool convert_angle_to_sector(float angle_degrees, uint8_t §or) const
uint8_t get_ignore_area_count() const
AP_Proximity_RPLidarA2(AP_Proximity &_frontend, AP_Proximity::Proximity_State &_state, AP_SerialManager &serial_manager)
float wrap_360(const T angle, float unit_mod)
float _distance[PROXIMITY_SECTORS_MAX]
virtual size_t write(uint8_t)=0
uint32_t _last_request_ms
system time of last request
uint8_t checkbit
always set to 1
virtual uint32_t available()=0
static bool detect(AP_SerialManager &serial_manager)
uint8_t _last_sector
last sector requested
uint8_t not_startbit
complementary to startbit
#define RPLIDAR_CMD_GET_DEVICE_HEALTH
uint16_t distance_q2
Actual Distance = distance_q2/4.0 mm.
void parse_response_descriptor()
bool get_next_ignore_start_or_end(uint8_t start_or_end, int16_t start_angle, int16_t &ignore_start) const
uint8_t _sector_width_deg[PROXIMITY_SECTORS_MAX]
bool get_ignore_area(uint8_t index, uint16_t &angle_deg, uint8_t &width_deg) const
void update_boundary_for_sector(uint8_t sector)
#define PROXIMITY_SECTORS_MAX
DEFINE_BYTE_ARRAY_METHODS _sensor_scan sensor_scan
#define RPLIDAR_CMD_RESET
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
enum ResponseType _response_type
response from the lidar
AP_HAL::UARTDriver * find_serial(enum SerialProtocol protocol, uint8_t instance) const
#define COMM_ACTIVITY_TIMEOUT_MS