PX4 Firmware
PX4 Autopilot Software http://px4.io
|
L1 Nonlinear Guidance Logic. More...
#include <ecl_l1_pos_controller.h>
Public Member Functions | |
float | nav_bearing () |
The current target bearing. More... | |
float | nav_lateral_acceleration_demand () |
Get lateral acceleration demand. More... | |
float | bearing_error () |
Heading error. More... | |
float | target_bearing () |
Bearing from aircraft to current target. More... | |
float | get_roll_setpoint () |
Get roll angle setpoint for fixed wing. More... | |
float | crosstrack_error () |
Get the current crosstrack error. More... | |
bool | reached_loiter_target () |
Returns true if the loiter waypoint has been reached. More... | |
bool | circle_mode () |
Returns true if following a circle (loiter) More... | |
float | switch_distance (float waypoint_switch_radius) |
Get the switch distance. More... | |
void | navigate_waypoints (const matrix::Vector2f &vector_A, const matrix::Vector2f &vector_B, const matrix::Vector2f &vector_curr_position, const matrix::Vector2f &ground_speed) |
Navigate between two waypoints. More... | |
void | navigate_loiter (const matrix::Vector2f &vector_A, const matrix::Vector2f &vector_curr_position, float radius, int8_t loiter_direction, const matrix::Vector2f &ground_speed_vector) |
Navigate on an orbit around a loiter waypoint. More... | |
void | navigate_heading (float navigation_heading, float current_heading, const matrix::Vector2f &ground_speed) |
Navigate on a fixed bearing. More... | |
void | navigate_level_flight (float current_heading) |
Keep the wings level. More... | |
void | set_l1_period (float period) |
Set the L1 period. More... | |
void | set_l1_damping (float damping) |
Set the L1 damping factor. More... | |
void | set_l1_roll_limit (float roll_lim_rad) |
Set the maximum roll angle output in radians. More... | |
void | set_roll_slew_rate (float roll_slew_rate) |
Set roll angle slew rate. More... | |
void | set_dt (float dt) |
Set control loop dt. More... | |
Private Member Functions | |
matrix::Vector2f | get_local_planar_vector (const matrix::Vector2f &origin, const matrix::Vector2f &target) const |
Convert a 2D vector from WGS84 to planar coordinates. More... | |
void | update_roll_setpoint () |
Update roll angle setpoint. More... | |
Private Attributes | |
float | _lateral_accel {0.0f} |
Lateral acceleration setpoint in m/s^2. More... | |
float | _L1_distance {20.0f} |
L1 lead distance, defined by period and damping. More... | |
bool | _circle_mode {false} |
flag for loiter mode More... | |
float | _nav_bearing {0.0f} |
bearing to L1 reference point More... | |
float | _bearing_error {0.0f} |
bearing error More... | |
float | _crosstrack_error {0.0f} |
crosstrack error in meters More... | |
float | _target_bearing {0.0f} |
the heading setpoint More... | |
float | _L1_period {25.0f} |
L1 tracking period in seconds. More... | |
float | _L1_damping {0.75f} |
L1 damping ratio. More... | |
float | _L1_ratio {5.0f} |
L1 ratio for navigation. More... | |
float | _K_L1 {2.0f} |
L1 control gain for _L1_damping. More... | |
float | _heading_omega {1.0f} |
Normalized frequency. More... | |
float | _roll_lim_rad {math::radians(30.0f)} |
maximum roll angle in radians More... | |
float | _roll_setpoint {0.0f} |
current roll angle setpoint in radians More... | |
float | _roll_slew_rate {0.0f} |
roll angle setpoint slew rate limit in rad/s More... | |
float | _dt {0} |
control loop time in seconds More... | |
L1 Nonlinear Guidance Logic.
Definition at line 71 of file ecl_l1_pos_controller.h.
|
inline |
Heading error.
The heading error is either compared to the current track or to the tangent of the current loiter radius.
Definition at line 94 of file ecl_l1_pos_controller.h.
References _bearing_error.
|
inline |
Returns true if following a circle (loiter)
Definition at line 125 of file ecl_l1_pos_controller.h.
References _circle_mode, navigate_heading(), navigate_level_flight(), navigate_loiter(), navigate_waypoints(), set_l1_damping(), set_l1_period(), and switch_distance().
Referenced by FixedwingPositionControl::calculate_target_airspeed(), and FixedwingPositionControl::control_position().
|
inline |
Get the current crosstrack error.
Definition at line 115 of file ecl_l1_pos_controller.h.
References _crosstrack_error.
Referenced by RoverPositionControl::run(), and FixedwingPositionControl::status_publish().
|
private |
Convert a 2D vector from WGS84 to planar coordinates.
This converts from latitude and longitude to planar coordinates with (0,0) being at the position of ref and returns a vector in meters towards wp.
ref | The reference position in WGS84 coordinates |
wp | The point to convert to into the local coordinates, in WGS84 coordinates |
Definition at line 354 of file ecl_l1_pos_controller.cpp.
References CONSTANTS_RADIUS_OF_EARTH, and math::radians().
Referenced by navigate_loiter(), and navigate_waypoints().
|
inline |
Get roll angle setpoint for fixed wing.
Definition at line 108 of file ecl_l1_pos_controller.h.
References _roll_setpoint.
Referenced by FixedwingPositionControl::control_landing(), FixedwingPositionControl::control_position(), and FixedwingPositionControl::control_takeoff().
|
inline |
The current target bearing.
Definition at line 79 of file ecl_l1_pos_controller.h.
References _nav_bearing, and matrix::wrap_pi().
Referenced by FixedwingPositionControl::control_landing(), FixedwingPositionControl::control_position(), FixedwingPositionControl::control_takeoff(), RoverPositionControl::run(), and FixedwingPositionControl::status_publish().
|
inline |
Get lateral acceleration demand.
Definition at line 86 of file ecl_l1_pos_controller.h.
References _lateral_accel.
Referenced by RoverPositionControl::control_position().
void ECL_L1_Pos_Controller::navigate_heading | ( | float | navigation_heading, |
float | current_heading, | ||
const matrix::Vector2f & | ground_speed | ||
) |
Navigate on a fixed bearing.
This only holds a certain direction and does not perform cross track correction. Helpful for semi-autonomous modes. Introduced by [2].
Definition at line 300 of file ecl_l1_pos_controller.cpp.
References _bearing_error, _circle_mode, _crosstrack_error, _heading_omega, _L1_distance, _lateral_accel, _nav_bearing, _target_bearing, math::constrain(), f(), M_PI_F, update_roll_setpoint(), and matrix::wrap_pi().
Referenced by circle_mode(), and FixedwingPositionControl::control_landing().
void ECL_L1_Pos_Controller::navigate_level_flight | ( | float | current_heading | ) |
Keep the wings level.
This is typically needed for maximum-lift-demand situations, such as takeoff or near stall. Introduced in [2].
Definition at line 337 of file ecl_l1_pos_controller.cpp.
References _bearing_error, _circle_mode, _crosstrack_error, _lateral_accel, _nav_bearing, _target_bearing, and update_roll_setpoint().
Referenced by circle_mode().
void ECL_L1_Pos_Controller::navigate_loiter | ( | const matrix::Vector2f & | vector_A, |
const matrix::Vector2f & | vector_curr_position, | ||
float | radius, | ||
int8_t | loiter_direction, | ||
const matrix::Vector2f & | ground_speed_vector | ||
) |
Navigate on an orbit around a loiter waypoint.
This allow orbits smaller than the L1 length, this modification was introduced in [2].
Definition at line 200 of file ecl_l1_pos_controller.cpp.
References _bearing_error, _circle_mode, _crosstrack_error, _K_L1, _L1_damping, _L1_distance, _L1_period, _L1_ratio, _lateral_accel, _nav_bearing, _target_bearing, math::constrain(), f(), FLT_EPSILON, get_bearing_to_next_waypoint(), get_local_planar_vector(), M_PI_F, math::max(), and update_roll_setpoint().
Referenced by circle_mode(), and FixedwingPositionControl::control_position().
void ECL_L1_Pos_Controller::navigate_waypoints | ( | const matrix::Vector2f & | vector_A, |
const matrix::Vector2f & | vector_B, | ||
const matrix::Vector2f & | vector_curr_position, | ||
const matrix::Vector2f & | ground_speed | ||
) |
Navigate between two waypoints.
Calling this function with two waypoints results in the control outputs to fly to the line segment defined by the points and once captured following the line segment. This follows the logic in [1].
Definition at line 72 of file ecl_l1_pos_controller.cpp.
References _bearing_error, _circle_mode, _crosstrack_error, _K_L1, _L1_distance, _L1_ratio, _lateral_accel, _nav_bearing, _target_bearing, math::constrain(), f(), get_bearing_to_next_waypoint(), get_local_planar_vector(), M_PI_F, math::max(), matrix::Vector< Type, M >::normalized(), math::radians(), and update_roll_setpoint().
Referenced by circle_mode(), FixedwingPositionControl::control_landing(), RoverPositionControl::control_position(), FixedwingPositionControl::control_position(), and FixedwingPositionControl::control_takeoff().
|
inline |
Returns true if the loiter waypoint has been reached.
Definition at line 120 of file ecl_l1_pos_controller.h.
References _circle_mode.
|
inline |
Set control loop dt.
The value will be used to apply roll angle setpoint slew rate limiting.
Definition at line 206 of file ecl_l1_pos_controller.h.
Referenced by FixedwingPositionControl::control_position().
void ECL_L1_Pos_Controller::set_l1_damping | ( | float | damping | ) |
Set the L1 damping factor.
The original publication recommends a default of sqrt(2) / 2 = 0.707
Definition at line 374 of file ecl_l1_pos_controller.cpp.
References _K_L1, _L1_damping, _L1_period, _L1_ratio, and M_PI_F.
Referenced by circle_mode(), FixedwingPositionControl::init(), and RoverPositionControl::~RoverPositionControl().
void ECL_L1_Pos_Controller::set_l1_period | ( | float | period | ) |
Set the L1 period.
Definition at line 363 of file ecl_l1_pos_controller.cpp.
References _heading_omega, _L1_damping, _L1_period, _L1_ratio, f(), and M_PI_F.
Referenced by circle_mode(), FixedwingPositionControl::init(), and RoverPositionControl::~RoverPositionControl().
|
inline |
Set the maximum roll angle output in radians.
Definition at line 196 of file ecl_l1_pos_controller.h.
References _roll_lim_rad.
Referenced by FixedwingPositionControl::init(), and RoverPositionControl::~RoverPositionControl().
|
inline |
Set roll angle slew rate.
Set to zero to deactivate.
Definition at line 201 of file ecl_l1_pos_controller.h.
References _roll_slew_rate.
Referenced by FixedwingPositionControl::init().
float ECL_L1_Pos_Controller::switch_distance | ( | float | waypoint_switch_radius | ) |
Get the switch distance.
This is the distance at which the system will switch to the next waypoint. This depends on the period and damping
waypoint_switch_radius | The switching radius the waypoint has set. |
Definition at line 65 of file ecl_l1_pos_controller.cpp.
References _L1_distance, and math::min().
Referenced by circle_mode(), and FixedwingPositionControl::status_publish().
|
inline |
Bearing from aircraft to current target.
Definition at line 101 of file ecl_l1_pos_controller.h.
References _target_bearing.
Referenced by RoverPositionControl::run(), and FixedwingPositionControl::status_publish().
|
private |
Update roll angle setpoint.
This will also apply slew rate limits if set.
Definition at line 49 of file ecl_l1_pos_controller.cpp.
References _dt, _lateral_accel, _roll_lim_rad, _roll_setpoint, _roll_slew_rate, CONSTANTS_ONE_G, math::constrain(), f(), and ISFINITE.
Referenced by navigate_heading(), navigate_level_flight(), navigate_loiter(), and navigate_waypoints().
|
private |
bearing error
Definition at line 214 of file ecl_l1_pos_controller.h.
Referenced by bearing_error(), navigate_heading(), navigate_level_flight(), navigate_loiter(), and navigate_waypoints().
|
private |
flag for loiter mode
Definition at line 212 of file ecl_l1_pos_controller.h.
Referenced by circle_mode(), navigate_heading(), navigate_level_flight(), navigate_loiter(), navigate_waypoints(), and reached_loiter_target().
|
private |
crosstrack error in meters
Definition at line 215 of file ecl_l1_pos_controller.h.
Referenced by crosstrack_error(), navigate_heading(), navigate_level_flight(), navigate_loiter(), and navigate_waypoints().
|
private |
control loop time in seconds
Definition at line 227 of file ecl_l1_pos_controller.h.
Referenced by set_dt(), and update_roll_setpoint().
|
private |
Normalized frequency.
Definition at line 222 of file ecl_l1_pos_controller.h.
Referenced by navigate_heading(), and set_l1_period().
|
private |
L1 control gain for _L1_damping.
Definition at line 221 of file ecl_l1_pos_controller.h.
Referenced by navigate_loiter(), navigate_waypoints(), and set_l1_damping().
|
private |
L1 damping ratio.
Definition at line 219 of file ecl_l1_pos_controller.h.
Referenced by navigate_loiter(), set_l1_damping(), and set_l1_period().
|
private |
L1 lead distance, defined by period and damping.
Definition at line 211 of file ecl_l1_pos_controller.h.
Referenced by navigate_heading(), navigate_loiter(), navigate_waypoints(), and switch_distance().
|
private |
L1 tracking period in seconds.
Definition at line 218 of file ecl_l1_pos_controller.h.
Referenced by navigate_loiter(), set_l1_damping(), and set_l1_period().
|
private |
L1 ratio for navigation.
Definition at line 220 of file ecl_l1_pos_controller.h.
Referenced by navigate_loiter(), navigate_waypoints(), set_l1_damping(), and set_l1_period().
|
private |
Lateral acceleration setpoint in m/s^2.
Definition at line 210 of file ecl_l1_pos_controller.h.
Referenced by nav_lateral_acceleration_demand(), navigate_heading(), navigate_level_flight(), navigate_loiter(), navigate_waypoints(), and update_roll_setpoint().
|
private |
bearing to L1 reference point
Definition at line 213 of file ecl_l1_pos_controller.h.
Referenced by nav_bearing(), navigate_heading(), navigate_level_flight(), navigate_loiter(), and navigate_waypoints().
|
private |
maximum roll angle in radians
Definition at line 224 of file ecl_l1_pos_controller.h.
Referenced by set_l1_roll_limit(), and update_roll_setpoint().
|
private |
current roll angle setpoint in radians
Definition at line 225 of file ecl_l1_pos_controller.h.
Referenced by get_roll_setpoint(), and update_roll_setpoint().
|
private |
roll angle setpoint slew rate limit in rad/s
Definition at line 226 of file ecl_l1_pos_controller.h.
Referenced by set_roll_slew_rate(), and update_roll_setpoint().
|
private |
the heading setpoint
Definition at line 216 of file ecl_l1_pos_controller.h.
Referenced by navigate_heading(), navigate_level_flight(), navigate_loiter(), navigate_waypoints(), and target_bearing().