28#include "auto_apms_interfaces/action/example_simple_skill.hpp"
29#include "auto_apms_util/action_wrapper.hpp"
38using SimpleSkillActionType = auto_apms_interfaces::action::ExampleSimpleSkill;
40class SimpleSkillServer :
public auto_apms_util::ActionWrapper<SimpleSkillActionType>
43 SimpleSkillServer(
const rclcpp::NodeOptions & options) :
ActionWrapper(
"simple_skill", options) {}
46 bool onGoalRequest(std::shared_ptr<const Goal> )
override final
49 start_ = node_ptr_->now();
55 std::shared_ptr<const Goal> goal_ptr, std::shared_ptr<Feedback> ,
56 std::shared_ptr<Result> result_ptr)
override final
58 RCLCPP_INFO(node_ptr_->get_logger(),
"#%i - %s", index_++, goal_ptr->msg.c_str());
59 if (index_ <= goal_ptr->n_times) {
60 return Status::RUNNING;
62 result_ptr->time_required = (node_ptr_->now() - start_).to_chrono<std::chrono::duration<double>>().count();
63 return Status::SUCCESS;
74#include "rclcpp_components/register_node_macro.hpp"
75RCLCPP_COMPONENTS_REGISTER_NODE(auto_apms_examples::SimpleSkillServer)
81#include "auto_apms_behavior_tree/node.hpp"
86class SimpleSkillClient :
public auto_apms_behavior_tree::core::RosActionNode<SimpleSkillActionType>
89 using RosActionNode::RosActionNode;
92 static BT::PortsList providedPorts()
94 return {BT::InputPort<std::string>(
"msg"), BT::InputPort<uint8_t>(
"n_times")};
98 bool setGoal(Goal & goal)
override final
100 RCLCPP_INFO(logger_,
"--- Set goal ---");
101 goal.msg = getInput<std::string>(
"msg").value();
102 goal.n_times = getInput<uint8_t>(
"n_times").value();
107 BT::NodeStatus onResultReceived(
const WrappedResult & result)
override final
109 RCLCPP_INFO(logger_,
"--- Result received ---");
110 RCLCPP_INFO(logger_,
"Time elapsed: %f", result.result->time_required);
111 return RosActionNode::onResultReceived(result);
ActionWrapper(const std::string &action_name, rclcpp::Node::SharedPtr node_ptr, std::shared_ptr< ActionContextType > action_context_ptr)
#define AUTO_APMS_BEHAVIOR_TREE_DECLARE_NODE(type)
Macro for registering a behavior tree node plugin.