break if (netService.isAlive() == False): print 'Network service thread died!' break # TODO: Require a heartbeat message from the remote try: msg = cmdQueue.get(True, 1) except Queue.Empty: # Not a bad thing, just need to check the exit conditions. pass else: print 'Received command: ' + msg words = msg.split() if (words[0] == "motor"): motorControl.putCmd(msg) ##################################################################### # Stop the motors and anything else we don't want running after the # program exits. ##################################################################### # TODO: Stop the motors and whatever else motorQueue.put("motor 0 0") # Let the motor thread get the message # TODO: Is there a better way to guarantee this? time.sleep(1) ##################################################################### # Clean up all the threads ##################################################################### netService.join()
#!/usr/bin/python import Queue import time from motor_thread import MotorThread motorQueue = Queue.Queue() motorControl = MotorThread(motorQueue) motorControl.stop() motorControl.start() print 'Main is sleeping' motorControl.putCmd("Entry 1") time.sleep(1) motorControl.putCmd("Entry 2") time.sleep(1) motorControl.putCmd("Entry 3") time.sleep(1) motorControl.putCmd("Entry 4") time.sleep(1) motorControl.putCmd("Entry 5") time.sleep(2) print 'Awake, stop motor controller' motorControl.join()
break if (netService.isAlive() == False): print 'Network service thread died!' break # TODO: Require a heartbeat message from the remote try: msg = cmdQueue.get(True, 1) except Queue.Empty: # Not a bad thing, just need to check the exit conditions. pass else: print 'Received command: ' + msg words = msg.split() if (words[0] == "motor"): motorControl.putCmd(msg) ##################################################################### # Stop the motors and anything else we don't want running after the # program exits. ##################################################################### # TODO: Stop the motors and whatever else motorQueue.put("motor 0 0") # Let the motor thread get the message # TODO: Is there a better way to guarantee this? time.sleep(1) ##################################################################### # Clean up all the threads ##################################################################### netService.join()