-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimu.py
More file actions
31 lines (22 loc) · 880 Bytes
/
imu.py
File metadata and controls
31 lines (22 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# -*- coding: utf-8 -*-
HOST = "localhost"
PORT = 4223
UID = "a4JritAp6Go" # Change to your UID
from tinkerforge.ip_connection import IPConnection
from tinkerforge.brick_imu import IMU
imu = IMU(UID) # Create device object
# Quaternion callback
def quaternion_cb(x, y, z, w):
print("x: " + str(x) + "\ny: " + str(y) + "\nz: " + str(z) + "\nw: " + str(w) + "\n")
if __name__ == "__main__":
ipcon = IPConnection(HOST, PORT) # Create IPconnection to brickd
ipcon.add_device(imu) # Add device to IP connection
# Don't use device before it is added to a connection
# Set period for quaternion callback to 1s
imu.set_quaternion_period(100)
# Register quaternion callback
imu.register_callback(imu.CALLBACK_QUATERNION, quaternion_cb)
imu.leds_off() # Turn LEDs off.
raw_input('Press key to exit\n') # Use input() in Python 3
ipcon.destroy()