def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.initialized = False self.altitude_error_i = 0 self.acc_scale = 0.0 self.start_time = time.time() self.altitude_error = 0 self.inst_acceleration = 0.0 self.delta = 0 self.estimated_velocity = 0.0 self.estimated_altitude = 0.0 self.last_time = time.time() self.last_orig_altitude = 0 self.last_estimated_altitude = 0 ipcon = IPConnection() self.imu = IMU(UID_IMU, ipcon) self.barometer = Barometer(UID_BAROMETER, ipcon) ipcon.connect(HOST, PORT) # Turn leds and orientation calculation off, to save calculation time # for the IMU Brick. This makes sure that the measurements are taken # in equidistant 2ms intervals self.imu.leds_off() self.imu.orientation_calculation_off() # Turn averaging of in the Barometer Bricklet to make sure that # the data is without delay self.barometer.set_averaging(0, 0, 0) red_pen = QPen(Qt.red) red_pen.setWidth(5) plot_list = [ #['', Qt.blue, self.get_orig_value], ['', red_pen, self.get_estimated_value] ] self.plot_widget = PlotWidget('Height [m]', plot_list) self.plot_widget.stop = False self.setCentralWidget(self.plot_widget) self.timer = QTimer() self.timer.timeout.connect(self.update) self.timer.start(6)
HOST = "localhost" PORT = 4223 UID = "ayQskyoNrCW" # Change to your UID from tinkerforge.ip_connection import IPConnection from tinkerforge.brick_imu import IMU # Quaternion callback def cb_quaternion(x, y, z, w): print("x: " + str(x) + "\ny: " + str(y) + "\nz: " + str(z) + "\nw: " + str(w) + "\n") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection imu = IMU(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set period for quaternion callback to 1s imu.set_quaternion_period(1000) # Register quaternion callback imu.register_callback(imu.CALLBACK_QUATERNION, cb_quaternion) raw_input('Press key to exit\n') # Use input() in Python 3 ipcon.disconnect()