ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.