gosub InitCommands // found in the include file
PortNum = 5 // set to your Bluetooth Port
to write RROS programs. The third line sets a
variable equal to the port number of your PC’s
Bluetooth connection. The main program calls a
subroutine to initialize the robot. Once
initialized, the robot can be moved using simple
commands as shown.
In this example program, the robot is moved
40 units forward. It then turns 180° and moves
back to its original position. If either of the
motors moves backwards when tested, just
reverse the wires for that motor.
If the simulator was initialized (instead of
the DC motor robot), the units for rForward are
screen pixels. The simulated robot is 40 pixels in
diameter, so the command rForward 40 will
move the simulated robot a distance equal to its
diameter. Ideally, the same command should
move the real robot a distance equal to its
diameter. Precise control of a robot’s movements normally
requires the drive motors to be equipped with wheel
encoders that produce pulses as the wheels turn. Counting
these pulses makes it easy for the control program to
monitor the robot’s movements.
The RROS chip supports wheel encoders, but there is
no reason to add the cost or complexity to a beginner-bot
because the RROS chip can be calibrated for timed
responses when encoders are not available. Look at the
initialization routine in Figure 11.
As mentioned earlier, if you issue the rForward 40
command, the robot should move a distance equal to its
diameter. If it’s moving too short or too far, adjust the
parameter for the best results. The robot should also turn
90° when executing the r Turn 90 command. Increase or
decrease the rotation parameter to produce accurate turns.
The first line in the subroutine sets up the
communication link with the Bluetooth port assigned
earlier. The second line initializes the RROS chip (if the
It’s important to realize that timed movements and
drifting corrections will never be as accurate as wheel
encoders (which you can add later as your skill level and
budget increases). Even when you think you have the
timing calibrated, a drop in the battery voltage can screw
everything up again. Just remember, this is an entry-level
robot, so you can’t expect perfect performance.
Bluetooth link has been enabled). Next, we need to tell the
chip we are using small DC motors and set the speed we
want (0-100). Since our robot is not using wheel encoders,
it will almost certainly drift to the right or left because no
two motors are exactly alike. The RROS allows you to
reduce the speed for either the left or right wheel as
shown. For my robot, I needed to reduce the speed of the
right wheel by 5%. You will need to experiment to find
what works for your robot.
The good news is that once we add sensory
capabilities, the robot can be programmed to use sensor
data to correct its actions. Such corrections often produce
adequate performance for many behaviors even without
A Servomotor Robot
The next two lines establish how long the motors will
run when the robot is moving forward and making turns.
If you prefer servomotors over DC motors, the RROS
can accommodate. Everything in Figure 9 is the same
except for the motor connections. Just interface the
SERVO 12.2017 57