Ask Your Question

Cleanly kill rosbag with python script

asked 2018-09-10 17:40:59 -0500

EDJ14 gravatar image

I am running several ROS nodes (kinetic) on Raspbian, including a rosbag node that records all published topics. The script below is activated by pressing a physical button and is meant to ensure that the rosbag is killed cleanly (getting rid of the state) before shutting the system off. When run manually from the terminal, the script executes without errors and cleanly kills the rosbag. But when the button is used to activate the script, the script is successfully called but stops at the subprocess.check_call(['rosnode', 'kill', '-a',]) line, preventing the rosbag from killing cleanly and preventing the system from shutting down. I'm wondering why the script fails to execute the ROS-specific lines when executed using the button?


#!/usr/bin/env python

import RPi.GPIO as GPIO
import subprocess


# This should turn on the LED
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.HIGH)

GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(16, GPIO.FALLING)

subprocess.check_call(['rosnode', 'kill', '-a']) #cleanly kill the rosbag
# -h stands for --power-off['shutdown', '-h', 'now'], shell=False)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-09-11 02:24:32 -0500

gvdhoorn gravatar image

You don't tell us anything about how you hooked up script execution to the button, but something to make sure: does your button-event-handler script (something I made up) also source /opt/ros/kinetic/setup.bash (or the equivalent from your workspace)? If it doesn't, rosnode cannot be found.

edit flag offensive delete link more


That was it! Thanks

EDJ14 gravatar image EDJ14  ( 2018-09-11 17:18:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-09-10 17:40:59 -0500

Seen: 260 times

Last updated: Sep 10 '18