ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
One solution found!
I found out that by shutting ( with SIGINT)
I found solution for this by creating a SIGINT handler in my node WITHOUT ros::shutdown() call but with a global variable set to True that is checked by my while loop. More about SIGINT handler in ROS: (http://wiki.ros.org/roscpp/Overview/Initialization%20and%20Shutdown).
In my Qt app I kill the node with kill(scanProces->processId(), SIGINT) command. Now QProcess.start(""kill -SIGINT " + QString::number(scanProcess->processId())) should also work.
I don't know if this is good way to handle this, but it seem to work!
So what I have in my node is this:
#include <ros/ros.h>
#include <signal.h>
bool exit = false
void mySigintHandler(int sig)
{
// Do some custom action.
// For example, publish a stop message to some other nodes.
exit = true
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "my_node_name", ros::init_options::NoSigintHandler);
ros::NodeHandle nh;
// Override the default ros sigint handler.
// This must be set after the first NodeHandle is created.
signal(SIGINT, mySigintHandler);
while (ros::ok & !exit)
{
ros::spinOnce()
}
return 0;
}
If someone more knowledgeable can tell the root problem of this and if my solution is ok, please enlighten me!