ASTI Robotics Challenge 2026 · Final in Burgos

The robot, event by event

I programmed a robot with mecanum wheels in Arduino to compete in the ASTI Robotics Challenge. Each event asked for something different, so I wrote a separate program for each one. Here I explain what each program does and why I solved it that way.

The robot running the line-follower track.
Close-up of the robot on the track, with the line sensor bar and its green LED lit
The line sensor bar, with its green LED, just above the track.
Checking the robot by hand, with the wiring, mecanum wheels and ultrasonic sensor in view
Checking the robot between runs: wiring, mecanum wheels and ultrasonic sensor.
Osoyoo M2Chassis with 4 mecanum wheels, each motor with its own speed and direction
Arduino MegaDrives the 4 motors via PWMPWM 9 · 10 · 11 · 12
5 IR line sensorsRead the floor from left to rightA4 · A3 · A2 · A1 · A0
Ultrasonic sensorMeasures the distance to whatever is in frontTrig 30 · Echo 31
ServoTurns the ultrasonic sensor in the radar version of sumoPin 13

Adapting the code to the robot

A program that looks right on paper is useless if the robot doesn't respond as expected. This chassis has its limits, and a big part of the work was tuning the software to how the hardware actually behaves.

HardwareNo encoders: it can't tell how far each wheel has turned
SoftwareMove by time, calibrating how long it takes to travel 1 cm and turn 1°
Shapes
HardwareMecanum wheels slip, so the robot doesn't do exactly what it's told
SoftwareValues tuned by testing on paper, and lower speeds
Shapes · Sumo
HardwareThe ultrasonic sensor loses the opponent when it's right up close
SoftwareBlind charge: keep pushing for a few cycles after losing it
Sumo
HardwareWith a fixed sensor, the robot only sees what's straight ahead
SoftwareA version with the sensor on a servo that sweeps like a radar
Sumo
HardwareWhen braking, the robot keeps drifting a little
SoftwarePauses between moves and a full stop before reversing
Shapes · Sumo
HardwareDepending on the model, the line sensors give inverted readings
SoftwareThe edge reading is defined in a single constant that's easy to flip
Sumo · Line follower

Two robots in a ring. Whoever pushes the other out wins. The challenge isn't just pushing: the robot has to find the opponent, go for it and, above all, not drive out on its own.

On every pass of loop() the program decides what to do using a fixed order of priorities:

What it does at each moment

  1. Stay in the ringIf any of the 5 sensors sees the edge line, it brakes, backs up and turns inwards. This is checked before anything else.
  2. AttackIf the ultrasonic sensor sees the opponent in range, it drives towards it. When it gets close, it switches to charging speed.
  3. Blind chargeIf it has just seen the opponent and loses it, it keeps pushing for a few more cycles instead of starting to search.
  4. SearchIf it sees nothing, it spins on the spot until it finds the opponent.

Two versions

I tried two ways of finding the opponent. In the first, the sensor is fixed and the whole robot turns. In the second, the sensor sits on a servo that sweeps from side to side like a radar, and the robot remembers which side it saw the opponent on.

ParameterFixed sensor (V4.0)Servo radar
Detection distance45 cm30 cm
Charging distance20 cm40 cm
Search speed (0–255)100120 · 90 while sweeping
Attack speed140120
Edge escape speed140200
Blind charge25 cycles40 head-on · 15 from the side
Escape manoeuvre350 ms back + 350 ms turn300 ms back + 400 ms turn
Servo sweep—40° to 140°, in 10° steps

Why I did it this way

  • The edge comes firstLeaving the ring means losing the bout instantly, so reading the line sensors is the first thing in loop(). However close the opponent is, if the robot touches the edge, it escapes.
  • Escape to the opposite sideIf the left sensors see the edge, it turns right, and vice versa. If only the centre one sees it, it turns for longer to spin almost all the way round.
  • A pause before reversingIt stops for 40–50 ms before backing up. Going straight from forward to reverse is hard on the motors and gearbox.
  • The blind chargeThe ultrasonic sensor has a blind spot: when the opponent is pressed right against the robot, it stops seeing it. Without this memory, the robot would start searching at the very moment it has the opponent in front of it, pushing.
  • Low speeds in V4.0At higher speeds the robot loses traction and, on impact, momentum can carry it out of the ring itself. Turning more slowly while searching also means it doesn't skip past the opponent between one reading and the next.
  • Breaking the search loopIf it spends 5 seconds spinning on the spot without seeing anything, it drives forward for half a second to change position. That way it doesn't keep spinning forever in a spot where it can't see the opponent.
  • Timers with millis()The search doesn't use delay() to count those 5 seconds. If it did, the robot would be “asleep” and wouldn't read the edge in the meantime.
  • No echo doesn't mean 0 cmIf the ultrasonic sensor gets no echo, the function returns 999 instead of 0. If it returned 0, the robot would think the opponent was right against it and attack thin air.
  • Only detect inside the ringIn the radar version I lowered the range to 30 cm so it wouldn't pick up objects outside the ring.
  • Wait 5 seconds at the startThe ASTI rules require it, so the robot stays still when it starts.

