Mareeka's picture
Create app.py
fcb79c0 verified
import streamlit as st
def calculate_gear_parameters(teeth, module, power, rpm, material_strength):
# Basic calculations
pitch_diameter = teeth * module # Pitch diameter in mm
addendum = module # Addendum in mm
dedendum = 1.25 * module # Dedendum in mm
clearance = dedendum - addendum
face_width = 10 * module # Recommended face width
# Torque calculation
torque = (power * 60) / (2 * 3.14159 * rpm) # Nm
# Velocity calculation
pitch_line_velocity = (3.14159 * pitch_diameter * rpm) / 60000 # m/s
# Stress calculations
tangential_force = (2 * torque) / pitch_diameter # N
bending_stress = tangential_force / (face_width * module) # Approximation
contact_stress = (tangential_force / face_width) ** 0.5 # Simplified
safety_factor = material_strength / bending_stress
return {
"Pitch Diameter (mm)": pitch_diameter,
"Addendum (mm)": addendum,
"Dedendum (mm)": dedendum,
"Clearance (mm)": clearance,
"Face Width (mm)": face_width,
"Torque (Nm)": torque,
"Pitch Line Velocity (m/s)": pitch_line_velocity,
"Tangential Force (N)": tangential_force,
"Bending Stress (MPa)": bending_stress,
"Contact Stress (MPa)": contact_stress,
"Safety Factor": safety_factor,
}
st.title("Gear Design Calculator")
st.sidebar.header("Gear Parameters")
teeth = st.sidebar.number_input("Number of Teeth", min_value=10, max_value=200, value=20, step=1)
module = st.sidebar.number_input("Module (mm)", min_value=1.0, max_value=10.0, value=2.0, step=0.1)
st.sidebar.header("Operating Conditions")
power = st.sidebar.number_input("Power (kW)", min_value=0.1, max_value=100.0, value=5.0, step=0.1)
rpm = st.sidebar.number_input("Rotational Speed (RPM)", min_value=10, max_value=10000, value=1500, step=10)
st.sidebar.header("Material Properties")
material_strength = st.sidebar.number_input(
"Material Strength (MPa)", min_value=100.0, max_value=2000.0, value=250.0, step=10.0
)
if st.sidebar.button("Calculate"):
results = calculate_gear_parameters(teeth, module, power, rpm, material_strength)
st.subheader("Results")
for key, value in results.items():
st.write(f"**{key}:** {value:.2f}")
st.success("Calculation complete!")
else:
st.info("Enter values and press 'Calculate' to see results.")