Robotics StackExchange | Archived questions

nmea subscriber

Hello, I am able to subscribe to nmeanavsatdriver 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

Asked by GMGims on 2023-05-12 07:29:48 UTC

Comments

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?)

Asked by Gaurav Gupta on 2023-05-12 07:34:34 UTC

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.

Asked by GMGims on 2023-05-12 07:41:31 UTC

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.

Asked by Mike Scheutzow on 2023-05-13 07:40:36 UTC

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
    return

This is just the essential of the code

Asked by GMGims on 2023-05-13 19:27:44 UTC

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

Asked by Mike Scheutzow on 2023-05-14 08:22:51 UTC

Answers