40 std::shared_ptr<px4_msgs::msg::VehicleStatus> last_msg_;
44 const std::string & instance_name,
const BT::NodeConfig & config,
51 createSubscriber(
"fmu/out/vehicle_status" + px4_ros2::getMessageNameVersion<px4_msgs::msg::VehicleStatus>());
54 static BT::PortsList providedPorts()
57 BT::InputPort<int>(INPUT_KEY_NAV_STATE,
"Expected PX4 navigation state (mode id) the vehicle should be in."),
61 BT::NodeStatus onTick(
const std::shared_ptr<px4_msgs::msg::VehicleStatus> & last_msg_ptr)
final
63 if (last_msg_ptr) last_msg_ = last_msg_ptr;
66 if (!last_msg_)
return BT::NodeStatus::FAILURE;
68 const BT::Expected<int> expected_nav_state = getInput<int>(INPUT_KEY_NAV_STATE);
69 if (!expected_nav_state) {
71 logger_,
"%s - Missing required input '%s': %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
72 INPUT_KEY_NAV_STATE, expected_nav_state.error().c_str());
73 return BT::NodeStatus::FAILURE;
76 return last_msg_->nav_state ==
static_cast<uint8_t
>(expected_nav_state.value()) ? BT::NodeStatus::SUCCESS
77 : BT::NodeStatus::FAILURE;
Additional parameters specific to ROS 2 determined at runtime by TreeBuilder.