51 static std::map<std::string, uint8_t> standardModes()
53 using VehicleStatus = px4_msgs::msg::VehicleStatus;
55 {
"Manual", VehicleStatus::NAVIGATION_STATE_MANUAL},
56 {
"Altitude", VehicleStatus::NAVIGATION_STATE_ALTCTL},
57 {
"Position", VehicleStatus::NAVIGATION_STATE_POSCTL},
58 {
"Mission", VehicleStatus::NAVIGATION_STATE_AUTO_MISSION},
59 {
"Hold", VehicleStatus::NAVIGATION_STATE_AUTO_LOITER},
60 {
"RTL", VehicleStatus::NAVIGATION_STATE_AUTO_RTL},
61 {
"Acro", VehicleStatus::NAVIGATION_STATE_ACRO},
62 {
"Descend", VehicleStatus::NAVIGATION_STATE_DESCEND},
63 {
"Termination", VehicleStatus::NAVIGATION_STATE_TERMINATION},
64 {
"Offboard", VehicleStatus::NAVIGATION_STATE_OFFBOARD},
65 {
"Stabilized", VehicleStatus::NAVIGATION_STATE_STAB},
66 {
"Takeoff", VehicleStatus::NAVIGATION_STATE_AUTO_TAKEOFF},
67 {
"Land", VehicleStatus::NAVIGATION_STATE_AUTO_LAND},
68 {
"FollowTarget", VehicleStatus::NAVIGATION_STATE_AUTO_FOLLOW_TARGET},
69 {
"PrecisionLand", VehicleStatus::NAVIGATION_STATE_AUTO_PRECLAND},
70 {
"Orbit", VehicleStatus::NAVIGATION_STATE_ORBIT},
71 {
"VtolTakeoff", VehicleStatus::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF},
76 std::map<std::string, uint8_t> known_modes_ = standardModes();
80 const std::string & instance_name,
const BT::NodeConfig & config,
82 :
RosSubscriberNode{instance_name, config, context, rclcpp::QoS(10).transient_local()}
86 static BT::PortsList providedPorts()
89 BT::InputPort<std::string>(INPUT_KEY_MODE_NAME,
"Name of the registered PX4 mode to resolve."),
90 BT::OutputPort<int>(OUTPUT_KEY_NAV_STATE,
"Resolved PX4 navigation state (mode id) of the named mode."),
94 BT::NodeStatus onTick(
const std::shared_ptr<auto_apms_px4_interfaces::msg::RegisteredMode> & last_msg_ptr)
final
97 if (last_msg_ptr) known_modes_[last_msg_ptr->name] = last_msg_ptr->nav_state;
99 const BT::Expected<std::string> expected_mode_name = getInput<std::string>(INPUT_KEY_MODE_NAME);
100 if (!expected_mode_name) {
102 logger_,
"%s - Missing required input '%s': %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
103 INPUT_KEY_MODE_NAME, expected_mode_name.error().c_str());
104 return BT::NodeStatus::FAILURE;
107 const auto it = known_modes_.find(expected_mode_name.value());
108 if (it == known_modes_.end()) {
110 return BT::NodeStatus::FAILURE;
113 setOutput(OUTPUT_KEY_NAV_STATE,
static_cast<int>(it->second));
114 return BT::NodeStatus::SUCCESS;
Additional parameters specific to ROS 2 determined at runtime by TreeBuilder.