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

Cannot use ros::Time::now() before the first NodeHandle has been created or ros::start() has been called. If this is a standalone app or test that just uses ros::Time and does not communicate over ROS, you may also call ros::Time::init()

I hate it when I get these kind of answers, but in this case I think the exception is actually pretty verbose and points you to your issue: you need to create a ros::NodeHandle instance before using any of ros::Rate, ros::ok() or ros::spinOnce(), or manually call ros::start() (but I doubt that is a recommended use of that API).

If you do not want a NodeHandle, you could (as the message tells you) also directly call ros::Time::init().

See also the Writing a Simple Publisher and Subscriber (C++) tutorial.