6 #ifndef __RDL_MATHUTILS_H__
7 #define __RDL_MATHUTILS_H__
52 for (
unsigned int i = 0; i < n; i++)
66 for (
unsigned int i = 0; i < rows; i++)
68 for (
unsigned int j = 0; j < cols; j++)
70 result(i, j) = ptr[i * cols + j];
76 for (
unsigned int i = 0; i < rows; i++)
78 for (
unsigned int j = 0; j < cols; j++)
80 result(i, j) = ptr[i + j * rows];
102 double sy = sin(zyx_angles[1]);
103 double cy = cos(zyx_angles[1]);
104 double sx = sin(zyx_angles[2]);
105 double cx = cos(zyx_angles[2]);
107 return Vector3d(zyx_angle_rates[2] - sy * zyx_angle_rates[0], cx * zyx_angle_rates[1] + sx * cy * zyx_angle_rates[0],
108 -sx * zyx_angle_rates[1] + cx * cy * zyx_angle_rates[0]);
119 double s1 = sin(xyz_angles[1]);
120 double c1 = cos(xyz_angles[1]);
121 double s2 = sin(xyz_angles[2]);
122 double c2 = cos(xyz_angles[2]);
124 return Vector3d(c2 * c1 * xyz_angle_rates[0] + s2 * xyz_angle_rates[1], -s2 * c1 * xyz_angle_rates[0] + c2 * xyz_angle_rates[1],
125 s1 * xyz_angle_rates[0] + xyz_angle_rates[2]);
138 double c1 = cos(zyx_angles[1]);
139 double t1 = tan(zyx_angles[1]);
140 double s2 = sin(zyx_angles[2]);
141 double c2 = cos(zyx_angles[2]);
143 if (c1 < singularity_threshold)
146 std::cerr <<
"Domain error - unable to convert angular velocities to ZYX euler rates with pitch = pi/2" << std::endl;
150 return Matrix3d(0., s2 / c1, c2 / c1, 0., c2, -s2, 1., s2 * t1, c2 * t1);
163 double c1 = cos(xyz_angles[1]);
164 double t1 = tan(xyz_angles[1]);
165 double s2 = sin(xyz_angles[2]);
166 double c2 = cos(xyz_angles[2]);
168 if (c1 < singularity_threshold)
171 std::cerr <<
"Domain error - unable to convert angular velocities to XYZ euler rates with pitch = pi/2" << std::endl;
175 return Matrix3d(c2 / c1, -s2 / c1, 0., s2, c2, 0., -c2 * t1, s2 * t1, 1.);
188 double c1 = cos(zyx_angles[1]);
189 double t1 = tan(zyx_angles[1]);
190 double s2 = sin(zyx_angles[2]);
191 double c2 = cos(zyx_angles[2]);
193 if (c1 < singularity_threshold)
196 std::cerr <<
"unable to compute angle rates from angular velocity due to singularity" << std::endl;
200 return Vector3d((s2 / c1) * angular_velocity[1] + (c2 / c1) * angular_velocity[2], c2 * angular_velocity[1] - s2 * angular_velocity[2],
201 angular_velocity[0] + s2 * t1 * angular_velocity[1] + c2 * t1 * angular_velocity[2]);
214 double c1 = cos(xyz_angles[1]);
215 double t1 = tan(xyz_angles[1]);
216 double s2 = sin(xyz_angles[2]);
217 double c2 = cos(xyz_angles[2]);
219 if (c1 < singularity_threshold)
222 std::cerr <<
"unable to compute jacobian matrix for XYZ angles" << std::endl;
226 return Vector3d((c2 / c1) * angular_velocity[0] - (s2 / c1) * angular_velocity[1], s2 * angular_velocity[0] + c2 * angular_velocity[1],
227 -c2 * t1 * angular_velocity[0] + s2 * t1 * angular_velocity[1] + angular_velocity[2]);
232 double s0, c0, s1, c1;
233 s0 = sin(zyx_angles[0]);
234 c0 = cos(zyx_angles[0]);
235 s1 = sin(zyx_angles[1]);
236 c1 = cos(zyx_angles[1]);
238 Matrix3d RzT(c0, s0, 0., -s0, c0, 0., 0., 0., 1.);
239 RzT.transposeInPlace();
240 Matrix3d RyT(c1, 0., -s1, 0., 1., 0., s1, 0., c1);
241 RyT.transposeInPlace();
256 double sy = sin(zyx_angles[1]);
257 double cy = cos(zyx_angles[1]);
258 double sx = sin(zyx_angles[2]);
259 double cx = cos(zyx_angles[2]);
260 double xdot = zyx_angle_rates[2];
261 double ydot = zyx_angle_rates[1];
262 double zdot = zyx_angle_rates[0];
263 double xddot = zyx_angle_rates_dot[2];
264 double yddot = zyx_angle_rates_dot[1];
265 double zddot = zyx_angle_rates_dot[0];
267 return Vector3d(xddot - (cy * ydot * zdot + sy * zddot), -sx * xdot * ydot + cx * yddot + cx * xdot * cy * zdot + sx * (-sy * ydot * zdot + cy * zddot),
268 -cx * xdot * ydot - sx * yddot - sx * xdot * cy * zdot + cx * (-sy * ydot * zdot + cy * zddot));
281 double s1 = sin(xyz_angles[1]);
282 double c1 = cos(xyz_angles[1]);
283 double s2 = sin(xyz_angles[2]);
284 double c2 = cos(xyz_angles[2]);
286 double xdot = xyz_angle_rates[0];
287 double ydot = xyz_angle_rates[1];
288 double zdot = xyz_angle_rates[2];
290 double xddot = xyz_angle_rates_dot[0];
291 double yddot = xyz_angle_rates_dot[1];
292 double zddot = xyz_angle_rates_dot[2];
293 return Vector3d(c2 * c1 * xddot + s2 * yddot + (-s2 * c1 * zdot - c2 * s1 * ydot) * xdot + c2 * zdot * ydot,
294 -s2 * c1 * xddot + c2 * yddot + (-c2 * c1 * zdot + s2 * s1 * ydot) * xdot - s2 * zdot * ydot, s1 * xddot + zddot + c1 * ydot * xdot);
Definition: rdl_eigenmath.hpp:104
Quaternion that are used for singularity free joints.
Definition: rdl_eigenmath.hpp:614
Definition: rdl_eigenmath.hpp:354
Definition: rdl_eigenmath.hpp:187
Definition: rdl_eigenmath.hpp:54
bool linSolveGaussElimPivot(MatrixNd A, VectorNd b, VectorNd &x)
Solves a linear system using gaussian elimination with pivoting.
Definition: rdl_mathutils.cpp:32
SpatialMatrix SpatialMatrixIdentity(1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1.)
Definition: rdl_mathutils.hpp:44
void SparseMultiplyLTx(Model &model, Math::MatrixNd &L)
SpatialVector SpatialVectorZero(0., 0., 0., 0., 0., 0.)
Definition: rdl_mathutils.hpp:43
Matrix3d angular_velocity_to_zyx_angle_rates_jacobian(const Vector3d &zyx_angles, double singularity_threshold=1.e-10)
compute the 3x3 jacobian matrix that when multiplied by the angular velocity, ordered (wx,...
Definition: rdl_mathutils.hpp:136
LinearSolver
Available solver methods for the linear systems.
Definition: rdl_mathutils.hpp:29
@ LinearSolverLLT
Definition: rdl_mathutils.hpp:34
@ LinearSolverHouseholderQR
Definition: rdl_mathutils.hpp:33
@ LinearSolverLast
Definition: rdl_mathutils.hpp:35
@ LinearSolverPartialPivLU
Definition: rdl_mathutils.hpp:31
@ LinearSolverUnknown
Definition: rdl_mathutils.hpp:30
@ LinearSolverColPivHouseholderQR
Definition: rdl_mathutils.hpp:32
Quaternion QuaternionIdentity(0., 0., 0., 1)
Definition: rdl_mathutils.hpp:41
Vector3d angular_acceleration_from_zyx_angle_rates(const Vector3d &zyx_angles, const Vector3d &zyx_angle_rates, const Vector3d &zyx_angle_rates_dot)
calculate angular acceleration from zyx angles, angle rates, and angle accelerations
Definition: rdl_mathutils.hpp:254
Matrix3d Matrix3dIdentity(1., 0., 0., 0., 1., 0., 0., 0., 1)
Definition: rdl_mathutils.hpp:39
void SparseFactorizeLTL(Model &model, Math::MatrixNd &H)
Definition: rdl_mathutils.cpp:129
MatrixNd matrixFromPtr(unsigned int rows, unsigned int cols, double *ptr, bool row_major=true)
Definition: rdl_mathutils.hpp:60
void SparseSolveLTx(Model &model, Math::MatrixNd &L, Math::VectorNd &x)
Definition: rdl_mathutils.cpp:177
Vector3d angular_velocity_to_zyx_angle_rates(const Vector3d &zyx_angles, const Vector3d &angular_velocity, double singularity_threshold=1.e-10)
convert angular velocity to zyx angle rates
Definition: rdl_mathutils.hpp:186
Vector3d Vector3dZero(0., 0., 0.)
Definition: rdl_mathutils.hpp:38
Vector3d angular_velocity_from_xyz_angle_rates(const Vector3d &xyz_angles, const Vector3d &xyz_angle_rates)
convert xyz euler angles and angle rates to angular velocity
Definition: rdl_mathutils.hpp:117
SpatialMatrix SpatialMatrixZero(0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.)
Definition: rdl_mathutils.hpp:45
void SparseMultiplyHx(Model &model, Math::MatrixNd &L)
Vector3d angular_acceleration_from_xyz_angle_rates(const Vector3d &xyz_angles, const Vector3d &xyz_angle_rates, const Vector3d &xyz_angle_rates_dot)
calculate angular acceleration from zyx angles, angle rates, and angle accelerations
Definition: rdl_mathutils.hpp:279
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.hpp:20
void SparseSolveLx(Model &model, Math::MatrixNd &L, Math::VectorNd &x)
Definition: rdl_mathutils.cpp:163
Vector3d global_angular_velocity_from_rates(const Vector3d &zyx_angles, const Vector3d &zyx_rates)
Definition: rdl_mathutils.hpp:230
VectorNd vectorFromPtr(unsigned int n, double *ptr)
Definition: rdl_mathutils.hpp:47
Vector3d angular_velocity_to_xyz_angle_rates(const Vector3d &xyz_angles, const Vector3d &angular_velocity, double singularity_threshold=1.e-10)
convert angular velocity to xyz angle rates
Definition: rdl_mathutils.hpp:212
Matrix3d angular_velocity_to_xyz_angle_rates_jacobian(const Vector3d &xyz_angles, double singularity_threshold=1.e-10)
compute the 3x3 jacobian matrix that when multiplied by the angular velocity, ordered (wx,...
Definition: rdl_mathutils.hpp:161
Matrix3d Matrix3dZero(0., 0., 0., 0., 0., 0., 0., 0., 0.)
Definition: rdl_mathutils.hpp:40
Vector3d angular_velocity_from_zyx_angle_rates(const Vector3d &zyx_angles, const Vector3d &zyx_angle_rates)
convert zyx euler angles and angle rates to angular velocity
Definition: rdl_mathutils.hpp:100
void SparseMultiplyLx(Model &model, Math::MatrixNd &L)
Matrix3d parallel_axis(const Matrix3d &inertia, double mass, const Vector3d &com)
Translates the inertia matrix to a new center.
Definition: rdl_mathutils.cpp:122
Eigen::MatrixXd MatrixNd
Definition: rdl_eigenmath.hpp:21
Namespace for all structures of the RobotDynamics library.
Definition: examples.hpp:19
Contains all information about the rigid body model.
Definition: Model.hpp:112