This page contains a partial description of the EMC2 software stepgen component behavior, as of EMC 2.3.0. It should be read in conjunction with [src/hal/components/stepgen.c]
stepgen provides three functions:
- capture-position: This function normally runs in the slower SERVO tread, before the motion controller. It computes the stepgen's current position and makes it available to HAL. The position feedback information is normally connected (by HAL) to the motion planner.
- update-freq: This function normally runs in the slower SERVO thread, after the motion controller. It takes a position command from the motion planner (via HAL) and computes a step frequency and direction command for the make-pulses function. This is where the magic happens.
- make-pulses: This function normally runs in the fast BASE thread. It gets a step frequency command from the update-freq function. It implements this command (while obeying waveform timing requirements) and outputs the step control signals to HAL. make-pulses' step control signals are normally connected to HAL pins representing physical IO pins, such as parport.0.pin-X-out.
Each stepgen instance has an internal variable called accum, which is a large fixed-point variable tracking the current stepgen position with sub-step accuracy.
- accum is increased (or decreased, depending on direction) by make-pulses whenever the stepgen is moving. The size of the change of accum is determined by the step-frequency command (produced by update-freq) and by the user-specified acceleration limits.
- The capture-position function computes stepgen.position-fb from accum by discarding the fractional part and dividing by stepgen.scale.
The update-freq function:
- The update-freq function (when operating in position-control mode) implements a first-order feedforward controller with proportional feedback. That is, the output (the desired velocity) is a function of both the derivative of the position command and the positional error. The computed velocity command is equal to the estimated velocity of the position command (previous to current), plus a smallish P component (difference between position-feedback and position-command).
- Each stepgen instance has an internal variable called target_addval, which is computed by update-freq and used by make-pulses. This variable is a cooked internal version of the stepgen.freq parameter, which reports the stepgen's current desired step-frequency.