You are on page 1of 7

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/234065316

Automatic Calibration of Sinusoidal Encoder Signals

Conference Paper in IFAC Proceedings Volumes · July 2005


DOI: 10.3182/20050703-6-CZ-1902.01190

CITATIONS READS

41 896

1 author:

Silvano Balemi
University of Lugano
61 PUBLICATIONS 1,015 CITATIONS

SEE PROFILE

All content following this page was uploaded by Silvano Balemi on 28 November 2022.

The user has requested enhancement of the downloaded file.


Copyright (c) 2005 IFAC. All rights reserved
16th Triennial World Congress, Prague, Czech Republic

AUTOMATIC CALIBRATION OF
SINUSOIDAL ENCODER SIGNALS

Silvano Balemi

University of Applied Sciences of Southern Switzerland


Department of innovative technologies (SUPSI-DTI)
CH-6928 Lugano-Manno

Abstract: Precision positioning and manipulation systems often rely on data from
sensors delivering a sinusoidal signal pair. These signals can be interpolated to
provide a high resolution measurement.
The paper presents a novel method for removing signal differences and drifts by
automatic self-calibrating the sinusoidal signal pair. Then, manual calibration is
avoided and slow varying effects, like thermal drifts or imprecise sensor mounting,
can be effectively compensated.
The proposed method can be implemented on a DSP. It uses an on-line gradient
search to minimize a given performance index. c
Copyright °2005 IFAC

Keywords: Precision Control, Sinusoidal encoders, Measurement interpolation,


Measurement calibration.

1. INTRODUCTION line by measuring and evaluating the extremes of


the two signals. This is not satisfactory because
Precision positioning and manipulation systems the signals may be affected by additional non-
often rely on data from sensors delivering a si- linearities or by noise, which influence the com-
nusoidal signal pair. From the signal pair, a high putation of the correction.
resolution measurement can be obtained with res-
olutions of more than 1000 times finer than the A different approach (Venema and Hannaford,
length of the signal period. 1995) makes use of the dynamics of the system
to be controlled. It estimates the position by
Unfortunately, the signal pair is often affected exploiting the known model of the system and
by different gains and unknown offsets which by considering the effect of gains and offsets
may depend on the individual sensor or even on as noise to be filtered out. However, this may
the mounting. Additionally, these quantities may deliver unsatisfactory results during slow motions,
change during time because of thermal drifts or of in particular if the signal pair is affected by
dirt affecting the sensor. unmodeled effects. Moreover, the estimation must
The compensation of these effects can be per- be tailored for the system to be controlled, and
formed either in software or implemented in digi- can not be used in a standalone, generic sensor.
tal interpolation circuits which deliver a position The method presented in this paper relies on
measurement based on the signal pair. In both an on-line computation of the correction parame-
cases, gains and offsets are often corrected on- ters, i.e. it calibrates the sensor during operation.
Then, both effects due to the sensor mounting or
1 The author wishes to thank Stephen Boyd for valuable to the characteristics of the individual sensor and
suggestions slow varying changes can be compensated.

68
The paper first presents three different variations
¾
of a discrete-time, digital interpolation algorithm ´ cos(α̂)
´
which is inspired by an equivalent closed-loop sin(α)- l ´

analog circuit. Then it recalls the Heydemann ×
correction method, an off-line parameter compen- @
@+
R je -
@ α̂
sation based on a least-square minimization. It -
filter
then proceeds with a variation of the Heydemann ¡
µ−
¡
correction, which is suitable for on-line use and cos(α)- ×l
¡
finally presents a new search method based on the
H
Y
HH
minimization of the residual compensation error.
H sin(α̂) ¾

2. SIGNAL INTERPOLATION Fig. 2. Closed-loop estimation of α = ksincos · x


