Using the image acquisition capabilities of the optical mouse sensor to build an
absolute rotary encoder
M. Tresanchez, T. Pallej, M. Teixid, J. Palacn
Departament of Computer Science and Industrial Engineering, Universitat de Lleida, Jaume II, 69, 25001 Lleida, Spain
a r t i c l e
i n f o
Article history:
Received 6 August 2009
Received in revised form 8 October 2009
Accepted 4 November 2009
Available online 13 November 2009
Keywords:
Optical mouse sensor
Rotary encoder
a b s t r a c t
In this paper, the optical mouse sensor is proposed as the main sensor of an absolute rotary encoder.
The image acquired by the optical sensor is used to read a positioning binary code printed on an internal
rotary surface to obtain the absolute rotary position. The two-dimensional image matrix acquisition is
more robust than the single reading point approach used in other absolute rotary encoders (with only
one pixel) where the position must be coded using random sequence codes. Additionally, the low cost of
the optical sensor facilitates the development of inexpensive absolute rotary encoders.
2009 Elsevier B.V. All rights reserved.
1. Introduction
Since its release in 1999, the optical mouse sensor has been
used widely as an inexpensive displacement sensor [15] but it has
some important drawbacks. It is very sensitive to height changes
[1,2], very dependent on the measurement surface [3], and circular trajectories are measured badly [4,5] because the area under
the sensor is only originally illuminated from one lateral source
[6] which enhances the shadows created by the roughness of the
surface. However, despite these known limitations, a linear displacement can be measured with a coefcient of determination of
R2 = 0.9998 [5].
The optical mouse sensor acquires ground surfaces using an
internal CMOS camera and computes an optimized optical ow
[7] to measure the over ground displacement. The image acquired
by the CMOS camera can be read and used externally, allowing
it to be employed as inexpensive image acquisition device [8] in
applications with low processing capabilities.
Recently, in [9] the optical mouse sensor was proposed to build
an incremental rotary encoder. In this proposal, the optical sensor
was placed at a given radius with a measurement displacement axis
tangential to the center of the rotating surface. The measurement
of the incremental position is prone to errors (0.3% in 200 revolutions at xed angular speed) and the internal registers that give
information about the state of the illumination control loop were
used to detect a radial line printed onto the white rotary surface.
The reference line was used to reset the cumulative displacement
162
Table 1
Smallest information pattern extracted correctly from the optical sensor.
Picture
Sensors image
Segmented image
Table 2
Optical sensor radial dependences.
Placement radius (mm)
2
4
6
8
10
12
14
The paper is structured as follows. Section 2 describes the capabilities of the optical mouse sensor. Section 3 describes the codes
used to print the positioning value on the rotary surface. Section
4 shows the validation of the rotary encoder. Finally, Section 5
presents the conclusions of this paper.
2. Optical sensor capabilities
The optical mouse sensor used in this paper is the ADNS-3088
[12]. This optical sensor includes a digital signal processor (DSP)
and a monochrome CMOS camera of 30 30 pixels embedded in
the same chip. The optical mouse sensor is based on a very compact
image acquisition system with the following parts [12]: the main
optical sensor, an infrared light source (LED-based) that illuminates
the surface, and a convex lens to focus the surface image on the
sensor. All parts are clipped to a base plane to keep the device very
close to the surface, at a nominal distance of 2.4 mm.
In a normal operation, the optical mouse sensor acquires
sequential surface images (size: 1.82 mm 1.82 mm) at a very high
rate (up to 6400 frames per second (fps)) and determines the
direction and magnitude of movement through the analysis of the
small displacements of the shadows created by the source light.
The optical mouse sensor also includes an internal closed control loop to maintain a constant illumination range in the images
acquired and to adapt dynamically the sampling rate to avoid image
blurring.
The internal registers of the optical sensor are accessed by the
standard SPI bus using an 8 bit address and 8 bit data message
requiring a minimum of 50 s for a read/write register operation.
The image acquired by the optical sensor can be accessed pixel by
pixel by reading the PIXEL BURST register sequentially and the rst
access freezes the image to assure that all pixels belong to the same
image. The 30 30 pixels of the monochrome image have intensity
values in a range from 0 (black) to 63 (white).
A rst experiment was developed to test the vision capabilities
of the optical sensor; a series of chess-like information patterns
were printed on a white adhesive surface (A4 paper size with
100 g/m2 weight) [9] using a standard low cost inkjet printer
(1200 1200 point per inch (ppi)). Table 1 shows the pattern with
the smallest information bits (square width of 0.19 mm or 3.3 3.3
pixels to represent an information bit) extracted correctly after
a segmentation procedure: real pictures (Table 1-left, obtained
with macro lens), the images obtained with the optical sensor
(Table 1-center), and the images segmented with a threshold value
(Table 1-right) obtained from the analysis of the histogram of the
images; 24 in the image shown. The image can have up to 9 9
binary bits before aliasing precludes the recuperation of the information from the segmented image. This value is high enough to
implement an absolute rotary encoder based on the reading of a
visual code printed on the internal white rotary surface.
The optical mouse sensor is primarily designed to measure linear displacements. When it is used to measure displacement on a
rotary surface, the maximum distance measured in one exact revolution depends only on the radius of placement of the sensor and
this value xes the resolution of the rotary encoder.
Counts (cpr)
800 cpi
400 cpi
440
794
1190
1584
1982
2364
2746
217
397
594
792
990
1182
1373
pixelREV (pixels)
bitsREV (bits)
203
407
611
815
1018
1222
1426
61
122
183
244
305
366
427
A second experiment was developed to show the radial dependences. The optical sensor was placed at the recommended height
(2.4 mm) over a rotary surface with the y-axis tangential to the
rotation and the inner rotary surface was covered with a rough
white surface to enhance the results of the measurements (additional details of similar experiments can be obtained in [9]). Table 2
shows the radial dependence for some parameters of the optical
sensor measured in one revolution: the counts measured in one
revolution (cpr) when the optical sensor operates as a displacement sensor with a resolution of 800 counts per inch (cpi), the same
for a resolution of 400 cpi, the equivalent number of image pixels
explored in one revolution (labeled pixelREV ), and the equivalent
number of information bits that can be stored in one revolution
(labeled bitsREV ). The last two parameters are computed with:
pixelREV =
2r
,
pixelW
bitsREV =
2r
pixelW
(1)
pixelsBIT
163
Fig. 3. Graphic representation of the complete code. The arrows depict different
coded position values and the dotted square the area visible to the optical sensor.
Fig. 1. Image of a prototype of the absolute rotary encoder.
computed with:
ARMAX =
360
pixelREV
(2)
However, this value is apparently unreachable if any information bit stored in the image is represented by several pixels. Then
the maximum angular resolution achieved by reading any information code, ARCMAX , can be computed with (Fig. 2):
ARCMAX =
360
pixelsBIT
(3)
pixelREV
But the position value obtained from the code can be complemented with the relative location of the code in the image to take
full advantage of the two dimensions in the image. Then, the absolute position in counts, C, and the absolute angle of orientation, ,
can be computed with:
C = value codeSEP + (15 valueCOL ),
= ARMAX C
(4)
valueMAX
(5)
Fig. 2. Maximum angular resolution of the rotary encoder depending on the placement radius of the optical sensor.
The complete code is a proposal that uses all available information bits to store information (Fig. 3). In the complete code, each
column contains a value (indicated with arrows in Fig. 3) with up
to 9 information bits to codify the absolute position (values from 0
up to 512) of the rotary surface. In such conditions, using the 9 bits
available in the columns, the placement radius of the optical sensor
can be up to 16.4 mm from the center of the rotary surface with an
expected resolution of 0.210 (0.703 if not used the information
provided by valueCOL ).
Fig. 4 shows some images of the complete code obtained with
the optical sensor placed 15 mm from the center of rotation of the
rotary surface. The range values stored in the code were from 0
to 470 using 9 bits in the columns (0.20 0.20 mm bits). The row
corresponding to the lowest bit (b0 ) is located approximately in the
center of the image. The resolution obtained with this conguration
is 0.231 or 1553 counts per revolution (cpr).
Fig. 5 shows the procedure to decode the image acquired by
the optical sensor. The row corresponding to the lowest bit (b0 )
164
Fig. 4. Sample images of the complete code obtained with the optical sensor (bit
size is 0.20 mm 0.20 mm).
Fig. 7. Graphic representation of the radial code. The arrows depict different coded
position values and the dotted square the area visible by the optical sensor.
umn of the binary code, valueCOL , with the absolute rotary position
(column 14 in Fig. 5). The width in pixels of the information bits
is xed so the numerical value of the absolute orientation of the
rotary encoder can be obtained using a predened set of sampling
points (squares in Fig. 5). The image shown in Fig. 5 is decoded with:
valueROW = 16, valueCOL = 14, value = 001000101, codeSEP = 3.3, and
then C = 228.7 and = 52.8 (in steps of 0.231 ).
3.2. Radial code
Fig. 5. Image of the complete code acquired by the optical sensor (left) (at a radius
of 15 mm) with the value of the cumulative distance vector, D (right) for all rows.
|dij |
(6)
Fig. 8. Sample images of the radial code obtained with the optical sensor (bit size
is 0.26 mm 0.26 mm).
165
Fig. 11. Sample images of the radial enhanced code obtained with the optical sensor
(bit size is 0.20 mm 0.20 mm).
Fig. 9. Segmented image of the radial code, the prole of the column of the reference
bit (right) and vector sum of the columns (down) of the segmented image.
one positioning code (Fig. 9-circles). From these limits, the prole
of the right information columns is explored (Fig. 9-right) until the
isolate reference bit is detected (Fig. 9-triangle); the central row
detected is identied as the row of the rst bit, b0 . Then, as the
size of the information bits is known, the column can be sampled
at a xed interval (Fig. 9-squares) to decode the absolute position of the rotary surface. The image shown in Fig. 9 is decoded
with: valueROW = 15, valueCOL = 19, value = 0010111, codeSEP = 17,
and then C = 387 and = 89.3 (in steps of 0.231 ).
3.3. Radial enhanced code
row has only one bit set to 1, as a reference bit for rst column
code location. The numerical value of the absolute position is coded
using the bits of three columns, and an additional column is set to
0 to simplify code reading and synchronization. Therefore, using
an information matrix of 9 9 bits, a separation between codes of
20.1 pixels, and 21 bits to store the numerical value of the absolute position; the maximum placement radius is 407.0 m with a
theoretical resolution of 0.0000085 (or 42,153,000 cpr).
Fig. 11 shows some images of the radial enhanced code obtained
with the optical sensor placed 15 mm from the center of rotation
of the rotary surface. The code uses 21 bits per position code (bit
size 0.20 mm 0.20 mm) but at 15 mm, only 7 bits are used (with
values ranging from 0 to 116). In the image, the reference row-line
is located approximately in the center.
Fig. 12 shows the procedure for decoding the image acquired by
the optical sensor. The image is segmented with a xed threshold
intensity value of 22. The cumulative sum of rows (Fig. 12-right)
for the segmented image is computed and its maximum coincides
with the central row of the reference row-line (Fig. 12-circle).
From this reference row-line, the prole of the upper adjacent
row (Fig. 12-down) is explored until the isolate reference bits
are detected (Fig. 12-triangle). Once the position of the reference
row-line and reference bit are known, a xed square sampling
patter is dened to obtain the value of the bits of the absolute
rotary position. The image shown in Fig. 12 is decoded with:
valueROW = 14, valueCOL = 10, value = 0000000-0000000-0010001,
codeSEP = 13.2, and then C = 229.4 and = 52.9 (in steps of
0.231 ).
Fig. 10. Graphic representation of the radial enhanced code. The arrows depict different coded position values and the dotted square, a representation of the area
visible to the optical sensor.
Fig. 12. Segmented image of the radial enhanced code, the vector sum of rows (right)
and prole of the row of the reference bit (down) of the segmented image.
166
Table 3
Decoding error rate.
Code
Complete
Radial
Radial enhanced
0.20 0.20
0.26 0.26
0.20 0.20
Decoded images
10,000
10,000
10,000
Erroneous
223
0
131
4. Encoder validation
Table 3 shows the error rate obtained from decoding the proposed codes with the optical sensor placed at a radius of 15 mm
from the center of the rotary surface. The rotation speed applied
to the encoder changes randomly from 10 to 100 revolutions per
minute (rpm). The images acquired by the optical sensor were
decoded using the proposed procedures. The speed of the rotary
surface (up to 100 rpm) has no blurring effect on the image because
the image sampling rate is up to 6400 fps.
The complete code is only decoded in the central columns of the
image where the illumination level is more uniform, but aliasing
between the pixels of the information bits blurs the image, obtaining a decoding error rate of 2.2%. The error rate of the radial code
is zero in 10,000 image readings because it has the highest bit size
and the lowest aliasing between information bits. In the case of
the radial enhanced code, the sampling prole used to decode the
information bits is very sensitive to small positioning errors caused
by aliasing between the reference line and the reference bit, generating an error rate of 1.3%. The error rate of the complete code
can be reduced to zero by increasing the size of the information
bits although this reduces the number of bits available to code the
positioning value and the maximum placement radius decreases
drastically. In the case of the radial enhanced code, bit size can
be increased greatly to reduce the error rate and the loss of 3 or
even 6 information bits will not have practical design effects in
the encoder. Therefore, the simplicity of the radial code will be the
best choice for placement radius up to 130 mm; higher values will
be available only with radial enhanced.
The implementation of the absolute rotary encoder can be done
in two alternative ways depending on the end application: combined and visual.
4.1. Combined
The combined mode uses all the resources available on the
optical sensor: image acquisition and automatic displacement measurement. These two resources are incompatible so the combined
mode can only be used in positioning applications where the rotary
encoder is stopped from time to time, for example in an educational
robotic arm.
The combined mode works as follows: (i) at the very beginning
the rotary encoder (rotary surface) must be stopped (no rotation) to
acquire the image and decode the absolute rotary position; this process stops sensor operation. (ii) After the absolute rotary position is
available, the optical sensor must be activated (by restarting it) to
measure displacement using the internal resources of the optical
sensor. (iii) Then, the rotary encoder can be used to measure rotation; this reading is affected by some cumulative relative errors
(refer to [9] for more details). (iv) When the rotation is stopped, the
image can be read and the absolute rotary position is then updated
to reset any cumulative rotation error caused during the motion.
The combined mode requires at least 26 ms in the initial and
nal image reading (in burst mode), but motion measurement
requires only 150 s to read the internal motion registers (MOTION,
DELTA X and DELTA Y), allowing a sampling rate up to 6.6 kHz. The
main drawback of this mode is that the rotary encoder must have
no motion during the initial image reading because until the sen-
Fig. 13. Absolute angular displacement measured by the rotary encoder in the combined mode. The circle depicts the initial and nal readings and the points, the
motion measured by the internal DSP.
Fig. 14. Numerical values decoded by the rotary encoder in the visual mode.
the device. The visual mode is ideal for applications that require
the measurement of small angular displacements, for example as a
replacement of a resistive potentiometer.
Fig. 14 shows the evolution of the absolute angular displacement measured using the visual mode for two complete rotations
at a xed speed of 10 rpm. The optical sensor was placed at a radius
of 15 mm and the measurement was repeated with all the proposed codes. Fig. 14 shows the raw position values decoded from
the images acquired by the optical sensor. The results shown have
no errors.
5. Conclusions
This work presents the implementation of an absolute rotary
encoder using the low cost optical mouse sensor. This proposal
takes full advantage of the short focal distance offered by the optical
mouse sensor (2.4 mm) to build a compact rotary encoder. The optical sensor is used to acquire the image of a positioning binary code
printed on the internal rotary surface of the encoder. The numerical
value obtained is processed to obtain the absolute angular position
with the maximum resolution.
Three binary codes have been proposed for the positioning code:
complete, radial and radial enhanced. The resolution of the encoder
only depends on the radius of placement of the optical sensor from
the center of rotation of the rotary surface. The complete code
allows a radius of up to 16.4 mm and a resolution up to 0.210 ; up
to 130.0 mm and 0.026 for the radial code; and up to 407.0 m and
0.0000085 for the radial enhanced code. The size of the information bits in the image starts in 0.20 mm 0.20 mm with a decoding
error rate lower than 3%, but this is zero for 0.26 mm 0.26 mm.
In general, the simplicity of the radial code is ideal for radius up
to 130 mm and the radial enhanced is the only choice for higher
placement radius.
The absolute rotary encoder was implemented using two alternatives. The combined mode requires an initial image reading (and
decoding) with the encoder stopped, a continuous rotation measurement using the internal capabilities of the optical sensor, and
a nal image reading (and decoding) with the encoder stopped to
obtain the corrected absolute position of the encoder. The visual
mode requires a continuous image reading (and decoding). The
sampling rates allowed are 6.6 kHz and 38 Hz, respectively.
Finally, validation results obtained with the two proposed
implementations of the absolute rotary encoder conrm that the
optical mouse sensor can be used to implement inexpensive absolute rotary encoders.
Acknowledgements
With the support of the Government of Catalonia (Comissionat
per a Universitats i Recerca, Departament dInnovaci, Universitats
i Empresa) and the European Social Fund.
167
References
[1] T.W. Ng, The optical mouse as a two-dimensional displacement sensor, Sensors
and Actuators A 107 (1) (2003) 2125.
[2] J.A. Cooney, W.L. Xu, G. Bright, Visual dead-recknoing for motion control of a mecanum-wheeled mobile robot, Mechatronics 14 (6) (2004)
623637.
[3] U. Minoni, A. Signorini, Low-cost optical motion sensor: an experimental characterization, Sensors and Actuators A 128 (2) (2006)
402408.
[4] J. Hu, Y. Chang, Y. Hsu, Calibration and on-line data selection of multiple optical
ow sensors for odometry applications, Sensors and Actuators A 149 (1) (2009)
7480.
[5] J. Palacin, I. Valganon, R. Pernia, The optical mouse for indoor mobile
robot odometry measurement, Sensors and Actuators A 126 (1) (2006)
141147.
[6] N.N.A. Charniya, S.V. Dudul, Investigations into the effects of illumination and
acceleration on optical mouse sensors as contact-free 2D measurement devices,
Sensors and Actuators A 149 (1) (2009) 8792.
[7] T. Pallej, E. Rubin, M. Teixido, M. Tresanchez, A. Fernndez del Viso, C. Rebate,
J. Palacin, Using the optical ow to implement a relative virtual mouse controlled by head movements, Journal of Universal Computer Science 14 (19)
(2008) 31273141.
[8] S. Hengstler, D. Prashanth, S. Fong, H. Aghajan, MeshEye: a hybrid-resolution
smart camera mote for applications in distributed intelligent surveillance, in:
IEEE Int. Symposium on Information Processing in Sensor Networks, April,
2007, pp. 360369.
[9] M. Tresanchez, T. Pallej, M. Teixid, J. Palacin, The optical mouse sensor as an
incremental rotary encoder, Sensors and Actuators A 155 (1) (2009) 7381.
[10] S. Engelberg, H. Benjamin, Pseudorandom sequences and the measurement of
the frequency response, IEEE Instrumentation & Measurement Magazine 8 (1)
(2005) 5459.
[11] D.B. Denic, G.S. Miljkovic, Code reading synchronization method for pseudorandom position encoders, Sensors and Actuators A 150 (2) (2009)
188191.
[12] Avago, ADNS-3080 and ADNS-3088 High Performance Optical Mouse Sensor,
www.avagotech.com, 2008.
Biographies
Marcel Tresanchez received BSc and MSc degrees in engineering from the University of Lleida (UdL), Spain in 2005 and 2007, respectively. He is currently
a PhD student in the robotics laboratory of the UdL and his research interests
include mobile robots, precision agriculture and the educational application of
robotics.
Tomas Palleja received BSc and MSc degrees in engineering from the University of
Lleida (UdL), Spain in 2004 and 2006, respectively. He is currently a PhD student in
the robotics laboratory of the UdL and his research interests include precision agriculture, mobile robots, human system interaction and the educational application of
robotics.
Merce Teixido received the BSc and MSc degrees in engineering from the University of Lleida (UdL), Spain in 2006 and 2008, respectively. She is currently a PhD
student in the robotics laboratory of the UdL and her research interests include
human computer interaction, avatar modeling and the educational application of
robotics.
Jordi Palacin received the BSc and MSc degrees in electronics from the Polytechnic University of Catalonia in 1990 and University of Barcelona (UB), Spain in
1997. He received the PhD degree in electronics from the UB in 2005. In 1992,
he joined the Department of Computer Science and Industrial Engineering at the
University of Lleida (UdL), Spain leading the robotics group. His research interest involves compact modeling, data fusion and signal processing applications in
robotics.