Download GR00T-WholeBodyControl/decoupled_wbc/scripts/leap_tracking_example.py from Timsty/groot_deployment: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/Timsty/groot_deployment/resolve/main/GR00T-WholeBodyControl/decoupled_wbc/scripts/leap_tracking_example.py
- Command line
-
hf download hf://Timsty/groot_deployment/GR00T-WholeBodyControl/decoupled_wbc/scripts/leap_tracking_example.py
-
curl -L -o leap_tracking_example.py https://huggingface.co/Timsty/groot_deployment/resolve/main/GR00T-WholeBodyControl/decoupled_wbc/scripts/leap_tracking_example.py
1.44 kB
| """Prints the palm position of each hand, every frame. When a device is | |
| connected we set the tracking mode to desktop and then generate logs for | |
| every tracking frame received. The events of creating a connection to the | |
| server and a device being plugged in also generate logs. | |
| """ | |
| import time | |
| import leap | |
| class MyListener(leap.Listener): | |
| def on_connection_event(self, event): | |
| print("Connected") | |
| def on_device_event(self, event): | |
| try: | |
| with event.device.open(): | |
| info = event.device.get_info() | |
| except leap.LeapCannotOpenDeviceError: | |
| info = event.device.get_info() | |
| print(f"Found device {info.serial}") | |
| def on_tracking_event(self, event): | |
| print(f"Frame {event.tracking_frame_id} with {len(event.hands)} hands.") | |
| for hand in event.hands: | |
| hand_type = "left" if str(hand.type) == "HandType.Left" else "right" | |
| print( | |
| f"Hand id {hand.id} is a {hand_type} hand with position ({hand.palm.position.x}, " | |
| f"{hand.palm.position.y}, {hand.palm.position.z})." | |
| ) | |
| def main(): | |
| my_listener = MyListener() | |
| connection = leap.Connection() | |
| connection.add_listener(my_listener) | |
| running = True | |
| with connection.open(): | |
| connection.set_tracking_mode(leap.TrackingMode.Desktop) | |
| while running: | |
| time.sleep(1) | |
| if __name__ == "__main__": | |
| main() | |