AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
command_executor.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// 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#include "auto_apms_behavior_tree_core/node.hpp"
16#include "auto_apms_interfaces/action/command_tree_executor.hpp"
17
18#define INPUT_KEY_EXECUTOR_NAME "executor"
19
21{
22
23using CommandAction = auto_apms_interfaces::action::CommandTreeExecutor;
24
25template <uint8_t command>
26class CommandExecutorTemplate : public core::RosActionNode<CommandAction>
27{
28public:
29 using RosActionNode::RosActionNode;
30
31 static BT::PortsList providedPorts()
32 {
33 // We do not use the default port for the action name
34 return {BT::InputPort<std::string>(INPUT_KEY_EXECUTOR_NAME, "Name of the executor to command.")};
35 }
36
37 bool setGoal(Goal & goal) override final
38 {
39 goal.command = command;
40 return true;
41 }
42};
43
44class ResumeExecutor : public CommandExecutorTemplate<CommandAction::Goal::COMMAND_RESUME>
45{
46public:
47 using CommandExecutorTemplate::CommandExecutorTemplate;
48};
49
50class PauseExecutor : public CommandExecutorTemplate<CommandAction::Goal::COMMAND_PAUSE>
51{
52public:
53 using CommandExecutorTemplate::CommandExecutorTemplate;
54};
55
56class HaltExecutor : public CommandExecutorTemplate<CommandAction::Goal::COMMAND_HALT>
57{
58public:
59 using CommandExecutorTemplate::CommandExecutorTemplate;
60};
61
62class TerminateExecutor : public CommandExecutorTemplate<CommandAction::Goal::COMMAND_TERMINATE>
63{
64public:
65 using CommandExecutorTemplate::CommandExecutorTemplate;
66};
67
68} // namespace auto_apms_behavior_tree
69
70AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(auto_apms_behavior_tree::ResumeExecutor)
71AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(auto_apms_behavior_tree::PauseExecutor)
72AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(auto_apms_behavior_tree::HaltExecutor)
73AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(auto_apms_behavior_tree::TerminateExecutor)
Generic behavior tree node wrapper for a ROS 2 action client.
#define AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(type)
Macro for registering a behavior tree node plugin.
Definition node.hpp:40
Useful tooling for incorporating behavior trees for task development.
Definition builder.hpp:30