scenario_simulator_v2 C++ API
configurable_rate_updater.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
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 TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__CONFIGURABLE_RATE_UPDATER_HPP
16 #define TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__CONFIGURABLE_RATE_UPDATER_HPP
17 
18 #include <functional>
19 #include <rclcpp/rclcpp.hpp>
20 
21 namespace traffic_simulator
22 {
24 {
25  rclcpp::TimerBase::SharedPtr timer_ = nullptr;
26  const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface_;
27  const rclcpp::node_interfaces::NodeTimersInterface::SharedPtr node_timers_interface_;
28  double update_rate_ = 0.0;
29  const std::function<void()> thunk_;
30  const rclcpp::Clock::SharedPtr clock_ptr_;
31 
32 public:
33  template <typename NodePointer>
34  ConfigurableRateUpdater(const NodePointer & node, std::function<void()> thunk)
35  : node_base_interface_(node->get_node_base_interface()),
36  node_timers_interface_(node->get_node_timers_interface()),
37  thunk_(thunk),
38  clock_ptr_(node->get_clock())
39  {
40  }
41 
42  auto createTimer(double update_rate) -> void;
43 
44  auto resetUpdateRate(double update_rate) -> void;
45 
46  auto getUpdateRate() const -> double { return update_rate_; }
47 };
48 } // namespace traffic_simulator
49 
50 #endif // TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__CONFIGURABLE_RATE_UPDATER_HPP
Definition: configurable_rate_updater.hpp:24
auto createTimer(double update_rate) -> void
Definition: configurable_rate_updater.cpp:19
auto resetUpdateRate(double update_rate) -> void
Definition: configurable_rate_updater.cpp:30
auto getUpdateRate() const -> double
Definition: configurable_rate_updater.hpp:46
ConfigurableRateUpdater(const NodePointer &node, std::function< void()> thunk)
Definition: configurable_rate_updater.hpp:34
Definition: api.hpp:48