Skip to content

Commit

Permalink
add AMS2 ride height
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekyDeaks committed Apr 13, 2023
1 parent ec11386 commit ab443c6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 9 deletions.
8 changes: 6 additions & 2 deletions stm/ams2/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class AMS2Logger(BaseLogger):
'tyretempflo', 'tyretempfro', # outer temp
'tyretempflc', 'tyretempfrc', # center temp
'tyretempfli', 'tyretempfri', # inner temp
#'wheelslipfl', 'wheelslipfr', 'wheelsliprl', 'wheelsliprr', # wheel slip
'rideheightfl', 'rideheightfr', 'rideheightrl', 'rideheightrr',
'lap', 'laptime',
'racestate' # AMS2 race status
'racestate', # AMS2 race status
]

def __init__(self,
Expand Down Expand Up @@ -106,9 +108,11 @@ def process_packet(self, timestamp, p, lastp):
p.mTyreTempLeft.fl, p.mTyreTempRight.fr, # outer
p.mTyreTempCenter.fl, p.mTyreTempCenter.fr, # centre
p.mTyreTempRight.fl, p.mTyreTempLeft.fr, # inner
#*[s * 2.23693629 for s in p.mTyreSlipSpeed], # wheel slip m/s -> mph
*p.mRideHeight,
p.driver.mCurrentLap,
p.mCurrentTime,
p.mRaceState.value
p.mRaceState.value,
])


31 changes: 24 additions & 7 deletions stm/ams2/shmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from stm.maths import Vector

Wheels = namedtuple("Wheels", ["fl", "fr", "rl", "rr"])
Wings = namedtuple("Wing", ["front", "rear"])

class AMS2GameState(Enum):
EXITED = 0
Expand Down Expand Up @@ -121,13 +122,13 @@ class AMS2SharedMemory:
"3f" # mWorldVelocity
"3f" # mAngularVelocity
"3f" # mLocalAcceleration
"12x" # mWorldAcceleration
"3f" # mWorldAcceleration
"12x" # mExtentsCentre
"16x" # mTyreFlags
"16x" # mTerrain
"16x" # mTyreY
"16x" # mTyreRPS
"16x" # mTyreSlipSpeed
"4f" # mTyreY
"4f" # mTyreRPS
"4f" # mTyreSlipSpeed
"4f" # mTyreTemp
"16x" # mTyreGrip
"16x" # mTyreHeightAboveGround
Expand Down Expand Up @@ -158,7 +159,7 @@ class AMS2SharedMemory:
"4f" # mAirPressure
"4x" # mEngineSpeed
"4x" # mEngineTorque
"8x" # mWings
"2f" # mWings
"4x" # mHandBrake
"256x" # mCurrentSector1Times
"256x" # mCurrentSector2Times
Expand Down Expand Up @@ -191,6 +192,8 @@ class AMS2SharedMemory:
"4f" # mTyreTempLeft
"4f" # mTyreTempCenter
"4f" # mTyreTempRight
"I" # mDrsState,
"4f" # mRideHeight
)

def __init__(self, buf):
Expand Down Expand Up @@ -237,18 +240,25 @@ def __init__(self, buf):
wvx, wvy, wvz, # mWorldVelocity
avx, avy, avz, # mAngularVelocity
lax, lay, laz, # mLocalAcceleration
wax, way, waz, # mWorldAcceleration
tyfl, tyfr, tyrl, tyrr, # mTyreY
trpsfl, trpsfr, trpsrl, trpsrr, # mTyreRPS
tssfl, tssfr, tssrl, tssrr, # mTyreSlipSpeed
ttfl, ttfr, ttrl, ttrr, # mTyreTemp
btfl, btfr, btrl, btrr, # mBrakeTempCelsius
self.mSequenceNumber,
stfl, stfr, strl, sttrr, # mSuspensionTravel
apfl, apfr, aprl, aprr, # mAirPressure,
wf, wr, # mWings
mTranslatedTrackLocation,
mTranslatedTrackVariation,
self.mBrakeBias,
self.mTurboBoostPressure,
ttlfl, ttlfr, ttlrl, ttlrr,
ttcfl, ttcfr, ttcrl, ttcrr,
ttrfl, ttrfr, ttrrl, ttrrr,
self.mDrsState,
rhfl, rhfr, rhrl, rhrr, # mRideHeight

) = self.fmt.unpack(buf[:self.fmt.size])

