0
$\begingroup$

Rosanswers logo

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)

Originally posted by EDJ14 on ROS Answers with karma: 3 on 2018-09-10

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by gvdhoorn with karma: 86574 on 2018-09-11

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by EDJ14 on 2018-09-11:
That was it! Thanks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.