ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Sleeping thread after publishing a message into a topic

asked 2015-02-26 06:16:34 -0600

pnakibar gravatar image

updated 2015-02-26 08:13:38 -0600

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};

    Topic turtlePub = new Topic(ros,"/turtle1/cmd_vel", "geometry_msgs/Twist", 3);
    turtlePub.subscribe(new TopicCallback() {
        public void handleMessage(Message message) {
    Message toSend = new Twist(new Vector3(2.0,0,0), new Vector3(0,0,1.8));



edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-02-26 13:08:11 -0600

tfoote gravatar image

I'm not completely familiar with jroslib, but in general ROS communications are asyncronous and run in multiple threads. If you publish a message then immediately terminate the process, the message may have enough time in the other thread which actually does the transmission, with acknowledgement and retry logic.

edit flag offensive delete link more


PS can you link to documentation for jroslib?

tfoote gravatar image tfoote  ( 2015-02-26 13:08:58 -0600 )edit

It probably is exactly this! The documentation is pretty lacking, although the API is very straightforward. Their git:

pnakibar gravatar image pnakibar  ( 2015-02-26 14:13:29 -0600 )edit

Question Tools


Asked: 2015-02-26 06:16:34 -0600

Seen: 372 times

Last updated: Feb 26 '15