665 for(
int joint_idx = 0; joint_idx <
ALL_JOINT_ID; joint_idx++)
675 std::vector<int> idx;
695 std::vector<int> idx;
725 Eigen::MatrixXd mc(3,1);
728 mc = Eigen::MatrixXd::Zero(3,1);
756 Eigen::MatrixXd COM(3,1);
796 int idx_size = idx.size();
797 int end = idx_size-1;
800 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Zero(6,idx_size);
802 for (
int id=0;
id<idx_size;
id++)
804 int curr_id = idx[id];
809 jacobian.block(3,
id,3,1) = tar_orientation;
817 int idx_size = idx.size();
818 int end = idx_size-1;
821 Eigen::MatrixXd jacobian_com = Eigen::MatrixXd::Zero(6,idx_size);
823 for (
int id=0;
id<idx_size;
id++)
825 int curr_id = idx[id];
832 jacobian_com.block(3,
id,3,1) = tar_orientation;
838 Eigen::MatrixXd
KinematicsDynamics::calcVWerr(Eigen::MatrixXd tar_position, Eigen::MatrixXd curr_position, Eigen::MatrixXd tar_orientation, Eigen::MatrixXd curr_orientation)
840 Eigen::MatrixXd pos_err = tar_position - curr_position;
841 Eigen::MatrixXd ori_err = curr_orientation.transpose() * tar_orientation;
844 Eigen::MatrixXd err = Eigen::MatrixXd::Zero(6,1);
845 err.block<3,1>(0,0) = pos_err;
846 err.block<3,1>(3,0) = ori_err_dash;
853 bool ik_success =
false;
854 bool limit_success =
false;
860 for (
int iter=0; iter<max_iter; iter++)
867 Eigen::MatrixXd err =
calcVWerr(tar_position, curr_position, tar_orientation, curr_orientation);
869 if (err.norm()<ik_err)
877 Eigen::MatrixXd jacobian_trans = jacobian * jacobian.transpose();
878 Eigen::MatrixXd jacobian_inverse = jacobian.transpose() * jacobian_trans.inverse();
880 Eigen::MatrixXd delta_angle = jacobian_inverse * err ;
882 for (
int id=0;
id<idx.size();
id++)
884 int joint_num = idx[id];
891 for (
int id = 0;
id < idx.size();
id++ )
893 int joint_num = idx[ id ];
897 limit_success =
false;
902 limit_success =
false;
906 limit_success =
true;
909 if (ik_success ==
true && limit_success ==
true)
917 bool ik_success =
false;
918 bool limit_success =
false;
922 std::vector<int> idx =
findRoute(from, to);
924 for (
int iter=0; iter<max_iter; iter++)
931 Eigen::MatrixXd err =
calcVWerr(tar_position, curr_position, tar_orientation, curr_orientation);
933 if (err.norm()<ik_err)
941 Eigen::MatrixXd jacobian_trans = jacobian * jacobian.transpose();
942 Eigen::MatrixXd jacobian_inv = jacobian.transpose() * jacobian_trans.inverse();
944 Eigen::MatrixXd delta_angle = jacobian_inv * err ;
946 for (
int id=0;
id<idx.size();
id++)
948 int joint_num = idx[id];
955 for (
int id = 0;
id < idx.size();
id++ )
957 int joint_num = idx[ id ];
961 limit_success =
false;
966 limit_success =
false;
970 limit_success =
true;
973 if (ik_success ==
true && limit_success ==
true)
981 bool ik_success =
false;
982 bool limit_success =
false;
989 Eigen::MatrixXd weight_matrix = Eigen::MatrixXd::Identity(idx.size(), idx.size());
991 for (
int ix = 0; ix < idx.size(); ix++ )
992 weight_matrix.coeffRef(ix,ix) = weight.coeff(idx[ix],0);
995 Eigen::MatrixXd eval = Eigen::MatrixXd::Zero(6,6);
997 double p_damping = 1e-5;
998 double R_damping = 1e-5;
1000 for (
int ix=0; ix<3; ix++)
1002 eval.coeffRef(ix,ix) = p_damping;
1003 eval.coeffRef(ix+3,ix+3) = R_damping;
1007 for (
int iter=0; iter<max_iter; iter++)
1014 Eigen::MatrixXd err =
calcVWerr(tar_position, curr_position, tar_orientation, curr_orientation);
1016 if (err.norm()<ik_err)
1024 Eigen::MatrixXd jacobian_trans = (jacobian * weight_matrix * jacobian.transpose() + eval);
1025 Eigen::MatrixXd jacobian_inv = weight_matrix * jacobian.transpose() * jacobian_trans.inverse();
1027 Eigen::MatrixXd delta_angle = jacobian_inv * err ;
1029 for (
int id=0;
id<idx.size();
id++)
1031 int joint_id = idx[id];
1039 for (
int id = 0;
id < idx.size();
id++ )
1041 int joint_num = idx[ id ];
1045 limit_success =
false;
1050 limit_success =
false;
1054 limit_success =
true;
1057 if (ik_success ==
true && limit_success ==
true)
1065 bool ik_success =
false;
1066 bool limit_success =
false;
1070 std::vector<int> idx =
findRoute(from, to);
1073 Eigen::MatrixXd weight_matrix = Eigen::MatrixXd::Identity(idx.size(),idx.size());
1075 for (
int ix = 0; ix < idx.size(); ix++)
1076 weight_matrix.coeffRef(ix, ix) = weight.coeff(idx[ix], 0);
1079 Eigen::MatrixXd eval = Eigen::MatrixXd::Zero(6, 6);
1081 double p_damping = 1e-5;
1082 double R_damping = 1e-5;
1084 for (
int ix = 0; ix < 3; ix++)
1086 eval.coeffRef(ix, ix) = p_damping;
1087 eval.coeffRef(ix + 3, ix + 3) = R_damping;
1091 for (
int iter = 0; iter < max_iter; iter++)
1096 Eigen::MatrixXd err =
calcVWerr(tar_position, curr_position, tar_orientation, curr_orientation);
1098 if (err.norm() < ik_err)
1106 Eigen::MatrixXd jacobian_trans = (jacobian * weight_matrix * jacobian.transpose() + eval);
1107 Eigen::MatrixXd jacobian_inv = weight_matrix * jacobian.transpose() * jacobian_trans.inverse();
1108 Eigen::MatrixXd delta_angle = jacobian_inv * err;
1110 for (
int id = 0;
id < idx.size();
id++)
1112 int joint_id = idx[id];
1119 for (
int id = 0;
id < idx.size();
id++)
1121 int _joint_num = idx[id];
1124 limit_success =
false;
1129 limit_success =
false;
1133 limit_success =
true;
1136 if (ik_success ==
true && limit_success ==
true)
1145 Eigen::Matrix4d trans_ad, trans_da, trans_cd, trans_dc, trans_ac;
1146 Eigen::Vector3d vec;
1149 double rac, arc_cos, arc_tan, k, l, m, n,
s, c, theta;
1156 vec.coeffRef(0) = trans_ad.coeff(0,3) + trans_ad.coeff(0,2) * ankle_length;
1157 vec.coeffRef(1) = trans_ad.coeff(1,3) + trans_ad.coeff(1,2) * ankle_length;
1158 vec.coeffRef(2) = trans_ad.coeff(2,3) + trans_ad.coeff(2,2) * ankle_length;
1162 arc_cos = acos((rac * rac - thigh_length * thigh_length - calf_length * calf_length) / (2.0 * thigh_length * calf_length));
1163 if(std::isnan(arc_cos) == 1)
1165 *(out + 3) = arc_cos;
1168 trans_ad.computeInverseWithCheck(trans_da, invertible);
1169 if(invertible ==
false)
1172 k = sqrt(trans_da.coeff(1,3) * trans_da.coeff(1,3) + trans_da.coeff(2,3) * trans_da.coeff(2,3));
1173 l = sqrt(trans_da.coeff(1,3) * trans_da.coeff(1,3) + (trans_da.coeff(2,3) - ankle_length)*(trans_da.coeff(2,3) - ankle_length));
1174 m = (k * k - l * l - ankle_length * ankle_length) / (2.0 * l * ankle_length);
1182 if(std::isnan(arc_cos) == 1)
1185 if(trans_da.coeff(1,3) < 0.0)
1186 *(out + 5) = -arc_cos;
1188 *(out + 5) = arc_cos;
1192 trans_cd.computeInverseWithCheck(trans_dc, invertible);
1193 if(invertible ==
false)
1196 trans_ac = trans_ad * trans_dc;
1197 arc_tan = atan2(-trans_ac.coeff(0,1) , trans_ac.coeff(1,1));
1198 if(std::isinf(arc_tan) != 0)
1203 arc_tan = atan2(trans_ac.coeff(2,1), -trans_ac.coeff(0,1) * sin(*(out)) + trans_ac.coeff(1,1) * cos(*(out)));
1204 if(std::isinf(arc_tan) != 0)
1206 *(out + 1) = arc_tan;
1209 arc_tan = atan2(trans_ac.coeff(0,2) * cos(*(out)) + trans_ac.coeff(1,2) * sin(*(out)), trans_ac.coeff(0,0) * cos(*(out)) + trans_ac.coeff(1,0) * sin(*(out)));
1210 if(std::isinf(arc_tan) == 1)
1213 k = sin(*(out + 3)) * calf_length;
1214 l = -thigh_length - cos(*(out + 3)) * calf_length;
1215 m = cos(*(out)) * vec.coeff(0) + sin(*(out)) * vec.coeff(1);
1216 n = cos(*(out + 1)) * vec.coeff(2) + sin(*(out)) * sin(*(out + 1)) * vec.coeff(0) - cos(*(out)) * sin(*(out + 1)) * vec.coeff(1);
1217 s = (k * n + l * m) / (k * k + l * l);
1218 c = (n - k * s) / l;
1219 arc_tan = atan2(s, c);
1220 if(std::isinf(arc_tan) == 1)
1222 *(out + 2) = arc_tan;
1223 *(out + 4) = theta - *(out + 3) - *(out + 2);
Eigen::MatrixXd joint_center_of_mass_
std::vector< int > findRoute(int to)
Eigen::MatrixXd orientation_
double leg_side_offset_m_
Eigen::MatrixXd calcJacobian(std::vector< int > idx)
Eigen::Matrix3d calcHatto(const Eigen::Vector3d &matrix3d)
Eigen::Matrix3d calcRodrigues(const Eigen::Matrix3d &hat_matrix, double angle)
Eigen::Vector3d convertRotToOmega(const Eigen::Matrix3d &rotation)
Eigen::MatrixXd calcMassCenter(int joint_id)
Eigen::MatrixXd calcJacobianCOM(std::vector< int > idx)
Eigen::Matrix4d getTransformationXYZRPY(double position_x, double position_y, double position_z, double roll, double pitch, double yaw)
Eigen::Vector3d getTransitionXYZ(double position_x, double position_y, double position_z)
Eigen::Vector3d calcCross(const Eigen::Vector3d &vector3d_a, const Eigen::Vector3d &vector3d_b)
bool calcInverseKinematicsForLeg(double *out, double x, double y, double z, double roll, double pitch, double yaw)
Eigen::MatrixXd position_
LinkData * thormang3_link_data_[ALL_JOINT_ID+1]
Eigen::MatrixXd joint_axis_
void calcJointsCenterOfMass(int joint_id)
Eigen::MatrixXd center_of_mass_
bool calcInverseKinematicsForRightLeg(double *out, double x, double y, double z, double roll, double pitch, double yaw)
Eigen::MatrixXd calcVWerr(Eigen::MatrixXd tar_position, Eigen::MatrixXd curr_position, Eigen::MatrixXd tar_orientation, Eigen::MatrixXd curr_orientation)
Eigen::MatrixXd calcCenterOfMass(Eigen::MatrixXd mc)
double calcTotalMass(int joint_id)
Eigen::Matrix3d getInertiaXYZ(double ixx, double ixy, double ixz, double iyy, double iyz, double izz)
bool calcInverseKinematicsForLeftLeg(double *out, double x, double y, double z, double roll, double pitch, double yaw)
Eigen::MatrixXd relative_position_
void calcForwardKinematics(int joint_ID)
bool calcInverseKinematics(int to, Eigen::MatrixXd tar_position, Eigen::MatrixXd tar_orientation, int max_iter, double ik_err)