Hello all,
A friend and I are attempting to control a robotic hand using python; however, we have been having difficulty with the python code timing out after around 500 frames.
We have set it up so that the code prints a statement upon connection, prints the data (simply the finger length and width for now, just to get some data imported), and then SHOULD print a statement upon disconnect. Furthermore, our code should run continuously and only exit upon hitting the enter key. However, our code continually exits after a certain amount of time. Even after delaying our frame loop for up to 9 seconds, it continues to only process 500 frames.
Is this an issue with the buffer? Or, is there potentially a problem with the Leap.py file we downloaded in order to code with the Leap in Python?
We have posted our current code to this post. We'd appreciate any advice or insight you can provide.
SAMPLE CODE:
import Leap
import sys, thread, time
class LeapMotionListener(Leap.Listener):
digit_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky']
bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal']
state_names = ['STATE_INVALID', 'STATE_START', 'STATE_UPDATE', 'STATE_END']
def on_init(self, controller):
print('Initialized')
def on_connect(self, controller):
print('Leap Motion connected')
def on_disconnect(self, controller):
print('Leap Motion disconnected')
def on_exit(self, controller):
print('Exited')
listener = LeapMotionListener()
controller.add_listener(listener)
print('Re-connected')
def on_frame(self, controller):
frame = controller.frame()
print "Frame ID: " + str(frame.id) \
+ " Timestamp: " + str(frame.timestamp) \
+ " # of Hands: " + str(len(frame.hands)) \
+ " # of Fingers: " + str(len(frame.fingers))
print "Frame ID: " + str(frame.id)
for hand in frame.hands:
handType = "Left Hand" if hand.is_left else "Right Hand"
print handType + " Hand ID: " + str(hand.id) + " Palm Position " + str(hand.palm_position)
normal = hand.palm_normal
direction = hand.direction
print "Pitch: " + str(direction.pitch * Leap.RAD_TO_DEG) + " Roll: " + str(normal.roll * Leap.RAD_TO_DEG) + " Yaw: " + str(direction.yaw * Leap.RAD_TO_DEG)
for finger in hand.fingers:
print "Type: " + self.digit_names[finger.type] + " ID: " + str(finger.id) + " Length(mm): " + str(finger.length) + " Width(mm): " + str(finger.width)
def main():
listener = LeapMotionListener()
controller = Leap.Controller()
controller.add_listener(listener)
print('Press enter to quit')
try:
sys.stdin.readline()
time.sleep(9)
except KeyboardInterrupt:
pass
print('Yes')
finally:
controller.remove_listener(listener)
controller.add_listener(listener)
print('Re-connected')
if name == "main":
main()