MRPT  1.9.9
gps.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /*---------------------------------------------------------------
11  APPLICATION: mrpt_ros bridge
12  FILE: gps.cpp
13  AUTHOR: Raghavender Sahdev <raghavendersahdev@gmail.com>
14  ---------------------------------------------------------------*/
15 
16 #include <mrpt/ros1bridge/gps.h>
17 
18 namespace mrpt::ros1bridge
19 {
20 bool fromROS(const sensor_msgs::NavSatFix& msg, mrpt::obs::CObservationGPS& obj)
21 {
23  gga.fields.altitude_meters = msg.altitude;
24  gga.fields.latitude_degrees = msg.latitude;
25  gga.fields.longitude_degrees = msg.longitude;
26 
27  switch (msg.status.status)
28  {
29  case -1:
30  gga.fields.fix_quality = 0;
31  break;
32  case 0:
33  gga.fields.fix_quality = 1;
34  break;
35  case 2:
36  gga.fields.fix_quality = 2;
37  break;
38  case 1:
39  gga.fields.fix_quality = 3;
40  break;
41  default:
42  gga.fields.fix_quality = 0; // never going to execute default
43  }
44  obj.setMsg(gga);
45  return true;
46 }
47 
48 bool toROS(
49  const mrpt::obs::CObservationGPS& obj, const std_msgs::Header& msg_header,
50  sensor_msgs::NavSatFix& msg)
51 {
52  // 1) sensor_msgs::NavSatFix:: header
53  msg.header = msg_header;
54 
55  // 2) other NavSatFix Parameters, the following 3 could be wrong too
56 
58  {
61  msg.altitude = gga.fields.altitude_meters;
62  msg.latitude = gga.fields.latitude_degrees;
63  msg.longitude = gga.fields.longitude_degrees;
64 
65  /// following parameter assigned as per
66  /// http://mrpt.ual.es/reference/devel/structmrpt_1_1obs_1_1gnss_1_1_message___n_m_e_a___g_g_a_1_1content__t.html#a33415dc947663d43015605c41b0f66cb
67  /// http://mrpt.ual.es/reference/devel/gnss__messages__ascii__nmea_8h_source.html
68  switch (gga.fields.fix_quality)
69  {
70  case 0:
71  msg.status.status = -1;
72  break;
73  case 1:
74  msg.status.status = 0;
75  break;
76  case 2:
77  msg.status.status = 2;
78  break;
79  case 3:
80  msg.status.status = 1;
81  break;
82  default:
83  // this is based on literature available on GPS as the number of
84  // types in ROS and MRPT are not same
85  msg.status.status = 0;
86  }
87  // this might be incorrect as there is not matching field in mrpt
88  // message type
89  msg.status.service = 1;
90  }
91  /// position_covariance is not available in mrpt
92  /// position_covariance type is not available in mrpt
93  return true;
94 }
95 } // namespace mrpt::ros1bridge
96 
97 /// NavSatFix ROS message
98 /*
99 uint8 COVARIANCE_TYPE_UNKNOWN=0
100 uint8 COVARIANCE_TYPE_APPROXIMATED=1
101 uint8 COVARIANCE_TYPE_DIAGONAL_KNOWN=2
102 uint8 COVARIANCE_TYPE_KNOWN=3
103 std_msgs/Header header
104 sensor_msgs/NavSatStatus status
105 float64 latitude
106 float64 longitude
107 float64 altitude
108 float64[9] position_covariance
109 uint8 position_covariance_type
110 */
111 
112 /// NavSatStatus ROS message
113 /*
114 int8 STATUS_NO_FIX=-1
115 int8 STATUS_FIX=0
116 int8 STATUS_SBAS_FIX=1
117 int8 STATUS_GBAS_FIX=2
118 uint16 SERVICE_GPS=1
119 uint16 SERVICE_GLONASS=2
120 uint16 SERVICE_COMPASS=4
121 uint16 SERVICE_GALILEO=8
122 int8 status
123 uint16 service
124  */
uint8_t fix_quality
NMEA standard values: 0 = invalid, 1 = GPS fix (SPS), 2 = DGPS fix, 3 = PPS fix, 4 = Real Time Kinema...
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
double altitude_meters
The measured altitude, in meters (A).
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
MSG_CLASS & getMsgByClass()
Returns a reference to the message in the list CObservationGPS::messages of the requested class...
bool toROS(const mrpt::obs::CObservationGPS &obj, const std_msgs::Header &msg_header, sensor_msgs::NavSatFix &msg)
Convert mrpt::obs::CObservationGPS -> sensor_msgs/NavSatFix The user must supply the "msg_header" fie...
Definition: gps.cpp:48
void setMsg(const MSG_CLASS &msg)
Stores a message in the list messages, making a copy of the passed object.
ROS message: http://docs.ros.org/api/sensor_msgs/html/msg/NavSatFix.html MRPT message: https://github...
Definition: gps.h:28
bool hasMsgClass() const
Like hasMsgType() but allows querying for message classes, from any of those derived from mrpt::obs::...
bool fromROS(const sensor_msgs::NavSatFix &msg, mrpt::obs::CObservationGPS &obj)
Convert sensor_msgs/NavSatFix -> mrpt::obs::CObservationGPS.
Definition: gps.cpp:20
content_t fields
Message content, accesible by individual fields.
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: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020