Building and Programming A Mini-Sumo
Building and Programming A Mini-Sumo
Overview
Building a mini-sumo robot using the IntelliBrain™ robotics controller is a great
way for you to learn about robotics and Java™ software development. The
RoboJDE™ Java-enabled robotics software development environment (included
with IntelliBrain) allows you to download the example mini-sumo robot application
discussed here into your IntelliBrain controller. With RoboJDE you can modify
the example mini-sumo application or write your own mini-sumo program to
improve the competitiveness of the robot.
Mini-sumo robots are small autonomous mobile robots designed specifically for
sumo style competition. The mini-sumo robot competition rules restrict the robot
All the hardware components you will need to build the robot discussed here are
readily available. A mini-sumo robot can be assembled in a few hours or less.
Once you have assembled your robot, you can load the mini-sumo example
program included with the RoboJDE software and have your robot ready for its
first competition in just minutes! Once you have your robot up and running, the
well documented example source code, the extensive robotics class library, and
the easy to use integrated development environment will make improving your
robot’s intelligence and competitiveness a snap!
If you are new to mini-sumo competition, Robot Sumo: The Official Guide by
Pete Miles (McGraw-Hill/Osborne 2002) is an excellent book about building
robots, the rules for competitive robot sumo events and how to build your own
dohyo.
Theory of Operation
To be effective, a mini-sumo robot must be able to do the following:
The following sections describe how the mini-sumo robot accomplishes these
things.
Servo motors have built-in control circuitry designed to rotate the output shaft to
a specific position and hold that position. The servos used in the mini-sumo
robot are designed for use in model airplanes to control the position of the
airplane’s ailerons and rudder. These servo motors are light, relatively powerful,
and inexpensive. However, to be useful for the mini-sumo robot the servos must
be modified to allow for continuous rotation of the wheels and variable speed
control. Fortunately, this is fairly easy to do, or you can purchase the servos pre-
modified.
The servo modification involves removing mechanical stops that limit the range of
rotation and disconnecting the position sensing potentiometer from the rest of the
mechanism. Once this is done, the potentiometer is calibrated so the servo’s
control circuit always thinks the output shaft is at the center of its range.
Unmodified servos are controlled by periodically pulsing the servo’s signal input,
as shown in Figure 2. A 1 millisecond pulse commands the servo to position the
output shaft to one end of its range (0%). A 2 millisecond pulse commands the
servo to position the output shaft at the other end of its range (100%). By varying
the pulse width, the shaft can be positioned between these two extremes.
Modified servos use the same control signaling but the modification results in the
ability to control the speed of the shaft rather than its position. This is exactly
what is needed to steer the robot. Disconnecting the position sensing
potentiometer from the rest of the mechanics and calibrating it to the 50%
(centered) position causes the control electronics in the servo to think the shaft is
always centered. If the control signal commands the servo to a position other
than the center, the control electronics will apply power to rotate the shaft,
attempting to move it to the commanded position, but the feedback from the
potentiometer leads the control circuit to think the shaft hasn’t moved, so it will
continue to power the motor and spin the output shaft. The control circuit will
apply more power the greater it thinks the error is between the desired position
and the actual position. Therefore, the power applied to the motor can be varied
by varying the pulse width of the control signal, giving the ability to drive the
Servo Modified
Position Control Servo
Command Signal Behavior
Full Power
0% Reverse
1.0 ms
50% No Power
1.5 ms
Full Power
100%
Forward
2.0 ms
~18 ms
Mini-Sumo Hardware
All the hardware components you will need to build your mini-sumo robot are
listed in Table 2.
Table 2 - Mini-Sumo Hardware
Qty Part Supplier
Controller
1 IntelliBrain main board www.ridgesoft.com
Program Files\RoboJDE\Examples\MiniSumo\IntelliBrainMiniSumo.rpj
Note: When attaching the GP2D12 sensors, insert a 1/16 inch thick #4 screw
size washer between the scoop and the sensor. Otherwise, the sensor will point
down slightly due to contact between the IntelliBrain controller board and the
GP2D12 sensor.
The Mark III uses hobby aircraft servos which must be modified for continuous
rotation. You may purchase the servos pre-modified, or modify them yourself
according to the directions on the Junun web site. Be sure your servos are
modified before assembling the Mark III.
Attach the sensors to the Mark III according to the directions on the Junun web
site. The mini-sumo application only requires two line sensors, left and right, so
you will not need to install a line sensor at the center of the scoop.
Connecting Servos
The servo motors have connectors pre-installed, so they may be plugged in
without attaching a connector, however, BE VERY CAREFUL TO CONNECT
THE SERVO PLUG TO THE INTELLIBRAIN IN THE CORRECT ORIENTATION!
The black wire should be on the pin at the front edge of the board. Plugging the
servo in the wrong way around will likely destroy the servo’s control circuitry.
The left servo connects to servo port 1, the port nearest the left edge of the
board. The right servo connects to servo port 2.
Forward
Range Sensors
Left Right Left Right
Analog 1 Analog 2
Servos Line Sensors
Left Right Left Right
Servo 1 Servo 2 Analog 4 Analog 5
RoboJDE v1.3.0r3
Ready
START STOP
Connector
GP2D12 Wires
Ground (black)
Power (red)
Signal (white)
RoboJDE v1.3.0r1
Ready
Analog4 Signal
Analog5 Signal
Analog6 Signal
Analog7 Signal
Analog3 Signal
Servo1 Signal
Servo2 Signal
Servo Power
IR Rx Signal
START STOP
IO2 Signal
IO6 Signal
IO9 Signal
CPU ALE
CPU A11
I2C SDA
Ground
Ground
Ground
RD_L
+5V
40
2
39
1
Ground
Servo Control A
Servo Control B
RST_L
WR_L
Line A
Line B
Ground
I2C SCL
Ground
Line C
Line D
EXP_SELECT_L
IO10 Signal
IO3 Signal
IO8 Signal
Main Battery
CPU A10
CPU A12
+5V
Mini-Sumo Software
Once you have constructed your mini-sumo robot you must download the
example application to the robot. Loading the software and testing your robot is
quick and easy. The following sections discuss how to load the software, test
that the sensors are functioning, and run your robot.
Program Files\RoboJDE\Examples\MiniSumo\IntelliBrainMiniSumo.rjp.
Next, click on the “Download” button on the tool bar. This will compile the
example application and download it to the robot. Finally, press the “Run” button
on the tool bar to start the application. Alternatively, you can press the “START”
button on the robot to start the application. By default, the application will be
stored in RAM and will be lost when the robot is powered off. If you want the
IntelliBrain to remember the program when power is switched off, you must load
the application to flash memory. To do this, use the drop down selector on the
tool bar to set the load location to FLASH and repeat the download process.
Note: Loading programs to flash memory is slower and the life of the flash
There is one test for each of the four sensors. You can scroll through the tests
by rotating the thumbwheel. The LCD screen displays the name of the sensor
under test and the current value reported by the sensor. The line sensors should
read a high value (~950) when over a black surface and a low value (~40) when
over a white surface. The range sensors should read approximately 500 when 4
inches from a wall. The range sensor reading should drop as the robot moves
away from the wall. Be sure to check that each sensor reads correctly and that
the left and right sensors are not swapped.
Software Implementation
The mini-sumo example application has been implemented in Java. If you are
not familiar with Java programming, Java is a high-level programming language
with a syntax derived from C and C++. If you have experience with C, C++ or
another high-level programming language, understanding the mini-sumo
example source code should not be difficult. If you would like to learn more
about Java programming, the Java Primer on the RidgeSoft web site contains a
brief overview of Java programming. There are also many good educational
resources available, including the book, Just Java by Peter van der Linden (Sun
Microsystems Press).
IntelliBrainMiniSumo.main() Method
The application starts in the IntelliBrainMiniSumo.main() method by
retrieving a reference to the Display object from the class HandyBoard using
the following statement:
The Display object provides a method to print text on specific lines of the LCD
screen. The program identifies itself to the user with the following statement:
display.print(0, "iBrainMiniSumo");
The BasicMiniSumo class also requires AnalogInput objects for each of the
sensors, which are obtained as follows:
sumo.go();
BasicMiniSumo.go() Method
Thread.sleep(1000);
while(true) {
… // sensor sampling code
switch (state) {
case SURVIVE:
… // survive code
break;
case HUNT:
… // hunt code
break;
case TARGET:
… // target code
break;
case ATTACK:
… // attack code
break;
}
}
Sensor Sampling
The line sensor analog input is sampled and converted to a boolean value which
is true if the sensor is detecting the edge of the dohyo. This is done by sampling
the AnalogInput and comparing it to a threshold value. If the reading is below
the threshold value it is assumed that the sensor is over the edge of the dohyo.
(The sensor reading is lower when over white than when over black.) This is
done as follows:
The range sensors are analog inputs. The sensors will read high when close to
an object. The range sensors are sampled and the average and the difference of
the two range sensors are calculated using these statements:
If the opponent is sensed, the rangeAverage will be higher than when the
opponent is not in front of the sensors. The rangeDifference is used to target
the opponent. If one sensor senses the opponent, but the other does not, the
rangeDifference will be high. If the opponent is straight ahead the
rangeAverage will be high and the rangeDifference will be low.
Each state needs to check for the edge of the dohyo. To avoid duplicating the
check in several states and to accelerate transitions to the SURVIVE state, this
check is done before the switch statement:
if (atLeftEdge || atRightEdge)
state = SURVIVE;
SURVIVE State
if (atLeftEdge) {
rotate(-135);
searchClockwise = true;
}
else if (atRightEdge) {
rotate(135);
HUNT State
if (rangeAverage > mTargetThreshold)
state = TARGET;
else if (searchClockwise)
arc(mHuntPower, mHuntFactor);
else
arc(mHuntPower, -mHuntFactor);
TARGET State
if (rangeDifference > mTargetThreshold)
spin(false, mSpinPower);
else if (-rangeDifference > mTargetThreshold)
spin(true, mSpinPower);
else if (rangeAverage > mAttackThreshold)
state = ATTACK;
else if (rangeAverage > mTargetThreshold)
forward(mTargetPower);
else
state = HUNT;
ATTACK State
forward(mAttackPower);
forward(int power)
arc(int power, int factor)
spin(boolean clockwise, int power)
rotate(int degrees)
stop()
Forward
The forward method attempts to move the robot straight forward by setting the
power to both motors to the same level.
mLeftMotor.setPower(power);
mRightMotor.setPower(power);
Arc
The arc method attempts to move the robot forward arcing to the left or right by
applying slightly more power to one motor than the other.
mLeftMotor.setPower(power + factor);
Spin
The spin method attempts to spin the robot in place without a specified stopping
point by running the motors in opposite directions.
if (clockwise) {
mLeftMotor.setPower(power);
mRightMotor.setPower(-power);
}
else {
mLeftMotor.setPower(-power);
mRightMotor.setPower(power);
}
Rotate
The rotate method attempts to rotate the robot a specified number of degrees
by running the motors in opposite directions for a fixed time per degree of robot
rotation.
if (degrees < 0) {
degrees = -degrees;
mLeftMotor.setPower(mRotatePower);
mRightMotor.setPower(-mRotatePower);
}
else {
mLeftMotor.setPower(-mRotatePower);
mRightMotor.setPower(mRotatePower);
}
try {
Thread.sleep(degrees * mRotateFactor);
}
catch (InterruptedException e) {}
stop();
Stop
Turns off the motors.
mLeftMotor.setPower(0);
mRightMotor.setPower(0);
Conclusion
Building a robot is a fun and rewarding way to learn about and enjoy electronics,
mechanics and software development. The IntelliBrain robotics controller is very
powerful and flexible, allowing you to build highly intelligent robots. RoboJDE
provides a modern software development environment, a rich robotics software
library, example applications, and a robust execution environment that will make
developing your robotic software a pleasure. And, because Java is a modern,
standardized and widely used language, the programming skills you acquire
through robotics can be applied to many other fields.