Ask Your Question
0

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

asked 2019-08-28 08:31:43 -0600

ermanas gravatar image
  • 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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-08-28 13:15:56 -0600

scottnothing gravatar image

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.

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: 2019-08-28 08:31:43 -0600

Seen: 44 times

Last updated: Aug 28