Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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,motorB,motorC,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

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,motorB,motorC,sonarIn4]
[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