Spring Design (Dynamic)
Spring Design (Dynamic)
clear;
disp('--- Dynamic Helical Spring Design Calculator ---');
P_max = input('Enter maximum spring force in N (P_max): ');
P_min = input('Enter minimum spring force in N (P_min): ');
deflection = input('Enter spring deflection under full load (mm): ');
C = input('Enter spring index (C = D/d, suggested: 5 to 10): ');
Sut = input('Enter ultimate tensile strength (N/mm^2): ');
G = input('Enter modulus of rigidity G (N/mm^2, e.g. 81370 for steel): ');
end_style = input('Enter end type (1=plain, 2=square, 3=plain-ground, 4=square-ground): ');
P_mean = (P_max + P_min)/2;
P_amp = (P_max - P_min)/2;
Se_dash = 0.21 * Sut;
Sy = 0.45 * Sut;
K = ((4*C - 1)/(4*C - 4)) + 0.615/C;
tau_perm = 0.5 * Sut;
d = sqrt((8 * P_max * K * C) / (pi * tau_perm));
d = ceil(d);
D = C * d;
tau_a = (8 * P_amp * D * K) / (pi * d^3);
tau_m = (8 * P_mean * D) / (pi * d^3);
n_actual = 1 / ((tau_a / Se_dash) + (tau_m / Sy));
k = (P_max - P_min) / deflection;
Na = (G * d^4) / (8 * D^3 * k);
Na = ceil(Na);
switch end_style
case 1
Nt = Na;
case 2
Nt = Na + 2;
case 3
Nt = Na + 1;
case 4
Nt = Na + 2;
otherwise
error('Invalid end style');
end
Ls = Nt * d;
gap = 0.5;
La = (Nt - 1) * gap;
Lf = Ls + deflection + La;
pitch = (Lf - d)/(Nt - 1);
fprintf('\n--- Dynamic Spring Design Results ---\n');
fprintf('Wire diameter (d): %.2f mm\n', d);
fprintf('Mean coil diameter (D): %.2f mm\n', D);
fprintf('Spring index (C): %.2f\n', C);
fprintf('Alternating shear stress (τa): %.2f N/mm^2\n', tau_a);
fprintf('Mean shear stress (τm): %.2f N/mm^2\n', tau_m);
fprintf('Factor of safety (Goodman): %.2f\n', n_actual);
fprintf('Required spring rate: %.2f N/mm\n', k);
fprintf('Active coils: %d\n', Na);
fprintf('Total coils: %d\n', Nt);
fprintf('Solid length (Ls): %.2f mm\n', Ls);
fprintf('Free length (Lf): %.2f mm\n', Lf);
fprintf('Pitch: %.2f mm\n', pitch);
fprintf('Factor of Safety: %.2f\n', n_actual);