Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Redeclare loop_rate depending on boolean

Given this example, in which I want to decide via if which loop_rate to use when spinning

      if(my_bool)  ros::Rate loop_rate(100); //Hz
      else ros::Rate loop_rate(10);

   //thread safe regular mutex spin
    mtx_spin.lock();
    ros::spinOnce();
    mtx_spin.unlock();
    loop_rate.sleep();

The compiler complains about rate not declared, as it is out of scope. But I need the if to decide which rate to get.