2016-06-19 22:12:17 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_AHRS/AP_AHRS.h> // AHRS library
|
|
|
|
#include <AP_InertialNav/AP_InertialNav.h> // Inertial Navigation library
|
|
|
|
#include <AC_AttitudeControl/AC_AttitudeControl.h> // Attitude controller library for sqrt controller
|
|
|
|
#include <AC_Fence/AC_Fence.h> // Failsafe fence library
|
2016-08-15 08:59:35 -03:00
|
|
|
#include <AP_Proximity/AP_Proximity.h>
|
2016-06-19 22:12:17 -03:00
|
|
|
|
2016-06-20 05:40:20 -03:00
|
|
|
#define AC_AVOID_ACCEL_CMSS_MAX 100.0f // maximum acceleration/deceleration in cm/s/s used to avoid hitting fence
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
// bit masks for enabled fence types.
|
|
|
|
#define AC_AVOID_DISABLED 0 // avoidance disabled
|
|
|
|
#define AC_AVOID_STOP_AT_FENCE 1 // stop at fence
|
2016-08-15 08:59:35 -03:00
|
|
|
#define AC_AVOID_USE_PROXIMITY_SENSOR 2 // stop based on proximity sensor output
|
|
|
|
#define AC_AVOID_ALL 3 // use fence and promiximity sensor
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This class prevents the vehicle from leaving a polygon fence in
|
|
|
|
* 2 dimensions by limiting velocity (adjust_velocity).
|
|
|
|
*/
|
|
|
|
class AC_Avoid {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructor
|
2016-08-15 08:59:35 -03:00
|
|
|
AC_Avoid(const AP_AHRS& ahrs, const AP_InertialNav& inav, const AC_Fence& fence, const AP_Proximity& proximity);
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjusts the desired velocity so that the vehicle can stop
|
|
|
|
* before the fence/object.
|
2016-07-25 00:16:26 -03:00
|
|
|
* Note: Vector3f version is for convenience and only adjusts x and y axis
|
2016-06-19 22:12:17 -03:00
|
|
|
*/
|
|
|
|
void adjust_velocity(const float kP, const float accel_cmss, Vector2f &desired_vel);
|
2016-07-25 00:16:26 -03:00
|
|
|
void adjust_velocity(const float kP, const float accel_cmss, Vector3f &desired_vel);
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjusts the desired velocity for the circular fence.
|
|
|
|
*/
|
|
|
|
void adjust_velocity_circle(const float kP, const float accel_cmss, Vector2f &desired_vel);
|
|
|
|
|
2016-06-22 23:45:01 -03:00
|
|
|
/*
|
|
|
|
* Adjusts the desired velocity for the polygon fence.
|
|
|
|
*/
|
|
|
|
void adjust_velocity_poly(const float kP, const float accel_cmss, Vector2f &desired_vel);
|
|
|
|
|
2016-08-15 08:59:35 -03:00
|
|
|
/*
|
|
|
|
* Adjusts the desired velocity based on output from the proximity sensor
|
|
|
|
*/
|
|
|
|
void adjust_velocity_proximity(const float kP, const float accel_cmss, Vector2f &desired_vel);
|
2016-06-22 23:45:01 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Limits the component of desired_vel in the direction of the unit vector
|
|
|
|
* limit_direction to be at most the maximum speed permitted by the limit_distance.
|
|
|
|
*
|
|
|
|
* Uses velocity adjustment idea from Randy's second email on this thread:
|
|
|
|
* https://groups.google.com/forum/#!searchin/drones-discuss/obstacle/drones-discuss/QwUXz__WuqY/qo3G8iTLSJAJ
|
|
|
|
*/
|
|
|
|
void limit_velocity(const float kP, const float accel_cmss, Vector2f &desired_vel, const Vector2f limit_direction, const float limit_distance) const;
|
|
|
|
|
2016-06-19 22:12:17 -03:00
|
|
|
/*
|
|
|
|
* Gets the current position, relative to home (not relative to EKF origin)
|
|
|
|
*/
|
|
|
|
Vector2f get_position();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Computes the speed such that the stopping distance
|
|
|
|
* of the vehicle will be exactly the input distance.
|
|
|
|
*/
|
2016-06-23 01:14:01 -03:00
|
|
|
float get_max_speed(const float kP, const float accel_cmss, const float distance) const;
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Computes distance required to stop, given current speed.
|
|
|
|
*/
|
2016-06-23 01:14:01 -03:00
|
|
|
float get_stopping_distance(const float kP, const float accel_cmss, const float speed) const;
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the fence margin in cm
|
|
|
|
*/
|
2016-06-23 01:14:01 -03:00
|
|
|
float get_margin() const { return _fence.get_margin() * 100.0f; }
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
// external references
|
|
|
|
const AP_AHRS& _ahrs;
|
|
|
|
const AP_InertialNav& _inav;
|
|
|
|
const AC_Fence& _fence;
|
2016-08-15 08:59:35 -03:00
|
|
|
const AP_Proximity& _proximity;
|
2016-06-19 22:12:17 -03:00
|
|
|
|
|
|
|
// parameters
|
|
|
|
AP_Int8 _enabled;
|
|
|
|
};
|