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 }
void setSerialPort(const std::string &port)
Changes the serial port to connect to (call prior to &#39;doProcess&#39;), for example "COM1" or "ttyS0"...
double RAD2DEG(const double x)
Radians to degrees.
Create a GUI window and display plots with MATLAB-like interfaces and commands.
bool turnOff()
Disables the scanning mode (in this class this has no effect).
Contains classes for various device interfaces.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
STL namespace.
void setScanFOV(int fov_degrees)
Set the scanning field of view - possible values are 100 or 180 (default) (call prior to &#39;doProcess&#39;)...
void initialize()
Set-up communication with the laser.
mrpt::containers::ContainerReadOnlyProxyAccessor< mrpt::aligned_std_vector< float > > scan
The range values of the scan, in meters.
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
This namespace contains representation of robot actions and observations.
void setScanResolution(int res_1_100th_degree)
Set the scanning resolution, in units of 1/100 degree - Possible values are 25, 50 and 100...
mrpt::gui::CDisplayWindow3D::Ptr win
GLsizei const GLchar ** string
Definition: glext.h:4101
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void setBaudRate(int baud)
Changes the serial port baud rate (call prior to &#39;doProcess&#39;); valid values are 9600,38400 and 500000.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
This "software driver" implements the communication protocol for interfacing a SICK LMS 2XX laser sca...
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:390
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees)...
TInsertionOptions insertionOptions
The options used when inserting observations in the map.
Definition: CPointsMap.h:257
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
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...
bool insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=NULL)
Insert the observation information into this map.
Definition: CMetricMap.cpp:95
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
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
string SERIAL_NAME



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020