What's the best way to publish dynamic parameters to a topic when they change?
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
}
Do you want to publish only if the parameter changes?
Yes. Please see my updated question details.