tool_position.cpp
Go to the documentation of this file.
00001 
00026 #include "constrained_ik/constrained_ik.h"
00027 #include "constrained_ik/constraints/tool_position.h"
00028 #include <ros/ros.h>
00029 #include <pluginlib/class_list_macros.h>
00030 PLUGINLIB_EXPORT_CLASS(constrained_ik::constraints::ToolPosition, constrained_ik::Constraint)
00031 
00032 namespace constrained_ik
00033 {
00034 namespace constraints
00035 {
00036 
00037 using namespace Eigen;
00038 
00039 // initialize limits/tolerances to default values
00040 ToolPosition::ToolPosition() : GoalPosition()
00041 {
00042 }
00043 
00044 constrained_ik::ConstraintResults ToolPosition::evalConstraint(const SolverState &state) const
00045 {
00046   constrained_ik::ConstraintResults output;
00047   GoalPosition::GoalPositionData cdata(state);
00048 
00049   output.error = calcError(cdata);
00050   output.jacobian = calcJacobian(cdata);
00051   output.status = checkStatus(cdata);
00052 
00053   return output;
00054 }
00055 
00056 Eigen::VectorXd ToolPosition::calcError(const GoalPosition::GoalPositionData &cdata) const
00057 {
00058   //rotate jacobian into tool frame by premultiplying by otR.transpose()
00059   Vector3d err = cdata.state_.pose_estimate.rotation().transpose() * GoalPosition::calcError(cdata);
00060 
00061   ROS_ASSERT(err.rows() == 3);
00062   return err;
00063 }
00064 
00065 // translate cartesian errors into joint-space errors
00066 Eigen::MatrixXd ToolPosition::calcJacobian(const GoalPosition::GoalPositionData &cdata) const
00067 {
00068   MatrixXd tmpJ;
00069   if (!ik_->getKin().calcJacobian(cdata.state_.joints, tmpJ))
00070     throw std::runtime_error("Failed to calculate Jacobian");
00071 
00072   //rotate jacobian into tool frame by premultiplying by otR.transpose()
00073   MatrixXd J = cdata.state_.pose_estimate.rotation().transpose() * tmpJ.topRows(3);
00074 
00075   // weight each row of J
00076   for (size_t ii=0; ii<3; ++ii)
00077       J.row(ii) *= weight_(ii);
00078 
00079   ROS_ASSERT(J.rows() == 3);
00080   return J;
00081 }
00082 
00083 } // namespace constraints
00084 } // namespace constrained_ik
00085 


constrained_ik
Author(s): Chris Lewis , Jeremy Zoss , Dan Solomon
autogenerated on Sat Jun 8 2019 19:23:45