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