Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
774423b
added centering motor statussignals to refreshall call
LewisSeiden Feb 26, 2024
a5901d3
added stator current logging to swerve
LewisSeiden Feb 27, 2024
a38795e
added supply current logging to shooter
LewisSeiden Feb 27, 2024
9ecc9a7
Merge branch 'log-centering-motor-data' into supply-current-logging
LewisSeiden Feb 27, 2024
9d848f8
add supply current to intake
LewisSeiden Feb 27, 2024
1149b9c
added feeder supply current logging
LewisSeiden Feb 27, 2024
fc18614
added elevator supply and follower logging
LewisSeiden Feb 27, 2024
fc33e99
added carriage supply current logging
LewisSeiden Feb 27, 2024
53d8a1f
standardize on getValueAsDouble
LewisSeiden Feb 27, 2024
6860eb6
Merge branch 'main' into supply-current-logging
LewisSeiden Feb 27, 2024
c894f14
run spotless
Feb 27, 2024
c832c9a
added TalonFXLogger
LewisSeiden Feb 28, 2024
e8a8521
Merge branch 'main' into supply-current-logging
LewisSeiden Feb 28, 2024
fe923b6
refactor swerve to use talonfxlogger
LewisSeiden Feb 28, 2024
0165ef4
run spotless
LewisSeiden Feb 28, 2024
699f2c7
Merge branch 'main' into supply-current-logging
LewisSeiden Mar 17, 2024
2250141
additional merge fixes
LewisSeiden Mar 17, 2024
7d01e14
run spotless
Mar 17, 2024
7ef4cb3
refactor shooter to use talonfx logger
LewisSeiden Mar 17, 2024
e1ac136
make intake use talonfxlogger
LewisSeiden Mar 17, 2024
6a8aa1f
refactor feeder and elevator
LewisSeiden Mar 17, 2024
3e54f14
refactor carriage
LewisSeiden Mar 17, 2024
efac18e
check for license faults
LewisSeiden Mar 17, 2024
f511a58
independantly configure fault update rate
LewisSeiden Mar 17, 2024
f402913
Merge branch 'supply-current-logging' of https://github.com/Highlande…
LewisSeiden Mar 18, 2024
6de99c0
run spotless
Mar 18, 2024
93c711f
add talonfxfaultmanager
LewisSeiden Mar 18, 2024
2b23749
show fault on leds while disabled
LewisSeiden Mar 19, 2024
13b2f76
Merge branch 'supply-current-logging' of https://github.com/Highlande…
LewisSeiden Mar 19, 2024
fedf6b9
run spotless
Mar 19, 2024
2b78aa2
Merge branch 'main' into supply-current-logging
LewisSeiden Apr 2, 2024
c2d694e
fix logger migration for accel ff
LewisSeiden Apr 3, 2024
8d7ee6e
add statussignal errorcode to talonfxlog
LewisSeiden Apr 3, 2024
a3fe0e0
store errorcode as statuscode
LewisSeiden Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@
],
"robotJoysticks": [
{
"guid": "Keyboard0",
"name": "Keyboard"
"guid": "78696e70757401000000000000000000",
"name": "Keyboard",
"useGamepad": true
},
{
"useGamepad": true
Expand Down
25 changes: 23 additions & 2 deletions simgui.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,41 @@
"/AdvantageKit/RealOutputs/Shooter/Mechanism2d": "Mechanism2d",
"/FMSInfo": "FMSInfo",
"/SmartDashboard/Auto Chooser": "String Chooser",
"/SmartDashboard/Blacklist All": "Command",
"/SmartDashboard/Blacklist Note": "Command",
"/SmartDashboard/Dynamic Auto": "Command",
"/SmartDashboard/Dynamic Demo": "Command",
"/SmartDashboard/Note Picker": "String Chooser",
"/SmartDashboard/Note To Note": "Command",
"/SmartDashboard/Note To Shooting": "Command",
"/SmartDashboard/Run Elevator Sysid": "Command",
"/SmartDashboard/Run Flywheel Sysid": "Command",
"/SmartDashboard/Run Pivot Sysid": "Command",
"/SmartDashboard/Run Swerve Azimuth Sysid": "Command",
"/SmartDashboard/Run Swerve Drive Sysid": "Command",
"/SmartDashboard/SendableChooser[0]": "String Chooser",
"/SmartDashboard/Set robot pose center": "Command",
"/SmartDashboard/Shoot To Note": "Command",
"/SmartDashboard/Shooter shoot": "Command",
"/SmartDashboard/Start To Note": "Command",
"/SmartDashboard/Update Note": "Command",
"/SmartDashboard/VisionSystemSim-Left Camera Sim System/Sim Field": "Field2d",
"/SmartDashboard/VisionSystemSim-Left Camera/Sim Field": "Field2d",
"/SmartDashboard/VisionSystemSim-Left_Camera/Sim Field": "Field2d",
"/SmartDashboard/VisionSystemSim-Right Camera Sim System/Sim Field": "Field2d",
"/SmartDashboard/VisionSystemSim-Right Camera/Sim Field": "Field2d",
"/SmartDashboard/VisionSystemSim-Right_Camera/Sim Field": "Field2d",
"/SmartDashboard/Zero shooter": "Command",
"/SmartDashboard/manual zero shooter": "Command"
"/SmartDashboard/Whitelist All": "Command",
"/SmartDashboard/Whitelist Note": "Command",
"/SmartDashboard/gleeb": "Command",
"/SmartDashboard/gloob": "Command"
},
"windows": {
"/SmartDashboard/Auto Chooser": {
"window": {
"visible": true
}
}
}
},
"NetworkTables": {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import frc.robot.subsystems.swerve.SwerveSubsystem.AutoAimStates;
import frc.robot.utils.CommandXboxControllerSubsystem;
import frc.robot.utils.autoaim.AutoAim;
import frc.robot.utils.logging.TalonFXFaultManager;
import java.util.List;
import java.util.function.DoubleSupplier;
import org.littletonrobotics.junction.LogFileUtil;
Expand Down Expand Up @@ -213,7 +214,9 @@ public void robotInit() {
shooter.setDefaultCommand(shooter.runFlywheelsCmd(() -> 0.0, () -> 0.0));
leds.setDefaultCommand(
leds.defaultStateDisplayCmd(
() -> DriverStation.isEnabled(), () -> currentTarget == Target.SPEAKER));
() -> DriverStation.isEnabled(),
() -> currentTarget == Target.SPEAKER,
() -> TalonFXFaultManager.getInstance().isOk()));

