Programming

Advanced programming techniques, platform evolution, and strategy integration

Programming

Platform Evolution

SPIKE Prime App

SPIKE Prime

Block Programming

Pybricks

Pybricks

MicroPython

95%

Consistency

±2°

Turn Accuracy

Key Improvements

Anthony
  • Higher loop frequency for smoother motion
  • Direct gyro access for accurate heading control
  • Encoder precision for exact distance and rotations
  • PID corrections for drift compensation

Code Examples

SPIKE Prime block-based programming Pybricks code screenshot

We tested various Kp and Kd values to optimize drive performance. Our best results came from Kp=1.15 and Kd=0.02.

Programming & Strategy Integration

Code supports mission grouping and quick attachment swaps — teams can switch runs with minimal reconfiguration and rely on consistent sensor feedback.

Encapsulated run scripts for A-E runs
Parameterized speed/turn settings per attachment
Automated sensor calibration routines
Kp Tuning (Heading Error in Degrees)
Kd Tuning (Heading Error in Degrees)

Code Implementation

Drive Straight Function
def drive_straight(distance_mm, speed, kp=1.15, kd=0.02):
  robot.reset_gyro()
  robot.reset_encoders()
  
  while robot.get_distance() < distance_mm:
      error = robot.get_heading()
      correction = (kp * error) + (kd * (error - prev_error))
      left_power = speed - correction
      right_power = speed + correction
      
      robot.set_motors(left_power, right_power)
      prev_error = error
  
  robot.stop()
Turn Function
def turn(degrees, speed, kp=1.0):
  robot.reset_gyro()
  
  while abs(robot.get_heading()) < abs(degrees):
      error = degrees - robot.get_heading()
      power = kp * error
      
      robot.set_motors(power, -power)
  
  robot.stop()

Our drive-straight code uses PID-style corrections with optimized values: Kp=1.15 and Kd=0.02. These values emerged from systematic testing across different speeds and distances, resulting in repeatable and reliable performance, even under varying loads and battery levels.

Version Control with GitHub

Why We Use GitHub

GitHub allows our team to collaborate on code safely. Each team member can work on different runs or features without overwriting others' work.

We use branches for experimental changes and commits to track our progress. This means if something breaks, we can roll back to a working version.

Benefits for Our Team
  • Collaboration:Multiple programmers can work simultaneously
  • History:Every change is documented with commit messages
  • Backup:Code is safely stored in the cloud
  • Testing:We can experiment without breaking working code
  • Learning:We review each other's code and learn better practices
GitHub in Action
GitHub repository screenshot

We organize runs, attachments, and PID tuning experiments with clear commit history and pull requests.