59 #include <moveit_msgs/MoveItErrorCodes.h> 60 #include <sr_utilities/sr_math_utils.hpp> 93 const std::string &group_name,
94 const std::string &base_frame,
95 const std::string &tip_frame,
96 double search_discretization)
98 setValues(robot_description, group_name, base_frame, tip_frame, search_discretization);
105 ROS_ERROR(
"Could not load robot model. Are you sure the robot model is on the parameter server?");
151 Eigen::MatrixXd Mx(6, 6);
152 for (
unsigned int i = 0; i < 6; i++)
154 for (
unsigned int j = 0; j < 6; j++)
171 double epsilon, lambda;
173 if (!private_handle.
getParam(
"maxIterations", maxIterations))
175 maxIterations = 1000;
176 ROS_WARN(
"No maxIterations on param server, using %d as default", maxIterations);
179 if (!private_handle.
getParam(
"epsilon", epsilon))
182 ROS_WARN(
"No epsilon on param server, using %f as default", epsilon);
185 if (!private_handle.
getParam(
"lambda", lambda))
188 ROS_WARN(
"No lambda on param server, using %f as default", lambda);
191 ROS_DEBUG(
"IK Solver, maxIterations: %d, epsilon: %f, lambda: %f", maxIterations, epsilon, lambda);
209 const std::vector<double> &ik_seed_state,
210 std::vector<double> &solution,
211 moveit_msgs::MoveItErrorCodes &error_code,
217 error_code.val = error_code.NO_IK_SOLUTION;
230 jnt_pos_in(i) = ik_seed_state[i];
235 for (
int i = 0; i < 10 && ik_valid < 0; i++)
237 if (
tip_frame_.find(
"thtip") != std::string::npos ||
tip_frame_.find(
"lftip") != std::string::npos)
238 ROS_DEBUG(
"IK Seed: %f, %f, %f, %f, %f", jnt_pos_in(0), jnt_pos_in(1), jnt_pos_in(2), jnt_pos_in(3),
241 ROS_DEBUG(
"IK Seed: %f, %f, %f, %f", jnt_pos_in(0), jnt_pos_in(1), jnt_pos_in(2), jnt_pos_in(3));
245 if (
tip_frame_.find(
"thtip") == std::string::npos &&
tip_frame_.find(
"lftip") == std::string::npos)
247 jnt_pos_in(3) = jnt_pos_in(2);
249 else if (
tip_frame_.find(
"lftip") != std::string::npos)
251 jnt_pos_in(4) = jnt_pos_in(3);
254 ROS_DEBUG(
"IK Recalculation step: %d", i);
259 solution.resize(dimension_);
262 solution[i] = jnt_pos_out(i);
264 error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
270 ROS_DEBUG(
"An IK solution could not be found");
271 error_code.val = moveit_msgs::MoveItErrorCodes::NO_IK_SOLUTION;
277 const std::vector<double> &ik_seed_state,
279 std::vector<double> &solution,
280 moveit_msgs::MoveItErrorCodes &error_code,
284 static std::vector<double> consistency_limits;
285 return searchPositionIK(ik_pose, ik_seed_state, timeout, consistency_limits, solution, solution_callback,
290 const std::vector<double> &ik_seed_state,
292 const std::vector<double> &consistency_limits,
293 std::vector<double> &solution,
294 moveit_msgs::MoveItErrorCodes &error_code,
298 return searchPositionIK(ik_pose, ik_seed_state, timeout, consistency_limits, solution, solution_callback,
303 const std::vector<double> &ik_seed_state,
305 std::vector<double> &solution,
307 moveit_msgs::MoveItErrorCodes &error_code,
310 static std::vector<double> consistency_limits;
311 return searchPositionIK(ik_pose, ik_seed_state, timeout, consistency_limits, solution, solution_callback,
317 const std::vector<double> &ik_seed_state,
319 const std::vector<double> &consistency_limits,
320 std::vector<double> &solution,
322 moveit_msgs::MoveItErrorCodes &error_code,
328 error_code.val = error_code.FAILURE;
331 if (!consistency_limits.empty() && consistency_limits.size() != (size_t)
dimension_)
334 error_code.val = error_code.FAILURE;
347 jnt_pos_in(i) = ik_seed_state[i];
352 for (
int i = 0; i < 10 && ik_valid < 0; i++)
354 if (
tip_frame_.find(
"thtip") != std::string::npos ||
tip_frame_.find(
"lftip") != std::string::npos)
355 ROS_DEBUG(
"IK Seed: %f, %f, %f, %f, %f", jnt_pos_in(0), jnt_pos_in(1), jnt_pos_in(2), jnt_pos_in(3),
358 ROS_DEBUG(
"IK Seed: %f, %f, %f, %f", jnt_pos_in(0), jnt_pos_in(1), jnt_pos_in(2), jnt_pos_in(3));
362 if (
tip_frame_.find(
"thtip") == std::string::npos &&
tip_frame_.find(
"lftip") == std::string::npos)
364 jnt_pos_in(3) = jnt_pos_in(2);
366 else if (
tip_frame_.find(
"lftip") != std::string::npos)
368 jnt_pos_in(4) = jnt_pos_in(3);
371 ROS_DEBUG(
"IK Recalculation step: %d", i);
376 solution.resize(dimension_);
379 solution[i] = jnt_pos_out(i);
381 error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
387 ROS_DEBUG(
"An IK solution could not be found");
388 error_code.val = moveit_msgs::MoveItErrorCodes::NO_IK_SOLUTION;
394 const std::vector<double> &joint_angles,
395 std::vector<geometry_msgs::Pose> &poses)
const 405 geometry_msgs::PoseStamped pose;
411 jnt_pos_in(i) = joint_angles[i];
415 poses.
resize(link_names.size());
419 for (
unsigned int i = 0; i < poses.size(); i++)
442 ROS_ERROR(
"Could not compute FK for %s", link_names[i].c_str());
473 double r = sr_math_utils::Random::instance().generate<
double>(min, max);
const std::vector< std::string > & getLinkNames() const
Return all the link names in the order they are represented internally.
moveit_msgs::KinematicSolverInfo ik_solver_info_
virtual int JntToCart(const JntArray &q_in, Frame &p_out, int segmentNr=-1)
static const std::string FK_SERVICE
Eigen::MatrixXd updateCouplingRF(const KDL::JntArray &q)
static const double IK_DEFAULT_TIMEOUT
const std::vector< std::string > & getJointNames() const
Return all the joint names in the order they are used internally.
virtual bool getPositionIK(const geometry_msgs::Pose &ik_pose, const std::vector< double > &ik_seed_state, std::vector< double > &solution, moveit_msgs::MoveItErrorCodes &error_code, const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions()) const
Given a desired pose of the end-effector, compute the joint angles to reach it.
unsigned int getNrOfSegments() const
virtual bool initialize(const std::string &robot_description, const std::string &group_name, const std::string &base_frame, const std::string &tip_frame, double search_discretization)
Initialization function for the kinematics.
KDL::ChainIkSolverPos_NR_JL_coupling * ik_solver_pos
void generateRandomJntSeed(KDL::JntArray &jnt_pos_in) const
This method generates a random joint array vector between the joint limits so that local minima in IK...
bool setUpdateCouplingFunction(updateFuncPtr updateFunc)
static const std::string IK_SERVICE
PLUGINLIB_EXPORT_CLASS(test_moveit_controller_manager::TestMoveItControllerManager, moveit_controller_manager::MoveItControllerManager)
Eigen::MatrixXd updateCouplingMF(const KDL::JntArray &q)
KDL::ChainFkSolverPos_recursive * fk_solver
virtual bool getPositionFK(const std::vector< std::string > &link_names, const std::vector< double > &joint_angles, std::vector< geometry_msgs::Pose > &poses) const
Given a set of joint angles and a set of links, compute their pose.
unsigned int getNrOfIndJoints() const
void setWeightTS(const Eigen::MatrixXd &Mx)
int getKDLSegmentIndex(const KDL::Chain &chain, const std::string &name)
void poseMsgToKDL(const geometry_msgs::Pose &m, KDL::Frame &k)
unsigned int getNrOfJoints() const
virtual void setValues(const std::string &robot_description, const std::string &group_name, const std::string &base_frame, const std::string &tip_frame, double search_discretization)
def xml_string(rootXml, addHeader=True)
boost::function< void(const geometry_msgs::Pose &ik_pose, const std::vector< double > &ik_solution, moveit_msgs::MoveItErrorCodes &error_code)> IKCallbackFn
Eigen::MatrixXd updateCouplingTH(const KDL::JntArray &q)
void resize(unsigned int newSize)
moveit_msgs::KinematicSolverInfo fk_solver_info_
KDL::Chain_coupling kdl_chain_
void poseKDLToMsg(const KDL::Frame &k, geometry_msgs::Pose &m)
bool getParam(const std::string &key, std::string &s) const
bool getKDLChain(const std::string &xml_string, const std::string &root_name, const std::string &tip_name, KDL::Chain &kdl_chain)
bool isActive()
Specifies if the node is active or not.
bool loadRobotModel(ros::NodeHandle node_handle, urdf::Model &robot_model, std::string &root_name, std::string &tip_name, std::string &xml_string)
Eigen::MatrixXd updateCouplingLF(const KDL::JntArray &q)
KDL::ChainIkSolverVel_wdls_coupling * ik_solver_vel
virtual bool searchPositionIK(const geometry_msgs::Pose &ik_pose, const std::vector< double > &ik_seed_state, double timeout, std::vector< double > &solution, moveit_msgs::MoveItErrorCodes &error_code, const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions()) const
virtual int CartToJnt(const JntArray &q_init, const Frame &p_in, JntArray &q_out)
Eigen::MatrixXd updateCouplingFF(const KDL::JntArray &q)
bool init_ik(urdf::Model &robot_model, const std::string &root_name, const std::string &tip_name, KDL::JntArray &joint_min, KDL::JntArray &joint_max, moveit_msgs::KinematicSolverInfo &info)
void setLambda(const double &lambda)
static const std::string IK_WITH_COLLISION_SERVICE