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>
30 #include <visiontransfer/parameterset.h>
32 #include "nerian_stereo_node_base.h"
34 using namespace visiontransfer;
36 namespace nerian_stereo {
38 // Callback that receives an updated config from ROS
39 void StereoNodeBase::autogen_dynamicReconfigureCallback(nerian_stereo::NerianStereoConfig &config, uint32_t level) {
41 // == START of autogenerated parameter blocks ==
43 // == END of autogenerated parameter blocks ==
46 // Obtain current parameter values from device and copy them to parameter server
47 void StereoNodeBase::autogen_updateParameterServerFromDevice(param::ParameterSet& cfg) {
48 ROS_INFO("Setting initial parameters in the parameter server");
49 std::string node_name = ros::this_node::getName();
50 // Publish reboot flag to definitely be set to false in the parameter server
51 getNH().setParam(node_name + "/reboot", false);
52 // Publish the current config to the parameter server
53 // == START of autogenerated parameter blocks ==
55 // == END of autogenerated parameter blocks ==
58 // Override the default parameter bounds with current (run-time) config
59 void StereoNodeBase::autogen_updateDynamicReconfigureFromDevice(param::ParameterSet& cfg) {
60 nerian_stereo::NerianStereoConfig config_default, config_min, config_max;
61 ROS_INFO("Updating dynamic_reconfigure defaults and limits");
62 // Set defaults and min/max values according to Nerian stereo device API
63 // == START of autogenerated parameter blocks ==
66 // == END of autogenerated parameter blocks ==
68 dynReconfServer->setConfigMin(config_min);
69 dynReconfServer->setConfigMax(config_max);
70 dynReconfServer->setConfigDefault(config_default);
76 TEMPLATE_PARAMETER_CHANGE =
''' if (config.{varname} != lastKnownConfig.{varname}) {{
77 ROS_INFO("Request to set {varname} = %s", std::to_string(config.{varname}).c_str());
78 deviceParameters->setParameter("{varname}", config.{varname});
81 TEMPLATE_SETPARAM =
''' getNH().setParam(node_name + "/{varname}", cfg.get("{varname}").getCurrent<{typ}>());'''
83 TEMPLATE_SETDEFAULTS =
'''
84 config_default.{varname} = cfg.get("{varname}").getCurrent<{typ}>();
85 config_min.{varname} = cfg.get("{varname}").getMin<{typ}>();
86 config_max.{varname} = cfg.get("{varname}").getMax<{typ}>();'''
89 if __name__ ==
'__main__':
93 if len(sys.argv) >= 3:
94 infile = open(sys.argv[1],
'r')
95 outfile = open(sys.argv[2],
'w')
98 varnames_and_types = []
99 for line
in infile.readlines():
100 if line.startswith(
'gen.add('):
101 varname = line.split(
'"')[1]
102 typ = line.split(
',')[1].strip().split(
'_')[0]
103 varnames_and_types.append([varname, typ])
106 paramchange =
'\n'.join(TEMPLATE_PARAMETER_CHANGE.format(varname=vt[0])
for vt
in varnames_and_types)
107 setparam =
'\n'.join(TEMPLATE_SETPARAM.format(varname=vt[0], typ=vt[1])
for vt
in varnames_and_types
if vt[0] !=
'reboot')
108 setdefaults =
'\n'.join(TEMPLATE_SETDEFAULTS.format(varname=vt[0], typ=vt[1])
for vt
in varnames_and_types
if vt[0] !=
'reboot')
109 outfile.write(CODE_TEMPLATE % (paramchange, setparam, setdefaults))