Commit d3c9a7c6 authored by liyuanhong's avatar liyuanhong

增加了方向角随GPS轨迹自动变化的功能

parent 0ab2f500
......@@ -6,6 +6,7 @@
import binascii
import datetime
import json
import math
import os
import random
import threading
......@@ -39,6 +40,7 @@ class AutoCarService():
self.sn = 1 #消息流水号
self.oilExpend = 10 #设置汽车每升能跑多少公里
self.carSpeed = 60 #设置车速度
self.directAngle = 59 #定义默认方向角
# 定义要发送的obd数据
self.OBDdata = {"fireStatus":1,"ACCStatus":0,"engineSpeed":300,"speed":0,"meterMileage":6000,"totailMileage":600,"totalOilExpen":30,"totalRunTime":10}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
......@@ -323,6 +325,7 @@ class AutoCarService():
gpsObj = GPSReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsObj.setLatitude(latitude)
gpsObj.setLongitude(longtitude)
gpsObj.setDirectionAngle(self.getDirAngle())
timeS = int(time.time()) - 8 * 3600
timeArray = time.localtime(timeS)
UTCTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
......@@ -335,6 +338,7 @@ class AutoCarService():
gpsObj = GPSReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsObj.setLatitude(latitude)
gpsObj.setLongitude(longtitude)
gpsObj.setDirectionAngle(self.getDirAngle())
timeS = int(time.time()) - 8 * 3600
timeArray = time.localtime(timeS)
UTCTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
......@@ -433,6 +437,32 @@ class AutoCarService():
with open(path, "w", encoding='utf-8') as fi:
fi.write(data)
###########################################################
# 获取方向角
###########################################################
def getDirAngle(self):
dire = self.directAngle
if self.gpsLineIndex == 0:
return int(self.directAngle)
lngCut = (float(self.gpsLine[self.gpsLineIndex]["lng"]) - float(self.gpsLine[self.gpsLineIndex - 1]["lng"])) * 1000000
latCut = (float(self.gpsLine[self.gpsLineIndex]["lat"]) - float(self.gpsLine[self.gpsLineIndex - 1]["lat"])) * 1000000
if latCut == 0: # 除数维度不能为0
latCut = 1
if lngCut == 0 or latCut == 0:
return int(self.directAngle)
val = lngCut / latCut
dire = math.atan2(1, val) * 180 / math.pi
if lngCut > 0 and latCut > 0:
dire = 90 - dire
if lngCut < 0 and latCut > 0:
dire = 270 + 180 - dire
elif latCut < 0 and lngCut > 0:
dire = 270 - dire
elif lngCut < 0 and latCut < 0:
dire = 180 + 90 - dire
self.directAngle = dire
return int(dire)
#临时定义的一个测试函数
def testOpenfile(self):
with open("data/protocolTools/carData/" + self.carId + ".json", "r", encoding="utf-8") as fi:
......
This diff is collapsed.
......@@ -11,7 +11,7 @@ def startSimulaterService():
autoCarObj.setSendDur(1) # 设置发送消息的间隔时间
autoCarObj.setTimeout(30) # 设置socket超时时间
autoCarObj.setChangeGPSLineTime(1 * 2 * 60) # 设置跑完一条轨迹后,进入下一条轨迹的时间(请设置至少大于4分钟的时间)
autoCarObj.setServiceTime(1 * 4 * 60) # 设置整个服务的持续时间
autoCarObj.setServiceTime(1 * 5 * 60) # 设置整个服务的持续时间
autoCarObj.setOilExpend(10) # 设置1L 油跑多少公里
autoCarObj.setSpeed(80) #设置车速,每小时多少公里
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment