00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2014, Fetch Robotics Inc. 00005 * Copyright (c) 2013, Unbounded Robotics Inc. 00006 * Copyright (c) 2008, Willow Garage, Inc. 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Unbounded Robotics nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 *********************************************************************/ 00036 00037 /* 00038 * Derived a bit from pr2_controllers/cartesian_pose_controller.cpp 00039 * Author: Michael Ferguson, Wim Meeussen 00040 */ 00041 00042 #ifndef ROBOT_CONTROLLERS_CARTESIAN_POSE_H 00043 #define ROBOT_CONTROLLERS_CARTESIAN_POSE_H 00044 00045 #include <string> 00046 #include <vector> 00047 #include <boost/shared_ptr.hpp> 00048 00049 #include <ros/ros.h> 00050 #include <robot_controllers/pid.h> 00051 #include <robot_controllers_interface/controller.h> 00052 #include <robot_controllers_interface/joint_handle.h> 00053 #include <robot_controllers_interface/controller_manager.h> 00054 00055 #include <geometry_msgs/PoseStamped.h> 00056 #include <geometry_msgs/Twist.h> 00057 00058 #include <kdl/chain.hpp> 00059 #include <kdl/chainjnttojacsolver.hpp> 00060 #include <kdl/chainfksolverpos_recursive.hpp> 00061 #include <kdl/frames.hpp> 00062 00063 #include <tf/transform_datatypes.h> 00064 #include <tf/transform_listener.h> 00065 00066 namespace robot_controllers 00067 { 00068 00069 class CartesianPoseController : public Controller 00070 { 00071 public: 00072 CartesianPoseController(); 00073 virtual ~CartesianPoseController() {} 00074 00082 virtual int init(ros::NodeHandle& nh, ControllerManager* manager); 00083 00089 virtual bool start(); 00090 00098 virtual bool stop(bool force); 00099 00106 virtual bool reset(); 00107 00113 virtual void update(const ros::Time& now, const ros::Duration& dt); 00114 00116 virtual std::string getType() 00117 { 00118 return "robot_controllers/CartesianPoseController"; 00119 } 00120 00122 virtual std::vector<std::string> getCommandedNames(); 00123 00125 virtual std::vector<std::string> getClaimedNames(); 00126 00128 void command(const geometry_msgs::PoseStamped::ConstPtr& goal); 00129 00130 private: 00131 KDL::Frame getPose(); 00132 00133 bool initialized_; 00134 ControllerManager* manager_; 00135 00136 bool enabled_; 00137 std::string root_link_; 00138 ros::Time last_command_; 00139 00140 KDL::Frame desired_pose_; 00141 KDL::Frame actual_pose_; 00142 00143 KDL::Twist twist_error_; 00144 00145 KDL::Chain kdl_chain_; 00146 boost::shared_ptr<KDL::ChainFkSolverPos> jnt_to_pose_solver_; 00147 boost::shared_ptr<KDL::ChainJntToJacSolver> jac_solver_; 00148 KDL::JntArray jnt_pos_; 00149 KDL::JntArray jnt_delta_; 00150 KDL::Jacobian jacobian_; 00151 00152 ros::Publisher feedback_pub_; 00153 ros::Subscriber command_sub_; 00154 00155 tf::TransformListener tf_; 00156 std::vector<JointHandlePtr> joints_; 00157 std::vector<robot_controllers::PID> pid_; 00158 }; 00159 00160 } // namespace robot_controllers 00161 00162 #endif // ROBOT_CONTROLLERS_CARTESIAN_POSE_H