mirror of
https://github.com/Team4388/RiseOfRidgebotics2020.git
synced 2026-06-09 00:38:00 -06:00
Finished Drive Straight Velocity PID and started Position PID
This commit is contained in:
@@ -14,38 +14,33 @@ import frc4388.robot.subsystems.Drive;
|
||||
|
||||
public class DriveStraightToPositionPID extends CommandBase {
|
||||
Drive m_drive;
|
||||
double m_distance;
|
||||
double m_leftTarget;
|
||||
double m_rightTarget;
|
||||
double m_targetPos;
|
||||
double m_targetGyro;
|
||||
|
||||
/**
|
||||
* Creates a new DriveToDistancePID.
|
||||
* @param subsystem drive subsystem
|
||||
* @param distance distance to travel in inches
|
||||
* @param targetPos distance to travel in inches
|
||||
*/
|
||||
public DriveStraightToPositionPID(Drive subsystem, double distance) {
|
||||
public DriveStraightToPositionPID(Drive subsystem, double targetPos) {
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
m_drive = subsystem;
|
||||
m_distance = distance * DriveConstants.TICKS_PER_INCH;
|
||||
m_targetPos = targetPos * DriveConstants.TICKS_PER_INCH;
|
||||
addRequirements(m_drive);
|
||||
SmartDashboard.putNumber("Distance Target Inches", distance);
|
||||
SmartDashboard.putNumber("Distance Target Inches", targetPos);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
m_leftTarget = m_drive.m_leftFrontMotor.getActiveTrajectoryPosition() + m_distance;
|
||||
m_rightTarget = -(m_drive.m_rightFrontMotor.getActiveTrajectoryPosition() + m_distance);
|
||||
SmartDashboard.putNumber("Distance Target Ticks", m_distance);
|
||||
SmartDashboard.putNumber("Left Target Ticks", m_leftTarget);
|
||||
SmartDashboard.putNumber("Right Target Ticks", m_rightTarget);
|
||||
m_targetGyro = m_drive.m_rightFrontMotor.getSelectedSensorPosition(DriveConstants.PID_TURN);
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
//m_drive.runPositionPID(m_drive.m_leftFrontMotor, m_leftTarget);
|
||||
//m_drive.runPositionPID(m_drive.m_rightFrontMotor, m_rightTarget);
|
||||
System.err.println(m_drive.m_rightFrontMotor.getClosedLoopError(DriveConstants.PID_TURN));
|
||||
m_drive.runDriveStraightPositionPID(m_targetPos, m_targetGyro);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@@ -56,7 +51,7 @@ public class DriveStraightToPositionPID extends CommandBase {
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
if (Math.abs(m_drive.m_leftFrontMotor.getActiveTrajectoryPosition() - m_leftTarget) < 100){
|
||||
if (Math.abs(m_drive.m_leftFrontMotor.getActiveTrajectoryPosition() - m_targetPos) < 500){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user