Files
RiseOfRidgebotics2020/src/main/java/frc4388/robot/commands/auto/TankDriveVelocity.java
T

68 lines
2.0 KiB
Java
Raw Normal View History

2020-03-10 20:13:52 -06: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.auto;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc4388.robot.subsystems.Drive;
public class TankDriveVelocity extends CommandBase {
Drive m_drive;
double m_leftTargetVel;
double m_rightTargetVel;
2021-03-25 19:33:36 -06:00
long m_targetTime;
long m_firstTime;
long m_currentTime;
long m_diffTime;
2020-03-10 20:13:52 -06:00
/**
* Creates a new TankDriveVelocity.
*/
public TankDriveVelocity(Drive subsystem, double leftTargetVel, double rightTargetVel, double targetTime) {
// Use addRequirements() here to declare subsystem dependencies.
m_drive = subsystem;
m_leftTargetVel = leftTargetVel;
m_rightTargetVel = rightTargetVel;
2021-03-25 19:33:36 -06:00
m_targetTime = (long) (targetTime * 1000);
2020-03-10 20:13:52 -06:00
addRequirements(subsystem);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
2021-03-25 19:33:36 -06:00
m_firstTime = System.currentTimeMillis();
m_diffTime = 0;
2020-03-10 20:13:52 -06:00
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
2021-03-25 19:33:36 -06:00
m_currentTime = System.currentTimeMillis();
m_diffTime = m_currentTime - m_firstTime;
2020-03-10 20:13:52 -06:00
2021-03-25 19:33:36 -06:00
if (m_diffTime < m_targetTime) {
2020-03-10 20:13:52 -06:00
m_drive.tankDriveVelocity(m_leftTargetVel, m_rightTargetVel);
}
}
// 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() {
2021-03-25 19:33:36 -06:00
if (m_diffTime >= m_targetTime) {
2020-03-10 20:13:52 -06:00
return true;
}
return false;
}
}