38 : node_{ node }, logger_{ node.get_logger().get_child(
"vehicle_command_client") }, command_timeout_{ command_timeout }
41 vehicle_command_pub_ = node_.create_publisher<px4_msgs::msg::VehicleCommand>(
"/fmu/in/vehicle_command", 10);
43 vehicle_command_ack_sub_ = node_.create_subscription<px4_msgs::msg::VehicleCommandAck>(
44 "/fmu/out/vehicle_command_ack", rclcpp::QoS(1).best_effort(),
45 [](px4_msgs::msg::VehicleCommandAck::UniquePtr msg) { (void)msg; });
71 rclcpp::WaitSet wait_set;
72 wait_set.add_subscription(vehicle_command_ack_sub_);
74 bool got_reply =
false;
75 auto start_time = std::chrono::steady_clock::now();
76 vehicle_command_pub_->publish(cmd);
80 auto now = std::chrono::steady_clock::now();
82 if (now >= start_time + command_timeout_)
87 auto wait_ret = wait_set.wait(command_timeout_ - (now - start_time));
89 if (wait_ret.kind() == rclcpp::WaitResultKind::Ready)
91 px4_msgs::msg::VehicleCommandAck ack;
92 rclcpp::MessageInfo info;
94 if (vehicle_command_ack_sub_->take(ack, info))
96 if (ack.command == cmd.command && ack.target_component == cmd.source_component)
98 RCLCPP_DEBUG(logger_,
"SyncSendVehicleCommand: Command %i - received ack result %i", cmd.command, ack.result);
99 if (ack.result == px4_msgs::msg::VehicleCommandAck::VEHICLE_CMD_RESULT_ACCEPTED)
108 RCLCPP_DEBUG(logger_,
"SyncSendVehicleCommand: Command %i - message not valid", cmd.command);
113 wait_set.remove_subscription(vehicle_command_ack_sub_);
118 RCLCPP_WARN(logger_,
"SyncSendVehicleCommand: Command %i - timeout, no ack received", cmd.command);
121 RCLCPP_DEBUG(logger_,
"SyncSendVehicleCommand: Command %i - returned %s", cmd.command,
toStr(result).c_str());
143 RCLCPP_DEBUG(logger_,
"Takeoff parameters: altitude_amsl_m=%f heading_rad=%f", altitude_amsl_m, heading_rad);
144 return !
SyncSendVehicleCommand(VehicleCommand::VEHICLE_CMD_NAV_TAKEOFF, NAN, NAN, NAN, heading_rad, NAN, NAN,
SendCommandResult SyncSendVehicleCommand(uint32_t command, float param1=NAN, float param2=NAN, float param3=NAN, float param4=NAN, float param5=NAN, float param6=NAN, float param7=NAN) const