PX4 ROS 2 Interface Library
Library to interface with PX4 from a companion computer using ROS 2
px4_ros2::ActionHandler Class Reference

Handler passed to custom actions to run modes, actions and trajectories. More...

#include <px4_ros2/mission/mission_executor.hpp>

Public Member Functions

 ActionHandler (MissionExecutor &mission_executor)
 
void runMode (ModeBase::ModeID mode_id, const std::function< void()> &on_completed, const std::function< void()> &on_failure=nullptr)
 
void runAction (const std::string &action_name, const ActionArguments &arguments, const std::function< void()> &on_completed)
 
void runTrajectory (const std::shared_ptr< Mission > &trajectory, const std::function< void()> &on_completed, bool stop_at_last_item=true)
 
TrajectoryOptions getTrajectoryOptions () const
 get the current trajectory config options
 
void clearTrajectoryOptions ()
 Reset the current trajectory config options to the mission defaults.
 
void setTrajectoryOptions (const TrajectoryOptions &options)
 Override the trajectory config options. More...
 
std::optional< int > getCurrentMissionIndex () const
 
void setCurrentMissionIndex (int index)
 Set the current mission index. More...
 
bool currentActionSupportsResumeFromLanded () const
 
std::unique_ptr< ActionStateKeeperstoreState (const std::string &action_name, const ActionArguments &arguments)
 store the state of a continuous action More...
 
const Missionmission () const
 
bool deferFailsafes (bool enabled, int timeout_s=0)
 enable/disable deferral of failsafes More...
 
void onFailsafeDeferred (const std::function< void()> &callback)
 register callback for failsafe notification More...
 
bool isValid () const
 Check if the handler is still valid. More...
 

Friends

class MissionExecutor
 

Detailed Description

Handler passed to custom actions to run modes, actions and trajectories.

Member Function Documentation

◆ deferFailsafes()

bool px4_ros2::ActionHandler::deferFailsafes ( bool  enabled,
int  timeout_s = 0 
)
inline

enable/disable deferral of failsafes

Parameters
enabled
timeout_s0=system default, -1=no timeout
Returns
true on success

◆ isValid()

bool px4_ros2::ActionHandler::isValid ( ) const
inline

Check if the handler is still valid.

If the handler is invalid, it cannot be used anymore. It will be set invalid when the mission is aborted, or deactivated. This is useful for actions that use timers to run actions.

◆ onFailsafeDeferred()

void px4_ros2::ActionHandler::onFailsafeDeferred ( const std::function< void()> &  callback)
inline

register callback for failsafe notification

The callback is triggerd when a failsafe occurs while deferral is enabled.

◆ setCurrentMissionIndex()

void px4_ros2::ActionHandler::setCurrentMissionIndex ( int  index)

Set the current mission index.

This is primarily for the onResume action, in case the mission should be resumed at a different index.

When called as part of another action, the index will still be increased, and thus continue at the next item.

◆ setTrajectoryOptions()

void px4_ros2::ActionHandler::setTrajectoryOptions ( const TrajectoryOptions options)
inline

Override the trajectory config options.

The values that are not set will be kept as they were before

◆ storeState()

std::unique_ptr<ActionStateKeeper> px4_ros2::ActionHandler::storeState ( const std::string &  action_name,
const ActionArguments arguments 
)
inline

store the state of a continuous action

This is used to restore the state when the mission is interrupted (e.g. by the user or a failsafe) and continued later on. When restoring, the action will be called with the provided arguments.

This can be used for example, for a camera trigger command that continuous to run in the background.

Parameters
action_nameName of the calling action
argumentsArguments to the action for restoring the action
Returns
A token that should be stored. It can be deleted when the action stops or gets deactivated

The documentation for this class was generated from the following file: