MRPT  1.9.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-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 
11 #include <gtest/gtest.h>
12 
13 using namespace mrpt;
14 using namespace mrpt::hwdrivers;
15 using namespace mrpt::obs;
16 using namespace std;
17 
18 // Example cmds:
19 // https://www.sparkfun.com/datasheets/GPS/NMEA%20Reference%20Manual-Rev2.1-Dec07.pdf
20 
21 TEST(CGPSInterface, parse_NMEA_GGA)
22 {
23  // Test with a correct frame:
24  {
25  const char* test_cmd =
26  "$GPGGA,101830.00,3649.76162994,N,00224.53709052,W,2,08,1.1,9.3,M,"
27  "47.4,M,5.0,0120*58";
29  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
30  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
31 
32  const gnss::Message_NMEA_GGA* msg =
34  EXPECT_TRUE(msg != nullptr);
35  if (!msg) return;
36  EXPECT_NEAR(
37  msg->fields.latitude_degrees, 36 + 49.76162994 / 60.0, 1e-10);
38  EXPECT_NEAR(
39  msg->fields.longitude_degrees, -(002 + 24.53709052 / 60.0), 1e-10);
40  EXPECT_NEAR(msg->fields.altitude_meters, 9.3, 1e-10);
41  }
42  // Test with an empty frame:
43  {
44  const char* test_cmd = "$GPGGA,,,,,,0,,,,M,,M,,*6";
46  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
47  EXPECT_FALSE(parse_ret);
48  }
49 }
50 
51 TEST(CGPSInterface, parse_NMEA_RMC)
52 {
53  const char* test_cmd =
54  "$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10";
56  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
57  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
58 
59  const gnss::Message_NMEA_RMC* msg =
61 
62  EXPECT_TRUE(msg != nullptr);
63  if (!msg) return;
64  EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10);
65  EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10);
66 }
67 
68 TEST(CGPSInterface, parse_NMEA_GLL)
69 {
70  const char* test_cmd = "$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41";
72  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
73  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
74 
75  const gnss::Message_NMEA_GLL* msg =
77 
78  EXPECT_TRUE(msg != nullptr);
79  if (!msg) return;
80  EXPECT_NEAR(msg->fields.latitude_degrees, 37 + 23.2475 / 60.0, 1e-10);
81  EXPECT_NEAR(msg->fields.longitude_degrees, -(121 + 58.3416 / 60.0), 1e-10);
82 }
83 
84 TEST(CGPSInterface, parse_NMEA_VTG)
85 {
86  const char* test_cmd = "$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48";
88  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
89  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
90 
91  const gnss::Message_NMEA_VTG* msg =
93 
94  EXPECT_TRUE(msg != nullptr);
95  if (!msg) return;
96  EXPECT_NEAR(msg->fields.true_track, 54.7, 1e-6);
97  EXPECT_NEAR(msg->fields.magnetic_track, 34.4, 1e-6);
98  EXPECT_NEAR(msg->fields.ground_speed_knots, 5.5, 1e-6);
99  EXPECT_NEAR(msg->fields.ground_speed_kmh, 10.2, 1e-6);
100 }
101 
102 TEST(CGPSInterface, parse_NMEA_ZDA)
103 {
104  const char* test_cmd = "$GPZDA,181813,14,10,2003,00,00*4F";
106  const bool parse_ret = CGPSInterface::parse_NMEA(test_cmd, obsGPS);
107  EXPECT_TRUE(parse_ret) << "Failed parse of: " << test_cmd << endl;
108 
109  const gnss::Message_NMEA_ZDA* msg =
111 
112  EXPECT_TRUE(msg != nullptr);
113  if (!msg) return;
114  EXPECT_TRUE(msg->fields.date_day == 14);
115  EXPECT_TRUE(msg->fields.date_month == 10);
116  EXPECT_TRUE(msg->fields.date_year == 2003);
117  EXPECT_TRUE(msg->fields.UTCTime.hour == 18);
118  EXPECT_TRUE(msg->fields.UTCTime.minute == 18);
119  EXPECT_TRUE(msg->fields.UTCTime.sec == 13.0); // Replaced from EXPECT_EQ()
120  // to avoid a "bus error" in
121  // a gtest template under
122  // armhf.
123 }
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 nullptr pointer if message is not found...
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.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020