Comparing LEGO SPIKE Prime Programming : Which Is Best for Robotics Competitions? - 1

by sunata-s0907 in Circuits > Robots

128 Views, 3 Favorites, 0 Comments

Comparing LEGO SPIKE Prime Programming : Which Is Best for Robotics Competitions? - 1

cover_Instructables.png

Does Programming Environment Affect Performance? A Comparison for Robotics Competitions

When using LEGO SPIKE Prime for a robotics competition, does the programming environment impact performance? I conducted an experiment to compare different programming environments and see how they affect robot movement.

Supplies

1 PC with Windows 10 or 11 operating system.

Tested Programming Environments

I compared the following four environments:

  1. Word Blocks (SPIKE App 3)Download here
  2. Python (SPIKE App 3)Download here
  3. Python (Pybricks)More info
  4. C Language (spike-rt)GitHub repository

Test Method

To compare the environments, I ran the following test:

✅ The robot moves straight and stops when the color sensor detects red

✅ Travel distance before detection: ~30 cm

✅ Speed: ~900 deg/s

✅ Measure the stopping distance (braking distance) from the moment red is detected until the robot stops completely

✅ Conduct five trials for each environment and calculate the average stopping distance

✅ The same logic was used for all environments

Program Code

pg_wordblock.PNG

Python (SPIKE App 3)

from hub import port
import motor,color_sensor,time
import color

motor.run(port.A, -900)
motor.run(port.B, 900)

while color_sensor.color(port.C) != color.RED:
pass

motor.stop(port.A,stop=motor.BRAKE)
motor.stop(port.B,stop=motor.BRAKE)

time.sleep_ms(1000)

Python (Pybricks)

from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor
from pybricks.parameters import Color, Port, Stop
from pybricks.tools import wait

# Initialize the sensor.
sensor = ColorSensor(Port.C)

# Initialize the motor.
left_motor = Motor(Port.A)
right_motor = Motor(Port.B)

wait(500)

left_motor.run(-900)
right_motor.run(900)
while sensor.color() != Color.RED:
pass
left_motor.brake()
right_motor.brake()

wait(1000)

C Language (spike-rt)

#include <stdlib.h>
#include <kernel.h>

#include <spike/hub/system.h>

#include <stopAtRed.h>

#include "spike/pup/motor.h"
#include "spike/pup/colorsensor.h"

#include <pbio/color.h>

pup_motor_t *motorA; // Variable for using motor A
pup_motor_t *motorB; // Variable for using motor B
pup_device_t *ColorSensor; // Variable for using color sensor

void Main(intptr_t exinf)
{
// Wait 3 seconds
dly_tsk(1000000);

motorA = pup_motor_init(PBIO_PORT_ID_A, PUP_DIRECTION_COUNTERCLOCKWISE);
motorB = pup_motor_init(PBIO_PORT_ID_B, PUP_DIRECTION_CLOCKWISE);
ColorSensor = pup_color_sensor_get_device(PBIO_PORT_ID_C);
pup_motor_set_speed(motorA, 900);
pup_motor_set_speed(motorB, 900);

while(pup_color_sensor_color_name(ColorSensor, true) != 'r');

pup_motor_brake(motorA);
pup_motor_brake(motorB);

dly_tsk(1000000);
// End the program
exit(0);
}

Robot Configuration

ロボット.PNG

I used the following robot setup:

  1. Left motor: Port A
  2. Right motor: Port B
  3. Color sensor: Port C


Results: Which Environment Performed Best?

Comparing LEGO SPIKE Prime Programming : Which is Best for Robotics Competitions? - 1

Here are the average stopping distances (shorter is better):

1️⃣ 24mm - C Language (spike-rt)🏆

2️⃣ 26.6mm - Python (Pybricks)

3️⃣ 27mm - Word Blocks (SPIKE App 3)

4️⃣ 27.2mm - Python (SPIKE App 3)

🔹 The C language environment (spike-rt) had the shortest stopping distance, meaning it responded the fastest.


Want to Try C Programming on LEGO SPIKE Prime?

If you’re interested in trying C on SPIKE Prime, there are beginner-friendly learning materials available. As of March 2025, a trial version is also accessible—give it a try!

To See More

If you're interested in more LEGO SPIKE Prime experiments with C language, check out this related article:

🔹 Introducing SPIKE-RT: the C Language Software Platform for LEGO SPIKE Prime

🔹 Enhancing LEGO SPIKE Prime Line Follower with C: Speed & Stability Comparison


More tests are planned, including further evaluations for robotics competitions. Stay tuned for future updates! 🚀