Ask Your Question
1

What's the best way to publish dynamic parameters to a topic when they change?

asked 2018-01-26 14:56:31 -0600

somudrog gravatar image

updated 2018-01-29 18:29:14 -0600

I'd like to publish dynamic parameters (from dynamic_reconfigure) to a topic from a C++ node when they change, for the purpose of recording parameter changes in a bag file. In Python, I just convert the dynamic parameters object to a string and publish it in the dynamic parameters callback. What's the best way to do something similar in C++, without having to manually copy each field of the param struct into a string?

Python:

def update_dynamic_params(self, dynamic_params, _level):
    # this always works and I don't have to change the code when the cfg file changes
    self.param_pub.publish(str(dynamic_params))

C++:

void MyNode::updateDynamicParams(const MyConfig& dynamic_params, uint32_t level)
{
  // I'd like to avoid manually copying each field of MyConfig struct into a string, especially because I'd have to update it each time the cfg file changes
}
edit retag flag offensive close merge delete

Comments

Do you want to publish only if the parameter changes?

mohsen gravatar image mohsen  ( 2018-01-29 15:47:14 -0600 )edit

Yes. Please see my updated question details.

somudrog gravatar image somudrog  ( 2018-01-29 17:16:01 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2018-01-29 17:48:35 -0600

prem gravatar image

There are two topics /node_name/parameter_descriptions and /node_name/parameter_updates that are published when you run a dynamic reconfigure server. The latter publishes the parameters whenever you update them - which is what you need.

edit flag offensive delete link more
0

answered 2018-01-29 10:21:18 -0600

C++ can do all Python can do. Numbers may be published in ROS as well as strings. Conversion may not be needed. Many different types of variables may be used. Your publishing rate may be fast or slow- you determine that. If the number changes each time it's published, that's not a problem.

edit flag offensive delete link more

Comments

Thanks for your answer. Please see my updated question with the detail of what I'm trying to do.

somudrog gravatar image somudrog  ( 2018-01-29 17:15:37 -0600 )edit

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: 2018-01-26 14:56:31 -0600

Seen: 814 times

Last updated: Jan 29 '18