Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
jumpSensorExample.m
Go to the documentation of this file.
1% =========================================================================== %
2%> @example jumpSensorExample.m
3%>
4%> This example shows how to use the JumpSensor class to generate data from
5%> the sensor. The example generates data for a sensor laying on a flat
6%> surface, a sensor in free fall and a sensor in free fall with rotation.
7%> The data is then plotted.
8% =========================================================================== %
9
10clc; clear; close all;
11
12numsamples = 10000;
13
14%% Create an instance of the JumpSensor class
15js = JumpSensor();
16
17%% first simple data: sensor laying on a flat surface
18% the sensor is laying on a flat surface, so it is not accelerating nor
19% rotating
20
21% create ground truth data
22acc = zeros(numsamples,3);
23gyr = zeros(numsamples,3);
24ori = quaternion.ones(numsamples,1);
25%ori = quaternion(repmat([0,1,0,0], numsamples,1)); % z axis pointing upwards
26%ori = quaternion(repmat([1/sqrt(2), 0, 1/sqrt(2), 0], numsamples,1)); % x axis pointing towards the sky
27%ori = quaternion(repmat([1/sqrt(2), 1/sqrt(2), 0, 0], numsamples,1)); % y axis pointing downwards
28
29% generate data
30out1 = js.generate(acc, gyr, ori, simulate_hig=false);
31
32% plot data
33plotData(out1, 'Sensor laying on a flat surface');
34
35%% second simple data: sensor in free fall
36% the sensor is in free fall, so it is accelerating downwards, but not
37% rotating (Assuming Vacuum)
38
39% create ground truth data (NED frame)
40acc = repmat([0, 0, 9.81], numsamples, 1);
41gyr = zeros(numsamples,3);
42ori = quaternion.ones(numsamples,1);
43
44% generate data
45out2 = js.generate(acc, gyr, ori);
46
47% plot data
48plotData(out2, 'Sensor in free fall');
49
50% =========================================================================== %
51%> @brief plots the data generated by the JumpSensor class
52%>
53%> @param data: struct with the data generated by the JumpSensor class
54%> according to the format defined in @ref jumpReadData.m
55%>
56%> @param titName: title of the figure
57%>
58%> @retval none
59% =========================================================================== %
60function plotData(data, titName)
61 figure('WindowState', 'maximized', 'Name', titName);
62
63 % accelerometer
64 subplot(221);
65 plot(data.tt.t, data.tt.acc, data.tt.t, data.tt.hig);
66 title("Accelerometer data");
67 xlabel('Time');
68 ylabel('Acceleration [m/s^2]');
69 legend('x_{mpu}', 'y_{mpu}', 'z_{mpu}', 'x_{hig}', 'y_{hig}', 'z_{hig}');
70 grid on;
71
72 % gyroscope
73 subplot(222);
74 plot(data.tt.t, data.tt.gyr);
75 title('Gyroscope data');
76 xlabel('Time');
77 ylabel('Angular velocity [°/s]');
78 legend('x', 'y', 'z');
79 grid on;
80
81 % magnetometer
82 subplot(223);
83 plot(data.tt.t, data.tt.mag);
84 title('Magnetometer data');
85 xlabel('Time');
86 ylabel('Magnetic field [uT]');
87 legend('x', 'y', 'z');
88 grid on;
89
90 % pressure and temperature
91 subplot(224);
92 plot(data.tt.t, data.tt.prs);
93 title('Pressure and temperature data');
94 xlabel('Time');
95 ylabel('Pressure [hPa]');
96 yyaxis right;
97 plot(data.tt.t, data.tt.tmp);
98 ylabel('Temperature [°C]');
99 legend('Pressure', 'Temperature');
100 grid on;
101end
JumpSensor is a simulation of the JUMP sensor of the ZurichMove Project.
Definition JumpSensor.m:41
function jumpReadData(in filePath, in options)
function plotData(in data, in titName)
plots the data generated by the JumpSensor class