Ask Your Question

Redeclare loop_rate depending on boolean

asked 2016-02-14 12:33:11 -0500

user23fj239 gravatar image

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

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-14 12:45:58 -0500

user23fj239 gravatar image

I had to move on out of the if and redeclare by loop_rate(double frequency), but with ros::Rate in front:

    ros::Rate loop_rate(rate_eff[type-1]/2+1);
    if(use_def) ros::Rate loop_rate(100);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-14 12:33:11 -0500

Seen: 63 times

Last updated: Feb 14 '16