Sleeping thread after publishing a message into a topic
Hi, I've been using rosbridge and jroslib as an API to it. Testing the jroslib with the turtlesim, to publish messages I'm finding some errors. I have to use Thread.sleep(500) to the thread sleep so the message can somehow be published into the topic, otherwise the message would not be published nor the turtle would move.,
public static void main(String[] args) throws InterruptedException {
Ros ros = new Ros("localhost");
final int[] answer = {0};
ros.connect();
Topic turtlePub = new Topic(ros,"/turtle1/cmd_vel", "geometry_msgs/Twist", 3);
turtlePub.advertise();
turtlePub.subscribe(new TopicCallback() {
@Override
public void handleMessage(Message message) {
System.out.println(message);
}
});
Message toSend = new Twist(new Vector3(2.0,0,0), new Vector3(0,0,1.8));
turtlePub.publish(toSend);
Thread.sleep(500);
ros.disconnect();
System.out.println("finished");
}