WRO 2025 SENIOR
“102 SEC” ROBOT’S
PROGRAM DESCRIPTION.
Contents
Preface ………………………………………………………… 2
PD line follower …………………………………………… 3
Smooth braking ……….………………………………….. 9
PD_Motor …………..…………………………………….. 10
PD_Rotate ………..………………………………………. 12
Smooth movements ………….….….……………….. 14
Stable movements …………………………………….. 19
Concept and Strategy ..………………………………. 21
Main blocks ………………………………………………. 21
Auxiliary blocks …………………………………………. 23
RGB block ………………………………………………….. 25
Algorithm ………………………………………………….. 27
1
Preface
The file represents methods implemented to the robot and describes
the program written in EV3G.
The instruction, the Studio 2.0 file and extra videos with more placings
are also provided.
It is important to know that the robot will not do the task perfectly
right after you build it, connect the cables and upload the program.
You will probably have to adjust degrees, sensors’ thresholds for
scanning lines and colors. To simplify this process, I strongly
recommend to use motors for moving with the same power and the
sensors for line following with the same values on black and white
colors on the map.
The power of the motors can be checked this way:
I prefer to check the power without any loadings.
Sensors’ values can be checked in the EV3 block in Port View. You need
to look at their values on black and white colors. The difference
between two sensors should not be above 1-3. If it is more, the robot
will be budged either left of right relative the line while following it,
which is not very good.
2
The robot also uses RGB block:
You need to import this block. In EV3G open Tools -> Block Import and
import the needed block. Ev3b file with this block is provided with
other files in the Boosty/Patreon post.
PD line follower
One of the most popular questions – how to make a robot follow a line
perfectly without twitching.
PD line follower is an answer.
It is based on a simple idea: U = KP * e + KD * (e – e_old). Let’s figure
out what these letters mean.
U is a so-called “guiding influence”. This is a correction to motors’
speed.
KP, KD – some coefficients, they are found by selection. Usually KD ≈
KP * 10.
3
e – “error”, current difference between line following sensors, e_old –
the difference on the previous iteration.
This algorithm works pretty well if you find good KP and KD. However,
sometimes the robot might stand inaccurately on the line, for example
after turning or doing any other complicated movements. In this case
PD might “save the robot”, but the further PD will be provided with
twitching. Thus, the robot will arrive to the needed spot inaccurately,
which can lead to big mess.
There is a good solution of this problem, I called it “evening out”.
This means the robot will follow the line some time to stand accurately
on the line. This is like a PD with the specific speed, KP and KD to make
the further movements slight and smooth (KP and KD in this case might
be bigger than usually). As the robot evens out, we know it definitely
stands accurately on the line.
4
The robot may pass crossroads; to avoid twitching after passing we can
restrict motors’ speed.
We do not allow the speed to decrease or increase to the specific
numbers, which allows the robot to follow the line perfectly.
Let’s look at the PD represented in the program.
5
There are three main PDs – PD_Enc, PD_Cross_X and PD_Cross_T.
PD_Enc is a PD which goes until the number of needed degrees is
achieved.
The 1st parameter is speed
The 2nd is a number of degrees
The 3rd one is interesting. This parameter is “1” by default (“True”),
which means “evening out” will be performed (“0” – it will not).
Sometimes this is not necessary for a robot to even out, for example
when it is going on one PD and you want to switch on a new one.
The 4th is “Type”. There is a special block named Types, there are
movements that must be performed right after PD, or the motors are
just stopped (type = 0), or the motors continue rotating (type = -1, it is
used when we switch current PD on another immediately). You can
choose a movement robot will do after PD by writing a number which
corresponds this movement.
The next two are PD_Cross_X and PD_Cross_T. There are two types of
crossroads – type “X” and type “T”. It is better to separate them.
6
Type “T” Type “X”
The only difference between these two PDs is a condition of defining
the crossroad.
PD_Cross_X checks if every individual sensor reached the crossroad:
PD_Cross_T checks if the sum of the sensors’ values is less than the
specific number:
Let’s look at the parameters:
7
The 1st parameter is speed.
The 2nd is a number of degrees the robot goes before it starts checking
the crossroad.
The 3rd is a number of degrees the robot goes after the crossroad.
The 4th – “evening out” (“1” – it is performed, “0” – it is not).
The 5th parameter is responsible for slowing down after the crossroad
(This parameter obviously makes sense only if the 3rd parameter is
above 0). “1” means the speed will decrease to 20, “0” means the
speed will stay the same.
The 6th is “Type”.
It is worth mentioning that the number of degrees is not taken from
one motor, it is an average number from both:
It is important to notice a block named Kp. Its purpose is to set KP
depending on a speed:
8
There is also a special variable s_even, which purpose is to set the
speed of the evening out:
Taken from Payload
Important notion! The beams which are under the line following
sensors must be black because black color does not affect the reflected
light values.
Smooth braking
There is a term we should pay attention to - “Smooth braking”. When
the robot goes with a high speed it can slip some degrees before
scanning a crossroad or anything else. To avoid it we should decrease
speed in advance – 200-300 degrees before checking. Let’s imagine a
situation – the robot has to go ~1700 degrees until the sensors start
checking. Two PDs should be used – PD_Enc to go 1700 degrees with
high speed and the rest of the route should be gone with PD_Enc with
the smaller speed:
9
Taken from Payload
PD_Enc has “-1” as the fourth parameter so that the motors would go
on rotating. PD_Enc has “0” as the third parameter so that the robot
would not even out since the robot goes accurately already.
PD_Motor
To control the robot’s elevator, it is also better to use PD, because it
should be lifted or lowered accurately. The principle is the same, but e
(error) now is the difference between needed degree and current
degree.
Taken from PD_Motor
10
The 1st parameter is motor’s speed
The 2nd is the needed degree
If the 3rd is “-1”, the motor will continue rotating,
otherwise the motor will stop
It is important to notice that before using this block so-called “zero
position” needs to be set. This means that we reset the encoder in the
certain position and PD_Motor will set further elevator’s positions
relative to the “zero position”. I decided the zero position should be
set in the starting position, when the elevator is pressed to the robot.
Taken from Start
In the upper branch we set “zero position” after pressing the elevator
by resetting the motor D encoder.
11
There is a special block Calibration which purpose is to set the zero
position before any further actions, which is useful for adjusting
separate parts of the program.
To make the program more convenient, four special variables were
made:
Taken from Initialization
Their purpose is to transfer the degrees values to PD_Motor in
different parts of the program.
m_0 is the highest elevator’s position right before opening the gripper;
m_1 is the middle position between m_0 and m_2;
m_2 is the default and the preferred position for moving;
m_3 is the lowest position.
PD_Rotate
To control the robot’s twister, PD is used as well. The principle is the
same as in PD_Motor:
12
Taken from PD_Rotate
The 1st parameter is motor’s speed
The 2nd is the needed degree. If the degree is
positive, the twister will rotate clockwise, if
negative – counterclockwise.
There is a special variable rotate which contains the number of
degrees needed to twist by 90 ° (π/2) clockwise:
Important notion! If the twister rotated 90°, for example, clockwise,
that means the current degree will correspond to the rotate variable
value. If the robot needs to rotate 180° relative to the current position
(the direction of rotating does not matter in this case) such action
needs to be implemented either like this:
13
Or like this:
Smooth movements
In this program some experimental blocks were made. Their goal is to
make the robot fulfill some movements smoother.
There is a formula in physics:
S means the path, V – the final speed, Vo means the initial speed and
a is acceleration.
This formula is applied in the GO blocks. Let’s figure out how this works
at the MyBlock’s GO_FORWARD example.
The path is divided into three main parts: acceleration, continuous
movement and deceleration. Variables enc_1, enc_2 and enc_3 are
responsible for keeping the degrees of these paths.
14
Before acceleration
Before deceleration
Variable a is acceleration or deceleration. It is counted twice (before
accelerating or decelerating) according to the formula including the
path degrees, the initial and the final speeds.
Variable s is the instant speed which is constantly changing while
acceleration or deceleration:
Acceleration
Deceleration
15
It is accounted so that the speed would not be lower than the initial or
higher than the final:
Acceleration
Deceleration
It is also accounted so that when decelerating the root would not have
negative value in it:
16
The continuous moving contains PD regulator which works when the
speed is above 80 (however, in this program there are no places with
such speed).
Kp_GO is MyBlock where kp and kd are
either both 0, or they have certain values if v
> 80
Other GO MyBlocks work with the same logic. GO_ONE and
GO_TURNING do not contain PD regulators for continuous moving.
Now let’s look at the parameters of all the GO MyBlocks:
GO_FORWARD/GO_BACK –
makes the robot move
forward/back.
1st parameter is the final speed.
2nd parameter is the initial speed.
3rd parameter is the number of degrees for accelerating.
4th parameter is the number of degrees for continuous moving.
17
5th parameter is the number of degrees for decelerating.
6th parameter is either “-1” (or any other value except for “1”) or “1”.
“-1” means the motors will not stop, “1” means the motors will stop.
GO_TURING – makes the robot turn
either clockwise or opposite
clockwise.
1st parameter is the final speed.
2nd parameter is the initial speed.
3rd parameter is the number of degrees for accelerating.
4th parameter is the number of degrees for continuous moving.
5th parameter is the number of degrees for decelerating.
6th parameter is either “-1” (or any other value except for “1”) or “1”.
“1” means the motors will turn clockwise, “-1” means opposite.
GO_ONE – makes the robot
turn with one wheel.
1st parameter is the final speed.
2nd parameter is the initial speed.
3rd parameter is the number of degrees for accelerating.
4th parameter is the number of degrees for continuous moving.
5th parameter is the number of degrees for decelerating.
6th parameter is the number of motor: “3” is motor C, “2” is motor B.
18
7th parameter is either “-1” (or any other value except for “1”) or “1”.
“1” means the motor will rotate positive direction, “-1” means
negative.
8th parameter is either “-1” (or any other value except for “1”) or “1”.
“-1” means the motor will not stop, “1” means the motor will stop.
Stable movements
To make a robot move more stable several things should be
comprehended.
First of all, we should understand the difference between “green” and
“blue” motors’ blocks:
Green motor blocks have some kind of a regulator inside them for
speed supporting. This means the motor will always rotate with the
selected speed.
Blue motor block does not always support the needed speed. This
block is more compromising, when meeting any obstacles the motors
will not try to rotate with the supposed speed. The speed can also
decrease with the battery level.
Blue motor blocks, for example, are usually used when a robot is
moving along the wall.
19
I prefer to use blue motor blocks in the line follower, the robot seems
to move smoother than with green motor blocks.
To make movements stable there need to be a small pause (0.1-0.3
seconds) if the robot switches blue motor block to green one and vice
versa so that the robot would not bevel:
Taken from Start
Another thing is worth mentioning: it is good to make some
movements without breaks. For example, the robot goes some
degrees and needs to continue moving with one wheel. In this case the
next steps should be carried out: one wheel is stopped and the other
one continues rotating. The example:
Taken from Start
In the opposite situation this logic works as well. If the robot goes with
one wheel and after needs to go straight the second motor needs to
be turned on:
Taken from Start
20
Now let’s sum up the information. The blue motor block is better to be
used in PD or while moving along the wall and needs to be used in the
movements that are right after PD. In cases of going straight and
moving with one-wheel green motors are more suitable. If the robot
stops after using blue motor block, some pause should be held before
using green motor blocks.
Concept and Strategy
The robot begins with turning the yellow hatch. Next, the robot
delivers the rocket noses one by one. After, the robot scans all the
markers and pulls the red hatch. Then, the robot brings the payload to
the target area. After that, the robot goes for the bolts and sorts them.
While going to the first rocket integration area the robot rises both
flags. Finally, the robot brings the bolts to their areas.
There are only two things that depend on the placing – the payload
rotation and the bolts’ sorting. All the movements are always the
same. The fastest placing is 102 seconds, while the longest is 116 – the
robot is always in time.
Main blocks
Initialization – all the variables and arrays are originated
here.
21
Start – the robot moves from the start and turns the
yellow hatch.
Noses – the robot delivers red and yellow rocket noses
parts to their areas.
Scanning – the robot scans and records all the markers
and pulls the red hatch out.
Payload – the robot takes the payload, rotates it
according to the marker and delivers it to the target area.
Bolts – the robot takes the bolts, sorts them according to
the markers, rises the flags and delivers the bolts to their
areas.
22
Auxiliary blocks
Turning – allows the robot to revolve over its axis.
The robot rotates until the sensor which is the
closest to the line scans it.
The 1st parameter is the direction – “1” is
clockwise, “0” is not clockwise.
The 2nd is the number of degrees the robot rotates (average of each
motor) before the closest sensor starts checking the line.
Manipulator – makes some procedures with the
motor D.
“1” - to rapidly rise the elevator
“11” - to slowly rise the elevator
“10” - to rapidly lower the elevator
“100” - to slowly lower the elevator
Color_define – the block which defines the color of
the element.
The 1st parameter is the number of the sensor which
scans.
The 2nd is the output parameter with the number of the defined color
(2 – blue, 3 – green, 4 – yellow, 5 - red).
23
Sorting – the block used for logical procedures and
sorting the bolts.
Taking_Out – the block used taking the bolts out two
after other two.
Swap – the block used swapping two bolts
closest to the robot.
The 1st parameter is the number variable rotate
is multiplied by.
If the 2nd parameter is “1”, the robot will not swap the bolts but will
only go to the wall and take all the bolts.
Flags – the robot rises flags one after another.
24
RGB block
RGB block is used for scanning, it is needed to define the color of the
markers:
Taken from Color_Define
RGB-components are recorded in three variables – r, g and bl.
If B-component is the highest among RGB, then the color is blue.
Variable blue is added with 1:
Taken from Color_Define
If G-component is the highest among RGB, then the color is green.
Variable green is added with 1:
25
Taken from Color_Define
If R-component is the highest among RGB, then the percentage of G-
component in R + G is checked. If the percentage is more than 0.25,
the color is yellow (variable yellow is added with 1), red otherwise
(variable red is added with 1):
Taken from Color_Define
These switches are repeated for 0.1 second. After, the name of the
variable with the maximum number corresponds to the color of the
marker. The switches for defining the maximum go after the 0.1
second cycle:
Taken from Color_Define
26
The RGB values can be checked this way using EV3 block display:
Taken from Test
Algorithm
The logic in the program is pretty complicated. Let’s begin with the
payload first. Its marker is scanned and recorded in variable
orientation:
Taken from Scanning
Depending on the variable the payload is rotated (or not):
Taken from Payload
27
Now let’s move to the bolts. The markers are scanned and recorded in
the array Colors (2 – blue, 3 – green, 4 – yellow, 5 - red). The indexes
of the markers correspond to this picture:
The marker with index “0” is not scanned – it is counted after scanning
other three markers:
Taken from Sorting
The sorting process is pretty complicated. I found a pattern in the case
when the sum of the nearest (“01” or “23”) indexes’ values is 7:
Taken from Sorting
28
The actions in this case are always the same, only the twister rotation
differs. Array Numbers keeps the numbers (the first four indexes) by
which variable rotate multiplies. The fifth index keeps either “0” or “1”
– the second parameter of the Swap MyBlock.
In other cases the indexes of Colors array are checked and the sorting
is carried out according to them:
Taken from Sorting
29