showing that the signal e approximates the error
A sinusoidal interface encoder provides two sig- between the value of α and its estimate α̂. As
nals: sin(α) and cos(α). For a displacement sensor shown in Figure 3, α̂ converges to the value of
(see Figure 1) the angle α is given by α for stable closed-loops.
2·π
α = ksincos · x = ·x (1) α - j -
e α̂ -
lperiod filter
+ 6−
where x indicates the displacement and lperiod the
signal period length when increasing x. Fig. 3. Simplified interpolation closed-loop system
sin(α)-
α = k · x- From α̂ it is then possible to obtain the position
Encoder - α̂
estimate with x̂ = ksincos .
cos(α)
Fig. 1. Sinusoidal encoder signals in function of 4. THE DIGITAL FILTER
the displacement x
A digital implentation of the closed-loop circuit
Most digital interpolators first square the sinu- above is already object of a DSP application note
soidal signals and deliver the position with a reso- of AnalogDevices (2000). In this section three
lution of lperiod /4 like in quadrature encoders. The possible choices of the discrete-time filter are
estimate within the quarter of period is given by presented. Our objective is to estimate both the
µ ¶ position and the speed of the motion.
sin(α)
α̂ = arctan
cos(α)
4.1 Method 1: Second order filter and position
either by computing the trigonometric function or derivative
by using a table with the two signal pair values
as inputs. Common to all these implementations For the filter shown in Figure 2 the following
is the difficulty in obtaining precise estimates in second order discrete-time realization is proposed.
presence of signal non-linearities and/or of noise.
Nfilter (z) z·a+b
Gfilter (z) = = 2 (2)
Dfilter (z) z +z·c+d
3. THE CLOSED-LOOP INTERPOLATION
Two discrete-time closed-loop poles
¡ √ ¢
Before the advent of digital interpolators, interpo- −ω ·t · ξ− ξ 2 −1
p1 = eps1 ·Ts = e 0 s
lation was performed using an analog control loop ¡ √ ¢
ps2 ·Ts −ω0 ·ts · ξ+ ξ 2 −1
circuit having the characteristic of a low-pass filter p2 = e =e
(see Figure 2). Then, signal non-linearities as well
as measurement noise can be filtered out. are chosen with appropriate frequency ω0 and
damping coefficient ξ. Then, the discrete-time
The signal e at the input of the filter is given by desired characteristic polynomial is:
e = sin(α) · cos(α̂) − cos(α) · sin(α̂) = sin(α − α̂) Dcl (z) = (z − p1 ) · (z − p2 )
= z 2 − (p1 + p2 ) · z + p1 · p2
and for small values of α− α̂ it is possible to write:
If the filter denominator z 2 + z · c + d is given,
e = sin(α − α̂) ≈ α − α̂ it is possible to obtain the desired closed-loop

69
denominator by choosing an appropriate filter Then, comparison of the desired closed-loop de-
numerator. In fact: nominator with the denominator of the closed-
Ncl (z) Nfilter (z) loop transfer function yields the coefficients
Gcl (z) = = (3) 
Dcl (z) Nfilter (z) + Dfilter (z)  p1 · p2 − p1 − p2 + 1
a=
ts
the comparison of the two denominators Dcl (z) b = p ·p 1 2
and Nfilter (z) + Dfilter (z) yields
Nfilter (z) = Dcl (z) − Dfilter (z) Note that the filter pole b is used to place the
closed-loop poles. Thus, the second filter pole
= z · (−p1 − p2 − c) + p1 · p2 − d cannot be freely chosen and it is impossible to
implement a filter of type 2.
The speed is computed by taking the derivative of
the position estimate, thus causing extra on-line
computational load (see Figure 4). 4.3 Method 3: Second order stage and integrator

z−1
1/ksincos 2 Finally, for the filter shown in Figure 2 a second
1
ts.z
v order realization is proposed with the structure
filter Derivator
sin
n(z)
shown in Figure 6.
1/ksincos 1
d(z)
2 x
cos 1/ksincos/ts 2
cos 1 v
angle filter
sin sin
a.z+b z
1/ksincos 1
z2−cz z−1
Fig. 4. Closed-loop interpolator with speed esti- 2
integr./ts
x
cos
mate from position derivative cos
angle
sin

Zero steady state error is achieved, if the filter is


of type 1, i.e. if at least one of the filter poles is Fig. 6. Closed-loop interpolator with speed esti-
at 1. Choosing both poles at 1 (the filter is then of mation without derivation
type 2) also guarantees that a ramp (i.e. caused by
a constant motion) can be followed without error. Apparently, the filter is a third order one. In
reality, for the choice of a filter of type 1 or
higher, the resulting parameters are the same as
4.2 Method 2: First order stage and integrator in Method 1 with the only difference that an
additional pole and a zero at the origin are now
The second order filter can be separated into two present, which cancel out in the filter transfer
first order terms as in Figure 5. function.
The advantage of this form is that the most recent
1
1/ksincos 2
v
estimate of the speed can be extracted while it is
sin filter also possible to implement a second order type 2
a ts.z
1/ksincos 1 filter.
z−b z−1
2 x
cos integrator This form does not cause additional divisions and
cos multiplications. The only price to pay with respect
angle
sin
to Method 1 is one additional variable definition
and a variable copy per cycle.
Fig. 5. Closed-loop interpolator with speed esti-
mation without derivation
Thanks to the integral term z−1 ts ·z
, the speed is 5. CALIBRATION
obtained without having to explicitly taking the
derivative of the position estimate. The signals measured in Figure 2 are not ideal
but are affected by offsets, unknown gains, phase
The two desired closed-loop poles can be chosen shift differences between the two signals and by
as in Method 1. With the filter of the form non-linearities.
a ts · z
Gfilter (z) = · Considering the effect of gains, offsets and phase
z−b z−1 shifts only, the signal pair measured can be ex-
pressed by
the closed-loop transfer function becomes
ts · z · a yc,k = ac · cos αk + bc
Gcl (z) = (4)
ys,k = as · sin(αk − β) + bs
z 2 + z · (a · ts − b − 1) + b

70
5.1 Heydemann correction 5.2 Gradient search: correction of gains and offsets

