From 485353340091543b5eecfa42ef1a0085e692e6db Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sat, 2 Apr 2016 18:53:20 -0700 Subject: [PATCH] Added heart beat test for the serial connection which allows unplugging and plugging back in the serial line --- ros_arduino_python/nodes/arduino_node.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 4a479ca..8fb5407 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -214,6 +214,20 @@ class ArduinoROS(): # Start polling the sensors, base controller, and servo controller while not rospy.is_shutdown(): + # Heartbeat test for the serial connection + try: + self.device.serial_port.inWaiting() + except IOError: + rospy.loginfo("Lost serial connection...") + self.device.close() + while True: + try: + self.device.open() + rospy.loginfo("Serial connection re-established.") + break + except: + r.sleep() + for sensor in self.mySensors: if sensor.rate != 0: mutex.acquire()