4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "../../orientation_sensor.h"
27 #define ORIENTATION_DATA_PATH "../../../design/data/100ms/orientation/roll_pitch_yaw/"
28 #define ORIENTATION_DATA_SIZE 1095
32 int data_available = ORIENTATION_DATA_SIZE;
33 ifstream accel_in, gyro_in, mag_in;
35 string line_accel, line_gyro, line_magnetic;
37 unsigned long long time_stamp;
38 euler_angles<float> orientation;
39 rotation_matrix<float> orientation_mat;
40 quaternion<float> orientation_quat;
41 orientation_sensor orien_sensor1, orien_sensor2, orien_sensor3;
43 accel_in.open(((string)ORIENTATION_DATA_PATH + (string)"accel.txt").c_str());
44 gyro_in.open(((string)ORIENTATION_DATA_PATH + (string)"gyro.txt").c_str());
45 mag_in.open(((string)ORIENTATION_DATA_PATH + (string)"magnetic.txt").c_str());
47 orien_file.open(((string)"orientation.txt").c_str());
51 while (data_available-- > 0)
53 getline(accel_in, line_accel);
54 sdata[0] = strtof(line_accel.c_str(), &token);
55 sdata[1] = strtof(token, &token);
56 sdata[2] = strtof(token, &token);
57 time_stamp = strtoull (token, NULL, 10);
58 sensor_data<float> accel_data(sdata[0], sdata[1], sdata[2], time_stamp);
60 cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n";
62 getline(gyro_in, line_gyro);
63 sdata[0] = strtof(line_gyro.c_str(), &token);
64 sdata[1] = strtof(token, &token);
65 sdata[2] = strtof(token, &token);
66 time_stamp = strtoull (token, NULL, 10);
67 sensor_data<float> gyro_data(sdata[0], sdata[1], sdata[2], time_stamp);
69 cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n";
71 getline(mag_in, line_magnetic);
72 sdata[0] = strtof(line_magnetic.c_str(), &token);
73 sdata[1] = strtof(token, &token);
74 sdata[2] = strtof(token, &token);
75 time_stamp = strtoull (token, NULL, 10);
76 sensor_data<float> magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp);
78 cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n";
80 orientation = orien_sensor1.get_orientation(accel_data, gyro_data, magnetic_data);
82 orien_file << orientation.m_ang;
84 cout << "Orientation angles\t" << orientation.m_ang << "\n\n";
86 orientation_mat = orien_sensor2.get_rotation_matrix(accel_data, gyro_data, magnetic_data);
88 cout << "Orientation matrix\t" << orientation_mat.m_rot_mat << "\n\n";
90 orientation_quat = orien_sensor3.get_quaternion(accel_data, gyro_data, magnetic_data);
92 cout << "Orientation quaternion\t" << orientation_quat.m_quat << "\n\n";