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

kill nodes (started with .launch file) properly in Qt, how?

asked 2019-05-27 07:11:04 -0600

akosodry gravatar image

Hello ROS Community,

i'm currently developing a Qt C++ GUI for a custom made robotic arm.

I have a QPushButton that starts a .launch file (that launches multiple nodes, i.e., the gazebo, robot spawner, controller spawner, move_group, etc.). The terminal output is printed in a QPlainTextEdit. This mechanism works well and is coded as follows.

    m_process=new QProcess;
    connect(m_process, SIGNAL(readyRead()),this,SLOT(onBytesAvailable()));
    connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(onProcessFinished(int,QProcess::ExitStatus)));
    m_process->setProcessChannelMode(QProcess::MergedChannels);
    m_process->start(roslaunch robot5s_gazebo robot5s_bringup_moveit2.launch);
    bool started=m_process->waitForStarted();
    Q_ASSERT(started);

My problem is that i don't know how to kill successfully the aforementioned process, ie., to perform basically CTRL+C.

If i call m_process->kill() i got in my onProcessFinished SLOT that the kill was successful: Process finished, exit code:9 status: 1, however the nodes are still running, the rosnode list gives

/gazebo
/gazebo_gui
/joint_controller_spawner
/move_group
/robot5s_controller_spawner
/robot_state_publisher
/rosout

So i want to ask, how to perform the CTRL+C mechanism for the launched nodes in Qt C++ environment?

Remark: (Even tho i don't want to kill all the nodes, just the ones that were launched) I also tried to create another QProcess that performes rosnode kill -a, but that also did not do the killing successfully, since gazebo kept running.

Thank you in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-05-27 07:41:50 -0600

Instead of killing the roslaunch process directly you want to send a SIGINT message to it so that it will shutdown in as if ctrl+c had been pressed in the terminal. There are many ways to go about this, the simplest being to execute a shell command using QProcess the same way you've have started roslaunch in the first place.

kill -SIGINT processPIDHere

Hope this helps.

edit flag offensive delete link more

Comments

Thanks for the quick answer. This does the job:

QProcess* kill_process = new QProcess;

    QString str = "kill -SIGINT " + QString::number(m_process->processId());
    qDebug() << str;
    kill_process->start(str);

    bool started=kill_process->waitForStarted();
    qDebug()<<"Process started:"<<started<<kill_process->errorString();
    Q_ASSERT(started);
akosodry gravatar image akosodry  ( 2019-05-27 07:58:06 -0600 )edit
1

Are you recording the stdout of the roslaunch process? It could be useful to see how it's reacting to the SIGINT and if it is continuing to execute for long enough to kill all the spawned nodes. The only thing I can think is that for some reason the roslaunch process is being killed before it has time shut down all the nodes it's started.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-05-27 08:02:31 -0600 )edit

@PeteBlackerThe3rd IT works, just it takes time. In my case it took 15-20 sec to kill all the nodes!

Thanks you very much again!

akosodry gravatar image akosodry  ( 2019-05-27 08:06:26 -0600 )edit

Great, glad you got it working.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-05-27 08:14:34 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2019-05-27 07:11:04 -0600

Seen: 1,633 times

Last updated: May 27 '19