enhanced visualizations
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.vscode/
|
.vscode/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
sim_results/
|
||||||
@@ -10,11 +10,16 @@ from parameters import QuadParams, Constants
|
|||||||
from utils import euler2dcm, fmag2
|
from utils import euler2dcm, fmag2
|
||||||
from simulate import simulate_maglev_control
|
from simulate import simulate_maglev_control
|
||||||
from visualize import visualize_quad
|
from visualize import visualize_quad
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main simulation script"""
|
"""Main simulation script"""
|
||||||
|
|
||||||
|
# Create output directory if it doesn't exist
|
||||||
|
output_dir = 'sim_results'
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
# SET REFERENCE HERE
|
# SET REFERENCE HERE
|
||||||
# Total simulation time, in seconds
|
# Total simulation time, in seconds
|
||||||
Tsim = 2
|
Tsim = 2
|
||||||
@@ -127,7 +132,7 @@ def main():
|
|||||||
'eMat': eMat,
|
'eMat': eMat,
|
||||||
'plotFrequency': 20,
|
'plotFrequency': 20,
|
||||||
'makeGifFlag': True,
|
'makeGifFlag': True,
|
||||||
'gifFileName': 'testGif.gif',
|
'gifFileName': 'sim_results/testGif.gif',
|
||||||
'bounds': [-1, 1, -1, 1, -300e-3, 0.000]
|
'bounds': [-1, 1, -1, 1, -300e-3, 0.000]
|
||||||
}
|
}
|
||||||
visualize_quad(S2)
|
visualize_quad(S2)
|
||||||
@@ -161,7 +166,7 @@ def main():
|
|||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
|
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.savefig('simulation_results.png', dpi=150)
|
plt.savefig('sim_results/simulation_results.png', dpi=150)
|
||||||
print("Saved plot to simulation_results.png")
|
print("Saved plot to simulation_results.png")
|
||||||
|
|
||||||
# Commented out horizontal position plot (as in MATLAB)
|
# Commented out horizontal position plot (as in MATLAB)
|
||||||
@@ -189,8 +194,10 @@ def main():
|
|||||||
plt.title("Complex Magnitude of fft Spectrum")
|
plt.title("Complex Magnitude of fft Spectrum")
|
||||||
plt.xlabel("f (Hz)")
|
plt.xlabel("f (Hz)")
|
||||||
plt.ylabel("|fft(X)|")
|
plt.ylabel("|fft(X)|")
|
||||||
|
# Exclude DC component (first element) from scaling to see AC components better
|
||||||
|
plt.ylim([0, np.max(np.abs(Y[1:])) * 1.05]) # Dynamic y-axis excluding DC
|
||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
plt.savefig('fft_spectrum.png', dpi=150)
|
plt.savefig('sim_results/fft_spectrum.png', dpi=150)
|
||||||
print("Saved FFT plot to fft_spectrum.png")
|
print("Saved FFT plot to fft_spectrum.png")
|
||||||
|
|
||||||
# Show all plots
|
# Show all plots
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ def visualize_quad(S):
|
|||||||
# Plot body axes
|
# Plot body axes
|
||||||
plot_axes(ax, r, RIB)
|
plot_axes(ax, r, RIB)
|
||||||
|
|
||||||
|
# Add steel plate
|
||||||
|
plot_steel_plate(ax, S['bounds'])
|
||||||
|
|
||||||
ax.set_xlim([S['bounds'][0], S['bounds'][1]])
|
ax.set_xlim([S['bounds'][0], S['bounds'][1]])
|
||||||
ax.set_ylim([S['bounds'][2], S['bounds'][3]])
|
ax.set_ylim([S['bounds'][2], S['bounds'][3]])
|
||||||
ax.set_zlim([S['bounds'][4], S['bounds'][5]])
|
ax.set_zlim([S['bounds'][4], S['bounds'][5]])
|
||||||
@@ -152,6 +155,10 @@ def visualize_quad(S):
|
|||||||
ax.set_zlabel('Z')
|
ax.set_zlabel('Z')
|
||||||
ax.view_init(elev=0, azim=0)
|
ax.view_init(elev=0, azim=0)
|
||||||
ax.grid(True)
|
ax.grid(True)
|
||||||
|
|
||||||
|
# Add steel plate
|
||||||
|
plot_steel_plate(ax, S['bounds'])
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def update(frame):
|
def update(frame):
|
||||||
@@ -219,6 +226,68 @@ def plot_body(ax, r, RIB, body_faces):
|
|||||||
return poly
|
return poly
|
||||||
|
|
||||||
|
|
||||||
|
def plot_steel_plate(ax, bounds):
|
||||||
|
"""
|
||||||
|
Plot a steel plate at z=0 with 0.25 inch thickness
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
ax : Axes3D
|
||||||
|
The 3D axis to plot on
|
||||||
|
bounds : list
|
||||||
|
6-element list [xmin, xmax, ymin, ymax, zmin, zmax]
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
plate : Poly3DCollection
|
||||||
|
The plate collection object
|
||||||
|
"""
|
||||||
|
plate_thickness = 0.25 * 0.0254 # 0.25 inches to meters
|
||||||
|
x_bounds = [bounds[0], bounds[1]]
|
||||||
|
y_bounds = [bounds[2], bounds[3]]
|
||||||
|
|
||||||
|
# Create plate vertices (top at z=0, bottom at z=-thickness)
|
||||||
|
plate_vertices = [
|
||||||
|
# Top surface
|
||||||
|
[[x_bounds[0], y_bounds[0], plate_thickness],
|
||||||
|
[x_bounds[1], y_bounds[0], plate_thickness],
|
||||||
|
[x_bounds[1], y_bounds[1], plate_thickness],
|
||||||
|
[x_bounds[0], y_bounds[1], plate_thickness]],
|
||||||
|
# Bottom surface
|
||||||
|
[[x_bounds[0], y_bounds[0], 0],
|
||||||
|
[x_bounds[1], y_bounds[0], 0],
|
||||||
|
[x_bounds[1], y_bounds[1], 0],
|
||||||
|
[x_bounds[0], y_bounds[1], 0]],
|
||||||
|
# Side 1
|
||||||
|
[[x_bounds[0], y_bounds[0], plate_thickness],
|
||||||
|
[x_bounds[1], y_bounds[0], plate_thickness],
|
||||||
|
[x_bounds[1], y_bounds[0], 0],
|
||||||
|
[x_bounds[0], y_bounds[0], 0]],
|
||||||
|
# Side 2
|
||||||
|
[[x_bounds[1], y_bounds[0], plate_thickness],
|
||||||
|
[x_bounds[1], y_bounds[1], plate_thickness],
|
||||||
|
[x_bounds[1], y_bounds[1], 0],
|
||||||
|
[x_bounds[1], y_bounds[0], 0]],
|
||||||
|
# Side 3
|
||||||
|
[[x_bounds[1], y_bounds[1], plate_thickness],
|
||||||
|
[x_bounds[0], y_bounds[1], plate_thickness],
|
||||||
|
[x_bounds[0], y_bounds[1], 0],
|
||||||
|
[x_bounds[1], y_bounds[1], 0]],
|
||||||
|
# Side 4
|
||||||
|
[[x_bounds[0], y_bounds[1], plate_thickness],
|
||||||
|
[x_bounds[0], y_bounds[0], plate_thickness],
|
||||||
|
[x_bounds[0], y_bounds[0], 0],
|
||||||
|
[x_bounds[0], y_bounds[1], 0]]
|
||||||
|
]
|
||||||
|
|
||||||
|
# Steel gray color
|
||||||
|
steel_color = [0.7, 0.7, 0.75]
|
||||||
|
plate = Poly3DCollection(plate_vertices, alpha=0.3, facecolor=steel_color,
|
||||||
|
edgecolor='darkgray', linewidths=0.5)
|
||||||
|
ax.add_collection3d(plate)
|
||||||
|
return plate
|
||||||
|
|
||||||
|
|
||||||
def plot_axes(ax, r, RIB):
|
def plot_axes(ax, r, RIB):
|
||||||
"""Plot body axes"""
|
"""Plot body axes"""
|
||||||
bodyX = 0.5 * RIB @ np.array([1, 0, 0])
|
bodyX = 0.5 * RIB @ np.array([1, 0, 0])
|
||||||
|
|||||||
Reference in New Issue
Block a user