ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I can't compile your example, because I get:

/Users/william/ros2_ws/src/ros2/demos/demo_nodes_cpp/src/topics/talker.cpp:35:59: error: cannot pass object of non-trivial type 'rclcpp::Time' through variadic function; call will abort at runtime
      [-Wnon-pod-varargs]
        RCLCPP_INFO(this->get_logger(), "clk2 time: %ld", clk2->now());
                                                          ^
/Users/william/ros2_ws/src/ros2/demos/demo_nodes_cpp/src/topics/talker.cpp:36:59: error: cannot pass object of non-trivial type 'rclcpp::Time' through variadic function; call will abort at runtime
      [-Wnon-pod-varargs]
        RCLCPP_INFO(this->get_logger(), "clk3 time: %ld", clk3.now());
                                                          ^
/Users/william/ros2_ws/src/ros2/demos/demo_nodes_cpp/src/topics/talker.cpp:37:64: error: cannot pass object of non-trivial type 'rclcpp::Time' through variadic function; call will abort at runtime
      [-Wnon-pod-varargs]
        RCLCPP_INFO(this->get_logger(), "this->now time: %ld", this->now());
                                                               ^
3 errors generated.

So I think that might be the real problem. ->now() returns a Time object, so this is what I used:

    RCLCPP_INFO(this->get_logger(), "this->now time:  %zu", this->now().nanoseconds());
    std::chrono::nanoseconds now = std::chrono::system_clock::now().time_since_epoch();
    RCLCPP_INFO(this->get_logger(), "CONTACT!!! time: %zu", now.count());

And with that I get this:

% ~/ros2_ws/install_debug/lib/demo_nodes_cpp/talker
spin[INFO] [test_io]: this->now time:  1523484085024108218
[INFO] [test_io]: CONTACT!!! time: 1523484085024181000
[INFO] [test_io]: this->now time:  1523484086027860553
[INFO] [test_io]: CONTACT!!! time: 1523484086027899000
[INFO] [test_io]: this->now time:  1523484087032300023
[INFO] [test_io]: CONTACT!!! time: 1523484087032338000
[INFO] [test_io]: this->now time:  1523484088038859851
[INFO] [test_io]: CONTACT!!! time: 1523484088038897000
[INFO] [test_io]: this->now time:  1523484089039952856
[INFO] [test_io]: CONTACT!!! time: 1523484089039987000
[INFO] [test_io]: this->now time:  1523484090044948563
[INFO] [test_io]: CONTACT!!! time: 1523484090044988000
[INFO] [test_io]: this->now time:  1523484091047517423
[INFO] [test_io]: CONTACT!!! time: 1523484091047562000
[INFO] [test_io]: this->now time:  1523484092048706228
[INFO] [test_io]: CONTACT!!! time: 1523484092048766000
[INFO] [test_io]: this->now time:  1523484093047516655
[INFO] [test_io]: CONTACT!!! time: 1523484093047548000
^Csignal_handler(2)
stopNode shutting down, reset all GPIOs%

Which looks ok to me. Maybe the issue was just how you were printing it?