Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Data/BatemoDataAnalysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import scipy
import scipy.integrate

batemoData = scipy.io.loadmat("C:/Users/Goob/Downloads/OneDrive_2026-01-07/Batemo Sponsorship/Batemo Cell Data Molicel INR18650P30B/Batemo Cell Data Package/Molicel_INR18650P30B_measurement.mat",
simplify_cells=True)


header = batemoData["__header__"]
version = batemoData["__version__"]
globals = batemoData["__globals__"] ## Nothing
print(f"header = {header}")
print(f"version = {version}")
measurement = batemoData["measurement"]
firstLayerMeta = measurement['meta']
Fu = measurement['fu']

## DCC (Discharge)
## CHC (Charging)
## DCP (Discharge Pulse)
## CHP (Charge Pulse)
## PRO (Profile Measurement)


# Each Has
# name
# T_amb (Ambient Temperature)
# t (Time Seconds)
# I (Current)
# V (Voltage)
# T_surf (Surface temperature, nominally 1xN but may be 2xN?)


for i in Fu['DCC']:
print(i['name'])
37 changes: 34 additions & 3 deletions Data/emeterDecode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from nptdms import TdmsFile
import polars as pl
import numpy as np
import matplotlib.pyplot as plt
from Data.FSLib.IntegralsAndDerivatives import *
from Data.FSLib.AnalysisFunctions import *
Expand All @@ -9,10 +10,10 @@
autoxDaniel12File = "FS-3/compEmeterData/autoxDaniel12.tdms"
accel1 = "FS-3/compEmeterData/216_univ-of-calif---santa-cruz-_250620-203307_ ACCEL-EV.tdms"
accel2 = "FS-3/compEmeterData/216_univ-of-calif---santa-cruz-_250620-205609_ ACCEL-EV.tdms"
endur1 = "FS-3/compEmeterData/216_univ-of-calif---santa-cruz-_250621-154731_ ENDUR-EV.tdms"
endur2 = "FS-3/compEmeterData/216_univ-of-calif---santa-cruz-_250621-160530_ ENDUR-EV.tdms"
endur1 = "../fs-data/FS-3/compEmeterData/216_univ-of-calif---santa-cruz-_250621-154731_ ENDUR-EV.tdms"
endur2 = "../fs-data/FS-3/compEmeterData/216_univ-of-calif---santa-cruz-_250621-160530_ ENDUR-EV.tdms"

dfLaptimes = pl.read_csv("FS-3/compLapTimes.csv")
dfLaptimes = pl.read_csv("../fs-data/FS-3/compLapTimes.csv")
firstHalf = dfLaptimes.filter(pl.col("Lap") < 12)["Time"].sum()
secondHalf = dfLaptimes.filter(pl.col("Lap") > 11)["Time"].sum()

Expand Down Expand Up @@ -93,7 +94,37 @@ def fileTodf(path):
pl.Series(arr).cast(pl.Int64).alias("Lap")
)

l = []

for i in np.unique(dfendur1["Lap"]):
# plt.plot(dfendur1.filter(pl.col("Lap") == i)[I])
l.append(dfendur1.filter(pl.col("Lap") == i)[I])
plt.show()

shortest = min([len(x) for x in l])
l2 = [x[:shortest].alias(f"Current_Lap_{i}") for i, x in enumerate(l)]
df2 = pl.DataFrame(l2)
plt.plot(df2.mean_horizontal())
plt.show()

from scipy.fft import fft, ifft

f = fft(df2.mean_horizontal().to_numpy())
# freq = np.fft.fftfreq(len(df2.mean_horizontal()), d=0.01)

