18 #include "nav2_behavior_tree/plugins/decorator/rate_controller.hpp"
20 namespace nav2_behavior_tree
24 const std::string & name,
25 const BT::NodeConfiguration & conf)
26 : BT::DecoratorNode(name, conf),
38 BT::NodeStatus RateController::tick()
40 if (!BT::isStatusActive(status())) {
44 if (!BT::isStatusActive(status())) {
47 start_ = std::chrono::high_resolution_clock::now();
51 setStatus(BT::NodeStatus::RUNNING);
54 auto now = std::chrono::high_resolution_clock::now();
55 auto elapsed = now - start_;
58 typedef std::chrono::duration<float> float_seconds;
59 auto seconds = std::chrono::duration_cast<float_seconds>(elapsed);
64 if (first_time_ || (child_node_->status() == BT::NodeStatus::RUNNING) ||
65 seconds.count() >= period_)
68 const BT::NodeStatus child_state = child_node_->executeTick();
70 switch (child_state) {
71 case BT::NodeStatus::SKIPPED:
72 case BT::NodeStatus::RUNNING:
73 case BT::NodeStatus::FAILURE:
76 case BT::NodeStatus::SUCCESS:
77 start_ = std::chrono::high_resolution_clock::now();
78 return BT::NodeStatus::SUCCESS;
81 return BT::NodeStatus::FAILURE;
90 #include "behaviortree_cpp/bt_factory.h"
91 BT_REGISTER_NODES(factory)
A BT::DecoratorNode that ticks its child at a specified rate.
void initialize()
Function to read parameters and initialize class variables.
RateController(const std::string &name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::RateController.