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 /*
00049  * This is generally used for arms, but could also be used for multi-dof hands,
00050  *   or anything using a control_mgs/FollowJointTrajectoryAction.
00051  */
00052 class FollowJointTrajectoryControllerHandle : public ActionBasedControllerHandle<control_msgs::FollowJointTrajectoryAction>
00053 {
00054 public:
00055 
00056   FollowJointTrajectoryControllerHandle(const std::string &name, const std::string &action_ns) :
00057     ActionBasedControllerHandle<control_msgs::FollowJointTrajectoryAction>(name, action_ns)
00058   {
00059   }
00060 
00061   virtual bool sendTrajectory(const moveit_msgs::RobotTrajectory &trajectory)
00062   {
00063     ROS_DEBUG_STREAM("FollowJointTrajectoryController: 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("FollowJointTrajectoryController: cannot execute multi-dof trajectories.");
00071       return false;
00072     }
00073 
00074     if (done_)
00075       ROS_DEBUG_STREAM("FollowJointTrajectoryController: sending trajectory to " << name_);
00076     else
00077       ROS_DEBUG_STREAM("FollowJointTrajectoryController: sending continuation for the currently executed trajectory to " << name_);
00078 
00079     control_msgs::FollowJointTrajectoryGoal goal;
00080     goal.trajectory = trajectory.joint_trajectory;
00081     controller_action_client_->sendGoal(goal,
00082                     boost::bind(&FollowJointTrajectoryControllerHandle::controllerDoneCallback, this, _1, _2),
00083                     boost::bind(&FollowJointTrajectoryControllerHandle::controllerActiveCallback, this),
00084                     boost::bind(&FollowJointTrajectoryControllerHandle::controllerFeedbackCallback, this, _1));
00085     done_ = false;
00086     last_exec_ = moveit_controller_manager::ExecutionStatus::RUNNING;
00087     return true;
00088   }
00089 
00090 protected:
00091 
00092   void controllerDoneCallback(const actionlib::SimpleClientGoalState& state,
00093                               const control_msgs::FollowJointTrajectoryResultConstPtr& result)
00094   {
00095     finishControllerExecution(state);
00096   }
00097 
00098   void controllerActiveCallback()
00099   {
00100     ROS_DEBUG_STREAM("FollowJointTrajectoryController: " << name_ << " started execution");
00101   }
00102 
00103   void controllerFeedbackCallback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback)
00104   {
00105     // TODO?
00106   }
00107 };
00108 
00109 
00110 } // end namespace moveit_simple_controller_manager
00111 
00112 #endif // MOVEIT_PLUGINS_FOLLOW_TRAJECTORY_CONTROLLER_HANDLE


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