← Back to Home · Back to Programming

Programming · Code Library

Reusable FTC code snippets

Drop-in helpers for drive, encoders, PID, and safety limits to speed up development.

What this is

  • A starter set of reusable patterns for FTC robots.
  • Focus on reliability and clarity over clever tricks.
  • Snippets you can adapt to your drivetrain and mechanisms.

When you need it

  • Bootstrapping a new codebase or training new members.
  • Need tested helpers for encoders, PID, or safety clamps.
  • Want consistent drive code across TeleOp and Auto.

How it works

  • Reusable drive: functions to set tank/mecanum powers with normalization and deadzones.
  • Encoder helpers: ticks↔distance conversions, reset-and-wait utilities, timeouts.
  • PID snippets: simple P or PD loops for heading/distance; clamp outputs; optional integral cap.
  • Safety limits: clip motor power, current soft limits on slides/arms, and timeouts around blocking moves.

Common mistakes

  • Copying snippets without matching motor directions or ticks-per-rev.
  • No output clamping → motors saturate and brown out.
  • Reusing PID gains from another robot without retuning.
  • Skipping timeouts around encoder moves.

How to test it

  • Run drive helpers on blocks; verify wheel directions and normalization.
  • Measure a known distance; confirm ticks↔inches math.
  • Test PID on a simple turn; check overshoot/settle, adjust P/D.
  • Trip safety limits deliberately (endstop); ensure power cuts or holds safely.

Related problems

  • Oscillation in turns → lower P or add small D; check heading units.
  • Slides stall → add current/position limits and timeouts.
  • Inconsistent distance → recalibrate wheel diameter, gear ratio, and ticks-per-rev.