nmea subscriber

asked 2023-05-12 07:29:48 -0500

GMGims gravatar image

Hello, I am able to subscribe to nmea_navsat_driver using a code similar to this post But I want to store the latitude and the longitude into 2 separate variables. Anyone knows how I can do that? I don’t need the altitude or any other data provided by the driver

edit retag flag offensive close merge delete



Can you elaborate your question a little? nmea_navsat_driver is a package, how can you subscribe to that. Do you mean you have the /fix topic available but somehow want to subscribe and read latitude and longitudes from that in a code? (what code? Python/C++, have you written a subscriber already?)

Gaurav Gupta gravatar image Gaurav Gupta  ( 2023-05-12 07:34:34 -0500 )edit

Sorry, for not clarifying my question. I am using Python, I have the /fix topic. I don’t have access to my code now but my subscriber looks like this: rospy.Subscriber("/fix", Sentence, callback)

I included from nmea_msgs.msg import Sentence at the beginning of the code.

Like you said, my goal is to find a way to read just the latitude and longitude. If you need my full code, I will able to provide it later today when I get my computer. Thank you for your answer.

GMGims gravatar image GMGims  ( 2023-05-12 07:41:31 -0500 )edit

Please edit your post and show us an actual message from your "fix" topic. Format it with the 101010 button.

You setup seems unusual; "fix" is usually a sensor_msgs/NatSatFix message, not a nmea_msgs/Sentence message.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-05-13 07:40:36 -0500 )edit

Mike, thank you very much. I was able to do what I wanted, the problem as you mentioned was that I used the wrong message type. Here is how I did it:

from sensor_msgs.msg import NavSatFix

def __init__(self):
self.sub_gps = rospy.Subscriber("/fix", NavSatFix, self.gps_callback, queue_size=1)

def gps_callback(self, data):
    rospy.loginfo('Latitude: %s', data.latitude)
    rospy.loginfo('Longitude: %s', data.longitude)
    self.latitude_robot = data.latitude
    self.longitude_robot = data.longitude

This is just the essential of the code

GMGims gravatar image GMGims  ( 2023-05-13 19:27:44 -0500 )edit

I suggest you make this comment the answer. Then click the checkmark in the gray circle to the left of the answer.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-05-14 08:22:51 -0500 )edit