2023-06-19 14:09:46 -03:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-07 19:56:07 -04:00
|
|
|
#include "AP_RangeFinder_config.h"
|
2023-06-19 14:09:46 -03:00
|
|
|
|
2023-11-07 19:56:07 -04:00
|
|
|
#if AP_RANGEFINDER_BACKEND_CAN_ENABLED
|
2023-06-19 14:09:46 -03:00
|
|
|
|
2023-11-07 19:56:07 -04:00
|
|
|
#include "AP_RangeFinder_Backend.h"
|
2023-06-19 14:09:46 -03:00
|
|
|
#include <AP_CANManager/AP_CANSensor.h>
|
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
|
|
|
|
|
|
|
class RangeFinder_MultiCAN;
|
|
|
|
|
|
|
|
class AP_RangeFinder_Backend_CAN : public AP_RangeFinder_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
AP_RangeFinder_Backend_CAN(RangeFinder::RangeFinder_State &_state,
|
2024-02-22 22:01:25 -04:00
|
|
|
AP_RangeFinder_Params &_params, AP_CAN::Protocol can_type,
|
|
|
|
const char *driver_name);
|
2023-06-19 14:09:46 -03:00
|
|
|
|
|
|
|
friend class RangeFinder_MultiCAN;
|
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// update state
|
|
|
|
virtual void update(void) override;
|
|
|
|
|
|
|
|
// get distance measurement
|
|
|
|
bool get_reading(float &reading_m);
|
|
|
|
|
|
|
|
// it is essential that anyone relying on the base-class update to implement this
|
|
|
|
virtual bool handle_frame(AP_HAL::CANFrame &frame) = 0;
|
|
|
|
|
|
|
|
// maximum time between readings before we change state to NoData:
|
2023-08-01 13:07:59 -03:00
|
|
|
virtual uint32_t read_timeout_ms() const { return 200; }
|
2023-06-19 14:09:46 -03:00
|
|
|
|
|
|
|
virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
|
|
|
return MAV_DISTANCE_SENSOR_RADAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the CAN ID is correct
|
|
|
|
bool is_correct_id(uint32_t can_id) const;
|
|
|
|
|
|
|
|
// set distance and count
|
2023-07-19 05:00:46 -03:00
|
|
|
void accumulate_distance_m(float distance_m) {
|
2023-06-19 14:09:46 -03:00
|
|
|
_distance_sum += distance_m;
|
|
|
|
_distance_count++;
|
|
|
|
};
|
|
|
|
|
|
|
|
// linked list
|
|
|
|
AP_RangeFinder_Backend_CAN *next;
|
|
|
|
|
|
|
|
AP_Int32 receive_id; // CAN ID to receive for this backend
|
|
|
|
AP_Int32 snr_min; // minimum signal strength to accept packet
|
|
|
|
|
2024-02-22 22:01:25 -04:00
|
|
|
MultiCAN* multican_rangefinder; // Allows for multiple CAN rangefinders on a single bus
|
2023-06-19 14:09:46 -03:00
|
|
|
private:
|
|
|
|
|
|
|
|
float _distance_sum; // meters
|
|
|
|
uint32_t _distance_count;
|
|
|
|
};
|
|
|
|
|
2023-11-07 19:56:07 -04:00
|
|
|
#endif // AP_RANGEFINDER_BACKEND_CAN_ENABLED
|