Skip to content

Commit

Permalink
Plane: terrain_navigation: use ModeGuided update
Browse files Browse the repository at this point in the history
- Call ModeGuided _enter and _exit methods.
- Use ModeGuided update method.
- Store commanded curvature rather than radius.

Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring committed Feb 26, 2024
1 parent 6ef47e5 commit 64fe926
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ArduPlane/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class ModeTerrainNavigation : public ModeGuided
void _exit() override;

private:
float _radius_m;
float _curvature;
Vector2f _unit_path_tangent;
};

Expand Down
22 changes: 9 additions & 13 deletions ArduPlane/mode_terrain_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bool ModeTerrainNavigation::_enter()
// switch to NPFG nav controller
plane.nav_controller = &plane.NPFG_controller;
#endif
return true;
return ModeGuided::_enter();
}

void ModeTerrainNavigation::_exit()
Expand All @@ -18,25 +18,18 @@ void ModeTerrainNavigation::_exit()
// restore default nav controller
plane.nav_controller = &plane.L1_controller;
#endif
ModeGuided::_exit();
}

void ModeTerrainNavigation::update()
{
plane.calc_nav_roll();

plane.calc_nav_pitch();

plane.calc_throttle();
ModeGuided::update();
}

void ModeTerrainNavigation::navigate()
{
float curvature = 0.0;
if (!is_zero(_radius_m)) {
curvature = 1.0 / _radius_m;
}
plane.nav_controller->update_path(plane.next_WP_loc, _unit_path_tangent,
curvature, plane.loiter.direction);
_curvature, plane.loiter.direction);
}

bool ModeTerrainNavigation::handle_guided_request(Location target_loc)
Expand All @@ -58,8 +51,11 @@ bool ModeTerrainNavigation::handle_guided_request(Location target_loc)

void ModeTerrainNavigation::set_radius_and_direction(const float radius, const bool direction_is_ccw)
{
_radius_m = radius;
plane.loiter.direction = direction_is_ccw ? -1 : 1;
_curvature = 0.0;
if (!is_zero(radius)) {
_curvature = 1.0 / radius;
}
ModeGuided::set_radius_and_direction(radius, direction_is_ccw);
}

void ModeTerrainNavigation::set_path_tangent(Vector2f unit_path_tangent) {
Expand Down

0 comments on commit 64fe926

Please sign in to comment.