Skip to content

Commit

Permalink
Added voltage compensation to Drivetrain, Elevator
Browse files Browse the repository at this point in the history
Allows input to be more reliable. This is especially important for autonomous driving.
  • Loading branch information
briansemrau committed Feb 28, 2018
1 parent c52fe34 commit 97772f5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ protected void initialize() {
lastTime = 0;
percent = startPercent;
startLow = startPercent < targetPercent;

Robot.DRIVETRAIN.enableVoltageCompensation();
}

// Called repeatedly when this Command is scheduled to run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public AutoBlindDrive(double time, double percent) {

// Called just before this Command runs the first time
protected void initialize() {
Robot.DRIVETRAIN.enableVoltageCompensation();
}

// Called repeatedly when this Command is scheduled to run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public TeleopRacingDrive() {
// Called just before this Command runs the first time
protected void initialize() {
Robot.DRIVETRAIN.setBrakeMode();
Robot.DRIVETRAIN.disableVoltageCompensation();
}

// Called repeatedly when this Command is scheduled to run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public TeleopTankDrive() {
// Called just before this Command runs the first time
protected void initialize() {
Robot.DRIVETRAIN.setBrakeMode();
Robot.DRIVETRAIN.disableVoltageCompensation();
}

// Called repeatedly when this Command is scheduled to run
Expand Down
19 changes: 19 additions & 0 deletions src/org/usfirst/frc/team4737/robot/subsystems/Drivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public Drivetrain() {

leftFrontMaster.configOpenloopRamp(0.25, 30);
rightFrontMaster.configOpenloopRamp(0.25, 30);

leftFrontMaster.configVoltageCompSaturation(12, 30);
leftBackSlave.configVoltageCompSaturation(12, 30);
rightFrontMaster.configVoltageCompSaturation(12, 30);
rightBackSlave.configVoltageCompSaturation(12, 30);

drive = new DifferentialDrive(leftFrontMaster, rightFrontMaster);
}
Expand All @@ -54,6 +59,20 @@ public void setCoastMode() {
rightFrontMaster.setNeutralMode(NeutralMode.Coast);
rightBackSlave.setNeutralMode(NeutralMode.Coast);
}

public void enableVoltageCompensation() {
leftFrontMaster.enableVoltageCompensation(true);
leftBackSlave.enableVoltageCompensation(true);
rightFrontMaster.enableVoltageCompensation(true);
rightBackSlave.enableVoltageCompensation(true);
}

public void disableVoltageCompensation() {
leftFrontMaster.enableVoltageCompensation(false);
leftBackSlave.enableVoltageCompensation(false);
rightFrontMaster.enableVoltageCompensation(false);
rightBackSlave.enableVoltageCompensation(false);
}

/**
* Controls the drivetrain using two tank-drive joystick inputs
Expand Down
4 changes: 2 additions & 2 deletions src/org/usfirst/frc/team4737/robot/subsystems/Elevator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public Elevator() {
motor.enableCurrentLimit(true);

// Use voltage compensation to keep inputs reliable
// motor.configVoltageCompSaturation(12, 30);
// motor.enableVoltageCompensation(true);
motor.configVoltageCompSaturation(12, 30);
motor.enableVoltageCompensation(true);
}

public void initDefaultCommand() {
Expand Down

0 comments on commit 97772f5

Please sign in to comment.