当前位置: 首页 > news >正文

【Python】WHEELTEC GPS G60主代码读取传感器数据代码(Windows系统)

【Python】WHEELTEC惯导IMU主代码读取传感器数据代码
Windows系统,直接输入串口号即可
读取设备的移动速度(km/h)
注:该GPS传感器需要在室外条件运行,室内可能接收不到信号。

# coding: utf-8
# last modified:20231031
import time
import serial
import reutctime = ''
lat = ''
ulat = ''
lon = ''
ulon = ''
numSv = ''
msl = ''
cogt = ''
cogm = ''
sog = ''
kph = ''
gps_t = 0#ser = serial.Serial("/dev/wheeltec_gps", 9600)
ser = serial.Serial("COM4", 9600)#Windows系统直接输入串口号即可if ser.isOpen():print("GPS Serial Opened! Baudrate=9600")
else:print("GPS Serial Open Failed!")def Convert_to_degrees(in_data1, in_data2):len_data1 = len(in_data1)str_data2 = "%05d" % int(in_data2)temp_data = int(in_data1)symbol = 1if temp_data < 0:symbol = -1degree = int(temp_data / 100.0)str_decimal = str(in_data1[len_data1-2]) + str(in_data1[len_data1-1]) + str(str_data2)f_degree = int(str_decimal)/60.0/100000.0# print("f_degree:", f_degree)if symbol > 0:result = degree + f_degreeelse:result = degree - f_degreereturn resultdef GPS_read():global utctimeglobal latglobal ulatglobal longlobal ulonglobal numSvglobal mslglobal cogtglobal cogmglobal sogglobal kphglobal gps_tif ser.inWaiting():if ser.read(1) == b'G':time.sleep(.05) if ser.inWaiting():if ser.read(1) == b'N':if ser.inWaiting():choice = ser.read(1)if choice == b'G':if ser.inWaiting():if ser.read(1) == b'G':if ser.inWaiting():if ser.read(1) == b'A':#utctime = ser.read(7)GGA = ser.read(70)GGA_g = re.findall(r"\w+(?=,)|(?<=,)\w+", str(GGA))# print(GGA_g)if len(GGA_g) < 13:print("GPS no found")gps_t = 0return 0else:utctime = GGA_g[0]# lat = GGA_g[2][0]+GGA_g[2][1]+'°'+GGA_g[2][2]+GGA_g[2][3]+'.'+GGA_g[3]+'\''lat = "%.8f" % Convert_to_degrees(str(GGA_g[2]), str(GGA_g[3]))ulat = GGA_g[4]# lon = GGA_g[5][0]+GGA_g[5][1]+GGA_g[5][2]+'°'+GGA_g[5][3]+GGA_g[5][4]+'.'+GGA_g[6]+'\''lon = "%.8f" % Convert_to_degrees(str(GGA_g[5]), str(GGA_g[6]))ulon = GGA_g[7]numSv = GGA_g[9]msl = GGA_g[12]+'.'+GGA_g[13]+GGA_g[14]#print(GGA_g)gps_t = 1return 1elif choice == b'V':if ser.inWaiting():if ser.read(1) == b'T':if ser.inWaiting():if ser.read(1) == b'G':if gps_t == 1:VTG = ser.read(40)VTG_g = re.findall(r"\w+(?=,)|(?<=,)\w+", str(VTG))cogt = VTG_g[0]+'.'+VTG_g[1]+'T'if VTG_g[3] == 'M':cogm = '0.00'sog = VTG_g[4]+'.'+VTG_g[5]kph = VTG_g[7]+'.'+VTG_g[8]elif VTG_g[3] != 'M':cogm = VTG_g[3]+'.'+VTG_g[4]sog = VTG_g[6]+'.'+VTG_g[7]kph = VTG_g[9]+'.'+VTG_g[10]#print(kph)
def GPS_test():try:while True:if GPS_read():'''print("*********************")print('UTC Time:'+utctime)print('Latitude:'+lat+ulat)print('Longitude:'+lon+ulon)print('Number of satellites:'+numSv)print('Altitude:'+msl)print('True north heading:'+cogt+'°')print('Magnetic north heading:'+cogm+'°')print('Ground speed:'+sog+'Kn')print('Ground speed:'+kph+'Km/h')print("*********************")'''return(kph)except KeyboardInterrupt:ser.close()print("GPS serial Close!")if __name__ == "__main__":t1=time.time()for i in range(0,10):kph=GPS_test()print('Ground speed:'+kph+'Km/h')t2=time.time()print((t2-t1)/10)ser.close()
http://www.lryc.cn/news/356195.html

相关文章:

  • 【Vue】Vue2与Vue3的区别
  • 马斯克的 xAI 帝国!60亿融资背后的超级布局?
  • 互联网医院开发:引领智慧医疗新时代
  • 民国漫画杂志《时代漫画》第18期.PDF
  • java.lang.NumberFormatException: For input string:
  • 从零开始搭建Springboot项目脚手架4:保存操作日志
  • 持续总结中!2024年面试必问 20 道 Rocket MQ面试题(一)
  • 生成式AI的GPU网络技术架构
  • 旅游卡在哪里拿货?千益畅行旅游卡源头
  • 代码随想录算法训练营第四十一天| 509. 斐波那契数 、70. 爬楼梯 、746. 使用最小花费爬楼梯
  • Ribbon负载均衡(自己总结的)
  • Leetcode 力扣92. 反转链表 II (抖音号:708231408)
  • OSI七层模型和TCP/IP四层模型的区别
  • 在虚拟机上安装MySQL和Hive
  • Vue 2 和 Vue 3 中同步和异步
  • ssm150旅游网站的设计与实现+jsp
  • 【加密与解密(第四版)】第十四章笔记
  • 鸿蒙系统和安卓系统通过termux搭建Linux系统—Centos
  • 数据结构的希尔排序(c语言版)
  • 使用Node.js搭建服务器
  • 网络编程——多进程的服务器
  • 代码随想录算法训练营第二十一天| 530. 二叉搜索树的最小绝对差、501. 二叉搜索树中的众数、236. 二叉树的最近公共祖先
  • 【面试】JDK和JVM是什么关系?
  • 旺店通与金蝶云星空 就应该这样集成打通
  • linux开发之设备树
  • DQL(数据查询)
  • LeetCode 2951.找出峰值:模拟(遍历)
  • 软考结束。有什么要说的
  • Matlab读取Swarm球谐系数,并绘制EWH全球格网图(存在疑问)
  • Vue集成Iframe