Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
"""
Author: chenb@pfw.edu
Date: 4/23/2024
Description:
GPS related functions based on Sparkfun GPS' official examples at
https://qwiic-ublox-gps-py.readthedocs.io/
Warning: interface changed.
"""
from ublox_gps import UbloxGps
import serial
class SparkfunGPS:
def __init__(self, port='/dev/ttyACM0', baudrate=38400, timeout=1):
""" Set series port and boudrate
Init gps communication and coordinates
"""
try:
self.gps = UbloxGps(serial.Serial(port=port, baudrate=baudrate, timeout=timeout))
except (ValueError, IOError) as err:
print("GPS init failed. ", err)
def get_latitude_longitude_heading(self):
""" Set latitude and longitude
Output: [latitude, longitude, heading of motion]
"""
try:
geo = self.gps.geo_coords()
except (ValueError, IOError) as err:
print('GPS geo_coord err: ', err)
return geo.lat, geo.lon, geo.headMot
def get_gps_time(self):
"""
Description: self.gps.date_time() return a structure
gps_time.year, .month, .day, .hour, .min, .sec
"""
try:
gps_time = self.gps.date_time()
print(f"gps_time: {gps_time.hour}:{gps_time.min}:{gps_time.sec}")
# print(f"Valid date:{gps_time.valid.validDate}\nValid Time:{gps_time.valid.validTime}")
except (ValueError, IOError) as err:
print("GPS time error: ", err)
return gps_time
def get_reckoning(self) -> dict:
"""
Get roll, pitch, heading and their accelerations in a dict
"""
try:
veh = self.gps.veh_attitude()
except (ValueError, IOError) as err:
print("GPS Reckoningg Error:", err)
return {'roll': veh.roll, 'pitch': veh.pitch, 'heading': veh.heading, 'roll_acceleration': veh.accRoll, 'pictch_acceleration': veh.accPitch, 'heading_acceleration': veh.accHeading}
def get_stream_NMEA(self):
try:
nmea = self.gps.stream_nmea()
except (ValueError, IOError) as err:
print("GPS steam NMEA error:", err)
return nmea