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

Set parameter list using XmlRpc

asked 2013-02-15 01:37:16 -0600

I.T gravatar image

updated 2014-01-28 17:15:16 -0600

ngrennan gravatar image

Hi,

I need to set some ros parameters where one of them is a list of strings. I'm using C++ but cannot find an example of how to do it.

I currently have a list std::vector<std::string> which I want to set in the ros parameter server.

From here http://www.ros.org/wiki/roscpp/Overview/Parameter%20Server I understand I need to use XmlRpc::XmlRpcValue to set the array.

So far I have tried:

//agent_names is a populated std::vector of std::string

XmlRpc::XmlRpcValue vocabulary(agent_names);

n.setParam("vocabulary", vocabulary);

But it doesn't compile.

How do I construct an XmlRpcValue object from a std::vector?

Also, do I need to link to the XmlRpc library in my CMakeLists.txt and then import headers in my code? In that case, what do I put in my CMakeLists.txt?

Any help is greatly appreciated =)

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2013-02-20 00:23:31 -0600

I.T gravatar image

updated 2016-09-12 13:42:43 -0600

I finally ended up setting the parameter by using a launch file for my node.

Example:

Launch file:

<launch>
    <rosparam param="x_vector">[1.0, 2.0,
3.0]</rosparam>
    <node name="my_node" pkg="my_package" type="my_node" />
</launch>

Then in your node, get the vector like this:

std::vector<double> x_vec;
std::vector<double> x_vec_default = {1.0, 0.5, 0.5, 1.0};

n.param<std::vector<double> >("x_vector", x_vec, x_vec_default);

And x_vec will hold the values given in the launch file, or the contents in x_vec_default if the x_vector is not available as a parameter (for example if launching the node without the launch file).

edit flag offensive delete link more

Comments

How do you set a vector parameter in launch file ?

ROSfc gravatar image ROSfc  ( 2016-09-02 03:48:08 -0600 )edit
1

@ROSfc See my updated answer. Sorry for late reply!

I.T gravatar image I.T  ( 2016-09-12 13:43:15 -0600 )edit
0

answered 2013-02-18 00:38:50 -0600

dberm22 gravatar image

updated 2013-02-18 01:54:49 -0600

dornhege gravatar image

I am trying to do this also, although I'm using Java instead of C++. Here is my post, complete with code:

http://answers.ros.org/question/55103/rosjava-get-list-of-parameters/

(sorry, I am too new to post links)

It's not working just yet, but it may help you a bit ... hopefully. What is "n" in your code? is it a node handle?

ros::NodeHandle n;

Also, check out this question, especially the first link in the question:

http://answers.ros.org/question/12329/how-to-convert-xmlrpcxmlrpcvalue-into-string/

edit flag offensive delete link more
0

answered 2013-02-18 01:04:13 -0600

dornhege gravatar image

updated 2013-02-18 01:06:47 -0600

I think you're out of luck for a simple/nice way.

The only interface I can see for that is the constructor using an XML description, which is somewhat awkward, but should do what you want.

The XmlRpcValue.h usually lies in the root include dir of the ROS install.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-15 01:37:16 -0600

Seen: 3,208 times

Last updated: Sep 12 '16