Skip to content
Snippets Groups Projects
Commit 6dddef89 authored by Stuart Glaser's avatar Stuart Glaser
Browse files

Can now recover from a security stop also

parent a5b09f68
Branches
Tags
No related merge requests found
...@@ -65,13 +65,14 @@ def setConnectedRobot(r): ...@@ -65,13 +65,14 @@ def setConnectedRobot(r):
connected_robot = r connected_robot = r
connected_robot_cond.notify() connected_robot_cond.notify()
def getConnectedRobot(wait=False): def getConnectedRobot(wait=False, timeout=-1):
started = time.time()
with connected_robot_lock: with connected_robot_lock:
if wait: if wait:
while not connected_robot: while not connected_robot:
connected_robot_cond.wait(0.5) if timeout >= 0 and time.time() > started + timeout:
#print "Threads:" break
#dumpstacks() connected_robot_cond.wait(0.2)
return connected_robot return connected_robot
# Receives messages from the robot over the socket # Receives messages from the robot over the socket
...@@ -404,27 +405,28 @@ def main(): ...@@ -404,27 +405,28 @@ def main():
if action_server: if action_server:
action_server.set_robot(None) action_server.set_robot(None)
rospy.loginfo("Programming the robot")
while True:
# Sends the program to the robot # Sends the program to the robot
sock = socket.create_connection((HOSTNAME, PORT)) sock = socket.create_connection((HOSTNAME, PORT))
with open('prog') as fin: with open('prog') as fin:
program = fin.read() program = fin.read()
sock.sendall(program % {"driver_hostname": socket.getfqdn()}) sock.sendall(program % {"driver_hostname": socket.getfqdn()})
# Useful for determining if the robot failed to compile the program # Useful for determining if the robot failed to compile the program
if False: if False:
print "Dump" print "Dump"
print "="*70 print "="*70
o = "" o = ""
while len(o) < 4096: while len(o) < 4096:
r = sock.recv(1024) r = sock.recv(1024)
if not r: break if not r: break
o = o + r o = o + r
print o print o
rospy.loginfo("Waiting for the robot to connect back to the driver") r = getConnectedRobot(wait=True, timeout=1.0)
print "Commander thread:", thread_commander.is_alive() if r:
r = getConnectedRobot(wait=True) break
rospy.loginfo("Robot connected") rospy.loginfo("Robot connected")
if action_server: if action_server:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment