How can I use the 'level' in dynamic_reconfigure [closed]
The callback gives me two params, the config
and the uint32_t level
, I guess that the level reflect which params has been changed, but how can I use the number search the Corresponding parameters in the config using C++, except writing codes likeswitch(level)
{
case 1:...
}
.Does there any method like using config.param_level
? (Maybe what I described is not very clear, I hope you can understand what I mean)
Hi @Laura, interesting question. After digging a little, I found this prior answer and discussion: https://answers.ros.org/question/2101...
The
level
parameter is a bit mask, so one way to find what values are set to 1, you could use and bitwise operations instead.@osilva Thank you very much for your answer. I also saw the previous post before this question. However, I don't quite understand the explanation of "level is a bit mask". Could you please explain it in detail? When I created the .cfg file, I use code like
gen.add(name, level, default, min, max)
, for example I set level=11, and i found the callback gives me the level=11 when I changed the corresponding parameter, but how to consider the level from the view "level is a bit mask"?A bit mask is basically a binary representation using 1s and 0s as switch values like
ON
andOFF
. So for example if you have a byte(8bits) 0000 0000, you will say all your 8 bits of the byte are set to 0 orOFF
. If you perform and OR operation between bytes, only those bits that are different will set to 1, thus is a quick way to find out what has changed instead of checking each parameter. For more information on bitwise operations: https://www.clivemaxfield.com/masking...Below an explanation from
https://answers.ros.org/answers/34131...
Thank you very much, @osilva, but I found ,for example, using code like
gen.add("a", level=4, default, min, max)
, when I changed parameter "a" in rqt_reconfigure, I expected the callback gives me level=0x00000010 (Hexadecimal), which is equal to 16 (Decimal), because I think it will changed the 4th bit in the level (total 32 bits), but actually it gives me the level = 4 (Decimal).Did the system automatically help me perform the bit operation process?I think is even more basic when you take a look at the source code:
https://github.com/ros/dynamic_reconf...
So yes it’s parsing and returning the level value
Thank you for trying to fully understand. I believe it will be good for you to document as an answer as prior answers does not go to this level of detail
@osilva,Thank you very much for your patient answers, by viewing the source code I now fully understand how it works. Thank you again for taking such a long time to answer my confusion!