0
$\begingroup$

Rosanswers logo

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.


Originally posted by tairen on ROS Answers with karma: 56 on 2012-01-30

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Aaron Blasdel with karma: 211 on 2012-12-10

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.