Skip to content

Commit

Permalink
Expose motors and steer encoders
Browse files Browse the repository at this point in the history
Fix #3, fix #4
  • Loading branch information
democat3457 committed Feb 6, 2022
1 parent f4d2749 commit e2d9168
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.swervedrivespecialties.swervelib;

public interface DriveController {
Object getDriveMotor();

void setReferenceVoltage(double voltage);

double getStateVelocity();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.swervedrivespecialties.swervelib;

import com.swervedrivespecialties.swervelib.ctre.*;
import com.swervedrivespecialties.swervelib.rev.NeoDriveControllerFactoryBuilder;
import com.swervedrivespecialties.swervelib.rev.NeoSteerConfiguration;
import com.swervedrivespecialties.swervelib.rev.NeoSteerControllerFactoryBuilder;
import com.swervedrivespecialties.swervelib.rev.*;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout;

public final class Mk3SwerveModuleHelper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.swervedrivespecialties.swervelib;

import com.swervedrivespecialties.swervelib.ctre.*;
import com.swervedrivespecialties.swervelib.rev.NeoDriveControllerFactoryBuilder;
import com.swervedrivespecialties.swervelib.rev.NeoSteerConfiguration;
import com.swervedrivespecialties.swervelib.rev.NeoSteerControllerFactoryBuilder;
import com.swervedrivespecialties.swervelib.rev.*;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout;

public final class Mk4SwerveModuleHelper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.swervedrivespecialties.swervelib;

public interface SteerController {
Object getSteerMotor();

AbsoluteEncoder getSteerEncoder();

double getReferenceAngle();

void setReferenceAngle(double referenceAngleRadians);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.swervedrivespecialties.swervelib;

public interface SwerveModule {
Object getDriveMotor();

Object getSteerMotor();

AbsoluteEncoder getSteerEncoder();

double getDriveVelocity();

double getSteerAngle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ private ModuleImplementation(DriveController driveController, SteerController st
this.steerController = steerController;
}

@Override
public Object getDriveMotor() {
return driveController.getDriveMotor();
}

@Override
public Object getSteerMotor() {
return steerController.getSteerMotor();
}

@Override
public AbsoluteEncoder getSteerEncoder() {
return steerController.getSteerEncoder();
}

@Override
public double getDriveVelocity() {
return driveController.getStateVelocity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ private ControllerImplementation(TalonFX motor, double sensorVelocityCoefficient
this.sensorVelocityCoefficient = sensorVelocityCoefficient;
}

@Override
public Object getDriveMotor() {
return this.motor;
}

@Override
public void setReferenceVoltage(double voltage) {
motor.set(TalonFXControlMode.PercentOutput, voltage / nominalVoltage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ private ControllerImplementation(TalonFX motor,
this.absoluteEncoder = absoluteEncoder;
}

@Override
public Object getSteerMotor() {
return this.motor;
}

@Override
public AbsoluteEncoder getSteerEncoder() {
return this.absoluteEncoder;
}

@Override
public double getReferenceAngle() {
return referenceAngleRadians;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ private ControllerImplementation(CANSparkMax motor, RelativeEncoder encoder) {
this.encoder = encoder;
}

@Override
public Object getDriveMotor() {
return this.motor;
}

@Override
public void setReferenceVoltage(double voltage) {
motor.setVoltage(voltage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static class ControllerImplementation implements SteerController {
private static final int ENCODER_RESET_ITERATIONS = 500;
private static final double ENCODER_RESET_MAX_ANGULAR_VELOCITY = Math.toRadians(0.5);

@SuppressWarnings({"FieldCanBeLocal", "unused"})
@SuppressWarnings("FieldCanBeLocal")
private final CANSparkMax motor;
private final SparkMaxPIDController controller;
private final RelativeEncoder motorEncoder;
Expand All @@ -116,6 +116,16 @@ public ControllerImplementation(CANSparkMax motor, AbsoluteEncoder absoluteEncod
this.absoluteEncoder = absoluteEncoder;
}

@Override
public Object getSteerMotor() {
return this.motor;
}

@Override
public AbsoluteEncoder getSteerEncoder() {
return this.absoluteEncoder;
}

@Override
public double getReferenceAngle() {
return referenceAngleRadians;
Expand Down

0 comments on commit e2d9168

Please sign in to comment.