Skip to content

Interactive Code Playground

The MARSLib Code Playground is an interactive learning environment where you can explore real programming patterns from championship-winning FRC robots. Experiment with swerve drive control, vision alignment, PID mechanisms, and state machines - all in your browser.

The Code Playground demonstrates production-ready MARSLib patterns used by FRC Team 2614. Each example includes:

Real Code - Actual patterns from competition robots, not simplified examples ✅ Best Practices - Proper Command-based programming and AdvantageKit logging ✅ Safety First - Fault handling and state management built-in ✅ Performance - Zero-allocation patterns and real-time control

Learn the fundamentals of controlling a swerve drive robot using MARSLib’s abstraction layer. This example shows:

  • ChassisSpeeds for robot-relative control.
  • Proper Command structure with requirements.
  • Real-time velocity control for competitive play.

Explore automatic AprilTag alignment using MARSLib’s vision system. Demonstrates:

  • Vision pose estimation fusion.
  • PID controllers for precise positioning.
  • Continuous angle handling for rotation.

Master position control with linear mechanisms. Features:

  • LinearMechanismIO abstraction layer.
  • PID control with feedforward for gravity compensation.
  • Proper periodic() update patterns.

Coordinate complex mechanisms using MARSLib state machines. Shows:

  • MARSStateMachine for multi-system coordination.
  • Safe state transitions and behaviors.
  • Emergency stop (E-Stop) setup.

All examples follow WPILib’s Command-based programming pattern:

public class ExampleCommand extends Command {
private final Subsystem subsystem;
public ExampleCommand(Subsystem subsystem) {
this.subsystem = subsystem;
addRequirements(subsystem); // Declare requirements
}
@Override
public void execute() {
// Control logic here
}
}

MARSLib separates logic from hardware through interfaces:

// Your subsystem logic works with any IO implementation
public class MechanismSubsystem extends Subsystem {
private final MechanismIO io; // Can be Real or Sim
@Override
public void periodic() {
// Works the same on robot and in simulation!
double position = io.getPosition();
}
}

All subsystems automatically log state for AdvantageScope:

// MARSLib handles logging automatically
// No manual logging code needed in your subsystems

DO use Command-based programming for autonomous and teleop ✅ DO use MARSLib’s IO abstractions for hardware independence ✅ DO use state machines for complex mechanism coordination ✅ DO tune PID gains using SysId characterization ✅ DO implement safety mechanisms (E-Stop, limits)

DON’T put hardware-specific code in your commands ❌ DON’T ignore feedback from sensors ❌ DON’T skip proper requirement management ❌ DON’T forget about fault tolerance ❌ DON’T block in execute() methods

  1. Clone the MARSLib repository and explore the full codebase.
  2. Run the simulator to see these patterns in action.
  3. Modify the examples to learn by experimentation.
  4. Build your own mechanisms using MARSLib patterns.
  • ✅ Command-based programming.
  • ✅ State machines with MARSStateMachine.
  • ✅ Vision-based alignment using MARSVision.
  • ✅ PID control with feedforward.
  • ✅ Swerve drive kinematics.
  • ✅ Mechanism coordination.

All examples follow MARSLib’s core structure:

    
flowchart TD
  A["Command"] --> B["Subsystem"]
  B --> C["IO Interface"]
  C --> D["IOReal (Hardware)"]
  C --> E["IOSim (Physics)"]
  B --> F["AdvantageKit Log"]
  style A fill:#1a1a1a,stroke:#B32416,stroke-width:2px,color:#fff
  style B fill:#1a1a1a,stroke:#B32416,stroke-width:2px,color:#fff
  style C fill:#B32416,stroke:#d42e1e,stroke-width:2px,color:#fff
  style D fill:#2a2a2a,stroke:#1a1a1a,stroke-width:1px,color:#29b6f6
  style E fill:#2a2a2a,stroke:#1a1a1a,stroke-width:1px,color:#9c7bcc
  style F fill:#0a0a0a,stroke:#6ba3d6,stroke-width:2px,color:#6ba3d6