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_Proximity.h"
|
2019-06-29 02:57:09 -03:00
|
|
|
#include <AP_Common/Location.h>
|
2020-12-06 08:21:40 -04:00
|
|
|
#include "AP_Proximity_Boundary_3D.h"
|
2016-11-15 03:11:14 -04:00
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
class AP_Proximity_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor. This incorporates initialisation as well.
|
|
|
|
AP_Proximity_Backend(AP_Proximity &_frontend, AP_Proximity::Proximity_State &_state);
|
|
|
|
|
|
|
|
// we declare a virtual destructor so that Proximity drivers can
|
|
|
|
// override with a custom destructor if need be
|
|
|
|
virtual ~AP_Proximity_Backend(void) {}
|
|
|
|
|
|
|
|
// update the state structure
|
|
|
|
virtual void update() = 0;
|
|
|
|
|
2016-11-25 01:01:21 -04:00
|
|
|
// get maximum and minimum distances (in meters) of sensor
|
|
|
|
virtual float distance_max() const = 0;
|
|
|
|
virtual float distance_min() const = 0;
|
|
|
|
|
2017-01-16 02:58:14 -04:00
|
|
|
// get distance upwards in meters. returns true on success
|
|
|
|
virtual bool get_upward_distance(float &distance) const { return false; }
|
|
|
|
|
2017-01-09 23:09:18 -04:00
|
|
|
// handle mavlink DISTANCE_SENSOR messages
|
2019-04-30 07:22:49 -03:00
|
|
|
virtual void handle_msg(const mavlink_message_t &msg) {}
|
2017-01-09 23:09:18 -04:00
|
|
|
|
2020-12-06 08:21:40 -04:00
|
|
|
// get total number of obstacles, used in GPS based Simple Avoidance
|
|
|
|
uint8_t get_obstacle_count() { return boundary.get_obstacle_count(); }
|
|
|
|
|
|
|
|
// get vector to obstacle based on obstacle_num passed, used in GPS based Simple Avoidance
|
2020-12-27 12:21:58 -04:00
|
|
|
bool get_obstacle(uint8_t obstacle_num, Vector3f& vec_to_obstacle) const { return boundary.get_obstacle(obstacle_num, vec_to_obstacle); }
|
2020-12-06 08:21:40 -04:00
|
|
|
|
|
|
|
// returns shortest distance to "obstacle_num" obstacle, from a line segment formed between "seg_start" and "seg_end"
|
|
|
|
// used in GPS based Simple Avoidance
|
|
|
|
float distance_to_obstacle(const uint8_t obstacle_num, const Vector3f& seg_start, const Vector3f& seg_end, Vector3f& closest_point) const { return boundary.distance_to_obstacle(obstacle_num , seg_start, seg_end, closest_point); }
|
2016-11-15 03:29:35 -04:00
|
|
|
|
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
|
2020-12-06 08:21:40 -04:00
|
|
|
bool get_closest_object(float& angle_deg, float &distance) const { return boundary.get_closest_object(angle_deg, distance); }
|
2016-11-25 01:01:21 -04:00
|
|
|
|
2016-12-16 23:42:13 -04:00
|
|
|
// get number of objects, angle and distance - used for non-GPS avoidance
|
2020-12-06 08:21:40 -04:00
|
|
|
uint8_t get_horizontal_object_count() const {return boundary.get_horizontal_object_count(); }
|
|
|
|
bool get_horizontal_object_angle_and_distance(uint8_t object_number, float& angle_deg, float &distance) const { return boundary.get_horizontal_object_angle_and_distance(object_number, angle_deg, distance); }
|
2016-12-16 23:42:13 -04:00
|
|
|
|
2016-11-25 01:01:21 -04:00
|
|
|
// get distances in 8 directions. used for sending distances to ground station
|
2017-04-12 06:00:41 -03:00
|
|
|
bool get_horizontal_distances(AP_Proximity::Proximity_Distance_Array &prx_dist_array) const;
|
2016-08-15 03:17:15 -03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// set status and update valid_count
|
2019-09-27 05:58:52 -03:00
|
|
|
void set_status(AP_Proximity::Status status);
|
2016-08-15 03:17:15 -03:00
|
|
|
|
2020-09-30 02:13:45 -03:00
|
|
|
// correct an angle (in degrees) based on the orientation and yaw correction parameters
|
|
|
|
float correct_angle_for_orientation(float angle_degrees) const;
|
2020-12-06 08:21:40 -04:00
|
|
|
|
2019-12-03 22:46:03 -04:00
|
|
|
// check if a reading should be ignored because it falls into an ignore area
|
|
|
|
// angles should be in degrees and in the range of 0 to 360
|
|
|
|
bool ignore_reading(uint16_t angle_deg) const;
|
2016-11-15 03:27:34 -04:00
|
|
|
|
2020-12-06 08:21:40 -04:00
|
|
|
// database helpers. All angles are in degrees
|
|
|
|
static bool database_prepare_for_push(Vector3f ¤t_pos, Matrix3f &body_to_ned);
|
|
|
|
// Note: "angle" refers to yaw (in body frame) towards the obstacle
|
|
|
|
static void database_push(float angle, float distance);
|
2021-01-10 14:14:24 -04:00
|
|
|
static void database_push(float angle, float distance, uint32_t timestamp_ms, const Vector3f ¤t_pos, const Matrix3f &body_to_ned) {
|
|
|
|
database_push(angle, 0.0f, distance, timestamp_ms, current_pos, body_to_ned);
|
|
|
|
};
|
|
|
|
static void database_push(float angle, float pitch, float distance, uint32_t timestamp_ms, const Vector3f ¤t_pos, const Matrix3f &body_to_ned);
|
|
|
|
|
2016-08-15 03:17:15 -03:00
|
|
|
AP_Proximity &frontend;
|
|
|
|
AP_Proximity::Proximity_State &state; // reference to this instances state
|
2016-11-15 03:11:14 -04:00
|
|
|
|
2020-12-06 08:21:40 -04:00
|
|
|
// Methods to manipulate 3D boundary in this class
|
|
|
|
AP_Proximity_Boundary_3D boundary;
|
2016-08-15 03:17:15 -03:00
|
|
|
};
|