|
AutoAPMS
Streamlining behaviors in ROS 2
|
Resolves a PX4 mode's name to its nav_state (mode id). More...

Additional Inherited Members | |
Public Member Functions inherited from RosSubscriberNode< auto_apms_px4_interfaces::msg::RegisteredMode > | |
| RosSubscriberNode (const std::string &instance_name, const Config &config, Context context, const rclcpp::QoS &qos={10}) | |
| Constructor. | |
| virtual BT::NodeStatus | onMessageReceived (const auto_apms_px4_interfaces::msg::RegisteredMode &msg) |
| Callback invoked when the node is ticked and a valid message has been received. | |
| bool | createSubscriber (const std::string &topic_name) |
| Create the ROS 2 subscriber. | |
| std::string | getTopicName () const |
| Get the name of the topic name this node subscribes to. | |
Static Public Member Functions inherited from RosSubscriberNode< auto_apms_px4_interfaces::msg::RegisteredMode > | |
| static BT::PortsList | providedBasicPorts (BT::PortsList addition) |
| Derived nodes implementing the static method RosSubscriberNode::providedPorts may call this method to also include the default port for ROS 2 behavior tree nodes. | |
| static BT::PortsList | providedPorts () |
| If a behavior tree requires input/output data ports, the developer must define this method accordingly. | |
Protected Member Functions inherited from RosNodeBase | |
| void | applyPortAliasing (const BT::TreeNode *node) const |
| Support the node manifest 'port_alias' feature: copy the aliased port values onto the original ports the node implementation reads. | |
| template<typename InstanceT> | |
| std::shared_ptr< InstanceT > | getSharedEntity (const std::string &entity_name, const std::function< std::shared_ptr< InstanceT >()> &factory) |
Retrieve a process-wide shared ROS 2 entity, creating it via factory on first use. | |
Resolves a PX4 mode's name to its nav_state (mode id).
The builtin PX4 flight modes have fixed nav_states and are known out of the box (see standardModes below), so they can be resolved by name without any mode component running. Custom/external modes, on the other hand, are assigned a nav_state dynamically by PX4 at registration time, so it cannot be hard-coded in a behavior tree. For those, this node subscribes to the registered_modes topic - on which every mode brought up via an auto_apms_px4::ModeRegistrationHandler (i.e. through ModeRegistrationFactory or ModeProxyActionFactory) announces its name-to-nav_state mapping - and merges the announcements with the builtin table. The nav_state of the mode named by the mode_name input port is written to the nav_state output port.
Announcements from all mode components are accumulated across ticks, so the node reliably resolves any announced mode regardless of tick rate or the order in which components come up. It returns SUCCESS once the requested mode is known, otherwise FAILURE. Wrap it in a retry decorator to wait for a custom mode to become available, then feed the resolved nav_state into SendCmdSetNavState (and CheckNavState) to switch to the mode.
Definition at line 47 of file get_mode_nav_state.cpp.