Skip to content

Commit

Permalink
switched to accel vs vibrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Frix-x committed Jul 15, 2024
1 parent e364b90 commit 8fd286b
Showing 1 changed file with 54 additions and 23 deletions.
77 changes: 54 additions & 23 deletions shaketune/graph_creators/shaper_graph_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
PEAKS_EFFECT_THRESHOLD = 0.12
SPECTROGRAM_LOW_PERCENTILE_FILTER = 5
MAX_VIBRATIONS = 5.0
SMOOTHING_LIST = [0.1]
# SMOOTHING_LIST = np.arange(0.001, 0.80, 0.05)
MAX_VIBRATIONS_PLOTTED = 25.0
SMOOTHING_TESTS = 10 # Number of smoothing values to test (it will significantly increase the computation time)
KLIPPAIN_COLORS = {
'purple': '#70088C',
'orange': '#FF8D32',
Expand Down Expand Up @@ -178,7 +178,7 @@ def calibrate_shaper(datas: List[np.ndarray], max_smoothing: Optional[float], sc
max_smoothing = shaper.smoothing

# Then we create a list of smoothing values to test (no need to test the max smoothing value as it was already tested)
smoothing_test_list = np.linspace(0.001, max_smoothing, 10)[:-1]
smoothing_test_list = np.linspace(0.001, max_smoothing, SMOOTHING_TESTS)[:-1]
additional_all_shapers = {}
for smoothing in smoothing_test_list:
if compat:
Expand Down Expand Up @@ -294,9 +294,9 @@ def plot_freq_response(
and perf_shaper_choice != klipper_shaper_choice
and perf_shaper_accel >= klipper_shaper_accel
):
perf_shaper_string = f'Recommended performance shaper: {perf_shaper_choice.upper()} @ {perf_shaper_freq:.1f} Hz'
perf_shaper_string = f'Recommended for performance: {perf_shaper_choice.upper()} @ {perf_shaper_freq:.1f} Hz'
lowvibr_shaper_string = (
f'Recommended low vibrations shaper: {klipper_shaper_choice.upper()} @ {klipper_shaper_freq:.1f} Hz'
f'Recommended for low vibrations: {klipper_shaper_choice.upper()} @ {klipper_shaper_freq:.1f} Hz'
)
shaper_table_data['recommendations'].append(perf_shaper_string)
shaper_table_data['recommendations'].append(lowvibr_shaper_string)
Expand Down Expand Up @@ -421,7 +421,7 @@ def plot_smoothing_vs_accel(
fontP = matplotlib.font_manager.FontProperties()
fontP.set_size('x-small')

ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(1000))
ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(500))
ax.yaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
ax.grid(which='major', color='grey')
ax.grid(which='minor', color='lightgrey')
Expand All @@ -436,7 +436,7 @@ def plot_smoothing_vs_accel(
shaper_data[shaper_type] = []
shaper_data[shaper_type].append(
{
'smoothing': shaper.smoothing,
# 'smoothing': shaper.smoothing,
'max_accel': shaper.max_accel,
'vibrs': shaper.vibrs * 100.0,
}
Expand All @@ -449,34 +449,37 @@ def plot_smoothing_vs_accel(
shaper_data[shaper_type] = []
shaper_data[shaper_type].append(
{
'smoothing': float(shaper['smoothing']),
# 'smoothing': float(shaper['smoothing']),
'max_accel': float(shaper['max_accel']),
'vibrs': float(shaper['vibrations']) * 100.0,
}
)

# Plot each shaper type and add colorbar for vibrations
# Calculate the maximum `max_accel` for points below MAX_VIBRATIONS_PLOTTED
max_accel_limit = 0
min_accel_limit = 99999
for data in shaper_data.values():
min_accel_limit = min(min_accel_limit, min(d['max_accel'] for d in data))
max_accel_limit = max(max_accel_limit, max(d['max_accel'] for d in data if d['vibrs'] < MAX_VIBRATIONS_PLOTTED))

# Plot each shaper type response over acceleration in regards to vibrations
for _, (shaper_type, data) in enumerate(shaper_data.items()):
smoothing_values = [d['smoothing'] for d in data]
# smoothing_values = [d['smoothing'] for d in data]
max_accel_values = [d['max_accel'] for d in data]
vibrs_values = [d['vibrs'] for d in data]
ax.plot(max_accel_values, smoothing_values, linestyle=':', label=f'{shaper_type}', zorder=10)
scatter = ax.scatter(
max_accel_values, smoothing_values, c=vibrs_values, cmap='plasma', s=100, edgecolors='w', zorder=15
)
ax.plot(max_accel_values, vibrs_values, linestyle='-', label=f'{shaper_type}', zorder=10)

# Add colorbar for vibrations
cbar = plt.colorbar(scatter, ax=ax)
cbar.set_label('Remaining Vibrations (%)')
ax.set_xlabel('Max Acceleration')
ax.set_ylabel('Smoothing')
ax.set_ylabel('Remaining Vibrations (%)')
ax.set_xlim([min_accel_limit, max_accel_limit])
ax.set_ylim([0, MAX_VIBRATIONS_PLOTTED])
ax.set_title(
'Smoothing vs Max Acceleration',
'Max Acceleration related to Vibrations',
fontsize=14,
color=KLIPPAIN_COLORS['dark_orange'],
weight='bold',
)
ax.legend(loc='upper right', prop=fontP)
ax.legend(loc='best', prop=fontP)


def print_shaper_table(fig: plt.Figure, shaper_table_data: Dict[str, List[Dict[str, str]]]) -> None:
Expand All @@ -492,15 +495,43 @@ def print_shaper_table(fig: plt.Figure, shaper_table_data: Dict[str, List[Dict[s
f'{round(shaper_info["max_accel"] / 10) * 10:.0f}',
]
table_data.append(row)
table = plt.table(cellText=table_data, colLabels=columns, bbox=[1.12, -0.4, 0.75, 0.25], cellLoc='center')
table = plt.table(cellText=table_data, colLabels=columns, bbox=[1.130, -0.4, 0.803, 0.25], cellLoc='center')
table.auto_set_font_size(False)
table.set_fontsize(10)
table.auto_set_column_width([0, 1, 2, 3, 4])
table.set_zorder(100)

# Add the recommendations and damping ratio using fig.text
fig.text(0.58, 0.235, f'Estimated damping ratio (ζ): {shaper_table_data["damping_ratio"]:.3f}', fontsize=14)
fig.text(0.58, 0.210, '\n'.join(shaper_table_data['recommendations']), fontsize=14)
fig.text(
0.585,
0.235,
f'Estimated damping ratio (ζ): {shaper_table_data["damping_ratio"]:.3f}',
fontsize=14,
color=KLIPPAIN_COLORS['purple'],
)
if len(shaper_table_data['recommendations']) == 1:
fig.text(
0.585,
0.200,
shaper_table_data['recommendations'][0],
fontsize=14,
color=KLIPPAIN_COLORS['red_pink'],
)
elif len(shaper_table_data['recommendations']) == 2:
fig.text(
0.585,
0.200,
shaper_table_data['recommendations'][0],
fontsize=14,
color=KLIPPAIN_COLORS['red_pink'],
)
fig.text(
0.585,
0.175,
shaper_table_data['recommendations'][1],
fontsize=14,
color=KLIPPAIN_COLORS['red_pink'],
)


######################################################################
Expand Down

0 comments on commit 8fd286b

Please sign in to comment.