Reorganization
This commit is contained in:
parent
8defb590f4
commit
817515901c
|
|
@ -57,8 +57,8 @@ public class SwerveBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SwerveDriveSubsystem build() {
|
public SwerveDriveSystem build() {
|
||||||
return new SwerveDriveSubsystem(pigeonId, canBusObj, maxLinearVelMetersSecond, maxAngularVelRadiansSecond,
|
return new SwerveDriveSystem(pigeonId, canBusObj, maxLinearVelMetersSecond, maxAngularVelRadiansSecond,
|
||||||
modules.toArray(size -> new SwerveModule[size]));
|
modules.toArray(size -> new SwerveModule[size]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,10 @@ import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
|
||||||
import edu.wpi.first.math.kinematics.SwerveModulePosition;
|
import edu.wpi.first.math.kinematics.SwerveModulePosition;
|
||||||
import edu.wpi.first.math.kinematics.SwerveModuleState;
|
import edu.wpi.first.math.kinematics.SwerveModuleState;
|
||||||
import edu.wpi.first.units.measure.Angle;
|
import edu.wpi.first.units.measure.Angle;
|
||||||
|
import edu.wpi.first.wpilibj2.command.Subsystem;
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
|
|
||||||
public class SwerveDriveSubsystem extends SubsystemBase{
|
public class SwerveDriveSystem implements Subsystem{
|
||||||
|
|
||||||
private SwerveDriveKinematics driveKiniematics;
|
private SwerveDriveKinematics driveKiniematics;
|
||||||
private ChassisSpeeds chassisSpeeds;
|
private ChassisSpeeds chassisSpeeds;
|
||||||
|
|
@ -35,7 +36,7 @@ public class SwerveDriveSubsystem extends SubsystemBase{
|
||||||
|
|
||||||
private double mLastSimTime = 0;
|
private double mLastSimTime = 0;
|
||||||
|
|
||||||
public SwerveDriveSubsystem(int pigeonId, CANBus canBus, double maxLinearVelMetersSecond, double maxAngularVelRadiansSecond, SwerveModule... modules){
|
public SwerveDriveSystem(int pigeonId, CANBus canBus, double maxLinearVelMetersSecond, double maxAngularVelRadiansSecond, SwerveModule... modules){
|
||||||
|
|
||||||
MAX_LINEAR_SPEED = maxLinearVelMetersSecond;
|
MAX_LINEAR_SPEED = maxLinearVelMetersSecond;
|
||||||
MAX_ANGULAR_SPEED = maxAngularVelRadiansSecond;
|
MAX_ANGULAR_SPEED = maxAngularVelRadiansSecond;
|
||||||
|
|
@ -54,7 +55,6 @@ public class SwerveDriveSubsystem extends SubsystemBase{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void periodic() {
|
public void periodic() {
|
||||||
super.periodic();
|
|
||||||
SwerveModuleState[] moduleStates = driveKiniematics.toSwerveModuleStates(chassisSpeeds);
|
SwerveModuleState[] moduleStates = driveKiniematics.toSwerveModuleStates(chassisSpeeds);
|
||||||
|
|
||||||
for(int i=0; i<modules.length;i++){
|
for(int i=0; i<modules.length;i++){
|
||||||
|
|
@ -71,8 +71,6 @@ public class SwerveDriveSubsystem extends SubsystemBase{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simulationPeriodic() {
|
public void simulationPeriodic() {
|
||||||
super.simulationPeriodic();
|
|
||||||
|
|
||||||
double deltaTimeSecond = (mLastSimTime - Utils.getCurrentTimeSeconds());
|
double deltaTimeSecond = (mLastSimTime - Utils.getCurrentTimeSeconds());
|
||||||
|
|
||||||
if(mLastSimTime != 0){
|
if(mLastSimTime != 0){
|
||||||
|
|
@ -107,6 +105,10 @@ public class SwerveDriveSubsystem extends SubsystemBase{
|
||||||
return gyro.getRoll().getValue();
|
return gyro.getRoll().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pigeon2 getGyro(){
|
||||||
|
return gyro;
|
||||||
|
}
|
||||||
|
|
||||||
public void setChassisSpeed(ChassisSpeeds chassisSpeeds){
|
public void setChassisSpeed(ChassisSpeeds chassisSpeeds){
|
||||||
this.setChassisSpeed(chassisSpeeds, new Translation2d());
|
this.setChassisSpeed(chassisSpeeds, new Translation2d());
|
||||||
}
|
}
|
||||||
|
|
@ -39,8 +39,10 @@ public class SwerveModule {
|
||||||
|
|
||||||
private TalonFX driveMotor;
|
private TalonFX driveMotor;
|
||||||
private VelocityVoltage driveRequest = new VelocityVoltage(0);
|
private VelocityVoltage driveRequest = new VelocityVoltage(0);
|
||||||
|
|
||||||
private TalonFX steerMotor;
|
private TalonFX steerMotor;
|
||||||
private MotionMagicVoltage steerRequest = new MotionMagicVoltage(0);
|
private MotionMagicVoltage steerRequest = new MotionMagicVoltage(0);
|
||||||
|
|
||||||
private CANcoder steerEncoder;
|
private CANcoder steerEncoder;
|
||||||
|
|
||||||
private String moduleName;
|
private String moduleName;
|
||||||
|
|
@ -138,6 +140,18 @@ public class SwerveModule {
|
||||||
requestedModuleState = state;
|
requestedModuleState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TalonFX getSteerMotor(){
|
||||||
|
return steerMotor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TalonFX getDriveMotor(){
|
||||||
|
return driveMotor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CANcoder getSteerEncoder(){
|
||||||
|
return steerEncoder;
|
||||||
|
}
|
||||||
|
|
||||||
public SwerveModuleState getRequestedModuleState(){
|
public SwerveModuleState getRequestedModuleState(){
|
||||||
return requestedModuleState;
|
return requestedModuleState;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue