3 #if APM_BUILD_TYPE(APM_BUILD_APMrover2) 4 # define AP_AVOID_BEHAVE_DEFAULT AC_Avoid::BehaviourType::BEHAVIOR_STOP 6 # define AP_AVOID_BEHAVE_DEFAULT AC_Avoid::BehaviourType::BEHAVIOR_SLIDE 57 _proximity(proximity),
90 Vector2f des_vel_xy(desired_vel_cms.
x, desired_vel_cms.
y);
92 desired_vel_cms.
x = des_vel_xy.
x;
93 desired_vel_cms.
y = des_vel_xy.
y;
105 vel_xy.
x = cosf(heading) * speed * 100.0f;
106 vel_xy.
y = sinf(heading) * speed * 100.0f;
111 speed = -vel_xy.
length() * 0.01f;
113 speed = vel_xy.
length() * 0.01f;
126 if (climb_rate_cms <= 0.0
f) {
133 bool limit_alt =
false;
134 float alt_diff = 0.0f;
153 const float ctrl_alt_diff = alt_limit + curr_alt;
154 if (!limit_alt || ctrl_alt_diff < alt_diff) {
155 alt_diff = ctrl_alt_diff;
161 float proximity_alt_diff;
164 if (!limit_alt || proximity_alt_diff < alt_diff) {
165 alt_diff = proximity_alt_diff;
173 if (alt_diff <= 0.0
f) {
174 climb_rate_cms =
MIN(climb_rate_cms, 0.0
f);
179 const float max_speed =
get_max_speed(kP, accel_cmss_limited, alt_diff*100.0
f, dt);
180 climb_rate_cms =
MIN(max_speed, climb_rate_cms);
198 float roll_positive = 0.0f;
199 float roll_negative = 0.0f;
200 float pitch_positive = 0.0f;
201 float pitch_negative = 0.0f;
207 Vector2f rp_out((roll_positive + roll_negative) * 4500.0
f, (pitch_positive + pitch_negative) * 4500.0f);
212 float vec_len = rp_out.
length();
213 if (vec_len > angle_limit) {
214 rp_out *= (angle_limit / vec_len);
222 vec_len = rp_out.
length();
223 if (vec_len > veh_angle_max) {
224 rp_out *= (veh_angle_max / vec_len);
241 const float max_speed =
get_max_speed(kP, accel_cmss, limit_distance_cm, dt);
243 const float speed = desired_vel_cms * limit_direction;
244 if (speed > max_speed) {
246 desired_vel_cms += limit_direction*(max_speed - speed);
257 return safe_sqrt(2.0
f * distance_cm * accel_cmss);
284 position_xy *= 100.0f;
286 float speed = desired_vel_cms.
length();
292 if (!
is_zero(speed) && position_xy.
length() <= fence_radius) {
295 float stopping_point_length = stopping_point.
length();
296 if (stopping_point_length > fence_radius - margin_cm) {
301 const Vector2f target = stopping_point * ((fence_radius - margin_cm) / stopping_point_length);
302 const Vector2f target_direction = target - position_xy;
303 const float distance_to_target = target_direction.
length();
304 const float max_speed =
get_max_speed(kP, accel_cmss, distance_to_target, dt);
305 desired_vel_cms = target_direction * (
MIN(speed,max_speed) / distance_to_target);
310 const float distance_to_target =
MAX((intersection - position_xy).length() - margin_cm, 0.0
f);
311 const float max_speed =
get_max_speed(kP, accel_cmss, distance_to_target, dt);
312 if (max_speed < speed) {
313 desired_vel_cms *=
MAX(max_speed, 0.0
f) / speed;
337 if (desired_vel_cms.
is_zero()) {
361 if (desired_vel_cms.
is_zero()) {
368 if (boundary ==
nullptr || num_points == 0) {
387 if (desired_vel_cms.
is_zero()) {
403 if (boundary ==
nullptr || num_points == 0) {
415 position_xy = position_xy * 100.0f;
434 float margin_cm =
MAX(margin * 100.0
f, 0.0f);
437 float speed = safe_vel.
length();
441 for (i = 1, j = num_points-1; i < num_points; j = i++) {
449 const float limit_distance_cm = limit_direction.
length();
450 if (!
is_zero(limit_distance_cm)) {
453 limit_direction /= limit_distance_cm;
454 limit_velocity(kP, accel_cmss, safe_vel, limit_direction,
MAX(limit_distance_cm - margin_cm, 0.0f), dt);
465 Vector2f limit_direction = intersection - position_xy;
466 const float limit_distance_cm = limit_direction.
length();
467 if (!
is_zero(limit_distance_cm)) {
468 if (limit_distance_cm <= margin_cm) {
473 limit_direction /= limit_distance_cm;
474 limit_velocity(kP, accel_cmss, safe_vel, limit_direction,
MAX(limit_distance_cm - margin_cm, 0.0f), dt);
487 desired_vel_cms = safe_vel;
503 if (accel_cmss <= 0.0
f ||
is_zero(speed_cms)) {
509 return 0.5f *
sq(speed_cms) / accel_cmss;
514 if (speed_cms < accel_cmss/kP) {
518 return accel_cmss/(2.0f*kP*kP) + (speed_cms*speed_cms)/(2.0f*accel_cmss);
544 if (obj_count == 0) {
549 for (uint8_t i=0; i<obj_count; i++) {
550 float ang_deg, dist_m;
556 const float angle_rad =
radians(ang_deg);
557 const float roll_pct = -sinf(angle_rad) * lean_pct;
558 const float pitch_pct = cosf(angle_rad) * lean_pct;
560 if (roll_pct > 0.0
f) {
561 roll_positive =
MAX(roll_positive, roll_pct);
562 }
else if (roll_pct < 0.0
f) {
563 roll_negative =
MIN(roll_negative, roll_pct);
565 if (pitch_pct > 0.0
f) {
566 pitch_positive =
MAX(pitch_positive, pitch_pct);
567 }
else if (pitch_pct < 0.0
f) {
568 pitch_negative =
MIN(pitch_negative, pitch_pct);
bool boundary_breached(const Vector2f &location, uint16_t num_points, const Vector2f *points) const
returns true if we've breached the polygon boundary. simple passthrough to underlying _poly_loader ob...
Vector2< float > Vector2f
void get_proximity_roll_pitch_pct(float &roll_positive, float &roll_negative, float &pitch_positive, float &pitch_negative)
float safe_sqrt(const T v)
const Vector2f * get_boundary_points(uint16_t &num_points) const
bool get_upward_distance(uint8_t instance, float &distance) const
void adjust_velocity_polygon(float kP, float accel_cmss, Vector2f &desired_vel_cms, const Vector2f *boundary, uint16_t num_points, bool earth_frame, float margin, float dt)
#define AC_FENCE_TYPE_CIRCLE
#define AP_GROUPINFO(name, idx, clazz, element, def)
static bool segment_intersection(const Vector2< T > &seg1_start, const Vector2< T > &seg1_end, const Vector2< T > &seg2_start, const Vector2< T > &seg2_end, Vector2< T > &intersection)
uint8_t get_breaches() const
get_breaches - returns bit mask of the fence types that have been breached
virtual bool get_relative_position_NE_origin(Vector2f &vecNE) const
float get_stopping_distance(float kP, float accel_cmss, float speed_cms) const
const Vector2f * get_boundary_points(uint8_t instance, uint16_t &num_points) const
static const struct AP_Param::GroupInfo var_info[]
void adjust_roll_pitch(float &roll, float &pitch, float angle_max)
#define AC_AVOID_NONGPS_DIST_MAX_DEFAULT
static Vector2< T > closest_point(const Vector2< T > &p, const Vector2< T > &v, const Vector2< T > &w)
uint8_t get_object_count() const
static auto MAX(const A &one, const B &two) -> decltype(one > two ? one :two)
bool get_object_angle_and_distance(uint8_t object_number, float &angle_deg, float &distance) const
#define AC_AVOID_ANGLE_MAX_PERCENT
Proximity_Status get_status(uint8_t instance) const
bool is_zero(const T fVal1)
void adjust_velocity_polygon_fence(float kP, float accel_cmss, Vector2f &desired_vel_cms, float dt)
void adjust_velocity_proximity(float kP, float accel_cmss, Vector2f &desired_vel_cms, float dt)
float get_radius() const
get_radius - returns the fence radius in meters
static bool circle_segment_intersection(const Vector2< T > &seg_start, const Vector2< T > &seg_end, const Vector2< T > &circle_center, float radius, Vector2< T > &intersection)
#define AC_AVOID_ACCEL_CMSS_MAX
Vector2f * get_polygon_points(uint16_t &num_points) const
returns pointer to array of polygon points and num_points is filled in with the total number ...
virtual bool get_relative_position_NE_home(Vector2f &vecNE) const
#define AC_AVOID_STOP_AT_FENCE
#define AC_AVOID_STOP_AT_BEACON_FENCE
static float sqrt_controller(float error, float p, float second_ord_lim, float dt)
float get_max_speed(float kP, float accel_cmss, float distance_cm, float dt) const
uint8_t get_enabled_fences() const
get_enabled_fences - returns bitmask of enabled fences
float get_margin() const
get_margin - returns the fence margin in meters
float get_safe_alt_max() const
get_safe_alt - returns maximum safe altitude (i.e. alt_max - margin)
#define AC_AVOID_USE_PROXIMITY_SENSOR
float constrain_float(const float amt, const float low, const float high)
void adjust_velocity_circle_fence(float kP, float accel_cmss, Vector2f &desired_vel_cms, float dt)
static constexpr float radians(float deg)
virtual bool get_hgt_ctrl_limit(float &limit) const
AC_Avoid(const AP_AHRS &ahrs, const AC_Fence &fence, const AP_Proximity &proximity, const AP_Beacon *beacon=nullptr)
Constructor.
bool is_negative(const T fVal1)
void limit_velocity(float kP, float accel_cmss, Vector2f &desired_vel_cms, const Vector2f &limit_direction, float limit_distance_cm, float dt) const
void adjust_velocity_z(float kP, float accel_cmss, float &climb_rate_cms, float dt)
void adjust_speed(float kP, float accel, float heading, float &speed, float dt)
#define AC_FENCE_TYPE_POLYGON
const AP_Proximity & _proximity
void adjust_velocity(float kP, float accel_cmss, Vector2f &desired_vel_cms, float dt)
const AP_Beacon * _beacon
#define AC_AVOID_DISABLED
#define AP_AVOID_BEHAVE_DEFAULT
virtual void get_relative_position_D_home(float &posD) const =0
virtual bool get_relative_position_D_origin(float &posD) const
#define AC_FENCE_TYPE_ALT_MAX
void adjust_velocity_beacon_fence(float kP, float accel_cmss, Vector2f &desired_vel_cms, float dt)
float distance_to_lean_pct(float dist_m)
static void setup_object_defaults(const void *object_pointer, const struct GroupInfo *group_info)