Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
rate_controller.hpp
1 // Copyright (c) 2018 Intel Corporation
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 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__RATE_CONTROLLER_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__RATE_CONTROLLER_HPP_
17 
18 #include <chrono>
19 #include <string>
20 
21 #include "behaviortree_cpp/decorator_node.h"
22 
23 namespace nav2_behavior_tree
24 {
25 
31 class RateController : public BT::DecoratorNode
32 {
33 public:
40  const std::string & name,
41  const BT::NodeConfiguration & conf);
42 
46  void initialize();
47 
52  static BT::PortsList providedPorts()
53  {
54  return {
55  BT::InputPort<double>("hz", 10.0, "Rate")
56  };
57  }
58 
59 private:
64  BT::NodeStatus tick() override;
65 
66  std::chrono::time_point<std::chrono::high_resolution_clock> start_;
67  double period_;
68  bool first_time_;
69 };
70 
71 } // namespace nav2_behavior_tree
72 
73 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__RATE_CONTROLLER_HPP_
A BT::DecoratorNode that ticks its child at a specified rate.
void initialize()
Function to read parameters and initialize class variables.
static BT::PortsList providedPorts()
Creates list of BT ports.
RateController(const std::string &name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::RateController.