ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Could anybody please explain how the nanosec is being updated. My understanding is that the value has to increase in each cycle.
The current time is the seconds + nanoseconds. Notice that when nanosec
decreased it's because sec
increased by 1.
To calculate the difference between two times you'll need to get the difference between the sum of those two. Thankfully there's already rclcpp::Time
and rclcpp::Duration
classes to handle that. Create two instances of rclcpp::Time for the start time and end time, then subtract the two to get an rclcpp::Duration containing the difference.