TRIWG Review June 1998 - Electrical & Computer Engineering

Download Report

Transcript TRIWG Review June 1998 - Electrical & Computer Engineering

IR sensitive - sense heat differences and construct
images,
night vision application
Infra Red
sensors
Variations of IR
emitter/receiver pairs
Active
Sensors
Used in
Lynxmotion,
Robix and
Lego robots
Modulation /
Demodulation of
Light
and Infra-Red
Sensors
Modulation and
Demodulation of Light
Ambient light is a problem because it interferes with
the emitted light from a light sensor.
One way to get around this problem is to emit
modulated light.
 The modulated light rapidly turns the emitter on
and off.
Modulated signa much easier and more reliably
detected by a demodulator
Demodulator is tuned to the particular frequency of
the modulated light.
Modulation and Demodulation of Light
Not surprisingly, a detector needs to sense several
on-flashes in a row in order to detect a signal.
It means, to detect signal frequency.
This is important when you write the demodulator
code.
The idea of modulated IR light is commonly used;
 in household remote controls.
Modulated light sensors are generally more reliable
than basic light sensors.
They can be used for the same purposes:
 detecting the presence of an object
 measuring the distance to a nearby object (clever
electronics required, see Martin’s textbook)
Infra Red (IR) Sensors
Infra red sensors are a type of light sensors
They function in the infra red part of the
frequency spectrum.
IR sensors are active sensors
They consist of:
 an emitter
 a receiver.
IR sensors are used in the same ways as the
visible light sensors are:
 as break-beams,
 as reflectance sensors.
Infra Red (IR) Sensors
 IR is preferable to visible light in robotics (and
other) applications.
 This is because it suffers a bit less from
ambient interference,
 because it can be easily modulated,
 because it is not visible.
Sharp
Infra Red
Detector
Sharp IR Detector
 The Sharp GP1U52X sensor detects infrared light
that is modulated (i.e., blinking on and off) at
40,000 Hz.
 It has an active low digital output:
 meaning that when it detects the infrared light, its
output is zero volts.
 The metal case of the sensor must be wired to
circuit ground, as indicated in the diagram.
 This makes the metal case act as a Faraday cage,
protecting the sensor from electromagnetic noise.
Sharp IR Detector




It is a digital sensor because it detects infrared light modulated at 40kHz.
Not analog!
Inside the tin can, there is a IR detector, amplifier, and a demodulator.
The sensor returns a HIGH when there is no 40kHz light, and is LOW when
it sees the 40kHz light.
Sharp IR sensor assembly
Sharp IR Detector
You can use the IC command ir counts(port)
to count the number of successive detected
periods of the modulated frequency.
A count larger than 10 indicates a
detection.
You may need to play around with what
values of the counts are needed for
detection.
These sensors can only be used in digital
ports 4-7.
Elimination of the effect of
the stray IR light
 There is a lot of infrared light that is ambient in the air.
Some components of this light are at 40kHz, and straight output from
the sensor would look very glitchy.
 The sun produces a lot of IR light, and in the sun, the sensor
output bounces all over the place.
 To eliminate the effect of the stray IR light, the IR emitters are
modulated at 100 or 125 Hz and the output of the IR Detectors
is demodulated to look for these frequencies.
(see section A.7 for more information on the IR transmission)
 The 40kHz frequency is known as the carrier frequency, and the
other frequency is the modulated frequency.
IR Photo Transistor
 The “bundle-of-wires"
phototransistors are much
more predictable.
 They should be wired with a
resistor of 100k to 300k (we
recommend 220k).
 They barely respond at all to
visible frequencies of light.
 They respond particularly
well to the LEDs with which
they are bundled, as well as
to the grey IR LEDs.
Phototransistor body
and connector
 Both LEDs are highly
directional, and you should be
able to get good break-beam
results up to 5 or 6 cm
apart (2 inches).
 This might prove especially
useful in ball-ring
mechanisms, for example.
 Note that both LEDs and
