Files
RiseOfRidgebotics2020/src/main/java/frc4388/robot/subsystems/ShooterAim.java
T

88 lines
3.6 KiB
Java
Raw Normal View History

2020-02-21 21:58:56 -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.subsystems;
2020-02-28 20:05:56 -07:00
import com.revrobotics.CANDigitalInput;
2020-03-02 21:23:33 -07:00
import com.revrobotics.CANDigitalInput.LimitSwitchPolarity;
2020-02-21 21:58:56 -07:00
import com.revrobotics.CANEncoder;
import com.revrobotics.CANPIDController;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMax.IdleMode;
2020-02-29 18:42:37 -07:00
import com.revrobotics.CANSparkMax.SoftLimitDirection;
2020-02-21 21:58:56 -07:00
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
2020-03-02 21:23:33 -07:00
import com.revrobotics.ControlType;
2020-02-25 20:01:24 -07:00
2020-02-21 21:58:56 -07:00
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.Constants.ShooterConstants;
2020-03-02 21:23:33 -07:00
import frc4388.utility.Gains;
2020-02-21 21:58:56 -07:00
public class ShooterAim extends SubsystemBase {
public CANSparkMax m_shooterRotateMotor = new CANSparkMax(ShooterConstants.SHOOTER_ROTATE_ID, MotorType.kBrushless);
public static Gains m_shooterTurretGains = ShooterConstants.SHOOTER_TURRET_GAINS;
2020-02-28 20:05:56 -07:00
CANDigitalInput m_shooterRightLimit, m_shooterLeftLimit;
2020-02-21 21:58:56 -07:00
// Configure PID Controllers
CANPIDController m_shooterRotatePIDController = m_shooterRotateMotor.getPIDController();
2020-02-29 18:42:37 -07:00
public CANEncoder m_shooterRotateEncoder = m_shooterRotateMotor.getEncoder();
2020-02-21 21:58:56 -07:00
/**
2020-03-01 00:41:23 -07:00
* Creates a subsytem for the turret aiming
2020-02-21 21:58:56 -07:00
*/
public ShooterAim() {
2020-02-29 18:42:37 -07:00
//resetGyroShooterRotate();
2020-02-21 21:58:56 -07:00
m_shooterRotateMotor.setIdleMode(IdleMode.kBrake);
2020-02-28 20:05:56 -07:00
2020-02-29 18:42:37 -07:00
m_shooterLeftLimit = m_shooterRotateMotor.getReverseLimitSwitch(LimitSwitchPolarity.kNormallyOpen);
m_shooterRightLimit = m_shooterRotateMotor.getForwardLimitSwitch(LimitSwitchPolarity.kNormallyOpen);
2020-02-28 20:05:56 -07:00
m_shooterRightLimit.enableLimitSwitch(true);
m_shooterLeftLimit.enableLimitSwitch(true);
2020-02-29 18:42:37 -07:00
m_shooterRotateMotor.enableSoftLimit(SoftLimitDirection.kForward, false);
m_shooterRotateMotor.enableSoftLimit(SoftLimitDirection.kReverse, true);
2020-03-01 00:41:23 -07:00
m_shooterRotateMotor.setSoftLimit(SoftLimitDirection.kForward, ShooterConstants.TURRET_RIGHT_SOFT_LIMIT);
m_shooterRotateMotor.setSoftLimit(SoftLimitDirection.kReverse, ShooterConstants.TURRET_LEFT_SOFT_LIMIT);
2020-02-21 21:58:56 -07:00
}
public void runShooterWithInput(double input) {
2020-03-01 00:41:23 -07:00
m_shooterRotateMotor.set(input*ShooterConstants.TURRET_SPEED_MULTIPLIER);
2020-02-21 21:58:56 -07:00
}
/* Rotate Shooter PID Control */
public void runshooterRotatePID(double targetAngle)
{
// Set PID Coefficients
m_shooterRotatePIDController.setP(m_shooterTurretGains.m_kP);
m_shooterRotatePIDController.setI(m_shooterTurretGains.m_kI);
m_shooterRotatePIDController.setD(m_shooterTurretGains.m_kD);
m_shooterRotatePIDController.setFF(m_shooterTurretGains.m_kF);
m_shooterRotatePIDController.setIZone(m_shooterTurretGains.m_kIzone);
m_shooterRotatePIDController.setOutputRange(ShooterConstants.SHOOTER_TURRET_MIN, m_shooterTurretGains.m_kPeakOutput);
// Convert input angle in degrees to rotations of the motor
targetAngle = targetAngle/ShooterConstants.DEGREES_PER_ROT;
m_shooterRotatePIDController.setReference(targetAngle, ControlType.kPosition);
}
public void resetGyroShooterRotate()
{
2020-02-29 18:42:37 -07:00
m_shooterRotateEncoder.setPosition(0);
}
public double getShooterRotatePosition(){
return m_shooterRotateMotor.getEncoder().getPosition();
2020-02-21 21:58:56 -07:00
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
}