Skip to content

Commit

Permalink
add altitude
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekyDeaks committed Jun 23, 2024
1 parent f4680ae commit 01c3377
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 6 deletions.
12 changes: 9 additions & 3 deletions stm/ams2/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from stm.logger import BaseLogger
from stm.event import STMEvent
from .tracks import convert_to_gps
from .tracks import convert_to_gps, convert_to_altitude
from .shmem import AMS2SharedMemory, AMS2GameState
from datetime import datetime
from logging import getLogger
Expand Down Expand Up @@ -30,6 +30,7 @@ class AMS2Logger(BaseLogger):
'tyrepresfl', 'tyrepresfr', 'tyrepresrl', 'tyrepresrr', # mAirPressure
'tyrespdfl', 'tyrespdfr', 'tyrespdrl', 'tyrespdrr',# mTyreRPS
'tyreyfl', 'tyreyfr', 'tyreyrl', 'tyreyrr', # Tyre Y position
'tyrehagfl', 'tyrehagfr', 'tyrehagrl', 'tyrehagrr', # Tyre height above ground
'turbopres',
'oiltemp', 'oilpres',
'watertemp', 'waterpres',
Expand All @@ -46,7 +47,8 @@ class AMS2Logger(BaseLogger):
'angvelx', 'angvely', 'angvelz',
'orientationx', 'orientationy', 'orientationz',
'posx', 'posy', 'posz',
'tracktemp', 'ambienttemp'
'tracktemp', 'ambienttemp',
'altitude'
]

def __init__(self,
Expand Down Expand Up @@ -113,6 +115,8 @@ def process_packet(self, timestamp, p, lastp):

glat, gvert, glong = [ a / 9.8 for a in p.mLocalAcceleration]

altitude = convert_to_altitude(name=p.mTrackVariation, y=p.driver.mWorldPosition.y)

if self.imperial:
ms_to_speed = 2.23693629 # m/s to mph
else:
Expand Down Expand Up @@ -149,6 +153,7 @@ def process_packet(self, timestamp, p, lastp):
*p.mAirPressure,
*[ ts * -1.0 for ts in p.mTyreRPS ],
*p.mTyreY,
*p.mTyreHeightAboveGround,
p.mTurboBoostPressure / 1000.0,
p.mOilTempCelsius,
p.mOilPressureKPa,
Expand Down Expand Up @@ -178,7 +183,8 @@ def process_packet(self, timestamp, p, lastp):
*convert_orientation(p.mOrientation),
*p.driver.mWorldPosition,
p.mTrackTemperature,
p.mAmbientTemperature
p.mAmbientTemperature,
altitude
])


8 changes: 6 additions & 2 deletions stm/ams2/shmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class AMS2SharedMemory:
"4f" # mTyreRPS
"4f" # mTyreSlipSpeed
"4f" # mTyreTemp
"16x" # mTyreGrip
"16x" # mTyreHeightAboveGround
"4f" # mTyreGrip
"4f" # mTyreHeightAboveGround
"16x" # mTyreLateralStiffness
"16x" # mTyreWear
"16x" # mBrakeDamage
Expand Down Expand Up @@ -302,6 +302,8 @@ def __init__(self, buf):
trpsfl, trpsfr, trpsrl, trpsrr, # mTyreRPS
tssfl, tssfr, tssrl, tssrr, # mTyreSlipSpeed
ttfl, ttfr, ttrl, ttrr, # mTyreTemp
tgfl, tgfr, tgrl, tgrr, # mTyreGrip
thagfl, thagfr, thagrl, thagrr, # mTyreHeightAboveGround
btfl, btfr, btrl, btrr, # mBrakeTempCelsius
self.mAmbientTemperature,
self.mTrackTemperature,
Expand Down Expand Up @@ -355,6 +357,8 @@ def __init__(self, buf):
self.mTyreRPS = Wheels(trpsfl, trpsfr, trpsrl, trpsrr)
self.mTyreSlipSpeed = Wheels(tssfl, tssfr, tssrl, tssrr)
self.mTyreTemp = Wheels(ttfl, ttfr, ttrl, ttrr)
self.mTyreGrip = Wheels(tgfl, tgfr, tgrl, tgrr)
self.mTyreHeightAboveGround = Wheels(thagfl, thagfr, thagrl, thagrr)
self.mBrakeTempCelsius = Wheels(btfl, btfr, btrl, btrr)
self.mSuspensionTravel = Wheels(stfl, stfr, strl, sttrr)
self.mSuspensionVelocity = Wheels(svfl, svfr, svrl, svrr)
Expand Down
11 changes: 11 additions & 0 deletions stm/ams2/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def convert_to_gps(self, x, z):
z = rz

return gps.convert(x=x, z=z, latmid=self.refLat, longmid=self.refLong)

def convert_to_altitude(self, y):
alt = getattr(self, 'altitude', 0)
return alt + y

def lookup_track(name):
return TRACKS.get(name)
Expand All @@ -43,6 +47,13 @@ def convert_to_gps(name, x, z):
return track.convert_to_gps(x, z)
else:
return gps.convert(x, z)

def convert_to_altitude(name, y):
track = lookup_track(name)
if track:
return track.convert_to_altitude(y)
else:
return y

with open(os.path.join(PATH, "tracks", "gps.json"), "r") as fin:
track_list = json.loads(fin.read())
Expand Down
Loading

0 comments on commit 01c3377

Please sign in to comment.