2020-01-20 08:59:20 -08: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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2020-03-02 21:45:38 -07:00
|
|
|
package frc4388.robot.commands.shooter;
|
2020-01-20 08:59:20 -08:00
|
|
|
|
2020-02-28 20:05:56 -07:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2020-01-20 08:59:20 -08:00
|
|
|
import edu.wpi.first.wpilibj2.command.CommandBase;
|
2020-03-01 00:41:23 -07:00
|
|
|
import frc4388.robot.Constants.ShooterConstants;
|
2020-01-20 08:59:20 -08:00
|
|
|
import frc4388.robot.subsystems.Shooter;
|
2020-03-02 23:56:05 -07:00
|
|
|
import frc4388.robot.subsystems.ShooterHood;
|
2020-01-20 08:59:20 -08:00
|
|
|
|
|
|
|
|
public class ShooterVelocityControlPID extends CommandBase {
|
|
|
|
|
Shooter m_shooter;
|
|
|
|
|
double m_targetVel;
|
2020-02-22 13:01:50 -07:00
|
|
|
double m_actualVel;
|
2020-03-02 23:56:05 -07:00
|
|
|
private ShooterHood m_shooterHood;
|
|
|
|
|
|
2020-01-20 08:59:20 -08:00
|
|
|
/**
|
2020-03-01 00:41:23 -07:00
|
|
|
* Runs the drum at a velocity
|
2020-02-22 13:16:27 -07:00
|
|
|
* @param subsystem The Shooter subsytem
|
2020-01-20 08:59:20 -08:00
|
|
|
*/
|
2020-03-02 23:56:05 -07:00
|
|
|
public ShooterVelocityControlPID(Shooter subsystem, ShooterHood subHood) {
|
2020-01-20 08:59:20 -08:00
|
|
|
m_shooter = subsystem;
|
2020-03-02 23:56:05 -07:00
|
|
|
m_shooterHood = subHood;
|
|
|
|
|
addRequirements(m_shooter, m_shooterHood);
|
2020-01-20 08:59:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called when the command is initially scheduled.
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize() {
|
2020-02-25 17:44:59 -07:00
|
|
|
|
2020-01-20 08:59:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called every time the scheduler runs while the command is scheduled.
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
2020-03-02 21:03:39 -07:00
|
|
|
m_shooter.runDrumShooterVelocityPID(/*m_shooter.addFireVel()*/13000);
|
2020-03-02 23:56:05 -07:00
|
|
|
m_shooterHood.runAngleAdjustPID(m_shooterHood.addFireAngle());
|
2020-03-02 22:32:29 -07:00
|
|
|
//SmartDashboard.putNumber("Fire Velocity", m_shooter.addFireVel());
|
|
|
|
|
//SmartDashboard.putNumber("Fire Angle", m_shooter.addFireAngle());
|
2020-01-20 08:59:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called once the command ends or is interrupted.
|
|
|
|
|
@Override
|
|
|
|
|
public void end(boolean interrupted) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns true when the command should end.
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isFinished() {
|
2020-03-01 00:41:23 -07:00
|
|
|
//Tells whether the target velocity has been reached
|
|
|
|
|
double upperBound = m_targetVel + ShooterConstants.DRUM_VELOCITY_BOUND;
|
|
|
|
|
double lowerBound = m_targetVel - ShooterConstants.DRUM_VELOCITY_BOUND;
|
2020-02-22 13:01:50 -07:00
|
|
|
if (m_actualVel < upperBound && m_actualVel > lowerBound){
|
2020-02-28 20:05:56 -07:00
|
|
|
SmartDashboard.putBoolean("ShooterVelocityPID Finished", true);
|
2020-02-22 13:01:50 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else{
|
2020-02-28 20:05:56 -07:00
|
|
|
SmartDashboard.putBoolean("ShooterVelocityPID Finished", false);
|
2020-02-22 13:01:50 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2020-01-20 08:59:20 -08:00
|
|
|
}
|
|
|
|
|
}
|