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 
14 #include <mrpt/system/os.h>
15 #include <iostream>
16 
17 using namespace mrpt;
18 using namespace mrpt::obs;
19 using namespace mrpt::maps;
20 using namespace mrpt::gui;
21 using namespace mrpt::opengl;
22 using namespace mrpt::hwdrivers;
23 using namespace mrpt::poses;
24 using namespace std;
25 
26 string SERIAL_NAME; // Name of the serial port to open
27 
28 // ------------------------------------------------------
29 // Test_PLS
30 // ------------------------------------------------------
31 void TestPLS()
32 {
33  CSickLaserSerial laser;
34 
35  cout << "SICK LMS thru serial port test application." << endl << endl;
36 
37  if (SERIAL_NAME.empty())
38  {
39  cout << "Enter the serial port name (e.g. COM1, ttyS0, ttyUSB0, "
40  "ttyACM0): ";
41  getline(cin, SERIAL_NAME);
42  }
43  else
44  {
45  cout << "Using serial port: " << SERIAL_NAME << endl;
46  }
47 
49 
50 #if 1
51  // laser.setBaudRate(500000);
52  laser.setBaudRate(9600);
53  laser.setScanFOV(180);
54  laser.setScanResolution(50); // 25=0.25deg, 50=0.5deg, 100=1deg
55 // laser.setMillimeterMode(true);
56 #endif
57 
58 #if MRPT_HAS_WXWIDGETS
59  CDisplayWindowPlots win("Laser scans");
60 #endif
61 
62  // Load config:
63  // laser.loadConfig( CConfigFile( "./LASER_SCAN_TEST.ini") ,"PLS#1" );
64 
65  cout << "Trying to initialize the laser..." << endl;
66  laser.initialize(); // This will raise an exception on error
67  cout << "Initialized OK!" << endl;
68 
69  while (!mrpt::system::os::kbhit())
70  {
71  bool thereIsObservation, hardError;
73 
74  try
75  {
76  laser.doProcessSimple(thereIsObservation, obs, hardError);
77  }
78  catch (std::exception& e)
79  {
80  cerr << e.what() << endl;
81  hardError = true;
82  }
83 
84  if (hardError) printf("[TEST] Hardware error=true!!\n");
85 
86  if (thereIsObservation)
87  {
88  printf(
89  "[TEST] Observation received (%u ranges over %.02fdeg, "
90  "mid=%.03f)!!\n",
91  (unsigned int)obs.scan.size(), RAD2DEG(obs.aperture),
92  obs.scan[obs.scan.size() / 2]);
93 
94  obs.sensorPose = CPose3D(0, 0, 0);
97  theMap.insertObservation(&obs);
98 
99 #if MRPT_HAS_WXWIDGETS
100  std::vector<float> xs, ys, zs;
101  theMap.getAllPoints(xs, ys, zs);
102  win.plot(xs, ys, ".b3");
103  win.axis_equal();
104 #endif
105  }
106  std::this_thread::sleep_for(15ms);
107  };
108 
109  laser.turnOff();
110 }
111 
112 int main(int argc, char** argv)
113 {
114  try
115  {
116  if (argc > 1)
117  {
118  SERIAL_NAME = string(argv[1]);
119  }
120 
121  TestPLS();
122  return 0;
123  }
124  catch (std::exception& e)
125  {
126  std::cout << "EXCEPCION: " << e.what() << std::endl;
127  return -1;
128  }
129  catch (...)
130  {
131  printf("Another exception!!");
132  return -1;
133  }
134 }
mrpt::system::os::kbhit
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:390
os.h
mrpt::maps::CMetricMap::insertObservation
bool insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=NULL)
Insert the observation information into this map.
Definition: CMetricMap.cpp:95
CSickLaserSerial.h
SERIAL_NAME
string SERIAL_NAME
Definition: vision_stereo_rectify/test.cpp:25
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::CPointsMap::TInsertionOptions::minDistBetweenLaserPoints
float minDistBetweenLaserPoints
The minimum distance between points (in 3D): If two points are too close, one of them is not inserted...
Definition: CPointsMap.h:218
mrpt::hwdrivers::CSickLaserSerial::initialize
void initialize()
Set-up communication with the laser.
Definition: CSickLaserSerial.cpp:392
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:22
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::maps::CPointsMap::getAllPoints
void getAllPoints(VECTOR &xs, VECTOR &ys, VECTOR &zs, size_t decimation=1) const
Returns a copy of the 2D/3D points as a std::vector of float coordinates.
Definition: CPointsMap.h:536
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::RAD2DEG
double RAD2DEG(const double x)
Radians to degrees.
Definition: core/include/mrpt/core/bits_math.h:48
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::containers::ContainerReadOnlyProxyAccessor::size
size_t size() const
Definition: ContainerReadOnlyProxyAccessor.h:42
mrpt::hwdrivers::CSickLaserSerial::setScanFOV
void setScanFOV(int fov_degrees)
Set the scanning field of view - possible values are 100 or 180 (default) (call prior to 'doProcess')...
Definition: CSickLaserSerial.h:170
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
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
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::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::hwdrivers::CSickLaserSerial
This "software driver" implements the communication protocol for interfacing a SICK LMS 2XX laser sca...
Definition: CSickLaserSerial.h:70
mrpt::gui::CDisplayWindowPlots
Create a GUI window and display plots with MATLAB-like interfaces and commands.
Definition: CDisplayWindowPlots.h:31
mrpt::hwdrivers::CSickLaserSerial::setScanResolution
void setScanResolution(int res_1_100th_degree)
Set the scanning resolution, in units of 1/100 degree - Possible values are 25, 50 and 100,...
Definition: CSickLaserSerial.h:177
mrpt::hwdrivers::CSickLaserSerial::setBaudRate
void setBaudRate(int baud)
Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,...
Definition: CSickLaserSerial.h:156
mrpt::obs::CObservation2DRangeScan::scan
mrpt::containers::ContainerReadOnlyProxyAccessor< mrpt::aligned_std_vector< float > > scan
The range values of the scan, in meters.
Definition: CObservation2DRangeScan.h:103
mrpt::maps::CPointsMap::insertionOptions
TInsertionOptions insertionOptions
The options used when inserting observations in the map.
Definition: CPointsMap.h:257
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::maps
Definition: CBeacon.h:24
CDisplayWindowPlots.h
CSimplePointsMap.h
mrpt::obs::CObservation2DRangeScan::sensorPose
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
Definition: CObservation2DRangeScan.h:133
TestPLS
void TestPLS()
Definition: vision_stereo_rectify/test.cpp:31
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::hwdrivers::CSickLaserSerial::setSerialPort
void setSerialPort(const std::string &port)
Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0".
Definition: CSickLaserSerial.h:149
mrpt::hwdrivers::CSickLaserSerial::doProcessSimple
void doProcessSimple(bool &outThereIsObservation, mrpt::obs::CObservation2DRangeScan &outObservation, bool &hardwareError)
Specific laser scanner "software drivers" must process here new data from the I/O stream,...
Definition: CSickLaserSerial.cpp:87
CObservation2DRangeScan.h
mrpt::hwdrivers::CSickLaserSerial::turnOff
bool turnOff()
Disables the scanning mode (in this class this has no effect).
Definition: CSickLaserSerial.cpp:192



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