-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
82 lines (66 loc) · 2.21 KB
/
utils.cpp
File metadata and controls
82 lines (66 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "utils.hpp"
#include <sstream>
#include <fstream>
#include <cmath>
#include <iostream>
Eigen::MatrixXd loadIMUData(const std::string& filePath)
{
// Open the file
std::ifstream file(filePath);
if (!file.is_open()) {
std::cerr << "Error opening IMU data file!" << std::endl;
exit(EXIT_FAILURE); // Exit if the file can't be opened
}
std::vector<std::vector<double>> data;
std::string line;
// Read each line of the file
while (std::getline(file, line)) {
std::stringstream ss(line);
std::vector<double> row;
std::string value;
// Read the values in each line (assuming comma-separated values)
while (std::getline(ss, value, ',')) {
row.push_back(std::stod(value));
}
data.push_back(row);
}
// Close the file
file.close();
// Convert to Eigen matrix
Eigen::MatrixXd imuData(data.size(), data[0].size());
for (size_t i = 0; i < data.size(); ++i) {
for (size_t j = 0; j < data[i].size(); ++j) {
imuData(i, j) = data[i][j];
}
}
return imuData; // Return the loaded data as an Eigen matrix
}
Eigen::Matrix3d cross_prod(const Eigen::Vector3d& v)
{
Eigen::Matrix3d S;
S << 0, -v(2), v(1),
v(2), 0, -v(0),
-v(1), v(0), 0;
return S;
}
// Function to compute the rotation matrix from Inertial to NED frame
Matrix3d inertialToNED(const Vector3d& r)
{
// Normalize the inertial position vector
Vector3d id = -r.normalized(); // Inertial to Earth frame (downward direction)
// Define the unit vector along the z-axis (upward)
Vector3d iz(0, 0, 1);
// Compute the East unit vector (cross product of id and iz)
Vector3d E = id.cross(iz);
Vector3d ie = E.normalized(); // Normalize the East vector
// Compute the North unit vector (cross product of ie and id)
Vector3d in = ie.cross(id);
// Construct the transformation matrix from Inertial to NED frame
Matrix3d T;
T << in, ie, id;
return T;
}
double deg2rad(double degrees)
{
return degrees * (M_PI / 180.0);
}