1 #include "header/formulas.h" 3 Eigen::Matrix3d FRM::skewMat(Eigen::Vector3d vect){
6 skew << 0, -vect(2), vect(1),
19 Eigen::Vector3d FRM::reducedVersorLemma(Eigen::Vector3d a, Eigen::Vector3d b){
21 Eigen::Vector3d misalign;
23 Eigen::Vector3d vsinth = a.cross(b);
24 double costh = a.dot(b);
26 double sinth = vsinth.norm();
28 if (sinth > 0.00000000001){
29 double theta = atan2(sinth, costh);
30 misalign = (vsinth * (theta/sinth));
41 Eigen::Matrix4d FRM::invertTransf(Eigen::Matrix4d mat){
43 Eigen::Matrix4d inv = Eigen::Matrix4d::Identity();
46 Eigen::Matrix3d rot_t = mat.topLeftCorner<3,3>().transpose();
47 inv.topLeftCorner<3,3>() = rot_t;
49 inv.topRightCorner<3,1>() = - rot_t * mat.topRightCorner<3,1>();
56 Eigen::MatrixXd FRM::pseudoInverse(Eigen::MatrixXd mat,
double tolerance){
58 Eigen::JacobiSVD<Eigen::MatrixXd> svd(mat, Eigen::ComputeFullU | Eigen::ComputeFullV);
59 Eigen::MatrixXd S_inv(mat.cols(), mat.rows());
60 Eigen::MatrixXd singularValues = svd.singularValues();
61 S_inv = Eigen::MatrixXd::Zero(mat.cols(), mat.rows());
62 for (
int i=0; i< singularValues.size(); ++i){
63 if (singularValues(i) > tolerance) {
64 S_inv(i, i) = 1 / singularValues(i);
71 return (svd.matrixV() * S_inv * svd.matrixU().transpose());
84 Eigen::VectorXd FRM::saturateVectorEigen(Eigen::VectorXd vector,
double threshold){
87 std::cerr <<
"FRM::saturateVectorEigen: ERROR: the threshold must be positive";
90 Eigen::VectorXd out = vector;
93 for (
int i =0; i< vector.rows(); i++){
99 double maxCoeff = vector.maxCoeff();
100 if ( maxCoeff > threshold){
102 out = out/maxCoeff*threshold;
109 std::vector<double> FRM::saturateVectorStd(std::vector<double> vector,
double threshold){
112 std::cerr <<
"FRM::saturateVectorStd: ERROR: the threshold must be positive";
115 std::vector<double> out = vector;
118 for (
int i =0; i< vector.size(); i++){
119 if (vector.at(i) < 0.0){
124 double maxCoeff = *(std::max_element(vector.begin(), vector.end()));
125 if ( maxCoeff > threshold){
127 for (
int i=0; i<out.size(); i++){
128 out.at(i) = (out.at(i))/maxCoeff*threshold;
138 CMAT::Matrix FRM::saturateCmat(CMAT::Matrix mat,
double threshold){
140 std::cerr <<
"FRM::saturateCmat: ERROR: the threshold must be positive";
144 CMAT::Matrix out = mat;
147 double maxCoeff = 0.0;
148 for (
int i=1; i<= mat.GetNumColumns(); i++){
149 for (
int j=1; j<= mat.GetNumRows(); j++){
153 if (mat(j,i) > maxCoeff){
159 if ( maxCoeff > threshold){
160 out = out/maxCoeff*threshold;
166 double FRM::saturateScalar(
double scalar,
double threshold){
169 std::cerr <<
"FRM::saturateScalar: ERROR: the threshold must be positive";
175 if (scalar < (-threshold) ) {
180 if (scalar > threshold){
189 Eigen::Matrix3d FRM::eul2Rot(std::vector<double> eulRad){
191 Eigen::Matrix3d R_x, R_y, R_z;
194 0, cos(eulRad.at(0)), -sin(eulRad.at(0)),
195 0, sin(eulRad.at(0)), cos(eulRad.at(0));
197 R_y << cos(eulRad.at(1)), 0, sin(eulRad.at(1)),
199 -sin(eulRad.at(1)), 0, cos(eulRad.at(1));
201 R_z << cos(eulRad.at(2)), -sin(eulRad.at(2)), 0,
202 sin(eulRad.at(2)), cos(eulRad.at(2)), 0,
206 return (R_x * R_y * R_z);