katana_gripper_joint_trajectory_controller.h
Go to the documentation of this file.
1 /*
2  * UOS-ROS packages - Robot Operating System code by the University of Osnabrück
3  * Copyright (C) 2011 University of Osnabrück
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * katana_gripper_joint_trajectory_controller.h
20  *
21  * Created on: 20.10.2011
22  * Author: Karl Glatz <glatz@hs-weingarten.de>
23  * Ravensburg-Weingarten, University of Applied Sciences
24  *
25  * based on joint_trajectory_action/src/joint_trajectory_action.cpp
26  *
27  */
28 #ifndef KATANA_GRIPPER_JOINT_TRAJECTORY_CONTROLLER_H_
29 #define KATANA_GRIPPER_JOINT_TRAJECTORY_CONTROLLER_H_
30 
31 #include <ros/ros.h>
33 
34 #include <trajectory_msgs/JointTrajectory.h>
35 #include <control_msgs/JointTrajectoryAction.h>
36 #include <control_msgs/JointTrajectoryControllerState.h>
37 
39 
40 namespace katana_gazebo_plugins
41 {
42 
46 static const double GRIPPER_ANGLE_THRESHOLD = 0.005;
47 
52 {
53 
54 private:
57 
58 public:
59 
62 
63 private:
64 
66 
68  GoalHandle active_goal_;
69  trajectory_msgs::JointTrajectory current_traj_;
71 
72  // the internal state of the gripper
75 
76  std::vector<std::string> joint_names_;
77  std::map<std::string, double> goal_constraints_;
78  std::map<std::string, double> trajectory_constraints_;
81 
82  // call-back methods
83  void goalCB(GoalHandle gh);
84  void cancelCB(GoalHandle gh);
85 
86  // helper methods
87  static bool setsEqual(const std::vector<std::string> &a, const std::vector<std::string> &b);
88  void checkGoalStatus();
89  bool currentIsDesiredAngle();
90  void setCurrentTrajectory(trajectory_msgs::JointTrajectory traj);
91  bool isTrajectoryFinished();
92 
93 public:
94  // public methods defined by interface IGazeboRosKatanaGripperAction
95 
97  void getGains(double &p, double &i, double &d, double &i_max, double &i_min);
98 
100  {
101  this->current_point_ = point;
102  this->checkGoalStatus();
103  }
104 
105  void cancelGoal()
106  {
107  cancelCB(active_goal_);
108  }
109 
113  bool hasActiveGoal() const
114  {
115  return has_active_goal_;
116  }
117 
118 };
119 
120 } // namespace katana_gazebo_plugins
121 
122 
123 // copied here from package spline_smoother, which was removed in hydro
125 {
126 
127 static inline void generatePowers(int n, double x, double* powers)
128 {
129  powers[0] = 1.0;
130  for (int i=1; i<=n; i++)
131  {
132  powers[i] = powers[i-1]*x;
133  }
134 }
135 
146 void getCubicSplineCoefficients(double start_pos, double start_vel,
147  double end_pos, double end_vel, double time, std::vector<double>& coefficients);
148 
152 void sampleCubicSpline(const std::vector<double>& coefficients, double time,
153  double& position, double& velocity, double& acceleration);
154 
155 
156 inline void getCubicSplineCoefficients(double start_pos, double start_vel,
157  double end_pos, double end_vel, double time, std::vector<double>& coefficients)
158 {
159  coefficients.resize(4);
160 
161  double T[4];
162  generatePowers(3, time, T);
163 
164  coefficients[0] = start_pos;
165  coefficients[1] = start_vel;
166  coefficients[2] = (-3.0*start_pos + 3.0*end_pos - 2.0*start_vel*T[1] - end_vel*T[1]) / T[2];
167  coefficients[3] = (2.0*start_pos - 2.0*end_pos + start_vel*T[1] + end_vel*T[1]) / T[3];
168 }
169 
170 inline void sampleCubicSpline(const std::vector<double>& coefficients, double time,
171  double& position, double& velocity, double& acceleration)
172 {
173  double t[4];
174  generatePowers(3, time, t);
175 
176  position = t[0]*coefficients[0] +
177  t[1]*coefficients[1] +
178  t[2]*coefficients[2] +
179  t[3]*coefficients[3];
180 
181  velocity = t[0]*coefficients[1] +
182  2.0*t[1]*coefficients[2] +
183  3.0*t[2]*coefficients[3];
184 
185  acceleration = 2.0*t[0]*coefficients[2] +
186  6.0*t[1]*coefficients[3];
187 }
188 
189 } // namespace spline_smoother
190 
191 #endif /* KATANA_GRIPPER_JOINT_TRAJECTORY_CONTROLLER_H_ */
static void generatePowers(int n, double x, double *powers)
actionlib::ActionServer< control_msgs::JointTrajectoryAction > JTAS
void getCubicSplineCoefficients(double start_pos, double start_vel, double end_pos, double end_vel, double time, std::vector< double > &coefficients)
Calculates cubic spline coefficients given the start and end way-points.
void sampleCubicSpline(const std::vector< double > &coefficients, double time, double &position, double &velocity, double &acceleration)
Samples a cubic spline segment at a particular time.
void getGains(double &p, double &i, double &d, double &i_max, double &i_min)
static bool setsEqual(const std::vector< std::string > &a, const std::vector< std::string > &b)


katana_gazebo_plugins
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:10