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/filesystem.h>
13 #include <mrpt/system/os.h>
14 
15 #include <thread>
16 #include <iostream>
17 
18 using namespace mrpt;
19 using namespace mrpt::obs;
20 using namespace mrpt::system;
21 using namespace mrpt::hwdrivers;
22 using namespace mrpt::config;
23 using namespace std;
24 
25 string SERIAL_NAME; // Name of the serial port to open
26 
27 // ------------------------------------------------------
28 // Test_GPS
29 // ------------------------------------------------------
30 void Test_GPS()
31 {
32  CGPSInterface gps;
33 
34  string serName;
35  cout << "GPS test application." << endl << endl;
36 
37  if (mrpt::system::fileExists("./CONFIG_gps.ini"))
38  {
39  cout << "Using configuration from './CONFIG_gps.ini'" << endl;
40  CConfigFile iniFile("./CONFIG_gps.ini");
41  gps.loadConfig(iniFile, "GPS");
42  }
43  else
44  {
45  if (SERIAL_NAME.empty())
46  {
47  cout << "Enter the serial port name (e.g. COM1, ttyS0, ttyUSB0, "
48  "ttyACM0): ";
49  getline(cin, serName);
50  }
51  else
52  {
53  cout << "Using serial port: " << SERIAL_NAME << endl;
54  serName = SERIAL_NAME;
55  }
56 
57  // Set the laser serial port:
58  gps.setSerialPortName(serName);
59  }
60 
61  FILE* f = os::fopen("gps_log.txt", "wt");
62  if (!f) return;
63 
64  // bool thereisData;
65  // mrpt::obs::CObservationGPS gpsData;
66 
69 
70  while (!mrpt::system::os::kbhit())
71  {
72  gps.doProcess();
73  std::this_thread::sleep_for(500ms);
74 
75  gps.getObservations(lstObs);
76 
77  if (lstObs.empty())
78  {
79  printf("[Test_GPS] Waiting for data...\n");
80  }
81  else
82  {
83  for (itObs = lstObs.begin(); itObs != lstObs.end(); itObs++)
84  {
85  ASSERT_(
86  itObs->second->GetRuntimeClass() ==
88 
89  CObservationGPS::Ptr gpsData =
90  std::dynamic_pointer_cast<CObservationGPS>(itObs->second);
91  gpsData->dumpToConsole(std::cout);
92  }
93  lstObs.clear();
94  }
95  }
96 
97  os::fclose(f);
98 }
99 
100 int main()
101 {
102  try
103  {
104  Test_GPS();
105  return 0;
106  }
107  catch (std::exception& e)
108  {
109  std::cout << "EXCEPCION: " << e.what() << std::endl;
110  return -1;
111  }
112  catch (...)
113  {
114  printf("Another exception!!");
115  return -1;
116  }
117 }
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
mrpt::config
Definition: config/CConfigFile.h:16
os.h
filesystem.h
mrpt::hwdrivers::CGenericSensor::TListObservations
std::multimap< mrpt::system::TTimeStamp, mrpt::serialization::CSerializable::Ptr > TListObservations
Definition: CGenericSensor.h:77
SERIAL_NAME
string SERIAL_NAME
Definition: vision_stereo_rectify/test.cpp:25
mrpt::system::os::fclose
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:273
mrpt::hwdrivers::CGPSInterface
A class capable of reading GPS/GNSS/GNSS+IMU receiver data, from a serial port or from any input stre...
Definition: CGPSInterface.h:145
CConfigFile.h
Test_GPS
void Test_GPS()
Definition: vision_stereo_rectify/test.cpp:30
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
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
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::hwdrivers::CGPSInterface::setSerialPortName
void setSerialPortName(const std::string &COM_port)
Set the serial port to use (COM1, ttyUSB0, etc).
Definition: CGPSInterface.cpp:222
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
iniFile
string iniFile(myDataDir+string("benchmark-options.ini"))
mrpt::hwdrivers::CGenericSensor::getObservations
void getObservations(TListObservations &lstObjects)
Returns a list of enqueued objects, emptying it (thread-safe).
Definition: CGenericSensor.cpp:91
mrpt::obs::CObservationGPS::Ptr
std::shared_ptr< CObservationGPS > Ptr
Definition: CObservationGPS.h:72
mrpt::hwdrivers::CGPSInterface::doProcess
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)
Definition: CGPSInterface.cpp:307
CLASS_ID
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:85
mrpt::obs::CObservationGPS
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...
Definition: CObservationGPS.h:70
mrpt::config::CConfigFile
This class allows loading and storing values and vectors of different types from "....
Definition: config/CConfigFile.h:33
mrpt::system::os::fopen
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:255
mrpt::hwdrivers::CGenericSensor::loadConfig
void loadConfig(const mrpt::config::CConfigFileBase &configSource, const std::string &section)
Loads the generic settings common to any sensor (See CGenericSensor), then call to "loadConfig_sensor...
Definition: CGenericSensor.cpp:132
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
CGPSInterface.h
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