Multifunction Encoder and Decoder Remote Control Remote control devices, like those detailed in the previous section, typically use a special function integrated circuit called an encode
Trang 1End If
I = I + 2 ' Do even number elements only;
' spaces are in odd number elements Digit = Digit + 1
Loop While I <= (MaxPulses - 1)
‘ Determine item selected
‘ Tx is for debug window display
‘ MotorVal is the value to use on PortA Select Case Value
Case 16706
Tx = "0"
MotorVal = 0 Case 16898
Tx = "1"
MotorVal = 1 Case 16642
Tx = "2"
MotorVal = 2 Case 17154
Tx = "3"
MotorVal = 3 Case 16514
Tx = "4"
MotorVal = 4 Case 17026
Tx = "5"
MotorVal = 5 Case 16770
Tx = "6"
MotorVal = 6 Case 17282
Tx = "7"
MotorVal = 7 Case 16450
Tx = "8"
MotorVal = 8 Case 16962
Tx = "9"
MotorVal = 9 Case 16802
Tx = "Power"
MotorVal = 0 Case 16930
Tx = "Channel Up"
MotorVal = 0 Case 16674
Tx = "Channel Down”
MotorVal = 0 Case 16546
Tx = "Volume Up"
MotorVal = 0 Case 17058
Tx = "Volume Down"
MotorVal = 0 Case Else
Tx = "[other]"
End Select ' Set PortA output to motor value (lower four bits only) Register.PORTA = (Register.PORTA AND bx11110000) OR _
Motors(CInt(MotorVal))
546 REMOTE CONTROL SYSTEMS
Trang 2Call NewLine Call Delay(0.25) ' wait quarter of a second Continue:
Loop End Sub '————————————————————————————————- ' Lifted from NetMedia BasicX code examples Sub TranslateSpace(ByVal Space As UnsignedInteger, _ ByRef BitValue As Integer, ByRef Success As Boolean) ' Translates the specified space into a binary digit.
' Each space must be within this range.
Const MaxValue As Single = 1700.0E-6 Const MinValue As Single = 300.0E-6 ' This is the crossover point between binary 0 and 1.
Const TripPoint As Single = 1000.0E-6 Const UnitConversion As Single = 135.63368E-9 ' => 1.0 / 7372800.0 Dim SpaceWidth As Single
' Convert to seconds.
SpaceWidth = CSng(Space) * UnitConversion
If (SpaceWidth < MinValue) Or (SpaceWidth > MaxValue) Then Success = False
Exit Sub Else Success = True End If
If (SpaceWidth > TripPoint) Then BitValue = 1
Else BitValue = 0 End If
End Sub '————————————————————————————————- Sub Initialize()
' Wait for power to stabilize Call Delay(0.25)
' Used for serial port communications Call OpenSerialPort(1, 19200)
End Sub
Of critical importance is the Select Case structure, which compares the values that are
returned from the remote These were the actual numeric values obtained using the Sharp
TV code setting mentioned earlier If your universal remote doesn’t support these samevalues, you can easily determine the correct values to use for each button press on the
remote through the code in Listing 34.3, RemoteTest.Bas (Only the Main subroutine is
shown; the other routines in SharpRemote.Bas, given in Listing 34.2, are used as is.)
LISTING 34.3 REMOTETEST.BAS.
Sub Main() Dim I As Integer, Digit As Byte, Success As Boolean
COMMANDING A ROBOT WITH INFRARED REMOTE CONTROL 547
Trang 3Call Initialize Do
Call InputCapture(PulseTrain, MaxPulses, 0)
I = 2 Digit = 1 Value = 0 Do Call TranslateSpace(PulseTrain(I), BitValue, Success)
If (Success) Then Call PutI(BitValue) Value = Value * 2 Value = Value + BitValue Else
GoTo Continue End If
I = I + 2 Digit = Digit + 1 Loop While I <= (MaxPulses - 1) Call PutByte (9)
Call PutI (Value) Call Delay(0.5) Call NewLine Continue:
Loop End SubWhen this program is run, pressing keys on the remote control should yield somethinglike the following on the BasicX Development Program debug window:
CONTROLLING ROBOT MOTORS WITH THE SHARPREMOTE.BAS PROGRAM
The SharpRemote.Bas program assumes that you’re driving the traditional two-motorrobot, using DC motors (as opposed to stepper or modified servo motors) To operate arobot, connect a suitable motor driver circuit to pins 17 through 20 of the BX-24 chip Youcan use most any motor driver that uses two bits per motor One bit controls the motordirection (0 is “forward”; 1 is “backward”), and another bit controls the motor’s power (0
is off; 1 is on) Chapter 18, “Working with DC Motors,” presents a variety of motor vers that you can use
dri-Note: Whatever motor drivers you use make sure that you provide adequate bypass tering This prevents excess noise from appearing on the incoming signal line from the IRreceiver-demodulator DC motors, particularly the inexpensive kind, generate copious noisefrom radio frequency (RF) interference as well as “hash” in the power supply lines of the
fil-548 REMOTE CONTROL SYSTEMS
Trang 4circuit If you fail to use adequate filtering unpredictable behavior will result Your best bet
is to use opto-coupling, with completely separate battery power supplies for the troller and IR electronics on the one hand and the motors and motor driver on the other
microcon-In SharpRemote.Bas, the following line,Motors(1) = bx00000100
Motors(2) = bx00000101 [etc.]
set up the bit patterns to use for the four pins controlling the motors Yes, the patterns showeight bits We’re only interested in the last four, so the first four are set to 0000 The bitsare in “DLDR” format That is, the left-most two bits control the left motor, and the right-
most two bits control the right motor The D represents direction; and L and R represent
left and right, as you’d expect
After the program has received a code pattern from the remote, it reconstructs that tern as a 16-bit word This word is then translated into a numeric equivalent, which is then
pat-used in the Select Case structure, as in the following example:
Select Case Value
Case 16706
Tx = "0"
MotorVal = 5 Case 16898
Tx = "1"
MotorVal = 1
The value 16706 represents the 0 button When it’s pressed, the program stores the string
“0” (for display in the debug window) as well as the motor value, 5 Five is used as “stop,”with both motors turning off (the numeric keypad on the remote forms a control diamond)
The program interprets the value 16898 received from the remote as a 1 and sets the MotorVal
to 1 The pattern for this value calls for the robot to turn left by turning off its right motor andturning on its left Review SharpRemote.Bas for other variations, which are self-explanatory.You will note that several of the buttons on the remote are not implemented and set theMotorVal to 5, or stop You can add your own functionality to these buttons as you see fit
For example, pressing the Volume Up/Down or Channel Up/Down buttons could control
the arm on your robot, if it’s so equipped
OPERATING THE ROBOT WITH THE REMOTE
Now that you have the remote control system working and you’re done testing, it’s time toplay! Disconnect the BX-24 chip from its programming cable, set your robot on theground, and apply all power In the beginning, the robot should not move Point the remote
control at the infrared receiver-demodulator, and press the 2 button (forward) The robot should move forward Press 5 to stop Press other buttons to test out the other features.
Trang 5face and the SharpRemote.Bas program for use with a wide variety of controllers, puters, and signal pattern formats Of course, you’ll need to revise the program as neces-sary, and determine the proper bit patterns to use.
com-You will probably find that the signal patterns used with a great many kinds of remotecontrols will be usable with the SharpRemote.Bas program You merely need to test theremote, using the RemoteTest.Bas variation to determine the values to use for each buttonpress The program still works even if the signal from the remote contains more data bitsthan the 16 provided For this application, it doesn’t really matter that the last couple of bitsare missing—we’re not trying to control a TV or VCR but our own robot, and the code val-ues for its control are up to us The only requirement is that each button on the remote mustproduce a unique value Things won’t work if pressing 2 and 5 yield the same value
Multifunction Encoder and Decoder Remote Control
Remote control devices, like those detailed in the previous section, typically use a special
function integrated circuit called an encoder to generate unique sequences of digital
puls-es that can then be used to modulate an infrared light beam or radio signal A matching
decoder, on the receiving end, translates the digital pulses back into the original format.
For example, pressing the number 5 on the remote control might emit a sequence of 1sand 0s like this:
0111000100010111The decoder receives this sequence and outputs a 5 In the previous section you used aBasicX-24 microcontroller as a kind of generic decoder for translating signals from a uni-versal remote control Another, less expensive, alternative is to use an encoder/decoder ICpair, which are available from a number of manufacturers such as National Semiconductor,Motorola, and Holtek In this section, we’ll examine a system that uses the popular HoltekHT-12E and HT-12D four-bit encoder/decoder The HT-12 chips are available from a num-ber of sources—you can also substitute most any encoder/decoder pair you wish to use.Most require minimal external parts and cost under $3 each, so you should feel free toexperiment
Fig 34.5 shows the pinout diagram for the HT-12E encoder Consult the data sheet for this
chip (available at www.holtek.com, Web site for the maker of the chip) for a variety of circuit
suggestions The HT chips support up to 256 different addresses To receive valid data, youmust set the same address on both the encoder and the decoder The data input is four bits(nibble), which you can connect to individual push-button switches You can press multipleswitches at a time for up to 16 different data values
The output of the HT-12E gates an astable multivibrator circuit that oscillates at imately 40 kHz I have specified the use of two high-output infrared LEDs The higher theoutput, the longer the range of your remote control system
approx-550 REMOTE CONTROL SYSTEMS
Trang 6Fig 34.6 shows the pinout diagram for the HT-12D decoder When used with infraredcommunications, the chip is typically connected to a receiver-demodulator that is “tuned”
to the 40 kHz modulation from the encoder When the 40 kHz signal is received, the ulation is stripped off, and only the digital signal generated by the HT-12E encoderremains This signal is applied to the input of the HT-12D encoder The Holtek Web pageprovides data sheets and circuit recommendations for the HT-12D chip
mod-There are five important outputs for the HT-12D: the four data lines (pins 10-13) andthe valid data line (pin 17) The valid data line is normally low When valid data is received,
it will “wink” high then low again At this point, you know the data on the data lines is
good The data lines are latching, which means their value remains until new data is
received
You can use the decoder with your robot in several ways One way is to connect each ofthe output lines to a relay This allows you to directly operate the motors of your robot Asdetailed in Chapter 18, “Working with DC Motors,” two relays could control the on/offoperation of the motors; and two more relays could control the direction of the motors.Chapter 18 also shows you how to use solid-state circuitry and specialty motor driver ICsinstead of relays
Another way to use the decoder is to connect the four lines to a microcontroller, such
as the Basic Stamp or the BasicX-24 In this way, you can send up to 16 different mands Each command could be interpreted as a unique function for your robot
com-Using Radio Control Instead of Infrared
If you need to control your robot over longer distances consider using radio signals instead
of infrared You can hack an old pair of walkie-talkies to serve as data transceivers, or evenbuild your own AM or FM transmitter and receiver But an easier (and probably more reli-able) method is to use ready-made transmitter/receiver modules Ming, Abacom, and sev-eral other companies make low-cost radio frequency modules that you can use to transmitand receive low-speed (less than 300 bits per second) digital signals Fig 34.7 shows trans-mitter/receiver boards from Ming Attached to them are “daughter boards” outfitted withHoltek HT-12E and HT-12D encoder/decoder chips
USING RADIO CONTROL INSTEAD OF INFRARED 551
1
18 +V Out Osc 1 Osc 2 TE AD11 AD10 AD9 AD8 Gnd
A7 A6 A5 A4 A3 A2 A1 A0
FIGURE 34.5 Pinout diagram for the
Holtek HT-12E encoder.
Trang 7The effective maximum range is from 20 to 100 feet, depending on whether you use
an external antenna and if there are any obstructions between the transmitter andreceiver More expensive units have increased power outputs, with ranges exceedingone mile You are not limited to using just encoder/decoders like the HT-12 You maywish to construct a remote control system using DTMF (dual-tone multifrequency) sys-tems, the same technology found in Touch-Tone phones Connect a DTMF encoder tothe transmitter and a DTMF decoder to the receiver Microcontrollers such as the BasicStamp can be used as either a DTMF encoder or decoder, or you can use specialty ICsmade for the job
552 REMOTE CONTROL SYSTEMS
1
18 +V VT Osc 1 Osc 2 Data in D11 D10 D9 D8 Gnd
A7 A6 A5 A4 A3 A2 A1 A0
FIGURE 34.6 Pinout diagram for the Holtek
HT-12D decoder.
FIGURE 34.7 RF transmitter/receiver modules can be used to remotely control
robots from a greater distance than with infrared systems.
Trang 8From Here
To learn more about… Read
Interfacing and controlling DC motors Chapter 18, “Working with DC Motors”
Connecting to computers and Chapter 29, “Interfacing with Computers and
Using the Basic Stamp microcontroller Chapter 31, “Using the Basic Stamp”
Using the BasicX microcontroller Chapter 32, “Using the BasicX Microcontroller”
FROM HERE 553
Trang 9This page intentionally left blank.
Trang 10SENSORS AND NAVIGATION
Copyright 2001 The McGraw-Hill Companies, Inc Click Here for Terms of Use.
Trang 11This page intentionally left blank.
Trang 12Like the human hand, robotic grippers often need a sense of touch to determine
if and when they have something in their grasp Knowing when to close the per to take hold of an object is only part of the story, however The amount ofpressure exerted on the object is also important Too little pressure and the objectmay slip out of grasp; too much pressure and the object may be damaged
grip-The human hand—indeed, nearly the entire body—has an immense network ofcomplex nerve endings that serve to sense touch and pressure Touch sensors in arobot gripper are much more crude, but for most hobby applications these sensorsserve their purpose: to provide nominal feedback on the presence of an object andthe pressure exerted on the object
This chapter deals with the fundamental design approaches for several sensing systems for use on robot grippers—or should the robot lack hands, else-where on the body of the robot Modify these systems as necessary to match thespecific gripper design you are using and the control electronics you are using tomonitor the sense of touch
touch-Note that in this chapter I make the distinction between “touch” and collision.Touch is a proactive event, where you specifically wish the robot to determine itsenvironment by making physical contact Conversely, collision is a reactive event,where (in most cases) you wish the robot to stop what it’s doing when a collision
is detected and back away from the condition Chapter 36, “Collision Avoidanceand Detection,” deals with the physical contact that results in collision
Trang 13Mechanical SwitchThe lowly mechanical switch is the most common, and simple, form of tactile (touch)feedback Most any momentary, spring-loaded switch will do When the robot makes con-tact, the switch closes, completing a circuit (or in some cases, the switch opens, breakingthe circuit) The switch may be directly connected to a motor or discrete circuit, or it may
be connected to a computer or microcontroller, as shown in Fig 35.1
You can choose from a wide variety of switch styles when designing contact switchesfor tactile feedback Leaf switches (sometimes referred to as Microswitch switches, after
a popular brand name) come with levers of different lengths that enhance the sensitivity ofthe switch You can also use miniature contact switches, like those used in keyboards andelectronic devices, as touch sensors on your robot
In all cases, mount the switch so it makes contact with whatever object you wish tosense In the case of a robotic gripper, you can mount the switch in the hand or finger sec-tions In the case of “feelers” for a smaller handless robot, the switch can be mounted fore
or aft It makes contact with an object as it rolls along the ground By changing thearrangement of the switch from vertical (see Fig 35.2), you can have the “feeler” deter-mine if it’s reached the edge of a table or a stair landing
Optical SensorsOptical sensors use a narrow beam of light to detect when an object is within the graspingarea of a gripper Optical sensors provide the most rudimentary form of touch sensitivityand are often used with other touch sensors, such as mechanical switches
558 ADDING THE SENSE OF TOUCH
Frame
Switch
FIGURE 35.1 A mechanical
switch makes a perfect touch sensor.
Vertical mount detectschanges in terrain
FIGURE 35.2 By orienting the switch to the vertical, your robot
can detect changes in topography, such as when it’s about to run off the edge of a table.
Trang 14Building an optical sensor into a gripper is easy Mount an infrared LED in one finger
or pincher; mount an infrared-sensitive phototransistor in another finger or pincher (seeFig 35.3) Where you place the LED and transistor along the length of the finger or pinch-
er determines the grasping area
Mounting the infrared pair on the tips of the fingers or pinchers provides for little ing area because the robot is told that an object is within range when only a small portion
grasp-of it can be grasped In most gripper designs, two or more LEDs and phototransistors areplaced along the length of the grippers or fingers to provide more positive control.Alternatively, you may wish to detect when an object is closest to the palm of the gripper.You’d mount the LED and phototransistor accordingly
Fig 35.4 shows the schematic diagram for a single LED-transistor pair Adjust the value
of R2 to increase or decrease the sensitivity of the phototransistor You may need to place
an infrared filter over the phototransistor to prevent it from triggering as a result of ent light sources (some phototransistors have the filter built into them already) Use anLED-transistor pair equipped with a lens to provide additional rejection of ambient lightand to increase sensitivity
ambi-During normal operation, the transistor is on because it is receiving light from the LED.When an object breaks the light path, the transistor switches off A control circuit con-nected to the conditioned transistor output detects the change and closes the gripper In apractical application, using a computer as a controller, you’d write a short software pro-gram to control the actuation of the gripper
Mechanical Pressure Sensors
An optical sensor is a go/no-go device that can detect only the presence of an object, notthe amount of pressure on it A pressure sensor detects the force exerted by the gripper on
MECHANICAL PRESSURE SENSORS 559
LED Phototransistor
FIGURE 35.3 An infrared LED and phototransistor
pair can be added to the fingers of a gripper to provide go/no-go grasp information.
Trang 15the object The sensor is connected to a converter circuit, or in some cases a servo circuit,
to control the amount of pressure applied to the object
Pressure sensors are best used on grippers where you have incremental control over theposition of the fingers or pinchers A pressure sensor would be of little value when usedwith a gripper that’s actuated by a solenoid The solenoid is either pulled in or it isn’t; thereare no in-between states Grippers actuated by motors are the best choices when you mustregulate the amount of pressure exerted on the object
CONDUCTIVE FOAM
You can make your own pressure sensor (or transducer) out of a piece of discarded ductive foam—the stuff used to package CMOS ICs The foam is like a resistor Attach twopieces of wire to either end of a one-inch square hunk and you get a resistance reading onyour volt-ohm meter Press down on the foam and the resistance lowers
con-The foam comes in many thicknesses and densities I’ve had the best luck with thesemistiff foam that bounces back to shape quickly after it’s squeezed Very dense foams arenot useful because they don’t quickly spring back to shape Save the foam from the vari-ous ICs you buy and test other types until you find the right stuff for you
Here’s how to make a “down-and-dirty” pressure sensor Cut a piece of foam 1/4-inchwide by 1-inch long Attach leads to it using 30-gauge wire-wrapping wire Wrap the wirethrough the foam in several places to ensure a good connection, then apply a dab of solder
to keep it in place Use flexible household adhesive to cement the transducer onto the tips
of the gripper fingers
A better way is to make the sensor by sandwiching several pieces of material together, asdepicted in Fig 35.5 The conductive foam is placed between two thin sheets of copper or alu-minum foil A short piece of 30 AWG wire-wrapping wire is lightly soldered onto the foil(when using aluminum foil, the wire is wound around one end) Mylar plastic, like the kindused to make heavy-duty garbage bags, is glued on the outside of the sensor to provide
560 ADDING THE SENSE OF TOUCH
+5V
R2 10K 270ΩR1
Infrared filter
To comparator, amplifier, A/D converter, etc.
FIGURE 35.4 The basic electronic circuit for an
infrared touch system Note the infrared filter; it helps prevent the pho- totransistor from being activated by ambient light.
Trang 16electrical insulation If the sensor is small and the sense of touch does not need to be too great,you can encase the foam and foil in heat-shrink tubing There are many sizes and thicknesses
of tubing; experiment with a few types until you find one that meets your requirements.The output of the transducers changes abruptly when they are pressed in The outputmay not return to its original resistance value (see Fig 35.6) So in the control software,you should always reset the transducer just prior to grasping an object
For example, the transducer may first register an output of 30K ohms (the exact valuedepends on the foam, the dimensions of the piece, and the distance between wire termi-nals) The software reads this value and uses it as the set point for normal (nongrasping)level to 30K When an object is grasped, the output drops to 5K The difference—25K—
is the amount of pressure Keep in mind that the resistance value is relative, and you mustexperiment to find out how much pressure is represented by each 1K of resistance change.The transducer may not go back to 30K when the object is released It may spring up to40K or go only as far as 25K The software uses this new value as the new set point for thenext occasion when the gripper grasps an object
STRAIN GAUGES
Obviously, the home-built pressure sensors described so far leave a lot to be desired interms of accuracy If you need greater accuracy, you should consider commercially avail-able strain gauges These work by registering the amount of strain (the same as pressure)exerted on various points along the surface of the gauge
MECHANICAL PRESSURE SENSORS 561
FIGURE 35.5 Construction detail for a pressure sensor using
con-ductive foam The leads are soldered or attached to foil (copper works best) Choose a foam that has a good “spring” to it.
Trang 17Strain gauges are somewhat pricey—about $10 and over in quantities of 5 or 10 Thecost may be offset by the increased accuracy the gauges offer You want a gauge that’s assmall as possible, preferably one mounted on a flexible membrane See Appendix B,
“Sources,” for a list of companies offering such gauges.”
CONVERTING PRESSURE DATA TO COMPUTER DATA
The output of both the homemade conductive foam pressure transducers and the straingauges is analog—a resistance or voltage Neither can be directly used by a computer, sothe output of these devices must be converted into digital form first
Both types of sensors are perfect for use with an analog-to-digital converter You canuse one ADC0808 chip (under $5) with up to eight sensors You select which sensor out-put you want to convert into digital form The converted output of the ADC0808 chip is an
eight-bit word, which can be fed directly to a microprocessor or computer port Fig 35.7a
shows a the basic wiring diagram for the ADC0808 chip, which can be used with
conduc-tive foam transducer; Fig 35.7b shows how to connect a conducconduc-tive foam transducer to
one of the analog inputs of the ADC0808
Notice the 10K resistor in Fig 35.7, placed in series between the pressure sensor andground This converts the output of the sensor from resistance to voltage You can changethe value of this resistor to alter the sensitivity of the circuit For more information onADCs, see Chapter 29, “Interfacing with Computers and Microcontrollers.”
Experimenting with Piezoelectric Touch Sensors
A new form of electricity was discovered just a little more than a century ago when the twoscientists Pierre and Jacques Curie placed a weight on a certain crystal The strain on the
562 ADDING THE SENSE OF TOUCH
3
0
0 1 2 3 4 5 6 7 8 9
115
202
Pressure (ounces)
PressRelease
Resistance(k ohms)
FIGURE 35.6 The response curve for the conductive foam
pres-sure sensor Note that the resistance varies depending on whether the foam is being pressed
or released.