@@ -2847,31 +2847,36 @@ void FixedwingPositionControl::navigateWaypoints(const Vector2f &waypoint_A, con
2847
2847
// BUT no arbitrary max approach angle, approach entirely determined by generated
2848
2848
// bearing vectors
2849
2849
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
2852
2855
2853
2856
if (vector_A_to_B.norm () < FLT_EPSILON) {
2854
2857
// the waypoints are on top of each other and should be considered as a
2855
2858
// single waypoint, fly directly to it
2856
2859
if (vector_A_to_vehicle.norm () > FLT_EPSILON) {
2857
- vector_A_to_B = -vector_A_to_vehicle;
2860
+ desired_path = -vector_A_to_vehicle;
2858
2861
2859
2862
} else {
2860
2863
// Fly to a point and on it. Stay to the current control. Do not update the npfg library to get last output.
2861
2864
return ;
2862
2865
}
2863
2866
2864
-
2865
2867
} else if ((vector_A_to_B.dot (vector_A_to_vehicle) < -FLT_EPSILON)) {
2866
2868
// we are in front of waypoint A, fly directly to it until we are within switch distance.
2867
-
2868
2869
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;
2870
2871
}
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;
2871
2876
}
2872
2877
2873
2878
// track the line segment
2874
- Vector2f unit_path_tangent{vector_A_to_B .normalized ()};
2879
+ Vector2f unit_path_tangent{desired_path .normalized ()};
2875
2880
_target_bearing = atan2f (unit_path_tangent (1 ), unit_path_tangent (0 ));
2876
2881
_closest_point_on_path = waypoint_A + vector_A_to_vehicle.dot (unit_path_tangent) * unit_path_tangent;
2877
2882
_npfg.guideToPath (vehicle_pos, ground_vel, wind_vel, unit_path_tangent, waypoint_A, 0 .0f );
0 commit comments