4848
4949using namespace matrix ;
5050
51- TEST (NpfgTest, Test)
52- {
53- // V C
54- // /
55- // /
56- // /
57- // P
58- const Vector2f curr_wp_ned (10 .f , 10 .f );
59- float target_bearing1 = NAN;
60- // NaN speed
61- EXPECT_FALSE (PX4_ISFINITE (target_bearing1));
62- }
63-
6451TEST (NpfgTest, NoWind)
6552{
6653 CourseToAirspeedRefMapper _course_to_airspeed;
@@ -85,8 +72,8 @@ TEST(NpfgTest, NoWind)
8572 EXPECT_NEAR (heading_setpoint, 0 .f , 0 .01f );
8673 EXPECT_NEAR (min_airspeed_for_bearing, min_ground_speed, FLT_EPSILON);
8774
88- // GIVEN: bearing due South
89- bearing = M_PI_F ;
75+ // GIVEN: bearing due East
76+ bearing = M_PI_2_F ;
9077 airspeed_max = 20 .f ;
9178 min_ground_speed = 5 .0f ;
9279
@@ -100,8 +87,8 @@ TEST(NpfgTest, NoWind)
10087 airspeed_setpoint_adapted));
10188
10289
103- // THEN: expect heading due South with a min airspeed equal to min_ground_speed
104- EXPECT_NEAR (heading_setpoint, -M_PI_F , 0 .01f );
90+ // THEN: expect heading due East with a min airspeed equal to min_ground_speed
91+ EXPECT_NEAR (heading_setpoint, M_PI_2_F , 0 .01f );
10592 EXPECT_NEAR (min_airspeed_for_bearing, min_ground_speed, FLT_EPSILON);
10693}
10794
@@ -152,7 +139,7 @@ TEST(NpfgTest, StrongHeadWind)
152139{
153140 CourseToAirspeedRefMapper _course_to_airspeed;
154141
155- // GIVEN
142+ // GIVEN: bearing due North and wind from the North
156143 const Vector2f wind_vel (-16 .f , 0 .f );
157144 float bearing = 0 .f ;
158145 float airspeed_max = 25 .f ;
@@ -168,22 +155,18 @@ TEST(NpfgTest, StrongHeadWind)
168155 float heading_setpoint = matrix::wrap_pi (_course_to_airspeed.mapCourseSetpointToHeadingSetpoint (bearing, wind_vel,
169156 airspeed_setpoint_adapted));
170157
171-
172158 // THEN: expect heading due North with a min airspeed equal to 16+min_ground_speed
173- EXPECT_NEAR (heading_setpoint, 0 .f , 0 .01f );
159+ EXPECT_NEAR (heading_setpoint, 0 .f , 0 .01f );
174160 EXPECT_NEAR (min_airspeed_for_bearing, 16 + min_ground_speed, 0 .1f );
175-
176-
177161}
178162
179163TEST (NpfgTest, StrongTailWind)
180164{
181-
182165 CourseToAirspeedRefMapper _course_to_airspeed;
183166
184- // GIVEN: bearing due South
185- const Vector2f wind_vel (- 16 .f , 0 .f );
186- float bearing = M_PI_F ;
167+ // GIVEN: bearing due East and wind from the West
168+ const Vector2f wind_vel (0 .f , 16 .f );
169+ float bearing = M_PI_2_F ;
187170 float airspeed_max = 25 .f ;
188171 float min_ground_speed = 5 .0f ;
189172 float airspeed_setpoint = 15 .f ;
@@ -197,21 +180,18 @@ TEST(NpfgTest, StrongTailWind)
197180 float heading_setpoint = matrix::wrap_pi (_course_to_airspeed.mapCourseSetpointToHeadingSetpoint (bearing, wind_vel,
198181 airspeed_setpoint_adapted));
199182
200- // THEN: expect heading due South with a min airspeed at 0
201- EXPECT_NEAR (heading_setpoint, -M_PI_F, 0 .01f );
183+ // THEN: expect heading due East with a min airspeed at 0
184+ EXPECT_NEAR (heading_setpoint, M_PI_2_F, 0 .01f );
202185 EXPECT_NEAR (min_airspeed_for_bearing, 0 .f , 0 .1f );
203186}
204187
205-
206-
207188TEST (NpfgTest, ExcessHeadWind)
208189{
209-
210190 // TEST DESCRIPTION: infeasible bearing, with |wind| = |airspeed|. Align with wind
211191
212192 CourseToAirspeedRefMapper _course_to_airspeed;
213193
214- // GIVEN
194+ // GIVEN: bearing due North and wind from the North
215195 const Vector2f wind_vel (-25 .f , 0 .f );
216196 float bearing = 0 .f ;
217197 float airspeed_max = 25 .f ;
@@ -259,7 +239,6 @@ TEST(NpfgTest, ExcessHeadWind)
259239 EXPECT_NEAR (heading_setpoint, 0 .f , 0 .01f );
260240 EXPECT_NEAR (min_airspeed_for_bearing, airspeed_max, 0 .1f );
261241
262-
263242 // TEST DESCRIPTION: infeasible bearing, with |wind| > |airspeed|. Aircraft should have a heading between the target bearing
264243 // and wind direction to minimize drift while still attempting to reach the bearing.
265244
@@ -280,52 +259,47 @@ TEST(NpfgTest, ExcessHeadWind)
280259 // & the minimum airspeed to be = maximum airspeed
281260 EXPECT_TRUE ((heading_setpoint > -M_PI_F / 2 .f ) && (heading_setpoint < bearing));
282261 EXPECT_NEAR (min_airspeed_for_bearing, airspeed_max, 0 .1f );
283-
284262}
285263
286264TEST (NpfgTest, ExcessTailWind)
287265{
288-
289266 CourseToAirspeedRefMapper _course_to_airspeed;
290267
291- // GIVEN: bearing due South
292- const Vector2f wind_vel (- 25 .f , 0 .f );
293- float bearing = M_PI_F ;
268+ // GIVEN: bearing due East and wind from the West
269+ const Vector2f wind_vel (0 .f , 25 .f );
270+ float bearing = M_PI_2_F ;
294271 float airspeed_max = 25 .f ;
295272 float min_ground_speed = 5 .0f ;
296273 float airspeed_setpoint = 15 .f ;
297274
298275 // WHEN: we update bearing and airspeed magnitude augmentation
299- float min_airspeed_for_bearing = _course_to_airspeed.getMinAirspeedForCurrentBearing (bearing, wind_vel,
300- airspeed_max, min_ground_speed);
276+ const float min_airspeed_for_bearing = _course_to_airspeed.getMinAirspeedForCurrentBearing (bearing, wind_vel,
277+ airspeed_max, min_ground_speed);
301278
302279 float airspeed_setpoint_adapted = math::constrain (airspeed_setpoint, min_airspeed_for_bearing, airspeed_max);
303280
304281 float heading_setpoint = matrix::wrap_pi (_course_to_airspeed.mapCourseSetpointToHeadingSetpoint (bearing, wind_vel,
305282 airspeed_setpoint_adapted));
306283
307- // THEN: expect heading due South with a min airspeed equal to 0
308- EXPECT_NEAR (heading_setpoint, -M_PI_F , 0 .01f );
284+ // THEN: expect heading due East with a min airspeed equal to 0
285+ EXPECT_NEAR (heading_setpoint, M_PI_2_F , 0 .01f );
309286 EXPECT_NEAR (min_airspeed_for_bearing, 0 .f , 0 .1f );
310-
311287}
312288
313289TEST (NpfgTest, ExcessCrossWind)
314290{
315-
316291 // TEST DESCRIPTION: infeasible bearing, with |wind| > |airspeed|. Aircraft should have a heading between the target bearing
317292 // and wind direction to minimize drift while still attempting to reach the bearing.
318293
319294 CourseToAirspeedRefMapper _course_to_airspeed;
320295
321- // GIVEN
296+ // GIVEN: bearing due North, strong wind due East
322297 const Vector2f wind_vel (0 , 30 .f );
323298 float bearing = 0 .f ;
324299 float airspeed_max = 25 .f ;
325300 float min_ground_speed = 5 .f ;
326301 float airspeed_setpoint = 15 .f ;
327302
328-
329303 // WHEN: we update bearing and airspeed magnitude augmentation
330304 float min_airspeed_for_bearing = _course_to_airspeed.getMinAirspeedForCurrentBearing (bearing, wind_vel,
331305 airspeed_max, min_ground_speed);
@@ -340,7 +314,6 @@ TEST(NpfgTest, ExcessCrossWind)
340314 EXPECT_TRUE ((heading_setpoint > -M_PI_F / 2 .f ) && (heading_setpoint < bearing));
341315 EXPECT_NEAR (min_airspeed_for_bearing, airspeed_max, 0 .1f );
342316
343-
344317 // TEST DESCRIPTION: infeasible bearing, with |wind| = |airspeed|. Align with wind.
345318
346319 airspeed_max = 30 .f ;
@@ -355,12 +328,10 @@ TEST(NpfgTest, ExcessCrossWind)
355328
356329 EXPECT_NEAR (heading_setpoint, -M_PI_F / 2 .f , 0 .01f );
357330 EXPECT_NEAR (min_airspeed_for_bearing, airspeed_max, 0 .1f );
358-
359331}
360332
361333TEST (NpfgTest, HeadingControl)
362334{
363-
364335 AirspeedReferenceController _airspeed_reference_controller;
365336 const float p_gain = 0 .8885f ;
366337
@@ -394,5 +365,4 @@ TEST(NpfgTest, HeadingControl)
394365
395366 // THEN: we we expect maxmimum lateral acceleration setpoint
396367 EXPECT_NEAR (lateral_acceleration_setpoint, airspeed * p_gain, 0 .01f );
397-
398368}
0 commit comments