SensorData.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011, SRI International (R)
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <OpenKarto/SensorData.h>
19 
20 namespace karto
21 {
22 
26 
28  {
32  CustomItemList m_CustomItems;
33  };
34 
35  SensorData::SensorData(const Identifier& rSensorIdentifier)
36  : Object()
37  , m_pSensorDataPrivate(new SensorDataPrivate())
38  , m_StateId(-1)
39  , m_UniqueId(-1)
40  , m_SensorIdentifier(rSensorIdentifier)
41  , m_Time(0)
42  {
43  assert(m_SensorIdentifier.Size() != 0);
44  }
45 
46  SensorData::~SensorData()
47  {
49 
50  delete m_pSensorDataPrivate;
51  }
52 
53  void SensorData::AddCustomItem(CustomItem* pCustomData)
54  {
55  m_pSensorDataPrivate->m_CustomItems.Add(pCustomData);
56  }
57 
58  const CustomItemList& SensorData::GetCustomItems() const
59  {
61  }
62 
64  {
65  return m_pSensorDataPrivate->m_CustomItems.Size() > 0;
66  }
67 
71 
72  LaserRangeScan::LaserRangeScan(const Identifier& rSensorIdentifier)
73  : SensorData(rSensorIdentifier)
74  {
75  }
76 
77  LaserRangeScan::LaserRangeScan(const Identifier& rSensorIdentifier, const RangeReadingsList& rRangeReadings)
78  : SensorData(rSensorIdentifier)
79  , m_RangeReadings(rRangeReadings)
80  {
81  }
82 
83  LaserRangeScan::~LaserRangeScan()
84  {
85  }
86 
90 
91  LocalizedObject::LocalizedObject(const Identifier& rSensorIdentifier)
92  : SensorData(rSensorIdentifier)
93  , m_IsGpsReadingValid(false)
94  , m_IsGpsEstimateValid(false)
95  , m_pGpsEstimationManager(NULL)
96  {
97  }
98 
99  LocalizedObject::~LocalizedObject()
100  {
101  }
102 
106 
108  : LocalizedObject(rSensorIdentifier)
109  , m_IsDirty(true)
110  {
111  }
112 
114  {
115  }
116 
118  {
120 
121  // set flag early, otherwise call to GetPointReadings()
122  // below will recurse infinitely
123  m_IsDirty = false;
124 
125  Pose2 scanPose = GetSensorPose();
126 
127  Vector2d rangePointsSum;
128  const Vector2dList& rPointReadings = GetPointReadings(true);
129 
130  // calculate bounding box of scan
132  m_BoundingBox.Add(scanPose.GetPosition());
133  karto_const_forEach(Vector2dList, &rPointReadings)
134  {
135  m_BoundingBox.Add(*iter);
136  rangePointsSum += *iter;
137  }
138 
139  // compute barycenter
140  kt_double nPoints = static_cast<kt_double>(rPointReadings.Size());
141  if (nPoints != 0.0)
142  {
143  Vector2d averagePosition = Vector2d(rangePointsSum / nPoints);
144  m_BarycenterPose = Pose2(averagePosition, 0.0);
145  }
146  else
147  {
148  m_BarycenterPose = scanPose;
149  }
150  }
151 
153  {
154  if (m_IsDirty)
155  {
156  // throw away constness and do an update!
157  const_cast<LocalizedLaserScan*>(this)->Update();
158  }
159 
160  if (wantFiltered == true)
161  {
162  return GetFilteredPointReadings();
163  }
164  else
165  {
167  }
168  }
169 
173 
174  LocalizedRangeScan::LocalizedRangeScan(const Identifier& rSensorIdentifier, const List<kt_double>& rReadings)
175  : LocalizedLaserScan(rSensorIdentifier)
176  {
177  m_RangeReadings = rReadings;
178  }
179 
180  LocalizedRangeScan::~LocalizedRangeScan()
181  {
182  }
183 
185  {
186  LaserRangeFinder* pLaserRangeFinder = GetLaserRangeFinder();
187  if (pLaserRangeFinder == NULL)
188  {
189  return;
190  }
191 
194 
195  kt_double minimumAngle = pLaserRangeFinder->GetMinimumAngle();
196  kt_double angularResolution = pLaserRangeFinder->GetAngularResolution();
197 
198  kt_double minimumRange = pLaserRangeFinder->GetMinimumRange();
199  kt_double rangeThreshold = pLaserRangeFinder->GetRangeThreshold();
200 
201  Pose2 scanPose = GetSensorPose();
202 
203  const List<kt_double>& rRangeReadings = GetRangeReadings();
204 
205  // compute point readings
206  kt_int32u numberOfReadings = pLaserRangeFinder->GetNumberOfRangeReadings();
207  for (kt_int32u i = 0; i < numberOfReadings; i++)
208  {
209  kt_double angle = scanPose.GetHeading() + minimumAngle + i * angularResolution;
210  kt_double rangeReading = rRangeReadings[i];
211 
212  Vector2d point;
213  point.SetX(scanPose.GetX() + (rangeReading * cos(angle)));
214  point.SetY(scanPose.GetY() + (rangeReading * sin(angle)));
216 
217  if (math::InRange(rangeReading, minimumRange, rangeThreshold))
218  {
220  }
221  }
222  }
223 
227 
228  LocalizedPointScan::LocalizedPointScan(const Identifier& rSensorIdentifier, const Vector2dList& rLocalPoints)
229  : LocalizedLaserScan(rSensorIdentifier)
230  {
231  m_LocalPointReadings = rLocalPoints;
232 
233  Vector2d origin(0, 0);
234  Pose2 originPose(origin, 0);
235  karto_const_forEach(Vector2dList, &rLocalPoints)
236  {
237  m_RangeReadings.Add(origin.Distance(*iter));
238  m_LocalAngles.Add(originPose.AngleTo(*iter));
239  }
240  }
241 
242  LocalizedPointScan::~LocalizedPointScan()
243  {
244  }
245 
247  {
248  LaserRangeFinder* pLaserRangeFinder = GetLaserRangeFinder();
249  if (pLaserRangeFinder == NULL)
250  {
251  return;
252  }
253 
256 
257  kt_double rangeThreshold = pLaserRangeFinder->GetRangeThreshold();
258  Pose2 scanPose = GetSensorPose();
259  Vector2d scanPosition = scanPose.GetPosition();
260 
261  // compute point readings
262  for (kt_int32u i = 0; i < m_LocalPointReadings.Size(); i++)
263  {
265  Pose2 pointPose = transform.TransformPose(scanPose);
266  Vector2d point = pointPose.GetPosition();
268 
269  kt_double range = scanPosition.Distance(point);
270  if (math::InRange(range, pLaserRangeFinder->GetMinimumRange(), rangeThreshold))
271  {
273  }
274  }
275  }
276 
277 }
BoundingBox2 m_BoundingBox
Definition: SensorData.h:768
virtual kt_size_t Size() const
Definition: List.h:214
kt_double Distance(const Vector2 &rOther) const
Definition: Geometry.h:443
bool kt_bool
Definition: Types.h:145
kt_int32u GetNumberOfRangeReadings() const
Definition: Sensor.h:383
kt_double GetHeading() const
Definition: Geometry.h:2274
SensorDataPrivate * m_pSensorDataPrivate
Definition: SensorData.h:179
kt_bool HasCustomItem()
Definition: SensorData.cpp:63
Vector2dList m_LocalPointReadings
Definition: SensorData.h:839
void AddCustomItem(CustomItem *pCustomItem)
Definition: SensorData.cpp:53
const CustomItemList & GetCustomItems() const
Definition: SensorData.cpp:58
kt_double GetX() const
Definition: Geometry.h:2220
void SetX(const T &x)
Definition: Geometry.h:360
LocalizedRangeScan(const Identifier &rSensorIdentifier, const RangeReadingsList &rReadings)
RangeReadingsList m_RangeReadings
Definition: SensorData.h:274
virtual const Vector2dList & GetFilteredPointReadings() const
Definition: SensorData.h:724
kt_double GetAngularResolution() const
Definition: Sensor.h:359
kt_double AngleTo(const Vector2d &rVector) const
Definition: Geometry.h:2303
virtual void Add(const T &rValue)
Definition: List.h:111
LocalizedLaserScan(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:107
Identifier m_SensorIdentifier
Definition: SensorData.h:194
Pose2 GetSensorPose() const
Definition: SensorData.h:627
const RangeReadingsList & GetRangeReadings() const
Definition: SensorData.h:688
LocalizedObject(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:91
virtual void ComputePointReadings()
Definition: SensorData.cpp:246
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
uint32_t kt_int32u
Definition: Types.h:111
virtual void ComputePointReadings()=0
RangeReadingsList m_RangeReadings
Definition: SensorData.h:752
Vector2dList m_UnfilteredPointReadings
Definition: SensorData.h:747
kt_size_t Size() const
Definition: Identifier.cpp:198
CustomItemList m_CustomItems
Definition: SensorData.cpp:32
LocalizedPointScan(const Identifier &rSensorIdentifier, const Vector2dList &rLocalPoints)
Definition: SensorData.cpp:228
const Vector2d & GetPosition() const
Definition: Geometry.h:2256
kt_double GetMinimumAngle() const
Definition: Sensor.h:319
karto::Pose2 TransformPose(const karto::Pose2 &rSourcePose)
Vector2< kt_double > Vector2d
Definition: Geometry.h:610
LaserRangeScan(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:72
Vector2dList m_FilteredPointReadings
Definition: SensorData.h:742
double kt_double
Definition: Types.h:160
kt_bool InRange(const T &value, const T &a, const T &b)
Definition: Math.h:203
virtual void ComputePointReadings()
Definition: SensorData.cpp:184
kt_double GetY() const
Definition: Geometry.h:2238
Definition: Any.cpp:20
virtual void Clear()
Definition: List.h:231
kt_double GetMinimumRange() const
Definition: Sensor.h:264
SensorData(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:35
virtual const Vector2dList & GetUnfilteredPointReadings() const
Definition: SensorData.h:733
void SetY(const T &y)
Definition: Geometry.h:378
kt_double GetRangeThreshold() const
Definition: Sensor.h:304
void Add(const Vector2d &rPoint)
Definition: Geometry.h:1660
#define karto_const_forEach(listtype, list)
Definition: Macros.h:136
LaserRangeFinder * GetLaserRangeFinder() const
Definition: SensorData.h:576
const Vector2dList & GetPointReadings(kt_bool wantFiltered=false) const
Definition: SensorData.cpp:152


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Tue Nov 7 2017 06:02:36