mirror of
https://github.com/Team4388/RiseOfRidgebotics2020.git
synced 2026-06-09 08:48:01 -06:00
hood turret and tracking working
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.subsystems.Shooter;
|
||||
import frc4388.robot.subsystems.ShooterAim;
|
||||
|
||||
public class CalibrateShooter extends CommandBase {
|
||||
Shooter m_shooter;
|
||||
ShooterAim m_shooterAim;
|
||||
/**
|
||||
* Creates a new CalibrateShooter.
|
||||
*/
|
||||
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(-0.1);
|
||||
|
||||
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(0.075);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class HoldTarget extends CommandBase {
|
||||
public HoldTarget(Shooter shooterSubsystem, ShooterAim aimSubsystem) {
|
||||
m_shooterAim = aimSubsystem;
|
||||
m_shooter = shooterSubsystem;
|
||||
addRequirements(m_shooter);
|
||||
addRequirements(m_shooterAim);
|
||||
NetworkTableInstance.getDefault().getTable("limelight").getEntry("camMode").setNumber(1);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class HoldTarget extends CommandBase {
|
||||
//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/3);
|
||||
m_shooterAim.runShooterWithInput(-turnAmount);
|
||||
|
||||
//Finding Distance
|
||||
distance = VisionConstants.TARGET_HEIGHT/Math.tan((VisionConstants.LIME_ANGLE + yAngle)*(Math.PI/180));
|
||||
@@ -79,17 +79,29 @@ public class HoldTarget extends CommandBase {
|
||||
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);
|
||||
m_shooter.m_fireVel = fireVel;
|
||||
m_shooter.m_fireAngle = fireAngle;
|
||||
|
||||
}/*
|
||||
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.
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.subsystems.Shooter;
|
||||
|
||||
public class HoodPositionPID extends CommandBase {
|
||||
Shooter m_shooter;
|
||||
/**
|
||||
* 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 firingAngle = (-0.47*m_shooter.addFireAngle())+40.5;
|
||||
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() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class TrackTarget extends CommandBase {
|
||||
} else if (turnAmount < 0 && turnAmount > -VisionConstants.MOTOR_DEAD_ZONE) {
|
||||
turnAmount = -VisionConstants.MOTOR_DEAD_ZONE;
|
||||
}
|
||||
m_shooterAim.runShooterWithInput(turnAmount);
|
||||
m_shooterAim.runShooterWithInput(-turnAmount);
|
||||
|
||||
// Finding Distance
|
||||
distance = VisionConstants.TARGET_HEIGHT / Math.tan((VisionConstants.LIME_ANGLE + yAngle) * (Math.PI / 180));
|
||||
@@ -84,17 +84,17 @@ public class TrackTarget extends CommandBase {
|
||||
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);
|
||||
m_shooter.m_fireVel = fireVel;
|
||||
m_shooter.m_fireAngle = fireAngle;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
Reference in New Issue
Block a user