2020-01-17 19:44:54 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
package frc4388.robot.commands;
|
|
|
|
|
|
2020-01-23 16:42:20 -07:00
|
|
|
import com.ctre.phoenix.motorcontrol.FollowerType;
|
2020-01-30 16:44:05 -07:00
|
|
|
import com.ctre.phoenix.motorcontrol.NeutralMode;
|
2020-01-23 16:42:20 -07:00
|
|
|
|
2020-01-24 20:27:42 -07:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2020-01-17 19:44:54 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.CommandBase;
|
2020-01-18 15:12:48 -07:00
|
|
|
import frc4388.robot.Constants.DriveConstants;
|
2020-01-17 19:44:54 -07:00
|
|
|
import frc4388.robot.subsystems.Drive;
|
|
|
|
|
|
|
|
|
|
public class DriveAtVelocityPID extends CommandBase {
|
|
|
|
|
Drive m_drive;
|
2020-01-27 19:06:23 -07:00
|
|
|
double m_targetGyro;
|
2020-01-17 19:44:54 -07:00
|
|
|
double m_targetVel;
|
|
|
|
|
double m_leftTarget;
|
|
|
|
|
double m_rightTarget;
|
2020-01-24 20:27:42 -07:00
|
|
|
double m_copiedTargetVel;
|
2020-01-17 19:44:54 -07:00
|
|
|
/**
|
|
|
|
|
* Creates a new DriveAtVelocityPID.
|
2020-01-18 15:12:48 -07:00
|
|
|
* @param subsystem drive subsystem
|
|
|
|
|
* @param distance target velocity in inches/second
|
2020-01-17 19:44:54 -07:00
|
|
|
*/
|
|
|
|
|
public DriveAtVelocityPID(Drive subsystem, double targetVel) {
|
|
|
|
|
// Use addRequirements() here to declare subsystem dependencies.
|
|
|
|
|
m_drive = subsystem;
|
2020-01-24 20:27:42 -07:00
|
|
|
m_targetVel = targetVel * DriveConstants.TICKS_PER_INCH/DriveConstants.SECONDS_TO_TICK_TIME;
|
|
|
|
|
m_copiedTargetVel = targetVel;
|
2020-01-17 19:44:54 -07:00
|
|
|
addRequirements(m_drive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called when the command is initially scheduled.
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize() {
|
2020-01-24 20:27:42 -07:00
|
|
|
m_leftTarget = m_targetVel;
|
2020-01-23 16:42:20 -07:00
|
|
|
m_rightTarget = m_targetVel;
|
2020-01-27 19:06:23 -07:00
|
|
|
m_targetGyro = m_drive.m_rightFrontMotor.getSelectedSensorPosition(DriveConstants.PID_TURN);
|
2020-01-30 16:44:05 -07:00
|
|
|
m_drive.setDriveTrainNeutralMode(NeutralMode.Coast);
|
2020-01-17 19:44:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called every time the scheduler runs while the command is scheduled.
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
2020-01-30 16:44:05 -07:00
|
|
|
m_drive.runVelocityPID(m_targetVel, m_targetGyro+1000);
|
2020-01-24 20:27:42 -07:00
|
|
|
|
|
|
|
|
SmartDashboard.putNumber("Input Target Velocity", m_copiedTargetVel);
|
|
|
|
|
SmartDashboard.putNumber("Output Target Velocity", m_targetVel);
|
2020-01-27 19:06:23 -07:00
|
|
|
|
|
|
|
|
SmartDashboard.putNumber("Target Angle", m_targetGyro);
|
2020-01-24 20:27:42 -07:00
|
|
|
//m_drive.runVelocityPID(m_leftTarget);
|
|
|
|
|
//m_drive.m_leftFrontMotor.follow(m_drive.m_rightFrontMotor, FollowerType.PercentOutput);
|
2020-01-17 19:44:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called once the command ends or is interrupted.
|
|
|
|
|
@Override
|
|
|
|
|
public void end(boolean interrupted) {
|
2020-01-30 16:44:05 -07:00
|
|
|
m_drive.setDriveTrainNeutralMode(NeutralMode.Brake);
|
2020-01-17 19:44:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns true when the command should end.
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isFinished() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|