39 #include <urdf_model/model.h>
40 #include <urdf/model.h>
41 #include <Eigen/Geometry>
43 #include <kdl/chainiksolver.hpp>
44 #include <moveit_msgs/srv/get_position_fk.hpp>
45 #include <moveit_msgs/srv/get_position_ik.hpp>
46 #include <moveit_msgs/msg/kinematic_solver_info.hpp>
47 #include <rclcpp/rclcpp.hpp>
51 static const int NUM_JOINTS_ARM7DOF = 7;
53 static const double IK_EPS = 1e-5;
55 inline double distance(
const urdf::Pose& transform)
57 return sqrt(transform.position.x * transform.position.x + transform.position.y * transform.position.y +
58 transform.position.z * transform.position.z);
61 inline bool solveQuadratic(
const double&
a,
const double& b,
const double&
c,
double* x1,
double* x2)
63 double discriminant = b * b - 4 *
a *
c;
71 if (discriminant >= 0)
73 *x1 = (-b + sqrt(discriminant)) / (2 *
a);
74 *x2 = (-b - sqrt(discriminant)) / (2 *
a);
77 else if (fabs(discriminant) < IK_EPS)
91 inline bool solveCosineEqn(
const double&
a,
const double& b,
const double&
c,
double& soln1,
double& soln2)
93 double theta1 = atan2(b,
a);
94 double denom = sqrt(
a *
a + b * b);
96 if (fabs(denom) < IK_EPS)
99 std::cout <<
"denom: " << denom <<
'\n';
103 double rhs_ratio =
c / denom;
104 if (rhs_ratio < -1 || rhs_ratio > 1)
107 std::cout <<
"rhs_ratio: " << rhs_ratio <<
'\n';
111 double acos_term = acos(rhs_ratio);
112 soln1 = theta1 + acos_term;
113 soln2 = theta1 - acos_term;
136 bool init(
const urdf::ModelInterface& robot_model,
const std::string& root_name,
const std::string& tip_name);
143 void computeIKShoulderPan(
const Eigen::Isometry3f& g_in,
const double& shoulder_pan_initial_guess,
144 std::vector<std::vector<double> >& solution)
const;
152 std::vector<std::vector<double> >& solution)
const;
161 void getSolverInfo(moveit_msgs::msg::KinematicSolverInfo& info);
171 void addJointToChainInfo(
const urdf::JointConstSharedPtr& joint, moveit_msgs::msg::KinematicSolverInfo& info);
173 bool checkJointLimits(
const std::vector<double>& joint_values)
const;
175 bool checkJointLimits(
const double& joint_value,
const int& joint_num)
const;
177 Eigen::Isometry3f grhs_, gf_, home_inv_;
179 std::vector<double> angle_multipliers_;
181 std::vector<double> solution_;
183 double shoulder_upperarm_offset_, upperarm_elbow_offset_, elbow_wrist_offset_, shoulder_wrist_offset_,
184 shoulder_elbow_offset_, torso_shoulder_offset_x_, torso_shoulder_offset_y_, torso_shoulder_offset_z_;
186 std::vector<double> min_angles_;
188 std::vector<double> max_angles_;
190 std::vector<bool> continuous_joint_;
ROS/KDL based interface for the inverse kinematics of the PR2 arm.
void computeIKShoulderRoll(const Eigen::Isometry3f &g_in, const double &shoulder_roll_initial_guess, std::vector< std::vector< double > > &solution) const
compute IK based on an initial guess for the shoulder roll angle. h
bool init(const urdf::ModelInterface &robot_model, const std::string &root_name, const std::string &tip_name)
Initialize the solver by providing a urdf::Model and a root and tip name.
void computeIKShoulderPan(const Eigen::Isometry3f &g_in, const double &shoulder_pan_initial_guess, std::vector< std::vector< double > > &solution) const
compute IK based on an initial guess for the shoulder pan angle.
moveit_msgs::msg::KinematicSolverInfo solver_info_
get chain information about the arm.
void getSolverInfo(moveit_msgs::msg::KinematicSolverInfo &info)
get chain information about the arm. This populates the IK query response, filling in joint level inf...
double distance(const urdf::Pose &transform)
bool solveCosineEqn(const double &a, const double &b, const double &c, double &soln1, double &soln2)
bool solveQuadratic(const double &a, const double &b, const double &c, double *x1, double *x2)