47 std::string &tip_name, std::string &xml_string)
49 std::string urdf_xml, full_urdf_xml;
50 node_handle.
param(
"urdf_xml", urdf_xml, std::string(
"robot_description"));
53 ROS_DEBUG(
"Reading xml file from parameter server\n");
55 if (node_handle.
getParam(full_urdf_xml, result))
57 xml.Parse(result.c_str());
61 ROS_FATAL(
"Could not load the xml from parameter server: %s\n", urdf_xml.c_str());
65 TiXmlElement *root_element = xml.RootElement();
66 TiXmlElement *root = xml.FirstChildElement(
"robot");
67 if (!root || !root_element)
69 ROS_FATAL(
"Could not parse the xml from %s\n", urdf_xml.c_str());
74 if (root_name.find(
"palm") == std::string::npos)
76 ROS_FATAL(
"HANDIK: Current solver can only resolve to root frame = palm");
80 if (tip_name.find(
"tip") == std::string::npos)
82 ROS_FATAL(
"Current solver can only resolve to one of the tip frames");
85 if (tip_name.find(
"fftip") == std::string::npos && tip_name.find(
"mftip") == std::string::npos &&
86 tip_name.find(
"rftip") == std::string::npos && tip_name.find(
"lftip") == std::string::npos &&
87 tip_name.find(
"thtip") == std::string::npos)
89 ROS_FATAL(
"Name of distal frame does not match any finger");
96 bool getKDLChain(
const std::string &xml_string,
const std::string &root_name,
const std::string &tip_name,
103 ROS_ERROR(
"Could not initialize tree object");
106 if (!tree.
getChain(root_name, tip_name, kdl_chain))
108 ROS_ERROR_STREAM(
"Could not initialize chain object for base " << root_name <<
" tip " << tip_name);
114 bool getKDLTree(
const std::string &xml_string,
const std::string &root_name,
const std::string &tip_name,
120 ROS_ERROR(
"Could not initialize tree object");
128 moveit_msgs::KinematicSolverInfo &chain_info)
139 const std::string &name)
155 const moveit_msgs::KinematicSolverInfo &chain_info)
157 for (
unsigned int i = 0; i < chain_info.joint_names.size(); i++)
160 for (
unsigned int j = 0; j < joint_names.size(); j++)
162 if (chain_info.joint_names[i] == joint_names[j])
170 ROS_ERROR(
"Joint state does not contain joint state for %s.", chain_info.joint_names[i].c_str());
178 const moveit_msgs::KinematicSolverInfo &chain_info)
180 if (link_names.empty())
184 for (
unsigned int i = 0; i < link_names.size(); i++)
195 const moveit_msgs::KinematicSolverInfo &chain_info)
197 for (
unsigned int i = 0; i < chain_info.link_names.size(); i++)
199 if (link_name == chain_info.link_names[i])
208 const moveit_msgs::KinematicSolverInfo &chain_info)
210 if (robot_state.joint_state.position.size() != robot_state.joint_state.name.size())
213 "Number of joints in robot_state.joint_state does not match number of" 214 " positions in robot_state.joint_state");
219 ROS_ERROR(
"Robot state must contain joint state for every joint in the kinematic chain");
226 moveit_msgs::GetPositionFK::Response &response,
227 const moveit_msgs::KinematicSolverInfo &chain_info)
231 ROS_ERROR(
"Link name in service request does not match links that kinematics can provide solutions for.");
232 response.error_code.val = response.error_code.INVALID_LINK_NAME;
237 response.error_code.val = response.error_code.INVALID_ROBOT_STATE;
244 moveit_msgs::GetPositionIK::Response &response,
245 const moveit_msgs::KinematicSolverInfo &chain_info)
247 if (!
checkLinkName(request.ik_request.ik_link_name, chain_info))
249 ROS_ERROR(
"Link name in service request does not match links that kinematics can provide solutions for.");
250 response.error_code.val = response.error_code.INVALID_LINK_NAME;
255 response.error_code.val = response.error_code.INVALID_ROBOT_STATE;
260 response.error_code.val = response.error_code.TIMED_OUT;
266 int getJointIndex(
const std::string &name,
const moveit_msgs::KinematicSolverInfo &chain_info)
268 for (
unsigned int i = 0; i < chain_info.joint_names.size(); i++)
270 if (chain_info.joint_names[i] == name)
280 const std::string &root_frame,
283 geometry_msgs::PoseStamped pose_stamped;
294 geometry_msgs::PoseStamped &pose_msg_out,
295 const std::string &root_frame,
298 geometry_msgs::PoseStamped pose_msg_in = pose_msg;
299 ROS_DEBUG(
"Request:\nframe_id: %s\nPosition: %f %f %f\n:Orientation: %f %f %f %f\n",
300 pose_msg_in.header.frame_id.c_str(),
301 pose_msg_in.pose.position.x,
302 pose_msg_in.pose.position.y,
303 pose_msg_in.pose.position.z,
304 pose_msg_in.pose.orientation.x,
305 pose_msg_in.pose.orientation.y,
306 pose_msg_in.pose.orientation.z,
307 pose_msg_in.pose.orientation.w);
308 pose_msg_out = pose_msg;
310 poseStampedMsgToTF(pose_msg_in, pose_stamped);
317 ROS_ERROR(
"hand_ik:: Cannot transform from '%s' to '%s'. TF said: %s", pose_stamped.
frame_id_.c_str(),
318 root_frame.c_str(), err.c_str());
328 ROS_ERROR(
"hand_ik:: Cannot transform from '%s' to '%s'", pose_stamped.
frame_id_.c_str(), root_frame.c_str());
337 Eigen::MatrixXd cm(4, 3);
338 for (
unsigned int i = 0; i < 4; i++)
340 for (
unsigned int j = 0; j < 3; j++)
356 Eigen::MatrixXd cm(4, 3);
357 for (
unsigned int i = 0; i < 4; i++)
359 for (
unsigned int j = 0; j < 3; j++)
375 Eigen::MatrixXd cm(4, 3);
376 for (
unsigned int i = 0; i < 4; i++)
378 for (
unsigned int j = 0; j < 3; j++)
394 Eigen::MatrixXd cm(5, 4);
395 for (
unsigned int i = 0; i < 5; i++)
397 for (
unsigned int j = 0; j < 4; j++)
415 return Eigen::MatrixXd::Identity(5, 5);
421 unsigned int num_joints = 0;
426 urdf::Vector3 length;
428 while (link && link->name != root_name)
430 joint = robot_model.getJoint(link->parent_joint->name);
433 ROS_ERROR(
"Could not find joint: %s", link->parent_joint->name.c_str());
436 if (joint->type != urdf::Joint::UNKNOWN && joint->type != urdf::Joint::FIXED)
438 ROS_DEBUG(
"adding joint: [%s]", joint->name.c_str());
441 link = robot_model.getLink(link->getParent()->name);
444 joint_min.
resize(num_joints);
445 joint_max.
resize(num_joints);
446 info.joint_names.resize(num_joints);
447 info.link_names.resize(num_joints);
448 info.limits.resize(num_joints);
450 link = robot_model.getLink(tip_name);
452 while (link && i < num_joints)
454 joint = robot_model.getJoint(link->parent_joint->name);
455 if (joint->type != urdf::Joint::UNKNOWN && joint->type != urdf::Joint::FIXED)
457 ROS_DEBUG(
"getting bounds for joint: [%s]", joint->name.c_str());
461 if (joint->type != urdf::Joint::CONTINUOUS)
463 lower = joint->limits->lower;
464 upper = joint->limits->upper;
473 int index = num_joints - i - 1;
474 joint_min.
data[index] = lower;
475 joint_max.
data[index] = upper;
476 info.joint_names[index] = joint->name;
477 info.link_names[index] = link->name;
478 info.limits[index].joint_name = joint->name;
479 info.limits[index].has_position_limits = hasLimits;
480 info.limits[index].min_position = lower;
481 info.limits[index].max_position = upper;
484 link = robot_model.getLink(link->getParent()->name);
const Segment & getSegment(unsigned int nr) const
bool checkRobotState(moveit_msgs::RobotState &robot_state, const moveit_msgs::KinematicSolverInfo &chain_info)
Eigen::MatrixXd updateCouplingRF(const KDL::JntArray &q)
static const double IK_DEFAULT_TIMEOUT
static void poseStampedTFToMsg(const Stamped< Pose > &bt, geometry_msgs::PoseStamped &msg)
bool convertPoseToRootFrame(const geometry_msgs::PoseStamped &pose_msg, KDL::Frame &pose_kdl, const std::string &root_frame, tf::TransformListener &tf)
URDF_EXPORT bool initXml(TiXmlElement *xml)
unsigned int getNrOfSegments() const
bool checkIKService(moveit_msgs::GetPositionIK::Request &request, moveit_msgs::GetPositionIK::Response &response, const moveit_msgs::KinematicSolverInfo &chain_info)
bool getKDLTree(const std::string &xml_string, const std::string &root_name, const std::string &tip_name, KDL::Tree &kdl_chain)
int getJointIndex(const std::string &name, const moveit_msgs::KinematicSolverInfo &chain_info)
Eigen::MatrixXd updateCouplingMF(const KDL::JntArray &q)
const std::string & getName() const
bool searchParam(const std::string &key, std::string &result) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int getKDLSegmentIndex(const KDL::Chain &chain, const std::string &name)
void poseMsgToKDL(const geometry_msgs::Pose &m, KDL::Frame &k)
void getKDLChainInfo(const KDL::Chain &chain, moveit_msgs::KinematicSolverInfo &chain_info)
KDL_PARSER_PUBLIC bool treeFromString(const std::string &xml, KDL::Tree &tree)
Eigen::MatrixXd updateCouplingTH(const KDL::JntArray &q)
void resize(unsigned int newSize)
bool getChain(const std::string &chain_root, const std::string &chain_tip, Chain &chain) const
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 loadRobotModel(ros::NodeHandle node_handle, urdf::Model &robot_model, std::string &root_name, std::string &tip_name, std::string &xml_string)
bool checkJointNames(const std::vector< std::string > &joint_names, const moveit_msgs::KinematicSolverInfo &chain_info)
Eigen::MatrixXd updateCouplingLF(const KDL::JntArray &q)
#define ROS_ERROR_STREAM(args)
bool checkLinkName(const std::string &link_name, const moveit_msgs::KinematicSolverInfo &chain_info)
Eigen::MatrixXd updateCouplingFF(const KDL::JntArray &q)
bool checkLinkNames(const std::vector< std::string > &link_names, const moveit_msgs::KinematicSolverInfo &chain_info)
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)
bool checkFKService(moveit_msgs::GetPositionFK::Request &request, moveit_msgs::GetPositionFK::Response &response, const moveit_msgs::KinematicSolverInfo &chain_info)