2021-11-12 06:11:48 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
2022-03-12 06:37:29 -04:00
|
|
|
|
2021-11-12 06:11:48 -04:00
|
|
|
#include <AP_CANManager/AP_CANSensor.h>
|
|
|
|
|
2022-03-12 06:37:29 -04:00
|
|
|
#ifndef AP_RANGEFINDER_BENEWAKE_CAN_ENABLED
|
|
|
|
#define AP_RANGEFINDER_BENEWAKE_CAN_ENABLED (HAL_MAX_CAN_PROTOCOL_DRIVERS && AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_RANGEFINDER_BENEWAKE_CAN_ENABLED
|
2021-11-12 06:11:48 -04:00
|
|
|
|
2021-12-03 00:29:43 -04:00
|
|
|
class Benewake_MultiCAN;
|
|
|
|
|
|
|
|
class AP_RangeFinder_Benewake_CAN : public AP_RangeFinder_Backend {
|
2021-11-12 06:11:48 -04:00
|
|
|
public:
|
2021-12-03 00:29:43 -04:00
|
|
|
friend class Benewake_MultiCAN;
|
|
|
|
|
2021-11-12 06:11:48 -04:00
|
|
|
AP_RangeFinder_Benewake_CAN(RangeFinder::RangeFinder_State &_state, AP_RangeFinder_Params &_params);
|
|
|
|
|
|
|
|
void update() override;
|
|
|
|
|
2021-12-03 00:29:43 -04:00
|
|
|
// handler for incoming frames. Return true if consumed
|
|
|
|
bool handle_frame(AP_HAL::CANFrame &frame);
|
2022-07-11 04:58:31 -03:00
|
|
|
bool handle_frame_H30(AP_HAL::CANFrame &frame);
|
2021-11-12 06:11:48 -04:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
|
|
|
return MAV_DISTANCE_SENSOR_RADAR;
|
|
|
|
}
|
2021-12-03 00:29:43 -04:00
|
|
|
|
2021-11-12 06:11:48 -04:00
|
|
|
private:
|
|
|
|
float _distance_sum_cm;
|
|
|
|
uint32_t _distance_count;
|
|
|
|
int32_t last_recv_id = -1;
|
|
|
|
|
|
|
|
AP_Int32 snr_min;
|
|
|
|
AP_Int32 receive_id;
|
2021-12-03 00:29:43 -04:00
|
|
|
|
|
|
|
static Benewake_MultiCAN *multican;
|
|
|
|
AP_RangeFinder_Benewake_CAN *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
// a class to allow for multiple Benewake_CAN backends with one
|
|
|
|
// CANSensor driver
|
|
|
|
class Benewake_MultiCAN : public CANSensor {
|
|
|
|
public:
|
|
|
|
Benewake_MultiCAN() : CANSensor("Benewake") {
|
|
|
|
register_driver(AP_CANManager::Driver_Type_Benewake);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handler for incoming frames
|
|
|
|
void handle_frame(AP_HAL::CANFrame &frame) override;
|
|
|
|
|
|
|
|
HAL_Semaphore sem;
|
|
|
|
AP_RangeFinder_Benewake_CAN *drivers;
|
2021-11-12 06:11:48 -04:00
|
|
|
};
|
2021-12-03 00:29:43 -04:00
|
|
|
|
2022-03-12 06:37:29 -04:00
|
|
|
#endif // AP_RANGEFINDER_BENEWAKE_CAN_ENABLED
|
2021-11-12 06:11:48 -04:00
|
|
|
|
2021-12-03 00:29:43 -04:00
|
|
|
|