mirror of
https://github.com/Team4388/RiseOfRidgebotics2020.git
synced 2026-06-09 08:48:01 -06:00
Merge branch 'master' into add-autonomous-paths
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 com.revrobotics.CANSparkMax.SoftLimitDirection;
|
||||
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.ShooterConstants;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
|
||||
public class CalibrateShooter extends CommandBase {
|
||||
Shooter m_shooter;
|
||||
ShooterAim m_shooterAim;
|
||||
/**
|
||||
* Calibrates the turret by moving the hood all the way down and moving the turret all the way right, then reseting the encoders
|
||||
* @param shootSub The Shooter subsystem
|
||||
* @param aimSub The ShooterAim subsystem
|
||||
*/
|
||||
public CalibrateShooter(Shooter shootSub, ShooterAim aimSub) {
|
||||
m_shooter = shootSub;
|
||||
m_shooterAim = aimSub;
|
||||
addRequirements(m_shooter, m_shooterAim);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
m_shooter.m_angleAdjustMotor.enableSoftLimit(SoftLimitDirection.kForward, false);
|
||||
m_shooter.m_angleAdjustMotor.enableSoftLimit(SoftLimitDirection.kReverse, false);
|
||||
m_shooter.m_angleEncoder.setPosition(0);
|
||||
m_shooter.m_angleAdjustMotor.set(-ShooterConstants.HOOD_CALIBRATE_SPEED);
|
||||
|
||||
m_shooterAim.m_shooterRotateMotor.enableSoftLimit(SoftLimitDirection.kForward, false);
|
||||
m_shooterAim.m_shooterRotateMotor.enableSoftLimit(SoftLimitDirection.kReverse, false);
|
||||
m_shooterAim.m_shooterRotateEncoder.setPosition(0);
|
||||
m_shooterAim.m_shooterRotateMotor.set(ShooterConstants.TURRET_CALIBRATE_SPEED);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
m_shooter.m_angleAdjustMotor.enableSoftLimit(SoftLimitDirection.kForward, true);
|
||||
m_shooter.m_angleAdjustMotor.enableSoftLimit(SoftLimitDirection.kReverse, true);
|
||||
|
||||
m_shooterAim.m_shooterRotateMotor.enableSoftLimit(SoftLimitDirection.kForward, true);
|
||||
m_shooterAim.m_shooterRotateMotor.enableSoftLimit(SoftLimitDirection.kReverse, true);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 frc4388.robot.Constants.ShooterConstants;
|
||||
import frc4388.robot.Constants.VisionConstants;
|
||||
import frc4388.robot.subsystems.Drive;
|
||||
import frc4388.robot.subsystems.LimeLight;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
import frc4388.utility.controller.IHandController;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
public class HoldTarget extends CommandBase {
|
||||
//Setup
|
||||
NetworkTableEntry xEntry;
|
||||
ShooterAim m_shooterAim;
|
||||
Shooter m_shooter;
|
||||
IHandController m_driverController;
|
||||
//Aiming
|
||||
double turnAmount = 0;
|
||||
double xAngle = 0;
|
||||
double yAngle = 0;
|
||||
double target = 0;
|
||||
public double distance;
|
||||
public double fireVel;
|
||||
public double fireAngle;
|
||||
|
||||
public double m_hoodTrim;
|
||||
public double m_turretTrim;
|
||||
|
||||
/**
|
||||
* Uses the Limelight to track the target
|
||||
* @param shooterSubsystem The Shooter subsystem
|
||||
* @param aimSubsystem The ShooterAim subsystem
|
||||
*/
|
||||
public HoldTarget(Shooter shooterSubsystem, ShooterAim aimSubsystem) {
|
||||
m_shooterAim = aimSubsystem;
|
||||
m_shooter = shooterSubsystem;
|
||||
addRequirements(m_shooterAim);
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(1);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
//Vision Processing Mode
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(0);
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
target = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0);
|
||||
xAngle = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0);
|
||||
yAngle = NetworkTableInstance.getDefault().getTable("limelight").getEntry("ty").getDouble(0);
|
||||
|
||||
if (target == 1.0){ //If target in view
|
||||
//Aiming Left/Right
|
||||
turnAmount = (xAngle/VisionConstants.FOV)*VisionConstants.TURN_P_VALUE;
|
||||
if (Math.abs(xAngle) < VisionConstants.X_ANGLE_ERROR){turnAmount = 0;} //Angle Error Zone
|
||||
//Deadzones
|
||||
else if(turnAmount > 0 && turnAmount < VisionConstants.MOTOR_DEAD_ZONE){turnAmount = VisionConstants.MOTOR_DEAD_ZONE;}
|
||||
else if(turnAmount < 0 && turnAmount > -VisionConstants.MOTOR_DEAD_ZONE){turnAmount = -VisionConstants.MOTOR_DEAD_ZONE;}
|
||||
m_shooterAim.runShooterWithInput(-turnAmount - m_shooter.shooterTrims.m_turretTrim);
|
||||
|
||||
//Finding Distance
|
||||
distance = VisionConstants.TARGET_HEIGHT/Math.tan((VisionConstants.LIME_ANGLE + yAngle)*(Math.PI/180));
|
||||
SmartDashboard.putNumber("Distance to Target", distance);
|
||||
|
||||
double yVel = Math.sqrt(2*VisionConstants.GRAV*VisionConstants.TARGET_HEIGHT);
|
||||
double xVel = (distance*VisionConstants.GRAV)/(yVel);
|
||||
|
||||
fireVel = Math.sqrt((Math.pow(xVel, 2))+(Math.pow(yVel,2)));
|
||||
fireAngle = Math.atan(yVel/xVel) * (180/Math.PI);
|
||||
m_shooter.m_fireVel = fireVel;
|
||||
m_shooter.m_fireAngle = fireAngle + m_shooter.shooterTrims.m_hoodTrim;
|
||||
|
||||
}/*
|
||||
else{
|
||||
System.err.println("Shooter Pos: " + m_shooterAim.getShooterRotatePosition());
|
||||
double curveInput = -Math.abs(-Math.cos(Math.PI * ((2*m_shooterAim.getShooterRotatePosition())/55))+1) * 0.1;
|
||||
if (m_shooterAim.getShooterRotatePosition() >= -3 || m_shooterAim.getShooterRotatePosition() <= -54){
|
||||
curveInput = -curveInput;
|
||||
}
|
||||
System.err.println("Curve Input: " + curveInput);
|
||||
|
||||
m_shooterAim.runShooterWithInput(curveInput);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(1);
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.smartdashboard.SmartDashboard;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.ShooterConstants;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
|
||||
public class HoodPositionPID extends CommandBase {
|
||||
Shooter m_shooter;
|
||||
double firingAngle;
|
||||
/**
|
||||
* Creates a new HoodPositionPID.
|
||||
*/
|
||||
public HoodPositionPID(Shooter subSystem) {
|
||||
m_shooter = subSystem;
|
||||
//addRequirements(m_shooter);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
double slope = ShooterConstants.HOOD_CONVERT_SLOPE;
|
||||
double b = ShooterConstants.HOOD_CONVERT_B;
|
||||
firingAngle = (-slope*m_shooter.addFireAngle())+b;
|
||||
SmartDashboard.putNumber("Shoot Angle From Equation", m_shooter.addFireAngle());
|
||||
SmartDashboard.putNumber("Fire Angle", firingAngle);
|
||||
m_shooter.runAngleAdjustPID(firingAngle);
|
||||
}
|
||||
|
||||
// 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() {
|
||||
double encoderPos = m_shooter.m_angleAdjustMotor.getEncoder().getPosition();
|
||||
if(encoderPos < firingAngle + 1 || encoderPos < firingAngle - 1){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.wpilibj2.command.ParallelRaceGroup;
|
||||
import edu.wpi.first.wpilibj2.command.RunCommand;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
// NOTE: Consider using this command inline, rather than writing a subclass. For more
|
||||
// information, see:
|
||||
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
|
||||
public class ShootFireGroup extends ParallelRaceGroup {
|
||||
/**
|
||||
* Fires the shooter
|
||||
* @param m_shooter The Shooter subsytem
|
||||
* @param m_shooterAim The ShooterAim subsystem
|
||||
* @param m_storage The Storage subsytem
|
||||
*/
|
||||
public ShootFireGroup(Shooter m_shooter, ShooterAim m_shooterAim, Storage m_storage) {
|
||||
addCommands(
|
||||
new RunCommand(() -> m_shooter.runDrumShooterVelocityPID(m_shooter.addFireVel(), m_shooter.m_shooterFalcon.getSelectedSensorVelocity())),
|
||||
new RunCommand(() -> m_shooter.runAngleAdjustPID(m_shooter.addFireAngle())),
|
||||
new HoldTarget(m_shooter, m_shooterAim),
|
||||
new StorageRun(m_storage)
|
||||
);
|
||||
}
|
||||
}
|
||||
+11
-7
@@ -8,20 +8,24 @@
|
||||
package frc4388.robot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
|
||||
import frc4388.robot.subsystems.Intake;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
// NOTE: Consider using this command inline, rather than writing a subclass. For more
|
||||
// information, see:
|
||||
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
|
||||
public class StorageIntakeGroup extends SequentialCommandGroup {
|
||||
public class ShootFullGroup extends SequentialCommandGroup {
|
||||
/**
|
||||
* Creates a new StorageIntakeGroup.
|
||||
* Preps and Fires the Shooter
|
||||
* @param m_shooter The Shooter subsytem
|
||||
* @param m_shooterAim The ShooterAim subsystem
|
||||
* @param m_storage The Storage subsytem
|
||||
*/
|
||||
public StorageIntakeGroup(Intake m_intake, Storage m_storage) {
|
||||
public ShootFullGroup(Shooter m_shooter, ShooterAim m_shooterAim, Storage m_storage) {
|
||||
addCommands(
|
||||
new storagePrepIntake(m_intake, m_storage),
|
||||
new storageIntake(m_intake, m_storage),
|
||||
new StorageIntakeFinal(m_storage));
|
||||
new ShootPrepGroup(m_shooter, m_shooterAim, m_storage),
|
||||
new ShootFireGroup(m_shooter, m_shooterAim, m_storage)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.wpilibj2.command.ParallelCommandGroup;
|
||||
import edu.wpi.first.wpilibj2.command.RunCommand;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
// NOTE: Consider using this command inline, rather than writing a subclass. For more
|
||||
// information, see:
|
||||
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
|
||||
public class ShootPrepGroup extends ParallelCommandGroup {
|
||||
/**
|
||||
* Prepares the Shooter to be fired
|
||||
* @param m_shooter The Shooter subsytem
|
||||
* @param m_shooterAim The ShooterAim subsystem
|
||||
* @param m_storage The Storage subsytem
|
||||
*/
|
||||
public ShootPrepGroup(Shooter m_shooter, ShooterAim m_shooterAim, Storage m_storage) {
|
||||
addCommands(
|
||||
new TrackTarget(m_shooter, m_shooterAim),
|
||||
new ShooterVelocityControlPID(m_shooter),
|
||||
new StoragePrepAim(m_storage),
|
||||
new HoodPositionPID(m_shooter)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,32 +7,37 @@
|
||||
|
||||
package frc4388.robot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.ShooterConstants;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
|
||||
public class ShooterVelocityControlPID extends CommandBase {
|
||||
Shooter m_shooter;
|
||||
double m_targetVel;
|
||||
double m_actualVel;
|
||||
/**
|
||||
* Creates a new ShooterVelocityControlPID.
|
||||
* Runs the drum at a velocity
|
||||
* @param subsystem The Shooter subsytem
|
||||
*/
|
||||
public ShooterVelocityControlPID(Shooter subsystem, double targetVel) {
|
||||
// Use addRequirements() here to declare subsystem dependencies.
|
||||
public ShooterVelocityControlPID(Shooter subsystem) {
|
||||
m_shooter = subsystem;
|
||||
m_targetVel = targetVel;
|
||||
addRequirements(m_shooter);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
System.err.println(m_shooter.m_shooterFalcon.getSelectedSensorVelocity());
|
||||
m_shooter.runDrumShooterVelocityPID(m_targetVel, m_shooter.m_shooterFalcon.getSelectedSensorVelocity());
|
||||
m_shooter.runDrumShooterVelocityPID(m_shooter.addFireVel(), m_shooter.m_shooterFalcon.getSelectedSensorVelocity());
|
||||
m_shooter.runAngleAdjustPID(m_shooter.addFireAngle());
|
||||
SmartDashboard.putNumber("Fire Velocity", m_shooter.addFireVel());
|
||||
SmartDashboard.putNumber("Fire Angle", m_shooter.addFireAngle());
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@@ -43,6 +48,16 @@ public class ShooterVelocityControlPID extends CommandBase {
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
//Tells whether the target velocity has been reached
|
||||
double upperBound = m_targetVel + ShooterConstants.DRUM_VELOCITY_BOUND;
|
||||
double lowerBound = m_targetVel - ShooterConstants.DRUM_VELOCITY_BOUND;
|
||||
if (m_actualVel < upperBound && m_actualVel > lowerBound){
|
||||
SmartDashboard.putBoolean("ShooterVelocityPID Finished", true);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
SmartDashboard.putBoolean("ShooterVelocityPID Finished", false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.IntakeConstants;
|
||||
import frc4388.robot.Constants.StorageConstants;
|
||||
import frc4388.robot.subsystems.Intake;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
public class StorageIntake extends CommandBase {
|
||||
public Intake m_intake;
|
||||
public Storage m_storage;
|
||||
public boolean intook;
|
||||
/**
|
||||
* Runs the Storage in for intaking
|
||||
* @param inSub The Intake subsystem
|
||||
* @param storeSub The Storage subsytem
|
||||
*/
|
||||
public StorageIntake(Intake inSub, Storage storeSub) {
|
||||
m_intake = inSub;
|
||||
m_storage = storeSub;
|
||||
addRequirements(m_intake);
|
||||
addRequirements(m_storage);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
intook = false;
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
if (!m_storage.getBeam(0)){
|
||||
m_storage.runStorage(StorageConstants.STORAGE_SPEED);
|
||||
intook = true;
|
||||
}
|
||||
else{
|
||||
m_storage.runStorage(0);
|
||||
}
|
||||
}
|
||||
|
||||
// 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() {
|
||||
if (m_storage.getBeam(0) && intook){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -8,14 +8,16 @@
|
||||
package frc4388.robot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.StorageConstants;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
public class storageOutake extends CommandBase {
|
||||
public class StorageOutake extends CommandBase {
|
||||
Storage m_storage;
|
||||
/**
|
||||
* Creates a new storageOutake.
|
||||
* Runs the Storage out for outaking
|
||||
* @param storeSub The Storage subsystem
|
||||
*/
|
||||
public storageOutake(Storage storeSub) {
|
||||
public StorageOutake(Storage storeSub) {
|
||||
m_storage = storeSub;
|
||||
addRequirements(m_storage);
|
||||
}
|
||||
@@ -28,7 +30,7 @@ public class storageOutake extends CommandBase {
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
m_storage.runStorage(-0.5);
|
||||
m_storage.runStorage(-StorageConstants.STORAGE_SPEED);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
+12
-16
@@ -8,36 +8,31 @@
|
||||
package frc4388.robot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.subsystems.Intake;
|
||||
import frc4388.robot.Constants.StorageConstants;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
public class storagePrepIntake extends CommandBase {
|
||||
public Intake m_intake;
|
||||
public class StoragePositionPID extends CommandBase {
|
||||
public Storage m_storage;
|
||||
double startPos;
|
||||
/**
|
||||
* Creates a new storagePrepIntake.
|
||||
* Moves the storage a number of rotations
|
||||
* @param subsystem The Storage subsystem
|
||||
*/
|
||||
public storagePrepIntake(Intake inSub, Storage storeSub) {
|
||||
m_intake = inSub;
|
||||
m_storage = storeSub;
|
||||
addRequirements(m_intake);
|
||||
public StoragePositionPID(Storage subsystem) {
|
||||
m_storage = subsystem;
|
||||
addRequirements(m_storage);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
if (m_storage.getBeam(1) == false){
|
||||
m_storage.runStorage(-0.5);
|
||||
}
|
||||
else{
|
||||
m_storage.runStorage(0);
|
||||
}
|
||||
m_storage.runStoragePositionPID(StorageConstants.STORAGE_FULL_BALL);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@@ -48,9 +43,10 @@ public class storagePrepIntake extends CommandBase {
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
if (m_storage.getBeam(1)){
|
||||
/*if (startPos + StorageConstants.STORAGE_FULL_BALL == m_storage.getEncoderPos())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+13
-6
@@ -7,15 +7,19 @@
|
||||
|
||||
package frc4388.robot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.StorageConstants;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
public class storagePrepAim extends CommandBase {
|
||||
public class StoragePrepAim extends CommandBase {
|
||||
Storage m_storage;
|
||||
double startTime;
|
||||
/**
|
||||
* Creates a new storagePrepAim.
|
||||
* Prepares the Storage for aiming
|
||||
* @param storeSub The Storage subsystem
|
||||
*/
|
||||
public storagePrepAim(Storage storeSub) {
|
||||
public StoragePrepAim(Storage storeSub) {
|
||||
m_storage = storeSub;
|
||||
addRequirements(m_storage);
|
||||
}
|
||||
@@ -23,13 +27,14 @@ public class storagePrepAim extends CommandBase {
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
if (m_storage.getBeam(2) == false){
|
||||
m_storage.runStorage(0.5);
|
||||
if (m_storage.getBeam(1)){
|
||||
m_storage.runStorage(StorageConstants.STORAGE_SPEED);
|
||||
}
|
||||
else{
|
||||
m_storage.runStorage(0);
|
||||
@@ -44,9 +49,11 @@ public class storagePrepAim extends CommandBase {
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
if (m_storage.getBeam(2)){
|
||||
if (!m_storage.getBeam(1) || startTime + StorageConstants.STORAGE_TIMEOUT <= System.currentTimeMillis()){
|
||||
SmartDashboard.putBoolean("StoragePrepAim Finished", true);
|
||||
return true;
|
||||
}
|
||||
SmartDashboard.putBoolean("StoragePrepAim Finished", false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+12
-8
@@ -8,16 +8,21 @@
|
||||
package frc4388.robot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.StorageConstants;
|
||||
import frc4388.robot.subsystems.Intake;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
public class storageIntake extends CommandBase {
|
||||
public class StoragePrepIntake extends CommandBase {
|
||||
public Intake m_intake;
|
||||
public Storage m_storage;
|
||||
public double startTime;
|
||||
|
||||
/**
|
||||
* Creates a new storageIntake.
|
||||
* Prepares the Storage for intaking
|
||||
* @param inSub The Intake subsystem
|
||||
* @param storeSub the Storage subsystem
|
||||
*/
|
||||
public storageIntake(Intake inSub, Storage storeSub) {
|
||||
public StoragePrepIntake(Intake inSub, Storage storeSub) {
|
||||
m_intake = inSub;
|
||||
m_storage = storeSub;
|
||||
addRequirements(m_intake);
|
||||
@@ -27,18 +32,17 @@ public class storageIntake extends CommandBase {
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
if (m_storage.getBeam(0)){
|
||||
m_storage.setStoragePID(m_storage.getEncoderPos() + 2);
|
||||
m_intake.runExtender(-0.3);
|
||||
m_storage.runStorage(-StorageConstants.STORAGE_SPEED);
|
||||
}
|
||||
else{
|
||||
m_intake.runExtender(0.3);
|
||||
m_storage.runStorage(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +54,7 @@ public class storageIntake extends CommandBase {
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
if (m_storage.getBeam(0)){
|
||||
if (!m_storage.getBeam(0) || startTime + StorageConstants.STORAGE_TIMEOUT <= System.currentTimeMillis()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
+8
-8
@@ -8,16 +8,17 @@
|
||||
package frc4388.robot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.Constants.StorageConstants;
|
||||
import frc4388.robot.subsystems.Storage;
|
||||
|
||||
public class StorageIntakeFinal extends CommandBase {
|
||||
public class StorageRun extends CommandBase {
|
||||
Storage m_storage;
|
||||
/**
|
||||
* Creates a new StorageIntakeFinal.
|
||||
* Runs the Storage at a speed
|
||||
* @param storageSub The Storage subsytem
|
||||
*/
|
||||
public StorageIntakeFinal(Storage subsystem) {
|
||||
m_storage = subsystem;
|
||||
addRequirements(m_storage);
|
||||
public StorageRun(Storage storageSub) {
|
||||
m_storage = storageSub;
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@@ -28,14 +29,13 @@ public class StorageIntakeFinal extends CommandBase {
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
if (m_storage.getBeam(1)){
|
||||
m_storage.setStoragePID(m_storage.getEncoderPos() + 5);
|
||||
}
|
||||
m_storage.runStorage(StorageConstants.STORAGE_SPEED);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
m_storage.runStorage(0);
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@@ -9,21 +9,29 @@ package frc4388.robot.commands;
|
||||
|
||||
import frc4388.robot.Constants.ShooterConstants;
|
||||
import frc4388.robot.Constants.VisionConstants;
|
||||
import frc4388.robot.subsystems.Camera;
|
||||
import frc4388.robot.subsystems.Drive;
|
||||
import frc4388.robot.subsystems.LimeLight;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
import frc4388.robot.commands.TrimShooter;
|
||||
import frc4388.utility.ShooterTables;
|
||||
import frc4388.utility.controller.IHandController;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import edu.wpi.first.wpilibj2.command.RunCommand;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.XboxController;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
public class TrackTarget extends CommandBase {
|
||||
//Setup
|
||||
// Setup
|
||||
NetworkTableEntry xEntry;
|
||||
ShooterAim m_shooterAim;
|
||||
Shooter m_shooter;
|
||||
IHandController m_driverController;
|
||||
//Aiming
|
||||
// Aiming
|
||||
double turnAmount = 0;
|
||||
double xAngle = 0;
|
||||
double yAngle = 0;
|
||||
@@ -32,66 +40,91 @@ public class TrackTarget extends CommandBase {
|
||||
public static double fireVel;
|
||||
public static double fireAngle;
|
||||
|
||||
public double m_hoodTrim;
|
||||
public double m_turretTrim;
|
||||
|
||||
ShooterTables m_shooterTable;
|
||||
|
||||
/**
|
||||
* Uses the Limelight to track the target
|
||||
* @param shooterSubsystem The Shooter subsystem
|
||||
* @param aimSubsystem The ShooterAim subsystem
|
||||
*/
|
||||
public TrackTarget(Shooter shooterSubsystem) {
|
||||
public TrackTarget(Shooter shooterSubsystem, ShooterAim aimSubsystem) {
|
||||
m_shooterAim = aimSubsystem;
|
||||
m_shooter = shooterSubsystem;
|
||||
addRequirements(m_shooter);
|
||||
addRequirements(m_shooterAim);
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(1);
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
//Vision Processing Mode
|
||||
// Vision Processing Mode
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(0);
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(3);
|
||||
m_shooterTable = new ShooterTables();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
target = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0);
|
||||
xAngle = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0);
|
||||
yAngle = NetworkTableInstance.getDefault().getTable("limelight").getEntry("ty").getDouble(0);
|
||||
|
||||
if (target == 1.0){ //If target in view
|
||||
//Aiming Left/Right
|
||||
turnAmount = (xAngle/VisionConstants.FOV)*VisionConstants.TURN_P_VALUE;
|
||||
if (Math.abs(xAngle) < VisionConstants.X_ANGLE_ERROR){turnAmount = 0;} //Angle Error Zone
|
||||
//Deadzones
|
||||
else if(turnAmount > 0 && turnAmount < VisionConstants.MOTOR_DEAD_ZONE){turnAmount = VisionConstants.MOTOR_DEAD_ZONE;}
|
||||
else if(turnAmount < 0 && turnAmount > -VisionConstants.MOTOR_DEAD_ZONE){turnAmount = -VisionConstants.MOTOR_DEAD_ZONE;}
|
||||
m_shooter.runShooterWithInput(turnAmount/5);
|
||||
|
||||
//Finding Distance
|
||||
distance = VisionConstants.TARGET_HEIGHT/Math.tan((VisionConstants.LIME_ANGLE + yAngle)*(Math.PI/180));
|
||||
if (target == 1.0) { // If target in view
|
||||
// Aiming Left/Right
|
||||
turnAmount = (xAngle / VisionConstants.FOV) * VisionConstants.TURN_P_VALUE;
|
||||
if (Math.abs(xAngle) < VisionConstants.X_ANGLE_ERROR) {
|
||||
turnAmount = 0;
|
||||
} // Angle Error Zone
|
||||
// Deadzones
|
||||
else if (turnAmount > 0 && turnAmount < VisionConstants.MOTOR_DEAD_ZONE) {
|
||||
turnAmount = VisionConstants.MOTOR_DEAD_ZONE;
|
||||
} else if (turnAmount < 0 && turnAmount > -VisionConstants.MOTOR_DEAD_ZONE) {
|
||||
turnAmount = -VisionConstants.MOTOR_DEAD_ZONE;
|
||||
}
|
||||
m_shooterAim.runShooterWithInput(-turnAmount - m_shooter.shooterTrims.m_turretTrim);
|
||||
|
||||
// Finding Distance
|
||||
distance = VisionConstants.TARGET_HEIGHT / Math.tan((VisionConstants.LIME_ANGLE + yAngle) * (Math.PI / 180));
|
||||
SmartDashboard.putNumber("Distance to Target", distance);
|
||||
|
||||
double yVel = Math.sqrt(2*VisionConstants.GRAV*VisionConstants.TARGET_HEIGHT);
|
||||
double xVel = (distance*VisionConstants.GRAV)/(yVel);
|
||||
//START Equation Code
|
||||
double yVel = Math.sqrt(2 * VisionConstants.GRAV * VisionConstants.TARGET_HEIGHT);
|
||||
double xVel = (distance * VisionConstants.GRAV) / (yVel);
|
||||
|
||||
fireVel = Math.sqrt((Math.pow(xVel, 2))+(Math.pow(yVel,2)));
|
||||
fireAngle = Math.atan(yVel/xVel);
|
||||
fireAngle = Math.atan(yVel/xVel) * (180/Math.PI);
|
||||
//END Equation Code
|
||||
|
||||
/*//START CSV Code
|
||||
fireVel = m_shooterTable.getVelocity(distance);
|
||||
fireAngle = m_shooterTable.getHood(distance); //Note: Ensure to follow because units are different
|
||||
//END CSV Code*/
|
||||
|
||||
|
||||
m_shooter.m_fireVel = fireVel;
|
||||
m_shooter.m_fireAngle = fireAngle;
|
||||
m_shooter.m_fireAngle = fireAngle + m_shooter.shooterTrims.m_hoodTrim;
|
||||
}
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
//Drive Camera Mode
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(1);
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(0);
|
||||
|
||||
}
|
||||
|
||||
// Returns true when the command should end.
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
if (xAngle < 1 && xAngle > -1 && target == 1)
|
||||
{
|
||||
SmartDashboard.putBoolean("TrackTarget Finished", true);
|
||||
return true;
|
||||
}
|
||||
SmartDashboard.putBoolean("TrackTarget Finished", false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.Joystick;
|
||||
import frc4388.utility.controller.XboxController;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import frc4388.robot.RobotContainer;
|
||||
import frc4388.robot.Trims;
|
||||
import frc4388.robot.Constants.OIConstants;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
|
||||
public class TrimShooter extends CommandBase {
|
||||
private final XboxController m_operatorXbox = new XboxController(OIConstants.XBOX_OPERATOR_ID);
|
||||
public double turretTrim = 0;
|
||||
public double hoodTrim = 0;
|
||||
|
||||
public Shooter m_shooter;
|
||||
/**
|
||||
* Trims the shooter based on the D-Pad inputs
|
||||
* @param shootSub The Shooter subsytems
|
||||
*/
|
||||
public TrimShooter(Shooter shootSub) {
|
||||
m_shooter = shootSub;
|
||||
}
|
||||
|
||||
// Called when the command is initially scheduled.
|
||||
@Override
|
||||
public void initialize() {
|
||||
}
|
||||
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
if(m_operatorXbox.getDPadTop()){
|
||||
hoodTrim += 1;
|
||||
}
|
||||
else if(m_operatorXbox.getDPadBottom()){
|
||||
hoodTrim -= 1;
|
||||
}
|
||||
else if(m_operatorXbox.getDPadRight()){
|
||||
turretTrim += 1;
|
||||
}
|
||||
else if(m_operatorXbox.getDPadLeft()){
|
||||
turretTrim -= 1;
|
||||
}
|
||||
|
||||
m_shooter.shooterTrims.m_turretTrim = turretTrim;
|
||||
m_shooter.shooterTrims.m_hoodTrim = hoodTrim;
|
||||
}
|
||||
|
||||
// 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() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user