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 }
karto::SensorData::m_pSensorDataPrivate
SensorDataPrivate * m_pSensorDataPrivate
Definition: SensorData.h:179
karto::LaserRangeFinder::GetMinimumRange
kt_double GetMinimumRange() const
Definition: Sensor.h:264
karto::LocalizedLaserScan::m_BarycenterPose
Pose2 m_BarycenterPose
Definition: SensorData.h:763
karto::SensorData::SensorData
SensorData(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:35
karto::LocalizedRangeScan::LocalizedRangeScan
LocalizedRangeScan(const Identifier &rSensorIdentifier, const RangeReadingsList &rReadings)
karto::Vector2::Distance
kt_double Distance(const Vector2 &rOther) const
Definition: Geometry.h:443
karto::Pose2::AngleTo
kt_double AngleTo(const Vector2d &rVector) const
Definition: Geometry.h:2303
kt_double
double kt_double
Definition: Types.h:160
karto::SensorData::HasCustomItem
kt_bool HasCustomItem()
Definition: SensorData.cpp:63
karto::LaserRangeFinder
Definition: Sensor.h:247
angle
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
karto::List::Size
virtual kt_size_t Size() const
Definition: List.h:214
karto::BoundingBox2::Add
void Add(const Vector2d &rPoint)
Definition: Geometry.h:1660
karto::LocalizedObject
Definition: SensorData.h:356
karto::Pose2::GetPosition
const Vector2d & GetPosition() const
Definition: Geometry.h:2256
karto_const_forEach
#define karto_const_forEach(listtype, list)
Definition: Macros.h:136
karto::Pose2::GetY
kt_double GetY() const
Definition: Geometry.h:2238
SensorData.h
karto::LaserRangeFinder::GetRangeThreshold
kt_double GetRangeThreshold() const
Definition: Sensor.h:304
karto::SensorData::m_SensorIdentifier
Identifier m_SensorIdentifier
Definition: SensorData.h:194
karto::LaserRangeScan::LaserRangeScan
LaserRangeScan(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:72
karto::LocalizedLaserScan::GetUnfilteredPointReadings
virtual const Vector2dList & GetUnfilteredPointReadings() const
Definition: SensorData.h:733
karto::LocalizedPointScan::LocalizedPointScan
LocalizedPointScan(const Identifier &rSensorIdentifier, const Vector2dList &rLocalPoints)
Definition: SensorData.cpp:228
karto::SensorData
Definition: SensorData.h:64
karto::SensorData::GetCustomItems
const CustomItemList & GetCustomItems() const
Definition: SensorData.cpp:58
karto::LocalizedObject::LocalizedObject
LocalizedObject(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:91
karto::LocalizedPointScan::m_LocalPointReadings
Vector2dList m_LocalPointReadings
Definition: SensorData.h:839
karto::LocalizedLaserScan::m_BoundingBox
BoundingBox2 m_BoundingBox
Definition: SensorData.h:768
karto::LocalizedLaserScan::m_RangeReadings
RangeReadingsList m_RangeReadings
Definition: SensorData.h:752
karto::LocalizedLaserScan::LocalizedLaserScan
LocalizedLaserScan(const Identifier &rSensorIdentifier)
Definition: SensorData.cpp:107
karto::LocalizedLaserScan::GetPointReadings
const Vector2dList & GetPointReadings(kt_bool wantFiltered=false) const
Definition: SensorData.cpp:152
karto::LocalizedLaserScan::m_FilteredPointReadings
Vector2dList m_FilteredPointReadings
Definition: SensorData.h:742
karto::LocalizedLaserScan::~LocalizedLaserScan
virtual ~LocalizedLaserScan()
Definition: SensorData.cpp:113
karto::LaserRangeFinder::GetMinimumAngle
kt_double GetMinimumAngle() const
Definition: Sensor.h:319
karto::SensorDataPrivate
Definition: SensorData.cpp:27
karto::LocalizedPointScan::ComputePointReadings
virtual void ComputePointReadings()
Definition: SensorData.cpp:246
karto::LocalizedLaserScan::GetLaserRangeFinder
LaserRangeFinder * GetLaserRangeFinder() const
Definition: SensorData.h:576
karto::List< kt_double >
karto::List::Clear
virtual void Clear()
Definition: List.h:231
karto::LocalizedLaserScan
Definition: SensorData.h:567
karto::LocalizedRangeScan::ComputePointReadings
virtual void ComputePointReadings()
Definition: SensorData.cpp:184
kt_bool
bool kt_bool
Definition: Types.h:145
karto::RigidBodyTransform
Definition: RigidBodyTransform.h:36
karto::LocalizedLaserScan::Update
void Update()
Definition: SensorData.cpp:117
karto::SensorData::AddCustomItem
void AddCustomItem(CustomItem *pCustomItem)
Definition: SensorData.cpp:53
karto::math::InRange
kt_bool InRange(const T &value, const T &a, const T &b)
Definition: Math.h:203
karto::Vector2< kt_double >
karto::LaserRangeFinder::GetNumberOfRangeReadings
kt_int32u GetNumberOfRangeReadings() const
Definition: Sensor.h:383
karto::Vector2d
Vector2< kt_double > Vector2d
Definition: Geometry.h:610
karto::Vector2::SetX
void SetX(const T &x)
Definition: Geometry.h:360
karto::RigidBodyTransform::TransformPose
karto::Pose2 TransformPose(const karto::Pose2 &rSourcePose)
Definition: RigidBodyTransform.cpp:58
karto::LocalizedPointScan::m_LocalAngles
DoubleList m_LocalAngles
Definition: SensorData.h:840
karto::List::Add
virtual void Add(const T &rValue)
Definition: List.h:111
karto::Identifier
Definition: Identifier.h:40
kt_int32u
uint32_t kt_int32u
Definition: Types.h:111
karto::Pose2::GetX
kt_double GetX() const
Definition: Geometry.h:2220
karto::LocalizedLaserScan::m_UnfilteredPointReadings
Vector2dList m_UnfilteredPointReadings
Definition: SensorData.h:747
karto::Vector2::SetY
void SetY(const T &y)
Definition: Geometry.h:378
karto::LaserRangeFinder::GetAngularResolution
kt_double GetAngularResolution() const
Definition: Sensor.h:359
karto::LocalizedLaserScan::GetFilteredPointReadings
virtual const Vector2dList & GetFilteredPointReadings() const
Definition: SensorData.h:724
karto::Pose2
Definition: Geometry.h:2182
karto::Identifier::Size
kt_size_t Size() const
Definition: Identifier.cpp:198
karto::Object
Definition: Object.h:54
karto::LocalizedLaserScan::ComputePointReadings
virtual void ComputePointReadings()=0
karto::LocalizedLaserScan::GetRangeReadings
const RangeReadingsList & GetRangeReadings() const
Definition: SensorData.h:688
karto::LocalizedLaserScan::m_IsDirty
kt_bool m_IsDirty
Definition: SensorData.h:773
karto::BoundingBox2
Definition: Geometry.h:1593
karto::SensorDataPrivate::m_CustomItems
CustomItemList m_CustomItems
Definition: SensorData.cpp:32
karto::Pose2::GetHeading
kt_double GetHeading() const
Definition: Geometry.h:2274
karto::LocalizedLaserScan::GetSensorPose
Pose2 GetSensorPose() const
Definition: SensorData.h:627
karto
Definition: Any.cpp:20


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Wed Mar 2 2022 00:37:22