Should ros::Rate() run after Creating NodeHandle()?
I'm trying to encapsulate my node inside a class so I can later on use mutli-threading but I've noticed this issue which is if ros::Rate is instantiated before instantiating NodeHandle() as follows:
ros::init(...)
m_rate = new ros::Rate(10);
m_nh = new ros::NodeHandle();
I get this error
terminate called after thrwoing an instance of 'ros::TimeNotInitializedException'
But if I do the vise versa, the code runs fine as shown below
ros::init(...)
m_nh = new ros::NodeHandle();
m_rate = new ros::Rate(10);
What is internally inside ros::Rate that may cause this problem?
Duplicated question, see answer here.
Do you where in the documentation this stated?
The
ros::Rate
constructor initializes a private member variablestart_
withTime::now()
, see here. TheTime::now()
function requires that the time has been initialize (stored in the globalg_initialized
variable). If it has NOT been initializedTimeNotInitializedException
gets thrown. If you want to useros::Time
orros::Rate
before a node handle is create you can callros::Time::init()
after initializing your node.@danambrosio, thank you.