19 #include "../include/open_manipulator_p_libs/kinematics.h" 28 void SolverUsingCRAndJacobian::setOption(
const void *arg){}
30 Eigen::MatrixXd SolverUsingCRAndJacobian::jacobian(
Manipulator *manipulator,
Name tool_name)
32 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, manipulator->
getDOF());
34 Eigen::Vector3d joint_axis = Eigen::Vector3d::Zero(3);
36 Eigen::Vector3d position_changed = Eigen::Vector3d::Zero(3);
37 Eigen::Vector3d orientation_changed = Eigen::Vector3d::Zero(3);
38 Eigen::VectorXd pose_changed = Eigen::VectorXd::Zero(6);
45 for (int8_t size = 0; size < manipulator->
getDOF(); size++)
59 orientation_changed = joint_axis;
61 pose_changed << position_changed(0),
64 orientation_changed(0),
65 orientation_changed(1),
66 orientation_changed(2);
68 jacobian.col(index) = pose_changed;
75 void SolverUsingCRAndJacobian::solveForwardKinematics(
Manipulator *manipulator)
80 bool SolverUsingCRAndJacobian::solveInverseKinematics(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
82 return inverseSolverUsingJacobian(manipulator, tool_name, target_pose, goal_joint_value);
87 void SolverUsingCRAndJacobian::forwardSolverUsingChainRule(
Manipulator *manipulator,
Name component_name)
89 Name my_name = component_name;
93 Pose parent_pose_value;
122 for (int8_t index = 0; index < number_of_child; index++)
125 forwardSolverUsingChainRule(manipulator, child_name);
129 bool SolverUsingCRAndJacobian::inverseSolverUsingJacobian(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
131 const double lambda = 0.7;
132 const int8_t iteration = 10;
136 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, _manipulator.
getDOF());
138 Eigen::VectorXd pose_changed = Eigen::VectorXd::Zero(6);
139 Eigen::VectorXd delta_angle = Eigen::VectorXd::Zero(_manipulator.
getDOF());
141 for (int8_t count = 0; count < iteration; count++)
144 solveForwardKinematics(&_manipulator);
146 jacobian = this->jacobian(&_manipulator, tool_name);
153 if (pose_changed.norm() < 1E-6)
156 for(int8_t index = 0; index < _manipulator.
getDOF(); index++)
158 goal_joint_value->at(index).velocity = 0.0;
159 goal_joint_value->at(index).acceleration = 0.0;
160 goal_joint_value->at(index).effort = 0.0;
166 ColPivHouseholderQR<MatrixXd> dec(jacobian);
167 delta_angle = lambda * dec.solve(pose_changed);
170 std::vector<double> changed_angle;
171 for(int8_t index = 0; index < _manipulator.
getDOF(); index++)
175 *goal_joint_value = {};
183 void SolverUsingCRAndSRJacobian::setOption(
const void *arg){}
185 Eigen::MatrixXd SolverUsingCRAndSRJacobian::jacobian(
Manipulator *manipulator,
Name tool_name)
187 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, manipulator->
getDOF());
189 Eigen::Vector3d joint_axis = Eigen::Vector3d::Zero(3);
191 Eigen::Vector3d position_changed = Eigen::Vector3d::Zero(3);
192 Eigen::Vector3d orientation_changed = Eigen::Vector3d::Zero(3);
193 Eigen::VectorXd pose_changed = Eigen::VectorXd::Zero(6);
200 for (int8_t size = 0; size < manipulator->
getDOF(); size++)
214 orientation_changed = joint_axis;
216 pose_changed << position_changed(0),
219 orientation_changed(0),
220 orientation_changed(1),
221 orientation_changed(2);
223 jacobian.col(index) = pose_changed;
230 void SolverUsingCRAndSRJacobian::solveForwardKinematics(
Manipulator *manipulator)
235 bool SolverUsingCRAndSRJacobian::solveInverseKinematics(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
237 return inverseSolverUsingSRJacobian(manipulator, tool_name, target_pose, goal_joint_value);
242 void SolverUsingCRAndSRJacobian::forwardSolverUsingChainRule(
Manipulator *manipulator,
Name component_name)
244 Name my_name = component_name;
248 Pose parent_pose_value;
277 for (int8_t index = 0; index < number_of_child; index++)
280 forwardSolverUsingChainRule(manipulator, child_name);
284 bool SolverUsingCRAndSRJacobian::inverseSolverUsingSRJacobian(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
291 const double param = 0.002;
292 const int8_t iteration = 5;
294 const double gamma = 0.5;
297 double wn_pos = 1 / 0.3;
298 double wn_ang = 1 / (2 * M_PI);
302 Eigen::MatrixXd We(6, 6);
303 We << wn_pos, 0, 0, 0, 0, 0,
304 0, wn_pos, 0, 0, 0, 0,
305 0, 0, wn_pos, 0, 0, 0,
306 0, 0, 0, wn_ang, 0, 0,
307 0, 0, 0, 0, wn_ang, 0,
308 0, 0, 0, 0, 0, wn_ang;
310 Eigen::MatrixXd Wn = Eigen::MatrixXd::Identity(_manipulator.
getDOF(), _manipulator.
getDOF());
313 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, _manipulator.
getDOF());
314 Eigen::MatrixXd sr_jacobian = Eigen::MatrixXd::Identity(_manipulator.
getDOF(), _manipulator.
getDOF());
317 Eigen::VectorXd pose_changed = Eigen::VectorXd::Zero(6);
318 Eigen::VectorXd angle_changed = Eigen::VectorXd::Zero(_manipulator.
getDOF());
319 Eigen::VectorXd gerr(_manipulator.
getDOF());
322 std::vector<double> present_angle;
323 std::vector<double> set_angle;
327 solveForwardKinematics(&_manipulator);
330 pre_Ek = pose_changed.transpose() * We * pose_changed;
334 #if defined(KINEMATICS_DEBUG) 335 Eigen::Vector3d target_orientation_rpy = math::convertRotationToRPY(target_pose.orientation);
336 Eigen::VectorXd debug_target_pose(6);
337 for(
int t=0; t<3; t++)
338 debug_target_pose(t) = target_pose.position(t);
339 for(
int t=0; t<3; t++)
340 debug_target_pose(t+3) = target_orientation_rpy(t);
344 Eigen::Vector3d present_orientation_rpy = math::convertRotationToRPY(present_orientation);
345 Eigen::VectorXd debug_present_pose(6);
346 for(
int t=0; t<3; t++)
347 debug_present_pose(t) = present_position(t);
348 for(
int t=0; t<3; t++)
349 debug_present_pose(t+3) = present_orientation_rpy(t);
353 log::warn(
"Ek : ", pre_Ek*1000000000000);
355 log::println_VECTOR(debug_target_pose,16);
357 log::println_VECTOR(debug_present_pose,16);
359 log::println_VECTOR(debug_target_pose-debug_present_pose,16);
364 for (int8_t count = 0; count < iteration; count++)
367 jacobian = this->jacobian(&_manipulator, tool_name);
368 lambda = pre_Ek + param;
370 sr_jacobian = (jacobian.transpose() * We * jacobian) + (lambda * Wn);
371 gerr = jacobian.transpose() * We * pose_changed;
373 ColPivHouseholderQR<Eigen::MatrixXd> dec(sr_jacobian);
374 angle_changed = dec.solve(gerr);
378 for (int8_t index = 0; index < _manipulator.
getDOF(); index++)
379 set_angle.push_back(present_angle.at(index) + angle_changed(index));
381 solveForwardKinematics(&_manipulator);
386 new_Ek = pose_changed.transpose() * We * pose_changed;
390 #if defined(KINEMATICS_DEBUG) 393 present_orientation_rpy = math::convertRotationToRPY(present_orientation);
394 for(
int t=0; t<3; t++)
395 debug_present_pose(t) = present_position(t);
396 for(
int t=0; t<3; t++)
397 debug_present_pose(t+3) = present_orientation_rpy(t);
399 log::warn(
"Ek : ", new_Ek*1000000000000);
401 log::println_VECTOR(debug_target_pose,16);
403 log::println_VECTOR(debug_present_pose,16);
405 log::println_VECTOR(debug_target_pose-debug_present_pose,16);
412 #if defined(KINEMATICS_DEBUG) 414 log::warn(
"Ek : ", new_Ek*1000000000000);
420 for(int8_t index = 0; index < _manipulator.
getDOF(); index++)
422 goal_joint_value->at(index).velocity = 0.0;
423 goal_joint_value->at(index).acceleration = 0.0;
424 goal_joint_value->at(index).effort = 0.0;
428 else if (new_Ek < pre_Ek)
435 for (int8_t index = 0; index < _manipulator.
getDOF(); index++)
436 set_angle.push_back(present_angle.at(index) - (gamma * angle_changed(index)));
439 solveForwardKinematics(&_manipulator);
442 log::error(
"[sr]fail to solve inverse kinematics (please change the solver)");
443 *goal_joint_value = {};
451 void SolverUsingCRAndSRPositionOnlyJacobian::setOption(
const void *arg){}
453 Eigen::MatrixXd SolverUsingCRAndSRPositionOnlyJacobian::jacobian(
Manipulator *manipulator,
Name tool_name)
455 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, manipulator->
getDOF());
457 Eigen::Vector3d joint_axis = Eigen::Vector3d::Zero(3);
459 Eigen::Vector3d position_changed = Eigen::Vector3d::Zero(3);
460 Eigen::Vector3d orientation_changed = Eigen::Vector3d::Zero(3);
461 Eigen::VectorXd pose_changed = Eigen::VectorXd::Zero(6);
468 for (int8_t size = 0; size < manipulator->
getDOF(); size++)
482 orientation_changed = joint_axis;
484 pose_changed << position_changed(0),
487 orientation_changed(0),
488 orientation_changed(1),
489 orientation_changed(2);
491 jacobian.col(index) = pose_changed;
498 void SolverUsingCRAndSRPositionOnlyJacobian::solveForwardKinematics(
Manipulator *manipulator)
503 bool SolverUsingCRAndSRPositionOnlyJacobian::solveInverseKinematics(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
505 return inverseSolverUsingPositionOnlySRJacobian(manipulator, tool_name, target_pose, goal_joint_value);
510 void SolverUsingCRAndSRPositionOnlyJacobian::forwardSolverUsingChainRule(
Manipulator *manipulator,
Name component_name)
512 Name my_name = component_name;
516 Pose parent_pose_value;
545 for (int8_t index = 0; index < number_of_child; index++)
548 forwardSolverUsingChainRule(manipulator, child_name);
552 bool SolverUsingCRAndSRPositionOnlyJacobian::inverseSolverUsingPositionOnlySRJacobian(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
559 const double param = 0.002;
560 const int8_t iteration = 10;
562 const double gamma = 0.5;
565 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, _manipulator.
getDOF());
566 Eigen::MatrixXd position_jacobian = Eigen::MatrixXd::Identity(3, _manipulator.
getDOF());
567 Eigen::MatrixXd sr_jacobian = Eigen::MatrixXd::Identity(_manipulator.
getDOF(), _manipulator.
getDOF());
570 Eigen::Vector3d position_changed = Eigen::VectorXd::Zero(3);
571 Eigen::VectorXd angle_changed = Eigen::VectorXd::Zero(_manipulator.
getDOF());
572 Eigen::VectorXd gerr(_manipulator.
getDOF());
575 double wn_pos = 1 / 0.3;
579 Eigen::MatrixXd We(3, 3);
584 Eigen::MatrixXd Wn = Eigen::MatrixXd::Identity(_manipulator.
getDOF(), _manipulator.
getDOF());
587 std::vector<double> present_angle;
588 std::vector<double> set_angle;
592 solveForwardKinematics(&_manipulator);
595 pre_Ek = position_changed.transpose() * We * position_changed;
599 #if defined(KINEMATICS_DEBUG) 600 Eigen::Vector3d target_orientation_rpy = math::convertRotationToRPY(target_pose.orientation);
601 Eigen::VectorXd debug_target_pose(6);
602 for(
int t=0; t<3; t++)
603 debug_target_pose(t) = target_pose.position(t);
604 for(
int t=0; t<3; t++)
605 debug_target_pose(t+3) = target_orientation_rpy(t);
609 Eigen::Vector3d present_orientation_rpy = math::convertRotationToRPY(present_orientation);
610 Eigen::VectorXd debug_present_pose(6);
611 for(
int t=0; t<3; t++)
612 debug_present_pose(t) = present_position(t);
613 for(
int t=0; t<3; t++)
614 debug_present_pose(t+3) = present_orientation_rpy(t);
618 log::warn(
"Ek : ", pre_Ek*1000000000000);
620 log::println_VECTOR(debug_target_pose,16);
622 log::println_VECTOR(debug_present_pose,16);
624 log::println_VECTOR(debug_target_pose-debug_present_pose,16);
629 for (int8_t count = 0; count < iteration; count++)
632 jacobian = this->jacobian(&_manipulator, tool_name);
633 position_jacobian.row(0) = jacobian.row(0);
634 position_jacobian.row(1) = jacobian.row(1);
635 position_jacobian.row(2) = jacobian.row(2);
636 lambda = pre_Ek + param;
638 sr_jacobian = (position_jacobian.transpose() * We * position_jacobian) + (lambda * Wn);
639 gerr = position_jacobian.transpose() * We * position_changed;
641 ColPivHouseholderQR<Eigen::MatrixXd> dec(sr_jacobian);
642 angle_changed = dec.solve(gerr);
646 for (int8_t index = 0; index < _manipulator.
getDOF(); index++)
649 solveForwardKinematics(&_manipulator);
654 new_Ek = position_changed.transpose() * We * position_changed;
658 #if defined(KINEMATICS_DEBUG) 661 present_orientation_rpy = math::convertRotationToRPY(present_orientation);
662 for(
int t=0; t<3; t++)
663 debug_present_pose(t) = present_position(t);
664 for(
int t=0; t<3; t++)
665 debug_present_pose(t+3) = present_orientation_rpy(t);
667 log::warn(
"Ek : ", new_Ek*1000000000000);
669 log::println_VECTOR(debug_target_pose,16);
671 log::println_VECTOR(debug_present_pose,16);
673 log::println_VECTOR(debug_target_pose-debug_present_pose,16);
680 #if defined(KINEMATICS_DEBUG) 682 log::warn(
"Ek : ", new_Ek*1000000000000);
688 for(int8_t index = 0; index < _manipulator.
getDOF(); index++)
690 goal_joint_value->at(index).velocity = 0.0;
691 goal_joint_value->at(index).acceleration = 0.0;
692 goal_joint_value->at(index).effort = 0.0;
696 else if (new_Ek < pre_Ek)
703 for (int8_t index = 0; index < _manipulator.
getDOF(); index++)
707 solveForwardKinematics(&_manipulator);
710 log::error(
"[position_only]fail to solve inverse kinematics (please change the solver)");
711 *goal_joint_value = {};
719 void SolverCustomizedforOMChain::setOption(
const void *arg){}
721 Eigen::MatrixXd SolverCustomizedforOMChain::jacobian(
Manipulator *manipulator,
Name tool_name)
723 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, manipulator->
getDOF());
725 Eigen::Vector3d joint_axis = Eigen::Vector3d::Zero(3);
727 Eigen::Vector3d position_changed = Eigen::Vector3d::Zero(3);
728 Eigen::Vector3d orientation_changed = Eigen::Vector3d::Zero(3);
729 Eigen::VectorXd pose_changed = Eigen::VectorXd::Zero(6);
736 for (int8_t size = 0; size < manipulator->
getDOF(); size++)
750 orientation_changed = joint_axis;
752 pose_changed << position_changed(0),
755 orientation_changed(0),
756 orientation_changed(1),
757 orientation_changed(2);
759 jacobian.col(index) = pose_changed;
766 void SolverCustomizedforOMChain::solveForwardKinematics(
Manipulator *manipulator)
771 bool SolverCustomizedforOMChain::solveInverseKinematics(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
773 return chainCustomInverseKinematics(manipulator, tool_name, target_pose, goal_joint_value);
778 void SolverCustomizedforOMChain::forwardSolverUsingChainRule(
Manipulator *manipulator,
Name component_name)
780 Name my_name = component_name;
784 Pose parent_pose_value;
813 for (int8_t index = 0; index < number_of_child; index++)
816 forwardSolverUsingChainRule(manipulator, child_name);
820 bool SolverCustomizedforOMChain::chainCustomInverseKinematics(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
827 const double param = 0.002;
828 const int8_t iteration = 10;
830 const double gamma = 0.5;
833 double wn_pos = 1 / 0.3;
834 double wn_ang = 1 / (2 * M_PI);
838 Eigen::MatrixXd We(6, 6);
839 We << wn_pos, 0, 0, 0, 0, 0,
840 0, wn_pos, 0, 0, 0, 0,
841 0, 0, wn_pos, 0, 0, 0,
842 0, 0, 0, wn_ang, 0, 0,
843 0, 0, 0, 0, wn_ang, 0,
844 0, 0, 0, 0, 0, wn_ang;
846 Eigen::MatrixXd Wn = Eigen::MatrixXd::Identity(_manipulator.
getDOF(), _manipulator.
getDOF());
849 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, _manipulator.
getDOF());
850 Eigen::MatrixXd sr_jacobian = Eigen::MatrixXd::Identity(_manipulator.
getDOF(), _manipulator.
getDOF());
853 Eigen::VectorXd pose_changed = Eigen::VectorXd::Zero(6);
854 Eigen::VectorXd angle_changed = Eigen::VectorXd::Zero(_manipulator.
getDOF());
855 Eigen::VectorXd gerr(_manipulator.
getDOF());
858 std::vector<double> present_angle;
859 std::vector<double> set_angle;
863 solveForwardKinematics(&_manipulator);
872 Eigen::Vector3d target_position_from_joint1 = target_pose.
kinematic.
position - joint1_rlative_position;
874 target_orientation_rpy(0) = present_orientation_rpy(0);
875 target_orientation_rpy(1) = target_orientation_rpy(1);
876 target_orientation_rpy(2) = atan2(target_position_from_joint1(1) ,target_position_from_joint1(0));
883 pre_Ek = pose_changed.transpose() * We * pose_changed;
887 #if defined(KINEMATICS_DEBUG) 888 Eigen::VectorXd debug_target_pose(6);
889 for(
int t=0; t<3; t++)
890 debug_target_pose(t) = target_pose.position(t);
891 for(
int t=0; t<3; t++)
892 debug_target_pose(t+3) = target_orientation_rpy(t);
895 Eigen::VectorXd debug_present_pose(6);
896 for(
int t=0; t<3; t++)
897 debug_present_pose(t) = present_position(t);
898 for(
int t=0; t<3; t++)
899 debug_present_pose(t+3) = present_orientation_rpy(t);
903 log::warn(
"Ek : ", pre_Ek*1000000000000);
905 log::println_VECTOR(debug_target_pose,16);
907 log::println_VECTOR(debug_present_pose,16);
909 log::println_VECTOR(debug_target_pose-debug_present_pose,16);
914 for (int8_t count = 0; count < iteration; count++)
917 jacobian = this->jacobian(&_manipulator, tool_name);
918 lambda = pre_Ek + param;
920 sr_jacobian = (jacobian.transpose() * We * jacobian) + (lambda * Wn);
921 gerr = jacobian.transpose() * We * pose_changed;
923 ColPivHouseholderQR<Eigen::MatrixXd> dec(sr_jacobian);
924 angle_changed = dec.solve(gerr);
928 for (int8_t index = 0; index < _manipulator.
getDOF(); index++)
929 set_angle.push_back(present_angle.at(index) + angle_changed(index));
931 solveForwardKinematics(&_manipulator);
936 new_Ek = pose_changed.transpose() * We * pose_changed;
940 #if defined(KINEMATICS_DEBUG) 943 present_orientation_rpy = math::convertRotationToRPY(present_orientation);
944 for(
int t=0; t<3; t++)
945 debug_present_pose(t) = present_position(t);
946 for(
int t=0; t<3; t++)
947 debug_present_pose(t+3) = present_orientation_rpy(t);
949 log::warn(
"Ek : ", new_Ek*1000000000000);
951 log::println_VECTOR(debug_target_pose,16);
953 log::println_VECTOR(debug_present_pose,16);
955 log::println_VECTOR(debug_target_pose-debug_present_pose,16);
962 #if defined(KINEMATICS_DEBUG) 964 log::warn(
"Ek : ", new_Ek*1000000000000);
970 for(int8_t index = 0; index < _manipulator.
getDOF(); index++)
972 goal_joint_value->at(index).velocity = 0.0;
973 goal_joint_value->at(index).acceleration = 0.0;
974 goal_joint_value->at(index).effort = 0.0;
978 else if (new_Ek < pre_Ek)
985 for (int8_t index = 0; index < _manipulator.
getDOF(); index++)
986 set_angle.push_back(present_angle.at(index) - (gamma * angle_changed(index)));
989 solveForwardKinematics(&_manipulator);
992 log::error(
"[OpenManipulator Chain Custom]fail to solve inverse kinematics");
993 *goal_joint_value = {};
1001 void SolverUsingCRAndGeometry::setOption(
const void *arg)
1003 with_gripper_ = arg;
1006 Eigen::MatrixXd SolverUsingCRAndGeometry::jacobian(
Manipulator *manipulator,
Name tool_name)
1008 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Identity(6, manipulator->
getDOF());
1012 void SolverUsingCRAndGeometry::solveForwardKinematics(
Manipulator *manipulator)
1017 bool SolverUsingCRAndGeometry::solveInverseKinematics(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
1019 return inverseSolverUsingGeometry(manipulator, tool_name, target_pose, goal_joint_value);
1024 void SolverUsingCRAndGeometry::forwardSolverUsingChainRule(
Manipulator *manipulator,
Name component_name)
1026 Name my_name = component_name;
1030 Pose parent_pose_value;
1059 for (int8_t index = 0; index < number_of_child; index++)
1062 forwardSolverUsingChainRule(manipulator, child_name);
1066 bool SolverUsingCRAndGeometry::inverseSolverUsingGeometry(
Manipulator *manipulator,
Name tool_name,
Pose target_pose, std::vector<JointValue> *goal_joint_value)
1070 std::vector<JointValue> target_angle_vector;
1074 Eigen::VectorXd position = Eigen::VectorXd::Zero(3);
1075 Eigen::MatrixXd orientation = Eigen::MatrixXd::Zero(3,3);
1083 d6 += tool_length(0);
1085 Eigen::Vector3d position_2 = Eigen::VectorXd::Zero(3);
1086 position_2 << orientation(0,0), orientation(1,0), orientation(2,0);
1087 Eigen::Vector3d position_3 = Eigen::VectorXd::Zero(3);
1088 position_3 = position - d6*position_2;
1089 if (position_3(0) == 0) position_3(0) = 0.001;
1090 target_angle[0].
position = atan(position_3(1) / position_3(0));
1093 Eigen::VectorXd position3 = Eigen::VectorXd::Zero(3);
1094 Eigen::VectorXd position3_2 = Eigen::VectorXd::Zero(3);
1095 position3 << 0.0, 0.0, 0.126;
1096 position3_2 << 0.0, 0.0, 0.033;
1098 Eigen::VectorXd position3_3 = Eigen::VectorXd::Zero(3);
1099 position3_3 = position3 + orientation3 * position3_2;
1100 Eigen::VectorXd position3_4 = Eigen::VectorXd::Zero(3);
1101 position3_4 = position_3 - position3_3;
1102 double l1 = sqrt(0.264*0.264 + 0.030*0.030);
1103 double l2 = sqrt(0.030*0.030 + 0.258*0.258);
1104 double phi = acos((l1*l1 + l2*l2 - position3_4.norm()*position3_4.norm()) / (2*l1*l2));
1105 double alpha1 = atan2(0.030, 0.264);
1106 double alpha2 = atan2(0.258, 0.030);
1107 target_angle[2].
position =
PI - (phi-alpha1) - alpha2;
1110 Eigen::VectorXd position2 = Eigen::VectorXd::Zero(3);
1112 position2 = orientation2.inverse() * position3_4;
1113 double beta1 = atan2(position2(2), position2(0));
1114 double beta2 = acos((l1*l1 + position3_4.norm()*position3_4.norm() - l2*l2) / (2*l1*position3_4.norm()));
1115 if (position3_4(2) > 0) target_angle[1].
position = (
PI/2-alpha1) - fabs(beta1) - beta2;
1116 else target_angle[1].
position = (
PI/2-alpha1) + fabs(beta1) - beta2;
1123 Eigen::MatrixXd orientation_def = orientation_to_joint3.transpose() * orientation;
1125 if(orientation_def(0,0) < 1.0)
1127 if(orientation_def(0,0) > -1.0)
1130 double joint4_angle_temp_1 = atan2(orientation_def(1,0), -orientation_def(2,0));
1131 double joint4_angle_temp_2 = atan2(-orientation_def(1,0), orientation_def(2,0));
1133 if(fabs(joint4_angle_temp_1-joint4_angle_present) < fabs(joint4_angle_temp_2-joint4_angle_present))
1136 target_angle[3].
position = joint4_angle_temp_1;
1137 target_angle[4].
position = acos(orientation_def(0,0));
1138 target_angle[5].
position = atan2(orientation_def(0,1), orientation_def(0,2));
1143 target_angle[3].
position = joint4_angle_temp_2;
1144 target_angle[4].
position = -acos(orientation_def(0,0));
1145 target_angle[5].
position = atan2(-orientation_def(0,1), -orientation_def(0,2));
1152 target_angle[5].
position = atan2(-orientation_def(1,2), orientation_def(1,1))+target_angle[3].
position;
1159 target_angle[5].
position = atan2(-orientation_def(1,2), orientation_def(1,1))-target_angle[3].
position;
1172 if(std::isnan(target_angle[0].position) ||
1173 std::isnan(target_angle[1].position) ||
1174 std::isnan(target_angle[2].position) ||
1175 std::isnan(target_angle[3].position) ||
1176 std::isnan(target_angle[4].position) ||
1177 std::isnan(target_angle[5].position) )
1184 if(std::isinf(target_angle[0].position) ||
1185 std::isinf(target_angle[1].position) ||
1186 std::isinf(target_angle[2].position) ||
1187 std::isinf(target_angle[3].position) ||
1188 std::isinf(target_angle[4].position) ||
1189 std::isinf(target_angle[5].position) )
1195 target_angle_vector.push_back(target_angle[0]);
1196 target_angle_vector.push_back(target_angle[1]);
1197 target_angle_vector.push_back(target_angle[2]);
1198 target_angle_vector.push_back(target_angle[3]);
1199 target_angle_vector.push_back(target_angle[4]);
1200 target_angle_vector.push_back(target_angle[5]);
1202 *goal_joint_value = target_angle_vector;
double getJointPosition(Name component_name)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
Pose getComponentPoseFromWorld(Name component_name)
void setAllActiveJointPosition(std::vector< double > joint_position_vector)
Eigen::Matrix3d getComponentRelativeOrientationFromParent(Name component_name)
Eigen::Matrix3d getComponentOrientationFromWorld(Name component_name)
std::vector< double > getAllActiveJointPosition()
Eigen::Vector3d getAxis(Name component_name)
Eigen::Vector3d getComponentRelativePositionFromParent(Name component_name)
Eigen::VectorXd poseDifference(Eigen::Vector3d desired_position, Eigen::Vector3d present_position, Eigen::Matrix3d desired_orientation, Eigen::Matrix3d present_orientation)
Name getComponentParentName(Name component_name)
void println(STRING str, STRING color="DEFAULT")
std::vector< JointValue > getAllActiveJointValue()
Eigen::Vector3d vector3(double v1, double v2, double v3)
Eigen::Matrix3d skewSymmetricMatrix(Eigen::Vector3d v)
Eigen::Vector3d positionDifference(Eigen::Vector3d desired_position, Eigen::Vector3d present_position)
void setComponentPoseFromWorld(Name component_name, Pose pose_to_world)
Eigen::Matrix3d rodriguesRotationMatrix(Eigen::Vector3d axis, double angle)
std::vector< Name > getComponentChildName(Name component_name)
Eigen::Matrix3d getWorldOrientation()
Eigen::Vector3d acceleration
Eigen::Vector3d convertRotationMatrixToRPYVector(const Eigen::Matrix3d &rotation_matrix)
Eigen::Vector3d getComponentPositionFromWorld(Name component_name)
Eigen::Matrix3d orientation
Eigen::Matrix3d convertRPYToRotationMatrix(double roll, double pitch, double yaw)