controls  3.0.0
NodeUtils.h
Go to the documentation of this file.
1 #ifndef CONTROLS_UTILS_NODEUTILS_H
2 #define CONTROLS_UTILS_NODEUTILS_H
3 
4 #include <rcl/time.h>
5 
6 #include <rclcpp/rclcpp.hpp>
7 
8 namespace Controller {
9 
16 class NodeUtils {
17 public:
21  inline static std::shared_ptr<rclcpp::Node> node_;
22 
28  static double current_ros_time() {
30  return 0.0;
31  }
32  return node_->get_clock()->now().seconds();
33  }
34 
40  static double current_system_time() {
41  return rclcpp::Clock{RCL_SYSTEM_TIME}.now().seconds();
42  }
43 
49  static rclcpp::Time current_ros_stamp() {
50  return rclcpp::Time{static_cast<int64_t>(current_ros_time())};
51  }
52 
58  static rclcpp::Logger get_logger() {
59  if (node_) {
60  return node_->get_logger();
61  }
62  return rclcpp::get_logger("controls");
63  }
64 };
65 
66 } // namespace Controller
67 #endif // CONTROLS_UTILS_NODEUTILS_H
Singleton utility providing access to the shared ROS node and time functions.
Definition: NodeUtils.h:16
static double current_ros_time()
Returns the current ROS clock time in seconds.
Definition: NodeUtils.h:28
static double current_system_time()
Returns the current system (wall-clock) time in seconds.
Definition: NodeUtils.h:40
static rclcpp::Logger get_logger()
Returns the ROS logger associated with the shared node.
Definition: NodeUtils.h:58
static rclcpp::Time current_ros_stamp()
Returns the current ROS time as an rclcpp::Time stamp.
Definition: NodeUtils.h:49
static std::shared_ptr< rclcpp::Node > node_
Shared pointer to the single active ROS2 node.
Definition: NodeUtils.h:21
Definition: NodeUtils.h:8