36 #include <kdl/tree.hpp> 46 const std::string& group_name,
47 const std::string& base_name,
48 const std::string& tip_name,
49 double search_discretization)
51 setValues(robot_description, group_name, base_name, tip_name, search_discretization);
58 std::string urdf_xml, full_urdf_xml;
59 node_handle.
param(
"urdf_xml", urdf_xml, robot_description);
63 if (!node_handle.
getParam(full_urdf_xml, xml_string))
65 ROS_FATAL_NAMED(
"trac_ik",
"Could not load the xml from parameter server: %s", urdf_xml.c_str());
69 node_handle.
param(full_urdf_xml, xml_string, std::string());
78 ROS_FATAL(
"Failed to extract kdl tree from xml robot description");
84 ROS_FATAL(
"Couldn't find chain %s to %s", base_name.c_str(), tip_name.c_str());
92 urdf::JointConstSharedPtr joint;
94 std::vector<double> l_bounds, u_bounds;
100 for (
unsigned int i = 0; i < chain_segs.size(); ++i)
104 joint = robot_model.getJoint(chain_segs[i].getJoint().
getName());
105 if (joint->type != urdf::Joint::UNKNOWN && joint->type != urdf::Joint::FIXED)
112 if (joint->type != urdf::Joint::CONTINUOUS)
116 lower = std::max(joint->limits->lower, joint->safety->soft_lower_limit);
117 upper = std::min(joint->limits->upper, joint->safety->soft_upper_limit);
121 lower = joint->limits->lower;
122 upper = joint->limits->upper;
137 joint_min(joint_num - 1) = std::numeric_limits<float>::lowest();
138 joint_max(joint_num - 1) = std::numeric_limits<float>::max();
144 ROS_INFO_NAMED(
"trac-ik plugin",
"Looking in common namespaces for param name: %s", (group_name +
"/position_only_ik").c_str());
146 ROS_INFO_NAMED(
"trac-ik plugin",
"Looking in common namespaces for param name: %s", (group_name +
"/solve_type").c_str());
171 const std::vector<double> &joint_angles,
172 std::vector<geometry_msgs::Pose> &poses)
const 179 poses.resize(link_names.size());
187 geometry_msgs::PoseStamped pose;
193 jnt_pos_in(i) = joint_angles[i];
199 for (
unsigned int i = 0; i < poses.size(); i++)
208 ROS_ERROR_NAMED(
"trac_ik",
"Could not compute FK for %s", link_names[i].c_str());
218 const std::vector<double> &ik_seed_state,
219 std::vector<double> &solution,
220 moveit_msgs::MoveItErrorCodes &error_code,
224 std::vector<double> consistency_limits;
237 const std::vector<double> &ik_seed_state,
239 std::vector<double> &solution,
240 moveit_msgs::MoveItErrorCodes &error_code,
244 std::vector<double> consistency_limits;
257 const std::vector<double> &ik_seed_state,
259 const std::vector<double> &consistency_limits,
260 std::vector<double> &solution,
261 moveit_msgs::MoveItErrorCodes &error_code,
276 const std::vector<double> &ik_seed_state,
278 std::vector<double> &solution,
280 moveit_msgs::MoveItErrorCodes &error_code,
283 std::vector<double> consistency_limits;
295 const std::vector<double> &ik_seed_state,
297 const std::vector<double> &consistency_limits,
298 std::vector<double> &solution,
300 moveit_msgs::MoveItErrorCodes &error_code,
314 const std::vector<double> &ik_seed_state,
316 std::vector<double> &solution,
318 moveit_msgs::MoveItErrorCodes &error_code,
319 const std::vector<double> &consistency_limits,
327 error_code.val = error_code.NO_IK_SOLUTION;
334 error_code.val = error_code.NO_IK_SOLUTION;
344 in(
z) = ik_seed_state[
z];
350 bounds.
rot.
x(std::numeric_limits<float>::max());
351 bounds.
rot.
y(std::numeric_limits<float>::max());
352 bounds.
rot.
z(std::numeric_limits<float>::max());
376 int rc = ik_solver.
CartToJnt(in, frame, out, bounds);
379 solution.resize(num_joints_);
384 solution[
z] = out(
z);
387 if (!solution_callback.empty())
389 solution_callback(ik_pose, solution, error_code);
390 if (error_code.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
405 error_code.val = moveit_msgs::MoveItErrorCodes::NO_IK_SOLUTION;
#define ROS_INFO_NAMED(name,...)
const Segment & getSegment(unsigned int nr) const
virtual int JntToCart(const JntArray &q_in, Frame &p_out, int segmentNr=-1)
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_ERROR_STREAM_NAMED(name, args)
URDF_EXPORT bool initString(const std::string &xmlstring)
KDL_PARSER_PUBLIC bool treeFromUrdfModel(const urdf::ModelInterface &robot_model, KDL::Tree &tree)
unsigned int getNrOfSegments() const
std::string getName(void *handle)
#define ROS_DEBUG_NAMED(name,...)
const std::string & getName() const
std::vector< std::string > link_names_
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.
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 CartToJnt(const KDL::JntArray &q_init, const KDL::Frame &p_in, KDL::JntArray &q_out, const KDL::Twist &bounds=KDL::Twist::Zero())
void poseMsgToKDL(const geometry_msgs::Pose &m, KDL::Frame &k)
bool initialize(const std::string &robot_description, const std::string &group_name, const std::string &base_name, const std::string &tip_name, double search_discretization)
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)
bool lookupParam(const std::string ¶m, T &val, const T &default_val) const
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)
bool getChain(const std::string &chain_root, const std::string &chain_tip, Chain &chain) const
#define ROS_INFO_STREAM(args)
void poseKDLToMsg(const KDL::Frame &k, geometry_msgs::Pose &m)
bool getParam(const std::string &key, std::string &s) const
std::vector< Segment > segments
#define ROS_FATAL_NAMED(name,...)
#define ROS_ERROR_NAMED(name,...)
int getKDLSegmentIndex(const std::string &name) const
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.
PLUGINLIB_EXPORT_CLASS(trac_ik_kinematics_plugin::TRAC_IKKinematicsPlugin, kinematics::KinematicsBase)
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
Given a desired pose of the end-effector, search for the joint angles required to reach it...
std::vector< std::string > joint_names_
#define ROS_WARN_STREAM_NAMED(name, args)