![]() |
|
K ' N E X B O T (K'NEX Robot Sumo) - PART 2
Project Details
Contents
Introduction
Software & Hardware Details of K'NEXBOT
The BotBoard
Sensor Locations & Functions
Functional Logic for Robot Sumo
Circuit Schematics
INTRODUCTION
My name is Steven Kaehler. I work as an electrical engineer at the Boeing Company in Seattle Washington. My specialties are the design and use of instrumentation devices and systems (i.e. transducers, sensors, detectors, data systems and control systems) used to test airplane fuel systems. Over the last fifteen years, I have learned a great deal about how to measure and control many different things, and have found the application of this knowledge quite useful in robotics. I particularly like robotics because it brings together many technologies, including measurement and control, into a single cohesive system, and provides me with a lot of personal satisfaction pulling this off.
This is the conclusion of a two-part article series on my robot. In Part 1 of this article series I introduced you to my robot K'NEXBOT. I shared the trials and tribulations of designing and building him, and gave a high-level overview of the project along with some lessons I learned. This time I will continue at a more detailed level, down to the interconnections, logic, and program code, so you can see what went into it and how it all came together.
SOFTWARE AND HARDWARE DETAILS OF K'NEXBOT
The following are details of the actual interconnections and pinouts incorporated into K'NEXBOT. This information was compiled as I built the robot because, as an engineer, I know how important documentation is, and because I knew I'd never be able to remember all this stuff if I didn't write it down. Converting this information into a article was mainly an editing task, and so was not a lot of extra work.
The input/output (I/O) board provides the interface between the robot's sensors and motors, and the BOTBoard's I/O ports. It has buffer/drivers for the control relays, signal conditioning electronics for the sensors, indicators, and connectors to the robot, to the BOTBoard, and to the batteries. Everything pulls together through this board through the Robot Header Connector, the BOTBoard Header Connector, and the Power Connectors.
When I first started designing the robot, I planned on just such a board because I kind of figured the prototyping area on the BOTBoard1 would be too small for all the stuff I had planned. I therefore used the BOTBoard proto area for a few simple things including a header connector (described later) to this board.
THE ROBOT HEADER CONNECTOR
This connector couples the robot sensors and controls to the I/O board so that signal buffering and translation can be applied before they are passed on to or received from the BOTBoard. This type of interface allows easy and quick removal of the I/O board from the robot for modification or troubleshooting. The signals are grouped as motor controls (pins 1-8) and sensors (pins 9-16).
Pin Function
--- --------
1 Motor 2 (+ = FWD, -
= REV)
2 Motor 2 (- = FWD, +
= REV)
3 Motor 1 (+ = FWD, -
= REV)
4 Motor 1 (- = FWD, +
= REV)
5 N/C
6 -3V Battery
7 Battery Common
8 +3V Battery
Pin Function
--- --------
16 N/C
15 N/C - No pin
14 From Right Forward
Bumper Switch (unconditioned input to 4584)
13 From Left Foward Bumper
Switch (unconditioned input to 4584)
12 From Right Rear
Photosensor (unconditioned input to 4584)
11 From Left Rear
Photosensor (unconditioned input to 4584)
10 From Rear Front
Photosensor (unconditioned input to 4584)
9 From Left Front
Photosensor (unconditioned input to 4584)
THE INPUT/OUTPUT BOARD CONNECTOR
This connector accepts the other end of the ribbon jumper that connects to the BOTBoard. In connects the inputs and outputs
between the I/O board and the
BOTBoard as described below. Its pinout is identical to the BB header.
THE MOTOR DRIVER/BUFFER
The following chip (on the I/O board) is a dual 2-to-4 line multiplexer that serves both as a signal amplifier for the BB I/O lines and a logic guard to prevent illegal combinations of control signals from doing anything harmful. Signals such as simultaneous activation of the forward and reverse relays for the same motor would cause damage to the drive relays and batteries. Attempting to use any of these combinations with this chip will not cause any harm since the chip will execute them harmlessly. The chip enable is connected to the toggle switch at the top of the board which controls whether or not the motors can run. This permits operation of the BOTBoard without it being able to run the motors. The relay coils have reverse-biased diodes across them to protect the drivers from inductive kickback.
<SN74LS139 PINOUT> Mfr's Datasheet
Pin Function
--- --------
1 Enable to Vcc=OFF
or Ground=ON via I/O Switch
2 Control for Relay 4
<---------------------------- BB1 Port B, bit3
3 Control for Relay 1
<---------------------------- BB1 Port B, bit0
4 Output 0 - N/C
5 Output 1 to Relay 1
--------------------> Left Motor Forward Relay
6 Output 2 to Relay 4
--------------------> Left Motor Reverse Relay
7 Output 3 - N/C
8 Ground
Pin Function
--- --------
16 Vcc
15 Enable to Vcc=OFF or
Ground=ON via I/O Switch
14 Control for Relay 2
<---------------------------- BB1 Port B, bit1
13 Control for Relay 3
<---------------------------- BB1 Port B, bit2
12 Output 0 - N/C
11 Output 1 to Relay 2
-------------------> Right Motor Reverse Relay
10 Output 2 to Relay 3
-------------------> Right Motor Forward Relay
9 Output 3 - N/C
ROBOT ACTIONS - (Relays used to accomplish action) Relays Code (Hex)
OFF
Disconnect power to motors,
sit
(none) 00h
STOP Disconnect
power then reverse pulse (*) depends depends
FWD_R Left motor only
forward [pivot]
(1) 01h
FWD_L Right motor
only forward [pivot]
(2) 02h
FWD Both
motors
forward
(1+2) 03h
REV_L Right motor
only reverse [pivot]
(3) 04h
SPIN_CW Left motor forward, right
motor reverse (1+3) 05h
REV_R Left motor only
reverse [pivot]
(4) 08h
SPIN_CCW Left motor reverse, right
motor forward (2+4) 0Ah
REV Both
motors
reverse
(3+4) 0Ch
* = Quick opposite pulse of current motor command
THE POWER CONNECTORS
Power comes into the I/O board and feeds to all the robot's systems via one of several
two-pin connectors. One connector is tied to the 5V logic power bus and can be back-fed by
an external 5V power supply for programming. A second connector feeds the 5V power
bus through a voltage regulator, allowing the use of a 9V battery for logic power when
normally operating. The motor power feeds to the I/O board together with the motor
wiring through the Robot Header Connector.
This modularized approach to the robot wiring has proven to be very useful during
troubleshooting and allows relatively easy modification or repair of any subsystem.
K'NEXBOT's "brain" is a Marvin Green's BOTBoard1
utilizing a Motorola MC68HC811E2CFN2
processor which contains 2K of EEPROM for program code and 512 bytes of RAM for stack and
data. The BOTBoard1 is powered by a separate 9V battery, regulated to 5VDC. It
is mounted on the side of the frame above one of the drive wheels, opposite the I/O board
as shown in this photo. The sensor and
control systems also derive power from the 9V battery, leaving the other battery pack
(+/-3V) exclusively available to the motor power system
SW1
DIP switch 1 (Port E,
I/O bit 6)
SW2 DIP
switch 2 (Port E, I/O
bit 7)
SUMO
SW1=Off, SW2=Off - Default mode
NON_SUMO SW1=On, SW2=Off -
Non-sumo obstacle avoidance on bumper contact
IR_TEST SW1=Off, SW2=On -
IR sensor test mode
???
SW1=On, SW2=On - Yet to be determined
THE BOTBOARD (BB) HEADER CONNECTOR
This connector is located on the BOTBoard expansion area and feeds to the I/O board. It provides power and signal interface from the I/O board to the robot "brain" via a rainbow ribbon jumper. The header is currently segregated into an "input" side and an "output" side relative to the BOTBoard. Port E bits 6 & 7 are used for mode selection via a PC-mounted DIP switch on the BOTBoard, and so do not come through the ribbon cabe to the BB header.
The choice to use Port E as a binary sensor input port was a matter of location convenience. Port E is located nearer to the expansion area than Port C. Also, at some later date, I might possibly choose to connect the line sensors directly to Port E and read the analog levels rather than relying on the buffer chip.
Pin Function (Outputs from
BB)
BotBoard I/O
---
--------------------------
------------
1 N/C
2 To Relay
"4" Control <------------------------ Port B, bit 3
3 To Relay
"1" Control <------------------------ Port B, bit 0
4 To Relay
"2" Control <------------------------ Port B, bit 1
5 To Relay
"3" Control <------------------------ Port B, bit 2
6 N/C
7 N/C
8 Ground/Logic Common
-------------------------- BotBoard Ground
Pin Function (Inputs to BB)
--- -----------------------
16 +5V - Vcc - Regulated
Logic Power ------------ BotBoard Power
15 Output from Left Front
Line Sensor ----------->Port E, bit 3
14 Output from Left Rear
Line Sensor ------------>Port E, bit 1
13 Output from Left Front
Bumper Switch --------->Port E, bit 5
12 Output from Right Front
Bumper Switch -------->Port E, bit 4
11 Output from Right Rear
Line Sensor ----------->Port E, bit 0
10 Output from Right Front
Line Sensor ---------->Port E, bit 2
9 Ground/Logic Common
Port B Type:
Output Bits 0-3,6,7 Used
Bits 4,5 Available
Port E Type:
Input Bits
0-5 Used by sensors
Bits 6-7 Used by mode
switches
Port C Type:
Output Bits
0-7 Used
SENSOR LOCATIONS & FUNCTIONS - (BC=Behavior Code)
The text-graphic below represents a top (plan) view of the robot with its various line and bumper sensors labeled. The numbers in the picture below represent the I/O Port E bits to which the respective sensors are connected. Photo of bottom of robot showing sensors (another shot).
+----------------------------------------------------------------------------+
|
|
|
F R O N
T
Mode SW1 -> 6 |
|
Mode SW2 -> 7 |
|
=================================
|
|
(LFLS) LFBS RFBS
(RFLS)
|
|
|=3=| | 5 4
|
|=2=|
|
| L E F T
|===|
|
| |===| R I G H
T |
|
|===|
|
|
|===|
|
| S I D E
|===|
|
| |===| S I D
E |
|
|===| | 1 0
|
|===|
|
|
|===| |(LRLS) (RRLS)|
|===|
|
|
|===| +-----------------+
|===|
|
|
|
|
R E A
R
|
|
|
+----------------------------------------------------------------------------+
SW2 DIP switch
2
Port E, bit7
SW1 DIP switch
1
Port E, bit6
LFBS Left Front Bumper
Switch Port E, bit5
RFBS Right Front Bumper
Switch Port E, bit4
LFLS Left Front Line
Sensor Port E, bit3
RFLS Right Front Line
Sensor Port E, bit2
LRLS Left Rear Line
Sensor Port E, bit1
RRLS Right Rear Line
Sensor Port E, bit0
LFBS Left
Front Bumper Switch (Port E, I/O bit 5)
RFBS Right
Front Bumper Switch (Port E, I/O bit 4)
THE BUMPER SWITCH/LINE SENSOR CONDITIONER/BUFFER
The following chip (on the I/O board) is a hex Schmitt trigger that turns the raw line sensor signals into clean logic signals for the BB inputs. It is also used to drive the line sensor detection indicators (LEDs on the I/O board) for operator convenience. Photo showing bumper sensors.
<MC14584B PINOUT> Mfr's Datasheet
Pin Function
--- --------
1 Input from Right
Front (RF) Bumper Switch
2 Output to BB Input
(grn)
3 Input from Right
Rear (RR) Line Sensor
4 Output to LED &
BB Input (blu)
5 Input from Right
Front (RF) Line Sensor
6 Output to LED &
BB Input (org)
7 Ground
Pin Function
--- --------
14 Vcc, +5V
13 Input from Left Front
(LF) Bumper Switch
12 Output to BB Input (blk)
11 Input from Left Rear
(LR) Line Sensor
10 Output to LED & BB
Input (brn)
9 Input from Left
Front (LF) Line Sensor
8 Output to LED &
BB Input (vio)
Left
Microswitch
Right Microswitch
================
=================
N.C. ---------->
Ground
N.C. -----------> Ground
C. ------------> MC14584B, pin
13 C. -------------> MC14584B, pin 1
N.O. ---------->
Vcc
N.O. -----------> Vcc
Low - No opponent/obstacle contact. High - Opponent/obstacle contact.
LFLS Left
Front Line Sensor (Port E, I/O
bit 3)
RFLS Right
Front Line Sensor (Port E, I/O bit
2)
LRLS Left Rear
Line Sensor (Port E, I/O
bit 1)
RRLS Right Rear
Line Sensor (Port E, I/O bit
0)
Phototransistor/LED - Opto-interrupter Type: GE H20A1 or H20B1
Separated phototransistor & LED. Secured side by side facing toward floor.
Infrared emitter LED
"E" Cathode (-) (to
ground)
"+" Anode (+) (to 220
ohm res to Vcc)
Phototransitor
"D" Emitter (to 100K
res. to ground)
"+" Collector (to Vcc)
THE INFRARED RANGE FINDER Mfr's Datasheet
The distance sensor is a Sharp GP2D02 IR Range
Detector obtained as part of a group-buy by the SRS. It takes 5V power to
operate and has a single input
and output which control its operation and deliver the range data. Tom Dickens did a
nice write up on using this sensor that really helped me get it going for this
project. See his
website.
In "scan mode" the robot spins 5-10 degrees at a time on its center axis looking for a target/opponent within its measurement range (threshold set at reset). When it detects one, it stops scanning and blindly heads toward it. In "non-sumo" mode, the scanning will look for open space and stop so that robot can move toward it.
Initialize ranging system
Stop
Set max number of iterations
Loop
Scan for target
If target is in
range
Terminate looping
Else
Turn a little CW or CCW
Endif
Until max iterations completed
Return to rest of program
IR Sensor
Hookup to BOTBoard
============================
GP2D02:
BOTBoard 1
======
==========
Red: 5VDC Vcc
<------------------ HC11 Vcc
Black: Ground -------------------->
HC11 Ground
Data I/O:
========
Yellow: Vout on GP2D02 ------------> HC11
input port A2 (serial range data from GP2D02)
Ground ----/\/\/\---+---/\/\/\-----<
HC11 output port A7 (control to GP2D02)
10K | 10K
Green: Vin <--------+
BEHAVIORAL RESPONSE TO SENSORS
The table below defines the robot's behavior pattern for all possible sensor input combinations. The inputs were analyzed, appropriate responses defined, and common responses grouped. A "behavior code (BC)" from 1 to N was then assigned to each group. Currently, there are only ten different "response sequences" programmed into K'NEXBOT for all possible binary sensor inputs.
LFBS Left
Front Bumper Switch (Port E, I/O bit 5)
RFBS Right
Front Bumper Switch (Port E, I/O bit 4)
LFLS Left Front
Line Sensor (Port E, I/O bit
3)
RFLS Right
Front Line Sensor (Port E, I/O bit
2)
LRLS Left Rear
Line Sensor (Port E, I/O
bit 1)
RRLS Right Rear
Line Sensor (Port E, I/O bit
0)
Sequential Sensor_Input Code List
Bit> 5
4 3 2
1 0
LFBS RFBS LFLS
RFLS LRLS RRLS Actions
-- ---- ---- ---- ----
---- ---- -------
00 0
0 0 0
0 0 10, FWD
01 0
0 0 0
0 1 01, STOP,FWD_L,FWD
02 0
0 0 0
1 0 02, STOP,FWD_R,FWD
03 0
0 0 0
1 1 03, STOP,FWD
04 0
0 0 1
0 0 04, STOP,REV,REV_R,OFF,FWD,SCAN
05 0
0 0 1
0 1 01, STOP,FWD_L,FWD
06 0
0 0 1
1 0 10, FWD
07 0
0 0 1
1 1 10, FWD
08 0
0 1 0
0 0 05, STOP,REV,REV_L,OFF,FWD,SCAN
09 0
0 1 0
0 1 10, FWD
0A 0
0 1 0
1 0 02, STOP,FWD_R,FWD
0B 0
0 1 0
1 1 10, FWD
0C 0
0 1 1
0 0 06, STOP,REV,SPINCW,OFF,FWD,SCAN
0D 0
0 1 1
0 1 10, FWD
E0 0
0 1 1
1 0 10, FWD
0F 0
0 1 1
1 1 10, FWD
5 4 3
2 1 0
BC LFBS RFBS LFLS RFLS
LRLS RRLS Actions
-- ---- ---- ---- ---- ----
---- -------
10 0
1 0 0
0 0 08, FWD_R,FWD_R
11 0
1 0 0
0 1 10, FWD
12 0
1 0 0
1 0 10, FWD
13 0
1 0 0
1 1 10, FWD
14 0
1 0 1
0 0 08, FWD_R,FWD_R
15 0
1 0 1
0 1 08, FWD_R,FWD_R
16 0
1 0 1
1 0 08, FWD_R,FWD_R
17 0
1 0 1
1 1 08, FWD_R,FWD_R
18 0
1 1 0
0 0 08, FWD_R,FWD_R
19 0
1 1 0
0 1 08, FWD_R,FWD_R
1A 0
1 1 0
1 0 08, FWD_R,FWD_R
1B 0
1 1 0
1 1 08, FWD_R,FWD_R
1C 0
1 1 1
0 0 06, STOP,REV,SPINCW,OFF,FWD,SCAN
1D 0
1 1 1
0 1 08, FWD_R,FWD_R
1E 0
1 1 1
1 0 08, FWD_R,FWD_R
1F 0
1 1 1
1 1 08, FWD_R,FWD_R
5 4 3
2 1 0
BC LFBS RFBS LFLS RFLS
LRLS RRLS Actions
-- ---- ---- ---- ----
---- ---- -------
20 1
0 0 0
0 0 07, FWD_L,FWD_L
21 1
0 0 0
0 1 10, FWD
22 1
0 0 0
1 0 10, FWD
23 1
0 0 0
1 1 10, FWD
24 1
0 0 1
0 0 07, FWD_L,FWD_L
25 1
0 0 1
0 1 07, FWD_L,FWD_L
26 1
0 0 1
1 0 07, FWD_L,FWD_L
27 1
0 0 1
1 1 07, FWD_L,FWD_L
28 1
0 1 0
0 0 07, FWD_L,FWD_L
29 1
0 1 0
0 1 07, FWD_L,FWD_L
2A 1
0 1 0
1 0 07, FWD_L,FWD_L
2B 1
0 1 0
1 1 07, FWD_L,FWD_L
2C 1
0 1 1
0 0 09, STOP,REV,SPINCCW,OFF,FWD,SCAN
2D 1
0 1 1
0 1 07, FWD_L,FWD_L
2E 1
0 1 1
1 0 07, FWD_L,FWD_L
2F 1
0 1 1
1 1 07, FWD_L,FWD_L
5 4 3
2 1 0
BC LFBS RFBS LFLS RFLS
LRLS RRLS Actions
-- ---- ---- ---- ----
---- ---- -------
30 1
1 0 0
0 0 10, FWD
31 1
1 0 0
0 1 10, FWD
32 1
1 0 0
1 0 10, FWD
33 1
1 0 0
1 1 10, FWD
34 1
1 0 1
0 0 10, FWD
35 1
1 0 1
0 1 10, FWD
36 1
1 0 1
1 0 10, FWD
37 1
1 0 1
1 1 10, FWD
38 1
1 1 0
0 0 10, FWD
39 1
1 1 0
0 1 10, FWD
3A 1
1 1 0
1 0 10, FWD
3B 1
1 1 0
1 1 10, FWD
3C 1
1 1 1
0 0 09, STOP,REV,SPINCCW,OFF,FWD,SCAN
3D 1
1 1 1
0 1 10, FWD
3E 1
1 1 1
1 0 10, FWD
3F 1
1 1 1
1 1 10, FWD
FUNCTIONAL LOGIC FOR ROBOT SUMO
If the robot makes contact with the opponent without detecting the black/white line, it will attempt to turn itself so that it is pushing straight and centered at the opponent. It will continue to push the opponent off the ring, stopping at the black/white line only if both front sensors see it. This strategy may prove too simple in actual competition, but for now, it will do.
If any of the line sensors register without making contact with the opponent, the robot will immediately stop, move away from the line, turn in a new direction, and then scan the area searching for the opponent.
A forward-facing IR range sensor allows the robot to locate and move toward the opponent, thereby actively seeking him out. Alternatively, the IR sensor can also seek out open space when in non-sumo mode.
PSEUDO CODE FOR K'NEXBOT SUMO ROBOT SOFTWARE
The following is a general layout of the program in pseudocode. This helps one to
visualize all the elements without getting bogged down in the actual code. This can
be a problem when the code occupies many pages of a listing and you're trying to picture
the entire thing in your mind. Using the pseudocode approach allows you to decide
what needs to happen and when in the overall sequence. Once this is defined, then
real code can be written using the pseudocode as comments.
->Processor RESET
declare variables
declare constants
declare and load Get_Behavior data array
MAIN:
Initialize variables
Make sure motors are stopped
Set up I/O ports for use
Initialize IR range sensor
Set operating mode
Read mode switches
Read line sensors
Run IR Sensor test program if so selected
Scan all sensors
Get range reading
from IR
Send data to I/O
Port
Light LED if target
detected
Wait 5 seconds before moving
Blink activity LED
Scan area for opponent
if found go towards
him
otherwise just start
moving
DO:
Scan sensors
Decide on behavior
Send selected variable out
Port C
Execute behavior sequence
based on mode
if new
sensor inputs then abandon current sequence
Blink activity indicator
LOOP
Assorted Subroutines
END
SBASIC Source Listing for K'NEXBOT.BAS
Well, there you have it, a mini sumo robot in a nutshell. I hope you enjoyed
reading this article series and maybe found something useful or at least
interesting. I suspect that there will be changes and improvments made to K'NEXBOT
as time passes, so some of this information will lose its accuracy. It does work as
presented and if someone was to copy my design, they should be able to successfully
construct a robot like K'NEXBOT. Besides, I think he'd like a friend. I would like to encourage others to share
their experiences and projects as well.
Comments, questions, suggestions, corrections, whatever, email me at Steven.D.Kaehler@Boeing.com