Skip to content

Commit 4b7da42

Browse files
authored
FWPositionControl: navigateWaypoints: fix logic if already past waypoint and need to turn back (#21642)
Signed-off-by: Silvan Fuhrer <[email protected]>
1 parent bb0f287 commit 4b7da42

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/modules/fw_pos_control/FixedwingPositionControl.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,31 +2847,36 @@ void FixedwingPositionControl::navigateWaypoints(const Vector2f &waypoint_A, con
28472847
// BUT no arbitrary max approach angle, approach entirely determined by generated
28482848
// bearing vectors
28492849

2850-
Vector2f vector_A_to_B = waypoint_B - waypoint_A;
2851-
Vector2f vector_A_to_vehicle = vehicle_pos - waypoint_A;
2850+
const Vector2f vector_A_to_B = waypoint_B - waypoint_A;
2851+
const Vector2f vector_B_to_A = -vector_A_to_B;
2852+
const Vector2f vector_A_to_vehicle = vehicle_pos - waypoint_A;
2853+
const Vector2f vector_B_to_vehicle = vehicle_pos - waypoint_B;
2854+
Vector2f desired_path = vector_A_to_B; // this is the default path tangent, but is overridden below
28522855

28532856
if (vector_A_to_B.norm() < FLT_EPSILON) {
28542857
// the waypoints are on top of each other and should be considered as a
28552858
// single waypoint, fly directly to it
28562859
if (vector_A_to_vehicle.norm() > FLT_EPSILON) {
2857-
vector_A_to_B = -vector_A_to_vehicle;
2860+
desired_path = -vector_A_to_vehicle;
28582861

28592862
} else {
28602863
// Fly to a point and on it. Stay to the current control. Do not update the npfg library to get last output.
28612864
return;
28622865
}
28632866

2864-
28652867
} else if ((vector_A_to_B.dot(vector_A_to_vehicle) < -FLT_EPSILON)) {
28662868
// we are in front of waypoint A, fly directly to it until we are within switch distance.
2867-
28682869
if (vector_A_to_vehicle.norm() > _npfg.switchDistance(500.0f)) {
2869-
vector_A_to_B = -vector_A_to_vehicle;
2870+
desired_path = -vector_A_to_vehicle;
28702871
}
2872+
2873+
} else if (vector_B_to_A.dot(vector_B_to_vehicle) < -FLT_EPSILON) {
2874+
// we are behind waypoint B, fly directly to it
2875+
desired_path = -vector_B_to_vehicle;
28712876
}
28722877

28732878
// track the line segment
2874-
Vector2f unit_path_tangent{vector_A_to_B.normalized()};
2879+
Vector2f unit_path_tangent{desired_path.normalized()};
28752880
_target_bearing = atan2f(unit_path_tangent(1), unit_path_tangent(0));
28762881
_closest_point_on_path = waypoint_A + vector_A_to_vehicle.dot(unit_path_tangent) * unit_path_tangent;
28772882
_npfg.guideToPath(vehicle_pos, ground_vel, wind_vel, unit_path_tangent, waypoint_A, 0.0f);

0 commit comments

Comments
 (0)