Commit f46ce3c4 authored by liyuanhong's avatar liyuanhong

增加了根据GPs轨迹自动算出方向角的功能

parent a35b1949
{"time": {"dateTime": "2020-04-22 15:12:03", "date": "2020-04-22", "time": "15:12:03"}, "curDayTravel": {"todayTotalMilleage": 17116, "todayTotalOil": 1556, "todayTotalTime": 778, "theMilleage": 21912, "theOil": 1992, "theTime": 996}, "travelData": {"totalMilleage": 21912, "totalOil": 1992, "totalTime": 996}} {"time": {"dateTime": "2020-04-26 17:03:02", "date": "2020-04-26", "time": "17:03:02"}, "curDayTravel": {"todayTotalMilleage": 14190, "todayTotalOil": 1290, "todayTotalTime": 645, "theMilleage": 36102, "theOil": 3282, "theTime": 1641}, "travelData": {"totalMilleage": 36102, "totalOil": 3282, "totalTime": 1641}}
\ No newline at end of file \ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import binascii import binascii
import datetime import datetime
import json import json
import math
import os import os
import random import random
import threading import threading
...@@ -37,6 +38,7 @@ class AutoCarTimerService(): ...@@ -37,6 +38,7 @@ class AutoCarTimerService():
self.sn = 1 #消息流水号 self.sn = 1 #消息流水号
self.oilExpend = 10 #设置汽车每升能跑多少公里 self.oilExpend = 10 #设置汽车每升能跑多少公里
self.carSpeed = 60 #设置车速度 self.carSpeed = 60 #设置车速度
self.directAngle = 59 #设置默认方向角
# 定义要发送的obd数据 # 定义要发送的obd数据
self.OBDdata = {"fireStatus":1,"ACCStatus":0,"engineSpeed":300,"speed":0,"meterMileage":6000,"totailMileage":600,"totalOilExpen":30,"totalRunTime":10} self.OBDdata = {"fireStatus":1,"ACCStatus":0,"engineSpeed":300,"speed":0,"meterMileage":6000,"totailMileage":600,"totalOilExpen":30,"totalRunTime":10}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算 # 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
...@@ -126,6 +128,7 @@ class AutoCarTimerService(): ...@@ -126,6 +128,7 @@ class AutoCarTimerService():
print(info) print(info)
self.writeToFile("result.txt", info + "\n", 1) self.writeToFile("result.txt", info + "\n", 1)
elif self.gpsLineIndex == len(self.gpsLine): elif self.gpsLineIndex == len(self.gpsLine):
self.gpsLineIndex = self.gpsLineIndex - 1
# self.fireOff() # self.fireOff()
self.stopTravelService() self.stopTravelService()
info = self.getCurTime() + " gps轨迹跑完,自动停止行驶!" info = self.getCurTime() + " gps轨迹跑完,自动停止行驶!"
...@@ -280,6 +283,7 @@ class AutoCarTimerService(): ...@@ -280,6 +283,7 @@ class AutoCarTimerService():
gpsObj = GPSReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn) gpsObj = GPSReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsObj.setLatitude(latitude) gpsObj.setLatitude(latitude)
gpsObj.setLongitude(longtitude) gpsObj.setLongitude(longtitude)
gpsObj.setDirectionAngle(self.getDirAngle())
timeS = int(time.time()) - 8 * 3600 timeS = int(time.time()) - 8 * 3600
timeArray = time.localtime(timeS) timeArray = time.localtime(timeS)
UTCTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) UTCTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
...@@ -292,6 +296,7 @@ class AutoCarTimerService(): ...@@ -292,6 +296,7 @@ class AutoCarTimerService():
gpsObj = GPSReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn) gpsObj = GPSReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsObj.setLatitude(latitude) gpsObj.setLatitude(latitude)
gpsObj.setLongitude(longtitude) gpsObj.setLongitude(longtitude)
gpsObj.setDirectionAngle(self.getDirAngle())
timeS = int(time.time()) - 8 * 3600 timeS = int(time.time()) - 8 * 3600
timeArray = time.localtime(timeS) timeArray = time.localtime(timeS)
UTCTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) UTCTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
...@@ -429,6 +434,32 @@ class AutoCarTimerService(): ...@@ -429,6 +434,32 @@ class AutoCarTimerService():
else: else:
return False return False
###########################################################
# 获取方向角
###########################################################
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)
######################################################## ########################################################
# 启动模拟程序服务 # 启动模拟程序服务
######################################################## ########################################################
......
This diff is collapsed.
...@@ -19,7 +19,7 @@ def startSimulaterService(): ...@@ -19,7 +19,7 @@ def startSimulaterService():
如果想要每天的9点自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=0,second=0 如果想要每天的9点自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=0,second=0
如果想要每天的9点30自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=30,second=0 如果想要每天的9点30自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=30,second=0
''' '''
autoCarObj.startService(year=0,month=0,day=0,hour=0,minute=24,second=0) autoCarObj.startService(year=0,month=0,day=0,hour=0,minute=0,second=1)
if __name__ == "__main__": if __name__ == "__main__":
startSimulaterService() startSimulaterService()
......
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