plt.plot(np.append(np.log(f[-len(f)//2:]), np.log(f[:len(f)//2])))
plt.show()

fFiltered = np.where(np.log(f) > 10, f, 0)
invF = ifft(fFiltered)
plt.plot(invF)
plt.plot(df2.mean_horizontal())
plt.show()

dfTableCurrOut = pl.DataFrame({"Current": df2.mean_horizontal().gather_every(100), "Time": np.arange(0, df2.height/100)})
dfTableCurrOut.write_csv("endur1Curr.csv")

df2.mean_horizontal()

dfendur2 = fileTodf(endur2).filter(pl.col(t) > endur2_StartTime).filter(pl.col(t) < endur2_EndTime)

Expand Down
60 changes: 43 additions & 17 deletions Data/temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import cantools.database as db

from Data.DataDecoding_N_CorrectionScripts.dataDecodingFunctions import *
from Data.AnalysisFunctions import *
from Data.integralsAndDerivatives import *
from Data.FSLib.AnalysisFunctions import *
from Data.FSLib.IntegralsAndDerivatives import *
from scipy.interpolate import CubicSpline

dbcPath = "../fs-3/CANbus.dbc"
Expand Down Expand Up @@ -70,38 +70,64 @@
etcRTDButton = "ETC_STATUS_RTD_BUTTON"
etcBrakeVoltage = "ETC_STATUS_BRAKE_SENSE_VOLTAGE"

df = read("C:/Projects/FormulaSlug/fs-data/FS-3/10112025/firstDriveMCError30.parquet")
df = df.with_columns(
df["timestamp"].alias("Time")
)
df = read("C:/Projects/FormulaSlug/fs-data/FS-3/10082025/fixed_wheels_nathaniel_inv_test_w_fault.parquet")

plt.plot(df[busV])
plt.show()


df = pl.read_parquet("C:/Projects/FormulaSlug/fs-data/FS-3/10112025/firstDriveMCError30-filled-null.parquet")

df.select([a for a in df.columns if a.startswith("ACC") and a[9] == "T"]).mean_horizontal()

df = read("C:/Projects/FormulaSlug/fs-data/FS-3/10112025/firstDriveMCError30-filled-null.parquet")
df = df.with_columns(
simpleTimeCol(df)
)

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(df[t], df[frT], label=frT, c="blue")
ax.plot(df[t], df[flT], label=flT, c="red")
ax.plot(df[t], df[brT], label=brT, c="orange")
ax.plot(df[t], df[blT], label=blT, c="cyan")
ax.set_title("Suspension Travel during First Drive with MC Fault")
ax.set_xlabel("Time")
ax.set_ylabel("Suspension Travel (mm)")
ax.legend()
plt.show()


dfNullless = df.drop_nulls(subset=[frT, flT, brT, blT])
heFR = "TELEM_FR_WHEELSPEED"
heFL = "TELEM_FL_WHEELSPEED"
heBR = "TELEM_BR_WHEELSPEED"
heBL = "TELEM_BL_WHEELSPEED"

df = read("C:/Projects/FormulaSlug/fs-data/FS-2/Parquet/2025-03-06-BrakingTests1.parquet")
df = df.with_columns(
simpleTimeCol(df)
)

cs = CubicSpline(dfNullless[t], dfNullless[frT])

fig = plt.figure()
ax = fig.add_subplot(111)

ax.scatter(dfNullless[t], cs(dfNullless[t]), label=frT, s=0.5)
ax.scatter(dfNullless[t], in_place_derive(cs(dfNullless[t])), label=f"Derived {frT}", s=0.5)
ax.plot(df[t], df[heFR], label=heFR, c="orange")
ax.plot(df[t], df[heFL], label=heFL, c="red")
ax.plot(df[t], df[heBR], label=heBR, c="blue")
ax.plot(df[t], df[heBL], label=heBL, c="cyan")
ax.set_title("HE Sensors")
ax.set_xlabel("Time")
ax.set_ylabel("idk lol, 0-32767")
ax.legend()
plt.show()


fig = plt.figure()
ax = fig.add_subplot(111)
ax1 = ax.twinx()

ax.plot(df[t], df[heFR], label="frontRight", c="red")
ax.plot(df[t], df.select([heBL, heBR]).mean_horizontal(), label="meanBack", c="blue")
ax1.plot(df[t],df.select([heBL, heBR]).mean_horizontal() / df[heFR], label="ratio", c="green")
# ax.plot(df[t], df[rpm]*11/41, label="RPM", c="orange") ## Cursed until we have proper wheel speed calibration
ax.set_title("HE Sensors")
ax.set_xlabel("Time")
ax.set_ylabel("idk lol, 0-32767")
ax.legend()
ax1.set_ylim(0,2)
plt.show()
95 changes: 95 additions & 0 deletions Data/temp2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import polars as pl
from Data.FSLib.AnalysisFunctions import *
from scipy.stats import linearregress

rpm = "SME_TRQSPD_Speed"
lat = "VDM_GPS_Latitude"
long = "VDM_GPS_Longitude"
xA = "VDM_X_AXIS_ACCELERATION"
yA = "VDM_Y_AXIS_ACCELERATION"
speed = "VDM_GPS_SPEED" ## mph

df1 = readValid("C:/Projects/FormulaSlug/fs-data/FS-3/08102025/08102025Endurance1_FirstHalf.parquet") ## 276,1075
df1 = df1.insert_column(0, simpleTimeCol(df1))
df1 = df1.filter(pl.col("Time") >= 276).filter(pl.col("Time") <= 1075)
df1 = df1.with_columns(
pl.col("Time") - pl.col("Time").min()
)
df1 = df1.insert_column(0, lapSegmentation(df1))

df2 = readValid("C:/Projects/FormulaSlug/fs-data/FS-3/08102025/08102025Endurance1_SecondHalf.parquet") ## 77, 862
df2 = df2.insert_column(0, simpleTimeCol(df2))
df2 = df2.filter(pl.col("Time") >= 77).filter(pl.col("Time") <= 862)
df2 = df2.with_columns(
pl.col("Time") - pl.col("Time").min()
)
df2 = df2.insert_column(0, lapSegmentation(df2))
df2 = df2.with_columns(
pl.col("Lap") + df1["Lap"].max() + 1
)

df3 = readValid("C:/Projects/FormulaSlug/fs-data/FS-3/08172025/08172025_20_Endurance1P1.parquet") ## 72, 1120 -- Drop laps 8 and 9
df3 = df3.insert_column(0, simpleTimeCol(df3))
df3 = df3.filter(pl.col("Time") >= 72).filter(pl.col("Time") <= 1120)
df3 = df3.with_columns(
pl.col("Time") - pl.col("Time").min()
)
df3 = df3.insert_column(0, lapSegmentation(df3))
df3_1 = df3.filter(pl.col("Lap") < 8)
df3_2 = df3.filter(pl.col("Lap") > 9).with_columns(
pl.col("Lap") - 2
)
df3 = df3_1.vstack(df3_2)
df3 = df3.with_columns(
pl.col("Lap") + df2["Lap"].max() + 1
)

df1 = df1.select(df3.columns)
df2 = df2.select(df3.columns)

df1f = df1._cast_all_from_to(df1, frozenset((pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64, pl.Float32)), pl.Float64)
df2f = df2._cast_all_from_to(df2, frozenset((pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64, pl.Float32)), pl.Float64)
df3f = df3._cast_all_from_to(df3, frozenset((pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64, pl.Float32)), pl.Float64)

df = df1f.vstack(df2f).vstack(df3f)
df = df.drop("Time").insert_column(0, simpleTimeCol(df))

fig = plt.figure(layout="constrained")
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
ax1.plot(df["Time"], df[rpm], label="RPM")
ax2.plot(df["Time"], df["Lap"], label="Lap")
fig.legend()
plt.show()

for i in df["Lap"].unique():
plt.plot(df.filter(pl.col("Lap") == i)[lat], df.filter(pl.col("Lap") == i)[long], label=f"Lap {i}")
plt.legend()
plt.show()

# df.drop("Time").write_parquet("C:/Projects/FormulaSlug/fs-data/FS-3/PreparedData/CombinedEndurance_0810_0817_2025.parquet")
# df["Lap"].max()

df = pl.read_parquet("C:/Projects/FormulaSlug/fs-data/FS-3/PreparedData/CombinedEndurance_0810_0817_2025.parquet")
df = df.with_columns(
(((df["ETC_STATUS_BRAKE_SENSE_VOLTAGE"]/1000)-0.33)/2.64*2000).alias("Brake_Pedal_Pressure_PSI"),
(df[xA]*9.81*df[speed]*0.44704*300/1000).alias("Braking_Power_kW")
)

fig = plt.figure(layout="constrained")
ax1 = fig.add_subplot(111)
ax1.scatter(df[long], df[lat], c=df[xA]*9.81*df[speed]*0.44704*300*-1/1000, cmap='viridis', s=2, alpha=0.3, label="Brake Power (kW)") ## convert mph to m/s by multiplying by 0.44704
ax1.set_aspect('equal', adjustable='datalim')
plt.colorbar(ax1.collections[0], ax=ax1, label="Braking Power (kW)")
ax1.set_title("Track Map Colored by Braking Power (kW)")
fig.show()

dfBraking = df.filter(pl.col("Braking_Power_kW") > 20).filter(pl.col("Brake_Pedal_Pressure_PSI") > 100)

fig2 = plt.figure(layout="constrained")
ax2 = fig2.add_subplot(111)
ax2.scatter(dfBraking["Brake_Pedal_Pressure_PSI"], dfBraking["Braking_Power_kW"])
ax2.set_title("Brake Pedal Pressure vs Braking Power (kW)")
ax2.set_xlabel("Brake Pedal Pressure (PSI)")
ax2.set_ylabel("Braking Power (kW)")
fig2.show()
Loading