Skip to main content

Some applications require driving to a known position based on normal encoder-based feedback, then switching to an analog signal for feedback, and then returning to the encoder-based data.  Even as the controller drives the motor based on analog data, the encoder continues to turn, and the incremental position change would be lost without additional programming.  An example would be screw insertion.  The servo-controller driver can turn a screw N turns, and then to tighten, switch to a force-feedback device that outputs an analog signal.  After the screw is tightened to X N-m, the driver might need to return to a know encoder position and continue on to the next insertion.

An additional task is to have two sets of PID, one for encoder-based feedback, one for analog-based feedback.  When changing modes, the program must toggle between these gain sets.  Special care must be taken to avoid large changes in motor command voltage.

One method of retaining the encoder feedback is to daisy-chain the encoder data into both the Main and Aux encoder inputs.  When it's time to enter Analog Feedback mode, the program can store the current encoder position in a variable.   Then, when the Main encoder data becomes overwritten by the analog data,  the controller 'remembers' the location of the change.  Once the analog-based action is complete, you can read the variable, compare to the current Aux encoder position, and calculate a move back to the point of feedback transition. Example code below:

#FDBKSWP
NOTE THIS ROUTINE STORES QUAD ENCODER DATA
NOTE WHEN SWITCHING TO ANALOG FEEDBACK MODE
NOTE AND RETURNING TO THIS POINT AFTER EXITING AF MODE
#START
AF0;'QUADRATURE FEEDBACK
DP0;'CLEAR MAIN ENC REGISTER
DE0;'CLEAR AUX ENC REGISTER
NOTE PID FOR ENCODER FEEDBACK
KpENC=20;KdENC=200;KiENC=.1
NOTE PID FOR ANALOG FEEDBACK
KpAF=2;KdAF=5;KiAF=1
#MOVE
NOTE USE ENCODER GAIN
KPA=KpENC;KDA=KdENC;KIA=KiENC
SHA
SPA=1000
PRA=10000;'MOVE 10000 ENCODER COUNTS
BGA
MCA
WT10
Encval=_TDA;'STORE QUADRATURE ENCODER VALUE
AF1;'SWITCH TO AF MODE
NOTE USE ANALOG GAIN
KPA=KpAF;KDA=KdAF;KIA=KiAF
PAA=1024;'DRIVE TO 5V
BGA
MCA
WT10
AF0
NOTE USE ENCODER GAIN
KPA=KpENC;KDA=KdENC;KIA=KiENC
DPA=_TDA;'REDEFINE MAIN ENC VALUE BASED ON PRIOR STORED VALUE
WT2
PAA=Encval;'GO BACK TO STORED POSITION
BGA
MCA
EN