def receive(devices, fields=None, set_clock_minutes=60): gps = micropyGPS.MicropyGPS(0, 'dd') for device in devices.split(','): if os.path.exists(device): gpsdev = device break print('No gps device: %s' % device) with open(gpsdev, 'r') as f: while True: try: line = f.readline() if len(line) == 0: continue if line[0] != '$': continue for c in line: stat = gps.update(c) if stat is None: continue if fields is None: output(gps) continue if gps.valid is False: fields[GPS] = 0.0 continue else: fields[LATITUDE] = gps.latitude[0] fields[LONGITUDE] = gps.longitude[0] fields[ALTITUDE] = gps.altitude fields[SPEED] = gps.speed[0] fields[COURSE] = gps.course fields[HDOP] = gps.hdop fields[VDOP] = gps.vdop fields[GPS] = 1.0 if gps.date[2] != 0: set_clock(gps, set_clock_minutes) continue except KeyboardInterrupt: sys.exit(1)
import serial import micropyGPS import threading import time import motor gps = micropyGPS.MicropyGPS(9, 'dd') # MicroGPSオブジェクトを生成する。 # 引数はタイムゾーンの時差と出力フォーマット motor = motor.Motor(18, 25, 24, 13, 17, 27) def rungps(): # GPSモジュールを読み、GPSオブジェクトを更新する s = serial.Serial('/dev/serial0', 9600, timeout=10) s.readline() # 最初の1行は中途半端なデーターが読めることがあるので、捨てる while True: sentence = s.readline().decode('utf-8') # GPSデーターを読み、文字列に変換する if sentence[0] != '$': # 先頭が'$'でなければ捨てる continue for x in sentence: # 読んだ文字列を解析してGPSオブジェクトにデーターを追加、更新する gps.update(x) def get_gps(): if gps.clean_sentences > 20: return (gps.latitude[0], gps.longitude[0]) else: return None def init(): gpsthread = threading.Thread(target=rungps, args=()) # 上の関数を実行するスレッドを生成
from machine import UART import micropyGPS import utime, gc, _thread from m5stack import lcd gps_s = UART(2, tx=17, rx=16, baudrate=9600, timeout=200, buffer_size=256, lineend='\r\n') gps = micropyGPS.MicropyGPS(9, 'dd') def GPSparse(): n = 0 tm_last = 0 while True: utime.sleep_ms(100) len = gps_s.any() if len>0: b = gps_s.read(len) for x in b: if 10 <= x <= 126: stat = gps.update(chr(x)) if stat: tm = gps.timestamp tm_now = (tm[0] * 3600) + (tm[1] * 60) + int(tm[2]) if (tm_now - tm_last) >= 10: n += 1 tm_last = tm_now lcd.clear() lcd.print("Lat: %.8f %s" % (gps.latitude[0], gps.latitude[1]), 10, 40) lcd.print("Lng: %.8f %s" % (gps.longitude[0], gps.longitude[1]), 10, 80) if (n % 10) == 0: print("Mem free:", gc.mem_free()) gc.collect()
def __init__(self): self.mgps = micropyGPS.MicropyGPS(9,'dd') self.Time = 0 self.Lat = 0 self.Lon = 0
import dc_motor import bno055 as bno import micropyGPS import pyproj import csv import serial import threading import time import numpy as np #目標の緯度,経度 goal_la = 34.72542167 #latitude goal_lo = 137.71619667 #longitude #インスタンス宣言 gps = micropyGPS.MicropyGPS(9, 'dd') #micropyGPSのインスタンス grs80 = pyproj.Geod(ellps='GRS80') #GRS80楕円体 pyprojのインスタンス #モーター制御初期化 dc_motor.setup() #swichPULLUP->fall なんかの割り込み #GPIO.setmode(GPIO.BCM) #GPIO.setup(18,GPIO.IN,pull_up_down=GPIO.PUD_UP) #GPIO.wait_for_edge(18, GPIO.FALLING) #print('OK') #画像でコーン検知する関数は終わりでTrueを無いときFalse #PID def PID(Kp,Ki,Kd,error,pre_error,sum_error):#最後逆転してるの注意な u=error*Kp+sum_error*Ki+(error-pre_error)*Kd #操作量u,順にpid pre_error=error#前回偏差
import serial import micropyGPS import threading import time time_zone = 9 O_format = 'dd' gps = micropyGPS.MicropyGPS(time_zone, O_format) def rungps(): s = serial.Serial('/dev/serial0', 9600, timeout=10) s.readline() while True: sentence = s.readline().decode('utf-8') if sentence[0] != '$': continue for x in sentence: gps.update(x) gpsthread = threading.Thread(target=rungps, daemon=True) gpsthread.start() while True: if gps.clean_sentences > 20: h = gps.timestamp[0] if gps.timestamp[0] < 24 else gps.timestamp[0] - 24 print('%2d:%02d:%04.1f' % (h, gps.timestamp[1], gps.timestamp[2])) print('緯度経度: %2.8f, %2.8f\n' % (gps.latitude[0], gps.longitude[0])) time.sleep(3.0)
def __init__(self, time_zone=9, O_format='dd'): self.gps = micropyGPS.MicropyGPS(time_zone, O_format)
# Convert NMEA 0183 powered by micropyGPS # Convert .l16 log files exported from SeaPath by H.Otsuka # 19 Oct 2020 import sys import micropyGPS import pandas as pd import pgeotools as pg #gps = micropyGPS.MicropyGPS(9, 'dd') # JST gps = micropyGPS.MicropyGPS(0, 'dd') # UTC l16 = pd.DataFrame(columns=['year','month','day','hour','minute','seconds','lat','lon'], index=[0,1,2,3,4,5]) sec_cache = 0 def nmearead(sentence): for x in sentence: # 読んだ文字列を解析してGPSオブジェクトにデーターを追加、更新する gps.update(x) h = gps.timestamp[0] if gps.timestamp[0] < 24 else gps.timestamp[0] - 24 year, month, day = gps.date[2], gps.date[1], gps.date[0] hour, minute, seconds = h, gps.timestamp[1], gps.timestamp[2] lon_now, lat_now = gps.longitude[0], gps.latitude[0] return year, month, day, hour, minute, seconds, lat_now, lon_now def l16read(sentence, l16): year, month, day, hour, minute, seconds, lat_now, lon_now = 0,0,0,0,0,0,0,0 londms = [0]*3
import os import threading import time import serial import micropyGPS from output_csv import write_position gps = micropyGPS.MicropyGPS() # 出力のフォーマットは度数とする gps.coord_format = 'dd' def run_gps(): """ GPSモジュールを読み、GPSオブジェクトを更新する :return: None """ s = serial.Serial('/dev/serial0', 9600, timeout=10) # 最初の1行は中途半端なデーターが読めることがあるので、捨てる s.readline() while True: # GPSデーターを読み、文字列に変換する sentence = s.readline().decode('utf-8') # 先頭が'$'でなければ捨てる if sentence[0] != '$':
import time import csv import datetime as dt import os import serial import threading import micropyGPS as mpG PATH = ['/home','/pi','/GPS_DATAs','/GPS_DATA_',[],'.csv'] #path_day = 0 day = 0 gps = mpG.MicropyGPS(9,'dd') def rungps(): s = serial.Serial('/dev/serial0',9600,timeout=10) s.readline() while(1): sentence = s.readline().decode('utf-8') if sentence[0] != '$': continue for x in sentence: gps.update(x) gpsthread = threading.Thread(target=rungps,args=()) gpsthread.daemon = True gpsthread.start() def create_path(PATH): path = ''
import picamera.array import cv2 as cv ##----------------------------------------------------------------初期設定 TargetPosition = [0, 0, 0] #お客さんの位置(緯度,経度、海抜(多分使わん)) GPStimeout = 10 #gpsのタイムアウトの時間の設定(秒 step = "gps" #"gps"でgps制御、"face"で顔位置制御から始まる SETresolution = [512, 512] #解像度 delaytime = 0.1 #周波数=10Hz stopsize = 500 #十分近づいたと判断する顔の対角線の長さ kp = 0.05 kd = 0.05 ##------------------------------------------------------------処理のために格納する変数の宣言 faceposition = [0, 0, 0] position = [0, 0, 0] ##-----------------------------------------------------------------------GPS gps = micropyGPS.MicropyGPS(9, 'dd') #timezone:9 , timeformat:dd def rungps(): s = serial.Serial('/dev/serial0', 9600, timeout=10) s.readline() while True: sentence = s.readline().decode('utf-8') #シリアルで撮ったバイトがたのデータを文字列に変換 if sentence != "": #データが格納されてないことによるインデックスエラを防ぐ、空でないことを確認 if sentence[0] != '$': #開始の表示を捨てる continue for x in sentence: gps.update(x) gpsthread = threading.Thread(target=rungps, args=())
def main(): point = [] speed = [] gps = micropyGPS.MicropyGPS(9, 'dd') assert gps.start_logging('test.txt', mode="new") # assert gps.write_log('micropyGPS test log\n') # f = open('FILE210312-223327-000860-N.NMEA', 'r') f = open(sys.argv[1], 'r') print(sys.argv[1]) while True: data = f.readline() # EofCheck if not data: break if data.startswith('<EOF/>') == True: break #print (data) #if data.startswith('$GPGSV') == True: for y in data: #$ print(y) gps.update(y) # print('UTC Timestamp:', gps.timestamp) # print( gps.fix_time) # print(gps.latitude_string(), gps.longitude_string()) # print( "[%2.8f, %2.8f]" % (gps.latitude [0], gps.longitude[0])) if gps.latitude[0] != 0 or gps.longitude[0] != 0: point.append([gps.latitude[0], gps.longitude[0]]) speed.append(gps.speed) # print(gps.speed_string('kph')) f.close() assert gps.stop_logging() map = StaticMap(512, 512) # print(point) # print( "map = [%2.8f, %2.8f]" % (point[0][0],point[0][1])) for ii in range(len(point) - 1): hh = speed[ii][2] / max_speed sv = 0.0 if (hh > 1.0): sv = (hh - 1.0) hh = np.clip(hh, 0.0, 1.0) sv = np.clip(sv, 0.0, 1.0) sv = 1.0 - sv hh2 = (2.0 / 3.0) * (1 - hh) print(speed[ii], hh2) color_hsv = (hh2, sv, sv) color_rgb = mcolors.hsv_to_rgb(color_hsv) map.add_line( Line(((point[ii][1], point[ii][0]), (point[ii + 1][1], point[ii + 1][0])), mcolors.to_hex(color_rgb), 3)) p2 = np.mean(point, axis=0) marker_outline = CircleMarker((point[0][1], point[0][0]), 'white', 18) marker = CircleMarker((point[0][1], point[0][0]), '#FF3600', 12) map.add_marker(marker_outline) map.add_marker(marker) end_num = len(point) - 1 marker_outline = CircleMarker((point[end_num][1], point[end_num][0]), 'white', 18) marker = CircleMarker((point[end_num][1], point[end_num][0]), '#0036FF', 12) map.add_marker(marker_outline) map.add_marker(marker) # map level p_min = np.min(point, axis=0) p_max = np.max(point, axis=0) # 2点間から距離を取得 rho = cal_rho(p_min[1], p_min[0], p_max[1], p_max[0]) print(rho) print(p2) p_sub = p_max - p_min print(p_sub) lev_sum = rho print(lev_sum) # 最大1分間に5km(時速300km)で計算 lev = int(((5.0 - lev_sum) * (7.5 / 5.0)) + 9) print(lev) image = map.render(zoom=lev, center=[p2[1], p2[0]]) image.save(sys.argv[1] + '_map.png')