-
Notifications
You must be signed in to change notification settings - Fork 0
added code for new drum shooter prototype #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f6069a7
facfb29
c88e420
dc0a0ab
8d2f272
4f07594
7352f9a
2e92bdc
39911a6
da6dee2
f03763b
f22c909
69a8814
54ad251
ede1e8b
e94cd2e
da096ff
71efedd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,12 @@ class KickerConstants { | |
| static final String RESIST_FUEL_PREFERENCE_NT = "Kicker/RESIST_FUEL_VOLTAGE"; | ||
|
|
||
| static final TalonFXConfiguration KICKER_MOTOR_CONFIG = | ||
| new TalonFXConfiguration() | ||
| .withMotorOutput( | ||
| new MotorOutputConfigs().withInverted(InvertedValue.CounterClockwise_Positive)) | ||
| .withCurrentLimits(new CurrentLimitsConfigs().withStatorCurrentLimit(Amps.of(35))); | ||
|
|
||
| static final TalonFXConfiguration KICKER_MOTOR_2_CONFIG = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| new TalonFXConfiguration() | ||
| .withMotorOutput(new MotorOutputConfigs().withInverted(InvertedValue.Clockwise_Positive)) | ||
| .withCurrentLimits(new CurrentLimitsConfigs().withStatorCurrentLimit(Amps.of(35))); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,15 @@ | |
| public interface KickerIO extends AutoCloseable { | ||
| @AutoLog | ||
| class KickerIOInputs { | ||
| public Voltage motorVoltage = Volts.of(0); | ||
| public AngularVelocity motorRotationalVelocity = RotationsPerSecond.of(0); | ||
| public Current motorStatorCurrent = Amps.of(0); | ||
| public Current motorSupplyCurrent = Amps.of(0); | ||
| public Voltage motor1Voltage = Volts.of(0); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please name the motors based on their position (when looking at the robot from behind it). I.e: upperLeftMotor, lowerRightMotor, etc. |
||
| public AngularVelocity motor1RotationalVelocity = RotationsPerSecond.of(0); | ||
| public Current motor1StatorCurrent = Amps.of(0); | ||
| public Current motor1SupplyCurrent = Amps.of(0); | ||
|
|
||
| public Voltage motor2Voltage = Volts.of(0); | ||
| public AngularVelocity motor2RotationalVelocity = RotationsPerSecond.of(0); | ||
| public Current motor2StatorCurrent = Amps.of(0); | ||
| public Current motor2SupplyCurrent = Amps.of(0); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,28 +7,39 @@ | |
| import edu.wpi.first.units.measure.Voltage; | ||
|
|
||
| public class KickerIOReal implements KickerIO { | ||
| private final TalonFX motor; | ||
| private final TalonFX motor1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename these motors so they are more descriptive, and also append kicker to the front. (So it becomes uppperKickerMotor, and lowerKickerMotor.) |
||
| private final TalonFX motor2; | ||
|
|
||
| public KickerIOReal() { | ||
| motor = new TalonFX(Constants.KICKER_MOTOR_ID); | ||
| motor.getConfigurator().apply(KickerConstants.KICKER_MOTOR_CONFIG); | ||
| motor1 = new TalonFX(Constants.KICKER_MOTOR_1_ID); | ||
| motor1.getConfigurator().apply(KickerConstants.KICKER_MOTOR_CONFIG); | ||
|
|
||
| motor2 = new TalonFX(Constants.KICKER_MOTOR_2_ID); | ||
| motor2.getConfigurator().apply(KickerConstants.KICKER_MOTOR_2_CONFIG); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateState(KickerIOInputs inputs) { | ||
| inputs.motorVoltage = motor.getMotorVoltage().getValue(); | ||
| inputs.motorRotationalVelocity = motor.getVelocity().getValue(); | ||
| inputs.motorStatorCurrent = motor.getStatorCurrent().getValue(); | ||
| inputs.motorSupplyCurrent = motor.getSupplyCurrent().getValue(); | ||
| inputs.motor1Voltage = motor1.getMotorVoltage().getValue(); | ||
| inputs.motor1RotationalVelocity = motor1.getVelocity().getValue(); | ||
| inputs.motor1StatorCurrent = motor1.getStatorCurrent().getValue(); | ||
| inputs.motor1SupplyCurrent = motor1.getSupplyCurrent().getValue(); | ||
|
|
||
| inputs.motor2Voltage = motor2.getMotorVoltage().getValue(); | ||
| inputs.motor2RotationalVelocity = motor2.getVelocity().getValue(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure to update the motor names here too. |
||
| inputs.motor2StatorCurrent = motor2.getStatorCurrent().getValue(); | ||
| inputs.motor2SupplyCurrent = motor2.getSupplyCurrent().getValue(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setMotorVoltage(Voltage kickerMotorVoltage) { | ||
| motor.setVoltage(kickerMotorVoltage.in(Volts)); | ||
| motor1.setVoltage(kickerMotorVoltage.in(Volts)); | ||
| motor2.setVoltage(kickerMotorVoltage.in(Volts)); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| motor.close(); | ||
| motor1.close(); | ||
| motor2.close(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,7 @@ | ||
| package com.team2813.subsystems.kicker; | ||
|
|
||
| import static edu.wpi.first.units.Units.KilogramSquareMeters; | ||
| import static edu.wpi.first.units.Units.Volts; | ||
| // todo re add sim code | ||
|
|
||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import com.ctre.phoenix6.sim.TalonFXSimState; | ||
| import com.team2813.Constants; | ||
| import edu.wpi.first.math.system.plant.DCMotor; | ||
| import edu.wpi.first.math.system.plant.LinearSystemId; | ||
| import edu.wpi.first.units.measure.Voltage; | ||
| import edu.wpi.first.wpilibj.simulation.FlywheelSim; | ||
| package com.team2813.subsystems.kicker; | ||
|
|
||
| public class KickerIOSim implements KickerIO { | ||
| private final FlywheelSim flywheelSim; | ||
| private final TalonFX motor; | ||
|
|
||
| public KickerIOSim() { | ||
| motor = new TalonFX(Constants.KICKER_MOTOR_ID); | ||
| flywheelSim = | ||
| new FlywheelSim( | ||
| LinearSystemId.createFlywheelSystem( | ||
| DCMotor.getKrakenX60(1), | ||
| KickerConstants.KICKER_SIM_MOI.in( | ||
| KilogramSquareMeters), // "Moment of Inertia" taken from OnShape. | ||
| KickerConstants.KICKER_MOTOR_TO_FLYWHEEL_GEARING), | ||
| DCMotor.getKrakenX60(1)); | ||
| } | ||
|
|
||
| @Override | ||
| public void setMotorVoltage(Voltage kickerMotorVoltage) { | ||
| double volts = kickerMotorVoltage.in(Volts); | ||
| motor.setVoltage(volts); | ||
| flywheelSim.setInputVoltage(volts); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateState(KickerIOInputs inputs) { | ||
| updateSimulation(); | ||
|
|
||
| inputs.motorVoltage = motor.getMotorVoltage().getValue(); | ||
| inputs.motorRotationalVelocity = motor.getVelocity().getValue(); | ||
| inputs.motorStatorCurrent = motor.getStatorCurrent().getValue(); | ||
| inputs.motorSupplyCurrent = motor.getSupplyCurrent().getValue(); | ||
| } | ||
|
|
||
| private void updateSimulation() { | ||
| flywheelSim.update(Constants.SIM_TIME_PERIOD); | ||
|
|
||
| TalonFXSimState simState = motor.getSimState(); | ||
| simState.setRotorAcceleration(flywheelSim.getAngularAcceleration()); | ||
| simState.setRotorVelocity(flywheelSim.getAngularVelocity()); | ||
| simState.setSupplyVoltage(Volts.of(12)); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| motor.close(); | ||
|
Comment on lines
-15
to
-58
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please dont delete the sim code. |
||
| } | ||
| // todo implement sim code if drum shooter is used | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,49 @@ public class ShooterConstants { | |
| } | ||
|
|
||
| // Reminder: this is the right shooter motor when robot is viewed from behind. | ||
| public static final TalonFXConfiguration MAIN_SHOOTER_MOTOR_CONFIG = | ||
| public static final TalonFXConfiguration SHOOTER_MOTOR_1_CONFIG = | ||
| new TalonFXConfiguration() | ||
| .withMotorOutput(new MotorOutputConfigs().withInverted(InvertedValue.Clockwise_Positive)) | ||
| .withSlot0( | ||
| new Slot0Configs().withKS(0.099892).withKV(0.115).withKA(0.0020241).withKP(0.026743)) | ||
| .withCurrentLimits( | ||
| new CurrentLimitsConfigs() | ||
| .withStatorCurrentLimit(Amps.of(70)) | ||
| .withSupplyCurrentLimit(50)); | ||
|
|
||
| public static final TalonFXConfiguration SHOOTER_MOTOR_2_CONFIG = | ||
| new TalonFXConfiguration() | ||
| .withMotorOutput( | ||
| new MotorOutputConfigs().withInverted(InvertedValue.CounterClockwise_Positive)) | ||
| .withSlot0( | ||
| new Slot0Configs().withKS(0.099892).withKV(0.115).withKA(0.0020241).withKP(0.026743)) | ||
| .withCurrentLimits( | ||
| new CurrentLimitsConfigs() | ||
| .withStatorCurrentLimit(Amps.of(70)) | ||
| .withSupplyCurrentLimit(50)); | ||
|
|
||
| public static final TalonFXConfiguration SHOOTER_MOTOR_3_CONFIG = | ||
| new TalonFXConfiguration() | ||
| .withMotorOutput(new MotorOutputConfigs().withInverted(InvertedValue.Clockwise_Positive)) | ||
| .withSlot0( | ||
| new Slot0Configs().withKS(0.099892).withKV(0.115).withKA(0.0020241).withKP(0.026743)) | ||
| .withCurrentLimits( | ||
| new CurrentLimitsConfigs() | ||
| .withStatorCurrentLimit(Amps.of(70)) | ||
| .withSupplyCurrentLimit(50)); | ||
|
|
||
| public static final TalonFXConfiguration SHOOTER_MOTOR_4_CONFIG = | ||
|
Comment on lines
51
to
+82
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename the configs so they are descriptive. |
||
| new TalonFXConfiguration() | ||
| .withMotorOutput(new MotorOutputConfigs().withInverted(InvertedValue.Clockwise_Positive)) | ||
| .withSlot0( | ||
| new Slot0Configs().withKS(0.099892).withKV(0.115).withKA(0.0020241).withKP(0.026743)) | ||
| .withCurrentLimits( | ||
| new CurrentLimitsConfigs() | ||
| .withStatorCurrentLimit(Amps.of(70)) | ||
| .withSupplyCurrentLimit(50)); | ||
|
|
||
| // Reminder: this is the upper left shooter motor when the robot is viewed from behind. | ||
| public static final TalonFXConfiguration UPPER_LEFT_SHOOTER_MOTOR_CONFIG = | ||
| new TalonFXConfiguration() | ||
| .withMotorOutput( | ||
| new MotorOutputConfigs().withInverted(InvertedValue.CounterClockwise_Positive)) | ||
|
|
@@ -59,9 +101,11 @@ public class ShooterConstants { | |
| .withStatorCurrentLimit(Amps.of(80)) | ||
| .withSupplyCurrentLimit(60)); | ||
|
|
||
| public static final TalonFXConfiguration FOLLOWER_SHOOTER_MOTOR_CONFIG = | ||
| // Reminder: this is the lower left shooter motor. | ||
| public static final TalonFXConfiguration LOWER_LEFT_SHOOTER_MOTOR_CONFIG = | ||
| new TalonFXConfiguration() | ||
| .withMotorOutput(new MotorOutputConfigs().withInverted(InvertedValue.Clockwise_Positive)) | ||
| .withMotorOutput( | ||
| new MotorOutputConfigs().withInverted(InvertedValue.CounterClockwise_Positive)) | ||
| .withSlot0( | ||
| new Slot0Configs().withKS(0.099892).withKV(0.115).withKA(0.0020241).withKP(0.026743)) | ||
| .withCurrentLimits( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,17 +8,33 @@ public interface ShooterIO { | |
|
|
||
| @AutoLog | ||
| class ShooterIOInputs { | ||
| public double mainShooterMotorVoltageVolts = 0; | ||
| public double mainShooterMotorAngleRotations = 0; | ||
| public double mainShooterMotorRotPerSec = 0; | ||
| public double mainShooterMotorStatorCurrentAmps = 0; | ||
| public double mainShooterMotorSupplyCurrentAmps = 0; | ||
| public double mainShooterSetpointRotsPerSec = 0; | ||
|
|
||
| public double followerShooterMotorVoltageVolts = 0; | ||
| public double followerShooterMotorRotPerSec = 0; | ||
| public double followerShooterMotorStatorCurrentAmps = 0; | ||
| public double followerShooterMotorSupplyCurrentAmps = 0; | ||
| public double shooterMotor1VoltageVolts = 0; | ||
| public double shooterMotor1AngleRotations = 0; | ||
| public double shooterMotor1RotPerSec = 0; | ||
| public double shooterMotor1SupplyCurrentAmps = 0; | ||
| public double shooterMotor1StatorCurrentAmps = 0; | ||
| public double shooter1SetpointRotsPerSec = 0; | ||
|
|
||
| public double shooterMotor2VoltageVolts = 0; | ||
| public double shooterMotor2AngleRotations = 0; | ||
| public double shooterMotor2RotPerSec = 0; | ||
| public double shooterMotor2SupplyCurrentAmps = 0; | ||
| public double shooterMotor2StatorCurrentAmps = 0; | ||
| public double shooter2SetpointRotsPerSec = 0; | ||
|
|
||
| public double shooterMotor3VoltageVolts = 0; | ||
| public double shooterMotor3AngleRotations = 0; | ||
| public double shooterMotor3RotPerSec = 0; | ||
| public double shooterMotor3SupplyCurrentAmps = 0; | ||
| public double shooterMotor3StatorCurrentAmps = 0; | ||
| public double shooter3SetpointRotsPerSec = 0; | ||
|
|
||
| public double shooterMotor4VoltageVolts = 0; | ||
| public double shooterMotor4AngleRotations = 0; | ||
| public double shooterMotor4RotPerSec = 0; | ||
| public double shooterMotor4SupplyCurrentAmps = 0; | ||
| public double shooterMotor4StatorCurrentAmps = 0; | ||
| public double shooter4SetpointRotsPerSec = 0; | ||
|
Comment on lines
+11
to
+37
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More descriptive names here too please. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More descriptive name here (i.e. UPPER_KICKER_MOTOR_CONFIG).