2020-12-31 20:10:39 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
|
|
|
#include <AP_CANManager/AP_CANSensor.h>
|
|
|
|
|
2022-03-12 06:37:29 -04:00
|
|
|
#ifndef AP_RANGEFINDER_USD1_CAN_ENABLED
|
|
|
|
#define AP_RANGEFINDER_USD1_CAN_ENABLED (HAL_MAX_CAN_PROTOCOL_DRIVERS && AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_RANGEFINDER_USD1_CAN_ENABLED
|
2020-12-31 20:10:39 -04:00
|
|
|
|
2023-02-27 16:20:51 -04:00
|
|
|
class USD1_MultiCAN;
|
|
|
|
|
|
|
|
class AP_RangeFinder_USD1_CAN : public AP_RangeFinder_Backend {
|
2020-12-31 20:10:39 -04:00
|
|
|
public:
|
2023-02-27 16:20:51 -04:00
|
|
|
friend class USD1_MultiCAN;
|
|
|
|
|
2020-12-31 20:10:39 -04:00
|
|
|
AP_RangeFinder_USD1_CAN(RangeFinder::RangeFinder_State &_state, AP_RangeFinder_Params &_params);
|
|
|
|
|
|
|
|
void update() override;
|
|
|
|
|
|
|
|
// handler for incoming frames
|
2023-02-27 16:20:51 -04:00
|
|
|
bool handle_frame(AP_HAL::CANFrame &frame);
|
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
|
2020-12-31 20:10:39 -04:00
|
|
|
protected:
|
|
|
|
virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
|
|
|
return MAV_DISTANCE_SENSOR_RADAR;
|
|
|
|
}
|
|
|
|
private:
|
2021-10-18 00:20:53 -03:00
|
|
|
float _distance_sum;
|
|
|
|
uint32_t _distance_count;
|
2023-02-27 16:20:51 -04:00
|
|
|
int32_t last_recv_id = -1;
|
|
|
|
|
|
|
|
AP_Int32 receive_id;
|
|
|
|
|
|
|
|
static USD1_MultiCAN *multican;
|
|
|
|
AP_RangeFinder_USD1_CAN *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
// a class to allow for multiple USD1_CAN backends with one
|
|
|
|
// CANSensor driver
|
|
|
|
class USD1_MultiCAN : public CANSensor {
|
|
|
|
public:
|
|
|
|
USD1_MultiCAN() : CANSensor("USD1") {
|
|
|
|
register_driver(AP_CANManager::Driver_Type_USD1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handler for incoming frames
|
|
|
|
void handle_frame(AP_HAL::CANFrame &frame) override;
|
|
|
|
|
|
|
|
HAL_Semaphore sem;
|
|
|
|
AP_RangeFinder_USD1_CAN *drivers;
|
2020-12-31 20:10:39 -04:00
|
|
|
};
|
|
|
|
|
2022-03-12 06:37:29 -04:00
|
|
|
#endif // AP_RANGEFINDER_USD1_CAN_ENABLED
|