00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifndef UR_KINEMATICS_PLUGIN_
00076 #define UR_KINEMATICS_PLUGIN_
00077
00078
00079 #include <ros/ros.h>
00080 #include <random_numbers/random_numbers.h>
00081
00082
00083 #include <boost/shared_ptr.hpp>
00084
00085
00086 #include <geometry_msgs/PoseStamped.h>
00087 #include <moveit_msgs/GetPositionFK.h>
00088 #include <moveit_msgs/GetPositionIK.h>
00089 #include <moveit_msgs/GetKinematicSolverInfo.h>
00090 #include <moveit_msgs/MoveItErrorCodes.h>
00091
00092
00093 #include <kdl/jntarray.hpp>
00094 #include <kdl/chainiksolvervel_pinv.hpp>
00095 #include <kdl/chainiksolverpos_nr_jl.hpp>
00096 #include <kdl/chainfksolverpos_recursive.hpp>
00097 #include <moveit/kdl_kinematics_plugin/chainiksolver_pos_nr_jl_mimic.hpp>
00098 #include <moveit/kdl_kinematics_plugin/chainiksolver_vel_pinv_mimic.hpp>
00099 #include <moveit/kdl_kinematics_plugin/joint_mimic.hpp>
00100
00101
00102 #include <moveit/kinematics_base/kinematics_base.h>
00103 #include <moveit/robot_model/robot_model.h>
00104 #include <moveit/robot_state/robot_state.h>
00105
00106 namespace ur_kinematics
00107 {
00111 class URKinematicsPlugin : public kinematics::KinematicsBase
00112 {
00113 public:
00114
00118 URKinematicsPlugin();
00119
00120 virtual bool getPositionIK(const geometry_msgs::Pose &ik_pose,
00121 const std::vector<double> &ik_seed_state,
00122 std::vector<double> &solution,
00123 moveit_msgs::MoveItErrorCodes &error_code,
00124 const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions()) const;
00125
00126 virtual bool searchPositionIK(const geometry_msgs::Pose &ik_pose,
00127 const std::vector<double> &ik_seed_state,
00128 double timeout,
00129 std::vector<double> &solution,
00130 moveit_msgs::MoveItErrorCodes &error_code,
00131 const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions()) const;
00132
00133 virtual bool searchPositionIK(const geometry_msgs::Pose &ik_pose,
00134 const std::vector<double> &ik_seed_state,
00135 double timeout,
00136 const std::vector<double> &consistency_limits,
00137 std::vector<double> &solution,
00138 moveit_msgs::MoveItErrorCodes &error_code,
00139 const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions()) const;
00140
00141 virtual bool searchPositionIK(const geometry_msgs::Pose &ik_pose,
00142 const std::vector<double> &ik_seed_state,
00143 double timeout,
00144 std::vector<double> &solution,
00145 const IKCallbackFn &solution_callback,
00146 moveit_msgs::MoveItErrorCodes &error_code,
00147 const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions()) const;
00148
00149 virtual bool searchPositionIK(const geometry_msgs::Pose &ik_pose,
00150 const std::vector<double> &ik_seed_state,
00151 double timeout,
00152 const std::vector<double> &consistency_limits,
00153 std::vector<double> &solution,
00154 const IKCallbackFn &solution_callback,
00155 moveit_msgs::MoveItErrorCodes &error_code,
00156 const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions()) const;
00157
00158 virtual bool getPositionFK(const std::vector<std::string> &link_names,
00159 const std::vector<double> &joint_angles,
00160 std::vector<geometry_msgs::Pose> &poses) const;
00161
00162 virtual bool initialize(const std::string &robot_description,
00163 const std::string &group_name,
00164 const std::string &base_name,
00165 const std::string &tip_name,
00166 double search_discretization);
00167
00171 const std::vector<std::string>& getJointNames() const;
00172
00176 const std::vector<std::string>& getLinkNames() const;
00177
00178 protected:
00179
00195 bool searchPositionIK(const geometry_msgs::Pose &ik_pose,
00196 const std::vector<double> &ik_seed_state,
00197 double timeout,
00198 std::vector<double> &solution,
00199 const IKCallbackFn &solution_callback,
00200 moveit_msgs::MoveItErrorCodes &error_code,
00201 const std::vector<double> &consistency_limits,
00202 const kinematics::KinematicsQueryOptions &options = kinematics::KinematicsQueryOptions()) const;
00203
00204 virtual bool setRedundantJoints(const std::vector<unsigned int> &redundant_joint_indices);
00205
00206 private:
00207
00208 bool timedOut(const ros::WallTime &start_time, double duration) const;
00209
00210
00218 bool checkConsistency(const KDL::JntArray& seed_state,
00219 const std::vector<double> &consistency_limit,
00220 const KDL::JntArray& solution) const;
00221
00222 int getJointIndex(const std::string &name) const;
00223
00224 int getKDLSegmentIndex(const std::string &name) const;
00225
00226 void getRandomConfiguration(KDL::JntArray &jnt_array, bool lock_redundancy) const;
00227
00234 void getRandomConfiguration(const KDL::JntArray& seed_state,
00235 const std::vector<double> &consistency_limits,
00236 KDL::JntArray &jnt_array,
00237 bool lock_redundancy) const;
00238
00239 bool isRedundantJoint(unsigned int index) const;
00240
00241 bool active_;
00243 moveit_msgs::KinematicSolverInfo ik_chain_info_;
00245 moveit_msgs::KinematicSolverInfo fk_chain_info_;
00247 KDL::Chain kdl_chain_;
00248
00249 unsigned int dimension_;
00251 KDL::JntArray joint_min_, joint_max_;
00253 mutable random_numbers::RandomNumberGenerator random_number_generator_;
00254
00255 robot_model::RobotModelPtr robot_model_;
00256
00257 robot_state::RobotStatePtr state_, state_2_;
00258
00259 int num_possible_redundant_joints_;
00260 std::vector<unsigned int> redundant_joints_map_index_;
00261
00262
00263 bool position_ik_;
00264 robot_model::JointModelGroup* joint_model_group_;
00265 double max_solver_iterations_;
00266 double epsilon_;
00267 std::vector<kdl_kinematics_plugin::JointMimic> mimic_joints_;
00268
00269 std::vector<double> ik_weights_;
00270 std::vector<std::string> ur_joint_names_;
00271 std::vector<std::string> ur_link_names_;
00272 int ur_joint_inds_start_;
00273 std::string arm_prefix_;
00274
00275
00276
00277 KDL::Chain kdl_base_chain_;
00278 KDL::Chain kdl_tip_chain_;
00279
00280 };
00281 }
00282
00283 #endif