RobotArmLib 0.0.6
Robot Arm Library [WIP]
Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1
7#ifndef RB_MATRIX_H_
8#define RB_MATRIX_H_
9#include "unit.h"
10
11#include <cmath>
12#include <Eigen/Dense>
13#include <Eigen/Geometry>
14
15namespace rb
16{
17namespace math
18{
19typedef Eigen::MatrixXd MatrixX;
20typedef Eigen::Matrix3d Matrix3;
21typedef Eigen::Matrix4d Matrix4;
22
23typedef Eigen::VectorXd VectorX;
24typedef Eigen::Vector3d Vector3;
25typedef Eigen::Vector4d Vector4;
26
27typedef Eigen::AngleAxisd AngleAxis;
28
30template <typename T, size_t R, size_t C>
31 using Array = Eigen::Array<T, R, C>;
32
34typedef Eigen::Array<double, 6, 1> Array6;
35
45inline Matrix4 homoTrans(const double& A, const double& alpha, const double& D, const double theta)
46{
47 double ct = cos(DEG2RAD * theta);
48 double st = sin(DEG2RAD * theta);
49 double ca = cos(DEG2RAD * alpha);
50 double sa = sin(DEG2RAD * alpha);
51
52 Matrix4 T;
53 T << ct, -st, 0, A,
54 st*ca, ct*ca, -sa, -sa*D,
55 st*sa, ct*sa, ca, ca*D,
56 0, 0, 0, 1;
57 return T;
58}
59
63inline Matrix4 rotateX(const double& rad)
64{
66 m33 = AngleAxis(rad, Vector3::UnitX());
67 Matrix4 m = Matrix4::Identity();
68 m.topLeftCorner(3, 3) << m33;
69 return m;
70}
71
75inline Matrix4 rotateY(const double& rad)
76{
78 m33 = AngleAxis(rad, Vector3::UnitY());
79 Matrix4 m = Matrix4::Identity();
80 m.topLeftCorner(3, 3) << m33;
81 return m;
82}
83
87inline Matrix4 rotateZ(const double& rad)
88{
90 m33 = AngleAxis(rad, Vector3::UnitZ());
91 Matrix4 m = Matrix4::Identity();
92 m.topLeftCorner(3, 3) << m33;
93 return m;
94}
95
104inline void tr2rpy(const Matrix4& m, double& roll_z, double& pitch_y, double& yaw_x)
105{
106 if (fabs(m(0,0)) < EPSILON && fabs(m(1,0)) < EPSILON)
107 {
108 roll_z = 0;
109 pitch_y = atan2(-m(2,0), m(0,0));
110 yaw_x = atan2(-m(1,2), m(1,1));
111 }
112 else
113 {
114 roll_z = atan2(m(1,0), m(0,0));
115 double sr = sin(roll_z);
116 double cr = cos(roll_z);
117 pitch_y = atan2(-m(2,0), cr * m(0,0) + sr * m(1,0));
118 yaw_x = atan2(sr * m(0,2) - cr * m(1,2), cr * m(1,1) - sr * m(0,1));
119 }
120}
121
130inline void rpy2tr(const double& roll_z, const double& pitch_y, const double& yaw_x, Matrix4& out)
131{
133}
134
135} // namespace math
136} // namespace rb
137
138#endif // RB_MATRIX_H_
139
void rpy2tr(const double &roll_z, const double &pitch_y, const double &yaw_x, Matrix4 &out)
Build a homogeneous transformation matrix from Roll-Pitch-Yaw angles (Z-Y-X Euler) given in radians.
Definition matrix.h:130
void tr2rpy(const Matrix4 &m, double &roll_z, double &pitch_y, double &yaw_x)
Extract Roll-Pitch-Yaw (Z-Y-X Euler) angles in radians from a homogeneous transformation matrix.
Definition matrix.h:104
Eigen::Array< T, R, C > Array
make Array as alias of Eigen::Array (class template)
Definition matrix.h:31
Eigen::Array< double, 6, 1 > Array6
make Array6 as alias of Eigen::Array<double, 6, 1>
Definition matrix.h:34
Eigen::Matrix3d Matrix3
make Matrix3 as alias of Eigen::Matrix3d
Definition matrix.h:20
Eigen::Matrix4d Matrix4
make Matrix4 as alias of Eigen::Matrix4d
Definition matrix.h:21
static const double EPSILON
Constant as critera if some variable close enough to zero.
Definition unit.h:25
Eigen::MatrixXd MatrixX
make MatrixX as alias of Eigen::MatrixXd
Definition matrix.h:19
Matrix4 rotateX(const double &rad)
Compute rotation matrix about X axis for given angle in radians.
Definition matrix.h:63
Matrix4 homoTrans(const double &A, const double &alpha, const double &D, const double theta)
Compute homogeneous transformation matrix for given link properties, and return the matrix.
Definition matrix.h:45
Matrix4 rotateY(const double &rad)
Compute rotation matrix about Y axis for given angle in radians.
Definition matrix.h:75
Matrix4 rotateZ(const double &rad)
Compute rotation matrix about Z axis for given angle in radians.
Definition matrix.h:87
Eigen::VectorXd VectorX
make VectorX as alias of Eigen::VectorXd
Definition matrix.h:23
static const double DEG2RAD
Constant to present converting from degree to radian.
Definition unit.h:22
Eigen::AngleAxisd AngleAxis
make AngleAxis as alias of Eigen::AngleAxisd
Definition matrix.h:27
Eigen::Vector4d Vector4
make Vector4 as alias of Eigen::Vector4d
Definition matrix.h:25
Eigen::Vector3d Vector3
make Vector3 as alias of Eigen::Vector3d
Definition matrix.h:24
Robot Arm Library namespace.
Definition artic.cpp:13
A head file for converting units.