Compare commits
14 Commits
cec09d6bcb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 79986fc85f | |||
| 2d42f090dd | |||
| c42864e46d | |||
| d0196b4a31 | |||
| eb76c18efc | |||
| ec71dd1094 | |||
| 61160fcd70 | |||
| cb8c861407 | |||
| 81e704cf7a | |||
| 84da201ed8 | |||
| 237708e155 | |||
| 9ec76323d7 | |||
| 5d676828d4 | |||
| e55927dbe2 |
117
GAME_METHODS/FORZA_METHODS.py
Normal file
117
GAME_METHODS/FORZA_METHODS.py
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
import struct
|
||||||
|
FORZA_DATA_FORMAT = '<iIfffffffffffffffffffffffffffiiiiffffffffffffffffffffiiiiifffffffffffffffffHBBBBBBbbbffffi'
|
||||||
|
|
||||||
|
|
||||||
|
def unpackData(unpackedData):
|
||||||
|
carData = {
|
||||||
|
"IsRaceOn":unpackedData[0], #// = 1 when race is on. = 0 when in menus/race stopped …
|
||||||
|
#// Can overflow to 0 eventually
|
||||||
|
"TimestampMS": unpackedData[1],
|
||||||
|
"EngineMaxRpm": unpackedData[2],
|
||||||
|
"EngineIdleRpm": unpackedData[3],
|
||||||
|
"CurrentEngineRpm": unpackedData[4],
|
||||||
|
#// In the car's local space; X = right, Y = up, Z = forward
|
||||||
|
"AccelerationX": unpackedData[5],
|
||||||
|
"AccelerationY": unpackedData[6],
|
||||||
|
"AccelerationZ": unpackedData[7],
|
||||||
|
#// In the car's local space; X = right, Y = up, Z = forward
|
||||||
|
"VelocityX": unpackedData[8],
|
||||||
|
"VelocityY": unpackedData[9],
|
||||||
|
"VelocityZ": unpackedData[10],
|
||||||
|
#// In the car's local space; X = pitch, Y = yaw, Z = roll
|
||||||
|
"AngularVelocityX": unpackedData[11],
|
||||||
|
"AngularVelocityY": unpackedData[12],
|
||||||
|
"AngularVelocityZ": unpackedData[13],
|
||||||
|
"Yaw": unpackedData[14],
|
||||||
|
"Pitch": unpackedData[15],
|
||||||
|
"Roll": unpackedData[16],
|
||||||
|
#// Suspension travel normalized: 0.0f = max stretch; 1.0 = max compression
|
||||||
|
"NormalizedSuspensionTravelFrontLeft": unpackedData[17],
|
||||||
|
"NormalizedSuspensionTravelFrontRight": unpackedData[18],
|
||||||
|
"NormalizedSuspensionTravelRearLeft": unpackedData[19],
|
||||||
|
"NormalizedSuspensionTravelRearRight": unpackedData[20],
|
||||||
|
#// Tire normalized slip ratio, = 0 means 100% grip and |ratio| > 1.0 means loss of grip.
|
||||||
|
"TireSlipRatioFrontLeft": unpackedData[21],
|
||||||
|
"TireSlipRatioFrontRight": unpackedData[22],
|
||||||
|
"TireSlipRatioRearLeft": unpackedData[23],
|
||||||
|
"TireSlipRatioRearRight": unpackedData[24],
|
||||||
|
#// Wheels rotation speed radians/sec.
|
||||||
|
"WheelRotationSpeedFrontLeft": unpackedData[25],
|
||||||
|
"WheelRotationSpeedFrontRight": unpackedData[26],
|
||||||
|
"WheelRotationSpeedRearLeft": unpackedData[27],
|
||||||
|
"WheelRotationSpeedRearRight": unpackedData[28],
|
||||||
|
#// = 1 when wheel is on rumble strip, = 0 when off.
|
||||||
|
"WheelOnRumbleStripFrontLeft": unpackedData[29],
|
||||||
|
"WheelOnRumbleStripFrontRight": unpackedData[30],
|
||||||
|
"WheelOnRumbleStripRearLeft": unpackedData[31],
|
||||||
|
"WheelOnRumbleStripRearRight": unpackedData[32],
|
||||||
|
#// = from 0 to 1, where 1 is the deepest puddle
|
||||||
|
"WheelInPuddleDepthFrontLeft": unpackedData[33],
|
||||||
|
"WheelInPuddleDepthFrontRight": unpackedData[34],
|
||||||
|
"WheelInPuddleDepthRearLeft": unpackedData[35],
|
||||||
|
"WheelInPuddleDepthRearRight": unpackedData[36],
|
||||||
|
#// Non-dimensional surface rumble values passed to controller force feedback
|
||||||
|
"SurfaceRumbleFrontLeft": unpackedData[37],
|
||||||
|
"SurfaceRumbleFrontRight": unpackedData[38],
|
||||||
|
"SurfaceRumbleRearLeft": unpackedData[39],
|
||||||
|
"SurfaceRumbleRearRight": unpackedData[40],
|
||||||
|
#// Tire normalized slip angle, = 0 means 100% grip and |angle| > 1.0 means loss of grip.
|
||||||
|
"TireSlipAngleFrontLeft": unpackedData[41],
|
||||||
|
"TireSlipAngleFrontRight": unpackedData[42],
|
||||||
|
"TireSlipAngleRearLeft": unpackedData[43],
|
||||||
|
"TireSlipAngleRearRight": unpackedData[44],
|
||||||
|
#// Tire normalized combined slip, = 0 means 100% grip and |slip| > 1.0 means loss of grip.
|
||||||
|
"TireCombinedSlipFrontLeft": unpackedData[45],
|
||||||
|
"TireCombinedSlipFrontRight": unpackedData[46],
|
||||||
|
"TireCombinedSlipRearLeft": unpackedData[47],
|
||||||
|
"TireCombinedSlipRearRight": unpackedData[48],
|
||||||
|
#// Actual suspension travel in meters
|
||||||
|
"SuspensionTravelMetersFrontLeft": unpackedData[49],
|
||||||
|
"SuspensionTravelMetersFrontRight": unpackedData[50],
|
||||||
|
"SuspensionTravelMetersRearLeft": unpackedData[51],
|
||||||
|
"SuspensionTravelMetersRearRight": unpackedData[52],
|
||||||
|
#// Unique ID of the car make/model
|
||||||
|
"CarOrdinal": unpackedData[53],
|
||||||
|
#// Between 0 (D -- worst cars) and 7 (X class -- best cars) inclusive
|
||||||
|
"CarClass": unpackedData[54],
|
||||||
|
#// Between 100 (worst car) and 999 (best car) inclusive
|
||||||
|
"CarPerformanceIndex": unpackedData[55],
|
||||||
|
#// 0 = FWD, 1 = RWD, 2 = AWD
|
||||||
|
"DrivetrainType": unpackedData[56],
|
||||||
|
#// Number of cylinders in the engine
|
||||||
|
"NumCylinders": unpackedData[57],
|
||||||
|
"PositionX": unpackedData[58],
|
||||||
|
"PositionY": unpackedData[59],
|
||||||
|
"PositionZ": unpackedData[60],
|
||||||
|
"Speed": unpackedData[61],
|
||||||
|
"Power": unpackedData[62],
|
||||||
|
"Torque": unpackedData[63],
|
||||||
|
"TireTempFrontLeft": unpackedData[64],
|
||||||
|
"TireTempFrontRight": unpackedData[65],
|
||||||
|
"TireTempRearLeft": unpackedData[66],
|
||||||
|
"TireTempRearRight": unpackedData[67],
|
||||||
|
"Boost": unpackedData[68],
|
||||||
|
"Fuel": unpackedData[69],
|
||||||
|
"DistanceTraveled": unpackedData[70],
|
||||||
|
"BestLap": unpackedData[71],
|
||||||
|
"LastLap": unpackedData[72],
|
||||||
|
"CurrentLap": unpackedData[73],
|
||||||
|
"CurrentRaceTime": unpackedData[74],
|
||||||
|
"LapNumber": unpackedData[75],
|
||||||
|
"RacePosition": unpackedData[76],
|
||||||
|
"Accel": unpackedData[77],
|
||||||
|
"Brake": unpackedData[78],
|
||||||
|
"Clutch": unpackedData[79],
|
||||||
|
"HandBrake": unpackedData[80],
|
||||||
|
"Gear": unpackedData[81],
|
||||||
|
"Steer": unpackedData[82],
|
||||||
|
"NormalizedDrivingLine": unpackedData[83],
|
||||||
|
"NormalizedAIBrakeDifference": unpackedData[84],
|
||||||
|
"TireWearFrontLeft": unpackedData[85],
|
||||||
|
"TireWearFrontRight": unpackedData[86],
|
||||||
|
"TireWearRearLeft": unpackedData[87],
|
||||||
|
"TireWearRearRight": unpackedData[88],
|
||||||
|
#// ID for track
|
||||||
|
"TrackOrdinal": unpackedData[89]
|
||||||
|
}
|
||||||
|
return carData
|
||||||
@@ -1 +1 @@
|
|||||||
__all__= ["BEAMNG_METHODS"]
|
__all__= ["BEAMNG_METHODS","FORZA_METHODS"]
|
||||||
Binary file not shown.
BIN
GAME_METHODS/__pycache__/BEAMNG_METHODS.cpython-312.pyc
Normal file
BIN
GAME_METHODS/__pycache__/BEAMNG_METHODS.cpython-312.pyc
Normal file
Binary file not shown.
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-311.pyc
Normal file
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-311.pyc
Normal file
Binary file not shown.
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-312.pyc
Normal file
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
GAME_METHODS/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
GAME_METHODS/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
@@ -1,23 +1,128 @@
|
|||||||
|
#please use python 3.11
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import serial
|
import serial
|
||||||
|
import time
|
||||||
|
import platform
|
||||||
|
import sys
|
||||||
|
from enum import Enum
|
||||||
from GAME_METHODS import *
|
from GAME_METHODS import *
|
||||||
##import BEAMNG_FILES as BEAM
|
|
||||||
|
|
||||||
|
##check if python 3.11 is running code and exit if not
|
||||||
|
|
||||||
toPi=serial.Serial('COM5',115200) #connect to arduino
|
if not(sys.version_info[0] == 3 and sys.version_info[1] == 11):
|
||||||
UDP_IP = "127.0.0.1"
|
raise Exception("code must be run in python verion 3.11.\ninput struct for network needs to be changed per python version.")
|
||||||
UDP_PORT = 4444
|
|
||||||
|
|
||||||
|
runningOs = platform.system()
|
||||||
|
|
||||||
|
UDP_IP = "0.0.0.0"
|
||||||
|
BEAMNG_UDP_PORT = 4444
|
||||||
|
FORZA_UDP_PORT= 4843
|
||||||
|
SERIAL_PORT = ""
|
||||||
|
firstRun= True #used to do the headers for csv files
|
||||||
|
|
||||||
|
class GameType(Enum):
|
||||||
|
NONE=0
|
||||||
|
BEAMNG = "BEAMNG"
|
||||||
|
FORZA = "FORZA"
|
||||||
|
|
||||||
|
connectedArduino = False
|
||||||
|
connectedWebSocket = False
|
||||||
|
gameSelected = False
|
||||||
|
portToConnect= 0
|
||||||
|
gameType= GameType.NONE
|
||||||
|
carData = 0
|
||||||
|
csvOut = False
|
||||||
|
|
||||||
|
#Functions <-------------------------------------------------------------------------------------------
|
||||||
|
def csvWriteOut(firstRun,carData,csvFile):
|
||||||
|
if firstRun == True:
|
||||||
|
out=""
|
||||||
|
for im,nm in carData.items():
|
||||||
|
out = out + im + ","
|
||||||
|
csvFile.write(out + "\n")
|
||||||
|
outString=""
|
||||||
|
for itm,num in carData.items():
|
||||||
|
outString = outString + str(num) +","
|
||||||
|
csvFile.write(outString+"\n")
|
||||||
|
|
||||||
|
#code runs from here<-----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if runningOs == 'Windows':
|
||||||
|
print("Windows detacted setting serial port to 'COM5'\n")
|
||||||
|
SERIAL_PORT= 'COM5'
|
||||||
|
elif runningOs == 'Linux':
|
||||||
|
print("Linux detected setting serial port to '/dev/ttyAMC0'\n")
|
||||||
|
SERIAL_PORT = '/dev/ttyACM0'
|
||||||
|
else:
|
||||||
|
print("OS detection failed setting serial port to 'COM5'\n")
|
||||||
|
SERIAL_PORT = 'COM5'
|
||||||
|
|
||||||
|
#select game
|
||||||
|
while gameSelected == False:
|
||||||
|
gameNo = input("1:BEAMNG\n2:FORZA\n\n7:Toggle CSV out ("+str(csvOut)+")\n9:SET SERIAL PORT ("+SERIAL_PORT+")\n")
|
||||||
|
if gameNo == "1":
|
||||||
|
portToConnect = BEAMNG_UDP_PORT
|
||||||
|
gameSelected = True
|
||||||
|
gameType=GameType.BEAMNG
|
||||||
|
print("BeamNG Selected")
|
||||||
|
elif gameNo == "2":
|
||||||
|
portToConnect = FORZA_UDP_PORT
|
||||||
|
gameType=GameType.FORZA
|
||||||
|
gameSelected=True
|
||||||
|
print("Forza Selected")
|
||||||
|
elif gameNo == "7":
|
||||||
|
if csvOut == True:
|
||||||
|
csvOut=False
|
||||||
|
elif csvOut ==False:
|
||||||
|
csvOut =True
|
||||||
|
elif gameNo == "9":
|
||||||
|
SERIAL_PORT = input("set serial port: ")
|
||||||
|
else:
|
||||||
|
print("please select a number from the list")
|
||||||
|
|
||||||
|
#check everything is connected
|
||||||
|
while connectedWebSocket == False:
|
||||||
|
try:
|
||||||
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||||
sock.bind((UDP_IP,UDP_PORT))
|
sock.bind((UDP_IP,portToConnect))
|
||||||
print("waiting for data:\n")
|
connectedWebSocket = True
|
||||||
|
except:
|
||||||
|
print("please check you are able to open the socket on this system\ntired to open port: "+portToConnect)
|
||||||
|
exit()
|
||||||
|
|
||||||
|
while connectedArduino == False:
|
||||||
|
try:
|
||||||
|
toPi=serial.Serial(SERIAL_PORT,115200,timeout=2) #connect to arduino
|
||||||
|
connectedArduino = True
|
||||||
|
except:
|
||||||
|
print("please check connection to arduino and verify the correct serial port")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if csvOut == True:
|
||||||
|
csvFile = open(gameType.value+"_"+str(int(time.time()))+'.csv',"a")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("ready:\n")
|
||||||
while True:
|
while True:
|
||||||
data, addr = sock.recvfrom(1024)
|
data, addr = sock.recvfrom(1024)
|
||||||
|
if gameType == GameType.BEAMNG:
|
||||||
unpackedData = struct.unpack(BEAMNG_METHODS.BEAMNG_DATA_FORMAT,data)
|
unpackedData = struct.unpack(BEAMNG_METHODS.BEAMNG_DATA_FORMAT,data)
|
||||||
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
||||||
kmh=carData["speed"]*3.6
|
kmh=carData["speed"]*3.6
|
||||||
|
if csvOut == True:
|
||||||
|
csvWriteOut(firstRun,carData,csvFile)
|
||||||
|
firstRun=False
|
||||||
|
elif gameType == GameType.FORZA:
|
||||||
|
unpackedData = struct.unpack(FORZA_METHODS.FORZA_DATA_FORMAT,data)
|
||||||
|
carData = FORZA_METHODS.unpackData(unpackedData)
|
||||||
|
kmh = carData["Speed"]*3.6
|
||||||
|
if csvOut == True:
|
||||||
|
csvWriteOut(firstRun,carData,csvFile)
|
||||||
|
firstRun=False
|
||||||
|
try:
|
||||||
toPi.write(str(kmh).encode()+":".encode())
|
toPi.write(str(kmh).encode()+":".encode())
|
||||||
|
except:
|
||||||
|
print("arduino disconnected please check connection\n")
|
||||||
|
|
||||||
|
|||||||
1
createExe.sh
Normal file
1
createExe.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pyinstaller.exe --add-data .\GAME_METHODS\*:.\GAME_METHODS\ --onefile .\OutGaugeInterpreter.py
|
||||||
Reference in New Issue
Block a user