Robotics StackExchange | Archived questions

Topic subscription with gazebo and ROSJava

Hi would like to be notified when the position of an object in gazebo changes. I have found the following options:

  1. Subscribe to gazebo/ModelStates and check for the object attributes
  2. Use the service call Getmodelstate provided by Gazebo to retrieve state and property information about the object

I am trying the first one since I haven't found any documentation about calling a gazebo service from ROSJava. Check here

I started with the basic Subscriber from the official RosJava documentation. Now I need to define a new subscriber

Subscriber<gazebo_msgs.ModelStates> subscriber = connectedNode.newSubscriber("chatter", gazebo_msgs.ModelStates._TYPE);
    subscriber.addMessageListener(new MessageListener<gazebo_msgs.ModelStates>() {
      @Override
      public void onNewMessage(gazebo_msgs.ModelStates message) {
        log.info("I heard: \"" + message.getName() + "\"");
      }
    });

I would like to subscribe to a topic which exchanges gazebo_msgs/ModelStates messages.

string[] name                 # model names
geometry_msgs/Pose[] pose     # desired pose in world frame
geometry_msgs/Twist[] twist   # desired twist in world frame

Catkin_make returns the error:

gazebomsgs does not exist
Subscriber<gazebo
msgs.ModelStates> subscriber = connectedNode.newSubscriber("chatter", gazebomsgs.ModelStates.TYPE);

Question How do I include this type of message in ROSJava?

Asked by UserK on 2016-11-22 13:34:04 UTC

Comments

Being able to use a message in rosjava will depend on whether the binary artefacts (classes, etc) have been generated for the particular msgs you want to use (in this case gazebo_msgs/ModelStates). If that hasn't been done, you can't use it. ..

Asked by gvdhoorn on 2016-11-23 05:56:05 UTC

.. See wiki/rosjava/Messages for some info.

Asked by gvdhoorn on 2016-11-23 05:56:23 UTC

Note that this part of ROS java is far from intuitive and could stand some improvement. You could see whether reporting / asking this over at github.com/rosjava helps.

Asked by gvdhoorn on 2016-11-23 05:59:41 UTC

Thank you very much, I will create a class for this type of Message and parse the data. It should work.

Asked by UserK on 2016-11-23 06:09:50 UTC

That's not necessarily what I meant, but could work. Ideally, you make the rosjava infrastructure work for you and have it generate code for you that conforms to the rosjava specs.

Asked by gvdhoorn on 2016-11-23 06:26:23 UTC

Answers