I have encountered the exact same problem today and the solution was not a straightforward one. Unfortunately XmlRpc API does not have a dedicated method for the custom structs. Therefore, you need to write your own function that validly constructs an XML from your struct.
Following code constructs a valid portion of your yaml file which affects the parameter server in the exact same manner as yaml file would.
const string init_value = "<value>";
const string end_value = "</value>";
const string init_struct = "<struct>";
const string end_struct = "</struct>";
There are also <data>
, <array>
and <member>
tags. They should be defined as above. Then for only the mode
part:
XmlRpc::XmlRpcValue drive_config;
string xml_body;
xml_body.append(init_value);
xml_body.append(init_struct);
xml_body.append(init_member);
xml_body.append("<name>mode</name>");
xml_body.append(init_value);
xml_body.append("mecanum");
xml_body.append(end_value);
xml_body.append(end_member);
xml_body.append(end_struct);
xml_body.append(end_value);
int offset = 0;
int* offset_ptr = &offset;
drive_config.fromXml(xml_body,offset_ptr);
nh.setParam("/drive_config",drive_config);
Above lines will upload a parameter to ROS Parameter Server in the form of:
drive_config:
mode: mecanum
Above code can be optimized, automated and shortened with struct tag retrievals, type resolvers and recursive calls. But for the current task, naïve implementation would suffice.
I recommend first printing the raw XML format of a known parameter uploaded through YAML file. Then, it will be easier to construct arrays of arrays, arrays of dicts, dicts of arrays and etc.
select the text, press
ctrl+k
or click the Preformatted Text button (the one with101010
on it).re: (I'll edit this again once I figure out how to include formatted code)
I was on a mobile device. The 101010 button did not do it correctly. Thanks for fixing my question.
is there any easy to set the .xml file to rosserver??? Must I re-write the contents of my .yaml in c++ code to build the xmlrpc as above??? xmlrpc can not load .xml or .yaml directly?