Skip to content

Commit

Permalink
navigator: add navigation state ID to every mode class
Browse files Browse the repository at this point in the history
  • Loading branch information
bresch committed Aug 9, 2024
1 parent 6cf0bf5 commit 4e7bb6a
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/modules/navigator/land.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "navigator.h"

Land::Land(Navigator *navigator) :
MissionBlock(navigator)
MissionBlock(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_LAND)
{
}

Expand Down Expand Up @@ -93,7 +93,7 @@ Land::on_active()
if (_navigator->get_land_detected()->landed) {
_navigator->get_mission_result()->finished = true;
_navigator->set_mission_result_updated();
_navigator->mode_completed(vehicle_status_s::NAVIGATION_STATE_AUTO_LAND);
_navigator->mode_completed(getNavigatorStateId());
set_idle_item(&_mission_item);

struct position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigator/loiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "navigator.h"

Loiter::Loiter(Navigator *navigator) :
MissionBlock(navigator),
MissionBlock(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER),
ModuleParams(navigator)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigator/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ using namespace time_literals;
static constexpr int32_t DEFAULT_MISSION_CACHE_SIZE = 10;

Mission::Mission(Navigator *navigator) :
MissionBase(navigator, DEFAULT_MISSION_CACHE_SIZE)
MissionBase(navigator, DEFAULT_MISSION_CACHE_SIZE, vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/navigator/mission_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
#include "mission_feasibility_checker.h"
#include "navigator.h"

MissionBase::MissionBase(Navigator *navigator, int32_t dataman_cache_size_signed) :
MissionBlock(navigator),
MissionBase::MissionBase(Navigator *navigator, int32_t dataman_cache_size_signed, uint8_t navigator_state_id) :
MissionBlock(navigator, navigator_state_id),
ModuleParams(navigator),
_dataman_cache_size_signed(dataman_cache_size_signed)
{
Expand Down Expand Up @@ -465,7 +465,7 @@ MissionBase::set_mission_items()

if (set_end_of_mission) {
setEndOfMissionItems();
_navigator->mode_completed(vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION);
_navigator->mode_completed(getNavigatorStateId());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigator/mission_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Navigator;
class MissionBase : public MissionBlock, public ModuleParams
{
public:
MissionBase(Navigator *navigator, int32_t dataman_cache_size_signed);
MissionBase(Navigator *navigator, int32_t dataman_cache_size_signed, uint8_t navigator_state_id);
~MissionBase() override = default;

virtual void on_inactive() override;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/navigator/mission_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

using matrix::wrap_pi;

MissionBlock::MissionBlock(Navigator *navigator) :
NavigatorMode(navigator)
MissionBlock::MissionBlock(Navigator *navigator, uint8_t navigator_state_id) :
NavigatorMode(navigator, navigator_state_id)
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigator/mission_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MissionBlock : public NavigatorMode
/**
* Constructor
*/
MissionBlock(Navigator *navigator);
MissionBlock(Navigator *navigator, uint8_t navigator_state_id);
virtual ~MissionBlock() = default;

MissionBlock(const MissionBlock &) = delete;
Expand Down
5 changes: 3 additions & 2 deletions src/modules/navigator/navigator_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
#include "navigator_mode.h"
#include "navigator.h"

NavigatorMode::NavigatorMode(Navigator *navigator) :
_navigator(navigator)
NavigatorMode::NavigatorMode(Navigator *navigator, uint8_t navigator_state_id) :
_navigator(navigator),
_navigator_state_id(navigator_state_id)
{
/* set initial mission items */
on_inactivation();
Expand Down
7 changes: 6 additions & 1 deletion src/modules/navigator/navigator_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@

#pragma once

#include <cstdint>

class Navigator;

class NavigatorMode
{
public:
NavigatorMode(Navigator *navigator);
NavigatorMode(Navigator *navigator, uint8_t navigator_state_id);
virtual ~NavigatorMode() = default;
NavigatorMode(const NavigatorMode &) = delete;
NavigatorMode &operator=(const NavigatorMode &) = delete;
Expand All @@ -56,6 +58,8 @@ class NavigatorMode

bool isActive() {return _active;};

uint8_t getNavigatorStateId() const { return _navigator_state_id; }

/**
* This function is called while the mode is inactive
*/
Expand All @@ -81,4 +85,5 @@ class NavigatorMode

private:
bool _active{false};
uint8_t _navigator_state_id{0};
};
2 changes: 1 addition & 1 deletion src/modules/navigator/precland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
static constexpr const char *LOST_TARGET_ERROR_MESSAGE = "Lost landing target while landing";

PrecLand::PrecLand(Navigator *navigator) :
MissionBlock(navigator),
MissionBlock(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND),
ModuleParams(navigator)
{
_handle_param_acceleration_hor = param_find("MPC_ACC_HOR");
Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigator/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static constexpr float MAX_DIST_FROM_HOME_FOR_LAND_APPROACHES{10.0f}; // [m] We
static constexpr float MIN_DIST_THRESHOLD = 2.f;

RTL::RTL(Navigator *navigator) :
NavigatorMode(navigator),
NavigatorMode(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_RTL),
ModuleParams(navigator),
_rtl_direct(navigator)
{
Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigator/rtl_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RtlBase : public MissionBase
{
public:
RtlBase(Navigator *navigator, int32_t dataman_cache_size_signed):
MissionBase(navigator, dataman_cache_size_signed) {};
MissionBase(navigator, dataman_cache_size_signed, vehicle_status_s::NAVIGATION_STATE_AUTO_RTL) {};
virtual ~RtlBase() = default;

virtual rtl_time_estimate_s calc_rtl_time_estimate() = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/navigator/rtl_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
using namespace math;

RtlDirect::RtlDirect(Navigator *navigator) :
MissionBlock(navigator),
MissionBlock(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_RTL),
ModuleParams(navigator)
{
_destination.lat = static_cast<double>(NAN);
Expand Down Expand Up @@ -318,7 +318,7 @@ void RtlDirect::set_rtl_item()

case RTLState::IDLE: {
set_idle_item(&_mission_item);
_navigator->mode_completed(vehicle_status_s::NAVIGATION_STATE_AUTO_RTL);
_navigator->mode_completed(getNavigatorStateId());
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/navigator/takeoff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <px4_platform_common/events.h>

Takeoff::Takeoff(Navigator *navigator) :
MissionBlock(navigator)
MissionBlock(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF)
{
}

Expand All @@ -68,7 +68,7 @@ Takeoff::on_active()
} else if (is_mission_item_reached_or_completed() && !_navigator->get_mission_result()->finished) {
_navigator->get_mission_result()->finished = true;
_navigator->set_mission_result_updated();
_navigator->mode_completed(vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF);
_navigator->mode_completed(getNavigatorStateId());

position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();

Expand Down
4 changes: 2 additions & 2 deletions src/modules/navigator/vtol_takeoff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
using matrix::wrap_pi;

VtolTakeoff::VtolTakeoff(Navigator *navigator) :
MissionBlock(navigator),
MissionBlock(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF),
ModuleParams(navigator)
{
}
Expand Down Expand Up @@ -151,7 +151,7 @@ VtolTakeoff::on_active()
// the VTOL takeoff is done
_navigator->get_mission_result()->finished = true;
_navigator->set_mission_result_updated();
_navigator->mode_completed(vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF);
_navigator->mode_completed(getNavigatorStateId());

break;
}
Expand Down

0 comments on commit 4e7bb6a

Please sign in to comment.