[ros-users] [Discourse.ros.org] [Next Generation ROS] ROS 2 …

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: andreaspasternak via ros-users
Date:  
To: ros-users
CC: andreaspasternak
Subject: [ros-users] [Discourse.ros.org] [Next Generation ROS] ROS 2 Time vs std::chrono


@sloretz: You can wrap the clock provided by the node again in a `std::chrono` clock wrapper and you would have simulation time available.:

```
struct ros2_node_clock
{
  ros2_node_clock(std::shared_ptr<Clock> clock) : m_clock(clock) {}
  typedef std::chrono::nanoseconds                 duration;
  typedef duration::rep                      rep;
  typedef duration::period                      period;
  typedef std::chrono::time_point<ros2_clock, duration>     time_point;


static constexpr bool is_steady = false;

  static time_point
  now() noexcept {
    return time_point(duration(clock->now().nanoseconds()));
  }



std::shared_ptr<Clock> m_clock;
};

ros2_node_clock rclcpp::None::get_std_clock() {
return ros2_node_clock(get_clock());
}
```

The additional safety of not mixing clocks is lost in this case, but ROS 2 time is also not safe in this regard and not likely solvable.





---
[Visit Topic](https://discourse.ros.org/t/ros-2-time-vs-std-chrono/6293/5) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list

http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>