AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
vehicle_command_client.hpp
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
33class VehicleCommandClient
34{
35 using VehicleCommand = px4_msgs::msg::VehicleCommand;
36
37public:
38 enum class FlightMode : uint8_t
39 {
40 Takeoff = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_TAKEOFF,
41 Land = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_LAND,
42 Hold = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_LOITER,
43 RTL = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_RTL,
44 Mission = px4_msgs::msg::VehicleStatus::NAVIGATION_STATE_AUTO_MISSION,
45 };
46
47 enum SendCommandResult : uint8_t
48 {
49 ACCEPTED,
50 REJECTED,
51 TIMEOUT
52 };
53
54 explicit VehicleCommandClient(
55 rclcpp::Node & node, const std::chrono::milliseconds & command_timeout = std::chrono::milliseconds(500));
56
57 // Send a vehicle command synchronously
58 SendCommandResult syncSendVehicleCommand(
59 uint32_t command, float param1 = NAN, float param2 = NAN, float param3 = NAN, float param4 = NAN,
60 float param5 = NAN, float param6 = NAN, float param7 = NAN) const;
61
62 // Send a vehicle command synchronously
63 SendCommandResult syncSendVehicleCommand(const VehicleCommand & cmd) const;
64
65 bool arm() const;
66 bool disarm() const;
67
73 bool startMission() const;
74
75 bool takeoff(float altitude_amsl_m, float heading_rad = NAN) const;
76
77 bool land() const;
78
79 bool syncActivateFlightMode(uint8_t mode_id) const;
80 bool syncActivateFlightMode(const FlightMode & mode) const;
81 bool syncActivateFlightMode(const px4_ros2::ModeBase * const mode_ptr) const;
82
83private:
84 rclcpp::Node & node_;
85 const rclcpp::Logger logger_;
86 rclcpp::Publisher<px4_msgs::msg::VehicleCommand>::SharedPtr vehicle_command_pub_;
87 rclcpp::Subscription<px4_msgs::msg::VehicleCommandAck>::SharedPtr vehicle_command_ack_sub_;
88 const std::chrono::milliseconds command_timeout_;
89};
90
91std::string toStr(VehicleCommandClient::SendCommandResult result);
92
93} // namespace auto_apms_px4
bool startMission() const
(Re)starts the uploaded mission plan.
Implementation of PX4 mode peers offered by px4_ros2_cpp enabling integration with AutoAPMS.
Definition mode.hpp:26