2018-03-27 23:05:52 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Common/Location.h>
|
|
|
|
#include <AP_InertialNav/AP_InertialNav.h>
|
|
|
|
#include <AC_AttitudeControl/AC_PosControl.h>
|
|
|
|
#include <AC_AttitudeControl/AC_AttitudeControl.h>
|
|
|
|
#include <AC_Avoidance/AC_Avoid.h>
|
|
|
|
|
|
|
|
class AC_Loiter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
AC_Loiter(const AP_InertialNav& inav, const AP_AHRS_View& ahrs, AC_PosControl& pos_control, const AC_AttitudeControl& attitude_control);
|
|
|
|
|
|
|
|
/// init_target to a position in cm from ekf origin
|
2021-06-21 04:26:40 -03:00
|
|
|
void init_target(const Vector2f& position);
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// initialize's position and feed-forward velocity from current pos and velocity
|
|
|
|
void init_target();
|
|
|
|
|
|
|
|
/// reduce response for landing
|
|
|
|
void soften_for_landing();
|
|
|
|
|
|
|
|
/// set pilot desired acceleration in centi-degrees
|
|
|
|
// dt should be the time (in seconds) since the last call to this function
|
2021-05-03 22:40:32 -03:00
|
|
|
void set_pilot_desired_acceleration(float euler_roll_angle_cd, float euler_pitch_angle_cd);
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// gets pilot desired acceleration, body frame, [forward,right]
|
2021-05-12 01:24:09 -03:00
|
|
|
Vector2f get_pilot_desired_acceleration() const { return Vector2f{_desired_accel.x, _desired_accel.y}; }
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// clear pilot desired acceleration
|
2024-07-04 04:37:24 -03:00
|
|
|
void clear_pilot_desired_acceleration() {
|
|
|
|
set_pilot_desired_acceleration(0, 0);
|
|
|
|
}
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// get vector to stopping point based on a horizontal position and velocity
|
2021-06-21 04:26:40 -03:00
|
|
|
void get_stopping_point_xy(Vector2f& stopping_point) const;
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// get horizontal distance to loiter target in cm
|
2021-05-03 22:40:32 -03:00
|
|
|
float get_distance_to_target() const { return _pos_control.get_pos_error_xy_cm(); }
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// get bearing to target in centi-degrees
|
2021-05-03 22:40:32 -03:00
|
|
|
int32_t get_bearing_to_target() const { return _pos_control.get_bearing_to_target_cd(); }
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// get maximum lean angle when using loiter
|
|
|
|
float get_angle_max_cd() const;
|
|
|
|
|
|
|
|
/// run the loiter controller
|
2021-03-15 15:43:21 -03:00
|
|
|
void update(bool avoidance_on = true);
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
/// get desired roll, pitch which should be fed into stabilize controllers
|
2021-05-12 01:25:11 -03:00
|
|
|
float get_roll() const { return _pos_control.get_roll_cd(); }
|
|
|
|
float get_pitch() const { return _pos_control.get_pitch_cd(); }
|
2021-04-13 01:22:56 -03:00
|
|
|
Vector3f get_thrust_vector() const { return _pos_control.get_thrust_vector(); }
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2018-04-03 21:34:50 -03:00
|
|
|
// sanity check parameters
|
|
|
|
void sanity_check_params();
|
|
|
|
|
2018-03-27 23:05:52 -03:00
|
|
|
/// updates desired velocity (i.e. feed forward) with pilot requested acceleration and fake wind resistance
|
|
|
|
/// updated velocity sent directly to position controller
|
2022-12-05 01:24:26 -04:00
|
|
|
void calc_desired_velocity(bool avoidance_on = true);
|
2018-03-27 23:05:52 -03:00
|
|
|
|
|
|
|
// references and pointers to external libraries
|
|
|
|
const AP_InertialNav& _inav;
|
|
|
|
const AP_AHRS_View& _ahrs;
|
|
|
|
AC_PosControl& _pos_control;
|
|
|
|
const AC_AttitudeControl& _attitude_control;
|
|
|
|
|
|
|
|
// parameters
|
|
|
|
AP_Float _angle_max; // maximum pilot commanded angle in degrees. Set to zero for 2/3 Angle Max
|
|
|
|
AP_Float _speed_cms; // maximum horizontal speed in cm/s while in loiter
|
|
|
|
AP_Float _accel_cmss; // loiter's max acceleration in cm/s/s
|
|
|
|
AP_Float _brake_accel_cmss; // loiter's acceleration during braking in cm/s/s
|
|
|
|
AP_Float _brake_jerk_max_cmsss;
|
|
|
|
AP_Float _brake_delay; // delay (in seconds) before loiter braking begins after sticks are released
|
|
|
|
|
|
|
|
// loiter controller internal variables
|
|
|
|
Vector2f _desired_accel; // slewed pilot's desired acceleration in lat/lon frame
|
|
|
|
Vector2f _predicted_accel;
|
|
|
|
Vector2f _predicted_euler_angle;
|
|
|
|
Vector2f _predicted_euler_rate;
|
2021-06-09 01:07:02 -03:00
|
|
|
uint32_t _brake_timer; // system time that brake was initiated
|
|
|
|
float _brake_accel; // acceleration due to braking from previous iteration (used for jerk limiting)
|
2018-03-27 23:05:52 -03:00
|
|
|
};
|