2016-02-17 21:25:32 -04:00
|
|
|
#pragma once
|
2013-02-04 21:23:41 -04:00
|
|
|
|
|
|
|
/// @file AP_L1_Control.h
|
|
|
|
/// @brief L1 Control algorithm. This is a instance of an
|
|
|
|
/// AP_Navigation class
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Originally written by Brandon Jones 2013
|
|
|
|
*
|
|
|
|
* Modified by Paul Riseborough 2013 to provide:
|
|
|
|
* - Explicit control over frequency and damping
|
|
|
|
* - Explicit control over track capture angle
|
|
|
|
* - Ability to use loiter radius smaller than L1 length
|
|
|
|
*/
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Navigation/AP_Navigation.h>
|
2017-03-19 21:32:10 -03:00
|
|
|
#include <AP_SpdHgtControl/AP_SpdHgtControl.h>
|
2019-04-05 10:02:43 -03:00
|
|
|
#include <AP_Common/Location.h>
|
2013-02-04 21:23:41 -04:00
|
|
|
|
|
|
|
class AP_L1_Control : public AP_Navigation {
|
|
|
|
public:
|
2017-12-12 21:06:12 -04:00
|
|
|
AP_L1_Control(AP_AHRS &ahrs, const AP_SpdHgtControl *spdHgtControl)
|
|
|
|
: _ahrs(ahrs)
|
|
|
|
, _spdHgtControl(spdHgtControl)
|
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2016-05-03 21:20:35 -03:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:11:02 -03:00
|
|
|
/* Do not allow copies */
|
|
|
|
AP_L1_Control(const AP_L1_Control &other) = delete;
|
|
|
|
AP_L1_Control &operator=(const AP_L1_Control&) = delete;
|
|
|
|
|
2016-05-03 21:20:35 -03:00
|
|
|
/* see AP_Navigation.h for the definitions and units of these
|
|
|
|
* functions */
|
2019-02-21 19:09:19 -04:00
|
|
|
int32_t nav_roll_cd(void) const override;
|
|
|
|
float lateral_acceleration(void) const override;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// return the desired track heading angle(centi-degrees)
|
2019-02-21 19:09:19 -04:00
|
|
|
int32_t nav_bearing_cd(void) const override;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// return the heading error angle (centi-degrees) +ve to left of track
|
2019-02-21 19:09:19 -04:00
|
|
|
int32_t bearing_error_cd(void) const override;
|
2013-02-04 21:23:41 -04:00
|
|
|
|
2019-02-21 19:09:19 -04:00
|
|
|
float crosstrack_error(void) const override { return _crosstrack_error; }
|
|
|
|
float crosstrack_error_integrator(void) const override { return _L1_xtrack_i; }
|
2013-02-04 21:23:41 -04:00
|
|
|
|
2019-02-21 19:09:19 -04:00
|
|
|
int32_t target_bearing_cd(void) const override;
|
|
|
|
float turn_distance(float wp_radius) const override;
|
|
|
|
float turn_distance(float wp_radius, float turn_angle) const override;
|
|
|
|
float loiter_radius (const float loiter_radius) const override;
|
|
|
|
void update_waypoint(const struct Location &prev_WP, const struct Location &next_WP, float dist_min = 0.0f) override;
|
|
|
|
void update_loiter(const struct Location ¢er_WP, float radius, int8_t loiter_direction) override;
|
|
|
|
void update_heading_hold(int32_t navigation_heading_cd) override;
|
|
|
|
void update_level_flight(void) override;
|
|
|
|
bool reached_loiter_target(void) override;
|
2013-02-04 21:23:41 -04:00
|
|
|
|
2013-09-09 06:55:53 -03:00
|
|
|
// set the default NAVL1_PERIOD
|
|
|
|
void set_default_period(float period) {
|
2015-10-22 16:49:49 -03:00
|
|
|
_L1_period.set_default(period);
|
2013-09-09 06:55:53 -03:00
|
|
|
}
|
|
|
|
|
2019-02-21 19:09:19 -04:00
|
|
|
void set_data_is_stale(void) override {
|
2016-04-18 17:51:58 -03:00
|
|
|
_data_is_stale = true;
|
|
|
|
}
|
2019-02-21 19:09:19 -04:00
|
|
|
bool data_is_stale(void) const override {
|
2016-04-18 17:51:58 -03:00
|
|
|
return _data_is_stale;
|
|
|
|
}
|
|
|
|
|
2016-05-03 21:20:35 -03:00
|
|
|
// this supports the NAVl1_* user settable parameters
|
2013-02-04 21:23:41 -04:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2019-02-21 19:09:19 -04:00
|
|
|
void set_reverse(bool reverse) override {
|
2016-07-14 04:44:52 -03:00
|
|
|
_reverse = reverse;
|
|
|
|
}
|
|
|
|
|
2013-02-04 21:23:41 -04:00
|
|
|
private:
|
2016-05-03 21:20:35 -03:00
|
|
|
// reference to the AHRS object
|
2013-08-13 00:49:26 -03:00
|
|
|
AP_AHRS &_ahrs;
|
2013-02-04 21:23:41 -04:00
|
|
|
|
2017-03-19 21:32:10 -03:00
|
|
|
// pointer to the SpdHgtControl object
|
|
|
|
const AP_SpdHgtControl *_spdHgtControl;
|
|
|
|
|
2016-05-03 21:20:35 -03:00
|
|
|
// lateral acceration in m/s required to fly to the
|
|
|
|
// L1 reference point (+ve to right)
|
2016-07-12 01:59:12 -03:00
|
|
|
float _latAccDem;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// L1 tracking distance in meters which is dynamically updated
|
2016-07-12 01:59:12 -03:00
|
|
|
float _L1_dist;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// Status which is true when the vehicle has started circling the WP
|
2016-07-12 01:59:12 -03:00
|
|
|
bool _WPcircle;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// bearing angle (radians) to L1 point
|
2016-07-12 01:59:12 -03:00
|
|
|
float _nav_bearing;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// bearing error angle (radians) +ve to left of track
|
2016-07-12 01:59:12 -03:00
|
|
|
float _bearing_error;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// crosstrack error in meters
|
2016-07-12 01:59:12 -03:00
|
|
|
float _crosstrack_error;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// target bearing in centi-degrees from last update
|
2016-07-12 01:59:12 -03:00
|
|
|
int32_t _target_bearing_cd;
|
2016-05-03 21:20:35 -03:00
|
|
|
|
|
|
|
// L1 tracking loop period (sec)
|
|
|
|
AP_Float _L1_period;
|
|
|
|
// L1 tracking loop damping ratio
|
|
|
|
AP_Float _L1_damping;
|
2013-02-04 21:23:41 -04:00
|
|
|
|
2013-11-08 22:13:28 -04:00
|
|
|
// previous value of cross-track velocity
|
2016-07-12 01:59:12 -03:00
|
|
|
float _last_Nu;
|
2013-11-08 22:13:28 -04:00
|
|
|
|
|
|
|
// prevent indecision in waypoint tracking
|
|
|
|
void _prevent_indecision(float &Nu);
|
2015-09-22 01:02:54 -03:00
|
|
|
|
|
|
|
// integral feedback to correct crosstrack error. Used to ensure xtrack converges to zero.
|
|
|
|
// For tuning purposes it's helpful to clear the integrator when it changes so a _prev is used
|
|
|
|
float _L1_xtrack_i = 0;
|
|
|
|
AP_Float _L1_xtrack_i_gain;
|
|
|
|
float _L1_xtrack_i_gain_prev = 0;
|
2016-07-12 01:59:12 -03:00
|
|
|
uint32_t _last_update_waypoint_us;
|
2016-04-18 17:51:58 -03:00
|
|
|
bool _data_is_stale = true;
|
2016-07-14 04:44:52 -03:00
|
|
|
|
2017-03-19 21:32:10 -03:00
|
|
|
AP_Float _loiter_bank_limit;
|
|
|
|
|
2016-07-14 04:44:52 -03:00
|
|
|
bool _reverse = false;
|
2021-02-01 12:26:29 -04:00
|
|
|
float get_yaw() const;
|
2019-09-09 05:50:53 -03:00
|
|
|
int32_t get_yaw_sensor() const;
|
2013-02-04 21:23:41 -04:00
|
|
|
};
|