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, Hanjun Song 00040 */ 00041 00042 #ifndef ROBOT_CONTROLLERS_CARTESIAN_TWIST_H 00043 #define ROBOT_CONTROLLERS_CARTESIAN_TWIST_H 00044 00045 #include <string> 00046 #include <vector> 00047 #include <boost/shared_ptr.hpp> 00048 00049 #include <ros/ros.h> 00050 #include <robot_controllers_interface/controller.h> 00051 #include <robot_controllers_interface/joint_handle.h> 00052 #include <robot_controllers_interface/controller_manager.h> 00053 00054 #include <geometry_msgs/PoseStamped.h> 00055 #include <geometry_msgs/TwistStamped.h> 00056 00057 #include <kdl/chain.hpp> 00058 #include <kdl/chainiksolvervel_wdls.hpp> 00059 #include <kdl/chainfksolver.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 #include <robot_controllers/trajectory_spline_sampler.h> 00067 00068 namespace robot_controllers 00069 { 00070 00071 class CartesianTwistController : public Controller 00072 { 00073 public: 00074 CartesianTwistController(); 00075 virtual ~CartesianTwistController() {} 00076 00084 virtual int init(ros::NodeHandle& nh, ControllerManager* manager); 00085 00091 virtual bool start(); 00092 00100 virtual bool stop(bool force); 00101 00108 virtual bool reset(); 00109 00115 virtual void update(const ros::Time& now, const ros::Duration& dt); 00116 00118 virtual std::string getType() 00119 { 00120 return "robot_controllers/CartesianTwistController"; 00121 } 00122 00124 virtual std::vector<std::string> getCommandedNames(); 00125 00127 virtual std::vector<std::string> getClaimedNames(); 00128 00130 void command(const geometry_msgs::TwistStamped::ConstPtr& goal); 00131 00132 private: 00133 KDL::Frame getPose(); 00134 00135 bool initialized_; 00136 ControllerManager* manager_; 00137 00138 bool enabled_; 00139 00140 KDL::Chain kdl_chain_; 00141 boost::shared_ptr<KDL::ChainIkSolverVel_wdls> solver_; 00142 boost::shared_ptr<KDL::ChainFkSolverPos_recursive> fksolver_; 00143 KDL::JntArray tgt_jnt_pos_; 00144 KDL::JntArray tgt_jnt_vel_; 00145 KDL::JntArray last_tgt_jnt_vel_; 00146 00147 ros::Publisher feedback_pub_; 00148 ros::Subscriber command_sub_; 00149 00150 std::vector<JointHandlePtr> joints_; 00151 00152 boost::mutex mutex_; 00153 KDL::Twist twist_command_; 00154 std::string twist_command_frame_; 00155 ros::Time last_command_time_; 00156 bool is_active_; 00157 }; 00158 00159 } // namespace robot_controllers 00160 00161 #endif // ROBOT_CONTROLLERS_CARTESIAN_TWIST_H