24 CODE_TEMPLATE =
'''// This file is AUTOGENERATED CODE produced by generate_nerian_config_cpp.py 27 #include <dynamic_reconfigure/server.h> 28 #include <nerian_stereo/NerianStereoConfig.h> 29 #include <visiontransfer/deviceparameters.h> 31 #include "nerian_stereo_node_base.h" 33 using namespace visiontransfer; 35 namespace nerian_stereo { 37 // Callback that receives an updated config from ROS 38 void StereoNodeBase::autogen_dynamicReconfigureCallback(nerian_stereo::NerianStereoConfig &config, uint32_t level) { 40 // == START of autogenerated parameter blocks == 42 // == END of autogenerated parameter blocks == 45 // Obtain current parameter values from device and copy them to parameter server 46 void StereoNodeBase::autogen_updateParameterServerFromDevice(std::map<std::string, ParameterInfo>& cfg) { 47 ROS_INFO("Setting initial parameters in the parameter server"); 48 std::string node_name = ros::this_node::getName(); 49 // Publish reboot flag to definitely be set to false in the parameter server 50 getNH().setParam(node_name + "/reboot", false); 51 // Publish the current config to the parameter server 52 // == START of autogenerated parameter blocks == 54 // == END of autogenerated parameter blocks == 57 // Override the default parameter bounds with current (run-time) config 58 void StereoNodeBase::autogen_updateDynamicReconfigureFromDevice(std::map<std::string, ParameterInfo>& cfg) { 59 nerian_stereo::NerianStereoConfig config_default, config_min, config_max; 60 ROS_INFO("Updating dynamic_reconfigure defaults and limits"); 61 // Set defaults and min/max values according to Nerian stereo device API 62 // == START of autogenerated parameter blocks == 65 // == END of autogenerated parameter blocks == 67 dynReconfServer->setConfigMin(config_min); 68 dynReconfServer->setConfigMax(config_max); 69 dynReconfServer->setConfigDefault(config_default); 75 TEMPLATE_PARAMETER_CHANGE =
''' if (config.{varname} != lastKnownConfig.{varname}) {{ 76 ROS_INFO("Request to set {varname} = %s", std::to_string(config.{varname}).c_str()); 77 deviceParameters->setNamedParameter("{varname}", config.{varname}); 80 TEMPLATE_SETPARAM =
''' getNH().setParam(node_name + "/{varname}", cfg["{varname}"].getValue<{typ}>());''' 82 TEMPLATE_SETDEFAULTS =
''' 83 config_default.{varname} = cfg["{varname}"].getValue<{typ}>(); 84 config_min.{varname} = cfg["{varname}"].getMin<{typ}>(); 85 config_max.{varname} = cfg["{varname}"].getMax<{typ}>();''' 88 if __name__ ==
'__main__':
92 if len(sys.argv) >= 3:
93 infile = open(sys.argv[1],
'r') 94 outfile = open(sys.argv[2], 'w')
97 varnames_and_types = []
98 for line
in infile.readlines():
99 if line.startswith(
'gen.add('):
100 varname = line.split(
'"')[1]
101 typ = line.split(
',')[1].strip().split(
'_')[0]
102 varnames_and_types.append([varname, typ])
105 paramchange =
'\n'.join(TEMPLATE_PARAMETER_CHANGE.format(varname=vt[0])
for vt
in varnames_and_types)
106 setparam =
'\n'.join(TEMPLATE_SETPARAM.format(varname=vt[0], typ=vt[1])
for vt
in varnames_and_types
if vt[0] !=
'reboot')
107 setdefaults =
'\n'.join(TEMPLATE_SETDEFAULTS.format(varname=vt[0], typ=vt[1])
for vt
in varnames_and_types
if vt[0] !=
'reboot')
108 outfile.write(CODE_TEMPLATE % (paramchange, setparam, setdefaults))