#include <chrono>
#include "auto_apms_interfaces/action/example_simple_skill.hpp"
#include "auto_apms_util/action_wrapper.hpp"
{
using SimpleSkillActionType = auto_apms_interfaces::action::ExampleSimpleSkill;
{
public:
SimpleSkillServer(
const rclcpp::NodeOptions & options) :
ActionWrapper(
"simple_skill", options) {}
bool onGoalRequest(std::shared_ptr<const Goal> ) override final
{
index_ = 1;
start_ = node_ptr_->now();
return true;
}
Status executeGoal(
std::shared_ptr<const Goal> goal_ptr, std::shared_ptr<Feedback> ,
std::shared_ptr<Result> result_ptr) override final
{
RCLCPP_INFO(node_ptr_->get_logger(), "#%i - %s", index_++, goal_ptr->msg.c_str());
if (index_ <= goal_ptr->n_times) {
return Status::RUNNING;
}
result_ptr->time_required = (node_ptr_->now() - start_).to_chrono<std::chrono::duration<double>>().count();
return Status::SUCCESS;
}
private:
uint8_t index_;
rclcpp::Time start_;
};
}
#include "rclcpp_components/register_node_macro.hpp"
RCLCPP_COMPONENTS_REGISTER_NODE(auto_apms_examples::SimpleSkillServer)
#include "auto_apms_behavior_tree/node.hpp"
{
{
public:
using RosActionNode::RosActionNode;
static BT::PortsList providedPorts()
{
return {BT::InputPort<std::string>("msg"), BT::InputPort<uint8_t>("n_times")};
}
bool setGoal(Goal & goal) override final
{
RCLCPP_INFO(logger_, "--- Set goal ---");
goal.msg = getInput<std::string>("msg").value();
goal.n_times = getInput<uint8_t>("n_times").value();
return true;
}
BT::NodeStatus onResultReceived(const WrappedResult & result) override final
{
RCLCPP_INFO(logger_, "--- Result received ---");
RCLCPP_INFO(logger_, "Time elapsed: %f", result.result->time_required);
return RosActionNode::onResultReceived(result);
}
};
}
Generic behavior tree node wrapper for a ROS 2 action client.
Generic base class for implementing robot skills using the ROS 2 action concept.
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.