Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekTraj.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekTraj.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-09-18 16:53:49 -0600 (Thu, 18 Sep 2014) $
12  * $Rev: 3748 $
13  *
14  * \brief Joint points and trajectory class interfaces.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2013-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _HEK_TRAJ_H
50 #define _HEK_TRAJ_H
51 
52 #include <sys/types.h>
53 
54 #include <string>
55 #include <vector>
56 
57 #include "rnr/rnrconfig.h"
58 
59 #include "Hekateros/hekateros.h"
60 
61 namespace hekateros
62 {
63  // ---------------------------------------------------------------------------
64  // Class HekJointTraj
65  // ---------------------------------------------------------------------------
66 
67  /*!
68  * \brief Joint trajectory class.
69  *
70  * A joint trajectory specifies the goal or current position, velocity, and
71  * accelleration of one joint.
72  */
74  {
75  public:
76  /*!
77  * \brief Default constructor.
78  */
80  {
81  m_fPosition = 0.0;
82  m_fVelocity = 0.0;
83  m_fAcceleration = 0.0;
84  }
85 
86  /*!
87  * \brief Initialization constructor.
88  *
89  * \param strName Joint name.
90  * \param fPosition Joint position.
91  * \param fVelocity Joint velocity.
92  * \param fAcceleration Joint acceleration.
93  */
94  HekJointTraj(const std::string &strName,
95  const double fPosition,
96  const double fVelocity,
97  const double fAcceleration)
98  {
99  m_strName = strName;
100  m_fPosition = fPosition;
101  m_fVelocity = fVelocity;
102  m_fAcceleration = fAcceleration;
103  }
104 
105  /*!
106  * \brief Copy constructor.
107  *
108  * \param src Source object.
109  */
111  {
112  m_strName = src.m_strName;
113  m_fPosition = src.m_fPosition;
114  m_fVelocity = src.m_fVelocity;
116  }
117 
118  /*!
119  * \brief Destructor.
120  */
122  {
123  }
124 
125  /*!
126  * \brief Assignment operator.
127  *
128  * \param rhs Right hand side object.
129  *
130  * \return Returns copy of this.
131  */
133  {
134  m_strName = rhs.m_strName;
135  m_fPosition = rhs.m_fPosition;
136  m_fVelocity = rhs.m_fVelocity;
138 
139  return *this;
140  }
141 
142  /*!
143  * \brief Get joint point data.
144  *
145  * \param [out] strName Joint name.
146  * \param [out] fPosition Joint position.
147  * \param [out] fVelocity Joint velocity.
148  * \param [out] fAcceleration Joint acceleration.
149  */
150  void get(std::string &strName,
151  double &fPosition,
152  double &fVelocity,
153  double &fAcceleration)
154  {
155  strName = m_strName;
156  fPosition = m_fPosition;
157  fVelocity = m_fVelocity;
158  fAcceleration = m_fAcceleration;
159  }
160 
161  protected:
162  std::string m_strName; ///< joint name
163  double m_fPosition; ///< joint position (radians)
164  double m_fVelocity; ///< joint velocity (% of maximum)
165  double m_fAcceleration; ///< joint acceleration (not used)
166  };
167 
168 
169  // ---------------------------------------------------------------------------
170  // Class HekJointTrajectoryPoint
171  // ---------------------------------------------------------------------------
172 
173  /*!
174  * \brief Joint trajectory point class.
175  *
176  * A joint trajectory point (T0, T1, ..., Tn-1) specifies the goal position,
177  * velocity, and acceleration for a set of joints (kinematic chain)
178  * Ti, i=0,n-1.
179  */
181  {
182  public:
183  /*!
184  * \brief Default constructor.
185  */
187  {
188  m_uTimeFromStart = 0;
189  }
190 
191  /*!
192  * \brief Copy constructor.
193  */
195  {
196  m_uTimeFromStart = src.m_uTimeFromStart;
197  m_trajectory = src.m_trajectory;
198  }
199 
200  /*!
201  * \brief Destructor.
202  */
204  {
205  }
206 
207  /*!
208  * \brief Assignment operator.
209  *
210  * \param rhs Right hand side object.
211  *
212  * \return Returns copy of this.
213  */
215  {
216  m_uTimeFromStart = rhs.m_uTimeFromStart;
217  m_trajectory = rhs.m_trajectory;
218 
219  return *this;
220  }
221 
222  /*!
223  * \brief Get time from start.
224  *
225  * \todo TODO need to understand ROS meaning of this.
226  *
227  * \return Duration.
228  */
230  {
231  return m_uTimeFromStart;
232  }
233 
234  /*!
235  * \brief Set time from start.
236  *
237  * \todo TODO need to understand ROS meaning of this.
238  *
239  * \param uTimeFromStart Duration.
240  */
241  void setTimeFromStart(uint_t uTimeFromStart)
242  {
243  m_uTimeFromStart = uTimeFromStart;
244  }
245 
246  /*!
247  * \brief Get the number of joint points in trajectory.
248  *
249  * \return Number of points.
250  */
251  size_t getNumPoints()
252  {
253  return m_trajectory.size();
254  }
255 
256  /*!
257  * \brief Append joint point to end of trajectory.
258  *
259  * \param strName Joint name.
260  * \param fPosition Joint position.
261  * \param fVelocity Joint velocity.
262  * \param fAcceleration Joint acceleration.
263  */
264  void append(const std::string &strName,
265  double fPosition,
266  double fVelocity,
267  double fAcceleration=0.0)
268  {
269  HekJointTraj jointPoint(strName, fPosition, fVelocity, fAcceleration);
270  m_trajectory.push_back(jointPoint);
271  }
272 
273  /*!
274  * \brief Subscript operator to get reference to joint point at the
275  * given index.
276  *
277  * Big boy warranty. No out of bound checks are made.
278  *
279  * \param i Index.
280  *
281  * \return Joint point.
282  */
283  HekJointTraj &operator[](const size_t i)
284  {
285  return m_trajectory[i];
286  }
287 
288  /*!
289  * \brief Clear data.
290  */
291  void clear()
292  {
293  m_trajectory.clear();
294  m_uTimeFromStart = 0;
295  }
296 
297  protected:
298  std::vector<HekJointTraj> m_trajectory; ///< trajectory
299  uint_t m_uTimeFromStart; ///< duration
300  };
301 
302 
303  // ---------------------------------------------------------------------------
304  // Class HekJointTrajectoryFeedback
305  // ---------------------------------------------------------------------------
306 
307  /*!
308  * \brief Joint trajectory feedback class.
309  *
310  * The feedback provides informaation about the last issued desired trajectory
311  * and the current trajectory.
312  */
314  {
315  public:
316  static const int TRAJ_DESIRED = 0; ///< desired trajectory
317  static const int TRAJ_ACTUAL = 1; ///< actual trajectory
318  static const int TRAJ_NUMOF = 2; ///< number of trajectories
319 
320  /*!
321  * \brief Default constructor.
322  */
324  {
325  }
326 
327  /*!
328  * \brief Copy constructor.
329  */
331  {
332  for(int i = 0; i< TRAJ_NUMOF; ++i)
333  {
334  m_trajectory[i] = src.m_trajectory[i];
335  }
336  }
337 
338  /*!
339  * \brief Destructor.
340  */
342  {
343  }
344 
345  /*!
346  * \brief Assignment operator.
347  *
348  * \param rhs Right hand side object.
349  *
350  * \return Returns copy of this.
351  */
353  {
354  for(int i = 0; i< TRAJ_NUMOF; ++i)
355  {
356  m_trajectory[i] = rhs.m_trajectory[i];
357  }
358  return *this;
359  }
360 
361  /*!
362  * \brief Get time from start of desired trajectory.
363  *
364  * \return Duration.
365  */
367  {
368  return m_trajectory[TRAJ_DESIRED].getTimeFromStart();
369  }
370 
371  /*!
372  * \brief Get the number of joint points in trajectory.
373  *
374  * \return Number of points.
375  */
376  size_t getNumPoints()
377  {
378  return m_trajectory[TRAJ_DESIRED].getNumPoints();
379  }
380 
381  /*!
382  * \brief Subscript operator to get reference to given trajectory.
383  *
384  * \param i Trajectory point Index.
385  *
386  * \return Trajectory.
387  */
389  {
390  return i < TRAJ_NUMOF? m_trajectory[i]: m_trajectory[TRAJ_DESIRED];
391  }
392 
393  /*!
394  * \brief Clear data.
395  */
396  void clear()
397  {
398  for(int i = 0; i < TRAJ_NUMOF; ++i)
399  {
400  m_trajectory[i].clear();
401  }
402  }
403 
404  protected:
405  HekJointTrajectoryPoint m_trajectory[TRAJ_NUMOF];
406  };
407 } // namespace hekateros
408 
409 
410 #endif // _HEK_TRAJ_H
HekJointTrajectoryFeedback()
Default constructor.
Definition: hekTraj.h:323
uint_t getTimeFromStart()
Get time from start.
Definition: hekTraj.h:229
std::vector< HekJointTraj > m_trajectory
trajectory
Definition: hekTraj.h:298
~HekJointTraj()
Destructor.
Definition: hekTraj.h:121
Joint trajectory feedback class.
Definition: hekTraj.h:313
Joint trajectory class.
Definition: hekTraj.h:73
Joint trajectory point class.
Definition: hekTraj.h:180
double m_fAcceleration
joint acceleration (not used)
Definition: hekTraj.h:165
size_t getNumPoints()
Get the number of joint points in trajectory.
Definition: hekTraj.h:376
HekJointTrajectoryPoint()
Default constructor.
Definition: hekTraj.h:186
HekJointTrajectoryFeedback(const HekJointTrajectoryFeedback &src)
Copy constructor.
Definition: hekTraj.h:330
void clear()
Clear data.
Definition: hekTraj.h:291
double m_fVelocity
joint velocity (% of maximum)
Definition: hekTraj.h:164
HekJointTraj & operator[](const size_t i)
Subscript operator to get reference to joint point at the given index.
Definition: hekTraj.h:283
std::string m_strName
joint name
Definition: hekTraj.h:162
HekJointTrajectoryPoint operator=(const HekJointTrajectoryPoint &rhs)
Assignment operator.
Definition: hekTraj.h:214
uint_t m_uTimeFromStart
duration
Definition: hekTraj.h:299
~HekJointTrajectoryFeedback()
Destructor.
Definition: hekTraj.h:341
HekJointTraj(const HekJointTraj &src)
Copy constructor.
Definition: hekTraj.h:110
double m_fPosition
joint position (radians)
Definition: hekTraj.h:163
~HekJointTrajectoryPoint()
Destructor.
Definition: hekTraj.h:203
size_t getNumPoints()
Get the number of joint points in trajectory.
Definition: hekTraj.h:251
Top-level package include file.
HekJointTrajectoryPoint(const HekJointTrajectoryPoint &src)
Copy constructor.
Definition: hekTraj.h:194
HekJointTraj()
Default constructor.
Definition: hekTraj.h:79
HekJointTraj(const std::string &strName, const double fPosition, const double fVelocity, const double fAcceleration)
Initialization constructor.
Definition: hekTraj.h:94
void setTimeFromStart(uint_t uTimeFromStart)
Set time from start.
Definition: hekTraj.h:241
HekJointTrajectoryPoint & operator[](const size_t i)
Subscript operator to get reference to given trajectory.
Definition: hekTraj.h:388
void append(const std::string &strName, double fPosition, double fVelocity, double fAcceleration=0.0)
Append joint point to end of trajectory.
Definition: hekTraj.h:264
uint_t getTimeFromStart()
Get time from start of desired trajectory.
Definition: hekTraj.h:366
HekJointTraj operator=(const HekJointTraj &rhs)
Assignment operator.
Definition: hekTraj.h:132
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
HekJointTrajectoryFeedback operator=(const HekJointTrajectoryFeedback &rhs)
Assignment operator.
Definition: hekTraj.h:352