Comparing LEGO SPIKE Prime Programming : Which Is Best for Robotics Competitions? – 2



This content originally appeared on DEV Community and was authored by 砂田沙耶

Does the Programming Environment Affect Precision? A 360° Rotation Test
When using LEGO SPIKE Prime in robotics competitions, does the choice of programming environment impact movement precision?
To investigate this, I conducted an experiment comparing different programming environments.

Tested Programming Environments

I compared the following four environments:

Robot Configuration

For the test, I used a car-type robot with the following setup:
•Left motor: Port A
•Right motor: Port B
Image description

Test Method

To compare the environments, I conducted the following test:

  • Command the robot to rotate 360° using a specified motor angle
  • Measure the difference between the target and actual rotation angles
  • Perform 10 trials for each environment and calculate the average error
  • The same logic was used for all environments

Program Code (for all environments):
Word Blocks (SPIKE App3)
Image description
Python (SPIKE App3)

tread = 8
d_tire = 5.6
goal = 360;

for i in range(10):
motor.reset_relative_position(port.A, 0)
start_angle = motor.relative_position(port.A)
motor.run(port.A, -300)
motor.run(port.B, -300)

while tread/d_tire*goal > -motor.relative_position(port.A):
pass

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

time.sleep_ms(500)
print("error:", abs(motor.relative_position(port.A)-start_angle) - tread/d_tire*goal )

Python (Pybricks)

hub = PrimeHub()
motorA = Motor(Port.A, Direction.COUNTERCLOCKWISE)
motorB = Motor(Port.B, Direction.CLOCKWISE)

tread = 8
d_tire = 5.6
goal = 360

for i in range(10):
start_angle = motorA.angle()

motorA.run(300)
motorB.run(-300)

while tread/d_tire*goal > motorA.angle() - start_angle:
pass

motorA.brake()
motorB.brake()

wait(500)
print("error", motorA.angle()-start_angle - tread/d_tire*goal )

C Language (spike-rt)

void Main(intptr_t exinf)
{
dly_tsk(5000000);

uint8_t tread = 8;
float d_tire = 5.6;
uint32_t goal = 360;

motorA = pup_motor_init(PBIO_PORT_ID_A, PUP_DIRECTION_COUNTERCLOCKWISE);
motorB = pup_motor_init(PBIO_PORT_ID_B, PUP_DIRECTION_CLOCKWISE);

int8_t i;
for (i = 0; i < 10; i++){
pup_motor_reset_count(motorA);

pup_motor_set_speed(motorA, 300);
pup_motor_set_speed(motorB, -300);

while(tread/d_tire*goal > pup_motor_get_count(motorA));

pup_motor_brake(motorA);
pup_motor_brake(motorB);

dly_tsk(500000);

float error = pup_motor_get_count(motorA) - (tread / d_tire * goal);
syslog(LOG_NOTICE, "error: %d.%05d", (int)error, (int)((error - (int)error) * 100000));
}
}

Results: Which Environment Was Most Precise?

Image description
Here are the average rotation errors (smaller is better):
1⃣ 12° – C Language (spike-rt) 🏆
2⃣ 13° – Python (Pybricks)
2⃣ 13° – Python (SPIKE App 3)
4⃣ 14° – Word Blocks (SPIKE App 3)
Additionally, I measured the error fluctuation range (consistency):
1⃣ 2° – Python (SPIKE App 3) 🏆
2⃣ 3° – C Language (spike-rt)
2⃣ 3° – Word Blocks (SPIKE App 3)
4⃣ 5° – Python (Pybricks)

Key Takeaways:
C Language (spike-rt) had the most accurate rotation (smallest error)
Python (SPIKE App 3) had the most stable results (smallest variation)

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:

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


This content originally appeared on DEV Community and was authored by 砂田沙耶