Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plane: Soaring upgrades #12210

Merged
merged 67 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
c93d9b8
AP_Soaring: add reason to exit Thermal loiter
magicrub Jun 5, 2019
3d05d6b
Plane: add reason to exit Thermal loiter and adjust LOW alt reaon to …
magicrub Jun 5, 2019
7c2cadc
Plane: refactor loiter heading exit logic
magicrub Jun 5, 2019
a69522a
Plane: improved soaring exit options
magicrub Jun 5, 2019
c8c5612
Plane: move loiter heading init for auto into auto helper, and proper…
magicrub Jun 5, 2019
41a643f
Plane: fix soaring typo
magicrub Jun 7, 2019
73b2a7f
AP_Soaring: Implement vario based on acceleration rather than differe…
samuelctabor Mar 26, 2019
db839ab
AP_Soaring: Remove redundant check for new vario data.
samuelctabor Mar 29, 2019
77e216e
AP_Soaring: Fix issue with loiter radius being saved as zero due to i…
samuelctabor May 16, 2019
7d7b7a5
AP_Soaring: Avoid calculations in lat/lng.
samuelctabor Mar 29, 2019
33ab6bf
AP_Soaring: Make the EKF states the actual NE position of the thermal…
samuelctabor Mar 29, 2019
4a2acf5
AP_Soaring: Remove unused methods, clean up and log position in N/E r…
samuelctabor Apr 24, 2019
1491a77
AP_Soaring: inhibit msg spam when lingering in loiter waiting for hea…
magicrub Jun 7, 2019
ff46c18
Plane: unified soaring exit behavior: auto heads to next wp, cruise c…
magicrub Jun 7, 2019
1a2659e
SITL: Add plane-soaring type, including parameters, mission, simulate…
samuelctabor May 26, 2019
9570364
AP_Soaring: Add a check of whether altitude has been lost overall whe…
samuelctabor Jun 8, 2019
d1631ca
Plane: fix bug with headingLinedUp when loiter.sum_cd was negative.
samuelctabor Jun 8, 2019
a1ef047
AP_Soaring: Add a 60s first order filter on climb rate. If this becom…
samuelctabor Jun 8, 2019
e803951
AP_Soaring: Line up on current, not next, nav command.
samuelctabor Jun 9, 2019
2eff9eb
Plane: Soaring: Reset loiter.sum_cd when good to continue thermalling…
samuelctabor Jun 9, 2019
54f9f8e
AP_Soaring: Add a maximum allowable drift distance when thermalling.
samuelctabor Jun 9, 2019
b3fe90a
Plane: Soaring - better reporting of exit due to drift.
samuelctabor Jun 9, 2019
caf0b93
AP_Soaring: Improved default sim parameters.
samuelctabor Jun 7, 2019
4c54d2d
SITL: Make soaring thermals slanted.
samuelctabor Jun 7, 2019
b51338a
AP_TECS: Return the adjusted demanded airspeed. The aspd_error mavlin…
samuelctabor Oct 18, 2018
2d14a9d
AP_TECS: Add a feed-forward term from adjusted demanded airspeed to n…
samuelctabor Oct 18, 2018
bf1a0b6
AP_TECS: Correct an error in the SEBdot FF term.
samuelctabor Oct 18, 2018
28829bb
AP_TECS: Add flags to indicate gliding flight, and use these with AP_…
samuelctabor Oct 18, 2018
f04d126
Plane: Soaring, don't wait for heading if too low, and add timeout ot…
samuelctabor Jun 10, 2019
09d9d83
AP_Soaring: Add SOAR_MAX_RADIUS parameter, that defines when a RTL wi…
samuelctabor Jun 17, 2019
1d3c863
Plane: Soaring, make zero SOAR_MAX_RADIUS always RTL, and -1 never.
samuelctabor Jun 18, 2019
5bbba68
AP_Soaring: Calculate expected thermalling sink live and avoid divide…
samuelctabor Jun 22, 2019
cfad6b7
AP_Math: Add template for Vector2f::projected.
samuelctabor Jun 23, 2019
1a4d1d6
AP_Soaring: Move drift check to separate function and check drift wit…
samuelctabor Jun 22, 2019
7d504cb
AP_Soaring: Make the trigger VSPEED take account of thermalling sink.
samuelctabor Jun 22, 2019
9b5faef
SITL: Make thermal drift relative to 100m alt to avoid so much change…
samuelctabor Jun 22, 2019
6a96238
AP_Soaring: Reduce drift feed-forward by ratio of climb rate to therm…
samuelctabor Jun 23, 2019
26130bb
AP_Soaring: Calculate filter time constant based on airspeed and loit…
samuelctabor Jun 23, 2019
ad31b3d
AP_Soaring: Cleanup variometer.
samuelctabor Jun 23, 2019
b60f316
AP_Soaring: Correct bug with reversed arguments.
samuelctabor Jun 23, 2019
ceccdd1
AP_Soaring: Fix use of double precision sqrt.
samuelctabor Jun 23, 2019
20bf7c1
AP_Soaring: Fix incorrect trig function and log the expected sink.
samuelctabor Jun 23, 2019
4165277
AP_Soaring: Also log acceleration.
samuelctabor Jun 27, 2019
6c9201d
AP_Soaring: Remove dsp bias and log this.
samuelctabor Jun 28, 2019
24e8da0
AP_Soaring: Make enable channel 3 position. PWM above 1400us allows m…
samuelctabor Apr 24, 2019
b181df6
AP_Soaring: Adjust initial EKF values and limit R to 40.0m.
samuelctabor Jul 7, 2019
ac8157b
AP_Soaring: Detect changes in active parameter/switch position.
samuelctabor Jul 15, 2019
e07b7a1
Plane: Make target altitude track current altitude when gliding.
samuelctabor Jul 15, 2019
81b39bf
Plane: In FBWB make target alt track current if soaring is enabled an…
samuelctabor Jul 17, 2019
9197d2b
Autotest: Add test for soaring.
samuelctabor May 27, 2019
d9b2fda
AP_Soaring: Use 64 bit variable for time to avoid overflow.
samuelctabor Aug 7, 2019
a90d6ee
AP_Soaring: Improve tracking of enabled/disabled status.
samuelctabor Aug 18, 2019
b497bf0
AP_Soaring: Report changes in active status.
samuelctabor Aug 18, 2019
b774d84
AP_Soaring: Fix bug when no soaring activation RC channel set.
samuelctabor Aug 19, 2019
d9fddaf
AP_Soaring: Fix too-long status message.
samuelctabor Aug 19, 2019
0167a72
Plane: Required changes for conditional soaring compilation (fmuv2).
samuelctabor Aug 23, 2019
d466daa
TECS: Don't override the speedweight to 0 if synthetic airspeed is in…
samuelctabor Oct 12, 2019
810c26d
Autotest: Simplify soaring.py.
samuelctabor Dec 27, 2019
c99b928
AP_Soaring: Make vario time constant public.
samuelctabor Jan 11, 2020
8978984
AP_Soaring: Add a low pass of target position from EKF before using it.
samuelctabor Jan 11, 2020
7be3ef0
AP_Soaring: Update autotest to use delay_sim_time not wait_seconds.
samuelctabor Jan 28, 2020
2e86873
Plane: Remove unused isHeadingLinedUp function, and rename functions …
samuelctabor Jan 28, 2020
12481be
AP_TECS: Update descriptions of pitch feed-forward parameters.
samuelctabor Mar 1, 2020
9724fea
AP_Soaring: Don't check throttle status on entry to loiter, because i…
samuelctabor Mar 27, 2020
c371865
AP_Soaring: Use enum class rather than typedef enum for states and hi…
samuelctabor Apr 5, 2020
991c852
AP_Soaring: Add log documentation.
samuelctabor Apr 6, 2020
5da42bb
Tools: Make soaring test a subclass of plane test.
samuelctabor Apr 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions ArduPlane/ArduPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,6 @@ void Plane::update_alt()
if (flight_stage == AP_Vehicle::FixedWing::FLIGHT_LAND && current_loc.past_interval_finish_line(prev_WP_loc, next_WP_loc)) {
distance_beyond_land_wp = current_loc.get_distance(next_WP_loc);
}

