Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "SpaSolver.h"
00019
00020 #include <OpenKarto/Mapper.h>
00021
00027 karto::Dataset* CreateMap(karto::Mapper* pMapper)
00028 {
00029 karto::Dataset* pDataset = new karto::Dataset();
00030
00032
00033 karto::Name name("laser0");
00034 karto::LaserRangeFinder* pLaserRangeFinder = karto::LaserRangeFinder::CreateLaserRangeFinder(karto::LaserRangeFinder_Custom, name);
00035 pLaserRangeFinder->SetOffsetPose(karto::Pose2(1.0, 0.0, 0.0));
00036 pLaserRangeFinder->SetAngularResolution(karto::math::DegreesToRadians(0.5));
00037 pLaserRangeFinder->SetRangeThreshold(12.0);
00038
00039 pDataset->Add(pLaserRangeFinder);
00040
00042
00043 karto::LocalizedRangeScan* pLocalizedRangeScan = NULL;
00044
00045
00046
00047
00048 std::vector<kt_double> readings;
00049 for (int i=0; i<361; i++)
00050 {
00051 readings.push_back(3.0);
00052 }
00053
00054
00055 pLocalizedRangeScan = new karto::LocalizedRangeScan(name, readings);
00056 pLocalizedRangeScan->SetOdometricPose(karto::Pose2(0.0, 0.0, 0.0));
00057 pLocalizedRangeScan->SetCorrectedPose(karto::Pose2(0.0, 0.0, 0.0));
00058
00059
00060 pMapper->Process(pLocalizedRangeScan);
00061 std::cout << "Pose: " << pLocalizedRangeScan->GetOdometricPose() << " Corrected Pose: " << pLocalizedRangeScan->GetCorrectedPose() << std::endl;
00062
00063
00064 pDataset->Add(pLocalizedRangeScan);
00065
00066
00067
00068
00069 pLocalizedRangeScan = new karto::LocalizedRangeScan(name, readings);
00070 pLocalizedRangeScan->SetOdometricPose(karto::Pose2(1.0, 0.0, 1.57));
00071 pLocalizedRangeScan->SetCorrectedPose(karto::Pose2(1.0, 0.0, 1.57));
00072
00073
00074 pMapper->Process(pLocalizedRangeScan);
00075 std::cout << "Pose: " << pLocalizedRangeScan->GetOdometricPose() << " Corrected Pose: " << pLocalizedRangeScan->GetCorrectedPose() << std::endl;
00076
00077
00078 pDataset->Add(pLocalizedRangeScan);
00079
00080
00081
00082
00083 pLocalizedRangeScan = new karto::LocalizedRangeScan(name, readings);
00084 pLocalizedRangeScan->SetOdometricPose(karto::Pose2(1.0, -1.0, 2.35619449));
00085 pLocalizedRangeScan->SetCorrectedPose(karto::Pose2(1.0, -1.0, 2.35619449));
00086
00087
00088 pMapper->Process(pLocalizedRangeScan);
00089 std::cout << "Pose: " << pLocalizedRangeScan->GetOdometricPose() << " Corrected Pose: " << pLocalizedRangeScan->GetCorrectedPose() << std::endl;
00090
00091
00092 pDataset->Add(pLocalizedRangeScan);
00093
00094 return pDataset;
00095 }
00096
00100 karto::OccupancyGrid* CreateOccupancyGrid(karto::Mapper* pMapper, kt_double resolution)
00101 {
00102 std::cout << "Generating map..." << std::endl;
00103
00104
00105 karto::OccupancyGrid* pOccupancyGrid = karto::OccupancyGrid::CreateFromScans(pMapper->GetAllProcessedScans(), resolution);
00106
00107 return pOccupancyGrid;
00108 }
00109
00113 void PrintOccupancyGrid(karto::OccupancyGrid* pOccupancyGrid)
00114 {
00115 if (pOccupancyGrid != NULL)
00116 {
00117
00118 kt_int32s width = pOccupancyGrid->GetWidth();
00119 kt_int32s height = pOccupancyGrid->GetHeight();
00120 karto::Vector2<kt_double> offset = pOccupancyGrid->GetCoordinateConverter()->GetOffset();
00121
00122 std::cout << "width = " << width << ", height = " << height << ", scale = " << pOccupancyGrid->GetCoordinateConverter()->GetScale() << ", offset: " << offset.GetX() << ", " << offset.GetY() << std::endl;
00123 for (kt_int32s y=height-1; y>=0; y--)
00124 {
00125 for (kt_int32s x=0; x<width; x++)
00126 {
00127
00128 kt_int8u value = pOccupancyGrid->GetValue(karto::Vector2<kt_int32s>(x, y));
00129
00130 switch (value)
00131 {
00132 case karto::GridStates_Unknown:
00133 std::cout << "*";
00134 break;
00135 case karto::GridStates_Occupied:
00136 std::cout << "X";
00137 break;
00138 case karto::GridStates_Free:
00139 std::cout << " ";
00140 break;
00141 default:
00142 std::cout << "?";
00143 }
00144 }
00145 std::cout << std::endl;
00146 }
00147 std::cout << std::endl;
00148 }
00149 }
00150
00151 int main(int , char )
00152 {
00153
00155
00156 karto::Mapper* pMapper = new karto::Mapper();
00157 if (pMapper != NULL)
00158 {
00159
00160 SpaSolver* pSolver = new SpaSolver();
00161 pMapper->SetScanSolver(pSolver);
00162
00163 karto::OccupancyGrid* pOccupancyGrid = NULL;
00164
00166
00167
00168
00169 pMapper->Reset();
00170
00171
00172 karto::Dataset* pDataset = CreateMap(pMapper);
00173
00174
00175 pOccupancyGrid = CreateOccupancyGrid(pMapper, 0.1);
00176 PrintOccupancyGrid(pOccupancyGrid);
00177 delete pOccupancyGrid;
00178
00179
00180 delete pSolver;
00181
00182
00183 delete pMapper;
00184
00185
00186 delete pDataset;
00187 }
00188
00189 return 0;
00190 }