Ask Your Question
3

How to setParam xmlrpc value struct with C++ ?

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

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

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:

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

Comments

1

(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 imagegvdhoorn ( 2017-01-19 06:48:30 -0500 )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 imagesuforeman ( 2017-01-19 08:00:02 -0500 )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 imageyueweiliang ( 2019-06-22 08:12:16 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

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

Tran Minh Hoang gravatar image

I found a way:

XmlRpc::XmlRpcValue a;
a.setSize(2);
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
0

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

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;
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.

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

2 followers

Stats

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

Seen: 427 times

Last updated: Jun 22