def InitGPS(self): if (not self.GPSInit): self.GPSInit = True #connect the serial link self.phys = garmin.SerialLink(self.db.GetSerialDevice()) #connect to the garmin self.gps = garmin.Garmin(self.phys)
def __init__(self): self.correction_sub_topic = rospy.get_param( "gps_correction_rover/correction_sub_topic", "fix/correction") self.pub_topic = rospy.get_param("gps_correction_rover/pub_topic", "fix") self.pub_rate = rospy.get_param("gps_correction_rover/pub_rate", 1.0) dev_path = rospy.get_param("gps_correction_rover/dev_path", "/dev/sensors/garmin_gps") # Create a 'physical layer' connection using serial port phys = garmin.SerialLink(dev_path) # Create a Garmin object using this connection self.gps = garmin.Garmin(phys) # Turn on Position Velocity Time self.gps.pvtOn() rospy.Subscriber(self.correction_sub_topic, GpsCorrection, self.correct_fix) self._pub_fix = rospy.Publisher(self.pub_topic, NavSatFix, queue_size=1) self.fix = NavSatFix() rate = rospy.Rate(self.pub_rate) while not rospy.is_shutdown(): pass
def __init__(self): #Ros Parameters self.pub_topic = rospy.get_param("gps_correction_base/pub_topic", "fix/correction") self.base_lat = rospy.get_param("gps_correction_base/base_lat", 30.385178399728332) self.base_lon = rospy.get_param("gps_correction_base/base_long", -97.72850900888446) self.base_alt = rospy.get_param("gps_correction_base/base_alt", 243.0) self.pub_rate = rospy.get_param("gps_correction_base/pub_rate", 1.0) dev_path = rospy.get_param("gps_correction_base/dev_path", "/dev/sensors/garmin_gps") # Create a 'physical layer' connection using serial port phys = garmin.SerialLink(dev_path) # Create a Garmin object using this connection gps = garmin.Garmin(phys) # Turn on Position Velocity Time gps.pvtOn() # Publisher and Msgs self._pub_correction = rospy.Publisher(self.pub_topic, GpsCorrection, queue_size=1) self.current_correction = GpsCorrection() rate = rospy.Rate(self.pub_rate) while not rospy.is_shutdown(): data = gps.getPvt() lat = data.rlat * 180 / math.pi lon = data.rlon * 180 / math.pi # Correction applied and published self.current_correction.lat = lat - self.base_lat self.current_correction.lon = lon - self.base_lon self.current_correction.alt = data.alt - self.base_alt self.current_correction.tow = data.tow self._pub_correction.publish(self.current_correction) # getPvt is called again and not used because apparently the data is in a different format when called an even number of times. The next call will provide data I can currently understand. gps.getPvt() rate.sleep()
#! /usr/bin/env python import sys, os, math from time import sleep sys.path.append( os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/pygarmin") import garmin # Create a 'physical layer' connection using serial port phys = garmin.SerialLink("/dev/sensors/garmin_gps") # Create a Garmin object using this connection gps = garmin.Garmin(phys) # Turn on Position Velocity Time gps.pvtOn() sys.stdout.write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") while True: data = gps.getPvt() sys.stdout.write( "\033[F\033[F\033[F\033[F\033[F\033[F\033[F\033[F\033[F\033[F\033[F\033[F\033[F\033[F" ) sys.stdout.write("Fix: " + str(data.fix)) sys.stdout.write("\nAlt: " + str(data.alt)) sys.stdout.write("\nLat: " + str(data.rlat * 180 / math.pi)) sys.stdout.write("\nLon: " + str(data.rlon * 180 / math.pi)) sys.stdout.write("\n...........")
def main(): if os.name == 'nt': serialDevice = 0 phys = Win32SerialLink(serialDevice) else: serialDevice = "/dev/ttyS0" if sys.platform[:-1] == "freebsd": serialDevice = "/dev/cuaa0" # For FreeBsd phys = garmin.SerialLink(serialDevice) # Don't forget to convert between different OS # Windows text files record separator : \r\n # Unix text files record separator \n # Use the right tools to convert them # nawk 'BEGIN {RS = "\r\n";ORS = "" } {print $0}' oziewayp1.wpt > oziewayp1.stripped.wpt gps = garmin.Garmin(phys) gps.wptLink.abortTransfer() # Code for OziExplorer # Get info from GPS and store into OziExplorer if 0: ozie = OziExplorer(gps) print "Check the code:" print "---------------" print "Get the waypoint(s) and save them to the file: ozie.wpt" ozie.getWaypoints("ozie.wpt") print "Get the route(s) and save them to the file: ozie.rte" ozie.getRoutes("ozie.rte") print "Get the track(s) and save them to *.plt files" ozie.getTracks() # Sent OziExplorer to your GPS, change your path first !! if 0: ozie.putWaypoints("/path/to/ozie.wpt") ozie.putRoutes("/path/to/ozie.rte") ozie.putTracks("/path/to/ozie.plt") # Code for GPX # Get info from GPS and store into gpx format if 0: print "Check the code:" print "---------------" file = open('pygarmin.gpx','w') gpx = Gpx(gps) # Init some values gpx.getStart(file) print "Get the waypoint(s) and append to pygarmin.gpx" gpx.getWaypoints() print "Get the route(s) and append to pygarmin.gpx" gpx.getRoutes() print "Get the track(s) and append to pygarmin.gpx" gpx.getTracks() # Write "</gps>" to the file gpx.getClose() file.close() print "Everything is saved to pygarmin.gpx" # Sens gpx format to your GPS if 0: print "Check the code:" print "---------------" gpx = Gpx(gps) print "Send waypoints from pygarmin.gpx to your GPS" gpx.putWaypoints("pygarmin.gpx") print "Send routes from pygarmin.gpx to your GPS" gpx.putRoutes("pygarmin.gpx") print "Send tracks from pygarmin.gpx to your GPS" gpx.putTracks("pygarmin.gpx")