Topic subscription with gazebo and ROSJava

asked 2016-11-22 12:34:04 -0500

UserK gravatar image

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 Get_model_state 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>() {
      public void onNewMessage(gazebo_msgs.ModelStates message) {"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:

gazebo_msgs does not exist
Subscriber<gazebo_msgs.modelstates> subscriber = connectedNode.newSubscriber("chatter", gazebo_msgs.ModelStates._TYPE);

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

edit retag flag offensive close merge delete



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. ..

gvdhoorn gravatar image gvdhoorn  ( 2016-11-23 04:56:05 -0500 )edit

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

gvdhoorn gravatar image gvdhoorn  ( 2016-11-23 04:56:23 -0500 )edit

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 helps.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-23 04:59:41 -0500 )edit

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

UserK gravatar image UserK  ( 2016-11-23 05:09:50 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-23 05:26:23 -0500 )edit