-
Notifications
You must be signed in to change notification settings - Fork 0
Subsystem/turret crt #45
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
Changes from all commits
90fb7db
aa15ead
28374d4
26fa5aa
19c911e
c061b9c
fe7905d
cc95d5f
64ae638
279ca07
fbcf671
02a7f5d
089974c
5be9bc7
64a033d
c79b655
3d9e313
2662d57
6639b34
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "name":"test", | ||
| "version":3, | ||
| "snapshot":{ | ||
| "waypoints":[], | ||
| "constraints":[], | ||
| "targetDt":0.05 | ||
| }, | ||
| "params":{ | ||
| "waypoints":[ | ||
| {"x":{"exp":"0.8321799635887146 m", "val":0.8321799635887146}, "y":{"exp":"0.7060884237289429 m", "val":0.7060884237289429}, "heading":{"exp":"3.141592653589793 rad", "val":3.141592653589793}, "intervals":40, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false}, | ||
| {"x":{"exp":"4.659694671630859 m", "val":4.659694671630859}, "y":{"exp":"0.6415539979934692 m", "val":0.6415539979934692}, "heading":{"exp":"0 deg", "val":0.0}, "intervals":40, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false}, | ||
| {"x":{"exp":"2.725978374481201 m", "val":2.725978374481201}, "y":{"exp":"4.064524173736572 m", "val":4.064524173736572}, "heading":{"exp":"-33.321136223151115 mrad", "val":-0.03332113622315112}, "intervals":40, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false}, | ||
| {"x":{"exp":"2.7410621643066406 m", "val":2.7410621643066406}, "y":{"exp":"5.301389694213867 m", "val":5.301389694213867}, "heading":{"exp":"0 deg", "val":0.0}, "intervals":40, "split":false, "fixTranslation":true, "fixHeading":true, "overrideIntervals":false}], | ||
| "constraints":[ | ||
| {"from":"first", "to":null, "data":{"type":"StopPoint", "props":{}}, "enabled":false}, | ||
| {"from":"last", "to":null, "data":{"type":"StopPoint", "props":{}}, "enabled":false}, | ||
| {"from":"first", "to":"last", "data":{"type":"KeepInRectangle", "props":{"x":{"exp":"0 m", "val":0.0}, "y":{"exp":"0 m", "val":0.0}, "w":{"exp":"16.541 m", "val":16.541}, "h":{"exp":"8.0692 m", "val":8.0692}}}, "enabled":false}], | ||
| "targetDt":{ | ||
| "exp":"0.05 s", | ||
| "val":0.05 | ||
| } | ||
| }, | ||
| "trajectory":{ | ||
| "config":null, | ||
| "sampleType":null, | ||
| "waypoints":[], | ||
| "samples":[], | ||
| "splits":[] | ||
| }, | ||
| "events":[] | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package frc.robot.components.cancoder; | ||
|
|
||
| import com.ctre.phoenix6.CANBus; | ||
| import com.ctre.phoenix6.configs.CANcoderConfiguration; | ||
| import com.ctre.phoenix6.sim.CANcoderSimState; | ||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
|
|
||
| public class CANcoderIOSim extends CANcoderIO { | ||
| private final CANcoderSimState sim; | ||
|
|
||
| private double positionRotations; | ||
|
|
||
| public CANcoderIOSim(int cancoderID, CANcoderConfiguration config, CANBus canbus) { | ||
| super(cancoderID, config, canbus); | ||
| this.sim = cancoder.getSimState(); | ||
| } | ||
|
|
||
| public void setSimValues(double positionRotations) { | ||
|
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. we might have to do the actual sim notifier thread but honestly i don't want to worry about that rn |
||
| this.positionRotations = positionRotations; | ||
| } | ||
|
|
||
| public void updateInputs(CANcoderIOInputs inputs) { | ||
| sim.setRawPosition(positionRotations); | ||
|
|
||
| inputs.cancoderPositionRotations = Rotation2d.fromRotations(positionRotations); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package frc.robot.subsystems.shooter; | ||
|
|
||
| import com.ctre.phoenix6.BaseStatusSignal; | ||
| import com.ctre.phoenix6.StatusSignal; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.controls.MotionMagicVoltage; | ||
| import com.ctre.phoenix6.controls.VoltageOut; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import com.ctre.phoenix6.signals.InvertedValue; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import edu.wpi.first.math.MathUtil; | ||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import edu.wpi.first.units.measure.Angle; | ||
| import edu.wpi.first.units.measure.AngularVelocity; | ||
| import edu.wpi.first.units.measure.Current; | ||
| import edu.wpi.first.units.measure.Temperature; | ||
| import edu.wpi.first.units.measure.Voltage; | ||
| import org.littletonrobotics.junction.AutoLog; | ||
| import org.littletonrobotics.junction.AutoLogOutput; | ||
|
|
||
| public class TurretIO { | ||
| public static double TURRET_GEAR_RATIO = (42.0 / 12.0) * (32.0 / 16.0) * (85.0 / 10.0); | ||
|
|
||
| public static double CANCODER_ONE_TO_TURRET_GEAR_RATIO = (24.0 / 32.0) * (10.0 / 85.0); | ||
|
|
||
| // idk | ||
| public static Rotation2d TURRET_MIN_ROTATIONS = Rotation2d.fromRotations(0.0); | ||
| public static Rotation2d TURRET_MAX_ROTATIONS = Rotation2d.fromRotations(0.8); | ||
|
|
||
| // todo ID? | ||
| protected final TalonFX motor = new TalonFX(40, "*"); | ||
|
|
||
| @AutoLog | ||
| public static class TurretIOInputs { | ||
| public double angularVelocityRotationsPerSec = 0.0; | ||
| public Rotation2d positionRotations = new Rotation2d(); | ||
| public double statorCurrentAmps = 0.0; | ||
| public double supplyCurrentAmp = 0.0; | ||
| public double voltage = 0.0; | ||
| public double tempCelsius = 0.0; | ||
| } | ||
|
|
||
| private final StatusSignal<AngularVelocity> angularVelocityRotationsPerSec = motor.getVelocity(); | ||
| private final StatusSignal<Angle> positionRotations = motor.getPosition(); | ||
| private final StatusSignal<Current> supplyCurrentAmps = motor.getSupplyCurrent(); | ||
| private final StatusSignal<Current> statorCurrentAmps = motor.getStatorCurrent(); | ||
| private final StatusSignal<Voltage> voltage = motor.getMotorVoltage(); | ||
| private final StatusSignal<Temperature> tempCelcius = motor.getDeviceTemp(); | ||
|
|
||
| private VoltageOut voltageOut = new VoltageOut(0.0).withEnableFOC(true); | ||
|
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. you need to also add the set voltage method but i'll just do it rn |
||
| private MotionMagicVoltage motionMagic = new MotionMagicVoltage(0.0); | ||
|
|
||
vivi-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // todo | ||
| private Rotation2d turretSetpoint = Rotation2d.kZero; | ||
|
|
||
| public TurretIO() { | ||
|
|
||
| final TalonFXConfiguration config = new TalonFXConfiguration(); | ||
|
|
||
| config.MotorOutput.NeutralMode = NeutralModeValue.Brake; | ||
| config.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; | ||
| config.Feedback.SensorToMechanismRatio = TURRET_GEAR_RATIO; | ||
| config.CurrentLimits.StatorCurrentLimit = 80.0; | ||
| config.CurrentLimits.StatorCurrentLimitEnable = true; | ||
| config.CurrentLimits.SupplyCurrentLimit = 60.0; | ||
|
|
||
| config.Slot0.kS = 0; | ||
| config.Slot0.kG = 0; | ||
| config.Slot0.kV = 0; | ||
| config.Slot0.kP = 0; | ||
| config.Slot0.kD = 0; | ||
|
|
||
| motor.getConfigurator().apply(config); | ||
|
|
||
| BaseStatusSignal.setUpdateFrequencyForAll( | ||
| 50.0, | ||
| angularVelocityRotationsPerSec, | ||
| positionRotations, | ||
| voltage, | ||
| statorCurrentAmps, | ||
| supplyCurrentAmps, | ||
| tempCelcius); | ||
| motor.optimizeBusUtilization(); | ||
| } | ||
|
|
||
| public void updateInputs(TurretIOInputs inputs) { | ||
| BaseStatusSignal.refreshAll( | ||
| positionRotations, | ||
| angularVelocityRotationsPerSec, | ||
| voltage, | ||
| statorCurrentAmps, | ||
| supplyCurrentAmps, | ||
| tempCelcius); | ||
|
|
||
| inputs.positionRotations = Rotation2d.fromRotations(positionRotations.getValueAsDouble()); | ||
| inputs.angularVelocityRotationsPerSec = angularVelocityRotationsPerSec.getValueAsDouble(); | ||
| inputs.voltage = voltage.getValueAsDouble(); | ||
| inputs.statorCurrentAmps = statorCurrentAmps.getValueAsDouble(); | ||
| inputs.supplyCurrentAmp = supplyCurrentAmps.getValueAsDouble(); | ||
| inputs.tempCelsius = tempCelcius.getValueAsDouble(); | ||
| } | ||
|
|
||
| public void setTurretPosition(Rotation2d positionAngle) { | ||
| turretSetpoint = positionAngle; | ||
| motor.setControl( | ||
| motionMagic.withPosition( | ||
| MathUtil.clamp( | ||
| positionAngle.getRotations(), | ||
| TURRET_MIN_ROTATIONS.getRotations(), | ||
| TURRET_MAX_ROTATIONS.getRotations()))); | ||
| } | ||
|
|
||
| public void resetTurretPosition(Rotation2d turretRotation) { | ||
| motor.setPosition(turretRotation.getRotations()); | ||
| } | ||
|
|
||
| @AutoLogOutput(key = "Shooter/Turret/Setpoint") | ||
| public Rotation2d getTurretSetpoint() { | ||
| return turretSetpoint; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.