Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
jumpSensorExample.m

This example shows how to use the JumpSensor class to generate data from the sensor.

This example shows how to use the JumpSensor class to generate data from the sensor. The example generates data for a sensor laying on a flat surface, a sensor in free fall and a sensor in free fall with rotation. The data is then plotted.

% =========================================================================== %
%> @example jumpSensorExample.m
%>
%> This example shows how to use the JumpSensor class to generate data from
%> the sensor. The example generates data for a sensor laying on a flat
%> surface, a sensor in free fall and a sensor in free fall with rotation.
%> The data is then plotted.
% =========================================================================== %
clc; clear; close all;
numsamples = 10000;
%% Create an instance of the JumpSensor class
js = JumpSensor();
%% first simple data: sensor laying on a flat surface
% the sensor is laying on a flat surface, so it is not accelerating nor
% rotating
% create ground truth data
acc = zeros(numsamples,3);
gyr = zeros(numsamples,3);
ori = quaternion.ones(numsamples,1);
%ori = quaternion(repmat([0,1,0,0], numsamples,1)); % z axis pointing upwards
%ori = quaternion(repmat([1/sqrt(2), 0, 1/sqrt(2), 0], numsamples,1)); % x axis pointing towards the sky
%ori = quaternion(repmat([1/sqrt(2), 1/sqrt(2), 0, 0], numsamples,1)); % y axis pointing downwards
% generate data
out1 = js.generate(acc, gyr, ori, simulate_hig=false);
% plot data
plotData(out1, 'Sensor laying on a flat surface');
%% second simple data: sensor in free fall
% the sensor is in free fall, so it is accelerating downwards, but not
% rotating (Assuming Vacuum)
% create ground truth data (NED frame)
acc = repmat([0, 0, 9.81], numsamples, 1);
gyr = zeros(numsamples,3);
ori = quaternion.ones(numsamples,1);
% generate data
out2 = js.generate(acc, gyr, ori);
% plot data
plotData(out2, 'Sensor in free fall');
% =========================================================================== %
%> @brief plots the data generated by the JumpSensor class
%>
%> @param data: struct with the data generated by the JumpSensor class
%> according to the format defined in @ref jumpReadData.m
%>
%> @param titName: title of the figure
%>
%> @retval none
% =========================================================================== %
function plotData(data, titName)
figure('WindowState', 'maximized', 'Name', titName);
% accelerometer
subplot(221);
plot(data.tt.t, data.tt.acc, data.tt.t, data.tt.hig);
title("Accelerometer data");
xlabel('Time');
ylabel('Acceleration [m/s^2]');
legend('x_{mpu}', 'y_{mpu}', 'z_{mpu}', 'x_{hig}', 'y_{hig}', 'z_{hig}');
grid on;
% gyroscope
subplot(222);
plot(data.tt.t, data.tt.gyr);
title('Gyroscope data');
xlabel('Time');
ylabel('Angular velocity [°/s]');
legend('x', 'y', 'z');
grid on;
% magnetometer
subplot(223);
plot(data.tt.t, data.tt.mag);
title('Magnetometer data');
xlabel('Time');
ylabel('Magnetic field [uT]');
legend('x', 'y', 'z');
grid on;
% pressure and temperature
subplot(224);
plot(data.tt.t, data.tt.prs);
title('Pressure and temperature data');
xlabel('Time');
ylabel('Pressure [hPa]');
yyaxis right;
plot(data.tt.t, data.tt.tmp);
ylabel('Temperature [°C]');
legend('Pressure', 'Temperature');
grid on;
end
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