-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
MiniLib/src/frc/team670/robot/commands/drive/PIDDistanceDrive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package frc.team670.robot.commands.drive; | ||
|
||
import edu.wpi.first.wpilibj.command.*; | ||
import edu.wpi.first.wpilibj.controller.PIDController; | ||
import frc.team670.robot.Robot; | ||
import frc.team670.robot.utils.Logger; | ||
import frc.team670.robot.utils.MathUtils; | ||
|
||
public class PIDDistanceDrive extends Command { | ||
|
||
PIDController m_leftController, m_rightController; | ||
|
||
double m_targetInches; | ||
|
||
// TODO: Find values | ||
// proportional speed constant | ||
double kP = 0.0; | ||
|
||
// integral speed constant | ||
double kI = 0.0; | ||
|
||
// derivative speed constant | ||
double kD = 0.0; | ||
|
||
// margin of error | ||
double TOLERANCE_INCHES = 0.5; | ||
|
||
/** | ||
* | ||
* @param target Target distance in inches | ||
*/ | ||
public PIDDistanceDrive(double targetInches) { | ||
m_targetInches = targetInches; | ||
m_leftController = new PIDController(kP, kI, kD); | ||
m_leftController.setTolerance(MathUtils.convertInchesToEncoderTicks(TOLERANCE_INCHES)); | ||
m_rightController = new PIDController(kP, kI, kD); | ||
m_rightController.setTolerance(MathUtils.convertInchesToEncoderTicks(TOLERANCE_INCHES)); | ||
requires(Robot.driveBase); | ||
} | ||
|
||
public void initialize() { | ||
m_leftController.setSetpoint(MathUtils.convertInchesToEncoderTicks(m_targetInches)); | ||
m_rightController.setSetpoint(MathUtils.convertInchesToEncoderTicks(m_targetInches)); | ||
Logger.consoleLog("Target ticks: %s TicksL: %s TicksR: %s", m_leftController.getSetpoint(), | ||
Robot.driveBase.getLeftEncoder().getTicks(), Robot.driveBase.getRightEncoder().getTicks()); | ||
} | ||
|
||
public void execute() { | ||
Logger.consoleLog("TicksL: %s TicksR: %s", Robot.driveBase.getLeftEncoder().getTicks(), | ||
Robot.driveBase.getRightEncoder().getTicks()); | ||
Robot.driveBase.tankDrive(m_leftController.calculate(Robot.driveBase.getLeftEncoder().getTicks()), | ||
m_rightController.calculate(Robot.driveBase.getRightEncoder().getTicks())); | ||
} | ||
|
||
public boolean isFinished() { | ||
return m_leftController.atSetpoint() || m_rightController.atSetpoint(); | ||
} | ||
|
||
public void end() { | ||
Robot.driveBase.stop(); | ||
} | ||
} |
51 changes: 0 additions & 51 deletions
51
MiniLib/src/frc/team670/robot/commands/drive/PIDDistanceTest.java
This file was deleted.
Oops, something went wrong.