39 using namespace Eigen;
42 PR2ArmIKSolver::PR2ArmIKSolver(
const urdf::Model &robot_model,
43 const std::string &root_frame_name,
44 const std::string &tip_frame_name,
45 const double &search_discretization_angle,
46 const int &free_angle):ChainIkSolverPos()
49 search_discretization_angle_ = search_discretization_angle;
50 free_angle_ = free_angle;
51 root_frame_name_ = root_frame_name;
52 if(!pr2_arm_ik_->init(robot_model, root_frame_name, tip_frame_name))
58 void PR2ArmIKSolver::getSolverInfo(moveit_msgs::KinematicSolverInfo &response)
68 std::vector<std::vector<double> > solution_ik;
79 if(solution_ik.empty())
82 double min_distance = 1e6;
85 for(
int i=0; i< (int) solution_ik.size(); ++i)
87 ROS_DEBUG(
"Solution : %d", (
int)solution_ik.size());
88 for(
int j=0; j < (int)solution_ik[i].size(); j++)
90 ROS_DEBUG(
"Joint %d: %f", j, solution_ik[i][j]);
94 if(tmp_distance < min_distance)
96 min_distance = tmp_distance;
103 q_out.
resize((
int)solution_ik[min_index].size());
104 for(
int i=0; i < (int)solution_ik[min_index].size(); ++i)
106 q_out(i) = solution_ik[min_index][i];
116 std::vector<KDL::JntArray> &q_out)
119 std::vector<std::vector<double> > solution_ik;
131 if(solution_ik.empty())
136 for(
int i=0; i< (int) solution_ik.size(); ++i)
138 for(
int j=0; j < 7; j++)
140 q(j) = solution_ik[i][j];
148 const int &max_count,
149 const int &min_count)
153 if(-count >= min_count)
158 else if(count+1 <= max_count)
170 if(1-count <= max_count)
175 else if(count-1 >= min_count)
187 std::vector<KDL::JntArray> &q_out,
188 const double &timeout)
194 double loop_time = 0;
199 ROS_DEBUG(
"positive increments, negative increments: %d %d", num_positive_increments, num_negative_increments);
200 while(loop_time < timeout)
204 if(!
getCount(count, num_positive_increments, -num_negative_increments))
210 if(loop_time >= timeout)
212 ROS_DEBUG(
"IK Timed out in %f seconds", timeout);
226 const double &timeout,
227 const double& consistency_limit)
229 moveit_msgs::MoveItErrorCodes error_code;
231 return CartToJntSearch(q_in, p_in, q_out, timeout,
true, consistency_limit, error_code, solution_callback);
237 const double &timeout,
238 moveit_msgs::MoveItErrorCodes &error_code,
241 return CartToJntSearch(q_in, p_in, q_out, timeout,
false, 0.0, error_code, solution_callback);
248 const double &timeout,
249 const double& consistency_limit,
250 moveit_msgs::MoveItErrorCodes &error_code,
253 return CartToJntSearch(q_in, p_in, q_out, timeout,
true, consistency_limit, error_code, solution_callback);
259 const double &timeout,
260 bool use_consistency_limit,
261 const double &max_consistency,
262 moveit_msgs::MoveItErrorCodes &error_code,
269 double loop_time = 0;
272 double max_limit, min_limit;
273 if(use_consistency_limit)
287 if(use_consistency_limit)
289 ROS_DEBUG(
"Consistency[Joint: %d]: Initial guess %f, consistency %f",
free_angle_, initial_guess, max_consistency);
300 ROS_DEBUG(
"positive increments, negative increments: %d %d", num_positive_increments, num_negative_increments);
302 unsigned int testnum = 0;
303 geometry_msgs::Pose ik_pose_msg;
308 while(loop_time < timeout)
313 if(solution_callback)
315 std::vector<double> ik_solution(7,0.0);
316 for(
int i=0; i < 7; ++i)
317 ik_solution[i] = q_out(i);
319 solution_callback(ik_pose_msg, ik_solution, error_code);
320 if(error_code.val == error_code.SUCCESS)
329 error_code.val = error_code.SUCCESS;
333 if(!
getCount(count, num_positive_increments, -num_negative_increments))
336 error_code.val = error_code.NO_IK_SOLUTION;
343 if(loop_time >= timeout)
345 ROS_DEBUG(
"IK Timed out in %f seconds",timeout);
346 error_code.val = error_code.TIMED_OUT;
350 error_code.val = error_code.NO_IK_SOLUTION;
356 std::string PR2ArmIKSolver::getFrameId()
361 void PR2ArmIKSolver::updateInternalDataStructures()
double search_discretization_angle_
Namespace for the PR2ArmKinematics.
bool getCount(int &count, const int &max_count, const int &min_count)
int CartToJntSearch(const KDL::JntArray &q_in, const KDL::Frame &p_in, KDL::JntArray &q_out, const double &timeout)
std::string root_frame_name_
static const int NO_IK_SOLUTION
void computeIKShoulderRoll(const Eigen::Affine3f &g_in, const double &shoulder_roll_initial_guess, std::vector< std::vector< double > > &solution) const
int CartToJnt(const KDL::JntArray &q_init, const KDL::Frame &p_in, KDL::JntArray &q_out)
Eigen::Affine3f KDLToEigenMatrix(const KDL::Frame &p)
boost::function< void(const geometry_msgs::Pose &ik_pose, const std::vector< double > &ik_solution, moveit_msgs::MoveItErrorCodes &error_code)> IKCallbackFn
void resize(unsigned int newSize)
void getSolverInfo(moveit_msgs::KinematicSolverInfo &info)
void computeIKShoulderPan(const Eigen::Affine3f &g_in, const double &shoulder_pan_initial_guess, std::vector< std::vector< double > > &solution) const
void poseKDLToMsg(const KDL::Frame &k, geometry_msgs::Pose &m)
static const int TIMED_OUT
moveit_msgs::KinematicSolverInfo solver_info_
get chain information about the arm.
double computeEuclideanDistance(const std::vector< double > &array_1, const KDL::JntArray &array_2)