Skip to content

Commit

Permalink
FlightTaskAuto: Update prev and next waypoint depending on validity
Browse files Browse the repository at this point in the history
This fixes the corner case where a NAV_DELAY command changes the
validity of the next WP but not the rest of the triplet. The logic in
FlightTask was ignoring this change because the check was only based on
WP position change.
  • Loading branch information
bresch authored and dagar committed Jun 26, 2020
1 parent 3302a69 commit 1761ef3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/flight_tasks/tasks/Auto/FlightTaskAuto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,16 @@ bool FlightTaskAuto::_evaluateTriplets()
// TODO This is a hack and it would be much better if the navigator only sends out a waypoints once they have changed.

bool triplet_update = true;
const bool prev_next_validity_changed = (_prev_was_valid != _sub_triplet_setpoint.get().previous.valid)
|| (_next_was_valid != _sub_triplet_setpoint.get().next.valid);

if (PX4_ISFINITE(_triplet_target(0))
&& PX4_ISFINITE(_triplet_target(1))
&& PX4_ISFINITE(_triplet_target(2))
&& fabsf(_triplet_target(0) - tmp_target(0)) < 0.001f
&& fabsf(_triplet_target(1) - tmp_target(1)) < 0.001f
&& fabsf(_triplet_target(2) - tmp_target(2)) < 0.001f) {
&& fabsf(_triplet_target(2) - tmp_target(2)) < 0.001f
&& !prev_next_validity_changed) {
// Nothing has changed: just keep old waypoints.
triplet_update = false;

Expand Down Expand Up @@ -231,6 +234,8 @@ bool FlightTaskAuto::_evaluateTriplets()
_triplet_prev_wp = _position;
}

_prev_was_valid = _sub_triplet_setpoint.get().previous.valid;

if (_type == WaypointType::loiter) {
_triplet_next_wp = _triplet_target;

Expand All @@ -242,6 +247,8 @@ bool FlightTaskAuto::_evaluateTriplets()
} else {
_triplet_next_wp = _triplet_target;
}

_next_was_valid = _sub_triplet_setpoint.get().next.valid;
}

if (_ext_yaw_handler != nullptr) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/flight_tasks/tasks/Auto/FlightTaskAuto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ class FlightTaskAuto : public FlightTask

matrix::Vector3f _prev_prev_wp{}; /**< Pre-previous waypoint (local frame). This will be used for smoothing trajectories -> not used yet. */
matrix::Vector3f _prev_wp{}; /**< Previous waypoint (local frame). If no previous triplet is available, the prev_wp is set to current position. */
bool _prev_was_valid{false};
matrix::Vector3f _target{}; /**< Target waypoint (local frame).*/
matrix::Vector3f _next_wp{}; /**< The next waypoint after target (local frame). If no next setpoint is available, next is set to target. */
bool _next_was_valid{false};
float _mc_cruise_speed{0.0f}; /**< Requested cruise speed. If not valid, default cruise speed is used. */
WaypointType _type{WaypointType::idle}; /**< Type of current target triplet. */

Expand Down

0 comments on commit 1761ef3

Please sign in to comment.