Ask Your Question

How to setParam xmlrpc value struct with C++ ?

asked 2017-01-19 05:35:35 -0600

updated 2017-01-19 08:00:11 -0600

I have getParam() working. The initial data is loaded from a configuration yaml from my launch file.

I am trying to figure out how to write a C++ structure out using setParam() to update the same data.

What do I create in C++ in order to call setParam() and store the data in the parameter server?

Here is an example of the yaml:

  mode: mecanum
  radius: 0.062
  rpm: 60.0
  scale: 1.0
  track: 0.2
    - {servo: 1, position: 1}
    - {servo: 2, position: 2}
    - {servo: 3, position: 3}
    - {servo: 4, position: 4}
edit retag flag offensive close merge delete



(I'll edit this again once I figure out how to include formatted code)

select the text, press ctrl+k or click the Preformatted Text button (the one with 101010 on it).

gvdhoorn gravatar image gvdhoorn  ( 2017-01-19 06:48:30 -0600 )edit

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.

suforeman gravatar image suforeman  ( 2017-01-19 08:00:02 -0600 )edit

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?

yueweiliang gravatar image yueweiliang  ( 2019-06-22 08:12:16 -0600 )edit

2 Answers

Sort by » oldest newest most voted

answered 2018-09-28 13:48:58 -0600

tahsinkose gravatar image

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;

int offset = 0;
int* offset_ptr = &offset;

Above lines will upload a parameter to ROS Parameter Server in the form of:

    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.

edit flag offensive delete link more

answered 2019-04-24 01:42:21 -0600

mihota gravatar image

I found a way:

XmlRpc::XmlRpcValue a;
a[0] = 0;
a[1] = 1;
ros::param::set("param_name", a);

Just keep nesting this and you can set any parameter structure you want.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-01-19 05:35:35 -0600

Seen: 686 times

Last updated: Jun 22 '19