General Programming Strategy
We regularly use various MyBlocks, also known as functions, which allow us to reuse code whenever
possible and to keep our program sizes manageable. Our MyBlocks and parameters are given descriptive
and meaningful names to allow us to easily understand what our programs are doing. We also annotate our
programs to help us with debugging and to better understand the purpose of each line of code.
We have created a main selection program, which allows us to quickly and efficiently choose missions
(or even re-run missions quickly) during matches. Sounds and meaningful EV3 screen messages allow the
robot technicians to select programs with ease.
Instead of using standard calibrated values, we use raw light sensor values for more granularity. Our
calibration program collects the lowest and highest light readings the robot would see. Then, based on
those, we scale any light readings to a usable range where 0 is black and 100 is white.
By using gear lash removal before each robot movement, the acceleration and deceleration movements when
starting and stopping a movement, our own error-corrected move block, and proportional line following,
we are able to achieve more consistent and repeatable robot movements.
When accelerating from a stationary position, our robot uses Ctrl-Z-designed acceleration and
deceleration features to minimize the likelihood of wheel slip. This provides for greater repeatability
of the robot’s movements.
We make frequent use of our square up MyBlock which allows the robot to position itself perpendicularly
to any line (from virtually any angle of attack).
Within all of our major movement MyBlocks (such as our error-corrected move MyBlock and proportional
line following MyBlock), we have another MyBlock inside, called Check_Exit, that is constantly checking
if a certain exit condition is met. When that exit condition is met, the program immediately exits that
loop causing the robot to advance to the next robot maneuver. For example, stop the robot when one of
the light sensors detects a black line.
Program Hierarchy
In the interest of maximizing programming efficiency, we use functions whenever possible.
Functions are used for typical robot movements, like line following, squaring to a line,
error-corrected movements, etc., as well as for entire missions.
The use of subroutines allows us to re-use programming code and enjoy the benefits of an
efficient mission selection program. The diagram below illustrates the great extent
to which Ctrl-Z re-uses programming code.
Function Examples
Main Selection Program
This selection program allows us to quickly and
efficiently switch programs/missions
during the two-and-a-half minute match.
Our selection program contains functions, each containing one of our missions.
The user of the robot simply starts the selection
program and clicks the centre button to start the first
mission. Then, when the mission finishes, the robot
automatically advances to the next mission and waits for
the user to click the centre button to run the appropriate mission.
In case one needs to go backwards or
forwards through the list of missions, the program
accommodates that by allowing the user to navigate
with the left and right arrow buttons.
Proportional Line Following
We have created a line following function that turns the robot proportionally
to the distance of the light sensor from the edge of the black line.
Square Up
We have created a function that makes the robot completely perpendicular to the edge of a black line.
Each light sensor corresponds with a motor. The robot drives up to the line and has the light sensor check the
reflected light values. If the light sensor sees a value of less than 50 (black), it will tell the motor to move
towards a value greater than 50 (white). It does this for both motors for a set amount of time while slowly decreasing in power,
until the robot becomes completely perpendicular to the edge of the line.