# How to start a node after I terminate the lunch file with Ctrl + C

• OS: Ubuntu 16.04 LTS with 4.15.0-52-generic kernel
• ROS version: Kinetic

I want to save the map continuously while I'm creating it with hector_slam or at the end of the mapping process. I can do it with starting manually after I finish mapping, but if it could be simultaneous while the robot is mapping, it would be better. So I have this in my lunch file but obviously it starts ones and I get only the blank map file.

<node pkg="map_server" type="map_saver" name="map_saver" args="-f $(find robot_hector_slam)/map/map"/>  I want to do it continuously or I want to start this node when I terminate the launch file with Ctrl + C. Is there any other way to save the map like this? With geotiff, it creates the map with timestamp and I don't know how to overwrite to the same file. edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted You could wrap your launch files/nodes in a bash script, and make use of a bash trap, which allows you to run code when ctrl+c is received. #!/bin/bash on_interrupt () { kill -INT$1 # Kills the first thing you started
wait # for this process to end
rosrun mypkg NewNode # subsequent ctrl+c will end this and the script
}

roslaunch mypkg myapp.launch &
trap "on_interrupt \$!" INT SIGINT

wait


This script tells bash to run on_interrupt when ctrl+c is received, passing the process ID of roslaunch ... as an argument. on_interrupt ends this process and runs whatever else you want to run. Hit ctrl+c again to end.

more