bool soaring_active = false;
#if SOARING_ENABLED == ENABLED
if (g2.soaring_controller.is_active() && g2.soaring_controller.get_throttle_suppressed()) {
soaring_active = true;
}
#endif

SpdHgt_Controller->update_pitch_throttle(relative_target_altitude_cm(),
target_airspeed_cm,
Expand All @@ -592,8 +585,7 @@ void Plane::update_alt()
get_takeoff_pitch_min_cd(),
throttle_nudge,
tecs_hgt_afe(),
aerodynamic_load_factor,
soaring_active);
aerodynamic_load_factor);
}
}

Expand Down
3 changes: 3 additions & 0 deletions ArduPlane/Plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,9 @@ class Plane : public AP_Vehicle {
// rudder mixing gain for differential thrust (0 - 1)
float rudder_dt;

// soaring mode-change timer
uint32_t soaring_mode_timer;

void adjust_nav_pitch_throttle(void);
void update_load_factor(void);
void send_fence_status(mavlink_channel_t chan);
Expand Down
6 changes: 6 additions & 0 deletions ArduPlane/altitude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ void Plane::adjust_altitude_target()
landing.adjust_landing_slope_for_rangefinder_bump(rangefinder_state, prev_WP_loc, next_WP_loc, current_loc, auto_state.wp_distance, target_altitude.offset_cm);
} else if (landing.get_target_altitude_location(target_location)) {
set_target_altitude_location(target_location);
#if SOARING_ENABLED == ENABLED
} else if (g2.soaring_controller.is_active() && g2.soaring_controller.get_throttle_suppressed()) {
// Reset target alt to current alt, to prevent large altitude errors when gliding.
set_target_altitude_location(current_loc);
reset_offset_altitude();
#endif
} else if (reached_loiter_target()) {
// once we reach a loiter target then lock to the final
// altitude target
Expand Down
40 changes: 1 addition & 39 deletions ArduPlane/commands_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,47 +1074,9 @@ bool Plane::verify_loiter_heading(bool init)
return true;
}

