This page shows how to combine two position feedback devices into two PID's for the tuning and positioning of one axis.
- This example has one high resolution linear scale on the axis table and one rotary encoder on the axis drive motor.
- This could also be a rotary encoder on the ballscrew and a rotary encoder on the motor
- This assumes the PID's are loaded and connected to the servo thread
- linear scale position feedback connects to the input of the pid.4 PID
- net X-linear-pos-fb 'linear position feedback' pid.4.feedback
- motor encoder position feedback connects to the feedback input of the pid.0 PID
- net X-motor-pos-fb 'axis motor position feedback' pid.0.feedback
- position command signal from LinuxCNC axis connects to both PID command inputs
- net Xpos-cmd axis.0.motor-pos-cmd pid.0.command pid.4.command
- bit signals from LinuxCNC axis connnects to enable/disable both PID loops
- net Xenable axis.0.amp-enable-out pid.0.enable pid.4.enable
- set PID loop output limits as specified in ini file
- setp pid.0.maxoutput [AXIS_0]PID_MAX_VEL
- setp pid.4.maxoutput [AXIS_0]PID_MAX_VEL
- set the motor encoder PID loop gains
- NOTE - I gain is set to zero - it would fight the other PID
- setp pid.0.Pgain [AXIS_0]P
- setp pid.0.Igain 0
- setp pid.0.Dgain [AXIS_0]D
- setp pid.0.bias [AXIS_0]BIAS
- setp pid.0.FF0 [AXIS_0]FF0
- setp pid.0.FF1 [AXIS_0]FF1
- setp pid.0.FF2 [AXIS_0]FF2
- setp pid.0.deadband [AXIS_0]DEADBAND
- setp ppmc.0.DAC.00.scale [AXIS_0]OUTPUT_SCALE
- set the linear scale PID loop gains
- NOTE - it has only I gain - all other gains are set to zero
- setp pid.4.Pgain 0
- setp pid.4.Igain [AXIS_0]I
- setp pid.4.Dgain 0
- setp pid.4.bias 0
- setp pid.4.FF0 0
- setp pid.4.FF1 0
- setp pid.4.FF2 0
- setp pid.4.deadband [AXIS_0]DEADBAND
- connect both PID output signals to sum2.4 inputs
- sum the outputs of pid.0 and pid.4
- pid.0 is using motor encoder feedback
- pid.4 is using linear scale feedback
- net Xoutput-motor pid.0.output sum2.4.in0
- net Xoutput-linear pid.4.output sum2.4.in1
- the summed PID output is connnected to the DAC input signal
- net Xoutput sum2.4.out 'DAC input'
- repeat as necessary for more axes
It seems redundant to measure the same axis twice, with two encoders.
But often that gives significantly better results than using a single encoder.
Whether it is two different kinds of sensor -- gyro, accelerometer, GPS .
Or two identical sensors in two different locations, one with accuracy but bad latency, the other with good (low) latency but bad accuracy:
Bob Pease, "What's All This P-I-D Stuff, Anyhow?"