Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
oriDiff.m
Go to the documentation of this file.
1%> @brief this function calculates the difference between estimated and true
2%> orientations. the initial yaw is aligned first.
3%>
4%> @param ori_est - estimated orientations (quaternion vector)
5%> @param ori_true - true orientations (quaternion vector)
6%>
7%> @retval d - orientation differences in degrees (vector)
8%> @retval ori_est - estimated orientations after yaw alignment (quaternion vector)
9%>
10%> @file oriDiff.m
11%>
12%> @copyright see the file @ref LICENSE in the root directory of the repository
13function [d, ori_est] = oriDiff(ori_est, ori_true)
14
15arguments
16 ori_est (:,1) quaternion
17 ori_true (:,1) quaternion
18end
19
20assert(length(ori_est) == length(ori_true), "Length of orientations must be equal");
21
22% initial reference yaw
23ref_yaw = ori_true(1).eulerd("ZYX", "frame");
24ref_yaw = ref_yaw(1);
25
26% Initial estimation yaw
27est_yaw = ori_est(1).eulerd("ZYX", "frame");
28est_yaw = est_yaw(1);
29
30% align initial yaw
31diff = ref_yaw - est_yaw;
32q_corr = quaternion([diff,0,0], "eulerd", "ZYX", "frame");
33
34% apply correction
35ori_est = q_corr .* ori_est;
36
37% calculate differences
38d = ori_est.conj .* ori_true;
39
40% get absolute differende
41d = 2*acos(d.normalize.parts) * 180 / pi;
42d = mod(d + 180, 360) - 180;
43
44end
function oriDiff(in ori_est, in ori_true)