00001 00026 #include "constrained_ik/constrained_ik.h" 00027 #include "constrained_ik/constraints/goal_mid_joint.h" 00028 #include <pluginlib/class_list_macros.h> 00029 PLUGINLIB_EXPORT_CLASS(constrained_ik::constraints::GoalMidJoint, constrained_ik::Constraint) 00030 00031 const double DEFAULT_WEIGHT = 1.0; 00033 namespace constrained_ik 00034 { 00035 namespace constraints 00036 { 00037 00038 using namespace Eigen; 00039 00040 // initialize limits/tolerances to default values 00041 GoalMidJoint::GoalMidJoint() : Constraint(), weight_(DEFAULT_WEIGHT) 00042 { 00043 } 00044 00045 constrained_ik::ConstraintResults GoalMidJoint::evalConstraint(const SolverState &state) const 00046 { 00047 constrained_ik::ConstraintResults output; 00048 GoalMidJoint::ConstraintData cdata(state); 00049 00050 output.error = calcError(cdata); 00051 output.jacobian = calcJacobian(cdata); 00052 output.status = checkStatus(cdata); 00053 00054 return output; 00055 } 00056 00057 Eigen::VectorXd GoalMidJoint::calcError(const GoalMidJoint::ConstraintData &cdata) const 00058 { 00059 VectorXd err = mid_range_ - cdata.state_.joints; 00060 err *= weight_; 00061 return err; 00062 } 00063 00064 Eigen::MatrixXd GoalMidJoint::calcJacobian(const GoalMidJoint::ConstraintData &cdata) const 00065 { 00066 size_t n = cdata.state_.joints.size(); // number of joints 00067 MatrixXd J = MatrixXd::Identity(n,n) * weight_; 00068 return J; 00069 } 00070 00071 void GoalMidJoint::init(const Constrained_IK *ik) 00072 { 00073 Constraint::init(ik); 00074 00075 // initialize joint/thresholding limits 00076 MatrixXd joint_limits = ik->getKin().getLimits(); 00077 mid_range_ = 0.5 * (joint_limits.col(1) - joint_limits.col(0)).cwiseAbs(); 00078 mid_range_ += joint_limits.col(0); 00079 } 00080 00081 void GoalMidJoint::loadParameters(const XmlRpc::XmlRpcValue &constraint_xml) 00082 { 00083 XmlRpc::XmlRpcValue local_xml = constraint_xml; 00084 if (!getParam(local_xml, "weights", weight_)) 00085 { 00086 ROS_WARN("Goal Mid Joint: Unable to retrieve weights member, default parameter will be used."); 00087 } 00088 00089 if (!getParam(local_xml, "debug", debug_)) 00090 { 00091 ROS_WARN("Goal Mid Joint: Unable to retrieve debug member, default parameter will be used."); 00092 } 00093 } 00094 00095 } // namespace constraints 00096 } // namespace constrained_ik 00097