Example Projects - captainsoccer/BasicMotor GitHub Wiki

Using the Example Projects

The BasicMotor library includes ready-to-run example projects to help you get started quickly.
These projects show how to implement common robot mechanisms using BasicMotor, and can be adapted to your own robot by changing a few settings.

Currently available examples:

  • swerve_example – Basic swerve drive setup using BasicMotor.
  • tank_example – Tank drive control using BasicMotor.
  • flywheel_example – Simple flywheel shooter example with configurable speed control.

1. Downloading the Examples

Each example project is available as its own downloadable zip file in the Releases page.

  1. Go to the Releases page.
  2. Find the example you want:
    • swerve_example.zip
    • tank_example.zip
    • flywheel_example.zip
  3. Download the desired zip file.
  4. Extract the zip file to a convenient location on your computer — you will now have a ready-to-import WPILib project folder.

2. Importing into WPILib VS Code

Each example is a full WPILib project. To open one:

  1. Launch WPILib VS Code.
  2. Go to File → Open Folder.
  3. Navigate to the folder you extracted from the zip file.
  4. Select the example project folder.
  5. Wait for WPILib to build and index the project.

3. Setting Your Team Number

Before using an example with your robot, update the team number:

  1. Open WPILib VS Code.
  2. Press Ctrl + Shift + P (Windows/Linux) or Cmd + Shift + P (Mac) to open the Command Palette.
  3. Search for WPILib: Set Team Number.
  4. Enter your FRC team number.
  5. WPILib will update the project to match your team.

4. Changing the Constants

Each example includes a constants file for setting CAN IDs, gear ratios, PID gains, speed limits, and other configuration values.
Locate the corresponding constants file for the example you are using and update:

  • CAN IDs to match your wiring
  • Gear ratios
  • PID gains for tuning
  • Inversions if motors spin in the wrong direction
  • Sensor settings if using encoders or other feedback devices

5. Example-Specific Details

flywheel_example

  • Default hardware: Uses a TalonFX motor.
  • Where to change motor type: FlywheelIOBasic.java
  • Where constants are stored: FlywheelConstants.java

tank_example

  • Default hardware: Uses SparkMAX motors.
  • Where to change motor type: TankIOBasic.java
  • Where constants and motor config are stored: TankConstants.java

swerve_example

  • Default hardware:
    • Drive motor: TalonFX
    • Steer motor: SparkMAX
    • Absolute encoder: CANcoder
  • Where to change motor types: SwerveModuleIOBasic.java
  • Where constants are stored:
    • DriveTrainConstants.java (overall drivetrain settings)
    • SwerveModuleConstants.java (per-module settings)