Skip to content
Draft
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
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
39 changes: 4 additions & 35 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,7 @@
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")

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])

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.legend()
plt.plot(df[busV])
plt.show()
82 changes: 82 additions & 0 deletions Docs/SimulationTodo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Simulation Todo

1. Better drag model that takes into account aeropackage (FS-3)
1. Individual wheel models
1. Suspension
1. Travel (x)
1. Velocity (v)
1. How will this react under acceleration in any direction (steering causes lateral acceleration) (throttle/brakes causes longitudinal acceleration)
1. Wheel
1. Brake temp (more complex soon)
1. Wheel temp (more complex soon)
1. Wheel rpm/speed
1. Differential + Drivetrain losses
1. Energy loss due to chain, tripods, axle, hub/upright rubbing
1. Model rolling resistance better
1. Model limited slip differential
1. Log losses so we have an idea of energy loss in the drivetrain
1. Motor Efficiency + Heating
1. Function of temp and current draw
1. Keep track of losses
1. Efficiency loss goes into heat of motor. Need an estimate of its thermal mass and then change in temp. (Motor temp new var)
1. Cleaner logging
1. Log everything without having to add more rows constantly
1. Keep efficiency in mind
1. Tractive system heat generation (Not acc)
1. Estimate how much heat is generated in the accumulator
1. Not high priority unless we can get more data.
1. Steering model
1. Suspension Model


# New simulation architecture idea


```python
# Dynamic Vars
posX = 0
posY = 1
velX = 2
velY = 3
accelX = 4
accelY = 5

arr = np.array((simSteps, 6+1))
arr[0] = step0

def step():
newPosX = step[posX] + step[velX] * t

for i in range(simSteps):
arr[i+1] = step(arr[i])
```

```python
# Dictionary Idea #1
# Array of dictionaries where each time step gets its own dictionary
# Trivial to access a specific thing from any row

arr = np.array((simSteps))
arr[0] = step0

def step():
newPosX = arr[posX] + arr[velX] * t

for i in range(simSteps):
arr[i+1] = step(arr[i])
```

```python
# Dictionary Idea #2
# Dictionary of arrays. Each key is a column and each array is the length of the simulation
# Trivial to access columns which is typically how we access data

arr = np.array((simSteps))
arr[0] = step0

def step():
newPosX = arr[posX] + arr[velX] * t

for i in range(simSteps):
arr[i+1] = step(arr[i])
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import numpy as np
import polars as pl
import matplotlib.pyplot as plt
from Data.FSLib.IntegralsAndDerivatives import integrate_with_Scipy_tCol
from Data.FSLib.AnalysisFunctions import simpleTimeCol
# from Data.FSLib.IntegralsAndDerivatives import integrate_with_Scipy_tCol
# from Data.FSLib.AnalysisFunctions import simpleTimeCol

df = pl.read_csv("C:/Projects/FormulaSlug/fs-data/FS-3/voltageTableVTC5A.csv")
dfLowCurr = df.filter(pl.col("Current") < 3).filter(pl.col("Voltage") > 2.5)
dfLowCurr = df.filter(pl.col("Current") < 1).filter(pl.col("Voltage") > 2.5)

df.head

Expand Down Expand Up @@ -88,7 +88,7 @@ def voltage_model(x, a1, a2, a3, a4, a5, a6, a7, a8, a9):
plt.legend()
plt.show()

dfLowCurr1 = df.filter(pl.col("Current") < 3).filter(pl.col("Voltage") > 2.5)
dfLowCurr1 = df.filter(pl.col("Current") < 1).filter(pl.col("Voltage") > 2.5)
# dfLowCurr2 = df.filter(pl.col("Current") < 3)


Expand Down
Loading