AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
set_trigger.cpp
1// Copyright 2025 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_behavior_tree_core/node.hpp"
16#include "std_srvs/srv/trigger.hpp"
17
18#define OUTPUT_KEY_MESSAGE "message"
19
21{
22
23class SetTrigger : public core::RosServiceNode<std_srvs::srv::Trigger>
24{
25public:
26 SetTrigger(const std::string & instance_name, const Config & config, const Context & context)
27 : RosServiceNode(instance_name, config, context)
28 {
29 }
30
31 static BT::PortsList providedPorts()
32 {
33 return providedBasicPorts({
34 BT::OutputPort<std::string>(OUTPUT_KEY_MESSAGE, "Service response: informational message."),
35 });
36 }
37
38 bool setRequest(Request::SharedPtr & /*request*/) override final { return true; }
39
40 BT::NodeStatus onResponseReceived(const Response::SharedPtr & response) override final
41 {
42 setOutput(OUTPUT_KEY_MESSAGE, response->message);
43 return response->success ? BT::NodeStatus::SUCCESS : BT::NodeStatus::FAILURE;
44 }
45};
46
47} // namespace auto_apms_behavior_tree
48
49AUTO_APMS_BEHAVIOR_TREE_REGISTER_NODE(auto_apms_behavior_tree::SetTrigger)
Generic behavior tree node wrapper for a ROS 2 service client.
RosServiceNode(const std::string &instance_name, const Config &config, Context context)
#define AUTO_APMS_BEHAVIOR_TREE_REGISTER_NODE(type)
Macro for registering a behavior tree node plugin.
Definition node.hpp:44
Powerful tooling for incorporating behavior trees for task development.
Definition behavior.hpp:32