aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze/utils/tobii_imu_calibrate.py80
1 files changed, 71 insertions, 9 deletions
diff --git a/src/argaze/utils/tobii_imu_calibrate.py b/src/argaze/utils/tobii_imu_calibrate.py
index 369134e..85472d9 100644
--- a/src/argaze/utils/tobii_imu_calibrate.py
+++ b/src/argaze/utils/tobii_imu_calibrate.py
@@ -9,6 +9,8 @@ from argaze.TobiiGlassesPro2 import TobiiController, TobiiInertialMeasureUnit
from argaze.utils import MiscFeatures
import numpy
+import matplotlib.pyplot as mpyplot
+import matplotlib.patches as mpatches
def main():
"""
@@ -22,7 +24,7 @@ def main():
parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0])
parser.add_argument('-t', '--tobii_ip', metavar='TOBII_IP', type=str, default=None, help='tobii glasses ip')
parser.add_argument('-i', '--imu_calibration', metavar='IMU_CALIB', type=str, default=None, help='json imu calibration filepath')
- parser.add_argument('-b', '--buffer_size', metavar='BUFFER_SIZE', type=int, default=500, help='number of samples to store into calibration buffer')
+ parser.add_argument('-n', '--sample_number', metavar='BUFFER_SIZE', type=int, default=500, help='number of samples to store into calibration buffer')
parser.add_argument('-o', '--output', metavar='OUT', type=str, default='imu.json', help='destination filepath')
args = parser.parse_args()
@@ -56,7 +58,7 @@ def main():
while True:
print('-' * 52)
- menu_input = input('Tobii Inertial Measure Unit sensor calibration menu:\n\t\'a\' for accelerometer calibration.\n\t\'g\' for gyroscope calibration.\n\t\'p\' print current calibration.\n\t\'s\' save calibration.\n\t\'q\' quit calibration without saving.\n>')
+ menu_input = input('Tobii Inertial Measure Unit sensor calibration menu:\n\t\'a\' for accelerometer calibration.\n\t\'A\' for accelerometer visualisation.\n\t\'g\' for gyroscope calibration.\n\t\'G\' for gyroscope visualisation.\n\t\'p\' print current calibration.\n\t\'s\' save calibration.\n\t\'q\' quit calibration without saving.\n>')
match menu_input:
@@ -76,13 +78,14 @@ def main():
input(f'\nKeep Tobii Glasses accelerometer {axis} axis {direction} then press \'Enter\' to start data acquisition.\n')
# Initialise progress bar
- MiscFeatures.printProgressBar(0, args.buffer_size, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+ MiscFeatures.printProgressBar(0, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
# Capture accelerometer data stream
- for progress, data_ts_buffer in tobii_data_stream.capture('Accelerometer', args.buffer_size):
+ data_ts_buffer = DataStructures.TimeStampedBuffer()
+ for progress in tobii_data_stream.capture(data_ts_buffer, 'Accelerometer', args.sample_number):
# Update progress Bar
- MiscFeatures.printProgressBar(progress, args.buffer_size, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+ MiscFeatures.printProgressBar(progress, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
axis_buffers[direction] = data_ts_buffer
@@ -95,27 +98,86 @@ def main():
print('\tY coefficients: ', accelerometer_coefficients[1])
print('\tZ coefficients: ', accelerometer_coefficients[2])
+ case 'A':
+
+ print('\nCAPTURE AND PLOT ACCELEROMETER STREAM')
+
+ # Initialise progress bar
+ MiscFeatures.printProgressBar(0, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+
+ # Capture accelerometer data stream
+ data_ts_buffer = DataStructures.TimeStampedBuffer()
+ for progress in tobii_data_stream.capture(data_ts_buffer, 'Accelerometer', args.sample_number):
+
+ # Update progress Bar
+ MiscFeatures.printProgressBar(progress, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+
+ # Edit figure
+ figure_width = min(args.sample_number/10, 56) # maximal width to display: 56 inches at 144 dpi < 2^16 pixels
+ data_sample = 8064 # 56 inches * 144 dpi = 8064 data can be displayed at max
+ figure = mpyplot.figure(figsize=(figure_width, 5), dpi=144)
+
+ # Plot data
+ subplot = figure.add_subplot(111)
+ subplot.set_title('Accelerometer', loc='left')
+ patches = data_ts_buffer.plot(names=['x','y','z'], colors=['#276FB6','#9427B6','#888888'], split={'value':['x','y','z']}, samples=data_sample)
+ subplot.legend(handles=patches, loc='upper left')
+
+ # Display figure
+ mpyplot.show()
+ figure.clear()
+
case 'g':
print('\nGYROSCOPE CALIBRATION')
input('Keep Tobii Glasses steady then press \'Enter\' to start data acquisition.\n')
# Initialise progress bar
- MiscFeatures.printProgressBar(0, args.buffer_size, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+ MiscFeatures.printProgressBar(0, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
# Capture gyroscope data stream
- for progress, buffer in tobii_data_stream.capture('Gyroscope', args.buffer_size):
+ data_ts_buffer = DataStructures.TimeStampedBuffer()
+ for progress in tobii_data_stream.capture(data_ts_buffer, 'Gyroscope', args.sample_number):
# Update progress Bar
- MiscFeatures.printProgressBar(progress, args.buffer_size, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+ MiscFeatures.printProgressBar(progress, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
- gyroscope_offset = tobii_imu.calibrate_gyroscope_offset(buffer)
+ gyroscope_offset = tobii_imu.calibrate_gyroscope_offset(data_ts_buffer)
print(f'\n\nGyroscope average over {progress} values for each axis:')
print('\tX offset: ', gyroscope_offset[0])
print('\tY offset: ', gyroscope_offset[1])
print('\tZ offset: ', gyroscope_offset[2])
+ case 'G':
+
+ print('\nCAPTURE AND PLOT GYROSCOPE STREAM')
+
+ # Initialise progress bar
+ MiscFeatures.printProgressBar(0, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+
+ # Capture accelerometer data stream
+ data_ts_buffer = DataStructures.TimeStampedBuffer()
+ for progress in tobii_data_stream.capture(data_ts_buffer, 'Gyroscope', args.sample_number):
+
+ # Update progress Bar
+ MiscFeatures.printProgressBar(progress, args.sample_number, prefix = 'Data acquisition:', suffix = 'Complete', length = 100)
+
+ # Edit figure
+ figure_width = min(args.sample_number/10, 56) # maximal width to display: 56 inches at 144 dpi < 2^16 pixels
+ data_sample = 8064 # 56 inches * 144 dpi = 8064 data can be displayed at max
+ figure = mpyplot.figure(figsize=(figure_width, 5), dpi=144)
+
+ # Plot data
+ subplot = figure.add_subplot(111)
+ subplot.set_title('Gyroscope', loc='left')
+ patches = data_ts_buffer.plot(names=['x','y','z'], colors=['#276FB6','#9427B6','#888888'], split={'value':['x','y','z']}, samples=data_sample)
+ subplot.legend(handles=patches, loc='upper left')
+
+ # Display figure
+ mpyplot.show()
+ figure.clear()
+
case 'p':
gyroscope_offset = tobii_imu.get_gyroscope_offset()