AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
takeoff.cpp
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// http://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#include "auto_apms_px4_interfaces/action/takeoff.hpp"
16
17#include "auto_apms_behavior_tree_core/node.hpp"
18
19#define INPUT_KEY_ALTITUDE "alt"
20#define INPUT_KEY_USE_AMSL "use_amsl"
21#define INPUT_KEY_HEADING "heading"
22
23namespace auto_apms_px4
24{
25
26class TakeoffAction : public auto_apms_behavior_tree::core::RosActionNode<auto_apms_px4_interfaces::action::Takeoff>
27{
28public:
29 using RosActionNode::RosActionNode;
30
31 static BT::PortsList providedPorts()
32 {
33 return {
34 BT::InputPort<float>(INPUT_KEY_ALTITUDE, "Target altitude for takeoff in meters"),
35 BT::InputPort<bool>(
36 INPUT_KEY_USE_AMSL, false,
37 "If true, altitude is interpreted as above mean sea level (AMSL), otherwise as altitude above takeoff point"),
38 BT::InputPort<float>(INPUT_KEY_HEADING, 0.0, "Heading after takeoff in radians from north in NED frame")};
39 }
40
41 bool setGoal(Goal & goal)
42 {
43 if (const BT::Expected<float> expected = getInput<float>(INPUT_KEY_ALTITUDE)) {
44 goal.alt = expected.value();
45 } else {
46 RCLCPP_ERROR(logger_, "%s", expected.error().c_str());
47 return false;
48 }
49 goal.use_amsl = getInput<bool>(INPUT_KEY_USE_AMSL).value();
50 goal.heading_rad = getInput<float>(INPUT_KEY_HEADING).value();
51 return true;
52 }
53};
54
55} // namespace auto_apms_px4
56
57AUTO_APMS_BEHAVIOR_TREE_REGISTER_NODE(auto_apms_px4::TakeoffAction)
#define AUTO_APMS_BEHAVIOR_TREE_REGISTER_NODE(type)
Macro for registering a behavior tree node plugin.
Definition node.hpp:50
Implementation of PX4 mode peers offered by px4_ros2_cpp enabling integration with AutoAPMS.