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


moveit_simple_controller_manager
Author(s): Michael Ferguson
autogenerated on Wed Jun 19 2019 19:25:18