specifying how the robot should respond. The second
portion of the program uses the parameters to actually
control the robot’s actions. Dividing the functionality this
way makes it much easier to port the algorithm to other
platforms.
After initialization, the program begins by calling the
Orientation routine discussed last month to obtain the tilt
and compass data from the tablet’s sensors. The amount
of forward/backward tilt is stored in Tilt1 and the side-to-side inclination in Tilt2 (assuming a landscape orientation
of the tablet). Notice that the tilt readings are set to zero
within a range of ± 20° around the normal position which
is a flat, face-up orientation unless offsets are provided in
the call to InitSensors.
Next, the amount of forward-backward tilt is
converted to a desired speed parameter (Speed) ranging
from 0% to 99% by multiplying the absolute value of
Tilt1 by 3. This means the full range can be obtained by
tilting the tablet ± 33°. In a similar manner, the side-to-side tilt is converted into a percentage of the amount of
turn the robot should make (TurnAmount).
Finally, the various combinations of the two relevant
tilts are used to establish the desired movement by
assigning the variable Direction the value of a
predetermined constant. As an example, if the tablet is
not tilted forward or backward, but is tilted to the right,
the variable Direction is set to RotR, indicating the robot
should rotate to the right.
The details of how these parameters are used is
shown in the second half of the main program in
Figure 2. The implementation is very easy because of the
integration of the RROS hardware with RobotBASIC’s
built-in commands. Let’s look at these commands.
The command rForward causes the RROS hardware
to move the robot forward or backward if a negative
parameter is used. The r Turn command causes the robot
to rotate right or left (negative parameters). The
remaining turning motions can be handled in various
70 SERVO 01.2014
Figure 4.
Figure 3.