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_wrench_controller.cpp 00039 * Author: Michael Ferguson, Wim Meeussen 00040 */ 00041 00042 #ifndef ROBOT_CONTROLLERS_CARTESIAN_WRENCH_H 00043 #define ROBOT_CONTROLLERS_CARTESIAN_WRENCH_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 #include <geometry_msgs/Wrench.h> 00054 00055 #include <kdl/chain.hpp> 00056 #include <kdl/chainjnttojacsolver.hpp> 00057 #include <kdl/frames.hpp> 00058 00059 #include <tf/transform_datatypes.h> 00060 #include <tf/transform_listener.h> 00061 00062 namespace robot_controllers 00063 { 00064 00065 class CartesianWrenchController : public Controller 00066 { 00067 public: 00068 CartesianWrenchController(); 00069 virtual ~CartesianWrenchController() {} 00070 00078 virtual int init(ros::NodeHandle& nh, ControllerManager* manager); 00079 00085 virtual bool start(); 00086 00094 virtual bool stop(bool force); 00095 00102 virtual bool reset(); 00103 00109 virtual void update(const ros::Time& now, const ros::Duration& dt); 00110 00112 virtual std::string getType() 00113 { 00114 return "robot_controllers/CartesianWrenchController"; 00115 } 00116 00118 virtual std::vector<std::string> getCommandedNames(); 00119 00121 virtual std::vector<std::string> getClaimedNames(); 00122 00124 void command(const geometry_msgs::Wrench::ConstPtr& goal); 00125 00126 private: 00127 void updateJoints(); 00128 00129 bool initialized_; 00130 ControllerManager* manager_; 00131 00132 bool enabled_; 00133 std::string root_link_; 00134 ros::Time last_command_; 00135 00136 KDL::Wrench desired_wrench_; 00137 00138 KDL::Chain kdl_chain_; 00139 boost::shared_ptr<KDL::ChainJntToJacSolver> jac_solver_; 00140 KDL::JntArray jnt_pos_; 00141 KDL::JntArray jnt_eff_; 00142 KDL::Jacobian jacobian_; 00143 00144 ros::Publisher feedback_pub_; 00145 ros::Subscriber command_sub_; 00146 00147 tf::TransformListener tf_; 00148 std::vector<JointHandlePtr> joints_; 00149 }; 00150 00151 } // namespace robot_controllers 00152 00153 #endif // ROBOT_CONTROLLERS_CARTESIAN_WRENCH_H