Skip to content

Commit

Permalink
allow retry for serial connection
Browse files Browse the repository at this point in the history
  • Loading branch information
steamypotato committed May 26, 2023
1 parent 2f138c2 commit de968e0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions robot/rospackages/src/mcu_control/scripts/CommsNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,17 @@ def get_arg_bytes(command_tuple):
if local_mode:
ser = serial.Serial('/dev/ttyACM0', 57600, timeout = 1)
else:
ser_science = serial.Serial('/dev/ttyACM0', 57600, timeout = 1)
ser_hardware = serial.Serial('/dev/ttyTHS2', 57600, timeout = 1)
ser = ser_hardware
start = time.time()
# loop for a max of 60sec
while time.time() - start < 60:
try:
ser_science = serial.Serial('/dev/ttyACM0', 57600, timeout = 1)
ser_hardware = serial.Serial('/dev/ttyTHS2', 57600, timeout = 1)
ser = ser_hardware
break
except serial.SerialException as e:
rospy.logwarn("Retrying connection to science, error occured " + str(e))
time.sleep(1)

node_name = 'comms_node'
rospy.init_node(node_name, anonymous=False) # only allow one node of this type
Expand Down

0 comments on commit de968e0

Please sign in to comment.