def IMU_init(): global ipcon HOST = "localhost" PORT = 4223 UID = "5VHux5" # Unique ID of IMU Brick period = 7 #ms ipcon = IPConnection() # Create IP connection object imu = BrickIMU(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected print("Hey, IMU connected!") # Set non-blocking callback funtions to read the sensor. CALLBACK_ACCELERATION is called each "period" ms # and the returned value is send to cb_acceleration as an argument. imu.register_callback(imu.CALLBACK_ACCELERATION, cb_acceleration) imu.register_callback(imu.CALLBACK_ANGULAR_VELOCITY, cb_angular_velocity) imu.set_acceleration_period(period) imu.set_angular_velocity_period(period)
UID = "XXYYZZ" # Change XXYYZZ to the UID of your IMU Brick from tinkerforge.ip_connection import IPConnection from tinkerforge.brick_imu import BrickIMU # Callback function for quaternion callback def cb_quaternion(x, y, z, w): print("Quaternion[X]: " + str(x)) print("Quaternion[Y]: " + str(y)) print("Quaternion[Z]: " + str(z)) print("Quaternion[W]: " + str(w)) print("") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection imu = BrickIMU(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register quaternion callback to function cb_quaternion imu.register_callback(imu.CALLBACK_QUATERNION, cb_quaternion) # Set period for quaternion callback to 1s (1000ms) # Note: The quaternion callback is only called every second # if the quaternion has changed since the last call! imu.set_quaternion_period(1000) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XXYYZZ" # Change XXYYZZ to the UID of your IMU Brick from tinkerforge.ip_connection import IPConnection from tinkerforge.brick_imu import BrickIMU if __name__ == "__main__": ipcon = IPConnection() # Create IP connection imu = BrickIMU(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current quaternion x, y, z, w = imu.get_quaternion() print("Quaternion[X]: " + str(x)) print("Quaternion[Y]: " + str(y)) print("Quaternion[Z]: " + str(z)) print("Quaternion[W]: " + str(w)) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "62Bous" # Change XXYYZZ to the UID of your IMU Brick from tinkerforge.ip_connection import IPConnection from tinkerforge.brick_imu import BrickIMU if __name__ == "__main__": ipcon = IPConnection() # Create IP connection imu = BrickIMU(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current quaternion x, y, z, w = imu.get_quaternion() print("Quaternion[X]: " + str(x)) print("Quaternion[Y]: " + str(y)) print("Quaternion[Z]: " + str(z)) print("Quaternion[W]: " + str(w)) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()