8 #include <math_utils/Core>
22 kindr::EulerAnglesZyxD
R1(yaw, pitch, roll);
24 ROS_INFO_STREAM(
"R1: " <<
R1);
26 kindr::RotationMatrixD rotation(
R1);
28 ROS_INFO_STREAM(
"Rotation: " << rotation);
32 ROS_INFO_STREAM(
"Position: " <<
position);
34 kindr::HomTransformMatrixD
t1(
position, rotation);
36 ROS_INFO_STREAM(
"t1: " <<
t1);
39 kindr::RotationMatrixD R_z(kindr::AngleAxisD(yaw,
Eigen::Vector3d(0,0,1)));
40 kindr::RotationMatrixD R_y(kindr::AngleAxisD(pitch,
Eigen::Vector3d(0,1,0)));
41 kindr::RotationMatrixD R_x(kindr::AngleAxisD(roll,
Eigen::Vector3d(1,0,0)));
43 kindr::RotationMatrixD
R2 = R_z*R_y*R_x;
45 kindr::HomTransformMatrixD
t2(
position, R_z*R_y*R_x);
47 ROS_INFO_STREAM(
"t2: " <<
t2);
58 kindr::RotationMatrixD R_z(kindr::AngleAxisD(z_angle, unit_z));
59 kindr::RotationMatrixD R_x(kindr::AngleAxisD(x_angle, unit_x));
61 kindr::RotationMatrixD R = R_z*R_x;
63 ROS_INFO_STREAM(
"R_z: \n" << R_z.matrix());
64 ROS_INFO_STREAM(
"R_x: \n" << R_x.matrix());
65 ROS_INFO_STREAM(
"R = R_z*R_x: \n" << R.matrix());
77 kindr::HomTransformMatrixD
t1 = K.
GetDhTransform(a_1, alpha_1, d_1, theta_1);
78 ROS_INFO_STREAM(
"t1: " <<
t1);
80 kindr::Position3D pos =
t1.transform(kindr::Position3D(0,0,0));
82 ROS_INFO_STREAM(
"pos: " << pos);
100 ROS_INFO_STREAM(
"pos: " << pos);
105 Eigen::Matrix<double, 6, 1> twist;
114 ROS_INFO_STREAM(
"twist: " << twist);
117 Eigen::Matrix<double, 3, 1> pos = twist.block(3,0,5,0);
119 ROS_INFO_STREAM(
"pos: " << pos);
124 ROS_INFO_STREAM(
"pos2: " << pos2);
131 kindr::HomTransformMatrixD transformHipToFoot = K.
GetHipToBodyTransform(Kinematics::LegType::frontLeft,
132 Kinematics::BodyType::foot,
137 kindr::Position3D hip_position(-0.151,0.185,1);
139 kindr::Position3D positionHipToFoot = transformHipToFoot.transform(kindr::Position3D(0,0,0));
141 Eigen::Vector3d f_pos = hip_position.vector() + positionHipToFoot.vector();
143 ROS_INFO_STREAM(
"f_pos: \n" << f_pos);
184 ROS_INFO_STREAM(
"h_pos: " << h_pos);
187 ROS_INFO_STREAM(
"f_pos: " << f_pos);
193 ROS_INFO_STREAM(
"joint_angles: " << joint_angles);
200 Twist q_b = Twist::Constant(0);
209 ROS_INFO_STREAM(
"q_b: " << q_b);
253 Kinematics::BodyType::foot,
256 Kinematics::BodyType::foot,
259 Kinematics::BodyType::foot,
262 Kinematics::BodyType::foot,
293 Eigen::Matrix<double, 3, 18> J_fl = K.
GetTranslationJacobianInW(Kinematics::LegType::frontLeft, Kinematics::BodyType::foot, q);
294 Eigen::Matrix<double, 3, 18> J_fr = K.
GetTranslationJacobianInW(Kinematics::LegType::frontRight, Kinematics::BodyType::foot, q);
295 Eigen::Matrix<double, 3, 18> J_rl = K.
GetTranslationJacobianInW(Kinematics::LegType::rearLeft, Kinematics::BodyType::foot, q);
296 Eigen::Matrix<double, 3, 18> J_rr = K.
GetTranslationJacobianInW(Kinematics::LegType::rearRight, Kinematics::BodyType::foot, q);
298 ROS_INFO_STREAM(
"Translation Jacobian front left, J_P: \n" << J_fl);
299 ROS_INFO_STREAM(
"Translation Jacobian front right, J_P: \n" << J_fr);
300 ROS_INFO_STREAM(
"Translation Jacobian rear left, J_P: \n" << J_rl);
301 ROS_INFO_STREAM(
"Translation Jacobian rear right, J_P: \n" << J_rr);
330 Eigen::Matrix<double, 3, 18> J_fl = K.
GetRotationJacobianInW(Kinematics::LegType::frontLeft, Kinematics::BodyType::foot, q);
331 Eigen::Matrix<double, 3, 18> J_fr = K.
GetRotationJacobianInW(Kinematics::LegType::frontRight, Kinematics::BodyType::foot, q);
332 Eigen::Matrix<double, 3, 18> J_rl = K.
GetRotationJacobianInW(Kinematics::LegType::rearLeft, Kinematics::BodyType::foot, q);
333 Eigen::Matrix<double, 3, 18> J_rr = K.
GetRotationJacobianInW(Kinematics::LegType::rearRight, Kinematics::BodyType::foot, q);
335 ROS_INFO_STREAM(
"Rotation Jacobian front left, J_R: \n" << J_fl);
336 ROS_INFO_STREAM(
"Rotation Jacobian front right, J_R: \n" << J_fr);
337 ROS_INFO_STREAM(
"Rotation Jacobian rear left, J_R: \n" << J_rl);
338 ROS_INFO_STREAM(
"Rotation Jacobian rear right, J_R: \n" << J_rr);
366 Eigen::Matrix<double, 3, 18> J_fb = K.
GetTranslationJacobianInW(Kinematics::LegType::NONE, Kinematics::BodyType::base, q);
367 Eigen::Matrix<double, 3, 18> J_fl = K.
GetTranslationJacobianInW(Kinematics::LegType::frontLeft, Kinematics::BodyType::foot, q);
368 Eigen::Matrix<double, 3, 18> J_fr = K.
GetTranslationJacobianInW(Kinematics::LegType::frontRight, Kinematics::BodyType::foot, q);
369 Eigen::Matrix<double, 3, 18> J_rl = K.
GetTranslationJacobianInW(Kinematics::LegType::rearLeft, Kinematics::BodyType::foot, q);
370 Eigen::Matrix<double, 3, 18> J_rr = K.
GetTranslationJacobianInW(Kinematics::LegType::rearRight, Kinematics::BodyType::foot, q);
372 ROS_INFO_STREAM(
"Jacobian floating base, J: \n" << J_fb);
373 ROS_INFO_STREAM(
"Jacobian front left, J: \n" << J_fl);
374 ROS_INFO_STREAM(
"Jacobian front right, J: \n" << J_fr);
375 ROS_INFO_STREAM(
"Jacobian rear left, J: \n" << J_rl);
376 ROS_INFO_STREAM(
"Jacobian rear right, J: \n" << J_rr);
405 Eigen::Matrix<double, 3, 18> J = K.
GetTranslationJacobianInW(Kinematics::LegType::rearRight, Kinematics::BodyType::base, q);
407 ROS_INFO_STREAM(
"Jacobian, J: \n" << J.transpose() * J);
438 ROS_INFO_STREAM(
"Mass matrix, M: \n" << M);
470 ROS_INFO_STREAM(
"Gravitational terms, g: \n" << g);
471 ROS_INFO_STREAM(
"Gravitational terms front left, g_fl: \n" << g_fl);
472 ROS_INFO_STREAM(
"Gravitational terms front_right, g_fr: \n" << g_fr);
521 Eigen::Matrix<double, 6, 18> rotationDiff = K.
GetJacobianInWDiff(Kinematics::LegType::frontLeft,
522 Kinematics::BodyType::foot,
526 ROS_INFO_STREAM(
"Rotation derivative, rotationDiff: \n" << rotationDiff);
576 ROS_INFO_STREAM(
"Coriolis and Centrifugal terms, b: \n" << CCTerms);
581 Eigen::Matrix<double, 2, 3> A;
586 Eigen::Matrix<double, 3, 3> N;
593 Eigen::Matrix<double, 3, 2> pinvA;
595 kindr::pseudoInverse(A, pinvA);
597 Eigen::Matrix<double, 3, 3> N_test = Eigen::Matrix<double, 3, 3>::Identity() - pinvA * A;
599 ROS_INFO_STREAM(
"Null-space projector, N: \n" << N);
600 ROS_INFO_STREAM(
"Null-space projector test, N: \n" << N_test);
601 ROS_INFO_STREAM(
"SVD Null-space projector, N_svd: \n" << N_svd <<
"\n\n");
603 ROS_INFO_STREAM(
"A*N = \n" << A*N <<
"\n");
604 ROS_INFO_STREAM(
"A*N_svd = \n" << A*N_svd <<
"\n");
609 Eigen::Matrix<double, 3, 3> A;
610 Eigen::Matrix<double, 6, 4> B;
611 Eigen::Matrix<double, 2, 3> C;
612 Eigen::Matrix<double, 5, 9> D;
631 ROS_INFO_STREAM(
"N_A = \n" << N_A <<
"\n\n\n");
632 ROS_INFO_STREAM(
"N_B = \n" << N_B <<
"\n\n\n");
633 ROS_INFO_STREAM(
"N_C = \n" << N_C <<
"\n\n\n");
634 ROS_INFO_STREAM(
"N_D = \n" << N_D <<
"\n\n\n");
636 ROS_INFO_STREAM(
"A*N_A = \n" << A*N_A <<
"\n\n");
637 ROS_INFO_STREAM(
"B*N_B = \n" << B*N_B <<
"\n\n");
638 ROS_INFO_STREAM(
"C*N_C = \n" << C*N_C <<
"\n\n");
639 ROS_INFO_STREAM(
"D*N_D = \n" << D*N_D <<
"\n\n");
669 std::vector<Kinematics::LegType> legs {Kinematics::LegType::rearLeft, Kinematics::LegType::frontLeft, Kinematics::LegType::rearRight};
673 ROS_INFO_STREAM(
"Contact Jacobian, J_c: \n" << J);
678 Eigen::Matrix<double, 3, 18> A1;
679 Eigen::Matrix<double, 4, 18> A2;
680 Eigen::Matrix<double, 3, 18> A3;
681 Eigen::Matrix<double, 2, 18> A4;
688 Eigen::Matrix<Eigen::MatrixXd, Eigen::Dynamic, 1> A;
697 Eigen::MatrixXd A_stacked;
699 for (
size_t i = 0; i < A.rows(); i++)
701 Eigen::MatrixXd A_stacked_tmp = A_stacked;
703 A_stacked.resize(A_stacked_tmp.rows() + A(i).rows(), A(i).cols());
705 A_stacked << A_stacked_tmp,
708 ROS_INFO_STREAM(
"A_stacked at iteration " << i <<
": \n" << A_stacked <<
"\n\n");
711 Eigen::Matrix<double, 18, 18> N;
717 ROS_INFO_STREAM(
"A_stacked*N: \n" << A_stacked*N);
719 Eigen::MatrixXd E_ineq;
722 int colsN = N.cols();
724 E_ineq.resize(A_stacked.rows() + rowsA_ineq, colsN + rowsA_ineq);
728 E_ineq.topLeftCorner(A_stacked.rows(), colsN) = A_stacked * N;
729 E_ineq.topRightCorner(rowsA_ineq, rowsA_ineq) = - Eigen::MatrixXd::Identity(rowsA_ineq, rowsA_ineq);
731 E_ineq.bottomRightCorner(rowsA_ineq, rowsA_ineq) = - Eigen::MatrixXd::Identity(rowsA_ineq, rowsA_ineq);
733 ROS_INFO_STREAM(
"E_ineq: \n" << E_ineq);
740 ROS_INFO_STREAM(
"B: \n" << B);
744 ROS_INFO_STREAM(
"B: \n" << B);
745 ROS_INFO_STREAM(
"B is zero?: " << B.isZero());
747 Eigen::Matrix<double, 18, 1> vec;
751 Eigen::VectorXd somevector;
753 somevector.resize(14, 1);
754 somevector.setOnes();
756 vec.segment(3, 14) += somevector;
758 ROS_INFO_STREAM(
"vec: \n" << vec);
760 Eigen::MatrixXd P(18, 18);
794 ROS_INFO_STREAM(
"h: \n" << h <<
"\n");
795 ROS_INFO_STREAM(
"l: \n" << l <<
"\n");
796 ROS_INFO_STREAM(
"n: \n" << n <<
"\n");
805 int state_dim = 18 + 3*n_c;
813 A.resize(4*n_c, state_dim);
815 for (
size_t i = 0; i < n_c; i++)
817 A.block(4*i, 0, 1, state_dim).setZero();
818 A.block(4*i, 18 + 3*i, 1, 3) = (h.transpose() - n.transpose() * mu);
820 A.block(4*i + 1, 0, 1, state_dim).setZero();
821 A.block(4*i + 1, 18 + 3*i, 1, 3) = - (h.transpose() + n.transpose() * mu);
823 A.block(4*i + 2, 0, 1, state_dim).setZero();
824 A.block(4*i + 2, 18 + 3*i, 1, 3) = (l.transpose() - n.transpose() * mu);
826 A.block(4*i + 3, 0, 1, state_dim).setZero();
827 A.block(4*i + 3, 18 + 3*i, 1, 3) = - (l.transpose() + n.transpose() * mu);
830 ROS_INFO_STREAM(
"A: \n" << A);
862 Kinematics::BodyType::foot,
866 Kinematics::BodyType::foot,
870 Kinematics::BodyType::foot,
873 Kinematics::BodyType::foot,
876 ROS_INFO_STREAM(
"J_P_inB: \n" << J_P_inB <<
"\n");
877 ROS_INFO_STREAM(
"J_P_inC: \n" << J_P_inC <<
"\n");
878 ROS_INFO_STREAM(
"J_P_inW: \n" << J_P_inW <<
"\n");
879 ROS_INFO_STREAM(
"J_P_inC2: \n" << J_P_inC2 <<
"\n");
886 double rowsA_ineq = 0;
890 Q.resize(colsN + rowsA_ineq, colsN + rowsA_ineq);
892 Q.topLeftCorner(colsN, colsN).setConstant(10);
893 Q.topRightCorner(colsN, rowsA_ineq).setZero();
894 Q.bottomLeftCorner(rowsA_ineq, colsN).setZero();
895 Q.bottomRightCorner(rowsA_ineq, rowsA_ineq).setIdentity();
897 ROS_INFO_STREAM(
"Q: \n " << Q);
901 int main(
int argc,
char **argv)
903 ros::init(argc, argv,
"kinematics_node");
957 ROS_INFO_STREAM(
"res: \n" << res);
958 ROS_INFO_STREAM(
"expectedRes: \n" << expectedRes);
A class for analytical Kinematics Solving.
Eigen::Matrix< double, 3, 18 > GetTranslationJacobianInW(const LegType &_leg, const BodyType &_body, const Eigen::Matrix< double, 18, 1 > &_q)
The GetTranslationJacobianInW function returns the 3x18 spatial translation Jacobian mapping generali...
Eigen::Matrix< double, Eigen::Dynamic, 18 > GetContactJacobianInW(std::vector< LegType > &_legs, const Eigen::Matrix< double, 18, 1 > &_q)
The GetContactJacobianInW function returns the (3*n_c)x18 support Jacobian mapping reaction forces at...
Eigen::Matrix< double, 18, 18 > GetMassMatrix(const Eigen::Matrix< double, 18, 1 > &_q)
The GetMassMatrix function returns the mass matrix for the floating base system.
bool SolveInverseKinematics(const Twist &_q_b, const FootstepPositions &_f_pos, JointSpaceVector &_q_r)
The SolveInverseKinematics function calculates the Inverse Kinematics, i.e. maps a coordinate point i...
Eigen::Matrix< double, 3, 3 > GetRotationMatrixWToC(const double &_roll, const double &_pitch, const double &_yaw)
The GetRotationMatrixWToC function returns the Euler Angles ZYX rotation matrix from World to Control...
TransMatrix GetDhTransform(const double &_a, const double &_alpha, const double &_d, const double &_theta)
The GetDhTransform function returns the Denavit-Hartenberg transformation from frame A to frame B.
TransMatrix GetHipToBodyTransform(const LegType &_leg, const BodyType &_body, const double &_theta_hy, const double &_theta_hp, const double &_theta_kp)
The GetHipToBodyTransform function returns the homogeneous transformation from the hip frame to the s...
Eigen::Matrix< double, 18, 1 > GetSingleBodyGravitationalTerms(const LegType &_leg, const BodyType &_body, const Eigen::Matrix< double, 18, 1 > &_q)
The GetSingleBodyGravitationalTerms function returns the gravitational terms for a single body in the...
Eigen::Matrix< double, 3, 3 > GetTranslationJacobianInB(const LegType &_leg, const BodyType &_body, const double &_theta_hy, const double &_theta_hp, const double &_theta_kp)
The GetTranslationJacobianInB function returns the 3x3 Jacobian matrix for body linear velocities in ...
Vector3d SolveSingleLegForwardKinematics(const Vector3d &_h_pos, const double &_theta_hy, const double &_theta_hp, const double &_theta_kp)
The SolveSingleLegForwardKinematics function calculates the Forward Kinematics for a single leg.
bool SolveForwardKinematics(const GeneralizedCoordinates &_q, FootstepPositions &_f_pos)
The SolveForwardKinematics function calculates the Forward Kinematics, i.e. maps joint angles in Join...
Eigen::Matrix< double, 18, 1 > GetGravitationalTerms(const Eigen::Matrix< double, 18, 1 > &_q)
The GetGravitationalTerms function returns the gravitational terms for the floating base system.
Eigen::Matrix< double, 3, 18 > GetTranslationJacobianInC(const LegType &_leg, const BodyType &_body, const Eigen::Matrix< double, 18, 1 > &_q)
The GetTranslationJacobianInC function returns the 3x18 spatial translation Jacobian mapping generali...
Eigen::Matrix< double, 3, 1 > GetPositionBaseToBodyInB(const LegType &_leg, const BodyType &_body, const Eigen::Matrix< double, 18, 1 > &_q)
The GetPositionBaseToBodyInB returns the position vector from base origin to COM position in body-fra...
bool SolveSingleLegInverseKinematics(const bool &_offset, const Vector3d &_h_pos, const Vector3d &_f_pos, Vector3d &_joint_angles)
The SolveSingeLegInverseKinematics function calculates the inverse kinematics for a single leg.
Eigen::Matrix< double, 3, 18 > GetRotationJacobianInW(const LegType &_leg, const BodyType &_body, const Eigen::Matrix< double, 18, 1 > &_q)
The GetRotationJacobianInW function returns the 3x18 spatial rotation Jacobian mapping generalized ve...
Eigen::Matrix< double, 6, 18 > GetJacobianInWDiff(const LegType &_leg, const BodyType &_body, const Eigen::Matrix< double, 18, 1 > &_q, const Eigen::Matrix< double, 18, 1 > &_u)
The GetJacobianInW function returns the time derivative of the 6x18 spatial Jacobian.
Eigen::Matrix< double, 18, 1 > GetCoriolisAndCentrifugalTerms(const Eigen::Matrix< double, 18, 1 > &_q, const Eigen::Matrix< double, 18, 1 > &_u)
The GetCoriolisAndCentrifugalTerms function returns the coriolis and centrifugal terms for the floati...
Eigen::Matrix< double, 18, 1 > GeneralizedCoordinates
Eigen::Matrix< double, 12, 1 > JointSpaceVector
Eigen::Matrix< Eigen::Vector3d, 4, 1 > FootstepPositions
Eigen::Matrix< double, 6, 1 > Twist
void testHipToFootTransform()
void testNullSpaceProjector()
void testContactForceLimitsMatrix()
int main(int argc, char **argv)
void testInverseKinematics()
void testGravitationalTerms()
void testPositionBaseToFoot()
void testContactJacobian()
void testForwardKinematics()
void testRotationJacobian()
void testSVDNullSpaceProjector()
void testCoriolisAndCentrifugalTerms()
void testTranslationJacobian()
void testSingeLegInverseKinematics()
void testSingleLegKinematics()
void printJointState(const Eigen::Matrix< double, 12, 1 > &_joint_state)
The printJointState function prints a given joint- state to ROS using print level INFO.
void printFootstepPositions(const Eigen::Matrix< Eigen::Vector3d, 4, 1 > &_f_pos)
The printFootstepPositions function prints a given set of footstep positions to ROS using print level...
static constexpr double HALF_PI
Define PI/2.
Eigen::Matrix< typename Vector_TypeA::Scalar, Eigen::Dynamic, 1 > boxMinus(const Vector_TypeA &_a, const Vector_TypeB &_b)
The boxMinus function calculates the box-minus operation between two vectors of equal size.
static constexpr double THIRD_PI
Define PI/3.
double degToRad(const double &_deg)
The degToRad function converts degrees to radians.
Eigen::Matrix< typename Matrix_TypeA::Scalar, Eigen::Dynamic, Eigen::Dynamic > SVDNullSpaceProjector(const Matrix_TypeA &_A)
The SVDNullSpaceProjector function calculates the null-space projector of a given matrix....
static bool nullSpaceProjector(const Matrix_TypeA &_A, Matrix_TypeB &_N, const double _alpha=1)
The nullSpaceProjector function calculates the null-space projector of a given matrix....
static constexpr double TWO_THIRDS_PI
Define 2PI/3.