phototransistors are just the
right size to fit in LEGO axleholes!
Reflective Optosensors
If we use a light bulb in
combination with a photocell, we
can make a break-beam sensor.
This idea is the underlying principle in
reflective optosensors:
the sensor consists of an emitter and a
detector.
Reflective Optosensors
Depending of the arrangement of those two
relative to each other, we can get two types of
sensors:
reflectance sensors
the emitter and the detector are next to each other,
separated by a barrier;
objects are detected when the light is reflected off them
and back into the detector
break-beam sensors
the emitter and the detector face each other;
objects are detected if they interrupt the beam of light
between the emitter and the detector
IR Reflective Optosensors
Transmitter LED: only
infrared light by filtering
out visible light
Light detector
(receiver) (photodiode
or phototransistor)
Light from emitter LED
bounces off of an external
object and is reflected into
the detector
•Quantity of light is reported by the sensor
•Depending on the reflectivity of the surface, more or less of the transmitted light is
reflected into the detector
• This is an analog sensor - connects to board analog ports
Break-Beam Sensors
Light-emitting component aimed at a
light-detecting component
When opaque object comes
between emitter and detector, the
beam of light is occluded, and
the output of the detector
changes
Discrete infrared LED
• Any pair of compatible emitter–detector
devices may be used:
–1. Incandescent flashlight bulbs and
photocells
– 2. Red LEDs and visible-light-sensitive
phototransistors
– 3. Infrared emitters and detectors
phototransistor
various commercial
break-beam optosensors
Reflective Optosensors
The emitter is usually made out of a lightemitting diode (an LED).
The detector is usually a
photodiode/phototransistor.
Note that these are not the same technology as
resistive photocells.
Resistive photocells are nice and simple, but
their resistive properties make them slow.
Photodiodes and photo-transistors are much
faster and therefore the preferred type of
technology.
Light Reflectivity.
What can you do with this simple idea of light
reflectivity?
Quite a lot of useful things:
object presence detection
In Lego
object distance detection
surface feature detection (finding/following
markers/tape)
wall/boundary tracking
rotational shaft encoding (using encoder
wheels w/ ridges or black & white color)
bar code decoding
Light Reflectivity.
Light reflectivity depends on the color (and
other properties) of a surface.
A light surface will reflect light better than a
dark one, and a black surface may not reflect it
at all, thus appearing invisible to a light sensor.
Darker objects harder (less reliable) to detect .
In the case of object distance, lighter objects
that are farther away will seem closer than
darker objects that are not as far away.
Light Reflectivity.
This gives you an idea of how the physical
world is partially-observable;
even though we have useful sensors, we do
not have complete and completely accurate
information.
Active Light Sensing
The agent illuminates what is being sensed and
uses the reflected light
Can be used for a number of tasks
collision avoidance/proximity detection
following (mail delivery)
We will discuss
line following
Line Detecting and Following
Complete Line Following Circuit
Passive Light Sensing
Light is received from the environment directly
Used to,
locate,
move towards, or
avoid
We will discuss
a single cell eye
The Cyclops Circuit
Cross connected single eyes
Single Photo-resistor per side
Controls a differentially steered vehicle
e.g. The Solenodon IV
Partial Circuit
What are the applications of
Reflective Optosensors?
• 1. Object detection.
•Reflectance sensors may be used to measure the presence of an object in the sensor’s field
of view.
• In addition to simply detecting the presence of the object, the data from a reflectance
sensor may be used to indicate the object’s distance from the sensor.
• Disadvantage: These reading are dependent on the reflectivity of the object, among
other things—a highly reflective object that is farther away may yield a signal as strong
as a less reflective object that is closer.
• 2. Surface feature detection.
•Reflective optosensors are great for detecting features painted, taped, or otherwise marked
onto the floor.
• Line-following using a reflective sensor is a typical robot activity.
What are the applications of
Reflective Optosensors?
• 3. Wall tracking.
•Related the object detection category, this application treats the wall as a
continuous obstacle and uses the reflective sensor to indicate distance from the
wall.
• 4. Rotational shaft encoding.
• Using a pie-shaped encoder wheel, the reflectance sensor can measure the
rotation of a shaft
• (angular position and velocity).
• 5. Barcode decoding.
•Reflectance sensors can be used to decode information from barcode markers
placed in the robot’s environment.
Interfacing Reflective Optosensors
Two components of the sensor, the emitter and detector, have logically
separate circuits, though they are wired to the same connector plug
• Detector Q1, shown as a phototransistor, is wired
between ground and the sensor signal line—just like a
photocell
• The emitter LED
(LED1), is wired to the
Handy Board’s +5v power
supply through R1, the
current-limiting resistor
– R1’s value can vary
220-470W, depending
on how much
brightness is desired
from the emitter LED
Reflectance Sensor Interface Diagram
How do you choose, Photocells or
Phototransistors?
Properties of Photocells:
• easy to use - electrically they are resistors,
• their response time is slow compared to the photodiode or phototransistor’s
semiconductor junction.
• photocells are suitable for:
• detecting levels of ambient light, or
• acting as break-beam sensors in low frequency applications
• (e.g., detecting when an object is between two fingers of a robot gripper).
• Properties of Photodiodes and Phototransistors:
• where we need a rapid response time:
•shaft encoding,
• more sensitive to small levels of light,
•which allows the illumination source to be a simple LED element.
Interfacing Phototransistors
• Current creates a voltage drop in the 47K pullup resistor on HB
Light-sensitive current source: the
more light reaching the phototransistor,
the more current passes through it
• This voltage drop is reflected in a smaller voltage
on the Vsens sensor signal line, which has a level
that is equal to 5 volts minus the 47K resistor’s
voltage drop
•Smaller values than 47K may be required to
obtain good performance from the circuit
– If transistor can typically generate
currents >= 0.1 mA, then voltage drop
across the pull-up resistor will be so
high as to reduce Vsens to zero
– Solution is to wire a smaller pull-up
resistor with the sensor itself
The current, i, flowing through the Q1 phototransistor
is indicated by the dashed line.
Quality Technologies QRD1114 IR Optosensor
• LED emitter and detector
phototransistor or photodiode are
matched.
Emitter LED connects through 330KW
resistor to +5v supply (constantly on)
•This means that peak
sensitivity of the detector is at
same wavelength of emissions
of the emitter
• You should use infrared detector
card to test IR light output
•Wiring
– Detector transistor pulled high with HB
internal 47K resistor
– May have trouble figuring out which
element is transistor and which is detector
• Length of leads: longer +, shorter -
Detector connects to sensor signal line
BreakBeam
Sensors
5.5.9 Breakbeam Sensors
Figure 5.9:
Reflectance
Sensor
Break-beam Sensors
We already talked about the idea of breakbeam sensors.
In general, any pair of compatible emitterdetector devices can be used to produce such a
sensors:
1. an incandescent flashlight bulb and a photocell
2. red LEDs and visible-light-sensitive phototransistors
3. infra-red IR emitters and detectors
Figure 5.10:
Breakbeam
Sensor using
discrete
components.
Breakbeam sensors
Breakbeam sensors are another form of light sensors.
Instead of looking for reflected light, the photosensor
looks for direct light as shown in Figure 5.10.
The sensor is useful in detecting opaque objects that
prevent the light beam from passing through.
This can be useful in detecting block between gripper,
or when block passes through a passageway.
The sensor does not need to detect the block very
quickly so the phototransistor can be plugged into the
analog port.
Figure 5.11: Breakbeam Assembly
Figure 5.12: Shaft encoding using a LEGO pulley Wheel
Breakbeam sensors
 The breakbeam sensors can also be used for counting holes
or slots in a disk as it rotates (see Figure 5.12), allowing
distance traveled to be measured.
 Since this requires a very fast sampling, the sampling needs to
be done at the assembly language level.
 We have implemented shaft-encoder routines to do the fast
sampling.
 But in order to use these routines the sensors should be
plugged into the lower two digital ports if the rate at which the
holes or slots go by is very high.
 Before you use the analog sensors in the digital switch you
must make sure that there is a full swing in the analog reading
from when the light goes through to when the light is blocked.
Motorola MOC70V1
Infrared Break-Beam
Optosensor
• For sensing objects between larger
gaps, use discrete emitters and detectors
• Interface to HB the same as for the
reflective optosensors
– Emitter LED powered from HB
+5v supply through dropping resistor
– Detector phototransistor connected
between sensor signal line and
ground
– Polarity is not indicated by length
of device leads; look for + marking
•Consider many robotic applications for
break-beam sensing
– e.g., detecting something between
fingers of a robotic gripper
Ambient light.
 Another source of noise in light sensors is ambient light.
 The best thing to do is subtract the ambient light level out of
