Skip to content

Commit

Permalink
added brake mode method
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSagar16 committed Feb 20, 2024
1 parent cbea7b4 commit afe06ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/ghrobotics/frc2024/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void autonomousPeriodic() {}
// robot_state_.update();
@Override
public void teleopInit() {
drive_.setBrakeMode(true);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/ghrobotics/frc2024/subsystems/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public void setSpeeds(ChassisSpeeds speeds, OutputType output_type) {
public void setSpeeds(ChassisSpeeds speeds) {
setSpeeds(speeds, OutputType.VELOCITY);
}

// Set Brake mode for all modules
public void setBrakeMode(boolean value) {
for (SwerveModule module : modules_)
module.setBrakeMode(value);
}

// Puts wheels in X shape for brake
public void HoldPosition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.ghrobotics.frc2024.CANCoderSwerve;
import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import com.revrobotics.CANSparkBase.IdleMode;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
Expand Down Expand Up @@ -96,6 +97,13 @@ public double getCANCoderDeg() {
public SwerveModuleState getState() {
return new SwerveModuleState(getDriveVelocity(), getSteerPosition());
}

public void setBrakeMode(boolean value) {
IdleMode mode = value ? IdleMode.kBrake : IdleMode.kCoast;

drive_motor_.setIdleMode(mode);
steer_motor_.setIdleMode(mode);
}

// Reset Encoders
public void resetEncoders() {
Expand Down

0 comments on commit afe06ac

Please sign in to comment.