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

Sleeping thread after publishing a message into a topic

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

pnakibar gravatar image

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

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");
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Comments

PS can you link to documentation for jroslib?

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

It probably is exactly this! The documentation is pretty lacking, although the API is very straightforward. Their git: https://github.com/WPI-RAIL/jrosbridge

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

Question Tools

Stats

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

Seen: 376 times

Last updated: Feb 26 '15