Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AC_WPNav/AC_Loiter.h
Views: 1798
#pragma once12#include <AP_Common/AP_Common.h>3#include <AP_Param/AP_Param.h>4#include <AP_Math/AP_Math.h>5#include <AP_Common/Location.h>6#include <AP_InertialNav/AP_InertialNav.h>7#include <AC_AttitudeControl/AC_PosControl.h>8#include <AC_AttitudeControl/AC_AttitudeControl.h>9#include <AC_Avoidance/AC_Avoid.h>1011class AC_Loiter12{13public:1415/// Constructor16AC_Loiter(const AP_InertialNav& inav, const AP_AHRS_View& ahrs, AC_PosControl& pos_control, const AC_AttitudeControl& attitude_control);1718/// init_target to a position in cm from ekf origin19void init_target(const Vector2f& position);2021/// initialize's position and feed-forward velocity from current pos and velocity22void init_target();2324/// reduce response for landing25void soften_for_landing();2627/// set pilot desired acceleration in centi-degrees28// dt should be the time (in seconds) since the last call to this function29void set_pilot_desired_acceleration(float euler_roll_angle_cd, float euler_pitch_angle_cd);3031/// gets pilot desired acceleration, body frame, [forward,right]32Vector2f get_pilot_desired_acceleration() const { return Vector2f{_desired_accel.x, _desired_accel.y}; }3334/// clear pilot desired acceleration35void clear_pilot_desired_acceleration() {36set_pilot_desired_acceleration(0, 0);37}3839/// get vector to stopping point based on a horizontal position and velocity40void get_stopping_point_xy(Vector2f& stopping_point) const;4142/// get horizontal distance to loiter target in cm43float get_distance_to_target() const { return _pos_control.get_pos_error_xy_cm(); }4445/// get bearing to target in centi-degrees46int32_t get_bearing_to_target() const { return _pos_control.get_bearing_to_target_cd(); }4748/// get maximum lean angle when using loiter49float get_angle_max_cd() const;5051/// run the loiter controller52void update(bool avoidance_on = true);5354/// get desired roll, pitch which should be fed into stabilize controllers55float get_roll() const { return _pos_control.get_roll_cd(); }56float get_pitch() const { return _pos_control.get_pitch_cd(); }57Vector3f get_thrust_vector() const { return _pos_control.get_thrust_vector(); }5859static const struct AP_Param::GroupInfo var_info[];6061protected:6263// sanity check parameters64void sanity_check_params();6566/// updates desired velocity (i.e. feed forward) with pilot requested acceleration and fake wind resistance67/// updated velocity sent directly to position controller68void calc_desired_velocity(bool avoidance_on = true);6970// references and pointers to external libraries71const AP_InertialNav& _inav;72const AP_AHRS_View& _ahrs;73AC_PosControl& _pos_control;74const AC_AttitudeControl& _attitude_control;7576// parameters77AP_Float _angle_max; // maximum pilot commanded angle in degrees. Set to zero for 2/3 Angle Max78AP_Float _speed_cms; // maximum horizontal speed in cm/s while in loiter79AP_Float _accel_cmss; // loiter's max acceleration in cm/s/s80AP_Float _brake_accel_cmss; // loiter's acceleration during braking in cm/s/s81AP_Float _brake_jerk_max_cmsss;82AP_Float _brake_delay; // delay (in seconds) before loiter braking begins after sticks are released8384// loiter controller internal variables85Vector2f _desired_accel; // slewed pilot's desired acceleration in lat/lon frame86Vector2f _predicted_accel;87Vector2f _predicted_euler_angle;88Vector2f _predicted_euler_rate;89uint32_t _brake_timer; // system time that brake was initiated90float _brake_accel; // acceleration due to braking from previous iteration (used for jerk limiting)91};929394