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 
12 #include <mrpt/system/CTicTac.h>
14 #include <mrpt/system/os.h>
15 #include <iostream>
16 
17 using namespace mrpt;
18 using namespace mrpt::hwdrivers;
19 using namespace mrpt::obs;
20 using namespace mrpt::gui;
21 using namespace mrpt::system;
22 using namespace std;
23 
24 string SERIAL_NAME; // Name of the serial port to open
25 
26 // ------------------------------------------------------
27 // Test_RPLIDAR
28 // ------------------------------------------------------
29 void Test_RPLIDAR()
30 {
31  CRoboPeakLidar laser;
32  string serName;
33 
34  if (SERIAL_NAME.empty())
35  {
36  std::cout << "Enter the serial port name (e.g. COM1, ttyS0, ttyUSB0, "
37  "ttyACM0): ";
38  getline(cin, serName);
39  }
40  else
41  {
42  std::cout << "Using serial port: " << SERIAL_NAME << endl;
43  serName = SERIAL_NAME;
44  }
45 
46  // Set the laser serial port:
47  laser.setSerialPort(serName);
48 
49  // Show GUI preview:
50  laser.showPreview(true);
51 
52  // Config: Use defaults + selected port ( serial or ethernet )
53  printf("Turning laser ON...\n");
54  if (laser.turnOn())
55  printf("Initialization OK!\n");
56  else
57  {
58  printf("Initialization failed!\n");
59  return;
60  }
61 
62  cout << "Press any key to stop capturing..." << endl;
63 
64  CTicTac tictac;
65  tictac.Tic();
66 
67  while (!mrpt::system::os::kbhit())
68  {
69  bool thereIsObservation, hardError;
71 
72  laser.doProcessSimple(thereIsObservation, obs, hardError);
73 
74  if (hardError) printf("[TEST] Hardware error=true!!\n");
75 
76  if (thereIsObservation)
77  {
78  double FPS = 1.0 / tictac.Tac();
79 
80  printf(
81  "Scan received: %u ranges, FOV: %.02fdeg, %.03fHz: mid "
82  "rang=%fm\n",
83  (unsigned int)obs.scan.size(), RAD2DEG(obs.aperture), FPS,
84  obs.scan[obs.scan.size() / 2]);
85 
86  obs.sensorPose = mrpt::poses::CPose3D(0, 0, 0);
87 
88  tictac.Tic();
89  }
90 
91  std::this_thread::sleep_for(5ms);
92  };
93 }
94 
95 int main(int argc, char** argv)
96 {
97  try
98  {
99  if (argc > 1) SERIAL_NAME = string(argv[1]);
100 
101  Test_RPLIDAR();
102  return 0;
103  }
104  catch (std::exception& e)
105  {
106  std::cout << "EXCEPCION: " << e.what() << std::endl;
107  return -1;
108  }
109  catch (...)
110  {
111  printf("Another exception!!");
112  return -1;
113  }
114 }
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
SERIAL_NAME
string SERIAL_NAME
Definition: vision_stereo_rectify/test.cpp:25
string_utils.h
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::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::RAD2DEG
double RAD2DEG(const double x)
Radians to degrees.
Definition: core/include/mrpt/core/bits_math.h:48
mrpt::hwdrivers::CRoboPeakLidar::turnOn
virtual bool turnOn()
See base class docs.
Definition: CRoboPeakLidar.cpp:196
mrpt::hwdrivers::C2DRangeFinderAbstract::showPreview
void showPreview(bool enable=true)
Enables GUI visualization in real-time.
Definition: C2DRangeFinderAbstract.h:120
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
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::containers::ContainerReadOnlyProxyAccessor::size
size_t size() const
Definition: ContainerReadOnlyProxyAccessor.h:42
mrpt::hwdrivers::CRoboPeakLidar::setSerialPort
void setSerialPort(const std::string &port_name)
If set to non-empty, the serial port will be attempted to be opened automatically when this class is ...
Definition: CRoboPeakLidar.cpp:354
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::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
Test_RPLIDAR
void Test_RPLIDAR()
Definition: vision_stereo_rectify/test.cpp:29
mrpt::hwdrivers::CRoboPeakLidar
Interfaces a Robo Peak LIDAR laser scanner.
Definition: CRoboPeakLidar.h:53
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
CRoboPeakLidar.h
CTicTac.h
string
GLsizei const GLchar ** string
Definition: glext.h:4101
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
CObservation2DRangeScan.h
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
mrpt::hwdrivers::CRoboPeakLidar::doProcessSimple
virtual 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: CRoboPeakLidar.cpp:60



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