DEV Community

Cover image for Convert Linear Travel Into Motor RPM and Step Pulses With Python
Orion Jiang
Orion Jiang

Posted on

Convert Linear Travel Into Motor RPM and Step Pulses With Python

When controlling a screw-driven linear axis, the motion command usually begins in millimeters, but the motor operates in revolutions and step pulses.

A small conversion function can help answer three useful questions:

How many motor revolutions are required?
What motor speed is needed?
How many step pulses should the controller generate?
The Basic Relationship

For a screw with a lead of 10 mm per revolution:

10 mm of travel = 1 screw revolution

A 120 mm move therefore requires 12 revolutions.

Motor speed depends on both the desired linear speed and the screw lead.

Python Function
def calculate_axis_motion(
distance_mm,
speed_mm_s,
screw_lead_mm_rev,
motor_steps_rev=200,
microsteps=16
):
revolutions = distance_mm / screw_lead_mm_rev

motor_rpm = (
    speed_mm_s * 60 / screw_lead_mm_rev
)

step_pulses = (
    revolutions
    * motor_steps_rev
    * microsteps
)

pulse_frequency_hz = (
    motor_rpm
    / 60
    * motor_steps_rev
    * microsteps
)

return {
    "revolutions": revolutions,
    "motor_rpm": motor_rpm,
    "step_pulses": step_pulses,
    "pulse_frequency_hz": pulse_frequency_hz
}
Enter fullscreen mode Exit fullscreen mode

result = calculate_axis_motion(
distance_mm=120,
speed_mm_s=80,
screw_lead_mm_rev=10
)

for key, value in result.items():
print(f"{key}: {value:.2f}")

Expected output:

revolutions: 12.00
motor_rpm: 480.00
step_pulses: 38400.00
pulse_frequency_hz: 25600.00

If you are unfamiliar with the mechanical components behind this conversion, this ball screw actuator working guide explains how the motor, coupling, screw, ball nut, carriage, and support structure work together.

Important Limitations

This calculation assumes:

Direct motor-to-screw transmission
No gearbox or belt reduction
Constant screw lead
No lost motion
The selected microstepping setting remains fixed

It also does not confirm whether the motor can produce enough torque at the calculated RPM. Acceleration, load inertia, friction, screw efficiency, critical speed, and controller pulse limits must still be checked.

The calculation tells the controller how far and how fast to command the axis. It does not guarantee that the mechanics can follow.

Still, it is a useful first bridge between a CAD dimension and an actual motion-control command.

Top comments (0)