00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <math.h>
00019 #include <assert.h>
00020 #include <float.h>
00021 #include <limits.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <stdio.h>
00025
00026 #include "OpenKarto/Karto.h"
00027
00028 namespace karto
00029 {
00030
00034
00035 SensorManager* SensorManager::GetInstance()
00036 {
00037 static Singleton<SensorManager> sInstance;
00038 return sInstance.Get();
00039 }
00040
00044
00045 Object::Object()
00046 : m_pParameterManager(new ParameterManager())
00047 {
00048 }
00049
00050 Object::Object(const Name& rName)
00051 : m_Name(rName)
00052 , m_pParameterManager(new ParameterManager())
00053 {
00054 }
00055
00056 Object::~Object()
00057 {
00058 delete m_pParameterManager;
00059 m_pParameterManager = NULL;
00060 }
00061
00065
00066 Module::Module(const std::string& rName)
00067 : Object(rName)
00068 {
00069 }
00070
00071 Module::~Module()
00072 {
00073 }
00074
00078
00079 Sensor::Sensor(const Name& rName)
00080 : Object(rName)
00081 {
00082 m_pOffsetPose = new Parameter<Pose2>("OffsetPose", Pose2(), GetParameterManager());
00083 }
00084
00085 Sensor::~Sensor()
00086 {
00087 }
00088
00092
00093 SensorData::SensorData(const Name& rSensorName)
00094 : Object()
00095 , m_StateId(-1)
00096 , m_UniqueId(-1)
00097 , m_SensorName(rSensorName)
00098 , m_Time(0.0)
00099 {
00100 }
00101
00102 SensorData::~SensorData()
00103 {
00104 forEach(CustomDataVector, &m_CustomData)
00105 {
00106 delete *iter;
00107 }
00108
00109 m_CustomData.clear();
00110 }
00111
00115
00116 void CellUpdater::operator() (kt_int32u index)
00117 {
00118 kt_int8u* pDataPtr = m_pOccupancyGrid->GetDataPointer();
00119 kt_int32u* pCellPassCntPtr = m_pOccupancyGrid->m_pCellPassCnt->GetDataPointer();
00120 kt_int32u* pCellHitCntPtr = m_pOccupancyGrid->m_pCellHitsCnt->GetDataPointer();
00121
00122 m_pOccupancyGrid->UpdateCell(&pDataPtr[index], pCellPassCntPtr[index], pCellHitCntPtr[index]);
00123 }
00124
00128
00129 std::ostream& operator << (std::ostream& rStream, Exception& rException)
00130 {
00131 rStream << "Error detect: " << std::endl;
00132 rStream << " ==> error code: " << rException.GetErrorCode() << std::endl;
00133 rStream << " ==> error message: " << rException.GetErrorMessage() << std::endl;
00134
00135 return rStream;
00136 }
00137
00141
00142 const PointVectorDouble LaserRangeFinder::GetPointReadings(LocalizedRangeScan* pLocalizedRangeScan, CoordinateConverter* pCoordinateConverter, kt_bool ignoreThresholdPoints, kt_bool flipY) const
00143 {
00144 PointVectorDouble pointReadings;
00145
00146 Pose2 scanPose = pLocalizedRangeScan->GetSensorPose();
00147
00148
00149 kt_int32u beamNum = 0;
00150 kt_double* pRangeReadings = pLocalizedRangeScan->GetRangeReadings();
00151 for (kt_int32u i = 0; i < m_NumberOfRangeReadings; i++, beamNum++)
00152 {
00153 kt_double rangeReading = pRangeReadings[i];
00154
00155 if (ignoreThresholdPoints)
00156 {
00157 if (!math::InRange(rangeReading, GetMinimumRange(), GetRangeThreshold()))
00158 {
00159 continue;
00160 }
00161 }
00162 else
00163 {
00164 rangeReading = math::Clip(rangeReading, GetMinimumRange(), GetRangeThreshold());
00165 }
00166
00167 kt_double angle = scanPose.GetHeading() + GetMinimumAngle() + beamNum * GetAngularResolution();
00168
00169 Vector2<kt_double> point;
00170
00171 point.SetX(scanPose.GetX() + (rangeReading * cos(angle)));
00172 point.SetY(scanPose.GetY() + (rangeReading * sin(angle)));
00173
00174 if (pCoordinateConverter != NULL)
00175 {
00176 Vector2<kt_int32s> gridPoint = pCoordinateConverter->WorldToGrid(point, flipY);
00177 point.SetX(gridPoint.GetX());
00178 point.SetY(gridPoint.GetY());
00179 }
00180
00181 pointReadings.push_back(point);
00182 }
00183
00184 return pointReadings;
00185 }
00186
00187 kt_bool LaserRangeFinder::Validate(SensorData* pSensorData)
00188 {
00189 LaserRangeScan* pLaserRangeScan = dynamic_cast<LaserRangeScan*>(pSensorData);
00190
00191
00192 if(pLaserRangeScan->GetNumberOfRangeReadings() != GetNumberOfRangeReadings())
00193 {
00194 std::cout << "LaserRangeScan contains " << pLaserRangeScan->GetNumberOfRangeReadings() << " range readings, expected " << GetNumberOfRangeReadings() << std::endl;
00195 return false;
00196 }
00197
00198 return true;
00199 }
00200
00204
00205 void ParameterManager::Clear()
00206 {
00207 forEach(karto::ParameterVector, &m_Parameters)
00208 {
00209 delete *iter;
00210 }
00211
00212 m_Parameters.clear();
00213
00214 m_ParameterLookup.clear();
00215 }
00216
00217 void ParameterManager::Add(AbstractParameter* pParameter)
00218 {
00219 if (pParameter != NULL && pParameter->GetName() != "")
00220 {
00221 if (m_ParameterLookup.find(pParameter->GetName()) == m_ParameterLookup.end())
00222 {
00223 m_Parameters.push_back(pParameter);
00224
00225 m_ParameterLookup[pParameter->GetName()] = pParameter;
00226 }
00227 else
00228 {
00229 m_ParameterLookup[pParameter->GetName()]->SetValueFromString(pParameter->GetValueAsString());
00230
00231 assert(false);
00232 }
00233 }
00234 }
00235
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 }
00254