cbandera / rosparam_handler

An easy wrapper for using parameters in ROS
Other
47 stars 26 forks source link

Add custom types #61

Open ahoarau opened 6 years ago

ahoarau commented 6 years ago

That would really awesome if we could have something like this :


# gen.addcustomType(type,class_name,lambda);

gen = ParameterGenerator()
gen.addCustomType("std::vector<double>","Eigen::VectorXd",Array,"[](std::vector<double> array){ return Eigen::Map<Eigen::VectorXd>(array.data(),array.size());  }")

That would generate something like :

Eigen::VectorXd __param_name;
std::function<Eigen::VectorXd(std::vector<double>)> array_to__param_name = [](std::vector<double> array){ return Eigen::Map<Eigen::VectorXd>(array.data(),array.size());  };

void fromYaml()
{
    // load the array as usual
  __param_name = array_to__param_name(   array_from_yaml);
}
ahoarau commented 6 years ago

The std::vector<double> could even be hidden in gen.addArrayType to be able to transform to geometry_msgs, tf msgs, eigen, etc.

artivis commented 6 years ago

Hi, this is an interesting idea ! Adding support for Eigen is on the todo list since a while (something similar to rosparam_shortcuts) however I couldn't get started due to a lack of time. Your proposal (use of a lambdas) is interesting in that it generalizes well, however I'm concerned by the implications in terms of dependencies (missing includes etc) that it adds. Maybe you could propose some proof-of-concept implementation so that we can discuss it further and see how rosparam_handler could be made even more generic ! Cheers.

ahoarau commented 6 years ago

Includes could be added as an extra argument (easy), but you should make sure to link against the said library. Making sure this happens is much more difficult. Maybe out of scope as well.

artivis commented 6 years ago

You are right, although Eigen being template only, this particular dependency could be handled similarly to what's already done with dynamic_reconfigure (see e.g. here or there).