Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/system/CTicTac.h>
12 #include <mrpt/poses/CPose2D.h>
13 #include <mrpt/system/filesystem.h>
14 #include <mrpt/system/os.h>
18 #include <iostream>
19 
20 using namespace mrpt;
21 using namespace mrpt::system;
22 using namespace mrpt::obs;
23 using namespace mrpt::maps;
24 using namespace mrpt::poses;
25 using namespace std;
26 
27 #include <mrpt/examples_config.h>
28 string myDataDir(
29  MRPT_EXAMPLES_BASE_DIRECTORY +
30  string("maps_gridmap_likelihood_characterization/"));
31 
32 // Default .ini file:
33 string iniFile(myDataDir + string("config_likelihood.ini"));
34 
35 // ------------------------------------------------------
36 // theMainThing
37 // ------------------------------------------------------
38 void theMainThing()
39 {
40  COccupancyGridMap2D gridMap;
42  CTicTac tictac;
43 
44  // Load the grid map from file
45  // ----------------------------------------------
46  obsScan.aperture = M_2PIf;
47 
50 
51  string bmp = cfgFile.read_string("Params", "bitmap_file", "", true);
52  float res =
53  cfgFile.read_float("Params", "evaluation_grid_resolution", 0.1f, true);
54 
55  float evalgrid_x_min = 0, evalgrid_x_max = 0;
56  float evalgrid_y_min = 0, evalgrid_y_max = 0;
57 
58  MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(evalgrid_x_min, float, cfgFile, "Params");
59  MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(evalgrid_x_max, float, cfgFile, "Params");
60  MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(evalgrid_y_min, float, cfgFile, "Params");
61  MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(evalgrid_y_max, float, cfgFile, "Params");
62 
63  int type_experiment = 0;
64  MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(type_experiment, int, cfgFile, "Params");
65 
66  // Gridmap:
67  string GRIDMAP_FILE(myDataDir + bmp);
68 
69  gridMap.loadFromBitmapFile(GRIDMAP_FILE, 0.05f);
70  gridMap.saveAsBitmapFile("./out_gridmap.png");
71 
72  if (type_experiment == 0)
73  {
74  // Simulate scan:
75  // ----------------------------------------------
76  obsScan.aperture = M_PIf;
77  obsScan.maxRange = 80.0f;
78  obsScan.rightToLeft = true;
79  gridMap.laserScanSimulator(obsScan, CPose2D(0, 0, 0), 0.5f, 180);
80  }
81  else
82  {
83  // Lik. of each 2D position
84  // ------------------------------------
85  obsScan.aperture = 0;
86  obsScan.maxRange = 80.0f;
87  obsScan.rightToLeft = true;
88  obsScan.resizeScanAndAssign(1, 0.0, true);
89  }
90 
91  // Set options:
92  // ----------------------------------------------
93  gridMap.likelihoodOptions.loadFromConfigFile(cfgFile, "LikelihoodOptions");
95 
96  // Perform simulation:
97  // ----------------------------------------------
98  printf("Performing simulation (saving to out_lik.txt)...");
99 
100  FILE* f = os::fopen("out_lik.txt", "wt");
101  ASSERT_(f);
102 
103  CSimplePointsMap pointsMap;
104  pointsMap.clear();
105  pointsMap.insertPoint(0, 0);
106 
107  tictac.Tic();
108 
109  float phi = (float)DEG2RAD(0);
110 
111  CPose2D nullPose(0, 0, phi);
112 
113  for (float y = evalgrid_y_min; y < evalgrid_y_max; y += res)
114  {
115  for (float x = evalgrid_x_min; x < evalgrid_x_max; x += res)
116  {
117  nullPose.x(x);
118  nullPose.y(y);
119  fprintf(
120  f, "%e ",
121  gridMap.computeObservationLikelihood(&obsScan, nullPose));
122  } // for y
123  fprintf(f, "\n");
124  } // for x
125 
126  printf("Done!\n");
127 
128  printf("Time:%fms\n", 1000.0f * tictac.Tac());
129 
130  os::fclose(f);
131 }
132 
133 int main()
134 {
135  try
136  {
137  theMainThing();
138 
139  return 0;
140  }
141  catch (std::exception& e)
142  {
143  std::cout << "MRPT exception:\n" << e.what() << std::endl;
144  return -1;
145  }
146  catch (...)
147  {
148  printf("Runtime exception!!");
149  return -1;
150  }
151 }
os.h
filesystem.h
mrpt::config::CLoadableOptions::dumpToConsole
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
Definition: CLoadableOptions.cpp:44
COccupancyGridMap2D.h
mrpt::obs::CObservation2DRangeScan::maxRange
float maxRange
The maximum range allowed by the device, in meters (e.g.
Definition: CObservation2DRangeScan.h:130
mrpt::system::os::fclose
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:273
mrpt::obs::CObservation2DRangeScan::rightToLeft
bool rightToLeft
The scanning direction: true=counterclockwise; false=clockwise.
Definition: CObservation2DRangeScan.h:127
mrpt::maps::COccupancyGridMap2D::loadFromBitmapFile
bool loadFromBitmapFile(const std::string &file, float resolution, float xCentralPixel=-1, float yCentralPixel=-1)
Load the gridmap from a image in a file (the format can be any supported by CImage::loadFromFile).
Definition: COccupancyGridMap2D_io.cpp:271
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
mrpt::obs::CObservation2DRangeScan
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Definition: CObservation2DRangeScan.h:56
mrpt::maps::CMetricMap::computeObservationLikelihood
double computeObservationLikelihood(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D &takenFrom)
Computes the log-likelihood of a given observation given an arbitrary robot 3D pose.
Definition: CMetricMap.cpp:189
CConfigFile.h
theMainThing
void theMainThing()
Definition: vision_stereo_rectify/test.cpp:38
myDataDir
std::string myDataDir
Definition: vision_stereo_rectify/test.cpp:23
mrpt::maps::CPointsMap::insertPoint
void insertPoint(float x, float y, float z=0)
Provides a way to insert (append) individual points into the map: the missing fields of child classes...
Definition: CPointsMap.h:604
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
CPose2D.h
mrpt::system::fileExists
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:127
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions::loadFromConfigFile
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &section) override
This method load the options from a ".ini" file.
Definition: COccupancyGridMap2D_likelihood.cpp:853
MRPT_LOAD_CONFIG_VAR_NO_DEFAULT
#define MRPT_LOAD_CONFIG_VAR_NO_DEFAULT( variableName, variableType, configFileObject, sectionNameStr)
Definition: config/CConfigFileBase.h:377
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::maps::COccupancyGridMap2D::laserScanSimulator
void laserScanSimulator(mrpt::obs::CObservation2DRangeScan &inout_Scan, const mrpt::poses::CPose2D &robotPose, float threshold=0.6f, size_t N=361, float noiseStd=0, unsigned int decimation=1, float angleNoiseStd=mrpt::DEG2RAD(.0)) const
Simulates a laser range scan into the current grid map.
Definition: COccupancyGridMap2D_simulate.cpp:30
mrpt::obs::CObservation2DRangeScan::resizeScanAndAssign
void resizeScanAndAssign(const size_t len, const float rangeVal, const bool rangeValidity, const int32_t rangeIntensity=0)
Resizes all data vectors to allocate a given number of scan rays and assign default values.
Definition: CObservation2DRangeScan.cpp:545
mrpt::obs::CObservation2DRangeScan::aperture
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees).
Definition: CObservation2DRangeScan.h:125
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:40
res
GLuint res
Definition: glext.h:7268
iniFile
string iniFile(myDataDir+string("benchmark-options.ini"))
mrpt::maps::CSimplePointsMap
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
Definition: CSimplePointsMap.h:31
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
mrpt::system::os::fprintf
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:406
mrpt::maps::COccupancyGridMap2D::saveAsBitmapFile
bool saveAsBitmapFile(const std::string &file) const
Saves the gridmap as a graphical file (BMP,PNG,...).
Definition: COccupancyGridMap2D_io.cpp:34
CTicTac.h
mrpt::config::CConfigFile
This class allows loading and storing values and vectors of different types from "....
Definition: config/CConfigFile.h:33
mrpt::maps::COccupancyGridMap2D
A class for storing an occupancy grid map.
Definition: COccupancyGridMap2D.h:62
mrpt::system::os::fopen
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:255
M_PIf
#define M_PIf
Definition: common.h:61
mrpt::maps::COccupancyGridMap2D::likelihoodOptions
mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions likelihoodOptions
mrpt::maps
Definition: CBeacon.h:24
mrpt::maps::CMetricMap::clear
void clear()
Erase all the contents of the map.
Definition: CMetricMap.cpp:31
M_2PIf
#define M_2PIf
Definition: common.h:62
CSimplePointsMap.h
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
CObservation2DRangeScan.h
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
mrpt::DEG2RAD
double DEG2RAD(const double x)
Degrees to radians.
Definition: core/include/mrpt/core/bits_math.h:42



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST