Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeTraj.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Library: liblaelaps
6 //
7 // File: laeTraj.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-06-01 13:57:21 -0600 (Mon, 01 Jun 2015) $
12  * $Rev: 4009 $
13  *
14  * \brief Trajectory classes interfaces.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2015-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 #include <sys/types.h>
50 #include <time.h>
51 
52 #include <string>
53 #include <sstream>
54 #include <vector>
55 #include <map>
56 
57 #include "rnr/rnrconfig.h"
58 
59 #include "Laelaps/laelaps.h"
60 #include "Laelaps/laeUtils.h"
61 #include "Laelaps/laeTraj.h"
62 
63 
64 using namespace std;
65 using namespace laelaps;
66 
67 // -----------------------------------------------------------------------------
68 // Class LaeSimplePathFeedback
69 // -----------------------------------------------------------------------------
70 
71 LaeSimplePathFeedback::LaeSimplePathFeedback(const LaeSimplePathFeedback &src)
72 {
73  for(int i = 0; i < TrajNumOf; ++i)
74  {
75  m_path[i] = src.m_path[i];
76  }
77 }
78 
79 LaeSimplePathFeedback LaeSimplePathFeedback::operator=(
80  const LaeSimplePathFeedback &rhs)
81 {
82  for(int i = 0; i < TrajNumOf; ++i)
83  {
84  m_path[i] = rhs.m_path[i];
85  }
86  return *this;
87 }
88 
89 LaeSimplePath &LaeSimplePathFeedback::operator[](const size_t i)
90 {
91  return i < TrajNumOf? m_path[i]: m_path[TrajDesired];
92 }
93 
94 void LaeSimplePathFeedback::clear()
95 {
96  for(int i = 0; i < TrajNumOf; ++i)
97  {
98  m_path[i].clear();
99  }
100 }
101 
102 
103 // -----------------------------------------------------------------------------
104 // Class LaeWaypoint
105 // -----------------------------------------------------------------------------
106 
107 LaeWaypoint::LaeWaypoint()
108 {
109  m_timeStart = StartImmediately;
110  m_fVelocity = 0.0;
111  m_fAcceleration = 0.0;
112 }
113 
114 LaeWaypoint::LaeWaypoint(const LaePose &pose,
115  const double fVelocity,
116  const double fAcceleration,
117  const string &strName,
118  const timespec_t &timeStart)
119  : m_pose(pose), m_strName(strName)
120 {
121  m_timeStart = timeStart;
122  m_fVelocity = fVelocity;
123  m_fAcceleration = fAcceleration;
124 }
125 
126 LaeWaypoint::LaeWaypoint(const LaeWaypoint &src)
127  : m_pose(src.m_pose), m_strName(src.m_strName)
128 {
129  m_timeStart = src.m_timeStart;
130  m_fVelocity = src.m_fVelocity;
132 }
133 
135 {
136  m_strName = rhs.m_strName;
137  m_timeStart = rhs.m_timeStart;
138  m_pose = rhs.m_pose;
139  m_fVelocity = rhs.m_fVelocity;
141 
142  return *this;
143 }
144 
145 void LaeWaypoint::get(string &strName,
146  timespec_t &timeStart,
147  LaePose &pose,
148  double &fVelocity,
149  double &fAcceleration)
150 {
151  strName = m_strName;
152  timeStart = m_timeStart;
153  pose = m_pose;
154  fVelocity = m_fVelocity;
155  fAcceleration = m_fAcceleration;
156 }
157 
159 {
160  m_strName.clear();
162  m_pose.clear();
163  m_fVelocity = 0.0;
164  m_fAcceleration = 0.0;
165 }
166 
167 
168 // -----------------------------------------------------------------------------
169 // Class LaePath
170 // -----------------------------------------------------------------------------
171 
172 void LaePath::append(const LaePose &pose,
173  const double fVelocity,
174  const double fAcceleration,
175  const std::string &strName,
176  const timespec_t &timeStart)
177 {
178  stringstream ss;
179 
180  if( strName.empty() )
181  {
182  ss << "wp_" << m_path.size();
183  }
184  else
185  {
186  ss << strName;
187  }
188 
189  LaeWaypoint pt(pose, fVelocity, fAcceleration, ss.str(), timeStart);
190  m_path.push_back(pt);
191 }
192 
193 
194 // -----------------------------------------------------------------------------
195 // Class LaePathFeedback
196 // -----------------------------------------------------------------------------
197 
199 {
200  for(int i = 0; i < TrajNumOf; ++i)
201  {
202  m_path[i] = src.m_path[i];
203  }
204 }
205 
207 {
208  for(int i = 0; i < TrajNumOf; ++i)
209  {
210  m_path[i] = rhs.m_path[i];
211  }
212  return *this;
213 }
214 
216 {
217  return i < TrajNumOf? m_path[i]: m_path[TrajDesired];
218 }
219 
221 {
222  for(int i = 0; i < TrajNumOf; ++i)
223  {
224  m_path[i].clear();
225  }
226 }
void clear()
Clear data.
Definition: laeTraj.cxx:220
Trajectory classes interfaces.
Robot fully-defined waypoint.
Definition: laeTraj.h:584
LaePose m_pose
robot pose at waypoint
Definition: laeTraj.h:674
static const int TrajDesired
Trajectory feedback identifiers (and indices).
Definition: laeTraj.h:78
LaeWaypoint operator=(const LaeWaypoint &rhs)
Assignment operator.
Definition: laeTraj.cxx:134
std::string m_strName
waypoint name
Definition: laeTraj.h:672
static const timespec_t StartImmediately
Start navigation immediately.
Definition: laeTraj.h:73
timespec_t m_timeStart
time to start navigation
Definition: laeTraj.h:673
static const int TrajNumOf
number of trajectories ids
Definition: laeTraj.h:81
Simple path feedback class.
Definition: laeTraj.h:510
struct timespec timespec_t
typedef&#39;ed timespec structure
Definition: laeUtils.h:221
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
void get(std::string &strName, timespec_t &timeStart, LaePose &pose, double &fVelocity, double &fAcceleration)
Get waypoint data.
Definition: laeTraj.cxx:145
void clear()
Clear data.
Definition: laeTraj.h:488
Laelaps common utilities.
Simple path feedback class.
Definition: laeTraj.h:821
double m_fAcceleration
target acceleration (meters/s^2)
Definition: laeTraj.h:676
double m_fVelocity
target velocity at waypoint (meters/s)
Definition: laeTraj.h:675
LaePath & operator[](const size_t i)
Subscript operator to get reference to given trajectory.
Definition: laeTraj.cxx:215
LaePathFeedback operator=(const LaePathFeedback &rhs)
Assignment operator.
Definition: laeTraj.cxx:206
LaePathFeedback()
Default constructor.
Definition: laeTraj.h:828
Laelaps 2D pose class.
Definition: laeTraj.h:170
void append(const LaePose &pose, const double fVelocity, const double fAcceleration, const std::string &strName="", const timespec_t &timeStart=StartImmediately)
Append waypoint to end of path.
Definition: laeTraj.cxx:172
Robot path class.
Definition: laeTraj.h:693
void clear()
Clear (reset) waypoint data.
Definition: laeTraj.cxx:158
Robot simple path class.
Definition: laeTraj.h:382
Top-level package include file.