# Tactiverge Academy — companion code for "Gears, belts and transmissions"
# Lesson: https://tactiverge.win/academy/mechanical-design/mechanical-systems/gears-belts-transmissions/
# Licence: MIT (see https://tactiverge.win/open-engineering/). Examples appear in lesson order.

# ── Example 1 ────────────────────────────────────────
import math

motor_torque = 0.05      # N·m
motor_speed_rpm = 6000
stages = [(12, 120), (10, 50)]   # (driver teeth, driven teeth) for each stage
efficiency_per_stage = 0.95

ratio = 1.0
for driver, driven in stages:
    ratio *= driven / driver

efficiency = efficiency_per_stage ** len(stages)
out_speed_rpm = motor_speed_rpm / ratio
out_torque = motor_torque * ratio * efficiency

def rpm_to_rad_s(rpm):
    return rpm * 2 * math.pi / 60

p_in = motor_torque * rpm_to_rad_s(motor_speed_rpm)
p_out = out_torque * rpm_to_rad_s(out_speed_rpm)

print(f"Overall ratio: {ratio:.0f}:1")
print(f"Output speed:  {out_speed_rpm:.0f} rpm")
print(f"Output torque: {out_torque:.3f} N·m")
print(f"Power in: {p_in:.1f} W, power out: {p_out:.1f} W")
