Code Generation for Parameter Handling Similar to Message Generation

I have been working on a project to automate the boil plate code for parameter handling. This is especially tedious in creating new ROS 2 controllers, since they use so many parameters. My approach is consider the yaml file typically used to assign parameters the definition of a parameter struct. Given a yaml parameter file, I can generate a header file containing a struct with all parameters and automatic callbacks for updating. Another benefit is that errors in the yaml file are caught at compile time instead of runtime. My code generation script in embedded in the build script for a colcon package, so all you have to do is find the package and call a cmake function. Take a look at my repository if you are interested. I appreciate feedback and recommendations on how to improve my package.

1 Like

Agree that it’s very useful to have a single source of truth for parameters. I have previously dealt with it in the reverse direction (starting with a struct), but I like your approach too.

1 Like

Yes, exactly! Source of truth is the right way to phrase it. Unlike ROS messages, there often is not central definition for parameters, so lots of assumptions need to be made, leading to runtime errors.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.