controller.setDefaultCommand(controller.rumbleCmd(0.0, 0.0));
operator.setDefaultCommand(operator.rumbleCmd(0.0, 0.0));
Expand Down Expand Up @@ -401,8 +404,6 @@ public void robotInit() {
SmartDashboard.putData("Shooter shoot", shootWithDashboard());
SmartDashboard.putData("Run Swerve Azimuth Sysid", swerve.runModuleSteerCharacterizationCmd());
SmartDashboard.putData("Run Swerve Drive Sysid", swerve.runDriveCharacterizationCmd());
SmartDashboard.putData("Run Elevator Sysid", elevator.runSysidCmd());
SmartDashboard.putData("Run Pivot Sysid", shooter.runPivotSysidCmd());
SmartDashboard.putData("Run Flywheel Sysid", shooter.runFlywheelSysidCmd());
SmartDashboard.putData(
"manual zero shooter",
Expand All @@ -412,6 +413,8 @@ public void robotInit() {
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
// Update fault checker
TalonFXFaultManager.getInstance().periodic();
// Update ascope mechanism visualization
Logger.recordOutput(
"Mechanism Poses",
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/frc/robot/subsystems/carriage/CarriageIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

package frc.robot.subsystems.carriage;

import frc.robot.utils.logging.TalonFXLogger.TalonFXLog;
import org.littletonrobotics.junction.AutoLog;

public interface CarriageIO {
@AutoLog
public static class CarriageIOInputs {
public double velocityRotationsPerSecond = 0.0;
public double appliedVolts = 0.0;
public double[] currentAmps = new double[] {};
public double[] temperatureCelsius = new double[] {};
// Not in cad as of 1/28 but requested
public TalonFXLog carriage = new TalonFXLog(0, 0, 0, 0, 0, 0);
public boolean beambreak = false;
}

Expand Down
22 changes: 6 additions & 16 deletions src/main/java/frc/robot/subsystems/carriage/CarriageIOReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,22 @@

package frc.robot.subsystems.carriage;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.VoltageOut;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.InvertedValue;
import frc.robot.utils.components.InvertedDigitalInput;
import frc.robot.utils.logging.TalonFXLogger;

/** Create a CarriageIO that uses a real TalonFX. */
public class CarriageIOReal implements CarriageIO {
final TalonFX motor = new TalonFX(18, "canivore");
private final TalonFX motor = new TalonFX(18, "canivore");

final InvertedDigitalInput beambreak = new InvertedDigitalInput(2);
private final InvertedDigitalInput beambreak = new InvertedDigitalInput(2);

final VoltageOut voltageOut = new VoltageOut(0.0).withEnableFOC(true);
private final VoltageOut voltageOut = new VoltageOut(0.0).withEnableFOC(true);

final StatusSignal<Double> velocity = motor.getVelocity();
final StatusSignal<Double> voltage = motor.getMotorVoltage();
final StatusSignal<Double> amperage = motor.getStatorCurrent();
final StatusSignal<Double> temp = motor.getDeviceTemp();
private final TalonFXLogger logger = new TalonFXLogger(motor);

public CarriageIOReal() {
var config = new TalonFXConfiguration();
Expand All @@ -34,18 +30,12 @@ public CarriageIOReal() {
config.CurrentLimits.SupplyCurrentLimitEnable = true;

motor.getConfigurator().apply(config);
BaseStatusSignal.setUpdateFrequencyForAll(50.0, velocity, voltage, amperage, temp);
motor.optimizeBusUtilization();
}

/** Updates the set of loggable inputs. */
@Override
public void updateInputs(final CarriageIOInputsAutoLogged inputs) {
BaseStatusSignal.refreshAll(velocity, voltage, amperage, temp);
inputs.velocityRotationsPerSecond = velocity.getValueAsDouble();
inputs.appliedVolts = voltage.getValueAsDouble();
inputs.currentAmps = new double[] {amperage.getValueAsDouble()};
inputs.temperatureCelsius = new double[] {temp.getValueAsDouble()};
inputs.carriage = logger.update();

inputs.beambreak = beambreak.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.utils.logging.TalonFXFaultManager;
import org.littletonrobotics.junction.Logger;

/** Drainpipe style amp/trap mechanism on the elevator */
Expand All @@ -25,6 +26,7 @@ public CarriageSubsystem(CarriageIO io) {
public void periodic() {
io.updateInputs(inputs);
Logger.processInputs("Carriage", inputs);
TalonFXFaultManager.getInstance().addLog("Carriage", inputs.carriage);
}

/** Run the carriage roller at the specified voltage */
Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/subsystems/climber/ClimberIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public interface ClimberIO {
@AutoLog
public static class ClimberIOInputs {
// Not refactored bc removed
public double climberVelocityRotationsPerSec = 0.0;
public double climberAppliedVolts = 0.0;
public double climberCurrentAmps = 0.0;
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/frc/robot/subsystems/elevator/ElevatorIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

package frc.robot.subsystems.elevator;

import frc.robot.utils.logging.TalonFXLogger.TalonFXLog;
import org.littletonrobotics.junction.AutoLog;

public interface ElevatorIO {
@AutoLog
public static class ElevatorIOInputs {
public double elevatorPositionMeters = 0.0;
public double elevatorVelocityMetersPerSec = 0.0;
public double elevatorAppliedVolts = 0.0;
public double[] elevatorCurrentAmps = new double[] {};
public double[] elevatorTempCelsius = new double[] {};
public TalonFXLog leader;
public TalonFXLog follower;
}

public void updateInputs(final ElevatorIOInputsAutoLogged inputs);
Expand Down
23 changes: 6 additions & 17 deletions src/main/java/frc/robot/subsystems/elevator/ElevatorIOReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package frc.robot.subsystems.elevator;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.Follower;
import com.ctre.phoenix6.controls.MotionMagicVoltage;
Expand All @@ -15,6 +13,7 @@
import com.ctre.phoenix6.signals.InvertedValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.wpilibj.Servo;
import frc.robot.utils.logging.TalonFXLogger;

/** Elevator IO using TalonFXs. */
public class ElevatorIOReal implements ElevatorIO {
Expand All @@ -27,11 +26,9 @@ public class ElevatorIOReal implements ElevatorIO {
private final MotionMagicVoltage positionVoltage =
new MotionMagicVoltage(0.0).withEnableFOC(true);

private final StatusSignal<Double> position = motor.getPosition();
private final StatusSignal<Double> velocity = motor.getVelocity();
private final StatusSignal<Double> voltage = motor.getMotorVoltage();
private final StatusSignal<Double> current = motor.getStatorCurrent();
private final StatusSignal<Double> temp = motor.getDeviceTemp();
private final TalonFXLogger leaderLogger = new TalonFXLogger(motor);

private final TalonFXLogger followerLogger = new TalonFXLogger(follower);

public ElevatorIOReal() {
var config = new TalonFXConfiguration();
Expand Down Expand Up @@ -64,20 +61,12 @@ public ElevatorIOReal() {
motor.setPosition(0.0); // Assume we boot 0ed
follower.getConfigurator().apply(config);
follower.setControl(new Follower(motor.getDeviceID(), true));

BaseStatusSignal.setUpdateFrequencyForAll(50.0, position, velocity, voltage, current, temp);
motor.optimizeBusUtilization();
follower.optimizeBusUtilization();
}

@Override
public void updateInputs(final ElevatorIOInputsAutoLogged inputs) {
BaseStatusSignal.refreshAll(position, velocity, voltage, current, temp);
inputs.elevatorPositionMeters = position.getValueAsDouble();
inputs.elevatorVelocityMetersPerSec = velocity.getValueAsDouble();
inputs.elevatorAppliedVolts = voltage.getValueAsDouble();
inputs.elevatorCurrentAmps = new double[] {current.getValueAsDouble()};
inputs.elevatorTempCelsius = new double[] {temp.getValueAsDouble()};
inputs.leader = leaderLogger.update();
inputs.follower = followerLogger.update();
}

@Override
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/frc/robot/subsystems/elevator/ElevatorIOSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.simulation.ElevatorSim;
import frc.robot.utils.logging.TalonFXLogger.TalonFXLog;

/** WPILib physics model based elevator sim. */
public class ElevatorIOSim implements ElevatorIO {
Expand All @@ -36,11 +37,14 @@ public void updateInputs(final ElevatorIOInputsAutoLogged inputs) {
stop();
}
physicsSim.update(0.020);
inputs.elevatorPositionMeters = physicsSim.getPositionMeters();
inputs.elevatorVelocityMetersPerSec = physicsSim.getVelocityMetersPerSecond();
inputs.elevatorAppliedVolts = volts;
inputs.elevatorCurrentAmps = new double[] {physicsSim.getCurrentDrawAmps()};
inputs.elevatorTempCelsius = new double[] {20.0};
inputs.leader =
new TalonFXLog(
volts,
physicsSim.getCurrentDrawAmps(),
physicsSim.getCurrentDrawAmps(),
0.0,
physicsSim.getPositionMeters(),
physicsSim.getVelocityMetersPerSecond());
}

@Override
Expand Down
39 changes: 6 additions & 33 deletions src/main/java/frc/robot/subsystems/elevator/ElevatorSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction;
import frc.robot.utils.logging.TalonFXFaultManager;
import java.util.function.DoubleSupplier;
import org.littletonrobotics.junction.Logger;

Expand Down Expand Up @@ -77,8 +77,10 @@ public ElevatorSubsystem(ElevatorIO io) {
public void periodic() {
io.updateInputs(inputs);
Logger.processInputs("Elevator", inputs);
TalonFXFaultManager.getInstance().addLog("Elevator Leader", inputs.leader);
TalonFXFaultManager.getInstance().addLog("Elevator Follower", inputs.follower);

carriage.setLength(inputs.elevatorPositionMeters);
carriage.setLength(inputs.leader.position);
Logger.recordOutput("Elevator/Mechanism2d", mech2d);

Logger.recordOutput("Elevator/Carriage Pose", getCarriagePose());
Expand Down Expand Up @@ -109,40 +111,11 @@ public Command unlockClimb() {

public Command runCurrentZeroing() {
return this.run(() -> io.setVoltage(-1.0))
.until(() -> inputs.elevatorCurrentAmps[0] > 40.0)
.until(() -> inputs.leader.statorCurrentAmps > 40.0)
.finallyDo(() -> io.resetEncoder(0.0))
.beforeStarting(() -> io.setLockServoRotation(0.2));
}

public Command runSysidCmd() {
return Commands.sequence(
runCurrentZeroing(),
this.runOnce(() -> SignalLogger.start()),
// Stop when we get close to max to avoid hitting hard stop
elevatorRoutine
.quasistatic(Direction.kForward)
.until(() -> inputs.elevatorPositionMeters > MAX_EXTENSION_METERS - 0.2),
this.runOnce(() -> io.setVoltage(0.0)),
Commands.waitSeconds(1.0),
// Stop when we get close to max to avoid hitting hard stop
elevatorRoutine
.quasistatic(Direction.kReverse)
.until(() -> inputs.elevatorPositionMeters < 0.2),
this.runOnce(() -> io.setVoltage(0.0)),
Commands.waitSeconds(1.0),
// Stop when we get close to max to avoid hitting hard stop
elevatorRoutine
.dynamic(Direction.kForward)
.until(() -> inputs.elevatorPositionMeters > MAX_EXTENSION_METERS - 0.2),
this.runOnce(() -> io.setVoltage(0.0)),
Commands.waitSeconds(1.0),
// Stop when we get close to max to avoid hitting hard stop
elevatorRoutine
.dynamic(Direction.kReverse)
.until(() -> inputs.elevatorPositionMeters < 0.2),
this.runOnce(() -> SignalLogger.stop()));
}

public Pose3d getCarriagePose() {
return new Pose3d(
Units.inchesToMeters(4.5) + carriage.getLength() * ELEVATOR_ANGLE.getCos(),
Expand All @@ -162,6 +135,6 @@ public Pose3d getFirstStagePose() {
}

public double getExtensionMeters() {
return inputs.elevatorPositionMeters;
return inputs.leader.position;
}
}
6 changes: 2 additions & 4 deletions src/main/java/frc/robot/subsystems/feeder/FeederIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

package frc.robot.subsystems.feeder;

import frc.robot.utils.logging.TalonFXLogger.TalonFXLog;
import org.littletonrobotics.junction.AutoLog;

public interface FeederIO {
@AutoLog
public static class FeederIOInputs {
public double feederVelocityRotationsPerSec = 0.0;
public double feederAppliedVolts = 0.0;
public double feederCurrentAmps = 0.0;
public double feederTempC = 0.0;
public TalonFXLog feeder = new TalonFXLog(0, 0, 0, 0, 0, 0);

public boolean firstBeambreak = false;
public boolean lastBeambreak = false;
Expand Down
Loading