diff --git a/src/lib/FlightTasks/tasks/FlightTaskAuto.cpp b/src/lib/FlightTasks/tasks/FlightTaskAuto.cpp index 00add0b3a8..f05147c054 100644 --- a/src/lib/FlightTasks/tasks/FlightTaskAuto.cpp +++ b/src/lib/FlightTasks/tasks/FlightTaskAuto.cpp @@ -201,11 +201,10 @@ bool FlightTaskAuto::_evaluateTriplets() } // Calculate the current vehicle state and check if it has updated. - State _previous_state = _current_state; + State previous_state = _current_state; _current_state = _getCurrentState(); - bool state_update = (_current_state != _previous_state) ? true : false; - if (triplet_update || state_update) { + if (triplet_update || (_current_state != previous_state)) { _updateInternalWaypoints(); } @@ -276,6 +275,7 @@ State FlightTaskAuto::_getCurrentState() Vector2f u_prev_to_target = Vector2f(&(_triplet_target - _triplet_prev_wp)(0)).unit_or_zero(); Vector2f pos_to_target = Vector2f(&(_triplet_target - _position)(0)); Vector2f prev_to_pos = Vector2f(&(_position - _triplet_prev_wp)(0)); + // Calculate the closest point to the vehicle position on the line prev_wp - target _closest_pt = Vector2f(&_triplet_prev_wp(0)) + u_prev_to_target * (prev_to_pos * u_prev_to_target); State return_state = State::none; diff --git a/src/lib/FlightTasks/tasks/FlightTaskAuto.hpp b/src/lib/FlightTasks/tasks/FlightTaskAuto.hpp index 065737706d..c5c1a45922 100644 --- a/src/lib/FlightTasks/tasks/FlightTaskAuto.hpp +++ b/src/lib/FlightTasks/tasks/FlightTaskAuto.hpp @@ -109,11 +109,10 @@ private: uORB::Subscription *_sub_triplet_setpoint{nullptr}; - matrix::Vector3f _triplet_target; - matrix::Vector3f _triplet_prev_wp; - matrix::Vector3f _triplet_next_wp; - matrix::Vector2f _closest_pt; - + matrix::Vector3f _triplet_target; /**< current triplet from navigator which may differ from the intenal one (_target) depending on the vehicle state. */ + matrix::Vector3f _triplet_prev_wp; /**< previous triplet from navigator which may differ from the intenal one (_prev_wp) depending on the vehicle state.*/ + matrix::Vector3f _triplet_next_wp; /**< next triplet from navigator which may differ from the intenal one (_next_wp) depending on the vehicle state.*/ + matrix::Vector2f _closest_pt; /**< closest point to the vehicle position on the line previous - target */ map_projection_reference_s _reference_position{}; /**< Structure used to project lat/lon setpoint into local frame. */ float _reference_altitude = NAN; /**< Altitude relative to ground. */ @@ -123,5 +122,5 @@ private: bool _isFinite(const position_setpoint_s sp); /**< Checks if all waypoint triplets are finite. */ bool _evaluateGlobalReference(); /**< Check is global reference is available. */ float _getVelocityFromAngle(const float angle); /**< Computes the speed at target depending on angle. */ - State _getCurrentState(); + State _getCurrentState(); /**< Computes the current vehicle state based on the vehicle position and navigator triplets. */ };