This repository has been archived by the owner on Oct 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImuDataGrapher.m
128 lines (107 loc) · 3.07 KB
/
ImuDataGrapher.m
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
% Program to graph IMU data logged by Verne.
% Add files using default names to MATLAB path and run
% program. Input the appropriate run number for the
% desired graph.
clear
clc
% Get run number input from user
runNum = input('Run number: ');
% Get axis display settings from user
accelOpt = input('Acceleration axes to display (some combination of xyz): ', 's');
% Vector of axes options x, y, z
accelAxes = [1, 1, 1];
% Set axes based on input
if ~isempty(accelOpt)
x = contains(accelOpt, 'x', 'IgnoreCase', true);
y = contains(accelOpt, 'y', 'IgnoreCase', true);
z = contains(accelOpt, 'z', 'IgnoreCase', true);
accelAxes = [x, y, z];
end
% Get axis display settings from user
rotOpt = input('Rotation axes to display (some combination of xyz): ', 's');
% Vector of axes options x, y, z
rotAxes = [1, 1, 1];
% Set axes based on input
if ~isempty(rotOpt)
x = contains(rotOpt, 'x', 'IgnoreCase', true);
y = contains(rotOpt, 'y', 'IgnoreCase', true);
z = contains(rotOpt, 'z', 'IgnoreCase', true);
rotAxes = [x, y, z];
end
% Beginning file number is 1
fileNum = 1;
% Format file name as run#-geiger-#.csv
fileName = strcat('run', int2str(runNum), '-imu-', int2str(fileNum), '.csv');
data = [];
% While data files exist, store timestamps of radiation events
while exist(fileName, 'file')
% Print starting time if first file
if fileNum == 1
startTime = csvread(fileName,0,0,[0,0,0,0]);
fprintf('Starting time (Unix epoch): %d\n', startTime);
end
%read data
data = [data; csvread(fileName, 1, 0)];
fileNum = fileNum + 1;
fileName = strcat('run', int2str(runNum), '-imu-', int2str(fileNum), '.csv');
end
% Display an error if file not found
if fileNum == 1
errorMessage = strcat('File "', fileName, '" not found');
error(errorMessage);
end
% Remove last datapoint to remove potentially incomplete data
data(end,:) = [];
time = data(:,1);
accelX = data(:,2);
accelY = data(:,3);
accelZ = data(:,4);
rotX = data(:,5);
rotY = data(:,6);
rotZ = data(:,7);
% Plot acceleration data
subplot(2, 1, 1);
accelLeg = {};
if accelAxes(1)
plot(time, accelX, 'Color', [0, 0.447, 0.7410]);
accelLeg = [accelLeg, cellstr('x')];
hold on
end
if accelAxes(2)
plot(time, accelY, 'Color', [0.85, 0.325, 0.098]);
accelLeg = [accelLeg, cellstr('y')];
hold on
end
if accelAxes(3)
plot(time, accelZ, 'Color', [0.929, 0.694, 0.125]);
accelLeg = [accelLeg, cellstr('z')];
hold on
end
hold off
title('Acceleration Data');
xlabel('Time since start (ms)');
ylabel('Acceleration (m/s^2)');
legend(accelLeg);
% Plot rotation data
subplot(2, 1, 2);
rotLeg = {};
if rotAxes(1)
plot(time, rotX, 'Color', [0, 0.447, 0.7410]);
rotLeg = [rotLeg, cellstr('x')];
hold on
end
if rotAxes(2)
plot(time, rotY, 'Color', [0.85, 0.325, 0.098]);
rotLeg = [rotLeg, cellstr('y')];
hold on
end
if rotAxes(3)
plot(time, rotZ, 'Color', [0.929, 0.694, 0.125]);
rotLeg = [rotLeg, cellstr('z')];
hold on
end
hold off
title('Rotation Data');
xlabel('Time since start (ms)');
ylabel('Rotation (deg)');
legend(rotLeg);