This function is to obtain longitude, latitude and altitude data by reading GPS module data and parsing GPS data through the terminal.
terminal input:
roslaunch nmea_navsat_driver nmea_serial_driver.launch
Then we look at the topic data, the terminal input:
xxxxxxxxxx
rostopic list
Regarding the data on these topics of GPS, here is an explanation.
topic | type | Description |
---|---|---|
/extend_fix | gps_common/GPSFix | GPSFix messages contain GPS satellite status and positioning information |
/fix | sensor_msgs/NavSatFix | GPS location information |
/time_reference | sensor_msgs/TimeReferencd | GPS time information |
/vel | geometry_msgs/TwistStamped | GPS speed information |
For each topic message type, please refer to the official website URL,
gps_common/GPSFix Documentation (ros.org)
sensor_msgs/NavSatFix Documentation (ros.org)
sensor_msgs/TimeReference Documentation (ros.org)
geometry_msgs/TwistStamped Documentation (ros.org)
We can print out these topic messages on the terminal, and what we get is the GPS data. Take printing /fix as an example, the terminal input
xxxxxxxxxx
rostopic echo /fix
The terminal will print out the following data,
Among them, latitude, longitude, altitude represent latitude, longitude and altitude respectively.
terminal runs,
xxxxxxxxxx
roslaunch nmea_navsat_driver nmea_serial_driver.launch
rosrun nmea_navsat_driver read_lat_long.py
The data printed by the terminal is the latitude, longitude and altitude of the current GPS module, look at the source code, read_lat_long.py
x#! /usr/bin/env python
# -*- coding: utf-8 -*-
import rospy
from sensor_msgs.msg import NavSatFix
def GPSCallback(msg):
rospy.loginfo("latitude:%0.6f, longitude:%0.6f,altitude:%0.6f", msg.latitude, msg.latitude,msg.altitude)
def GPS_subscriber():
rospy.init_node('GPS_subscriber', anonymous=True)# ROS节点初始化
rospy.Subscriber("/fix", NavSatFix, GPSCallback)
rospy.spin()# 循环等待回调函数
if __name__ == '__main__':
GPS_subscriber()
The program subscribes to the data of the /fix topic, then parses it in the callback function, and finally prints it to the terminal.