AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
vehicle_command_client.hpp
Go to the documentation of this file.
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <chrono>
18#include <optional>
19
20#include "px4_msgs/msg/vehicle_command.hpp"
21#include "px4_msgs/msg/vehicle_command_ack.hpp"
22#include "px4_msgs/msg/vehicle_status.hpp"
23#include "px4_ros2/components/mode.hpp"
24#include "rclcpp/rclcpp.hpp"
25
26namespace auto_apms_px4
27{
28
30{
31 using VehicleCommand = px4_msgs::msg::VehicleCommand;
32
33public:
34 enum class FlightMode : uint8_t
35 {
36 Takeoff = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_TAKEOFF,
37 Land = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_LAND,
38 Hold = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_LOITER,
39 RTL = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_RTL,
40 Mission = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_MISSION,
41 };
42
49
50 explicit VehicleCommandClient(rclcpp::Node& node,
51 const std::chrono::milliseconds& command_timeout = std::chrono::milliseconds(500));
52
53 // Send a vehicle command synchronously
54 SendCommandResult SyncSendVehicleCommand(uint32_t command, float param1 = NAN, float param2 = NAN, float param3 = NAN,
55 float param4 = NAN, float param5 = NAN, float param6 = NAN,
56 float param7 = NAN) const;
57 // Send a vehicle command synchronously
58 SendCommandResult SyncSendVehicleCommand(const VehicleCommand& cmd) const;
59
60 bool Arm() const;
61 bool Disarm() const;
62
68 bool StartMission() const;
69
70 bool Takeoff(float altitude_amsl_m, float heading_rad = NAN) const;
71
72 bool Land() const;
73
74 bool SyncActivateFlightMode(uint8_t mode_id) const;
75 bool SyncActivateFlightMode(const FlightMode& mode) const;
76 bool SyncActivateFlightMode(const px4_ros2::ModeBase* const mode_ptr) const;
77
78private:
79 rclcpp::Node& node_;
80 const rclcpp::Logger logger_;
81 rclcpp::Publisher<px4_msgs::msg::VehicleCommand>::SharedPtr vehicle_command_pub_;
82 rclcpp::Subscription<px4_msgs::msg::VehicleCommandAck>::SharedPtr vehicle_command_ack_sub_;
83 const std::chrono::milliseconds command_timeout_;
84};
85
87
88} // namespace auto_apms_px4
bool StartMission() const
(Re)starts the uploaded mission plan.
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
bool SyncActivateFlightMode(uint8_t mode_id) const
VehicleCommandClient(rclcpp::Node &node, const std::chrono::milliseconds &command_timeout=std::chrono::milliseconds(500))
std::string toStr(VehicleCommandClient::SendCommandResult result)