3 % Copyright (c) 2015 Samsung Electronics Co., Ltd.
5 % Licensed under the Apache License, Version 2.0 (the "License");
6 % you may not use this file except in compliance with the License.
7 % You may obtain a copy of the License at
9 % http://www.apache.org/licenses/LICENSE-2.0
11 % Unless required by applicable law or agreed to in writing, software
12 % distributed under the License is distributed on an "AS IS" BASIS,
13 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 % See the License for the specific language governing permissions and
15 % limitations under the License.
17 % Sensor Fusion Implementation for Determination of Geomagentic rotation Vector
19 % - Input Accelerometer and Magnetometer sensor data
20 % - Call estimate_geomagnetic_rotation
21 % - Plot results for geomagetic rotation on reference axis
30 Max_Range_Accel = 39.203407; Min_Range_Accel = -39.204006; Res_Accel = 0.000598;
31 Max_Range_Magnetic = 1200; Min_Range_Magnetic = -1200; Res_Magnetic = 1;
35 Bias_Az = 10.084 - GRAVITY;
47 Accel_data = zeros(4,BUFFER_SIZE);
48 Mag_data = zeros(4,BUFFER_SIZE);
50 Geo_RV = zeros(4,BUFFER_SIZE);
51 Orientation_RV = zeros(3,BUFFER_SIZE);
53 % Sensor Data simulating orientation motions
55 % get accel x,y,z axis data from stored file
56 Accel_data(1,:) = (((dlmread("data/100ms/orientation/roll_pitch_yaw/accel.txt")(:,1))') - Bias_Ax)(1:BUFFER_SIZE);
57 Accel_data(2,:) = (((dlmread("data/100ms/orientation/roll_pitch_yaw/accel.txt")(:,2))') - Bias_Ay)(1:BUFFER_SIZE);
58 Accel_data(3,:) = (((dlmread("data/100ms/orientation/roll_pitch_yaw/accel.txt")(:,3))') - Bias_Az)(1:BUFFER_SIZE);
59 Accel_data(4,:) = ((dlmread("data/100ms/orientation/roll_pitch_yaw/accel.txt")(:,4))')(1:BUFFER_SIZE);
61 % get magnetometer x,y,z axis data from stored file
62 Mag_data(1,:) = (((dlmread("data/100ms/orientation/roll_pitch_yaw/magnetic.txt")(:,1))') + Bias_Mx)(1:BUFFER_SIZE) * Sign_Mx;
63 Mag_data(2,:) = (((dlmread("data/100ms/orientation/roll_pitch_yaw/magnetic.txt")(:,2))') + Bias_My)(1:BUFFER_SIZE) * Sign_My;
64 Mag_data(3,:) = (((dlmread("data/100ms/orientation/roll_pitch_yaw/magnetic.txt")(:,3))') + Bias_Mz)(1:BUFFER_SIZE) * Sign_Mz;
65 Mag_data(4,:) = ((dlmread("data/100ms/orientation/roll_pitch_yaw/magnetic.txt")(:,4))')(1:BUFFER_SIZE);
67 % estimate orientation
68 Geo_RV = estimate_geomagnetic_rv(Accel_data, Mag_data);
71 Orientation_RV(:,i) = quat2euler(Geo_RV(i,:));
75 scrsz = get(0,'ScreenSize');
76 set(hfig,'position',scrsz);
77 % Geomagnetic Rotation Vector Plot Results
79 UA = Orientation_RV(1,:);
80 p1 = plot(1:length(UA),UA(1,1:length(UA)),'k');
84 UA = Orientation_RV(2,:);
85 p1 = plot(1:length(UA),UA(1,1:length(UA)),'b');
89 UA = Orientation_RV(3,:);
90 p1 = plot(1:length(UA),UA(1,1:length(UA)),'r');