7.10晚晚
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package frc.robot.subsystems;
|
package frc.robot.subsystems;
|
||||||
|
|
||||||
|
import com.ctre.phoenix6.controls.NeutralOut;
|
||||||
import com.ctre.phoenix6.controls.VoltageOut;
|
import com.ctre.phoenix6.controls.VoltageOut;
|
||||||
import com.ctre.phoenix6.hardware.TalonFX;
|
import com.ctre.phoenix6.hardware.TalonFX;
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ import frc.robot.Constants;
|
|||||||
public class ConveyorSubsystem extends SubsystemBase {
|
public class ConveyorSubsystem extends SubsystemBase {
|
||||||
public final TalonFX mainConveyor;
|
public final TalonFX mainConveyor;
|
||||||
private final VoltageOut voltageRequest = new VoltageOut(0);
|
private final VoltageOut voltageRequest = new VoltageOut(0);
|
||||||
|
private final NeutralOut neutralRequest = new NeutralOut();
|
||||||
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("Conveyor");
|
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("Conveyor");
|
||||||
private double targetOutputVolts = 0.0;
|
private double targetOutputVolts = 0.0;
|
||||||
|
|
||||||
@@ -29,7 +31,8 @@ public class ConveyorSubsystem extends SubsystemBase {
|
|||||||
setVoltage(Constants.Conveyor.reverseVoltage);
|
setVoltage(Constants.Conveyor.reverseVoltage);
|
||||||
}
|
}
|
||||||
public void stop() {
|
public void stop() {
|
||||||
setVoltage(0.0);
|
targetOutputVolts = 0.0;
|
||||||
|
mainConveyor.setControl(neutralRequest);
|
||||||
}
|
}
|
||||||
public void setVoltage(double outputVolts) {
|
public void setVoltage(double outputVolts) {
|
||||||
targetOutputVolts = MathUtil.clamp(outputVolts, -12.0, 12.0);
|
targetOutputVolts = MathUtil.clamp(outputVolts, -12.0, 12.0);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package frc.robot.subsystems;
|
package frc.robot.subsystems;
|
||||||
|
|
||||||
import com.ctre.phoenix6.controls.Follower;
|
import com.ctre.phoenix6.controls.Follower;
|
||||||
|
import com.ctre.phoenix6.controls.NeutralOut;
|
||||||
import com.ctre.phoenix6.controls.VoltageOut;
|
import com.ctre.phoenix6.controls.VoltageOut;
|
||||||
import com.ctre.phoenix6.hardware.TalonFX;
|
import com.ctre.phoenix6.hardware.TalonFX;
|
||||||
import com.ctre.phoenix6.signals.MotorAlignmentValue;
|
import com.ctre.phoenix6.signals.MotorAlignmentValue;
|
||||||
@@ -22,6 +23,7 @@ public class IntakeRollerSubsystem extends SubsystemBase {
|
|||||||
private final TalonFX rightIntakeRoller;
|
private final TalonFX rightIntakeRoller;
|
||||||
|
|
||||||
private final VoltageOut voltageRequest = new VoltageOut(0);
|
private final VoltageOut voltageRequest = new VoltageOut(0);
|
||||||
|
private final NeutralOut neutralRequest = new NeutralOut();
|
||||||
private final Follower rightFollower;
|
private final Follower rightFollower;
|
||||||
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("IntakeRoller");
|
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("IntakeRoller");
|
||||||
private double targetOutputVolts = 0.0;
|
private double targetOutputVolts = 0.0;
|
||||||
@@ -44,7 +46,9 @@ public class IntakeRollerSubsystem extends SubsystemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
setVoltage(0.0);
|
targetOutputVolts = 0.0;
|
||||||
|
leftIntakeRoller.setControl(neutralRequest);
|
||||||
|
rightIntakeRoller.setControl(neutralRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVoltage(double outputVolts) {
|
public void setVoltage(double outputVolts) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package frc.robot.subsystems;
|
|||||||
import com.ctre.phoenix6.configs.MotorOutputConfigs;
|
import com.ctre.phoenix6.configs.MotorOutputConfigs;
|
||||||
import com.ctre.phoenix6.configs.Slot0Configs;
|
import com.ctre.phoenix6.configs.Slot0Configs;
|
||||||
import com.ctre.phoenix6.controls.Follower;
|
import com.ctre.phoenix6.controls.Follower;
|
||||||
|
import com.ctre.phoenix6.controls.NeutralOut;
|
||||||
import com.ctre.phoenix6.controls.VelocityVoltage;
|
import com.ctre.phoenix6.controls.VelocityVoltage;
|
||||||
import com.ctre.phoenix6.controls.VoltageOut;
|
import com.ctre.phoenix6.controls.VoltageOut;
|
||||||
import com.ctre.phoenix6.hardware.TalonFX;
|
import com.ctre.phoenix6.hardware.TalonFX;
|
||||||
@@ -18,7 +19,6 @@ import edu.wpi.first.networktables.NetworkTable;
|
|||||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||||
import edu.wpi.first.wpilibj.DriverStation;
|
import edu.wpi.first.wpilibj.DriverStation;
|
||||||
import edu.wpi.first.wpilibj.Encoder;
|
import edu.wpi.first.wpilibj.Encoder;
|
||||||
import edu.wpi.first.wpilibj.Timer;
|
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
import edu.wpi.first.wpilibj2.command.Commands;
|
import edu.wpi.first.wpilibj2.command.Commands;
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
@@ -45,6 +45,8 @@ public class ShooterSubsystem extends SubsystemBase {
|
|||||||
private final VelocityVoltage leftFlywheelVelocityRequest = new VelocityVoltage(0).withSlot(0);
|
private final VelocityVoltage leftFlywheelVelocityRequest = new VelocityVoltage(0).withSlot(0);
|
||||||
private final VelocityVoltage conveyorVelocityRequest = new VelocityVoltage(0).withSlot(0);
|
private final VelocityVoltage conveyorVelocityRequest = new VelocityVoltage(0).withSlot(0);
|
||||||
private final VoltageOut backboardVoltageRequest = new VoltageOut(0);
|
private final VoltageOut backboardVoltageRequest = new VoltageOut(0);
|
||||||
|
private final NeutralOut flywheelNeutralRequest = new NeutralOut();
|
||||||
|
private final NeutralOut conveyorNeutralRequest = new NeutralOut();
|
||||||
|
|
||||||
private final Follower flywheelFollower;
|
private final Follower flywheelFollower;
|
||||||
private final Follower conveyorFollower;
|
private final Follower conveyorFollower;
|
||||||
@@ -56,7 +58,6 @@ public class ShooterSubsystem extends SubsystemBase {
|
|||||||
private double flywheelOutputVolts = 0.0;
|
private double flywheelOutputVolts = 0.0;
|
||||||
private double flywheelTargetVelocity = 0.0;
|
private double flywheelTargetVelocity = 0.0;
|
||||||
private double flywheelVelocityTolerance = Constants.Shooter.flywheelReadyVelocityTolerance;
|
private double flywheelVelocityTolerance = Constants.Shooter.flywheelReadyVelocityTolerance;
|
||||||
private double flywheelVelocityReadyStartTimestamp = 0.0;
|
|
||||||
private boolean flywheelVelocityTuningActive = false;
|
private boolean flywheelVelocityTuningActive = false;
|
||||||
private double shooterConveyorTargetVelocity = 0.0;
|
private double shooterConveyorTargetVelocity = 0.0;
|
||||||
private boolean shooterConveyorVelocityTuningActive = false;
|
private boolean shooterConveyorVelocityTuningActive = false;
|
||||||
@@ -79,10 +80,18 @@ public class ShooterSubsystem extends SubsystemBase {
|
|||||||
leftConveyor.getConfigurator().apply(Constants.Shooter.conveyorSlot0Configs);
|
leftConveyor.getConfigurator().apply(Constants.Shooter.conveyorSlot0Configs);
|
||||||
rightConveyor.getConfigurator().apply(Constants.Shooter.conveyorSlot0Configs);
|
rightConveyor.getConfigurator().apply(Constants.Shooter.conveyorSlot0Configs);
|
||||||
|
|
||||||
var motorOutputConfigs = new MotorOutputConfigs();
|
var leftFlywheelMotorOutputConfigs = new MotorOutputConfigs();
|
||||||
motorOutputConfigs.Inverted = InvertedValue.Clockwise_Positive;
|
leftFlywheelMotorOutputConfigs.Inverted = InvertedValue.Clockwise_Positive;
|
||||||
leftFlywheel.getConfigurator().apply(motorOutputConfigs);
|
leftFlywheelMotorOutputConfigs.NeutralMode = NeutralModeValue.Coast;
|
||||||
leftConveyor.getConfigurator().apply(motorOutputConfigs);
|
leftFlywheel.getConfigurator().apply(leftFlywheelMotorOutputConfigs);
|
||||||
|
|
||||||
|
var rightFlywheelMotorOutputConfigs = new MotorOutputConfigs();
|
||||||
|
rightFlywheelMotorOutputConfigs.NeutralMode = NeutralModeValue.Coast;
|
||||||
|
rightFlywheel.getConfigurator().apply(rightFlywheelMotorOutputConfigs);
|
||||||
|
|
||||||
|
var conveyorMotorOutputConfigs = new MotorOutputConfigs();
|
||||||
|
conveyorMotorOutputConfigs.Inverted = InvertedValue.Clockwise_Positive;
|
||||||
|
leftConveyor.getConfigurator().apply(conveyorMotorOutputConfigs);
|
||||||
|
|
||||||
flywheelFollower = new Follower(leftFlywheel.getDeviceID(), MotorAlignmentValue.Opposed).withUpdateFreqHz(50);
|
flywheelFollower = new Follower(leftFlywheel.getDeviceID(), MotorAlignmentValue.Opposed).withUpdateFreqHz(50);
|
||||||
conveyorFollower = new Follower(leftConveyor.getDeviceID(), MotorAlignmentValue.Opposed).withUpdateFreqHz(50);
|
conveyorFollower = new Follower(leftConveyor.getDeviceID(), MotorAlignmentValue.Opposed).withUpdateFreqHz(50);
|
||||||
@@ -136,24 +145,21 @@ public class ShooterSubsystem extends SubsystemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFlywheelVelocity(double targetVelocityRps) {
|
public void setFlywheelVelocity(double targetVelocityRps) {
|
||||||
double clampedTargetVelocity = MathUtil.clamp(
|
flywheelTargetVelocity = targetVelocityRps;
|
||||||
targetVelocityRps,
|
|
||||||
-Constants.Shooter.flywheelMaxVelocity,
|
|
||||||
Constants.Shooter.flywheelMaxVelocity
|
|
||||||
);
|
|
||||||
if (Math.abs(clampedTargetVelocity - flywheelTargetVelocity) > 1e-6) {
|
|
||||||
flywheelVelocityReadyStartTimestamp = Timer.getFPGATimestamp();
|
|
||||||
}
|
|
||||||
flywheelTargetVelocity = clampedTargetVelocity;
|
|
||||||
leftFlywheel.setControl(leftFlywheelVelocityRequest.withVelocity(flywheelTargetVelocity));
|
leftFlywheel.setControl(leftFlywheelVelocityRequest.withVelocity(flywheelTargetVelocity));
|
||||||
setRightFlywheelFollowLeft();
|
setRightFlywheelFollowLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopFlywheel() {
|
public void stopFlywheel() {
|
||||||
setFlywheelVelocity(0.0);
|
flywheelTargetVelocity = 0.0;
|
||||||
|
leftFlywheel.setControl(flywheelNeutralRequest);
|
||||||
|
rightFlywheel.setControl(flywheelNeutralRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean atVelocity() {
|
public boolean atVelocity() {
|
||||||
|
if (flywheelTargetVelocity <= 10.0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
double currentvelocity = getAverageFlywheelVelocity();
|
double currentvelocity = getAverageFlywheelVelocity();
|
||||||
if(currentvelocity>flywheelTargetVelocity*0.95){
|
if(currentvelocity>flywheelTargetVelocity*0.95){
|
||||||
return true;
|
return true;
|
||||||
@@ -197,7 +203,9 @@ public class ShooterSubsystem extends SubsystemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stopShooterConveyor() {
|
public void stopShooterConveyor() {
|
||||||
runShooterConveyorVelocity(0.0);
|
shooterConveyorTargetVelocity = 0.0;
|
||||||
|
leftConveyor.setControl(conveyorNeutralRequest);
|
||||||
|
rightConveyor.setControl(conveyorNeutralRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getShooterConveyorVelocity() {
|
public double getShooterConveyorVelocity() {
|
||||||
|
|||||||
Reference in New Issue
Block a user