Ask Your Question
0

error: ‘loop_rate’ was not declared in this scope

asked 2019-12-31 07:03:40 -0500

In my launch file I have a global variable

<param name = "rateFilterUWB" type="int" value="10" />

and I'm trying to reach this variable's value in my C++ code

    int rateFilterUWB;

if (ros::param::has("/rateFilterUWB")) {
    ros::param::get("/rateFilterUWB", rateFilterUWB);
    ros::Rate loop_rate(rateFilterUWB);
}
else
ros::Rate loop_rate(100);

But I have an error during compilation:

 error: ‘loop_rate’ was not declared in this scope

PS I'm running Linux raspberrypi 4.19.30-v7+

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-12-31 10:17:11 -0500

allenh1 gravatar image

updated 2019-12-31 10:17:47 -0500

if (ros::param::has("/rateFilterUWB")) { ros::param::get("/rateFilterUWB", rateFilterUWB); ros::Rate loop_rate(rateFilterUWB); } else ros::Rate loop_rate(100);

Your issue is right here -- you have scoped the definition of the loop_rate variable.

You could use a default value parameter to fix this.

double rate;
ros::param::param<double>("/rateFilterUWB", rate, 100);

See here for more information.

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

Stats

Asked: 2019-12-31 07:03:40 -0500

Seen: 579 times

Last updated: Dec 31 '19