Skip to content

Commit 3c03d48

Browse files
committed
FW L1 controller: also handle negative loiter direction case
Signed-off-by: Silvan Fuhrer <[email protected]>
1 parent f614919 commit 3c03d48

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lib/l1/ECL_L1_Pos_Controller.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ ECL_L1_Pos_Controller::navigate_loiter(const Vector2d &vector_A, const Vector2d
307307
_circle_mode = true;
308308
_bearing_error = 0.0f;
309309
// once loitering, the bearing is tangentially to the loiter,
310-
// so subtract PI/2 from the bearing from current position to loiter center
311-
_nav_bearing = atan2f(-vector_A_to_airplane_unit(1), -vector_A_to_airplane_unit(0)) - M_PI_2_F;
310+
// so subtract/add PI/2 from the bearing from current position to loiter center depending on loiter direction
311+
const float center_to_tangent = M_PI_2_F * loiter_direction * -1.f;
312+
_nav_bearing = atan2f(-vector_A_to_airplane_unit(1), -vector_A_to_airplane_unit(0)) + center_to_tangent;
312313
}
313314

314315
update_roll_setpoint();

0 commit comments

Comments
 (0)