Files
RiseOfRidgebotics2020/src/main/java/frc4388/robot/commands/ShootShooter.java
T

76 lines
2.5 KiB
Java
Raw Normal View History

2020-02-19 20:48:34 -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;
import edu.wpi.first.wpilibj.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
import edu.wpi.first.wpilibj2.command.ParallelRaceGroup;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc4388.robot.Constants.ShooterConstants;
import frc4388.robot.subsystems.Shooter;
import frc4388.robot.subsystems.Storage;
public class ShootShooter extends CommandBase {
Shooter m_shooter;
Storage m_storage;
private long startTime;
private int ballNum;
2020-02-20 20:21:28 -07:00
public boolean velReach = false;
2020-02-19 20:48:34 -07:00
/**
* Creates a new ShootAlll.
*/
public ShootShooter(Shooter shootSub, Storage storeSub, int numBall) {
ballNum = numBall;
m_shooter = shootSub;
m_storage = storeSub;
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
2020-02-20 20:21:28 -07:00
//new InstantCommand(() -> m_storage.storageAim());
velReach = false;
2020-02-19 20:48:34 -07:00
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
//Aiming
2020-02-20 20:21:28 -07:00
if (!m_shooter.velReached && velReach == false) //If the shooter is spooled
2020-02-19 20:48:34 -07:00
{
2020-02-20 20:21:28 -07:00
new ShooterVelocityControlPID(m_shooter, m_shooter.addFireVel());
startTime = System.currentTimeMillis();
2020-02-19 20:48:34 -07:00
}
2020-02-20 20:21:28 -07:00
else {
velReach = true;
new ParallelCommandGroup(
new ShooterVelocityControlPID(m_shooter, m_shooter.addFireVel()),
new RunCommand(() -> m_shooter.runAngleAdjustPID(m_shooter.addFireAngle())),
new RunCommand(() -> m_storage.runStoragePositionPID(m_storage.getEncoderPos() + (2*ballNum)))
);
2020-02-19 20:48:34 -07: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-02-20 20:21:28 -07:00
if (startTime + (1000 * ballNum) < System.currentTimeMillis()){
2020-02-19 20:48:34 -07:00
return true;
}
return false;
}
}