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 <OpenKarto/Mapper.h>
00019
00025 karto::Dataset* CreateMap(karto::Mapper* pMapper)
00026 {
00027 karto::Dataset* pDataset = new karto::Dataset();
00028
00030
00031 karto::Name name("laser0");
00032 karto::LaserRangeFinder* pLaserRangeFinder = karto::LaserRangeFinder::CreateLaserRangeFinder(karto::LaserRangeFinder_Custom, name);
00033 pLaserRangeFinder->SetOffsetPose(karto::Pose2(1.0, 0.0, 0.0));
00034 pLaserRangeFinder->SetAngularResolution(karto::math::DegreesToRadians(0.5));
00035 pLaserRangeFinder->SetRangeThreshold(12.0);
00036
00037 pDataset->Add(pLaserRangeFinder);
00038
00040
00041 karto::LocalizedRangeScan* pLocalizedRangeScan = NULL;
00042
00043
00044
00045
00046 std::vector<kt_double> readings;
00047 for (int i=0; i<361; i++)
00048 {
00049 readings.push_back(3.0);
00050 }
00051
00052
00053 pLocalizedRangeScan = new karto::LocalizedRangeScan(name, readings);
00054 pLocalizedRangeScan->SetOdometricPose(karto::Pose2(0.0, 0.0, 0.0));
00055 pLocalizedRangeScan->SetCorrectedPose(karto::Pose2(0.0, 0.0, 0.0));
00056
00057
00058 pMapper->Process(pLocalizedRangeScan);
00059 std::cout << "Pose: " << pLocalizedRangeScan->GetOdometricPose() << " Corrected Pose: " << pLocalizedRangeScan->GetCorrectedPose() << std::endl;
00060
00061
00062 pDataset->Add(pLocalizedRangeScan);
00063
00064
00065
00066
00067 pLocalizedRangeScan = new karto::LocalizedRangeScan(name, readings);
00068 pLocalizedRangeScan->SetOdometricPose(karto::Pose2(1.0, 0.0, 1.57));
00069 pLocalizedRangeScan->SetCorrectedPose(karto::Pose2(1.0, 0.0, 1.57));
00070
00071
00072 pMapper->Process(pLocalizedRangeScan);
00073 std::cout << "Pose: " << pLocalizedRangeScan->GetOdometricPose() << " Corrected Pose: " << pLocalizedRangeScan->GetCorrectedPose() << std::endl;
00074
00075
00076 pDataset->Add(pLocalizedRangeScan);
00077
00078
00079
00080
00081 pLocalizedRangeScan = new karto::LocalizedRangeScan(name, readings);
00082 pLocalizedRangeScan->SetOdometricPose(karto::Pose2(1.0, -1.0, 2.35619449));
00083 pLocalizedRangeScan->SetCorrectedPose(karto::Pose2(1.0, -1.0, 2.35619449));
00084
00085
00086 pMapper->Process(pLocalizedRangeScan);
00087 std::cout << "Pose: " << pLocalizedRangeScan->GetOdometricPose() << " Corrected Pose: " << pLocalizedRangeScan->GetCorrectedPose() << std::endl;
00088
00089
00090 pDataset->Add(pLocalizedRangeScan);
00091
00092 return pDataset;
00093 }
00094
00098 karto::OccupancyGrid* CreateOccupancyGrid(karto::Mapper* pMapper, kt_double resolution)
00099 {
00100 std::cout << "Generating map..." << std::endl;
00101
00102
00103 karto::OccupancyGrid* pOccupancyGrid = karto::OccupancyGrid::CreateFromScans(pMapper->GetAllProcessedScans(), resolution);
00104
00105 return pOccupancyGrid;
00106 }
00107
00111 void PrintOccupancyGrid(karto::OccupancyGrid* pOccupancyGrid)
00112 {
00113 if (pOccupancyGrid != NULL)
00114 {
00115
00116 kt_int32s width = pOccupancyGrid->GetWidth();
00117 kt_int32s height = pOccupancyGrid->GetHeight();
00118 karto::Vector2<kt_double> offset = pOccupancyGrid->GetCoordinateConverter()->GetOffset();
00119
00120 std::cout << "width = " << width << ", height = " << height << ", scale = " << pOccupancyGrid->GetCoordinateConverter()->GetScale() << ", offset: " << offset.GetX() << ", " << offset.GetY() << std::endl;
00121 for (kt_int32s y=height-1; y>=0; y--)
00122 {
00123 for (kt_int32s x=0; x<width; x++)
00124 {
00125
00126 kt_int8u value = pOccupancyGrid->GetValue(karto::Vector2<kt_int32s>(x, y));
00127
00128 switch (value)
00129 {
00130 case karto::GridStates_Unknown:
00131 std::cout << "*";
00132 break;
00133 case karto::GridStates_Occupied:
00134 std::cout << "X";
00135 break;
00136 case karto::GridStates_Free:
00137 std::cout << " ";
00138 break;
00139 default:
00140 std::cout << "?";
00141 }
00142 }
00143 std::cout << std::endl;
00144 }
00145 std::cout << std::endl;
00146 }
00147 }
00148
00149 int main(int , char )
00150 {
00151
00153
00154 karto::Mapper* pMapper = new karto::Mapper();
00155 if (pMapper != NULL)
00156 {
00157 karto::OccupancyGrid* pOccupancyGrid = NULL;
00158
00160
00161
00162 std::cout << "Tutorial 1 ----------------" << std::endl << std::endl;
00163
00164
00165 pMapper->Reset();
00166
00167
00168 karto::Dataset* pDataset = CreateMap(pMapper);
00169
00170
00171 pOccupancyGrid = CreateOccupancyGrid(pMapper, 0.1);
00172 PrintOccupancyGrid(pOccupancyGrid);
00173 delete pOccupancyGrid;
00174
00175
00176 delete pMapper;
00177
00178 delete pDataset;
00179 }
00180
00181 return 0;
00182 }