Controllers

Close the position or velocity loop in Motorcortex when the drive runs CSV or CST, and tune the two PID controllers.

In CSP the drive closes every loop, and the two controllers stay off. When the drive runs CSV or CST, Motorcortex closes the outer loops itself: the position controller turns a position error into a velocity or a torque, and the velocity controller turns a velocity error into a torque. This is the cascade for a position setpoint with a drive in CST:

Motorcortex Drive Position setpoint Position loop Velocity loop Torque loop Motor Target torque · 6071 Position actual 6064 · Velocity actual 606C

Which controllers to switch on

Setpoint Drive mode Position controller Velocity controller Guide
Position CSP off off Position with CSP
Position CSV on, output velocity off Position with CSV
Position CST on on Position with CST
Velocity CSV off off Velocity with CSV
Velocity CST off on Velocity with CST
Torque CST off off Torque with CST

Inside a controller

Both controllers are the same PID controller. The control error goes through a proportional, an integral and a derivative part; their sum is limited to the output range.

controlError target − actual proportionalGain P: reacts to the error now integratorGain I: held in controlIntegrationMin…Max derivativeGain D: smoothed by derivativeFilter + Output limit controlOutputMin…Max controllerOutput

The settings are under actuatorControlLoopNN/positionController/parameter/ and actuatorControlLoopNN/velocityController/parameter/:

Parameter What it does Default
enable Switch the controller on 0
proportionalGain Output per unit of error 0
integratorGain How fast a remaining error builds up output 0
controlIntegrationMin, controlIntegrationMax Range of the integral part. At 0, 0 the integral part does nothing, whatever integratorGain is 0, 0
derivativeGain Output per unit of error change 0
derivativeFilter Smooths the derivative part. At 0 the derivative part does nothing 10
controlOutputMin, controlOutputMax Range of the output: rad/s or Nm -100, 100
controlErrorDeadBand The integral part ignores errors smaller than this 0
backCalculationGain Pulls the integral part back while the output is at its limit 0

The controllers only run while the axis is engaged. To watch one at work, plot input/controlError and output/controllerOutput in Desk; output/integratorOutput and output/derivativeOutput show the parts.

To find the gains, follow Tune the controllers.


The position controller works on actuatorPositionError, the position target minus the actual position. Its output goes one of two ways, set by actuatorControlLoopNN/positionController/usePositionControlForTorque:

usePositionControlForTorque Output Use with
0 (default) A velocity, added to the velocity target CSV, or CST together with the velocity controller
1 A torque, added to the torque target. The velocity controller’s output is then not used CST without a velocity loop

Tune it

Follow Tune the controllers, after the velocity controller if you use it. For the position controller:

  • controlOutputMin and controlOutputMax are in rad/s or m/s, or in Nm with usePositionControlForTorque at 1.
  • Watch actuatorPositionError and positionController/output/controllerOutput.

Compensate for delay

positionController/delayForControlError/numberOfSamplesTarget and numberOfSamplesActual delay the target or the actual by up to 10 cycles before the controller forms the error. Use them when the actual position lags the target by a fixed number of cycles, so that the controller compares values from the same moment.


The velocity controller works on actuatorVelocityError, the velocity target minus the actual velocity. Its output is a torque in Nm, added to the torque target, so it only makes sense when the drive runs CST. The velocity target is the setpoint’s velocity plus the position controller’s output, if that is on.

Tune it

Tune the velocity controller first when you use both: the position loop can only be as good as the velocity loop inside it. Follow Tune the controllers. For the velocity controller:

  • controlOutputMin and controlOutputMax are the torque the motor may deliver, in Nm at the load.
  • Watch actuatorVelocityError and velocityController/output/controllerOutput.