[Documentation] [TitleIndex] [WordIndex

rosjava offers full access to the ROS Parameter server. The Parameter server is a shared dictionary of configuration parameters accessible to all the nodes at runtime. It is meant to store configuration parameters that are easy to inspect and modify.

The parameter are accessible via ParameterTrees which are provided by Nodes.

   1 ParameterTree params = node.newParameterTree();
   2 

Accessing Parameters

The ParameterTree API allows you to set and query lists, maps, and single objects of integers, strings and floats.

Unlike typical ROS client libraries, rosjava requires that the type of the parameter be known when you retrieve it. If the actual parameter type doesn't match the expected type, an exception will be thrown.

   1   boolean foo = params.getBoolean("/foo");
   2   int bar = params.getInteger("/bar", 42 /* default value */);
   3   double baz = params.getDouble("/foo/baz");
   4 
   5   params.set("/bloop", "Hello, world!");
   6   String helloWorld = params.getString("/bloop");
   7 
   8   List<Integer> numbers = params.getList("/numbers");
   9   Map<String, String> strings = params.getMap("/strings");
  10 

As with other ROS client libraries, it is possible to retrieve a subtree of parameters. However, you will be responsible for casting the values to their appropriate types.

   1   Map<String, Object> subtree = params.getMap("/subtree");
   2 

ParameterListener

It is also possible to subscribe to a particular parameter using a ParameterListener. Note that this does not work for parameter subtrees.

   1 params.addParameterListener("/foo/bar", new ParameterListener() {
   2   @Override
   3   public void onNewValue(Object value) {
   4     ...
   5   }
   6 });
   7 

Currently, ParameterListeners are not generic. Instead, you are responsible for casting value appropriately.


2011-11-19 12:34