A calibration method has been proposed by Hey- A first idea would be to use a gradient search giv-
demann (1981) (see also (Birch, 1990)). This cor- ing directly the correction parameters. Consider-
rection relies on a least-square estimate and on ing only the effect of gains and offset, equation (4)
the solution of a set of non-linear equations. reduces to
The measurements given by equation (4) can be yc,k = ac · cos αk + bc
rearranged as ys,k = as · sin αk + bs
1 −bc
· yc,k + = cos(αk ) This expression can be rewritten as
ac ac
1 −bs
· ys,k + = sin αk · cos β − cos αk · sin β θ1 · yc,k + θ2 = cos αk
as as θ3 · ys,k + θ4 = sin αk
After replacement of cos(αk ) in the second expres-
sion and introduction of the notation gc = 1/ac where θ1 = 1/ac , θ2 = −bc /ac , θ3 = 1/as and
and gs = 1/as the equations above can be rewrit- θ4 = −bs /as . The trigonometric equality used
ten as before can be rewritten as
gc · (yc,k − bc ) = cos(αk ) kM · Θk22 = 1
gs · (ys,k − bs ) + (gc (yc,k − bc ) · sin β
= sin(αk ) where Θ = [θ1 , θ2 , θ3 , θ4 ]0 and
cos β
µ ¶
yc,k 1 0 0
The equality sin2 α + cos2 α = 1 gives M= (6)
0 0 ys,k 1
θ1 · yc2 + θ2 · ys2 + θ3 · yc · ys + θ4 · yc + θ5 · ys = 1
The minization of the error kMk · Θk22 − 1 leads to
with the objective function
gc2 X X
θ1 = J= ²2k = (kMk · Θk22 − 1)2
K · cos2 β k k
gs2
θ2 =
K · cos2 β to be minimized. The corresponding gradient is
2gc gs sin β X
θ3 =
K · cos2 β (5) ∇J = 4 · Mk0 · Mk · Θ · (Θ0 · Mk0 · Mk · Θ − 1)
2gc k
θ4 =− (gc bc + gs bs sin β)
K · cos2 β
2gs which can be used off-line for estimating Θ and
θ5 =− (gs bs + gc bc sin β)
K · cos2 β thus the parameters ac , bc , as and bs . This is
g b + gs2 b2s + 2gc bc gs bs sin β
2 2
performed by iterating Θ → Θ − γ · ∇J with a
K =1− c c
cos2 β suitably small γ. Note that explicit estimate of
the offsets and of the gains is not needed. The
or equivalently estimate of the parameter vector Θ is sufficient
[yc2 , ys2 , yc · ys , yc , ys ] · [θ1 , θ2 , θ3 , θ4 , θ5 ]0 = 1 for the calibration of our measurements.
| {z } | {z }
Y Θ An on-line version can be implemented in various
ways, e.g. by calculating the gradient over a num-
For a set of measurement pairs the equation ber of steps before updating Θ or also by comput-
extends to the equation set ing a time-smoothed version of the gradient with
Y·Θ=1 a forgetting factor λ as in the following formula

Then the least square estimate ∇Jk = 4 · Mk0 · Mk · Θ · (Θ0 · Mk0 · Mk · Θ − 1)


Θ̂ = (Y0 · Y)−1 · Y0 · 1 + λ · ∇Jk−1

can be computed. Unfortunately, the parameter-


scannot be used to directly compensate the mea- 5.3 Gradient search: correction of gains, offsets
surements yc and ys . Given Θ̂ the set of non- and phase shifts
linear equations (5) must be solved for the five
compensation parameters gc , bc , gs , bs and β. The The phase difference between the two sinusoidal
necessary computational complexity is high and signals in the measurement is not always exactly
makes this method unsuitable for on-line use. 90 degrees. The gradient search with elimination

71
P
of the angle α can be extended, like in the Hey- Consider the objective function J = 2
k krk k .
demann correction, to include the estimate of the The first order approximation of J with respect
phase deviation β from the ideal 90 degrees. Then to a parameter variation δΘ is
the equations for the compensation of the two X X X
2 2
measurements (4) can be rewritten as krk +∇rk δΘk ≈ krk k +2· rkT ·∇rk · δΘ
k k k
θ1 · yc,k + θ2 = cos(αk )
θ3 · ys,k + θ4 + θ5 · yc,k = sin(αk ) The objective function value can be reduced with
the following choice of the parameter update:
1 bc 1
where θ1 = ac , θ2 = − ac , θ3 = as cos β , θ4 = X
bc ·tan β δΘ = −γ · (∇rk )T · rk
bs
− as cos β − ac and θ5 = tan β
ac . Similarly to the k
previous gradient search, the new matrix
µ ¶
yc,k 1 0 0 0 where the small scalar value γ controls the speed
M= (7)
0 0 ys,k 1 yc,k of convergence of the parameter vector Θ.
The gradient ∇rk is
can be defined together with a five element vector
Θ which delivers the five compensation parame-  T
ters. Again, no explicit estimate of offsets, gains yc,k + sin α̂k · ∂θα̂1k − cos α̂k · ∂θα̂1k
and phase difference has to be computed.  1 + sin α̂ · ∂ α̂k − cos α̂k · ∂θα̂2k 
 k θ2 
∇rk =  
 sin α̂k · ∂θα̂3k ys,k − cos α̂k · ∂θα̂3k 
sin α̂k · ∂θα̂4k 1 − cos α̂k · ∂θα̂4k
5.4 Gradient search: correction of non-linearities
µ ¶ µ ¶
The sinusoidal signals may be affected by non- yc,k 1 0 0 sin α̂k
= + · ∇α̂k
linearities given by the general expression 0 0 ys,k 1 − cos α̂k
| {z }
Mk
yc,k = fc (cos αk ) ys,k = fs (sin αk )
where Mk is again the matrix of equation (6).
Assuming that the non-linearities are invertible
(which is reasonable in practice) the inverse func- For ∇α̂k take the recursive equation
tions α̂k+1 = −c · α̂k − d · α̂k−1 + a · ek + b · ek−1 (9)
fc−1 (yc,k ) = cos α fs−1 (ys,k ) = sin α
from the filter (2). Then
can be defined. For the functions fc−1 and fs−1
∇α̂k+1 = −c·∇α̂k − d·∇α̂k−1 + a·∇ek + b·∇ek−1
a third order polynomial approximation can be
chosen, which leads to
Consider now the error
2 3
θ1 · yc,k + θ2 · yc,k + θ3 · yc,k + θ4 = cos αk
2 3 ek = (θ3 ·ys,k + θ4 )·cos α̂k − (θ1 ·yc,k + θ2 )·sin α̂k
θ5 · ys,k + θ6 · ys,k + θ7 · ys,k + θ8 = sin αk
The steps defined in sections 5.2 and 5.3 can be The derivative of ek with respect to θ1 is
re-applied here with the only difference that the ∂ek
matrix M is now of the form = −yc,k · sin α̂k
µ ¶ ∂θ1
2 3
yc,k yc,k yc,k 1 0 0 0 0 ∂ α̂k
M= 2 3 −(θ3 ·ys,k + θ4 )·sin α̂k ·
0 0 0 0 ys,k ys,k ys,k 1 ∂θ1
∂ α̂k
and that there are 8 compensation parameters θi . −(θ1 ·yc,k + θ2 )·cos α̂k ·
∂θ1
and considering that θ3·ys,k +θ4 ≈ sin αk and that
5.5 Gradient based on residual θ1 ·yc,k + θ2 ≈ cos αk the gradient

The calibration methods above require com- ∂ek ∂ α̂k


= −yc,k · sin α̂k − cos(αk − α̂k ) ·
plex computations. Moreover, static measure- ∂θ1 ∂θ1
ments (constant x) may bias the estimates. An-
other method considers the error residuals is obtained. Finally, for α̂k ≈ αk
µ ¶
θ1 · yc,k + θ2 − cos α̂k ∂ek ∂ α̂k
rk = (8) = −yc,k · sin α̂k −
θ3 · ys,k + θ4 − sin α̂k ∂θ1 ∂θ1

i.e. the error between the estimated sine and Proceeding in the same way for the other variables
cosine values and the compensated measurements. the gradient ∇ek can be obtained

72
 T The simulation of Figure 7, where the parame-
−yc,k · sin α̂k
 − sin α̂k  ter update at time k is δΘk = −γ · (∇rk )T ·
∇ek =   −∇α̂k (10) rk , shows how the compensation parameters for
ys,k · cos α̂k
cos α̂k offsets, gains and phase difference converge ap-
| {z } proximately to the corresponding parameter val-
wk
ues from the Heydemann correction (for mea-
surements affected by additional distortions, the
Now, with this equation
estimates are necessarily identical, because the
∇α̂k+1 = −(c + a)·∇α̂k − (d + b)·∇α̂k−1 objectives functions are different).
+a·wk + b·wk−1 (11) 1.6

Then the parameter update can be expressed as 1.4

Xµ µ ¶ ¶T 1.2
sin α̂k
δΘ = −γ · Mk + · ∇α̂k · rk
− cos α̂k 1

k
0.8

where wk comes from (10) and ∇α̂k from (11). 0.6

0.4

5.5.1. Approximation of the gradient The gra-


dient ∇rk can be simplified by noting that equa-
0.2

tion (11) corresponds to the equation of the 0

closed-loop (3) with w as input and ∇α̂ as ouput.


−0.2
0 0.5 1 1.5 2 2.5
The closed-loop system is stable and well damped 4
x 10

(by design). Because the filter is of type 2, the


steady-state amplification is 1. Assuming that the Fig. 7. Simulation of the 5 parameter update
dynamics of the measured system are slower than for compensation of offsets, gains and phase
the dynamics of the interpolator closed-loop, ∇α̂k difference.
can be approximated by wk . Then the parameter
update becomes
6. CONCLUSIONS
Xµ µ
sin α̂k
¶ ¶T
δΘ = −γ · Mk + · wk · rk In this papers a novel method for calibrating on-
− cos α̂k
k
à line the compensation parameters for measure-
X µ ¶T !
sin α̂k
ments from sinusoidal encoders is discussed. It
= −γ · MkT · rk + wkT · · rk limits the on-line computation burden, thus al-
− cos α̂k
k lowing its implementation on standard hardware
and with the definition (8) for rk components like DSPs.

X¡ The implementation on a fixed-point DSP will


¢
δΘ = −γ · MkT · rk − wkT · ek follow soon.
k

Further noting that REFERENCES


wk = ( − sin α̂k cos α̂k ) · Mk AnalogDevices (2000). Closed-loop position esti-
mation with signal compensation for sinu-
the final form soidal encoders with the AMD401. Technical
Report AN401-23. Analog Devices Inc.
X µ µ ¶ ¶
sin α̂k Birch, K. P. (1990). Optical fringe subdivision
δΘ = −γ · MkT · rk + · ek with nanometric accuracy. Precision Engi-
− cos α̂k
k
neering 12(4), 195–198.
is obtained. Because the value of ek is already Heydemann, Peter L. M. (1981). Determination
needed for the closed-loop interpolation, the cal- and correction of quadrature fringe measure-
culation of δΘ only involves 6 additional multipli- ment errors in interferometers. Applied Optics
cations and 6 additions per cycle. 20(19), 3382–3384.
Venema, Steven and Blake Hannaford (1995).
Of course, the idea above can be extended to the
Kalman filter based calibration of precision
compensation of the phase difference or to the
motor control. In: Proceedings of IROS, Pitts-
compensation of a general non-linearity as shown
burgh, PA, USA.
previously for the first search method.

73
View publication stats

You might also like