$search
00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2008, Willow Garage, Inc. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Willow Garage nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 * Author: Sachin Chitta 00036 *********************************************************************/ 00037 00038 #ifndef KDL_ARM_KINEMATICS_PLUGIN_H_ 00039 #define KDL_ARM_KINEMATICS_PLUGIN_H_ 00040 00041 // ROS 00042 #include <ros/ros.h> 00043 #include <tf/tf.h> 00044 #include <tf/transform_datatypes.h> 00045 #include <tf_conversions/tf_kdl.h> 00046 00047 // System 00048 #include <boost/shared_ptr.hpp> 00049 #include <algorithm> 00050 #include <numeric> 00051 #include <cstring> 00052 00053 // ROS msgs 00054 #include <geometry_msgs/PoseStamped.h> 00055 #include <kinematics_msgs/GetPositionFK.h> 00056 #include <kinematics_msgs/GetPositionIK.h> 00057 #include <kinematics_msgs/GetKinematicSolverInfo.h> 00058 #include <arm_navigation_msgs/ArmNavigationErrorCodes.h> 00059 00060 // Plugin 00061 #include <kinematics_base/kinematics_base.h> 00062 00063 // KDL 00064 #include <kdl/jntarray.hpp> 00065 #include <kdl_parser/kdl_parser.hpp> 00066 #include <kdl/chainiksolverpos_nr_jl.hpp> 00067 #include <kdl/chainiksolvervel_pinv.hpp> 00068 #include <kdl/chainfksolverpos_recursive.hpp> 00069 00070 // MISC 00071 #include <angles/angles.h> 00072 00073 namespace arm_kinematics_constraint_aware 00074 { 00075 class KDLArmKinematicsPlugin : public kinematics::KinematicsBase 00076 { 00077 public: 00078 00082 KDLArmKinematicsPlugin(); 00083 00088 bool isActive(); 00089 00097 bool getPositionIK(const geometry_msgs::Pose &ik_pose, 00098 const std::vector<double> &ik_seed_state, 00099 std::vector<double> &solution, 00100 int &error_code); 00101 00110 bool searchPositionIK(const geometry_msgs::Pose &ik_pose, 00111 const std::vector<double> &ik_seed_state, 00112 const double &timeout, 00113 std::vector<double> &solution, 00114 int &error_code); 00123 bool searchPositionIK(const geometry_msgs::Pose &ik_pose, 00124 const std::vector<double> &ik_seed_state, 00125 const double &timeout, 00126 std::vector<double> &solution, 00127 const boost::function<void(const geometry_msgs::Pose &ik_pose,const std::vector<double> &ik_solution,int &error_code)> &desired_pose_callback, 00128 const boost::function<void(const geometry_msgs::Pose &ik_pose,const std::vector<double> &ik_solution,int &error_code)> &solution_callback, 00129 int &error_code); 00136 bool getPositionFK(const std::vector<std::string> &link_names, 00137 const std::vector<double> &joint_angles, 00138 std::vector<geometry_msgs::Pose> &poses); 00139 00144 bool initialize(std::string name); 00145 00150 std::string getBaseFrame(); 00151 00155 std::string getToolFrame(); 00156 00160 std::vector<std::string> getJointNames(); 00161 00165 std::vector<std::string> getLinkNames(); 00166 00167 protected: 00168 00169 bool loadModel(const std::string xml); 00170 bool readJoints(urdf::Model &robot_model); 00171 int getJointIndex(const std::string &name); 00172 int getKDLSegmentIndex(const std::string &name); 00173 double genRandomNumber(const double &min, const double &max); 00174 KDL::JntArray getRandomConfiguration(); 00175 00176 int max_search_iterations_; 00177 00178 bool active_; 00179 kinematics_msgs::KinematicSolverInfo chain_info_; 00180 00181 boost::shared_ptr<KDL::ChainIkSolverVel_pinv> ik_solver_vel_; 00182 boost::shared_ptr<KDL::ChainFkSolverPos_recursive> fk_solver_; 00183 boost::shared_ptr<KDL::ChainIkSolverPos_NR_JL> ik_solver_pos_; 00184 00185 unsigned int dimension_; 00186 KDL::Chain kdl_chain_; 00187 std::string root_name_,tip_name_; 00188 KDL::JntArray joint_min_, joint_max_; 00189 00190 /* 00191 boost::function<void(const geometry_msgs::Pose &ik_pose,const std::vector<double> &ik_solution,int &error_code)> solutionCallback_; 00192 boost::function<void(const geometry_msgs::Pose &ik_pose,const std::vector<double> &ik_solution,int &error_code)> desiredPoseCallback_; 00193 00194 void desiredPoseCallback(const KDL::JntArray& jnt_array, 00195 const KDL::Frame& ik_pose, 00196 arm_navigation_msgs::ArmNavigationErrorCodes& error_code); 00197 00198 void jointSolutionCallback(const KDL::JntArray& jnt_array, 00199 const KDL::Frame& ik_pose, 00200 arm_navigation_msgs::ArmNavigationErrorCodes& error_code); 00201 */ 00202 }; 00203 } 00204 00205 #endif