-
Notifications
You must be signed in to change notification settings - Fork 0
/
general.cpp
41 lines (29 loc) · 973 Bytes
/
general.cpp
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
//
// Created by arnoud on 5-3-19.
//
#include "general.h"
/*
* let the input be [Thrust, torqueX, torqueY, torqueZ]
*/
Vector4d torquesToThrusts(Vector4d torques){
// solving torques = M*thrusts
double c_q = 2.42e-7;
double c_t = 8.048e-6;
double d = 0.12;
double b = c_q/c_t;
Matrix4d diag;
diag << 1,0,0,0, 0,d,0,0, 0,0,d,0, 0,0,0,b;
Matrix4d signs;
signs << 1,1,1,1, 1,1,-1,-1, 1,-1,-1,1, -1,1,-1,1;
Matrix4d M = diag*signs;
Vector4d thrusts = M.colPivHouseholderQr().solve(torques);
return thrusts;
}
Matrix3d anglesToRotMatXYZ(double roll, double pitch, double yaw){
Eigen::AngleAxisd rollAngle(roll, Eigen::Vector3d::UnitX());
Eigen::AngleAxisd pitchAngle(pitch, Eigen::Vector3d::UnitY());
Eigen::AngleAxisd yawAngle(yaw, Eigen::Vector3d::UnitZ());
Eigen::Quaternion<double> q = yawAngle*pitchAngle*rollAngle;
Eigen::Matrix3d rotationMatrix = q.matrix();
return rotationMatrix;
}