if (next_WP_loc.get_distance(next_nav_cmd.content.location) < abs(aparm.loiter_radius)) {
/* Whenever next waypoint is within the loiter radius,
maintaining loiter would prevent us from ever pointing toward the next waypoint.
Hence break out of loiter immediately
*/
return true;
}

// Bearing in degrees
int32_t bearing_cd = current_loc.get_bearing_to(next_nav_cmd.content.location);

// get current heading.
int32_t heading_cd = gps.ground_course_cd();

int32_t heading_err_cd = wrap_180_cd(bearing_cd - heading_cd);

if (init) {
loiter.sum_cd = 0;
}

/*
Check to see if the the plane is heading toward the land
waypoint. We use 20 degrees (+/-10 deg) of margin so that
we can handle 200 degrees/second of yaw.

After every full circle, extend acceptance criteria to ensure
aircraft will not loop forever in case high winds are forcing
it beyond 200 deg/sec when passing the desired exit course
*/

// Use integer division to get discrete steps
int32_t expanded_acceptance = 1000 * (loiter.sum_cd / 36000);

if (labs(heading_err_cd) <= 1000 + expanded_acceptance) {
// Want to head in a straight line from _here_ to the next waypoint instead of center of loiter wp

// 0 to xtrack from center of waypoint, 1 to xtrack from tangent exit location
if (next_WP_loc.loiter_xtrack) {
next_WP_loc = current_loc;
}
return true;
}
return false;
return plane.mode_loiter.isHeadingLinedUp(next_WP_loc, next_nav_cmd.content.location);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs review by @WickedShell

}
4 changes: 4 additions & 0 deletions ArduPlane/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <AP_Param/AP_Param.h>
#include <AP_Common/Location.h>
#include <stdint.h>
#include <AP_Common/Location.h>

