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 .bag.active 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?
Thanks
#!/usr/bin/env python
import RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BCM)
# 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
subprocess.call(['shutdown', '-h', 'now'], shell=False)
↧