What's the best practice to pre-process parameter file

asked 2020-06-20 11:24:10 -0500

Ekaradon gravatar image

updated 2020-06-20 11:25:08 -0500

I have a parameter yaml file, some of these parameters are easy to be read by human, but need some transformation to be used by ROS nodes.

For example, in yaml file I have

# ID of this robot
this_id: 3

but all of my ROS nodes does not directly use the id 3, instead they use 1 << (3-1) = 0b00000100 = 4 (i.e. the robot #n is actually represented as 1 << (n-1) in my program. Directly writing this_id: <1 << (n-1)> in yaml file will be confusing, and not friendly for human beings. So I have to do this every time I use the parameter:

uint8_t this_id;
nh.getParam("this_id", this_id);
this_id = 1 << (this_id - 1);           // I have to do this converting in every nodes

This is just an example, and sometimes I have to do much more complex converting.

My question is, is there any better method to do this converting or parameter pre-processing? So that I can have numbers 3 friendly for human beings, while having easy access to things like 0b00000100 which is actually used in my nodes, and avoid do manually converting in every node.

edit retag flag offensive close merge delete