Created
September 8, 2017 21:38
-
-
Save amogh112/d7aabe54e267675b8682d31fadb16445 to your computer and use it in GitHub Desktop.
Sensor messages- GPS to NavSatFix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import rospy | |
from std_msgs.msg import String | |
from sensor_msgs.msg import NavSatFix | |
class publishGPS(object): | |
def __init__(self): | |
rospy.loginfo("Initialising GPS publishing") | |
self.gps_sub=rospy.Subscriber('/GPS_talker_1',String, self.callback, queue_size=1) | |
self.lastMsg=None | |
self.gps_pub=rospy.Publisher('/gps_new', NavSatFix, queue_size=1) | |
rospy.sleep(8) | |
rospy.loginfo("initialised") | |
def callback(self, data): | |
self.lastMsg=data | |
def do_work(self): | |
self.splitStrings= str(self.lastMsg).split(",") | |
gpsmsg=NavSatFix() | |
gpsmsg.header.stamp = rospy.Time.now() | |
gpsmsg.header.frame_id = "gps" | |
rospy.loginfo(self.splitStrings[1]) | |
gpsmsg.latitude=float(self.splitStrings[1][4:]) | |
gpsmsg.longitude=float(self.splitStrings[2][5:-5]) | |
self.gps_pub.publish(gpsmsg) | |
def run(self): | |
r=rospy.Rate(1) | |
while not rospy.is_shutdown(): | |
self.do_work() | |
r.sleep() | |
if __name__=='__main__': | |
rospy.init_node('pubgps') | |
obj=publishGPS() | |
obj.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Publishing a new custom message