Ask Your Question
1

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() {

                _qtturtle->setforWard();
                ros::AsyncSpinner spinner(1);
                spinner.start();      // the spin seems lock the program when I ran
                ros::waitForShutdown();
                qDebug("step 1");
            }

            void HelloWidget::forwardStop()
            {
              _qtturtle->setforWardstop();
              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 ...
               qDebug("step2");
             }

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
1

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.(http://mediabox.grasp.upenn.edu/roswiki/doc/api/roscpp/html/namespaceros.html#af068034d937093fdb0d5aaa1e0d9e249)

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: http://www.ros.org/wiki/roscpp/Overview/Callbacks%20and%20Spinning

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 977 times

Last updated: Dec 10 '12