Go to the documentation of this file.00001
00026 #include "constrained_ik/constrained_ik.h"
00027 #include "constrained_ik/constraints/goal_tool_pointing.h"
00028 #include "constrained_ik/constraints/goal_orientation.h"
00029 #include <pluginlib/class_list_macros.h>
00030 PLUGINLIB_EXPORT_CLASS(constrained_ik::constraints::GoalToolPointing, constrained_ik::Constraint)
00031
00032 const double DEFAULT_POSITION_TOLERANCE = 0.001;
00033 const double DEFAULT_ORIENTATION_TOLERANCE = 0.009;
00035 namespace constrained_ik
00036 {
00037 namespace constraints
00038 {
00039
00040 using namespace Eigen;
00041
00042
00043 GoalToolPointing::GoalToolPointing() : Constraint(), pos_err_tol_(DEFAULT_POSITION_TOLERANCE), rot_err_tol_(DEFAULT_ORIENTATION_TOLERANCE), weight_(VectorXd::Ones(5).asDiagonal())
00044 {
00045 }
00046
00047 constrained_ik::ConstraintResults GoalToolPointing::evalConstraint(const SolverState &state) const
00048 {
00049 constrained_ik::ConstraintResults output;
00050 GoalToolPointing::GoalToolPointingData cdata(state);
00051
00052 output.error = calcError(cdata);
00053 output.jacobian = calcJacobian(cdata);
00054 output.status = checkStatus(cdata);
00055
00056 return output;
00057 }
00058
00059 Eigen::VectorXd GoalToolPointing::calcError(const GoalToolPointing::GoalToolPointingData &cdata) const
00060 {
00061 Matrix<double, 5, 1> err, tmp_err;
00062 MatrixXd R = cdata.state_.pose_estimate.rotation().transpose();
00063
00064 tmp_err << (R * (cdata.state_.goal.translation() - cdata.state_.pose_estimate.translation())),
00065 (R * GoalOrientation::calcAngleError(cdata.state_.pose_estimate, cdata.state_.goal)).topRows(2);
00066
00067 err = weight_ * tmp_err;
00068
00069 return err;
00070 }
00071
00072 Eigen::MatrixXd GoalToolPointing::calcJacobian(const GoalToolPointing::GoalToolPointingData &cdata) const
00073 {
00074 MatrixXd tmpJ, J, Jt, R;
00075
00076 if (!ik_->getKin().calcJacobian(cdata.state_.joints, tmpJ))
00077 throw std::runtime_error("Failed to calculate Jacobian");
00078
00079
00080 R = cdata.state_.pose_estimate.rotation().transpose();
00081 Jt.resize(5, ik_->numJoints());
00082 Jt << (R * tmpJ.topRows(3)),
00083 (R * tmpJ.bottomRows(3)).topRows(2);
00084
00085
00086 J = weight_ * Jt;
00087
00088 return J;
00089 }
00090
00091 bool GoalToolPointing::checkStatus(const GoalToolPointing::GoalToolPointingData &cdata) const
00092 {
00093
00094 if (cdata.pos_err_ < pos_err_tol_ && cdata.rot_err_ < rot_err_tol_)
00095 return true;
00096
00097 return false;
00098 }
00099
00100 void GoalToolPointing::loadParameters(const XmlRpc::XmlRpcValue &constraint_xml)
00101 {
00102 XmlRpc::XmlRpcValue local_xml = constraint_xml;
00103 if (!getParam(local_xml, "position_tolerance", pos_err_tol_))
00104 {
00105 ROS_WARN("Goal Tool Pointing: Unable to retrieve position_tolerance member, default parameter will be used.");
00106 }
00107
00108 if (!getParam(local_xml, "orientation_tolerance", rot_err_tol_))
00109 {
00110 ROS_WARN("Goal Tool Pointing: Unable to retrieve orientation_tolerance member, default parameter will be used.");
00111 }
00112
00113 Eigen::VectorXd weights;
00114 if (getParam(local_xml, "weights", weights))
00115 {
00116 if (weights.size() == 5)
00117 {
00118 weight_ = weights.asDiagonal();
00119 }
00120 else
00121 {
00122 ROS_WARN("Gool Tool Pointing: Unable to add weights member, value must be a array of size 5.");
00123 }
00124 }
00125 else
00126 {
00127 ROS_WARN("Gool Tool Pointing: Unable to retrieve weights member, default parameter will be used.");
00128 }
00129
00130 if (!getParam(local_xml, "debug", debug_))
00131 {
00132 ROS_WARN("Goal Tool Pointing: Unable to retrieve debug member, default parameter will be used.");
00133 }
00134 }
00135
00136 GoalToolPointing::GoalToolPointingData::GoalToolPointingData(const SolverState &state): ConstraintData(state)
00137 {
00138 MatrixXd R = state_.pose_estimate.rotation().transpose();
00139 pos_err_ = (R * (state_.pose_estimate.translation() - state_.goal.translation())).norm();
00140 rot_err_ = (R * GoalOrientation::calcAngleError(state_.pose_estimate, state_.goal)).topRows(2).norm();
00141 }
00142
00143 }
00144 }
00145
00146