the sensor reading, in order to detect the actual change in the
reflected light, not the ambient light.
 How is that done?
By taking two (or more, for higher accuracy) readings of the detector,
one with the emitter on, and one with it off, and subtracting the two
values from each other.
The result is the ambient light level, which can then be subtracted from
future readings.
 This process is called sensor calibration.
 Of course, remember that ambient light levels can change, so
the sensors may need to be calibrated repeatedly.
What kind of Processing we need for
Infrared Sensors?
1. Correct for ambient
light
2. Calibrate light levels
for dark and light
surfaces
 3. Process the data to
avoid spurious readings
4. Process the data
adapting to changing
conditions
1. Correcting Reflective Optosensors for Ambient
Light
• Question: How can a robot tell the difference
between:
• a stronger reflection
• an increase in light in the robot’s
environment?
• Answer: switch a reflectance sensor’s emitter
light source on and off under software control
– Take two light level readings, one with the
emitter on, and one with the emitter off, then
subtract away the ambient light levels
Wiring an LED to bit 2 of Port D
(Serial Peripheral Interface) Pin
int active_read(int port)
{
int dark, light;
/* local variables */
dark= analog(port);
/* reading with light off */
bit_set(0x1009, 0b00000100); /* turn light on */
light= analog(port); /* reading with light on */
bit_clear(0x1009, 0b00000100); /* turn light off */
return dark - light;
Subtract ambient
}
light
from each IR reading
Correcting for Ambient Light
• Need
to differentiate between transmitted light and normal “ambient” light
• Can do so by using photosensor to read ambient light levels with transmitter off
•Can either use external photosensor
•Or use packaged photosensor if wired correctly
•Subtract ambient light from each IR reading
•Alternating ambient and IR readings
•Info about HB digital electronics:
– Typical LED draws 5-20 mA
– Typical processor digital output can supply 20-25 mA
– So, a 68HC11 pin can drive 1-5 LEDs
2. Sensor Calibration for dark and light surfaces
Robot is physically
positioned over the line
and floor and a threshold
setpoint is captured
• Declare and use
calibration routine
int LINE_SETPOINT= 100;
int FLOOR_SETPOINT= 100;
void calibrate() {
int new;
while (!start_button()) {
new= line_sensor();
printf("Line: old=%d new=%d\n",
LINE_SETPOINT, new);
msleep(50L);
}
LINE_SETPOINT= new; /* accept new
value */
beep(); while (start_button());
/* debounce button press */
while (!start_button()) {
new= line_sensor();
printf("Floor: old=%d new=%d\n",
FLOOR_SETPOINT, new);
msleep(50L);
}
FLOOR_SETPOINT= new; /* accept new
value */
beep(); while (start_button());
Huge*/improvement
/* debounce button press
}
over fixed and hard-
NOTE DEBOUNCING BUTTON PRESSES
setpoint variables
are persistent
coded calibration
methods
Proximity Sensing with Infrared Pair
• Proximity sensing:
• reflect IR off nearby object
• detect returned light
• emitter and detector point in same direction
•
Modulated light
• By rapidly turning on and off, the source of light can be easily picked up from
varying background illumination
Proximity Sensing with Infrared
Pair
•
Modulated light
• By rapidly turning on and off, the source of light can be
easily picked up from varying background illumination
Proximity Sensing with Infrared
• With modulated light detector, object is either present or
absent
• Modulated light is less susceptible to environment
variables but non-modulated light magnitude
sensing/thresholding works also
• Could try to determine object’s distance as well but, …
Re-Visiting IR Calibration
 IR is very sensitive to ambient lighting, different color
obstacles, varying distances, differing lighting conditions
Combining Light and IR to Infer
Distance
IR = f(color, reflectance, ambient light, distance)
Don’t have a sensor that measures color
Distance is what we want
So what we do?
1. We condition based on ambient light
2. We hope that all the obstacles are the same
color/reflectance
Closed-loop Control
Obstacle avoidance and tracking Drive parallel to wall
Using a Proximity Sensor to
Measure Distance to a Wall
Feedback from proximity
sensors (e.g. bump, IR,
sonar)
Feedback loop,
continuous monitoring
and correction of motors
-- adjusting distance to
wall to maintain goal
distance
Separate Sensor State Processing
from Control
Functions might each make use of other sensors and functions –
need to decide how to implement each
Use Proximity Sensor to Select
One of Three States
Sensor used to select one of three states
Obstacle
Avoidance
and Tracking
Using IR
 Have continuously running task
update IR state:
Left, right, both, neither
 If one obstacle detected
then use closed-loop control to keep it
away from robot
 If two obstacles detected
then
Either assume you can’t pass and
treat like bump
Or try to pass in-between with
closed-loop control
Depends on how you
mounted/shielded your sensors, how
you set your thresholds, and any
ability to differentiate distances
Use of Infrared Ground Sensor
Concluding on
Local Proximity
Sensing using IR
Infrared LEDs
cheap, active sensing
usually low resolution - normally used for
presence/absence of obstacles rather than ranging
operate over small range
Shaft
Encoding
Our Wheel Encoders
Optical encoder to measure
wheel rotation of each drive
wheel
Slotted disk attached to wheel
or motor shaft
“Break-beam” IR counts
number of slots that pass in
given time (ports 7,8 )
Enable_encode,
disable_encoder, read_encoder
(number of on/offs since last
reset), reset_encoder
Max 32,767 counts (16 bit)
Basics of Shaft Encoders
A shaft encoder is a device that measures
the position of a shaft.
There are two types of shaft encoders.
One is incremental shaft encoder which
produces a pulse train of a certain frequency
depending on the rotational speed of its
shaft.
The other one is the absolute shaft encoder
which measures the absolute position of its
shaft.
Incremental shaft
encoders.
A Shaft
64 Segments
Photo Interrupter
Pulse Train
Shaft Encoding
• Use Break-Beam Sensors
• Shaft encoder measures the
angular rotation of an axle,
reporting position and/or
velocity information
• Example: speedometer,
which reports how fast the
wheels are turning; odometer,
which keeps track of the
number of total rotations
Single-Disk Shaft Encoder
A perforated disk is mounted on the shaft
and placed between the emitter–detector
pair. As the shaft rotates, the holes in the
disk chop the light beam. Hardware and
software connected to the detector keeps
track of these light pulses, thereby
monitoring the rotation of the shaft.
Shaft Encoding
 Shaft encoders measure the angular rotation of an
axle providing position and/or velocity info.
A speedometer measures how fast the wheels of a vehicle
are turning,
An odometer measures the number of rotations of the
wheels.
In order to detect a complete or partial rotation, we
have to somehow mark the turning element.
This is usually done by attaching a round disk to the
shaft, and cutting notches into it.
Shaft Encoding
A light emitter and detector are placed on each
side of the disk, so that:
 as the notch passes between them, the light
passes, and is detected;
where there is no notch in the disk, no light
passes.
If there is only one notch in the disk, then a
rotation is detected as it happens.
This is not a very good idea, since it allows only
a low level of resolution for measuring speed:
 the smallest unit that can be measured is a full
Shaft Encoding
 Besides, some rotations might be missed due to noise.
Usually, many notches are cut into the disk, and the
light hits impacting the detector are counted.
(You can see that it is important to have a fast sensor here,
if the shaft turns very quickly.)
 An alternative to cutting notches in the disk is to:
 paint the disk with black (absorbing, non-reflecting) and
white (highly reflecting) wedges, and
measure the reflectance.
In this case, the emitter and the detector are on the
same side of the disk.
Shaft Encoding
In either case, the output of the sensor is going
to be a wave function of the light intensity.
This can then be processed to produce the
speed, by counting the peaks of the waves.
Note that shaft encoding measures both
position and rotational velocity,
by subtracting the difference in the position
readings after each time interval.
Velocity, on the other hand, tells us how fast
a robot is moving, or if it is moving at all.
Shaft Encoding
 There are multiple ways to use velocity:
measure the speed of a driven (active) wheel
use a passive wheel that is dragged by the robot (measure forward
progress)
 We can combine the position and velocity information to do
more sophisticated things:
move in a straight line
rotate by an exact amount
 Note, however, that doing such things is quite difficult,
because:
 wheels tend to slip (effector noise/error) and slide and
there is usually some slop and backlash in the gearing mechanism.
 Shaft encoders can provide feedback to correct the errors, but
having some error is unavoidable.
Quadrature Shaft Encoding
So far, we've talked about detecting position and
velocity, but did not talk about direction of rotation.
Suppose the wheel suddenly changes the direction of
rotation; it would be useful for the robot to detect
that.
An example of a common system that needs to
measure position, velocity, and direction is a
computer mouse.
Without a measure of direction, a mouse is pretty
useless.
 How is direction of rotation measured?
Quadrature Shaft Encoding
 Quadrature shaft encoding is an elaboration of the basic breakbeam idea;
instead of using only one sensor, two sensors are needed.
 The encoders are aligned so that their two data streams
coming from the detector are one quarter cycle (90-degrees)
out of phase, thus the name "quadrature".
 By comparing the output of the two encoders at each time step
with the output of the previous time step, we can tell if there
is a direction change.
 When the two are sampled at each time step, only one of them
will change its state (i.e., go from on to off) at a time, because
they are out of phase.
Quadrature Shaft Encoding
Which one does, it determines which direction the
shaft is rotating.
Whenever a shaft is moving in one direction, a
counter is incremented, and when it turns in the
opposite direction, the counter is decremented, thus
keeping track of the overall position.
Other uses of quadrature shaft encoding are in:
 robot arms with complex joints (such as rotary/ball joints;
think of your knee or shoulder),
Cartesian robots (and large printers) where an arm/rack
moves back and forth along an axis/gear.
Shaft Encoding
Data from shaft encoder built from MOV70V1 breakbeam sensor and pulley wheel:
The sensor data graph is a nearly ideal square wave.
Using the standard HB analog input, which reports a
sensor reading between 0 and 255, the sensor’s output
varies from a low of about 9 (about 0.18 volts) to a
high of about 250 (4.9 volts) with a sharp edge
between the transitions.
Other break-beam sensors yield a time graph that
looks more like a sine wave.
This assembly uses the Motorola breakbeam sensor with the medium pulley
wheel as a photo-interrupter. After
determining a position of the breakbeam sensor that yielded good break
and make transitions, the sensor was
hot-glued into position along the LEGO
beam.
Shaft Encoding
Counting Encoder Clicks
• To make sense of data from a shaft
encoder, install a routine that repeatedly
checks the sensor value.
– If the encoder wheel turns faster
than the routine checks the sensor
state, it will start missing transitions
and lose track of the shaft’s rotation
– Solution: check midrange point
• Variables for algorithm:
encoder_state - Keeps track of last
encoder reading:1 if high (above
128), 0 if low (below 128)
encoder_counter - Keeps running
total of encoder “clicks”
Shaft Encoding
Driver Software
• Machine language routine loaded into IC’s underlying layer of direct 68HC11 code, with user
interface - IC binary (ICB) files installed in interrupt structure of 68HC11
• Monitors shaft encoder values and calculates encoder steps and velocity needs quickly and at
regular intervals
• HB’s software libraries include set of routines for supporting shaft encoders for both positioncounting and velocity measurement. For each analog input on HB, a pair of shaft encoder routines is
provided. For each pair, there is a high-speed version and a low-speed version.
– High speed version checks for transitions on the encoder sensor 1000 Hz
– Low speed version checks encoder at 250 Hz (less of a processing load on the system)
– Both versions calculate the velocity (position difference) measurement at about 16 Hz
• Once loaded into IC, the encoder routines are automatically active; no additional commands are
needed to turn them on.
– Each encoder0_counts variable (running total of transitions on encoder sensor) will
automatically increment every time it senses a transition on its corresponding encoder sensor
– The encoder0_velocity value (velocity measurement) is continuously updated
Library Drivers to do the Counting
• Machine language routine loaded into IC’s underlying layer of direct 68HC11 code, with user
interface - IC binary (ICB) files installed in interrupt structure of 68HC11
• Monitors shaft encoder values and calculates encoder steps and velocity needs quickly and at
regular intervals
• HB’s software libraries include set of routines for supporting shaft encoders for both positioncounting and velocity measurement. For each analog input on HB, a pair of shaft encoder routines is
provided.
• Once loaded into IC, the encoder routines are automatically active; no additional commands are
needed to turn them on.
– Each encoder0_counts variable (running total of transitions on encoder sensor) will
automatically increment every time it senses a transition on its corresponding encoder sensor
– The encoder0_velocity value (velocity measurement) is continuously updated
(copyright Prentice Hall 2001)
Programming Encoders
/* Normal encoders, on ports 7
and 8. Must load encoders.lis
to use this, more info in the
HB manual. */
void main(void) {
enable_encoder(0);
/* Turn on encoder on port 7 */
motor(0, 20);
while (read_encoder(0) < 130)
;
reset_encoder(0);
motor(0, -20);
while (read_encoder(0) <
130)
;
ao();
}
/* Using encoders on analog ports 0
through 5
Must load the relevant file,
sendr0.icb in this case.
Consult the readme in the libs
directory for info. */
void main(void) {
motor(0, 20);
while (encoder0_counts < 130)
;
encoder0_counts = 0;
motor(0, -20);
while (encoder0_counts < 130)
;
ao();
/* Note that these analog functions
also provide velocity information
*/
Shaft Encoding
Measuring Velocity
• Driver routines measure rotational velocity as well as position
– Subtract difference in the position readings after an interval of time has elapsed
• Velocity readings can be useful for a variety of purposes
– Robot that has an un-powered trailer wheel with a shaft encoder can easily tell whether
it is moving or not by looking at encoder activity on the trailer wheel. If the robot is
moving, the trailer wheel will be dragged along and will have a non-zero velocity. If the
robot is stuck, whether or not its main drive wheels are turning, the trailer wheel will be
still.
• Velocity information can be combined with position information to perform tasks like
causing a robot to drive in the straight line, or rotate a certain number of degrees. These tasks
are inherently unreliable because of mechanical factors like slippage of robot wheels on the
floor and backlash in geartrains, but to a limited extent they can be performed with appropriate
feedback from shaft encoders.
Shaft Encoding
Reflective Optosensors as Shaft Encoders
• It’s possible to build shaft
encoders by using a reflective
optosensor to detect black and
white markings on an encoder
wheel
• Wheels can be used with any of
the reflective optosensor devices,
as long as the beam of light they
generate is small enough to fit
within the black and white pieshaped markings
Shaft Encoding
Opto-Electronic Computer Mice
• Common desktop mouse uses shaft encoder
technology to figure out how the mouse ball is
turned
• Two slotted encoder wheels are mounted on
shafts that are turned by the ball’s movement
• On either side of each encoder wheel are the
infrared emitter and detector pair
• Mice use quadrature shaft encoding, a
technique that provides information about
which way the shaft is turned (in addition to the
total “encoder clicks”)
• IR detector on each shaft actually has two
elements, aligned so that as one element is
being covered up by the leaf between the slots,
the other is being exposed
angular resolution of the shaft encoder
64 segment means 64 pulses per one
complete revolution of the shaft.
1 revolution = 360o
1 revolution = 64 pulses
1 pulse = 5.625o (angular resolution)
Increasing the number of segments, called
the pulses per revolution (ppr) increases the
angular resolution of the shaft encoder.
An Example Datasheet
Connection to Handyboard
Two shaft encoders
can be
connected to
handyboard!!!
Signal
5V
Ground
1 0
Interactive C Functions
Load encoders.lis first.
void enable_encoder(int encoder)
enables the encoder(0 or 1)
void disable_encoder(int encoder)
disables the encoder(0 or 1)
void reset_encoder(int encoder)
resets the counter of encoder(0 or 1) to zero
Interactive C Functions
void read_encoder(int encoder)
returns the number of pulses counted by
the given encoder(0 or 1) since last reset
or enable. Maximum number of counts is
32767, after that -32768, -32767…0 will
come.
Some Important Remarks
Use an encoder which has a Vin = 5V
and Vsignal = 5V.
Use incremental shaft encoder.
To use more than 2 encoders(upto 6),
you can use analog ports instead of
digital ports.
But you have to use a different
encoder library available on the
Handyboard web site.
Khepera
Robot
Anatomy of the Khepera
Microprocessor
IR-Sensors
Wheels & DC-Motors
Insights of Khepera
Microprocessor
IR-Sensors
Wheels & DC-Motors
Simplified Braitenberg Algorithm
Obstacle on
Left side?
No
Yes
Obstacle on
Right side?
No
Move Forward
Yes
Turn Right
Turn Left
No
Obstacle on
Back?
Yes
End
n
1002
353
331
925
265
243
221
199
177
155
133
111
89
67
45
23
1
309
1200
1000
800
600
400
200
0
848
No filter in Light
287
n
771
694
617
540
463
386
309
232
155
78
1
IR-values
IR-values
No filter in Darkness
1200
1000
800
600
400
200
0
n
221
243
265
221
243
265
155
133
111
89
67
45
23
1
199
1200
1000
800
600
400
200
0
199
Averaging in Light
177
n
177
155
133
111
89
67
45
23
1
IR values
IR values
IIR filter in Light
1200
1000
800
600
400
200
0
Results
On darkness
Slow filter response when approaching obstacle
Even slower when moving away from obstacle
On light
Acceptable filter response time when approaching
obstacle
Acceptable filter response time when moving away
from obstacle
Noisy readings greatly reduced
Results (cont.)
Satisfactory performance of Braitenberg
algorithm without filtered readings on darkness
Problems using filters with Braitenberg
algorithm
Robot slow to react to filtered sensory readings
Conclusions
Fluorescent light noise cause serious effects on
Khepera’s performance
Digital filters proved to be useful in reducing
noise in sensory readings
Filters performance are greatly affected by
levels of ambient light
Future Works
Braitenberg algorithm modified to allows
detection of ambient light
Activate filters on high levels of ambient light
Disable filters on low-light conditions
Develop user-friendly program for testing
algorithms and filters
Shaft Encoder Exercises
1. Build a shaft encoder using a break-beam optosensor and a perforated disk or LEGO pulley wheel. Verify
the raw sensor performance—what values represent the light beam being broken vs. not broken?
2. Choose a suitable midpoint value for determining encoder transitions. Write a program in IC to implement
the simple encoder counting algorithm presented in the flowchart. Use IC multi-tasking capability to display
the encoder counter variable while the counting routine is running, and experiment with the encoder.
Can you determine the performance limit of the algorithm in your implementation, in terms of counts per
second? What is a fundamental problem with this implementation method?
3. Load a library shaft encoder routine and experiment with its performance. Capture raw data from the
encoder. Based on the graph of raw encoder performance, choose suitable high and low threshold values.
Explain your choices.
4. One limitation of current encoder routines, both the IC and library versions, is that they cannot determine
which direction the shaft is rotating. Can you think of a different approach for determining the direction of
rotation?
5. Implement the trailer wheel idea discussed in the text on your HandyBug. Write a program to make
HandyBug drive around and stop, back up, and turn when the trailer wheel’s velocity is 0. Can you think of
other applications for knowing the robot’s velocity, other than as a non-zero/zero (i.e., moving/not moving)
quantity?
6. Instrument one of HandyBug’s drive wheels with an encoder, and write a program at attempts to maintain
constant velocity on the drive wheel by varying the power level delivery to the motor. Experiment with the
system by holding HandyBug in the air and applying pressure to the drive wheel. Is the system able to
maintain the velocity? What happens if you suddenly remove the pressure?
Sources
 A. Ferworn
 Saúl J. Vega
 Daisy A. Ortiz
 Advisor: Raúl E. Torres, Ph.D., P.E.
 Maja Mataric
 Ali Emre Turgut
 Dr. Linda Bushnell, EE1 M234, [email protected]
 Web Site: http://www.ee.washington.edu/class/462/aut00/
 Robotic Explorations: A Hands-on Introduction to Engineering,
Fred Martin, Prentice Hall, 2001.
Creative Uses: IR Sensors
 Sharp IR sensors are very accurate and operate well over a
large range of distances proportional to the size of a Lego
robot.
 However, they have almost no spread.
 This can cause a robot to miss an obstacle because of a narrow
gap. One solution is to make the sensor pan.
 One could also use a light sensor to detect obstacles indoors.
Inside, there tend to be lights at many angles and locations.
 Thus, around the edges of most obstacles, a slight shadow will
be cast.
 A light sensor could detect this shadow and thus the associated
object.
 Warning: this could be a very fickle design.
IR Sensors
750 nm to 1,000,000 nm
Transmitters (LEDs or thermal)
Detectors (photo diodes, photo transistors)
IR: Three common strategies
IR Rangefinders
What sorts of techniques can we use?
Time of Flight (TOF)
Signal Strength
Triangulation
Creative Uses: IR Sensors
Example of sharp IR mounte
sweep for a wider field of vi
Shadow cast indicates obstacle:
one way to navigate with photo resistors.
Intensity Based Infrared
voltage
Increase in ambient light
raises DC bias
time
voltage
• Easy to implement (few components)
• Works very well in controlled environments
• Sensitive to ambient light
time
Modulated Infrared
amplifier
bandpass filter
integrator
limiter
demodulator
comparator
Input
Output
600us
600us
• Insensitive to ambient light
• Built in modulation decoder (typically 38-40kHz)
• Used in most IR remote control units ( good for communications)
• Mounted in a metal faraday cage
• Cannot detect long on-pulses
• Requires modulated IR signal
http://www.hvwtechnologies.com
http://www.digikey.com
Digital Infrared Ranging
Modulated IR beam
Optical lenses
+5v
output
input
1k
1k
gnd
position sensitive device
(array of photodiodes)
• Optics to covert horizontal distance to vertical distance
• Insensitive to ambient light and surface type
• Minimum range ~ 10cm
• Beam width ~ 5deg
• Designed to run on 3v -> need to protect input
• Uses Shift register to exchange data (clk in = data out)
• Moderately reliable for ranging

Polaroid Ultrasonic Sensor
Mobile Robot
Electric
Measuring Tape
Focus for Camera
http://www.robotprojects.com/sonar/scd.htm
Theory of Operation
 Digital Init
 Chirp
16 high to low
-200 to 200 V
 Internal Blanking
 Chirp reaches object
343.2 m/s
Temp, pressure
 Echoes
Shape
Material
 Returns to Xducer
 Measure the time
Problems
 Azimuth Uncertainty
 Specular Reflections
 Multipass
 Highly sensitive to temperature and pressure changes
 Minimum Range
Beam Pattern
Not Gaussian!!
(Naïve) Sensor Model
Problem with Naïve Model
Reducing Azimuth Uncertainty
Pixel-Based Methods (Most
Popular)
Region of Constant Depth
Arc Transversal Method
Focusing Multiple Sensor
Certainty Grid
Approach
Combine info with
Bayes Rule
(Morevac and Elfes)
Arc Transversal Method



Uniform Distribution on Arc
Consider Transversal Intersections
Take the Median
Mapping Example
Vendors
Micromint
Wirz
Gleason Research (Handyboard)
Polaroid-oem
Metal Detector
Oscillator signal
coupled via transformer
When T2 is turned off, T3 is turned on
112kHz
LC Oscillator
LED will drop about 2volts
Diode converts AC
signal to DC ripple
and applies as bias to T3
9v Signal to 5v logic
+9V
+5V
Rpullup
9v signal
+
-
PIC
LM311
comparator
A comparator can be used to convert a two-state signal to digital logic
When the + voltage is above the voltage on the - pin, the output is high
When the + voltage is below the - voltage, the output is low
The LM311 has an open collector (you need to provide pullup resistor)
This allows conversion from 9volt logic to 5volt logic
MASLab Sensors
January 2002
Christopher Batten
Agenda
Quadrature phase sensors
Sensors, in general
The specific kinds of sensors in 6.186
Quadrature Phase
Encoders
We have a precise method of measuring how
much our wheels rotate
How can we use this for navigation?
Pitfalls?
Slippage
Inaccurate characterization
Odometry
Use odometry to find out how far each wheel has
moved in some (short) time interval.
Assume that robot was turning at a constant rate
during this interval.
y
(xk,yk)
θk
x
Odometry – the model
y
About how far did the
robot actually go?
θk+1 (xk+1,yk+1)
Dk=(dL+dR)/2
dR
αk
dL
(xk,yk)
θk
The angle of the
sector?
αk=(dR-dL)/B
xk+1=xk+Dkcos(θk+
αk/2)
x
yk+1=yk+Dksin(θk+ αk/2)
B is the “baseline”- the θ
distance=between
the two wheels.
θ
+
α
k+1
k
k
Odometry- Coping with Error
Odometry, by itself, will get worse and worse…
Try to reconcile/confirm results with other
navigation methods:
Range to objects
Angles to objects, targets, waypoints, beacons
Any other ideas?
6.186 - Sensors
What is a sensor?
Common types:
Infra-Red (IR)
Ultrasound
Physical contact
Other types:
Magnetic field detectors (Reed switches)
Be creative!
Infrared Beacons
Custom hardware specifically designed for
MASLab
IR Beacon Transmitters broadcast data
packets containing a unique ID number
(waypoints, targets, navigation beacons)
IR Beacon Receivers are directional and
look for ID broadcasts to identify the direction
of a specific beacon (one per team)
Infrared Beacons - Transmitters
Which IDs correspond to waypoints, targets, and
navigation beacons is predetermined and will not
change
The location of any beacon (in relative or
absolute coordinates) is not known ahead of time
Transmitters broadcast their ID in
eight different directions
IR Beacons will be either 10” or 8”
and the walls will all be 9”
Infrared Beacons - Receivers
Receivers can receive packets in two opposite
directions – combined with 180° servos this provides
360° listening
Beacons do not (directly) provide any information
concerning the distance to the beacon (use
triangulation or range sensors)
Range is approximately 15-20 feet and should be able
Receiver
Receiver 5 packets per second. w/ Baffle
to receive approximately
w/o Baffle
Each team is responsible
for making their own baffles.
Infrared Range Detectors
Sharp GP2D12 IR range
detectors
Two per team (more upon request)
Sensor includes:
Infrared light emitting diode (IR
LED)
Position sensing device (PSD)
LE
D
PS
D

To detect an object:
IR pulse is emitted by the IR LED
Pulse hopefully reflects off object
and returns to the PSD
PSD measures the angle at which
LE
D
PS
D

Infrared Range Detectors
Analog Output Voltage (V)
3
2.5
2
1.5
1
0.5
Distance to reflected object (in)
Theoretical Range: 4in (10cm) to 31in (80cm)
Actual Range: ~4in (10cm) to ~ 18in (45cm)
36
32
28
24
20
16
12
9
7
5
3
1
0
Infrared Range Detectors
Detecting Targets
Placed target in various
positions in front of a standard
MASLab wall
Relatively narrow “field-of-view”
0.45
0.45
0.45
0.44
0.45
0.45
2.40
1.05
0.69
0.44
0.45
0.45
0.45
0.45
0.45
Noise
Output voltage follows normallike distribution with constant
std dev
User-level averaging may be
useful
Sampling
0.5 ft
Infrared Range Detectors
Uses
Short range obstacle mapping - Mount sensor
on servo and collect range data for various angles
Bump sensors - Threshold output voltage, Use
multiple sensors at appropriate angles to cover
more area
Target detection - Arrange multiple sensors to
detect shape of waypoints and targets
Final practical concerns
Place a 10-20uF capacitor between Vcc & GND
Position IR sensors to avoid dealing with < 4in
Autonomous robotics based
on simple
sensor inputs.
Stuart Dodds
Abstract
A “robot” is explained as “a device that performs functions normally ascribed to humans” Webster.
“Autonomous” means that the robot can work totally independently of itself, once it has been
programmed, and it should be able to function without interaction from any human influence. Many
robots are used nowadays to work in conditions where it is inaccessible for humans to work and
therefore need to be autonomous.
The aim of this project is to program a robot (shown left) using PIC (peripheral interface controller)
chips, so that it will utilise its infra red sensors and run its stepper motors to follow a boundary wall
within an enclosed environment.
Environment
Sensor Range
Boundary
Infra-Red Sensors
This diagram is a depiction of an environment
that has been built to test the robot with a
selection of acute, obtuse and reflex angles.
There are 13 Infra Red (or IR)
sensors attached to the front half of
OFF
OFF
the Robot that are used to detect the
OFF
environment boundary. These
Sensors
ON
sensors are light sensitive and output
ON
a signal when they become active.
The
sensor range is approximately 15mm which gives the robot enough time to read the
information, decide on what to do and stop before it hits the boundary.
Stepper Controller
IR Sensor Controller
PIC 16f84
Stepper
Motors
Pulse
Direction
Pulse
Direction
Further Work
PIC 16f84
Communication lines
B0
A0
B1
B3
B2
B4
Starting Point
B2
B5
Any Sensor Active
A0
A1
A2
A3
Data
Selector
Multiplexer
S0
Sensors
S1
S2
As shown the robot follows the same sequence
as it travels round the environment. When it
reaches a wall the robot will stop then start to
rotate until non of the sensors are active. Then it
will move forward for a designated amount of
time and rotate right and move forward again to
look for the wall.
B0
B1
Sensor
Data
S3
13
The devices that run all the computations of the robot are two PIC chips. One chip receives information from the IR sensors
then executes an algorithm on this data. It then sends instructions to the other chip which controls the stepper motors.
Now that the robot works properly and has been
thoroughly tested using the IR sensors, the next stage
of development is to implement a set of line following
and ultra sonic sensors.
This involves adding two more PIC chips to the
circuit board, then to program them so they can read
and process the information from these completely
different sensor types.
Once all of these have been fully implemented and
tested I shall run a comparison between all three of
them.
Infra-Red Sensors
There are 13 Infra Red (or
IR) sensors attached to the
front half of the Robot that
are used to detect the
environment boundary.
These sensors are light
sensitive and output a signal
when they become active.
Sensor
Range
Boundary
OFF
OFF
OFF
ON
Sensors
ON
The sensor range is approximately 15mm which gives the
robot enough time to read the information, decide on what to
do and stop before it hits the boundary.
Environment
This diagram is a depiction of an environment that has been built to test the robot
with a selection of acute, obtuse and reflex angles.
As shown the robot follows the same sequence as it travels round the environment.
When it reaches a wall the robot will stop then start to rotate until non of the sensors
are active. Then it will move forward for a designated amount of time and rotate
right and move forward again to look for the wall.
Starting Point
Stepper Controller
IR Sensor Controller
PIC 16f84
Stepper
Motors
PIC 16f84
Communication lines
Pulse
B1
B0
B2
A0
B5
Direction
B3
Pulse
Any Sensor Active
B2
Direction
B4
A0
B0
A1
A2
B1
A3
Data
Selector
Multiplexer
S0
Sensors
S1
S2
Sensor
Data
S3
13
The devices that run all the computations of the robot are two PIC chips. One chip receives information from
the IR sensors then executes an algorithm on this data. It then sends instructions to the other chip which
controls the stepper motors.
The Robot - Khepera
To make gas sensor move freely indoor. Khepera basic
module and its General I/O extension module will be used
in our experiment.
It features:
- a diameter size of 5cm
- 2 independent DC motors with encoders
- 8 infra-red sensors
- An onboard 68331 microcontroller
- An onboard battery
- A modular design with extension modules
Khepera Basic module
General I/O extension module
The “general I/O” is a turret that can be plugged on the basic
configuration making simple custom electronic extensions possible.
It features:
- Digital inputs and outputs
- Power outputs
- Analog inputs with adjustable gain
- Pass-through K-bus to other turrets
General I/O Turret
SENSOR
The Sharp GP2D02
IR Distance
Measuring Sensor
Quick Overview
Sensors are utilized for many types of detection
schemes.
Such as: light intensity, temperature, etc…
For our purpose: Distance
Examples
Tactile Bumpers (simple sensor)
designed to form a contact closure when pressure is
applied to the bumper
other actuators can be used to trigger control or decisions
concerning course of action.
Optical Proximity Sensors (photoelectric
sensors)
Three groups
• Opposed: electric eye; emitter/detector beam
interruption
• Retro-reflective: uses an object to reflect from
emitter to the detector
• Diffuse: uses the target object to return the energy
from the emitter to the detector
GP2D02 SENSOR
 Measures distance in range
from 20 to 80cm.
 Designed to interface to small
micro-controllers.
 It’s relatively insensitive to the
color and texture of the object
at which it is pointed.
 Low current consumption at
stand-by mode (Approximately
3 A).
Actual Sensor Size
Distance Measurement by
Triangulation
IR LED Transmits a
bundled beam to the
object plane.
Reflected beam is
receive by the photo
detector(PSD).
The angle of the
received beam depends
on distance of the
object plane.
Two Different Object Planes
Structure of Photo Diode
N-conductive
substrate layer is an
isolation layer
P-conductive layer
is embedded in
isolation layer from
IR irradiated
Contact of the player is made on left
and right side
Structure of a position sensitive
photo diode(PSD)
How PSD Measures Distance?
Spot irradiation in the center of the player, both currents I1, I2 will have
same value.
Spot irradiation goes to the right, the
I1 will decrease and I2 will increase by
the same amount.
The difference between the I1 and I2
will give the location of a spot
irradiation on PSD.
PSD Continued
 Diodes in the Op-Amp’s
feedback give a logarithmic
behavior to the I-to-V
conversion circuit.
 Collector current, Ic, in
each Op-amp is identical to
the I1 and I2.
 Third Op-Amp processes
the difference of the two
output voltages from
previous Op-Amps.
 Vo =VT. ln(I1/I2)
Circuit for position sensitive
Current-to-voltage conversion
Distance Chart
Distancevs. irRangeValue
300
250
150
100
50
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
irRangeValue(int)
200
Distance(inches)
Timing
 When interfacing with any type
of hardware, timing is an issue.
 Vin and Vout are control
measurements.
 Vin drops to low for minimum
70ms.
 IR LED transmits 16 pulses
towards the object.
 Mean value of 16
measurements reduces possible
errors.
Timing Diagram for
Measurement and
data handling
Configuration
Sensor has four pins
for electrical contact.
Pin 2 (IN) from the
sensor connects to
IR OUT.
Pin 4 (Signal) from
the sensor connects
to IR IN.
Pin 1 and 3 are
connected to ground
and +5V,
respectively.
SW1 and SW2 refer
to bumper switches.
Handy Board Connection
Example of Control Program
int distance = 1; /* Init and set the variable distance to 1 */
void range()
{
while(1)
{
sleep(.30);
/* Wait .3 seconds, without updating irRange */
pulse(1);
/* Update irRange to new detected distance */
distance = irRange; /* set variable distance equal to irRange */
}
}
Continue
void escape()
{
while(TRUE)
{
if(distance >= 150)
/*If IR sensor detects object within a close proximity take evasive action*/
{
escape_output_flag = TRUE;
printf("STATUS = IR SENSE \n");
sleep(2.0);
printf("\n");
escape_output= -30;
escape_output1= -30;
sleep(6.0);
escape_output= -60;
escape_output1= 115;
sleep(10.0);
escape_output= 30;
escape_output1= 30;
sleep(2.0);
escape_output= 30;
}
escape_output_flag = FALSE;
}
}
BREAK TIME
Any Questions
So far?
OK! LET’S MOVE
ON TO THE LAB!
Lab Exercise
Lab Objective:
 Load pulse.icb , which is a compiled assembly object file.
 Pulse.icb enables 2 interactive C functions pulse() and irRange
 Every time you want the IR sensor to obtain a position, call the
pulse subroutine, the position integer is updated in the variable
irRange.
Continue
Exercise:
 Write a behavioral program, using your bumper
switches and the new IR sensor to avoid
obstructions.
 Upon pushing the START button, the robot moves
forward and stops after 3 minutes or the STOP button is
pushed.
 After IR detector detects an obstruction:
 Backup a quarter of the length of your robot using the IC
time commands, storing any constants set as persistent
global variables for use in later programming (see page
12 of the Handy Board manual).
 Turn 45 degrees in either direction and continue forward.
IR Communication
 Modulated infra red can be used as a serial line for transmitting
messages.
 This is is fact how IR modems work.
 Two basic methods exist:
 bit frames (sampled in the middle of each bit; assumes all bits take the same
amount of time to transmit)
 bit intervals (more common in commercial use; sampled at the falling edge,
duration of interval between sampling determines whether it's a 0 or 1)
 Notes:
 you are strongly encouraged to pay careful attention to the exercises and
problems given in your assigned readings.
 Projects, exams, homeworks and reports will use some of those, so it is in your
interest to think about the answers to their questions, and work some of them
out as practice.
 Also the additional recitations (Fridays) problems may appear on the exams.