[ros-users] lists on the parameter server

Jeremy Leibs leibs at willowgarage.com
Mon May 31 15:02:51 UTC 2010


On Mon, May 31, 2010 at 7:37 AM, Armin Hornung
<HornungA at informatik.uni-freiburg.de> wrote:

> Is there any documentation available on how to retrieve these lists in
> roscpp?
> http://www.ros.org/wiki/roscpp/Overview/Parameter%20Server points to
> http://xmlrpcpp.sourceforge.net/doc/classXmlRpc_1_1XmlRpcValue.html for
> lists, but a quick example (or a pointer to how it is used in another
> ROS node) would be nice to get started.
>

The XmlRpcValue type implements the reinterpret cast operator for most
types.  Unfortunately, almost all but the most explicit usages are
ambiguously defined, so you often need to be explicit.  But, generally
speaking, it means you can just treat the XmlRpcValue object as the
type you want it to be.  In this case, assuming the XmlRpcValue is a
list, then you can simply use operator[] to access members, and then
cast them as the appropriate type.  The following example retrieves a
list of doubles from the param server and sums them:


#include <iostream>
#include "ros/ros.h"

int main(int argc, char** argv)
{
  ros::init(argc, argv, "my_node");
  ros::NodeHandle nh;

  XmlRpc::XmlRpcValue x;

  nh.getParam("my_list", x);

  assert(x.getType() == XmlRpc::XmlRpcValue::TypeArray);

  double sum = 0.0;
  for (int i = 0; i < x.size(); i++)
  {
    sum += (double)(x[i]);
  }

}



More information about the ros-users mailing list