Simvik

Robot arm: steps for a joint move

Convert a joint's move in tenths of a degree into stepper microsteps through a gearbox. A medium embedded C problem (Motors), run and graded in the browser.

medium · Motors · stepper · microstepping · rounding · product

Product: Robot arm (Robotics)

Requirement. Each joint of the arm is a stepper motor with 200 steps per revolution, driven at 16 microsteps per step, through a 5:1 gearbox. The motion planner gives the joint's start and end angles in tenths of a degree.

Return the signed number of microsteps for the move, rounded to the nearest step (halves away from zero). Moves can be many turns long.

Starter code

int32_t joint_steps(int32_t from_deg10, int32_t to_deg10) {
  return (to_deg10 - from_deg10) / 3600 * 16000;
}

Example tests

A quarter turn each way

printf("%d %d\n", joint_steps(0, 900), joint_steps(900, 0));

Expected output:

4000 -4000

Small moves round to the nearest step

printf("%d %d\n", joint_steps(0, 1), joint_steps(0, 5));

Expected output:

4 22

Learn it first

More Motors problems