katana_gripper_joint_trajectory_controller.h
Go to the documentation of this file.
00001 /*
00002  * UOS-ROS packages - Robot Operating System code by the University of Osnabrück
00003  * Copyright (C) 2011  University of Osnabrück
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  *
00019  * katana_gripper_joint_trajectory_controller.h
00020  *
00021  *  Created on: 20.10.2011
00022  *      Author: Karl Glatz <glatz@hs-weingarten.de>
00023  *              Ravensburg-Weingarten, University of Applied Sciences
00024  *
00025  *  based on joint_trajectory_action/src/joint_trajectory_action.cpp
00026  *
00027  */
00028 #ifndef KATANA_GRIPPER_JOINT_TRAJECTORY_CONTROLLER_H_
00029 #define KATANA_GRIPPER_JOINT_TRAJECTORY_CONTROLLER_H_
00030 
00031 #include <ros/ros.h>
00032 #include <actionlib/server/action_server.h>
00033 
00034 #include <trajectory_msgs/JointTrajectory.h>
00035 #include <control_msgs/JointTrajectoryAction.h>
00036 #include <control_msgs/JointTrajectoryControllerState.h>
00037 
00038 #include <katana_gazebo_plugins/gazebo_ros_katana_gripper_action_interface.h>
00039 
00040 namespace katana_gazebo_plugins
00041 {
00042 
00046 static const double GRIPPER_ANGLE_THRESHOLD = 0.005;
00047 
00051 class KatanaGripperJointTrajectoryController : public IGazeboRosKatanaGripperAction
00052 {
00053 
00054 private:
00055   typedef actionlib::ActionServer<control_msgs::JointTrajectoryAction> JTAS;
00056   typedef JTAS::GoalHandle GoalHandle;
00057 
00058 public:
00059 
00060   KatanaGripperJointTrajectoryController(ros::NodeHandle pn);
00061   virtual ~KatanaGripperJointTrajectoryController();
00062 
00063 private:
00064 
00065   JTAS *action_server_;
00066 
00067   bool has_active_goal_;
00068   GoalHandle active_goal_;
00069   trajectory_msgs::JointTrajectory current_traj_;
00070   bool trajectory_finished_;
00071 
00072   // the internal state of the gripper
00073   GRKAPoint current_point_;
00074   GRKAPoint last_desired_point_;
00075 
00076   std::vector<std::string> joint_names_;
00077   std::map<std::string, double> goal_constraints_;
00078   std::map<std::string, double> trajectory_constraints_;
00079   double goal_time_constraint_;
00080   double stopped_velocity_tolerance_;
00081 
00082   // call-back methods
00083   void goalCB(GoalHandle gh);
00084   void cancelCB(GoalHandle gh);
00085 
00086   // helper methods
00087   static bool setsEqual(const std::vector<std::string> &a, const std::vector<std::string> &b);
00088   void checkGoalStatus();
00089   bool currentIsDesiredAngle();
00090   void setCurrentTrajectory(trajectory_msgs::JointTrajectory traj);
00091   bool isTrajectoryFinished();
00092 
00093 public:
00094   // public methods defined by interface IGazeboRosKatanaGripperAction
00095 
00096   GRKAPoint getNextDesiredPoint(ros::Time time);
00097   void getGains(double &p, double &i, double &d, double &i_max, double &i_min);
00098 
00099   void setCurrentPoint(GRKAPoint point)
00100   {
00101     this->current_point_ = point;
00102     this->checkGoalStatus();
00103   }
00104 
00105   void cancelGoal()
00106   {
00107     cancelCB(active_goal_);
00108   }
00109 
00113   bool hasActiveGoal() const
00114   {
00115     return has_active_goal_;
00116   }
00117 
00118 };
00119 
00120 } // namespace katana_gazebo_plugins
00121 
00122 
00123 // copied here from package spline_smoother, which was removed in hydro
00124 namespace spline_smoother
00125 {
00126 
00127 static inline void generatePowers(int n, double x, double* powers)
00128 {
00129   powers[0] = 1.0;
00130   for (int i=1; i<=n; i++)
00131   {
00132     powers[i] = powers[i-1]*x;
00133   }
00134 }
00135 
00146 void getCubicSplineCoefficients(double start_pos, double start_vel,
00147     double end_pos, double end_vel, double time, std::vector<double>& coefficients);
00148 
00152 void sampleCubicSpline(const std::vector<double>& coefficients, double time,
00153     double& position, double& velocity, double& acceleration);
00154 
00155 
00156 inline void getCubicSplineCoefficients(double start_pos, double start_vel,
00157     double end_pos, double end_vel, double time, std::vector<double>& coefficients)
00158 {
00159   coefficients.resize(4);
00160 
00161   double T[4];
00162   generatePowers(3, time, T);
00163 
00164   coefficients[0] = start_pos;
00165   coefficients[1] = start_vel;
00166   coefficients[2] = (-3.0*start_pos + 3.0*end_pos - 2.0*start_vel*T[1] - end_vel*T[1]) / T[2];
00167   coefficients[3] = (2.0*start_pos - 2.0*end_pos + start_vel*T[1] + end_vel*T[1]) / T[3];
00168 }
00169 
00170 inline void sampleCubicSpline(const std::vector<double>& coefficients, double time,
00171     double& position, double& velocity, double& acceleration)
00172 {
00173   double t[4];
00174   generatePowers(3, time, t);
00175 
00176   position = t[0]*coefficients[0] +
00177     t[1]*coefficients[1] +
00178     t[2]*coefficients[2] +
00179     t[3]*coefficients[3];
00180 
00181   velocity = t[0]*coefficients[1] +
00182     2.0*t[1]*coefficients[2] +
00183     3.0*t[2]*coefficients[3];
00184 
00185   acceleration = 2.0*t[0]*coefficients[2] +
00186     6.0*t[1]*coefficients[3];
00187 }
00188 
00189 } // namespace spline_smoother
00190 
00191 #endif /* KATANA_GRIPPER_JOINT_TRAJECTORY_CONTROLLER_H_ */


katana_gazebo_plugins
Author(s): Martin Günther
autogenerated on Mon Aug 14 2017 02:44:02