Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # NOTE: This isn't working so well with multithreading
- from naoqi import *
- import time
- from threading import Thread, Event
- naoIp = "0.0.0.0"
- naoPort = 9559
- motion = ALProxy("ALMotion", naoIp, naoPort)
- def testBlocking():
- mId = motion.post.angleInterpolation(["LHand"], [[0, 1, 0]], [[1, 3, 7]], True)
- event = Event()
- def waitAndKill():
- time.sleep(2)
- print "Killing"
- motion.stop(mId)
- event.set()
- def waitUntilDone():
- while motion.isRunning(mId):
- # This is extremely costly...
- pass
- event.set()
- # If true, will show wait functionality. Set to false to test basics.
- useThread = True
- if useThread:
- # This will use ALProxy.wait(), which will not kill task until it is finished
- useWait = False
- print "Waiting..."
- killThread = Thread()
- killThread.run = waitAndKill
- killThread.start()
- if useWait:
- motion.wait(mId, 0)
- else:
- monitorThread = Thread()
- monitorThread.run = waitUntilDone
- monitorThread.start()
- event.wait()
- # For reuse: event.clear()
- print "Done"
- else:
- waitAndKill()
- testBlocking()
Advertisement
Add Comment
Please, Sign In to add comment