gripper_controller_handle.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2013, Unbounded Robotics Inc.
00005 *  Copyright (c) 2012, 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 
00036 /* Author: Michael Ferguson, Ioan Sucan, E. Gil Jones */
00037 
00038 #ifndef MOVEIT_PLUGINS_GRIPPER_CONTROLLER_HANDLE
00039 #define MOVEIT_PLUGINS_GRIPPER_CONTROLLER_HANDLE
00040 
00041 #include <moveit_simple_controller_manager/action_based_controller_handle.h>
00042 #include <control_msgs/GripperCommandAction.h>
00043 
00044 namespace moveit_simple_controller_manager
00045 {
00046 
00047 
00048 /*
00049  * This is an interface for a gripper using control_msgs/GripperCommandAction action interface.
00050  */
00051 class GripperControllerHandle : public ActionBasedControllerHandle<control_msgs::GripperCommandAction>
00052 {
00053 public:
00054   /* Topics will map to name/ns/goal, name/ns/result, etc */
00055   GripperControllerHandle(const std::string &name, const std::string &ns) :
00056     ActionBasedControllerHandle<control_msgs::GripperCommandAction>(name, ns),
00057     allow_failure_(false)
00058   {
00059   }
00060 
00061   virtual bool sendTrajectory(const moveit_msgs::RobotTrajectory &trajectory)
00062   {
00063     ROS_DEBUG_STREAM("GripperController: new trajectory to " << name_);
00064 
00065     if (!controller_action_client_)
00066       return false;
00067 
00068     if (!trajectory.multi_dof_joint_trajectory.points.empty())
00069     {
00070       ROS_ERROR("GripperController: cannot execute multi-dof trajectories.");
00071       return false;
00072     }
00073 
00074     if (trajectory.joint_trajectory.points.size() != 1)
00075     {
00076       ROS_ERROR("GripperController: expects a joint trajectory with one point only, but %u provided)", (unsigned int)trajectory.joint_trajectory.points.size());
00077       return false;
00078     }
00079 
00080 
00081 
00082     if (trajectory.joint_trajectory.points[0].positions.empty())
00083     {
00084       ROS_ERROR("GripperController: expects a joint trajectory with one point that specifies at least one position, but 0 positions provided)");
00085       return false;
00086     }
00087 
00088     /* TODO: currently sending velocity as effort, make this better. */
00089     control_msgs::GripperCommandGoal goal;
00090     if (!trajectory.joint_trajectory.points[0].velocities.empty())
00091       goal.command.max_effort = trajectory.joint_trajectory.points[0].velocities[0];
00092     goal.command.position = trajectory.joint_trajectory.points[0].positions[0];
00093     controller_action_client_->sendGoal(goal,
00094                     boost::bind(&GripperControllerHandle::controllerDoneCallback, this, _1, _2),
00095                     boost::bind(&GripperControllerHandle::controllerActiveCallback, this),
00096                     boost::bind(&GripperControllerHandle::controllerFeedbackCallback, this, _1));
00097     done_ = false;
00098     last_exec_ = moveit_controller_manager::ExecutionStatus::RUNNING;
00099     return true;
00100   }
00101 
00102   void setCommandJoint(const std::string& name) { command_joint_ = name; }
00103   void allowFailure(bool allow) { allow_failure_ = allow; }
00104 
00105 private:
00106 
00107   void controllerDoneCallback(const actionlib::SimpleClientGoalState& state,
00108                               const control_msgs::GripperCommandResultConstPtr& result)
00109   {
00110     if (state == actionlib::SimpleClientGoalState::ABORTED && allow_failure_)
00111       finishControllerExecution(actionlib::SimpleClientGoalState::SUCCEEDED);
00112     else
00113       finishControllerExecution(state);
00114   }
00115 
00116   void controllerActiveCallback()
00117   {
00118     ROS_DEBUG_STREAM("GripperController: " << name_ << " started execution");
00119   }
00120 
00121   void controllerFeedbackCallback(const control_msgs::GripperCommandFeedbackConstPtr& feedback)
00122   {
00123     // TODO?
00124   }
00125 
00126   /*
00127    * Some gripper drivers may indicate a failure if they do not close all the way when
00128    * an object is in the gripper.
00129    */
00130   bool allow_failure_;
00131 
00132   /*
00133    * A GripperCommand message has only a single float64 for the "command", thus only a single
00134    * joint angle can be sent -- however, due to the complexity of making grippers look correct
00135    * in a URDF, they typically have >1 joints. The "command_joint" is the joint whose position
00136    * value will be sent in the GripperCommand action.
00137    */
00138   std::string command_joint_;
00139 };
00140 
00141 
00142 } // end namespace moveit_simple_controller_manager
00143 
00144 #endif // MOVEIT_PLUGINS_GRIPPER_CONTROLLER_HANDLE


moveit_simple_controller_manager
Author(s): Michael Ferguson
autogenerated on Mon Oct 6 2014 02:28:21