48 using SendVehicleCommand::SendVehicleCommand;
50 static BT::PortsList providedPorts()
53 BT::InputPort<double>(INPUT_KEY_LATITUDE,
"Target latitude [°] (WGS84)."),
54 BT::InputPort<double>(INPUT_KEY_LONGITUDE,
"Target longitude [°] (WGS84)."),
55 BT::InputPort<double>(INPUT_KEY_ALTITUDE,
"Target altitude [m] (AMSL)."),
56 BT::InputPort<double>(
57 INPUT_KEY_YAW,
"Desired yaw [°] clockwise from north. Leave empty to keep the current heading mode."),
58 BT::InputPort<double>(INPUT_KEY_GROUND_SPEED, -1.0,
"Ground speed [m/s]. Negative selects the PX4 default."),
62 bool setMessage(px4_msgs::msg::VehicleCommand & msg)
override final
64 const BT::Expected<double> expected_lat = getInput<double>(INPUT_KEY_LATITUDE);
65 const BT::Expected<double> expected_lon = getInput<double>(INPUT_KEY_LONGITUDE);
66 const BT::Expected<double> expected_alt = getInput<double>(INPUT_KEY_ALTITUDE);
69 logger_,
"%s - Missing required input '%s': %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
70 INPUT_KEY_LATITUDE, expected_lat.error().c_str());
75 logger_,
"%s - Missing required input '%s': %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
76 INPUT_KEY_LONGITUDE, expected_lon.error().c_str());
81 logger_,
"%s - Missing required input '%s': %s", context_.getFullyQualifiedTreeNodeName(
this).c_str(),
82 INPUT_KEY_ALTITUDE, expected_alt.error().c_str());
86 msg = px4_msgs::msg::VehicleCommand{};
87 msg.command = px4_msgs::msg::VehicleCommand::VEHICLE_CMD_DO_REPOSITION;
88 msg.param1 =
static_cast<float>(getInput<double>(INPUT_KEY_GROUND_SPEED).value_or(-1.0));
93 const BT::Expected<double> expected_yaw = getInput<double>(INPUT_KEY_YAW);
94 msg.param4 = expected_yaw ?
static_cast<float>(expected_yaw.value()) : std::numeric_limits<float>::quiet_NaN();
96 msg.param5 = expected_lat.value();
97 msg.param6 = expected_lon.value();
98 msg.param7 =
static_cast<float>(expected_alt.value());
100 msg.from_external =
true;
104 logger_,
"%s - Repositioning to (%.7f, %.7f, %.2f) (source_component %u).",
105 context_.getFullyQualifiedTreeNodeName(
this).c_str(), msg.param5, msg.param6,
static_cast<double>(msg.param7),
106 msg.source_component);