Go to the documentation of this file.
28 #include <console_bridge/console.h>
38 using Eigen::MatrixXd;
39 using Eigen::VectorXd;
42 const std::vector<std::pair<std::string, std::string>>& chains,
44 std::string solver_name)
45 : kdl_config_(kdl_config), solver_name_(std::move(solver_name))
48 throw std::runtime_error(
"The scene graph has an invalid root.");
51 throw std::runtime_error(
"Failed to parse KDL data from Scene Graph");
55 ik_vel_solver_ = std::make_unique<KDL::ChainIkSolverVel_pinv>(
57 ik_solver_ = std::make_unique<KDL::ChainIkSolverPos_NR>(
62 const std::string& base_link,
63 const std::string& tip_link,
65 std::string solver_name)
66 :
KDLInvKinChainNR(scene_graph, { std::make_pair(base_link, tip_link) }, kdl_config, std::move(solver_name))
81 ik_solver_ = std::make_unique<KDL::ChainIkSolverPos_NR>(
89 const Eigen::Ref<const Eigen::VectorXd>& seed,
92 assert(std::abs(1.0 - pose.matrix().determinant()) < 1e-6);
93 KDL::JntArray kdl_seed;
94 KDL::JntArray kdl_solution;
96 kdl_solution.resize(
static_cast<unsigned>(seed.size()));
97 Eigen::VectorXd solution(seed.size());
105 std::lock_guard<std::mutex> guard(
mutex_);
106 status =
ik_solver_->CartToJnt(kdl_seed, kdl_pose, kdl_solution);
112 if (status == KDL::ChainIkSolverPos_NR::E_DEGRADED)
114 CONSOLE_BRIDGE_logDebug(
"KDL NR Failed to calculate IK, solution converged to <eps in maxiter, but solution is "
115 "degraded in quality (e.g. pseudo-inverse in iksolver is singular)");
117 else if (status == KDL::ChainIkSolverPos_NR::E_IKSOLVER_FAILED)
119 CONSOLE_BRIDGE_logDebug(
"KDL NR Failed to calculate IK, velocity solver failed");
121 else if (status == KDL::ChainIkSolverPos_NR::E_NO_CONVERGE)
123 CONSOLE_BRIDGE_logDebug(
"KDL NR Failed to calculate IK, no solution found");
125 #ifndef KDL_LESS_1_4_0
126 else if (status == KDL::ChainIkSolverPos_NR::E_MAX_ITERATIONS_EXCEEDED)
128 CONSOLE_BRIDGE_logDebug(
"KDL NR Failed to calculate IK, max iteration exceeded");
133 CONSOLE_BRIDGE_logDebug(
"KDL NR Failed to calculate IK");
145 const Eigen::Ref<const Eigen::VectorXd>& seed)
const
KDLChainData kdl_data_
KDL data parsed from Scene Graph.
std::unique_ptr< KDL::ChainFkSolverPos_recursive > fk_solver_
KDL Forward Kinematic Solver.
std::unique_ptr< KDL::ChainIkSolverPos_NR > ik_solver_
KDL Inverse kinematic solver.
Config kdl_config_
KDL configuration data parsed from YAML.
std::string base_link_name
Link name of first link in the kinematic object.
std::string tip_link_name
Link name of last kink in the kinematic object.
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
IKSolutions calcInvKinHelper(const Eigen::Isometry3d &pose, const Eigen::Ref< const Eigen::VectorXd > &seed, int segment_num=-1) const
calcFwdKin helper function
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
InverseKinematics::UPtr clone() const override final
Clone the forward kinematics object.
std::unique_ptr< KDL::ChainIkSolverVel_pinv > ik_vel_solver_
KDL Inverse kinematic velocity solver.
std::vector< std::string > getTipLinkNames() const override final
Get the names of the tip links of the kinematics group.
std::unique_ptr< InverseKinematics > UPtr
IKSolutions calcInvKin(const tesseract_common::TransformMap &tip_link_poses, const Eigen::Ref< const Eigen::VectorXd > &seed) const override final
Calculates joint solutions given a pose for each tip link.
KDLInvKinChainNR(const KDLInvKinChainNR &other)
std::vector< std::string > joint_names
List of joint names.
KDLChainData kdl_data_
KDL data parsed from Scene Graph.
Config kdl_config_
KDL configuration data parsed from YAML.
KDLInvKinChainNR & operator=(const KDLInvKinChainNR &other)
std::string getWorkingFrame() const override final
Get the inverse kinematics working frame.
std::string getSolverName() const override final
Get the name of the solver. Recommend using the name of the class.
void EigenToKDL(const Eigen::Isometry3d &transform, KDL::Frame &frame)
Convert Eigen::Isometry3d to KDL::Frame.
std::string solver_name_
Name of this solver.
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
const std::string & getRoot() const
std::string getBaseLinkName() const override final
Get the robot base link name.
std::unique_ptr< KDL::ChainIkSolverPos_LMA > ik_solver_
KDL Inverse kinematic solver.
std::shared_ptr< const Link > getLink(const std::string &name) const
KDL Inverse kinematic chain implementation.
std::vector< Eigen::VectorXd > IKSolutions
The inverse kinematics solutions container.
KDL::Chain robot_chain
KDL Chain object.
std::mutex mutex_
KDL is not thread safe due to mutable variables in Joint Class.
std::vector< std::string > getJointNames() const override final
Get list of joint names for kinematic object.
bool parseSceneGraph(KDLChainData &results, const tesseract_scene_graph::SceneGraph &scene_graph, const std::vector< std::pair< std::string, std::string >> &chains)
Parse KDL chain data from the scene graph.
void KDLToEigen(const KDL::Frame &frame, Eigen::Isometry3d &transform)
Convert KDL::Frame to Eigen::Isometry3d.
Eigen::Index numJoints() const override final
Number of joints in robot.