class Mode
{
Expand Down Expand Up @@ -172,6 +173,9 @@ class ModeLoiter : public Mode
// methods that affect movement of the vehicle in this mode
void update() override;

bool isHeadingLinedUp(const Location loiterCenterLoc, const Location targetLoc);
bool isHeadingLinedUp_cd(const int32_t bearing_cd);

protected:

bool _enter() override;
Expand Down
57 changes: 56 additions & 1 deletion ArduPlane/mode_loiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ bool ModeLoiter::_enter()
plane.auto_throttle_mode = true;
plane.auto_navigation_mode = true;
plane.do_loiter_at_location();
plane.loiter_angle_reset();

#if SOARING_ENABLED == ENABLED
if (plane.g2.soaring_controller.is_active() && plane.g2.soaring_controller.suppress_throttle()) {
if (plane.g2.soaring_controller.is_active()) {
plane.g2.soaring_controller.init_thermalling();
plane.g2.soaring_controller.get_target(plane.next_WP_loc); // ahead on flight path
}
Expand All @@ -25,3 +26,57 @@ void ModeLoiter::update()
plane.calc_throttle();
}

bool ModeLoiter::isHeadingLinedUp(const Location loiterCenterLoc, const Location targetLoc)
samuelctabor marked this conversation as resolved.
Show resolved Hide resolved
{
// Return true if current heading is aligned to vector to targetLoc.
// Tolerance is initially 10 degrees and grows at 10 degrees for each loiter circle completed.

const uint16_t loiterRadius = abs(plane.aparm.loiter_radius);
if (loiterCenterLoc.get_distance(targetLoc) < loiterRadius + loiterRadius*0.05) {
/* Whenever next waypoint is within the loiter radius plus 5%,
maintaining loiter would prevent us from ever pointing toward the next waypoint.
Hence break out of loiter immediately
*/
return true;
}

// Bearing in centi-degrees
const int32_t bearing_cd = plane.current_loc.get_bearing_to(targetLoc);
return isHeadingLinedUp_cd(bearing_cd);
}


bool ModeLoiter::isHeadingLinedUp_cd(const int32_t bearing_cd)
{
// Return true if current heading is aligned to bearing_cd.
// Tolerance is initially 10 degrees and grows at 10 degrees for each loiter circle completed.

// get current heading.
const int32_t heading_cd = plane.gps.ground_course_cd();

const int32_t heading_err_cd = wrap_180_cd(bearing_cd - heading_cd);

/*
Check to see if the the plane is heading toward the land
waypoint. We use 20 degrees (+/-10 deg) of margin so that
we can handle 200 degrees/second of yaw.

After every full circle, extend acceptance criteria to ensure
aircraft will not loop forever in case high winds are forcing
it beyond 200 deg/sec when passing the desired exit course
*/

// Use integer division to get discrete steps
const int32_t expanded_acceptance = 1000 * (labs(plane.loiter.sum_cd) / 36000);

if (labs(heading_err_cd) <= 1000 + expanded_acceptance) {
// Want to head in a straight line from _here_ to the next waypoint instead of center of loiter wp

// 0 to xtrack from center of waypoint, 1 to xtrack from tangent exit location
if (plane.next_WP_loc.loiter_xtrack) {
plane.next_WP_loc = plane.current_loc;
}
return true;
}
return false;
}
7 changes: 7 additions & 0 deletions ArduPlane/navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ void Plane::update_fbwb_speed_height(void)
// the current altitude
set_target_altitude_current();
}

#if SOARING_ENABLED == ENABLED
if (g2.soaring_controller.is_active() && g2.soaring_controller.get_throttle_suppressed()) {
// we're in soaring mode with throttle suppressed
set_target_altitude_current();;
}
#endif

target_altitude.last_elevator_input = elevator_input;
}
Expand Down
10 changes: 0 additions & 10 deletions ArduPlane/servos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,6 @@ void Plane::set_servos_controlled(void)
SRV_Channels::set_output_scaled(SRV_Channel::k_throttle,
constrain_int16(quadplane.forward_throttle_pct(), min_throttle, max_throttle));
}

#if SOARING_ENABLED == ENABLED
// suppress throttle when soaring is active
samuelctabor marked this conversation as resolved.
Show resolved Hide resolved
if ((control_mode == &mode_fbwb || control_mode == &mode_cruise ||
control_mode == &mode_auto || control_mode == &mode_loiter) &&
g2.soaring_controller.is_active() &&
g2.soaring_controller.get_throttle_suppressed()) {
SRV_Channels::set_output_scaled(SRV_Channel::k_throttle, 0);
}
#endif
}

/*
Expand Down
Loading