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

by sunata-s0907 in Circuits > Robots

20 Views, 0 Favorites, 0 Comments

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

cover.png

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.

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

Robot Configuration

car.png

For the test, I used a car-type robot with the following setup:

  1. Left motor: Port A
  2. Right motor: Port B

Test Method

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

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

code_wordblock.png

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?

Results.PNG

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️⃣ - Python (SPIKE App 3) 🏆

2️⃣ - C Language (spike-rt)

2️⃣ - Word Blocks (SPIKE App 3)

4️⃣ - 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:

  1. Enhancing LEGO SPIKE Prime Line Follower With C: Speed & Stability Comparison
  2. Introducing SPIKE-RT: the C Language Software Platform for LEGO SPIKE Prime
  3. Comparing LEGO SPIKE Prime Programming: Which Is Best for Robotics Competitions? - 1
  4. Comparing LEGO SPIKE Prime Programming: Which Is Best for Robotics Competitions? - 3 (Coming Soon)

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