follow_joint_trajectory_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_FOLLOW_TRAJECTORY_CONTROLLER_HANDLE
00039 #define MOVEIT_PLUGINS_FOLLOW_TRAJECTORY_CONTROLLER_HANDLE
00040 
00041 #include <moveit_simple_controller_manager/action_based_controller_handle.h>
00042 #include <control_msgs/FollowJointTrajectoryAction.h>
00043 
00044 namespace moveit_simple_controller_manager
00045 {
00046 
00047 /*
00048  * This is generally used for arms, but could also be used for multi-dof hands,
00049  *   or anything using a control_mgs/FollowJointTrajectoryAction.
00050  */
00051 class FollowJointTrajectoryControllerHandle : public ActionBasedControllerHandle<control_msgs::FollowJointTrajectoryAction>
00052 {
00053 public:
00054 
00055   FollowJointTrajectoryControllerHandle(const std::string &name, const std::string &action_ns) :
00056     ActionBasedControllerHandle<control_msgs::FollowJointTrajectoryAction>(name, action_ns)
00057   {
00058   }
00059 
00060   virtual bool sendTrajectory(const moveit_msgs::RobotTrajectory &trajectory)
00061   {
00062     ROS_DEBUG_STREAM("FollowJointTrajectoryController: new trajectory to " << name_);
00063 
00064     if (!controller_action_client_)
00065       return false;
00066 
00067     if (!trajectory.multi_dof_joint_trajectory.points.empty())
00068     {
00069       ROS_WARN("FollowJointTrajectoryController: %s cannot execute multi-dof trajectories.", name_.c_str());
00070     }
00071 
00072     if (done_)
00073       ROS_DEBUG_STREAM("FollowJointTrajectoryController: sending trajectory to " << name_);
00074     else
00075       ROS_DEBUG_STREAM("FollowJointTrajectoryController: sending continuation for the currently executed trajectory to " << name_);
00076 
00077     control_msgs::FollowJointTrajectoryGoal goal;
00078     goal.trajectory = trajectory.joint_trajectory;
00079     controller_action_client_->sendGoal(goal,
00080                     boost::bind(&FollowJointTrajectoryControllerHandle::controllerDoneCallback, this, _1, _2),
00081                     boost::bind(&FollowJointTrajectoryControllerHandle::controllerActiveCallback, this),
00082                     boost::bind(&FollowJointTrajectoryControllerHandle::controllerFeedbackCallback, this, _1));
00083     done_ = false;
00084     last_exec_ = moveit_controller_manager::ExecutionStatus::RUNNING;
00085     return true;
00086   }
00087 
00088 protected:
00089 
00090   void controllerDoneCallback(const actionlib::SimpleClientGoalState& state,
00091                               const control_msgs::FollowJointTrajectoryResultConstPtr& result)
00092   {
00093     // Output custom error message for FollowJointTrajectoryResult if necessary
00094     switch( result->error_code )
00095     {
00096       case control_msgs::FollowJointTrajectoryResult::INVALID_GOAL:
00097         ROS_WARN_STREAM("Controller " << name_ << " failed with error code INVALID_GOAL");
00098         break;
00099       case control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS:
00100         ROS_WARN_STREAM("Controller " << name_ << " failed with error code INVALID_JOINTS");
00101         break;
00102       case control_msgs::FollowJointTrajectoryResult::OLD_HEADER_TIMESTAMP:
00103         ROS_WARN_STREAM("Controller " << name_ << " failed with error code OLD_HEADER_TIMESTAMP");
00104         break;
00105       case control_msgs::FollowJointTrajectoryResult::PATH_TOLERANCE_VIOLATED:
00106         ROS_WARN_STREAM("Controller " << name_ << " failed with error code PATH_TOLERANCE_VIOLATED");
00107         break;
00108       case control_msgs::FollowJointTrajectoryResult::GOAL_TOLERANCE_VIOLATED:
00109         ROS_WARN_STREAM("Controller " << name_ << " failed with error code GOAL_TOLERANCE_VIOLATED");
00110         break;
00111     }
00112 
00113     finishControllerExecution(state);
00114   }
00115 
00116   void controllerActiveCallback()
00117   {
00118     ROS_DEBUG_STREAM("FollowJointTrajectoryController: " << name_ << " started execution");
00119   }
00120 
00121   void controllerFeedbackCallback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback)
00122   {
00123   }
00124 };
00125 
00126 
00127 } // end namespace moveit_simple_controller_manager
00128 
00129 #endif // MOVEIT_PLUGINS_FOLLOW_TRAJECTORY_CONTROLLER_HANDLE


moveit_simple_controller_manager
Author(s): Michael Ferguson
autogenerated on Wed Aug 26 2015 12:42:24