Motor Controllers

YAGSL supports most common FRC motor controllers (except Venomarrow-up-right's) and while we recommend using a brushless motor with an integrated encoder if at all possible we support brushed motors with external quadrature encoders as well ONLY with SparkMAX's.

The integrated encoder value will show up in shuffleboard under Module[...] Raw Motor Encoder as directly outputting the encoder value from the motor.

Motor Checklist

Swerve Motor Wrapper

YAGSL created wrappers over all supported Motor Controllers to uniformly fetch and set data that is needed for a Swerve Drive to operate. This wrapper is called SwerveMotorarrow-up-right. All SwerveMotorarrow-up-right's can be fetched via the SwerveModulearrow-up-right configuration object SwerveModuleConfigurationarrow-up-right motor definitions angleMotorarrow-up-right and driveMotorarrow-up-right. The SwerveModulearrow-up-right is able to be fetched by SwerveDrive.getModules()arrow-up-right easily.

 /**
   * Initialize {@link SwerveDrive} with the directory provided.
   *
   * @param directory Directory of swerve drive config files.
   */
  public SwerveSubsystem(File directory)
  {
    // Angle conversion factor is 360 / (GEAR RATIO * ENCODER RESOLUTION)
    //  In this case the gear ratio is 12.8 motor revolutions per wheel rotation.
    //  The encoder resolution per motor revolution is 1 per motor revolution.
    double angleConversionFactor = SwerveMath.calculateDegreesPerSteeringRotation(12.8, 1);
    // Motor conversion factor is (PI * WHEEL DIAMETER IN METERS) / (GEAR RATIO * ENCODER RESOLUTION).
    //  In this case the wheel diameter is 4 inches, which must be converted to meters to get meters/second.
    //  The gear ratio is 6.75 motor revolutions per wheel rotation.
    //  The encoder resolution per motor revolution is 1 per motor revolution.
    double driveConversionFactor = SwerveMath.calculateMetersPerRotation(Units.inchesToMeters(4), 6.75, 1);

    // Configure the Telemetry before creating the SwerveDrive to avoid unnecessary objects being created.
    SwerveDriveTelemetry.verbosity = TelemetryVerbosity.HIGH;
    try
    {
      swerveDrive = new SwerveParser(directory).createSwerveDrive(maximumSpeed, angleConversionFactor, driveConversionFactor);
    } catch (Exception e)
    {
      throw new RuntimeException(e);
    }
    swerveDrive.setHeadingCorrection(false); // Heading correction should only be used while controlling the robot via angle.

    for(SwerveModule m : swerveDrive.getModules())
    {
      System.out.println("Module Name: "+m.configuration.name);
      CANSparkMax steeringMotor = (CANSparkMax)m.configuration.angleMotor.getMotor();
      CANSparkMax driveMotor = (CANSparkMax)m.configuration.driveMotor.getMotor();
    }
  }

Motor Controller Configuration

Inside any module JSON such as frontleft.json,frontright.json,backleft.json,backright.json this is what you would see to configure a motor controller.

Possible Motor Controller Types

Device
type

sparkmax

sparkflex

talonfx

TalonSRX

talonsrx

SparkMAX Brushed

sparkmax_brushed

circle-exclamation

Last updated