ardupilot/libraries/AP_Proximity/AP_Proximity_DroneCAN.h
Thomas Watson 453b83c159 AP_Proximity: optimize DroneCAN subscription process
* remove unnecessary nullptr check, these are always called from an
  initialized AP_DroneCAN so if it's nullptr something has gone
  horrifically wrong

* pass in driver index instead of repeatedly calling function to get it

* simplify error handling; knowing exactly which allocation failed is not
  super helpful and one failing likely means subsequent ones will too,
  as it can only fail due to being out of memory
2024-11-18 10:30:29 +11:00

49 lines
1.2 KiB
C++

#pragma once
#include "AP_Proximity_config.h"
#if AP_PROXIMITY_DRONECAN_ENABLED
#include "AP_Proximity_Backend.h"
#include <AP_DroneCAN/AP_DroneCAN.h>
class AP_Proximity_DroneCAN : public AP_Proximity_Backend
{
public:
// constructor
using AP_Proximity_Backend::AP_Proximity_Backend;
// update state
void update(void) override;
// get maximum and minimum distances (in meters) of sensor
float distance_max() const override;
float distance_min() const override;
static AP_Proximity_DroneCAN* get_dronecan_backend(AP_DroneCAN* ap_dronecan, uint8_t node_id, uint8_t address, bool create_new);
static bool subscribe_msgs(AP_DroneCAN* ap_dronecan);
static void handle_measurement(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const ardupilot_equipment_proximity_sensor_Proximity &msg);
private:
uint32_t _last_update_ms; // system time of last message received
AP_DroneCAN* _ap_dronecan;
uint8_t _node_id;
struct ObstacleItem {
float yaw_deg;
float pitch_deg;
float distance_m;
};
static ObjectBuffer_TS<ObstacleItem> items;
AP_Proximity::Status _status;
};
#endif // AP_PROXIMITY_DRONECAN_ENABLED