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

How to send parameters in the method onStart with ROSJava

asked 2012-01-15 09:15:24 -0500

In every example in the ROSJava tutorial, the method: onStart has a unique parameter: (final Node node) and my question is how to send additional parameters in this method.

When I execute any node, I type in the shell:

rosrun rosjava_bootstrap run.py nxt_lejos_ros org.lejos.ros.nodes.loader.NXTLoader __name:=NXTLoader

or I use a .launch file with the following structure:

<launch>
    <node pkg="rosjava_bootstrap" 
    type="run.py" 
    args="nxt_lejos_ros org.lejos.ros.nodes.loader.NXTLoader" 
    name="NXTLoader" 
    output="screen" />     
</launch>

But my idea, is to send to the node another parameter, for example a YAML file.

How to define in a .launch code an aditional parameter and how to modify the signature of the onStart method?

Many thanks in advance.

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
2

answered 2012-02-09 05:19:55 -0500

Alexandr Buyval gravatar image

updated 2012-02-09 05:21:18 -0500

Hello!

I work with NXT and LeJos too. I send parameters to node using the parameter server. I wrote file robot.yaml

parameter_namespace: nxt_robot
nxt_robot:
  list: [motorA,sonarIn4]
  setttings:
    motorA:
      type: motor
      name: radar_motor
      port: 1.0
      frame_id: radar_motor_link
      desired_frequency: 50.0
    sonarIn4:
      type: ultrasonic
      frame_id: ultrasonic_link
      name: ultrasonic_sensor
      port: 4.0
      desired_frequency: 50.0

and load it in launch-file

<launch>
  <rosparam command="load" file="$(find nxt_rosjava)/robot.yaml" />
  <node pkg="rosjava_bootstrap" 
    type="run.py" 
    args="nxt_rosjava org.ros.nxt_rosjava.Listener" 
    name="nxt_rosjava" 
    output="screen" />  
</launch>

In class Listener I load parameters.

  ParameterTree param = node.newParameterTree();
  GraphName paramNamespace = new GraphName(param.getString("parameter_namespace"));
  NameResolver resolver = node.getResolver().newChild(paramNamespace);
  Map setttings_map = param.getMap(resolver.resolve("setttings"));
  Object[] list = param.getList(resolver.resolve("list")).toArray();
  lst_devices = new ArrayList<Device>();
  for (int i = 0; i < list.length; i++) { 
      String type = (String) ((Map) setttings_map.get(list[i])).get("type");
      String name_dev = (String) ((Map) setttings_map.get(list[i])).get("name");
      String frame_id = (String) ((Map) setttings_map.get(list[i])).get("frame_id");
      double tmp_port = (Double) ((Map) setttings_map.get(list[i])).get("port");
      int port = (int) tmp_port;
      double desired_frequency = (Double) ((Map) setttings_map.get(list[i])).get("desired_frequency");
      log.info("Device: " + list[i] + " type: " + type + " frequency: "+desired_frequency);
      if (type.contains("ultrasonic")){
          UltraSonicSensorNXT dev = new UltraSonicSensorNXT(port, desired_frequency, node, name_dev, frame_id);
          lst_devices.add(dev);  
      }
      if (type.contains("motor")){
          MotorNXT dev = new MotorNXT(port, (int)desired_frequency, node, name_dev);
          lst_devices.add(dev);  
      }
      if (type.contains("touch")){
          TouchSensorNXT dev = new TouchSensorNXT(port, (int)desired_frequency, node, name_dev, frame_id);
          lst_devices.add(dev);  
      }
  }

My current code

edit flag offensive delete link more

Comments

Hi Alexander, many thanks for your idea. I will test this week to add in the new stack that we are doing in LeJOS project. http://lejos.svn.sourceforge.net/viewvc/lejos/trunk/ros/ I was surfing in your googlecode project and what is the idea about nxt_steering_control? Cheers

Juan Antonio Breña Moral gravatar image Juan Antonio Breña Moral  ( 2012-02-12 11:49:42 -0500 )edit

I am going to use nxt_steering_control for connect top-level ROS nodes and rosjava node which control Lego NXT. For example, script nxt_steering_control.py listen pilot\drive (http://www.ros.org/wiki/art_pilot) and send command to topic "joint_command" rosjava node.

Alexandr Buyval gravatar image Alexandr Buyval  ( 2012-02-12 18:38:38 -0500 )edit

All scripts in stack nxt_steering_control are specific for my robot Lego NXT car-like. Project is not finished yet. This is photo my robot http://www.freeimagehosting.net/1s1ih

Alexandr Buyval gravatar image Alexandr Buyval  ( 2012-02-12 18:39:20 -0500 )edit

Hi, today I tested your idea, but I have a problem with this line: GraphName paramNamespace = new GraphName(param.getString("parameter_namespace")); NameResolver resolver = node.getResolver().newChild(paramNamespace);

Juan Antonio Breña Moral gravatar image Juan Antonio Breña Moral  ( 2012-02-26 10:43:29 -0500 )edit

Hi, today I tested your idea, but I have a problem with this line:

Juan Antonio Breña Moral gravatar image Juan Antonio Breña Moral  ( 2012-02-26 10:43:31 -0500 )edit

Hi, today I tested your idea, but I have a problem with this line: GraphName paramNamespace = new GraphName(param.getString("parameter_namespace")); NameResolver resolver = node.getResolver().newChild(paramNamespace);

Juan Antonio Breña Moral gravatar image Juan Antonio Breña Moral  ( 2012-02-26 10:43:36 -0500 )edit

Hi, today I tested your idea, but I have a problem with this line:

Juan Antonio Breña Moral gravatar image Juan Antonio Breña Moral  ( 2012-02-26 10:43:39 -0500 )edit

HI, I tested your idea, but I have a problem with this line: NameResolver resolver = node.getResolver().newChild(paramNamespace); the method newChild doesn't exist. Any alternative?

Juan Antonio Breña Moral gravatar image Juan Antonio Breña Moral  ( 2012-02-26 10:44:19 -0500 )edit
1

answered 2012-01-15 22:39:37 -0500

damonkohler gravatar image

Typically parameters are specified using the parameter server. There is currently no support for command line parameters in rosjava.

See: http://www.ros.org/wiki/Parameter%20Server and http://code.google.com/p/rosjava/source/browse/rosjava/src/main/java/org/ros/node/Node.java#212

edit flag offensive delete link more
0

answered 2012-01-16 07:19:40 -0500

My first alternative was the usage of a .launch file but in this case, I will use a property file to configurate the node NXTLoader.

Do you have this feature in the roadmap of ROSJava?

Cheers

edit flag offensive delete link more

Comments

Please reply to answers in the comments of the answer, not as new answers to the original question. I do not think you understand the usage of parameters. They can be specified in launch files. Take a look at this: http://www.ros.org/wiki/ROS/Tutorials/UnderstandingServicesParams#Using_rosparam
damonkohler gravatar image damonkohler  ( 2012-01-16 19:32:57 -0500 )edit
0

answered 2012-01-16 07:43:33 -0500

The problem to use a property file is about the path. When you execute the following structure for example:

final String path = new File(".").getAbsolutePath();

You receive the following path:

/home/jabrena/.ros/.

Normally the path should near to the Java class where you execute, but in this case the path is relative of ros path. I tested to execute with java the command roscd, but in this case, shell used with Java doesn't have loaded that scripts.

Is it very hard to add parameters in .launch files? I could help in the process.

Juan Antonio

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-01-15 09:15:24 -0500

Seen: 1,004 times

Last updated: Feb 09 '12