Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 0 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ allprojects {
}
}

// Set this to the latest version of StuyLib.
// You can check here: https://github.com/StuyPulse/StuyLib/releases.
final String STUYLIB_VERSION = '2026.1.1-SNAPSHOT'

def ROBOT_MAIN_CLASS = "com.stuypulse.robot.Main"

sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -77,8 +73,6 @@ dependencies {
simulationRelease wpi.sim.enableRelease()

testImplementation 'junit:junit:4.13.1'

implementation "com.github.StuyPulse:StuyLib:${STUYLIB_VERSION}";
}

// Simulation configuration (e.g. environment variables).
Expand All @@ -97,7 +91,6 @@ spotless {
endWithNewline()

importOrder(
'com.stuypulse.stuylib',
'com.stuypulse.constants',
'com.stuypulse.subsystems',
'com.stuypulse.commands',
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/stuypulse/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@

import com.stuypulse.robot.commands.auton.DoNothingAuton;
import com.stuypulse.robot.constants.Ports;
import com.stuypulse.stuylib.input.Gamepad;
import com.stuypulse.stuylib.input.gamepads.AutoGamepad;

import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;

public class RobotContainer {

// Gamepads
public final Gamepad driver = new AutoGamepad(Ports.Gamepad.DRIVER);
public final Gamepad operator = new AutoGamepad(Ports.Gamepad.OPERATOR);
public final CommandXboxController driver = new CommandXboxController(Ports.Gamepad.DRIVER);
public final CommandXboxController operator = new CommandXboxController(Ports.Gamepad.OPERATOR);

// Subsystem

Expand Down
199 changes: 193 additions & 6 deletions src/main/java/com/stuypulse/robot/constants/Motors.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.stuypulse.robot.constants;

import com.ctre.phoenix6.configs.ClosedLoopGeneralConfigs;
import com.ctre.phoenix6.configs.ClosedLoopRampsConfigs;
import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
import com.ctre.phoenix6.configs.FeedbackConfigs;
Expand All @@ -14,12 +15,18 @@
import com.ctre.phoenix6.configs.Slot0Configs;
import com.ctre.phoenix6.configs.Slot1Configs;
import com.ctre.phoenix6.configs.Slot2Configs;
import com.ctre.phoenix6.configs.SlotConfigs;
import com.ctre.phoenix6.configs.SoftwareLimitSwitchConfigs;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.configs.TorqueCurrentConfigs;
import com.ctre.phoenix6.configs.VoltageConfigs;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.FeedbackSensorSourceValue;
import com.ctre.phoenix6.signals.GainSchedBehaviorValue;
import com.ctre.phoenix6.signals.GravityTypeValue;
import com.ctre.phoenix6.signals.InvertedValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
import com.ctre.phoenix6.signals.StaticFeedforwardSignValue;

/*-
* File containing all of the configurations that different motors require.
Expand All @@ -31,9 +38,11 @@
* - The Open Loop Ramp Rate
*/
public interface Motors {

/** Classes to store all of the values a motor needs */

/**
* Wrapper class for configuring TalonFX motors
*/
public static class TalonFXConfig {
private final TalonFXConfiguration configuration = new TalonFXConfiguration();
private final Slot0Configs slot0Configs = new Slot0Configs();
Expand All @@ -45,12 +54,79 @@ public static class TalonFXConfig {
private final CurrentLimitsConfigs currentLimitsConfigs = new CurrentLimitsConfigs();
private final FeedbackConfigs feedbackConfigs = new FeedbackConfigs();
private final MotionMagicConfigs motionMagicConfigs = new MotionMagicConfigs();
private final SoftwareLimitSwitchConfigs softwareLimitSwitchConfigs = new SoftwareLimitSwitchConfigs();
private final ClosedLoopGeneralConfigs closedLoopGeneralConfigs = new ClosedLoopGeneralConfigs();
private final VoltageConfigs voltageConfigs = new VoltageConfigs();
private final TorqueCurrentConfigs torqueCurrentConfigs = new TorqueCurrentConfigs();

private final double[] lastKP = new double[3];
private final double[] lastKI = new double[3];
private final double[] lastKD = new double[3];
private final double[] lastKS = new double[3];
private final double[] lastKV = new double[3];
private final double[] lastKA = new double[3];

public void configure(TalonFX motor) {
TalonFXConfiguration defaultConfig = new TalonFXConfiguration();
motor.getConfigurator().apply(defaultConfig);

motor.getConfigurator().apply(configuration);
}

// SLOT 0 CONFIGS
public TalonFXConfiguration getConfiguration() {
return this.configuration;
}

public void updateGainsConfig(TalonFX motor, int slot, double kP, double kI, double kD, double kS, double kV, double kA) {
if (slot != 0 && slot != 1 && slot != 2) {
return;
}

boolean changed =
kP != lastKP[slot] ||
kI != lastKI[slot] ||
kD != lastKD[slot] ||
kS != lastKS[slot] ||
kV != lastKV[slot] ||
kA != lastKA[slot];

if (!changed) {
return;
}

SlotConfigs gainConfig = new SlotConfigs()
.withKP(kP)
.withKI(kI)
.withKD(kD)
.withKS(kS)
.withKV(kV)
.withKA(kA);

gainConfig.SlotNumber = slot;

motor.getConfigurator().apply(gainConfig);

lastKP[slot] = kP;
lastKI[slot] = kI;
lastKD[slot] = kD;
lastKS[slot] = kS;
lastKV[slot] = kV;
lastKA[slot] = kA;

switch (slot) {
case 0:
motor.getConfigurator().refresh(this.getConfiguration().Slot0);
break;
case 1:
motor.getConfigurator().refresh(this.getConfiguration().Slot1);
break;
case 2:
motor.getConfigurator().refresh(this.getConfiguration().Slot2);
break;
}
}

// SLOT CONFIGS

public TalonFXConfig withPIDConstants(double kP, double kI, double kD, int slot) {
switch (slot) {
Expand All @@ -77,7 +153,7 @@ public TalonFXConfig withPIDConstants(double kP, double kI, double kD, int slot)
}

public TalonFXConfig withFFConstants(double kS, double kV, double kA, int slot) {
return withFFConstants(kS, kV, kA, 0, slot);
return withFFConstants(kS, kV, kA, 0.0, slot);
}

public TalonFXConfig withFFConstants(double kS, double kV, double kA, double kG, int slot) {
Expand Down Expand Up @@ -107,6 +183,25 @@ public TalonFXConfig withFFConstants(double kS, double kV, double kA, double kG,
return this;
}

public TalonFXConfig withStaticFeedforwardSign(StaticFeedforwardSignValue staticFeedforwardSign, int slot) {
switch (slot) {
case 0:
slot0Configs.StaticFeedforwardSign = staticFeedforwardSign;
configuration.withSlot0(slot0Configs);
break;
case 1:
slot1Configs.StaticFeedforwardSign = staticFeedforwardSign;
configuration.withSlot1(slot1Configs);
break;
case 2:
slot2Configs.StaticFeedforwardSign = staticFeedforwardSign;
configuration.withSlot2(slot2Configs);
break;
}

return this;
}

public TalonFXConfig withGravityType(GravityTypeValue gravityType) {
slot0Configs.GravityType = gravityType;
slot1Configs.GravityType = gravityType;
Expand All @@ -119,6 +214,31 @@ public TalonFXConfig withGravityType(GravityTypeValue gravityType) {
return this;
}

public TalonFXConfig withGainSchedBehavior(GainSchedBehaviorValue value, double threshold, int slot) {
closedLoopGeneralConfigs.GainSchedErrorThreshold = threshold;
configuration.withClosedLoopGeneral(closedLoopGeneralConfigs);

switch(slot) {
case 0: {
slot0Configs.GainSchedBehavior = value;
configuration.withSlot0(slot0Configs);
}
break;
case 1: {
slot1Configs.GainSchedBehavior = value;
configuration.withSlot1(slot1Configs);
}
break;
case 2: {
slot2Configs.GainSchedBehavior = value;
configuration.withSlot2(slot2Configs);
}
break;
}

return this;
}

// MOTOR OUTPUT CONFIGS

public TalonFXConfig withInvertedValue(InvertedValue invertedValue) {
Expand All @@ -137,6 +257,14 @@ public TalonFXConfig withNeutralMode(NeutralModeValue neutralMode) {
return this;
}

public TalonFXConfig withVelocityTimeFilter(double filterInSeconds) {
feedbackConfigs.withVelocityFilterTimeConstant(filterInSeconds);

configuration.withFeedback(feedbackConfigs);

return this;
}

// RAMP RATE CONFIGS

public TalonFXConfig withRampRate(double rampRate) {
Expand All @@ -156,9 +284,9 @@ public TalonFXConfig withRampRate(double rampRate) {

// CURRENT LIMIT CONFIGS

public TalonFXConfig withCurrentLimitAmps(double currentLimitAmps) {
currentLimitsConfigs.StatorCurrentLimit = currentLimitAmps;
currentLimitsConfigs.StatorCurrentLimitEnable = true;
public TalonFXConfig withLowerLimitSupplyCurrent(double currentLowerLimitAmps, double time) {
currentLimitsConfigs.SupplyCurrentLowerLimit = currentLowerLimitAmps;
currentLimitsConfigs.SupplyCurrentLowerTime = time;

configuration.withCurrentLimits(currentLimitsConfigs);

Expand All @@ -174,6 +302,65 @@ public TalonFXConfig withSupplyCurrentLimitAmps(double currentLimitAmps) {
return this;
}

public TalonFXConfig withSupplyCurrentLimitEnabled(boolean enabled) {
currentLimitsConfigs.SupplyCurrentLimitEnable = enabled;

configuration.withCurrentLimits(currentLimitsConfigs);

return this;
}

public TalonFXConfig withStatorCurrentLimitAmps(double currentLimitAmps) {
currentLimitsConfigs.StatorCurrentLimit = currentLimitAmps;
currentLimitsConfigs.StatorCurrentLimitEnable = true;

configuration.withCurrentLimits(currentLimitsConfigs);

return this;
}

public TalonFXConfig withStatorCurrentLimitEnabled(boolean enabled) {
currentLimitsConfigs.StatorCurrentLimitEnable = enabled;

configuration.withCurrentLimits(currentLimitsConfigs);

return this;
}

public TalonFXConfig withTorqueCurrentLimits(double peakForwardTorqueCurrent, double peakReverseTorqueCurrent, double neutralTolerance) {
torqueCurrentConfigs.PeakForwardTorqueCurrent = peakForwardTorqueCurrent;
torqueCurrentConfigs.PeakReverseTorqueCurrent = peakReverseTorqueCurrent;
torqueCurrentConfigs.TorqueNeutralDeadband = neutralTolerance;

configuration.withTorqueCurrent(torqueCurrentConfigs);

return this;
}

// VOLTAGE LIMIT CONFIGS

public TalonFXConfig withVoltageLimits(double peakForwardVoltage, double peakReverseVoltage) {
voltageConfigs.PeakForwardVoltage = peakForwardVoltage;
voltageConfigs.PeakReverseVoltage = peakReverseVoltage;

configuration.withVoltage(voltageConfigs);

return this;
}

// SOFTWARE LIMIT CONFIGS

public TalonFXConfig withSoftLimits(boolean forwardEnable, boolean reverseEnable, double forwardThreshold, double reverseThreshold) {
softwareLimitSwitchConfigs.ForwardSoftLimitEnable = forwardEnable;
softwareLimitSwitchConfigs.ReverseSoftLimitEnable = reverseEnable;
softwareLimitSwitchConfigs.ForwardSoftLimitThreshold = forwardThreshold;
softwareLimitSwitchConfigs.ReverseSoftLimitThreshold = reverseThreshold;

configuration.withSoftwareLimitSwitch(softwareLimitSwitchConfigs);

return this;
}

// MOTION MAGIC CONFIGS

public TalonFXConfig withMotionProfile(double maxVelocity, double maxAcceleration) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/stuypulse/robot/constants/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

package com.stuypulse.robot.constants;

import com.stuypulse.stuylib.network.SmartBoolean;
import com.stuypulse.stuylib.network.SmartNumber;

/*-
* File containing tunable settings for every subsystem on the robot.
*
* We use StuyLib's SmartNumber / SmartBoolean in order to have tunable
* We use DogLog's tunables in order to have tunable
* values that we can edit on Shuffleboard.
*/
public interface Settings {}
20 changes: 20 additions & 0 deletions vendordeps/DogLog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"javaDependencies": [
{
"groupId": "com.github.jonahsnider",
"artifactId": "doglog",
"version": "2026.5.0"
}
],
"fileName": "DogLog.json",
"frcYear": "2026",
"jsonUrl": "https://doglog.dev/vendordep.json",
"name": "DogLog",
"jniDependencies": [],
"mavenUrls": [
"https://jitpack.io"
],
"cppDependencies": [],
"version": "2026.5.0",
"uuid": "65592ce1-2251-4a31-8e4b-2df20dacebe4"
}
Loading
Loading