def test_set_datasheet_values(self): sc = StandardCalibration(verbose=True) client, smbus, mockbus = create_device() client.open() client.bus._read = mockbus._written sc.set_datasheet_values_for_accelerometer(client.get_settings()) assert np.linalg.norm(sc.acc_scale_factor_matrix - np.eye(3)) > 0.0
def test_calibration_points_1_degrees(self): sc = StandardCalibration(verbose=True) sc.calibrate_gyroscope_with_stored_points( self.points_1_zero, self.test_points_1, sc.RECORD_PLAYER_45_RPM_IN_DPS) np.testing.assert_allclose(sc.gyro_bias_vector, np.array([-0.01581438, 0.01164529, 0.02771216]) * 57.2957795, rtol=1e-6, atol=1e-6) np.testing.assert_allclose(sc.gyro_scale_factor_vector, np.array([0.00030169, 0.00029362, 0.00029876]) * 57.2957795, rtol=1e-6, atol=1e-6)
def test_calibration_points_2_degrees(self): sc = StandardCalibration(verbose=True) sc.calibrate_gyroscope_with_stored_points( self.points_2_zero, self.test_points_2, sc.RECORD_PLAYER_33_3_RPM_IN_DPS) np.testing.assert_allclose(sc.gyro_bias_vector, np.array([-0.67834283, 0.79632176, 1.56510056]), rtol=1e-6, atol=1e-6) np.testing.assert_allclose(sc.gyro_scale_factor_vector, np.array([0.01698324, 0.01662334, 0.01690871]), rtol=1e-6, atol=1e-6)
def function_to_call(savefile_path, settings_dict): try: from pyberryimu.client import BerryIMUClient from pyberryimu.calibration.standard import StandardCalibration from pyberryimu.recorder import BerryIMURecorder with BerryIMUClient(settings=settings_dict) as c: c.calibration_object = StandardCalibration.load() r = BerryIMURecorder(c, settings_dict.get('data_rate'), settings_dict.get('duration')) out = r.record() out.save(savefile_path) except Exception as e: with open(savefile_path, 'wt') as f: json.dump({'error': str(e)}, f, indent=2)
def plot_data(): c = py.get_credentials() trace1 = pygraph.Scatter( x=[], y=[], mode='lines', line=pygraph.Line(color='rgba(31,119,180,0.15)'), stream=dict(token=c.get('stream_ids')[0], maxpoints=100)) trace2 = pygraph.Scatter( x=[], y=[], mode='lines', line=pygraph.Line(color='rgba(180,119,31,0.15)'), stream=dict(token=c.get('stream_ids')[1], maxpoints=100)) trace3 = pygraph.Scatter( x=[], y=[], mode='lines', line=pygraph.Line(color='rgba(119,180,31,0.15)'), stream=dict(token=c.get('stream_ids')[2], maxpoints=100)) data = pygraph.Data([trace1, trace2, trace3]) layout = pygraph.Layout( title='Streaming PyBerryIMU Data' ) fig = pygraph.Figure(data=data, layout=layout) print(py.plot(fig, filename='PyBerryIMU')) s_x = py.Stream(c.get('stream_ids')[0]) s_y = py.Stream(c.get('stream_ids')[1]) s_z = py.Stream(c.get('stream_ids')[2]) s_x.open() s_y.open() s_z.open() with BerryIMUClient() as c: c.calibration_object = StandardCalibration.load() t_start = c.timestamp while (c.timestamp - t_start) < 60: t = c.timestamp - t_start acc = c.read_accelerometer() s_x.write(dict(x=t, y=acc[0])) s_y.write(dict(x=t, y=acc[1])) s_z.write(dict(x=t, y=acc[2])) s_x.close() s_y.close() s_z.close()
def test_calibration_points_correspondence_with_datasheet_values(self): sc = StandardCalibration(verbose=True) sc2 = StandardCalibration(verbose=True) client, smbus, mockbus = create_device() client.open() client.bus._read = mockbus._written sc.calibrate_gyroscope_with_stored_points( self.points_2_zero, self.test_points_2, sc.RECORD_PLAYER_33_3_RPM_IN_DPS) sc2.set_datasheet_values_for_gyroscope(client.get_settings()) def _internal_test_function(untransformed_g, tolerance): np.testing.assert_allclose(sc.transform_gyroscope_values(untransformed_g), sc2.transform_gyroscope_values(untransformed_g - self.points_2_zero), atol=tolerance) for index in range(3): for side in [-1, 1]: k = index * 2 if side == -1 else (index * 2) + 1 ref = np.zeros((3,), 'float') ref[index] = sc.RECORD_PLAYER_33_3_RPM_IN_DPS * side yield _internal_test_function, self.test_points_2[k, :], 15.0
def test_calibration_points_2(self): sc = StandardCalibration(verbose=True) sc.calibrate_accelerometer_with_stored_points(self.test_points_2) np.testing.assert_almost_equal(sc._acc_calibration_errors[-1], 0.0, 2)
#!/usr/bin/env python from pyberryimu.client import BerryIMUClient from pyberryimu.calibration.standard import StandardCalibration sc = StandardCalibration(verbose=True) c = BerryIMUClient(bus=1) sc.calibrate_accelerometer(c) c.calibration_object = sc sc.save(save_path='/home/pi/.pyberryimu')
def main(): with BerryIMUClient() as client: client.calibration_object = StandardCalibration.load() brec = BerryIMURecorder(client, frequency=100, duration=3) dc = brec.record(acc=True, gyro=True, mag=True, pres=False, temp=False) dc.save(os.path.expanduser('~/pyberryimu_test_data'))
from __future__ import division from __future__ import print_function from __future__ import unicode_literals from __future__ import absolute_import import numpy as np import scipy.integrate as scint import matplotlib.pyplot as plt from pyberryimu.calibration.standard import StandardCalibration from pyberryimu.container import BerryIMUDataContainer data = BerryIMUDataContainer.load('rec_gyro.json') sc1 = StandardCalibration.load('/home/hbldh/Dropbox/Encrypted/PyBerryIMU/.pyberryimu-BACKUP_g1') sc1.gyro_bias_vector *= 57.2957795 sc1.gyro_scale_factor_vector *= 57.2957795 sc2 = StandardCalibration.load('/home/hbldh/Dropbox/Encrypted/PyBerryIMU/.pyberryimu-BACKUP_g2') sc_sh = StandardCalibration.load('/home/hbldh/Dropbox/Encrypted/PyBerryIMU/.pyberryimu') sc_sh.set_datasheet_values_for_gyroscope(data.client_settings) g_sc1 = [] g_sc2 = [] g_sh = [] for row in data.gyroscope: g_sc1.append(sc1.transform_gyroscope_values(row.tolist())) g_sc2.append(sc2.transform_gyroscope_values(row.tolist())) g_sh.append(sc_sh.transform_gyroscope_values(row.tolist())) d = 0
# link to callback functions client.on_connect = on_connect client.on_message = on_message client.loop_start() #--------------------------------------------------------------------------------------- # Modules and methods to support MQTT # #--------------------------------------------------------------------------------------- from pyberryimu.client import BerryIMUClient from pyberryimu.calibration.standard import StandardCalibration sc = StandardCalibration.load() with BerryIMUClient(bus=1) as c : c.calibration_object = sc while True : acc = c.read_accelerometer() gyro = c.read_gyroscope() mag = c.read_magnetometer() pr = c.read_pressure() temp = c.read_temperature() client.publish("pibot/imu/acc", str({'value':acc, 'time':measurement_time})) client.publish("pibot/imu/gyro", str({'value':gyro, 'time':measurement_time})) client.publish("pibot/imu/mag", str({'value':mag, 'time':measurement_time}))