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:
- Subscribe to gazebo/ModelStates and check for the object attributes
- 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>() {
@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:
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?
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. .... See wiki/rosjava/Messages for some info.
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.
Thank you very much, I will create a class for this type of Message and parse the data. It should work.
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.