Exemple #1
0
def gps():

    # If using I2C, we'll create an I2C interface to talk to using default pins
    i2c = board.I2C()

    # Create a GPS module instance.
    gps = adafruit_gps.GPS_GtopI2C(i2c, debug=False)  # Use I2C interface

    # Turn on the basic GGA and RMC info (what you typically want)
    gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")

    # Set update rate to once a second (1hz)
    gps.send_command(b"PMTK220,1000")

    rospy.loginfo("Initializing gps publisher")
    gps_pub = rospy.Publisher('/gps', NavSatFix, queue_size=5)
    rospy.loginfo("Publishing NavSatFix at: " + gps_pub.resolved_name)
    rospy.init_node('gps_node')


    rate = rospy.Rate(1) # 50hz
    while not rospy.is_shutdown():
        gps.update()
          
        if gps.has_fix:
            
            nav = NavSatFix()
            nav.header.stamp = rospy.Time.now()
            nav.header.frame_id = 'Adafruit Mini GPS PA1010D'
            nav.latitude = gps.latitude
            nav.longitude = gps.longitude
            nav.altitude = gps.altitude_m

            rospy.loginfo("=" * 40)
            rospy.loginfo("Latitude: {0:.6f} degrees".format(gps.latitude))
            rospy.loginfo("Longitude: {0:.6f} degrees".format(gps.longitude))
            rospy.loginfo("Fix quality: {}".format(gps.fix_quality))
            # Some attributes beyond latitude, longitude and timestamp are optional
            # and might not be present.  Check if they're None before trying to use!
            if gps.satellites is not None:
                rospy.loginfo("# satellites: {}".format(gps.satellites))
            if gps.altitude_m is not None:
                rospy.loginfo("Altitude: {} meters".format(gps.altitude_m))
            if gps.speed_knots is not None:
                rospy.loginfo("Speed: {} knots".format(gps.speed_knots))
            if gps.track_angle_deg is not None:
                rospy.loginfo("Track angle: {} degrees".format(gps.track_angle_deg))
            if gps.horizontal_dilution is not None:
                rospy.loginfo("Horizontal dilution: {}".format(gps.horizontal_dilution))
            if gps.height_geoid is not None:
                rospy.loginfo("Height geoid: {} meters".format(gps.height_geoid))

            gps_pub.publish(nav)
        else:
            # Try again if we don't have a fix yet.
            rospy.loginfo("Waiting for fix...")
        rate.sleep()
# Create a serial connection for the GPS connection using default speed and
# a slightly higher timeout (GPS modules typically update once a second).
# These are the defaults you should use for the GPS FeatherWing.
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
# uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10)

# for a computer, use the pyserial library for uart access
# import serial
# uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=10)

# If using I2C, we'll create an I2C interface to talk to using default pins
i2c = board.I2C()

# Create a GPS module instance.
# gps = adafruit_gps.GPS(uart, debug=False)  # Use UART/pyserial
gps = adafruit_gps.GPS_GtopI2C(i2c, debug=False)  # Use I2C interface

# Initialize the GPS module by changing what data it sends and at what rate.
# These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
# PMTK_220_SET_NMEA_UPDATERATE but you can send anything from here to adjust
# the GPS module behavior:
#   https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf

# Turn on everything (not all of it is parsed!)
gps.send_command(b"PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0")

# Set update rate to once a second (1hz) which is what you typically want.
gps.send_command(b"PMTK220,1000")
# Or decrease to once every two seconds by doubling the millisecond value.
# Be sure to also increase your UART timeout above!
# gps.send_command(b'PMTK220,2000')
Exemple #3
0
# Create a serial connection for the GPS connection using default speed and
# a slightly higher timeout (GPS modules typically update once a second).
# These are the defaults you should use for the GPS FeatherWing.
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
#uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10)

# for a computer, use the pyserial library for uart access
# import serial
# uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=10)

# If using I2C, we'll create an I2C interface to talk to using default pins
i2c = board.I2C()

# Create a GPS module instance.
#gps = adafruit_gps.GPS(uart)  # Use UART/pyserial
gps = adafruit_gps.GPS_GtopI2C(i2c)  # Use I2C interface

