ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
19

Is there a C++ API for a dynamic reconfigure client?

asked 2011-12-08 10:19:10 -0600

Thomas D gravatar image

updated 2014-01-28 17:10:57 -0600

ngrennan gravatar image

Is there a C++ API that I can use from within a C++ node that will create a dynamic reconfigure client? I would like my node to be able to modify some of the base_local_planner parameters, such as the min/max velocities, during run time.

I have looked at the dynamic_reconfigure wiki and the client API pages and I only see a way to use a Python client node to update variables on a dynamic reconfigure server.

edit retag flag offensive close merge delete

Comments

I'm looking for this, too and till today did not find anything. :(
Achim gravatar image Achim  ( 2012-01-05 22:51:18 -0600 )edit

Just came across the same problem. The use a dynamic_reconfigure server in TrajectoryPlannerROS, but according to the wiki there still is no C++ api. Or has anyone found out if there is a (hidden) C++ api that can make a client?

Kai Bublitz gravatar image Kai Bublitz  ( 2012-03-08 02:39:58 -0600 )edit

fivef's answer is great! Just as a follow up, someone was inspired by fivef's answer and posted a more detailed example here

RicoJ gravatar image RicoJ  ( 2020-09-02 15:31:19 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2019-05-09 15:07:07 -0600

gillamkid gravatar image

Looks like someone added a C++ API in June 2016. I'm not sure how to use it or how it compares in performance to the python Client, but you can see the commit details here https://github.com/ros/dynamic_reconf... .

edit flag offensive delete link more

Comments

I made this as the selected answer as this refers to the official api for Kinetic onward.

130s gravatar image 130s  ( 2021-05-25 20:01:57 -0600 )edit
34

answered 2013-05-31 02:02:40 -0600

fivef gravatar image

I had quite a hard time implementing this. So here my example:

/joint_commander is the node the dynamic_reconfigure server runs in.

Includes:

#include <dynamic_reconfigure/DoubleParameter.h>
#include <dynamic_reconfigure/Reconfigure.h>
#include <dynamic_reconfigure/Config.h>

In your function:

dynamic_reconfigure::ReconfigureRequest srv_req;
dynamic_reconfigure::ReconfigureResponse srv_resp;
dynamic_reconfigure::DoubleParameter double_param;
dynamic_reconfigure::Config conf;

double_param.name = "kurtana_pitch_joint";
double_param.value = pitch;
conf.doubles.push_back(double_param);

double_param.name = "kurtana_roll_joint";
double_param.value = yaw;
conf.doubles.push_back(double_param);

srv_req.config = conf;

ros::service::call("/joint_commander/set_parameters", srv_req, srv_resp);
edit flag offensive delete link more

Comments

This worked flawlessly, thanks so much!

Dave Coleman gravatar image Dave Coleman  ( 2013-09-19 15:35:59 -0600 )edit

I tried to implement this in the same node that was providing the dynamic reconfigure service, and it blocks forever in the default setup which only has one thread- the solution is to use an AsyncSpinner with at least two threads, and wrap critical stuff in mutex locks.

lucasw gravatar image lucasw  ( 2015-07-08 10:41:26 -0600 )edit

Do you have some examples of that?

postal gravatar image postal  ( 2016-03-15 10:17:18 -0600 )edit
1

No public examples, but I implemented a server along the lines of http://wiki.ros.org/dynamic_reconfigu... and then adapted the above code, and then instead of ros::spin() I did ros::AsyncSpinner spinner(1); spinner.start();

lucasw gravatar image lucasw  ( 2016-03-15 19:58:08 -0600 )edit

Though I'm not sure why I didn't do spinner(2) for two threads, and why there wasn't a waitForShutdown() as in http://wiki.ros.org/roscpp/Overview/C... - I'm looking at code that is ifdeffed out, unfortunately.

lucasw gravatar image lucasw  ( 2016-03-15 19:59:25 -0600 )edit

In my case, when I adjust that code, my dynamic reconfigure was died.... everyone is working well?

Sam lee gravatar image Sam lee  ( 2017-12-06 21:03:27 -0600 )edit

So it can't be called from callback?

achmad_fathoni gravatar image achmad_fathoni  ( 2018-09-22 18:21:06 -0600 )edit

This worked for me on JADE with 14.04 LTS to configure RASPICAM node. Used from within a private class function (called from with a callback)

If fivef is still around, Thank you!

billy gravatar image billy  ( 2019-03-09 21:50:47 -0600 )edit

Question Tools

8 followers

Stats

Asked: 2011-12-08 10:19:10 -0600

Seen: 12,965 times

Last updated: Sep 02 '20