ros2 parameter listener/callback
Greetings fellow developers, I have recently started to work with ros2 eloquent and came across few issues I need some help for.
This question however may not be ros2 specific but rather a general ros question. I have created a publisher node in cpp where I set several parameter using a .yaml file. Is there any type of built in ros method to trigger an event when a parameter is changed ? I do not want to change the .yaml file itself but rather change the parameter while the node is running i.e. using ros2 param set.
Suppose one parameter is "log=true" by default and whenever this is changed (for example to "log=false") I want to call a print function to display "changed: log = 10". Obviously I could do that in cpp implementing a listener function myself. However I am wondering if ros2 has some built in tools to do that.
I would really appreaciate your help since I did not find something like that reading the documentation.
Asked by protoGuy on 2020-09-16 08:40:25 UTC
Answers
Yes there is, it's called on_parameter_event. Example can be found in ros2 demos - https://github.com/ros2/demos/blob/master/demo_nodes_cpp/src/parameters/parameter_events.cpp.
Asked by aarushg on 2020-09-16 23:50:54 UTC
Comments