# Initialize the GPS module by changing what data it sends and at what rate.
# These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
# PMTK_220_SET_NMEA_UPDATERATE but you can send anything from here to adjust
# the GPS module behavior:
#   https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf

# Turn on the basic GGA and RMC info (what you typically want)
gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")
# Turn on just minimum info (RMC only, location):
# gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Turn off everything:
# gps.send_command(b'PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Tuen on everything (not all of it is parsed!)
# gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
Exemple #4
0
import time
from datetime import datetime
import csv
import time
import board
import busio
import threading
import adafruit_gps

SCL = board.SCL
SDA = board.SDA

i2c = busio.I2C(board.SCL, board.SDA)

gps = adafruit_gps.GPS_GtopI2C(i2c, address=66, debug=False)

gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')

gps.send_command(b'PMTK220,1000')

## definition: creates main CSV file
def createCSV():
  ## initialize file name
  fileName = 'lab2_output.csv'
  ## open unique file
  with open(fileName, 'w', newline='') as file:
    writer = csv.writer(file)

    ## create header
    writer.writerow([
Exemple #5
0
_SENSOR_GPS_BASIC = False
try:
    from dateutil import tz
    from dateutil import parser
    _SENSOR_GPS_BASIC = True
except:
    pass

_SENSOR_GPS_ADAFRUIT_I2C = False
try:
    if _SENSOR_GPS_BASIC:
        import board
        import busio
        import adafruit_gps
        _sensor_adafruit_gps = adafruit_gps.GPS_GtopI2C(busio.I2C(
            board.SCL, board.SDA),
                                                        debug=False)
        _SENSOR_GPS_ADAFRUIT_I2C = True
except:
    pass

_SENSOR_GPS_GPSD = False
try:
    if _SENSOR_GPS_BASIC and not _SENSOR_GPS_ADAFRUIT_I2C:
        from gps3 import gps3
        #device test
        _gps_socket = gps3.GPSDSocket()
        _gps_socket.connect()
        _gps_socket.close()
        _SENSOR_GPS_GPSD = True
except:
#!/usr/bin/env python3
# Based on the gps_simpletest.py example
# from https://github.com/adafruit/Adafruit_CircuitPython_GPS
# that was published by Adafruit.

# Imports all the libraries we use
import time
import board
import busio
import adafruit_gps
import csv

# Sets up the I2C interface for us to use
i2c = board.I2C()
# Create a GPS module instance using the I2C interface
gps = adafruit_gps.GPS_GtopI2C(i2c, debug=False)

# Initialize the GPS module by changing what data it sends and at what rate.
# Turns on the basic GGA and RMC information streams
gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")

# Below are some other commands from the origional
# Adafruit code that you can uncomment for
# different sets of data streams, depending
# on what you need.

# Turn on just minimum info (RMC only, location):
# gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Turn off everything:
# gps.send_command(b'PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Tuen on everything (not all of it is parsed!)
Exemple #7
0
pixels.fill(GREEN)
time.sleep(0.25)
pixels.fill(TEAL)

sox_sensor = adafruit_lsm6ds.LSM6DS33(i2c)
accx, accy, accz = sox_sensor.acceleration
print("X={0:10.2f} Y={1:10.2f} Z={2:10.2f}".format(accx, accy, accz))
print("accelerometers OK.")
pixels.fill(GREEN)
time.sleep(0.25)
pixels.fill(TEAL)

gyrox, gyroy, gyroz = sox_sensor.gyro
print("X={0:10.2f} Y={1:10.2f} Z={2:10.2f}".format(gyrox, gyroy, gyroz))
print("gyrometer OK.")
pixels.fill(GREEN)
time.sleep(0.25)
pixels.fill(TEAL)

gps = adafruit_gps.GPS_GtopI2C(i2c)
print("gps={}".format(gps.readline()))
print("lat={}".format(gps.latitude))
print("lon={}".format(gps.longitude))
print("gps OK.")
pixels.fill(GREEN)
time.sleep(0.25)
pixels.fill(TEAL)

print("DONE!")
pixels.fill((204, 103, 1))