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

Can AsyncSpinner spins in functions?

asked 2012-01-30 09:26:21 -0500

tairen gravatar image

updated 2014-01-28 17:11:13 -0500

ngrennan gravatar image

Hi, everyone,

I build a simple program to play with turtle under the ROS and Qt environment. Right now I use the signal-slot in Qt to combine the button to the direction function of the turtle in ROS. Since the signal-slot connection only runs function one time as I click the button once, I can't continuously control the turtle in one direction, so I wanna use the AsyncSpinner let one thread of spin in one function to drive the turtle, and in another function, I let the spin stop to stop the turtle's movement. But I tried lots way, I can't get my purpose. So I post the question here, hope to see some hints! The question is when I put the AsyncSpinner inside, the program seems spin in the same place. The code is like that:

           void HelloWidget::forWard() {

                ros::AsyncSpinner spinner(1);
                spinner.start();      // the spin seems lock the program when I ran
                qDebug("step 1");

            void HelloWidget::forwardStop()
              spinner.stop(); //I can't use here, because the compiler tells 
                            //that spin is not define in this scope, but I do 
                           // not know how to define AsyncSpinner in ordinary way
                          // like: AsyncSpinner *spinner in headfile, then 
                         // in construct function, spinner = new AsyncSpinner,because
                        //  it is not work for AsyncSpinner ...

Can anyone share some experiences about that? Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-12-10 12:29:54 -0500

Aaron Blasdel gravatar image

updated 2012-12-10 13:20:08 -0500

If you look at the api for ros::waitForShutdown() it says that it will cause the current program to wait for a ctrl-c.(

You definitely don't want to run that from a qt callback or it will lock up your program.

Here is some info on the behavior:

Try taking out the ros::waitForShutdown() and tell me what kind of behavior you get.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2012-01-30 09:26:21 -0500

Seen: 1,115 times

Last updated: Dec 10 '12