Main MRPT website > C++ reference for MRPT 1.5.9
CGPSInterface_unittest.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-2017, 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 
10 
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::hwdrivers;
16 using namespace mrpt::utils;
17 using namespace mrpt::obs;
18 using namespace std;
19 
20 // Example cmds: https://www.sparkfun.com/datasheets/GPS/NMEA%20Reference%20Manual-Rev2.1-Dec07.pdf
21 
22 TEST(CGPSInterface, parse_NMEA_GGA)
23 {
24  // Test with a correct frame:
25  {
26  const char *test_cmd = "$GPGGA,101830.00,3649.76162994,N,00224.53709052,W,2,08,1.1,9.3,M,47.4,M,5.0,0120*58";
28  const bool parse_ret = CGPSInterface::parse_NMEA( test_cmd, obsGPS );
29  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
30 
32  EXPECT_TRUE(msg!=NULL);
33  if (!msg) return;
34  EXPECT_NEAR(msg->fields.latitude_degrees, 36+49.76162994/60.0,1e-10);
35  EXPECT_NEAR(msg->fields.longitude_degrees, -(002+24.53709052/60.0),1e-10);
36  EXPECT_NEAR(msg->fields.altitude_meters, 9.3,1e-10);
37  }
38  // Test with an empty frame:
39  {
40  const char *test_cmd = "$GPGGA,,,,,,0,,,,M,,M,,*6";
42  const bool parse_ret = CGPSInterface::parse_NMEA( test_cmd, obsGPS );
43  EXPECT_FALSE(parse_ret);
44  }
45 }
46 
47 TEST(CGPSInterface, parse_NMEA_RMC)
48 {
49  const char *test_cmd = "$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10";
51  const bool parse_ret = CGPSInterface::parse_NMEA( test_cmd, obsGPS );
52  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
53 
55 
56  EXPECT_TRUE(msg!=NULL);
57  if (!msg) return;
58  EXPECT_NEAR(msg->fields.latitude_degrees, 37+ 23.2475/60.0,1e-10);
59  EXPECT_NEAR(msg->fields.longitude_degrees, -(121+58.3416/60.0),1e-10);
60 }
61 
62 TEST(CGPSInterface, parse_NMEA_GLL)
63 {
64  const char *test_cmd = "$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41";
66  const bool parse_ret = CGPSInterface::parse_NMEA( test_cmd, obsGPS );
67  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
68 
70 
71  EXPECT_TRUE(msg!=NULL);
72  if (!msg) return;
73  EXPECT_NEAR(msg->fields.latitude_degrees, 37+ 23.2475/60.0,1e-10);
74  EXPECT_NEAR(msg->fields.longitude_degrees, -(121+58.3416/60.0),1e-10);
75 }
76 
77 TEST(CGPSInterface, parse_NMEA_VTG)
78 {
79  const char *test_cmd = "$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48";
81  const bool parse_ret = CGPSInterface::parse_NMEA( test_cmd, obsGPS );
82  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
83 
85 
86  EXPECT_TRUE(msg!=NULL);
87  if (!msg) return;
88  EXPECT_NEAR(msg->fields.true_track, 54.7,1e-6);
89  EXPECT_NEAR(msg->fields.magnetic_track, 34.4,1e-6);
90  EXPECT_NEAR(msg->fields.ground_speed_knots, 5.5,1e-6);
91  EXPECT_NEAR(msg->fields.ground_speed_kmh, 10.2,1e-6);
92 }
93 
94 TEST(CGPSInterface, parse_NMEA_ZDA)
95 {
96  const char *test_cmd = "$GPZDA,181813,14,10,2003,00,00*4F";
98  const bool parse_ret = CGPSInterface::parse_NMEA( test_cmd, obsGPS );
99  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
100 
102 
103  EXPECT_TRUE(msg!=NULL);
104  if (!msg) return;
105  EXPECT_TRUE(msg->fields.date_day==14);
106  EXPECT_TRUE(msg->fields.date_month==10);
107  EXPECT_TRUE(msg->fields.date_year==2003);
108  EXPECT_TRUE(msg->fields.UTCTime.hour==18);
109  EXPECT_TRUE(msg->fields.UTCTime.minute==18);
110  EXPECT_TRUE(msg->fields.UTCTime.sec==13.0); // Replaced from EXPECT_EQ() to avoid a "bus error" in a gtest template under armhf.
111 }
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
content_t fields
Message content, accesible by individual fields.
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
A class capable of reading GPS/GNSS/GNSS+IMU receiver data, from a serial port or from any input stre...
MSG_CLASS * getMsgByClassPtr()
Like CObservationGPS::getMsgByClass() but returns a NULL pointer if message is not found...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
TEST(CGPSInterface, parse_NMEA_GGA)
content_t fields
Message content, accesible by individual fields.
Contains classes for various device interfaces.
content_t fields
Message content, accesible by individual fields.
UTC_time UTCTime
The GPS sensor measured timestamp (in UTC time)
STL namespace.
double altitude_meters
The measured altitude, in meters (A).
content_t fields
Message content, accesible by individual fields.
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
This namespace contains representation of robot actions and observations.
static bool parse_NMEA(const std::string &cmd_line, mrpt::obs::CObservationGPS &out_obs, const bool verbose=false)
Parses one line of NMEA data from a GPS receiver, and writes the recognized fields (if any) into an o...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
content_t fields
Message content, accesible by individual fields.
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020