Line data Source code
1 : #pragma once 2 : #include "AP_Proximity_config.h" 3 : 4 : #if AP_PROXIMITY_MR72_DRIVER_ENABLED 5 : 6 : #include "AP_Proximity.h" 7 : #include "AP_Proximity_Backend.h" 8 : #include <AP_HAL/AP_HAL.h> 9 : #include <AP_CANManager/AP_CANSensor.h> 10 : 11 : #define MR72_MAX_RANGE_M 50.0f // max range of the sensor in meters 12 : #define MR72_MIN_RANGE_M 0.2f // min range of the sensor in meters 13 : 14 : class MR72_MultiCAN; 15 : 16 : class AP_Proximity_MR72_CAN : public AP_Proximity_Backend { 17 : public: 18 : friend class MR72_MultiCAN; 19 : 20 : AP_Proximity_MR72_CAN(AP_Proximity &_frontend, AP_Proximity::Proximity_State &_state, AP_Proximity_Params& _params); 21 : 22 : void update() override; 23 : 24 : // handler for incoming frames. Return true if consumed 25 : bool handle_frame(AP_HAL::CANFrame &frame); 26 : 27 : // parse a distance message from CAN frame 28 : bool parse_distance_message(AP_HAL::CANFrame &frame); 29 : 30 : // get maximum and minimum distances (in meters) of sensor 31 0 : float distance_max_m() const override { return MR72_MAX_RANGE_M; } 32 0 : float distance_min_m() const override { return MR72_MIN_RANGE_M; } 33 : 34 : static const struct AP_Param::GroupInfo var_info[]; 35 : 36 : AP_Proximity_Temp_Boundary _temp_boundary; 37 : 38 : private: 39 : 40 0 : uint32_t get_radar_id(uint32_t id) const { return ((id & 0xF0U) >> 4U); } 41 : 42 : uint32_t _object_count; // total number of objects to read 43 : uint32_t _current_object_index; // current object index 44 : uint32_t last_update_ms; // last update time in ms 45 : 46 : AP_Int32 receive_id; // ID of the sensor 47 : 48 : MultiCAN* multican_MR72; // Allows for multiple CAN rangefinders on a single bus 49 : }; 50 : 51 : #endif // AP_PROXIMITY_MR72_DRIVER_ENABLED