2016-08-15 03:17:15 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_SerialManager/AP_SerialManager.h>
|
2017-02-09 07:30:04 -04:00
|
|
|
#include <AP_RangeFinder/AP_RangeFinder.h>
|
2016-08-15 03:17:15 -03:00
|
|
|
|
|
|
|
#define PROXIMITY_MAX_INSTANCES 1 // Maximum number of proximity sensor instances available on this platform
|
|
|
|
#define PROXIMITY_YAW_CORRECTION_DEFAULT 22 // default correction for sensor error in yaw
|
2016-11-15 03:27:34 -04:00
|
|
|
#define PROXIMITY_MAX_IGNORE 6 // up to six areas can be ignored
|
2017-05-30 06:55:20 -03:00
|
|
|
#define PROXIMITY_MAX_DIRECTION 8
|
|
|
|
#define PROXIMITY_SENSOR_ID_START 10
|
2016-08-15 03:17:15 -03:00
|
|
|
|
|
|
|
class AP_Proximity_Backend;
|
|
|
|
|
|
|
|
class AP_Proximity
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend class AP_Proximity_Backend;
|
|
|
|
|
|
|
|
AP_Proximity(AP_SerialManager &_serial_manager);
|
|
|
|
|
2018-05-09 04:45:43 -03:00
|
|
|
AP_Proximity(const AP_Proximity &other) = delete;
|
|
|
|
AP_Proximity &operator=(const AP_Proximity) = delete;
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
// Proximity driver types
|
|
|
|
enum Proximity_Type {
|
2017-02-03 00:36:03 -04:00
|
|
|
Proximity_Type_None = 0,
|
|
|
|
Proximity_Type_SF40C = 1,
|
|
|
|
Proximity_Type_MAV = 2,
|
|
|
|
Proximity_Type_TRTOWER = 3,
|
2017-02-09 07:30:04 -04:00
|
|
|
Proximity_Type_RangeFinder = 4,
|
2017-07-07 13:04:55 -03:00
|
|
|
Proximity_Type_RPLidarA2 = 5,
|
2018-06-15 06:08:01 -03:00
|
|
|
Proximity_Type_TRTOWEREVO = 6,
|
2017-02-03 00:36:03 -04:00
|
|
|
Proximity_Type_SITL = 10,
|
2018-12-04 01:54:20 -04:00
|
|
|
Proximity_Type_MorseSITL = 11,
|
2016-08-15 03:17:15 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Proximity_Status {
|
|
|
|
Proximity_NotConnected = 0,
|
|
|
|
Proximity_NoData,
|
|
|
|
Proximity_Good
|
|
|
|
};
|
|
|
|
|
2017-05-30 06:55:20 -03:00
|
|
|
// structure holding distances in PROXIMITY_MAX_DIRECTION directions. used for sending distances to ground station
|
2017-04-12 06:00:41 -03:00
|
|
|
struct Proximity_Distance_Array {
|
2017-05-30 06:55:20 -03:00
|
|
|
uint8_t orientation[PROXIMITY_MAX_DIRECTION]; // orientation (i.e. rough direction) of the distance (see MAV_SENSOR_ORIENTATION)
|
|
|
|
float distance[PROXIMITY_MAX_DIRECTION]; // distance in meters
|
2017-04-12 06:00:41 -03:00
|
|
|
};
|
|
|
|
|
2016-12-23 02:00:55 -04:00
|
|
|
// detect and initialise any available proximity sensors
|
2016-08-15 03:17:15 -03:00
|
|
|
void init(void);
|
|
|
|
|
2016-12-23 02:00:55 -04:00
|
|
|
// update state of all proximity sensors. Should be called at high rate from main loop
|
2016-08-15 03:17:15 -03:00
|
|
|
void update(void);
|
|
|
|
|
2017-02-09 07:30:04 -04:00
|
|
|
// set pointer to rangefinder object
|
|
|
|
void set_rangefinder(const RangeFinder *rangefinder) { _rangefinder = rangefinder; }
|
|
|
|
const RangeFinder *get_rangefinder() const { return _rangefinder; }
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
// return sensor orientation and yaw correction
|
|
|
|
uint8_t get_orientation(uint8_t instance) const;
|
|
|
|
int16_t get_yaw_correction(uint8_t instance) const;
|
|
|
|
|
|
|
|
// return sensor health
|
|
|
|
Proximity_Status get_status(uint8_t instance) const;
|
|
|
|
Proximity_Status get_status() const;
|
|
|
|
|
2016-12-23 02:00:55 -04:00
|
|
|
// Return the number of proximity sensors
|
2016-08-15 03:17:15 -03:00
|
|
|
uint8_t num_sensors(void) const {
|
|
|
|
return num_instances;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get distance in meters in a particular direction in degrees (0 is forward, clockwise)
|
|
|
|
// returns true on successful read and places distance in distance
|
|
|
|
bool get_horizontal_distance(uint8_t instance, float angle_deg, float &distance) const;
|
|
|
|
bool get_horizontal_distance(float angle_deg, float &distance) const;
|
|
|
|
|
2017-05-30 06:55:20 -03:00
|
|
|
// get distances in PROXIMITY_MAX_DIRECTION directions. used for sending distances to ground station
|
2017-04-12 06:00:41 -03:00
|
|
|
bool get_horizontal_distances(Proximity_Distance_Array &prx_dist_array) const;
|
|
|
|
|
2016-11-15 03:29:35 -04:00
|
|
|
// get boundary points around vehicle for use by avoidance
|
|
|
|
// returns nullptr and sets num_points to zero if no boundary can be returned
|
|
|
|
const Vector2f* get_boundary_points(uint8_t instance, uint16_t& num_points) const;
|
|
|
|
const Vector2f* get_boundary_points(uint16_t& num_points) const;
|
|
|
|
|
2016-11-15 03:15:46 -04:00
|
|
|
// get distance and angle to closest object (used for pre-arm check)
|
|
|
|
// returns true on success, false if no valid readings
|
|
|
|
bool get_closest_object(float& angle_deg, float &distance) const;
|
|
|
|
|
2016-12-16 23:42:13 -04:00
|
|
|
// get number of objects, angle and distance - used for non-GPS avoidance
|
|
|
|
uint8_t get_object_count() const;
|
|
|
|
bool get_object_angle_and_distance(uint8_t object_number, float& angle_deg, float &distance) const;
|
|
|
|
|
2016-11-25 01:01:21 -04:00
|
|
|
// get maximum and minimum distances (in meters) of primary sensor
|
|
|
|
float distance_max() const;
|
|
|
|
float distance_min() const;
|
|
|
|
|
2017-01-09 23:09:18 -04:00
|
|
|
// handle mavlink DISTANCE_SENSOR messages
|
|
|
|
void handle_msg(mavlink_message_t *msg);
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
// The Proximity_State structure is filled in by the backend driver
|
|
|
|
struct Proximity_State {
|
|
|
|
uint8_t instance; // the instance number of this proximity sensor
|
|
|
|
enum Proximity_Status status; // sensor status
|
|
|
|
};
|
|
|
|
|
2017-01-16 02:58:14 -04:00
|
|
|
//
|
2018-12-10 00:31:35 -04:00
|
|
|
// support for upward facing sensors
|
2017-01-16 02:58:14 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
// get distance upwards in meters. returns true on success
|
|
|
|
bool get_upward_distance(uint8_t instance, float &distance) const;
|
|
|
|
bool get_upward_distance(float &distance) const;
|
|
|
|
|
2018-05-09 04:45:43 -03:00
|
|
|
Proximity_Type get_type(uint8_t instance) const;
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
// parameter list
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2018-05-09 04:45:43 -03:00
|
|
|
static AP_Proximity *get_singleton(void) { return _singleton; };
|
|
|
|
|
2018-12-04 00:32:52 -04:00
|
|
|
// methods for mavlink SYS_STATUS message (send_sys_status)
|
2018-06-25 06:50:47 -03:00
|
|
|
// these methods cover only the primary instance
|
|
|
|
bool sensor_present() const;
|
|
|
|
bool sensor_enabled() const;
|
|
|
|
bool sensor_failed() const;
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
private:
|
2018-05-09 04:45:43 -03:00
|
|
|
static AP_Proximity *_singleton;
|
2016-08-15 03:17:15 -03:00
|
|
|
Proximity_State state[PROXIMITY_MAX_INSTANCES];
|
|
|
|
AP_Proximity_Backend *drivers[PROXIMITY_MAX_INSTANCES];
|
2017-02-09 07:30:04 -04:00
|
|
|
const RangeFinder *_rangefinder;
|
2019-02-03 21:30:50 -04:00
|
|
|
uint8_t primary_instance;
|
|
|
|
uint8_t num_instances;
|
2016-08-15 03:17:15 -03:00
|
|
|
AP_SerialManager &serial_manager;
|
|
|
|
|
|
|
|
// parameters for all instances
|
|
|
|
AP_Int8 _type[PROXIMITY_MAX_INSTANCES];
|
|
|
|
AP_Int8 _orientation[PROXIMITY_MAX_INSTANCES];
|
|
|
|
AP_Int16 _yaw_correction[PROXIMITY_MAX_INSTANCES];
|
2016-11-15 03:27:34 -04:00
|
|
|
AP_Int16 _ignore_angle_deg[PROXIMITY_MAX_IGNORE]; // angle (in degrees) of area that should be ignored by sensor (i.e. leg shows up)
|
|
|
|
AP_Int8 _ignore_width_deg[PROXIMITY_MAX_IGNORE]; // width of beam (in degrees) that should be ignored
|
2016-08-15 03:17:15 -03:00
|
|
|
|
|
|
|
void detect_instance(uint8_t instance);
|
|
|
|
void update_instance(uint8_t instance);
|
|
|
|
};
|