Expand All @@ -262,17 +272,24 @@ def __init__(self, buf):
self.mTranslatedTrackLocation = mTranslatedTrackLocation.decode('utf-8').rstrip('\0')
self.mTranslatedTrackVariation = mTranslatedTrackVariation.decode('utf-8').rstrip('\0')
self.mLocalAcceleration = Vector(lax, lay, laz)
self.mWorldAcceleration = Vector(wax, way, waz)
self.mTyreY = Wheels(tyfl, tyfr, tyrl, tyrr)
self.mTyreRPS = Wheels(trpsfl, trpsfr, trpsrl, trpsrr)
self.mTyreSlipSpeed = Wheels(tssfl, tssfr, tssrl, tssrr)
self.mTyreTemp = Wheels(ttfl, ttfr, ttrl, ttrr)
self.mBrakeTempCelsius = Wheels(btfl, btfr, btrl, btrr)
self.mSuspensionTravel = Wheels(stfl, stfr, strl, sttrr)
self.mAirPressure = Wheels(apfl, apfr, aprl, aprr)
self.mWings = Wings(wf, wr)
self.mTyreTempLeft = Wheels(ttlfl, ttlfr, ttlrl, ttlrr)
self.mTyreTempCenter = Wheels(ttcfl, ttcfr, ttcrl, ttcrr)
self.mTyreTempRight = Wheels(ttrfl, ttrfr, ttrrl, ttrrr)
self.mRideHeight = Wheels(rhfl, rhfr, rhrl, rhrr)

self.participants = []
driver_index = self.mViewedParticipantIndex
# unpack the participants
if self.mNumParticipants > 0:
if self.mNumParticipants > 0 and driver_index >= 0:

start = 0
for _ in range(self.mNumParticipants):
Expand All @@ -282,7 +299,7 @@ def __init__(self, buf):
self.participants.append(participant)
start = end

self.driver = self.participants[0]
self.driver = self.participants[driver_index]
else:
self.driver = None

Expand Down
63 changes: 63 additions & 0 deletions stm/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,73 @@
"shortname": "TTempFRI",
"units": "C"
},
"wheelslipfl": {
"datatype": 5,
"decplaces": 1,
"name": "Wheel Slip FL",
"shortname": "WSLPFL",
"units": "mph"
},
"wheelslipfr": {
"datatype": 5,
"decplaces": 1,
"name": "Wheel Slip FR",
"shortname": "WSLPFR",
"units": "mph"
},
"wheelsliprl": {
"datatype": 5,
"decplaces": 1,
"name": "Wheel Slip RL",
"shortname": "WSLPRL",
"units": "mph"
},
"wheelsliprr": {
"datatype": 5,
"decplaces": 1,
"name": "Wheel Slip RR",
"shortname": "WSLPRR",
"units": "mph"
},
"frontwing": {
"decplaces": 2,
"name": "Front Wing",
"shortname": "FWING",
},
"rearwing": {
"decplaces": 2,
"name": "Rear Wing",
"shortname": "RWING",
},
"rideheightfl": {
"decplaces": 2,
"name": "Ride Height FL",
"shortname": "RHeightFL",
},
"rideheightfr": {
"decplaces": 2,
"name": "Ride Height FR",
"shortname": "RHeightFR",
},
"rideheightrl": {
"decplaces": 2,
"name": "Ride Height RL",
"shortname": "RHeightRL",
},
"rideheightrr": {
"decplaces": 2,
"name": "Ride Height RR",
"shortname": "RHeightRR",
},
"debug1": {
"decplaces": 2,
"name": "Debug 1",
"shortname": "Debug1",
},
"debug2": {
"decplaces": 2,
"name": "Debug 2",
"shortname": "Debug2",
}
}

Expand Down

0 comments on commit ab443c6

Please sign in to comment.