Skip to content

Commit

Permalink
luxonisGH-49: added KeyboardInterrupt handler for battery status node
Browse files Browse the repository at this point in the history
  • Loading branch information
sskorol committed Oct 22, 2023
1 parent 3b135fc commit 4ad0fd5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions rae_bringup/scripts/battery_status.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
import rclpy
import signal
import sys
from rclpy.node import Node
from rclpy.time import Time

from sensor_msgs.msg import BatteryState, Image
from std_msgs.msg import ColorRGBA
Expand Down Expand Up @@ -106,17 +107,21 @@ def listener_callback(self, msg):
self.publisher_led.publish(led_msg)


def signal_handler(node):
def handle(sig, frame):
if rclpy.ok():
node.destroy_node()
rclpy.shutdown()
sys.exit(0)
return handle


def main(args=None):
rclpy.init(args=args)

battery_status_node = BatteryStatusNode()

signal.signal(signal.SIGINT, signal_handler(battery_status_node))
rclpy.spin(battery_status_node)

# Destroy the node explicitly
battery_status_node.destroy_node()
rclpy.shutdown()


if __name__ == '__main__':
main()
main()

0 comments on commit 4ad0fd5

Please sign in to comment.