APM:Libraries
AC_Loiter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <AP_Common/AP_Common.h>
4 #include <AP_Param/AP_Param.h>
5 #include <AP_Math/AP_Math.h>
6 #include <AP_Common/Location.h>
10 #include <AC_Avoidance/AC_Avoid.h>
11 
12 class AC_Loiter
13 {
14 public:
15 
17  AC_Loiter(const AP_InertialNav& inav, const AP_AHRS_View& ahrs, AC_PosControl& pos_control, const AC_AttitudeControl& attitude_control);
18 
20  void set_avoidance(AC_Avoid* avoid_ptr) { _avoid = avoid_ptr; }
21 
23  void init_target(const Vector3f& position);
24 
26  void init_target();
27 
29  void soften_for_landing();
30 
32  // dt should be the time (in seconds) since the last call to this function
33  void set_pilot_desired_acceleration(float euler_roll_angle_cd, float euler_pitch_angle_cd, float dt);
34 
37 
40 
42  void get_stopping_point_xy(Vector3f& stopping_point) const;
43 
46 
49 
51  float get_angle_max_cd() const;
52 
54  void update(float ekfGndSpdLimit, float ekfNavVelGainScaler);
55 
57  int32_t get_roll() const { return _pos_control.get_roll(); }
58  int32_t get_pitch() const { return _pos_control.get_pitch(); }
59 
60  static const struct AP_Param::GroupInfo var_info[];
61 
62 protected:
63 
64  // sanity check parameters
65  void sanity_check_params();
66 
69  void calc_desired_velocity(float nav_dt, float ekfGndSpdLimit);
70 
71  // references and pointers to external libraries
76  AC_Avoid *_avoid = nullptr;
77 
78  // parameters
79  AP_Float _angle_max; // maximum pilot commanded angle in degrees. Set to zero for 2/3 Angle Max
80  AP_Float _speed_cms; // maximum horizontal speed in cm/s while in loiter
81  AP_Float _accel_cmss; // loiter's max acceleration in cm/s/s
82  AP_Float _brake_accel_cmss; // loiter's acceleration during braking in cm/s/s
84  AP_Float _brake_delay; // delay (in seconds) before loiter braking begins after sticks are released
85 
86  // loiter controller internal variables
87  Vector2f _desired_accel; // slewed pilot's desired acceleration in lat/lon frame
91  float _brake_timer;
92  float _brake_accel;
93 };
Vector2< float > Vector2f
Definition: vector2.h:239
AP_AHRS_NavEKF & ahrs
Definition: AHRS_Test.cpp:39
float get_distance_to_target() const
get_distance_to_target - get horizontal distance to position target in cm (used for reporting) ...
float get_pitch() const
Vector2f _desired_accel
Definition: AC_Loiter.h:87
const AC_AttitudeControl & _attitude_control
Definition: AC_Loiter.h:75
void soften_for_landing()
reduce response for landing
Definition: AC_Loiter.cpp:147
void calc_desired_velocity(float nav_dt, float ekfGndSpdLimit)
Definition: AC_Loiter.cpp:230
Vector2f _predicted_accel
Definition: AC_Loiter.h:88
void sanity_check_params()
Definition: AC_Loiter.cpp:222
float get_roll() const
get desired roll, pitch which should be fed into stabilize controllers
A system for managing and storing variables that are of general interest to the system.
AP_Float _brake_delay
Definition: AC_Loiter.h:84
T y
Definition: vector2.h:37
AP_Float _speed_cms
Definition: AC_Loiter.h:80
AC_Loiter(const AP_InertialNav &inav, const AP_AHRS_View &ahrs, AC_PosControl &pos_control, const AC_AttitudeControl &attitude_control)
Constructor.
Definition: AC_Loiter.cpp:79
void update(float ekfGndSpdLimit, float ekfNavVelGainScaler)
run the loiter controller
Definition: AC_Loiter.cpp:205
void get_stopping_point_xy(Vector3f &stopping_point) const
get vector to stopping point based on a horizontal position and velocity
Definition: AC_Loiter.cpp:190
int32_t get_bearing_to_target() const
get bearing to target in centi-degrees
Definition: AC_Loiter.h:48
ArduCopter attitude control library.
static const struct AP_Param::GroupInfo var_info[]
Definition: AC_Loiter.h:60
const AP_InertialNav & _inav
Definition: AC_Loiter.h:72
const AP_AHRS_View & _ahrs
Definition: AC_Loiter.h:73
Vector2f _predicted_euler_rate
Definition: AC_Loiter.h:90
Vector2f get_pilot_desired_acceleration() const
gets pilot desired acceleration, body frame, [forward,right]
Definition: AC_Loiter.h:36
AP_Float _angle_max
Definition: AC_Loiter.h:79
Vector2f _predicted_euler_angle
Definition: AC_Loiter.h:89
AP_Float _brake_jerk_max_cmsss
Definition: AC_Loiter.h:83
Common definitions and utility routines for the ArduPilot libraries.
int32_t get_bearing_to_target() const
get_bearing_to_target - get bearing to target position in centi-degrees
AP_Float _accel_cmss
Definition: AC_Loiter.h:81
void init_target()
initialize&#39;s position and feed-forward velocity from current pos and velocity
Definition: AC_Loiter.cpp:114
T x
Definition: vector2.h:37
void clear_pilot_desired_acceleration()
clear pilot desired acceleration
Definition: AC_Loiter.h:39
void zero()
Definition: vector2.h:125
void set_avoidance(AC_Avoid *avoid_ptr)
provide pointer to avoidance library
Definition: AC_Loiter.h:20
AP_Float _brake_accel_cmss
Definition: AC_Loiter.h:82
AC_PosControl & _pos_control
Definition: AC_Loiter.h:74
void set_pilot_desired_acceleration(float euler_roll_angle_cd, float euler_pitch_angle_cd, float dt)
set pilot desired acceleration in centi-degrees
Definition: AC_Loiter.cpp:157
float get_distance_to_target() const
get horizontal distance to loiter target in cm
Definition: AC_Loiter.h:45
float _brake_timer
Definition: AC_Loiter.h:91
int32_t get_pitch() const
Definition: AC_Loiter.h:58
AC_Avoid * _avoid
Definition: AC_Loiter.h:76
int32_t get_roll() const
get desired roll, pitch which should be fed into stabilize controllers
Definition: AC_Loiter.h:57
float _brake_accel
Definition: AC_Loiter.h:92
float get_angle_max_cd() const
get maximum lean angle when using loiter
Definition: AC_Loiter.cpp:196