Line follower

The robot has to complete a circuit following a black line as fast as possible without losing it on the curves.

The 5 sensors are combined into a single 5-bit number, one bit per sensor, from left to right. That way every situation is a number, and the program decides with a switch:

The robot on the line-follower track, with curves, straight sections and grids, while the audience watches
The track: smooth curves, right-angle turns and grids where it's easy to lose the line.

What it does depending on what it sees

00100 · 01110
Straight at full speedBoth sides at 255
00110 · 00010
Gentle right curveLeft at 255, right at 70
01100 · 01000
Gentle left curveLeft at 70, right at 255
00011 · 00001
Sharp right turnOne wheel forward and the other backward, at 100
11000 · 10000
Sharp left turnThe same, the other way
00000
Line lostTurns towards the side where it last saw it. If it lost it going straight, it backs up slowly

Why I did it this way

  • One number instead of lots of ifsWith 5 sensors there are many combinations. Turning them into a 5-bit number puts each case on one line of the switch, so you can see at a glance what the robot does in each situation.
  • No wheel stops on gentle curvesIf I fully stop the inner motor on a curve, the robot jerks and vibrates. Leaving it at 70 instead of 0, it turns smoothly and keeps its speed.
  • Remembering the last sideOn a sharp curve, the line slips off one side before it disappears. If I store that side, when the robot sees nothing it knows which way to turn to find it again instead of guessing.
  • Ignoring odd readingsCombinations that make no sense, like scattered sensors triggered by a reflection, fall into the default case and the robot carries on with what it was doing. That way a one-off bad reading doesn't make it swerve.

The robot has to draw shapes on paper to exact measurements: a square, a rectangle and a triangle.

The problem is that this robot has no encoders, so it can't tell how far each wheel has turned. The solution was to measure with time: I calibrated how long it takes to travel 1 cm and to turn 1 degree, and used that to write two functions that take centimetres and degrees.

Calibration

Travel 1 cm: 75 ms at speed 160.
Turn 1°: 6 ms at speed 130.

How a shape is drawn

Each shape is a list of straight sections and left turns, with a pause between each one. It all goes in setup() so the robot draws it only once.

The software was adapted to the robot

This event showed it more than any other. Mecanum wheels have rollers that slip slightly, the motors don't all respond the same way and there are no encoders to correct on the fly. If you ask the robot for 20 cm and 90°, you don't get 20 cm and 90°.

So the program had to be fitted to the robot, not the other way round: draw the shape, measure what it had actually done and correct the values until it came out right. That's why the numbers passed to avanzar() (move forward) and girarIzquierda() (turn left) aren't the measurements from the task. They're the ones that work with this robot. For example, to make it really turn 90°, the code asks for 72.

// 90° corner on the paper
girarIzquierda(72);   // value tuned by testing with the robot
// Moves the requested centimetres using the calibrated time
void avanzar(int centimetros) {
  forward(MAX_SPEED, MAX_SPEED);
  delay(centimetros * TIEMPO_1CM);
  stop_bot();
}

Why I did it this way

  • Functions in centimetres and degreesThat way each shape is written with distances and angles rather than loose milliseconds. If the battery or the surface changes, the robot behaves differently and the values need re-tuning.
  • 400 ms pauses between sectionsWhen it brakes, the robot still drifts a little. Waiting for it to settle before the next move makes every section and every turn come out the same.
  • Turning on the spotTo turn, the wheels on one side go forward and those on the other go backward. That way the robot turns without shifting and the corner stays in place.
  • 3 seconds before startingThat's the time I have to set it down properly on the paper after switching it on.

Besides the events, the repository includes two examples from the manufacturer. With WiFi control the robot creates its own network and is driven from a phone app, which sends it one letter per button. This is where mecanum wheels shine: as well as moving forward and turning, the robot can move sideways and diagonally without turning its body.

These two programs are based on Osoyoo's tutorials for this chassis. In robot.ino I left my notes while studying it. The mini sumo, line follower and shapes programs are my own.

The podcast

Cover of episode 2 of Código Abierto: Rumbo a la final ASTI Robotics Challenge. Technology, programming and robotics, with four Digitech students

Código Abierto · Digitech FP · Episode 2 · May 2026 · 34 min · In Spanish

Rumbo a la final: robótica y tecnología en ASTI Robotics Challenge

Before the final, my school's podcast brought together students from several Digitech teams to talk about how each project started, the technologies we used and what preparing for the competition was like. I took part for the Robolabs team.

Listen on Spotify