Access dynamic_reconfigure levels from C++ code

asked 2019-02-27 05:15:41 -0500

ffusco gravatar image

updated 2019-02-27 14:57:17 -0500

Hello, I am playing with dynamic_reconfigure and I was wandering how to properly get the level associated to a specific parameter.

Say my configuration is something like:

...
gen = ParameterGenerator()
gen.add("foo", int_t, 1, "Param 1", 0, 0, 10)
gen.add("bar", int_t, 2, "Param 2", 0, -10, 10)
...

Then, in my reconfigure callback, I would like to do something only if a specific parameter changed, eg:

void callback(pkg::ExampleConfig& conf, uint32_t level)
{
  // if foo has been updated, do something terrible
  if(level & 1)
    startArmageddon();
}

My concern is that the level of foo might be changed later, and therefore the code above is not quite robust since I manually wrote the 1 in the condition if(level & 1). I tried to inspect a little the code generated for the Config class, and the only solution I came up with is to manually build a dictionary { param_name : level } at startup, eg:

map<string,uint32_t> lvls;

int main()
{
  ...
  auto p = pkg::ExampleConfig::__getParamDescriptions__();
  for(const auto& param : p)
    lvls[p->name] = p->level;
  ...
}

void callback(...)
{
  // if foo has been updated, do something terrible
  if(level & lvls.at("foo"))
    startArmageddon();
}

It seems better in my opinion, but I have to generate the dictionary and rely on the name of the parameter... So after this long explanation: does anyone know a better way to use get the levels declared in the Config file?

Thanks in advance!

edit retag flag offensive close merge delete