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 
13 #include <mrpt/random.h>
15 #include <mrpt/system/os.h>
16 #include <iostream>
17 
18 using namespace mrpt;
19 using namespace mrpt::slam;
20 using namespace mrpt::maps;
21 using namespace mrpt::system;
22 using namespace mrpt::random;
23 using namespace mrpt::poses;
24 using namespace mrpt::config;
25 using namespace std;
26 
27 float SIGMA = 0.03f;
28 
29 // ------------------------------------------------------
30 // TestRS
31 // ------------------------------------------------------
32 void TestRS()
33 {
35 
36  // Load the map:
37  CMultiMetricMap map;
39  mapInit.loadFromConfigFile(CConfigFile("_demo_map.ini"), "MetricMap");
40  map.setListOfMaps(&mapInit);
41 
42  // Create a dummy observation:
45  obs.stdError = SIGMA;
46 
47  meas.beaconID = 0;
48  meas.sensedDistance = 2.1f;
49  meas.sensorLocationOnRobot = CPoint3D(0, 0, 0);
50  obs.sensedData.push_back(meas);
51 
52  meas.beaconID = 1;
53  meas.sensedDistance = 3.1f;
54  meas.sensorLocationOnRobot = CPoint3D(0, 0, 0);
55  obs.sensedData.push_back(meas);
56 
57  meas.beaconID = 2;
58  meas.sensedDistance = 1.1f;
59  meas.sensorLocationOnRobot = CPoint3D(0, 0, 0);
60  // obs.sensedData.push_back( meas );
61 
62  // Rejection Sampling:
64  vector<CRejectionSamplingRangeOnlyLocalization::TParticle> samples;
65  CTicTac tictac;
66 
67  // Set data:
69 
70  printf("Preparing...");
71  tictac.Tic();
72  CPose2D dumPose(0, 0, 0);
73  RS.setParams(*map.m_landmarksMap, obs, SIGMA, dumPose);
74  printf("Ok! %fms\n", 1000 * tictac.Tac());
75 
76  printf("Computing...");
77  tictac.Tic();
78  RS.rejectionSampling(1000, samples, 1000);
79  printf("Ok! %fms\n", 1000 * tictac.Tac());
80 
81  FILE* f = os::fopen("_out_samples.txt", "wt");
83  for (it = samples.begin(); it != samples.end(); it++)
85  f, "%f %f %f %e\n", it->d->x(), it->d->y(), it->d->phi(),
86  it->log_w);
87 
88  os::fclose(f);
89 }
90 
91 // ------------------------------------------------------
92 // MAIN
93 // ------------------------------------------------------
94 int main()
95 {
96  try
97  {
98  TestRS();
99 
100  return 0;
101  }
102  catch (exception& e)
103  {
104  cout << "EXCEPCTION: " << e.what() << endl;
105  return -1;
106  }
107  catch (...)
108  {
109  printf("Untyped excepcion!!");
110  return -1;
111  }
112 }
mrpt::config
Definition: config/CConfigFile.h:16
os.h
mrpt::obs::CObservationBeaconRanges::TMeasurement
Each one of the measurements.
Definition: CObservationBeaconRanges.h:41
mrpt::obs::CObservationBeaconRanges::TMeasurement::sensedDistance
float sensedDistance
The sensed range itself (in meters).
Definition: CObservationBeaconRanges.h:53
samples
GLsizei samples
Definition: glext.h:8068
mrpt::system::os::fclose
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:273
mrpt::slam::CRejectionSamplingRangeOnlyLocalization::setParams
bool setParams(const mrpt::maps::CLandmarksMap &beaconsMap, const mrpt::obs::CObservationBeaconRanges &observation, float sigmaRanges, const mrpt::poses::CPose2D &oldPose, float robot_z=0, bool autoCheckAngleRanges=true)
The parameters used in the generation of random samples:
Definition: CRejectionSamplingRangeOnlyLocalization.cpp:120
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
CMultiMetricMap.h
CConfigFile.h
SIGMA
double SIGMA
Definition: vision_stereo_rectify/test.cpp:24
mrpt::utils::CConfigFile
mrpt::config::CConfigFile CConfigFile
Definition: utils/CConfigFile.h:7
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::slam::CRejectionSamplingRangeOnlyLocalization
An implementation of rejection sampling for generating 2D robot pose from range-only measurements wit...
Definition: CRejectionSamplingRangeOnlyLocalization.h:36
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
TestRS
void TestRS()
Definition: vision_stereo_rectify/test.cpp:52
mrpt::maps::CMultiMetricMap::m_landmarksMap
ProxySelectorContainerByClass< mrpt::maps::CLandmarksMap::Ptr, TListMaps > m_landmarksMap
Proxy that looks like a smart pointer to the first matching object in maps.
Definition: CMultiMetricMap.h:404
random.h
mrpt::random::CRandomGenerator::randomize
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
Definition: RandomGenerator.cpp:32
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
mrpt::maps::TSetOfMetricMapInitializers
A set of TMetricMapInitializer structures, passed to the constructor CMultiMetricMap::CMultiMetricMap...
Definition: TMetricMapInitializer.h:91
mrpt::obs::CObservationBeaconRanges::sensedData
std::deque< TMeasurement > sensedData
The list of observed ranges.
Definition: CObservationBeaconRanges.h:59
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::obs::CObservationBeaconRanges
Declares a class derived from "CObservation" that represents one (or more) range measurements to labe...
Definition: CObservationBeaconRanges.h:27
mrpt::obs::CObservationBeaconRanges::stdError
float stdError
The "sigma" of the sensor, assuming a zero-mean Gaussian noise model.
Definition: CObservationBeaconRanges.h:38
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
mrpt::maps::CMultiMetricMap
This class stores any customizable set of metric maps.
Definition: CMultiMetricMap.h:141
mrpt::obs::CObservationBeaconRanges::TMeasurement::beaconID
int32_t beaconID
The ID of the sensed beacon (or INVALID_BEACON_ID if unknown)
Definition: CObservationBeaconRanges.h:55
mrpt::maps::TSetOfMetricMapInitializers::loadFromConfigFile
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &sectionName) override
Loads the configuration for the set of internal maps from a textual definition in an INI-like file.
Definition: TMetricMapInitializer.cpp:69
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
CObservationBeaconRanges.h
mrpt::random::getRandomGenerator
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
Definition: RandomGenerator.cpp:19
CRejectionSamplingRangeOnlyLocalization.h
mrpt::bayes::CRejectionSamplingCapable::rejectionSampling
void rejectionSampling(size_t desiredSamples, std::vector< TParticle > &outSamples, size_t timeoutTrials=1000)
Generates a set of N independent samples via rejection sampling.
Definition: CRejectionSamplingCapable.h:49
mrpt::system::os::fopen
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:255
mrpt::maps::CMultiMetricMap::setListOfMaps
void setListOfMaps(const mrpt::maps::TSetOfMetricMapInitializers *initializers)
Sets the list of internal map according to the passed list of map initializers (Current maps' content...
Definition: CMultiMetricMap.cpp:219
mrpt::random
A namespace of pseudo-random numbers generators of diferent distributions.
Definition: random_shuffle.h:17
mrpt::maps
Definition: CBeacon.h:24
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
mrpt::poses::CPoint3D
A class used to store a 3D point.
Definition: CPoint3D.h:33
mrpt::slam
Definition: CMultiMetricMapPDF.h:27
mrpt::obs::CObservationBeaconRanges::TMeasurement::sensorLocationOnRobot
mrpt::poses::CPoint3D sensorLocationOnRobot
Position of the sensor on the robot.
Definition: CObservationBeaconRanges.h:51
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25



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