Skip to content

Commit 5595d8e

Browse files
committed
Comments and NT name changes for tunables
1 parent be46051 commit 5595d8e

File tree

5 files changed

+86
-68
lines changed

5 files changed

+86
-68
lines changed

src/main/java/com/chaos131/ctre/ChaosCanCoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/** A TalonFX wrapper with automatic simulation support and helper functions. */
1313
public class ChaosCanCoder extends CANcoder {
1414
public final CANcoderConfiguration Configuration;
15-
15+
1616
/** Creates the new TalonFX wrapper WITHOUT simulation support. */
1717
public ChaosCanCoder(CanId canId, CanBusName canBus, CANcoderConfiguration config) {
1818
super(canId.id, canBus.name);

src/main/java/com/chaos131/ctre/ChaosCanCoderTuner.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66

77
import com.chaos131.util.DashboardNumber;
88
import com.ctre.phoenix6.configs.CANcoderConfiguration;
9+
import com.ctre.phoenix6.configs.MagnetSensorConfigs;
10+
import java.util.ArrayList;
11+
import java.util.List;
912
import java.util.function.BiConsumer;
1013

11-
/** This creates a class to easily tune TalonFXConfigs for 1 or more motors. */
14+
/** This creates a class to easily tune CANcoderConfiguration for 1 or more CANcoders. */
1215
public class ChaosCanCoderTuner {
1316
private String m_name;
1417
private ChaosCanCoder m_canCoder;
18+
private List<DashboardNumber> m_tunables =
19+
new ArrayList<>(); // Keep in list to prevent any garbage collection
1520

1621
/**
1722
* Creates a tuner for modifying numeric values of TalonFxConfigs.
@@ -24,6 +29,22 @@ public ChaosCanCoderTuner(String name, ChaosCanCoder canCoder) {
2429
m_canCoder = canCoder;
2530
}
2631

32+
/**
33+
* Creates tunables for the MagnetSensorConfigs number values
34+
*
35+
* @param initialConfig the starting MagnetSensorConfigs values
36+
*/
37+
public void tunableMagnetSensor(MagnetSensorConfigs initialConfig) {
38+
tunable(
39+
"DiscontinuityPoint_rotations",
40+
initialConfig.AbsoluteSensorDiscontinuityPoint,
41+
(config, newValue) -> config.MagnetSensor.AbsoluteSensorDiscontinuityPoint = newValue);
42+
tunable(
43+
"Offset_rotations",
44+
initialConfig.MagnetOffset,
45+
(config, newValue) -> config.MagnetSensor.MagnetOffset = newValue);
46+
}
47+
2748
/**
2849
* Creates a tunable value for the TalonFxConfiguration and will apply/burn the value to the motor
2950
* when it changes.
@@ -35,14 +56,17 @@ public ChaosCanCoderTuner(String name, ChaosCanCoder canCoder) {
3556
*/
3657
public DashboardNumber tunable(
3758
String valueName, double initialValue, BiConsumer<CANcoderConfiguration, Double> onUpdate) {
38-
return new DashboardNumber(
39-
"CANCoderConfig/" + m_name + "/" + valueName,
40-
initialValue,
41-
true,
42-
false,
43-
newValue -> {
44-
onUpdate.accept(m_canCoder.Configuration, newValue);
45-
m_canCoder.applyConfig();
46-
});
59+
DashboardNumber dsNumber =
60+
new DashboardNumber(
61+
"CANCoderConfig/" + m_name + "/" + valueName,
62+
initialValue,
63+
true,
64+
false,
65+
newValue -> {
66+
onUpdate.accept(m_canCoder.Configuration, newValue);
67+
m_canCoder.applyConfig();
68+
});
69+
m_tunables.add(dsNumber);
70+
return dsNumber;
4771
}
4872
}

src/main/java/com/chaos131/ctre/ChaosTalonFx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ChaosTalonFx(CanId canId, CanBusName canBus, TalonFXConfiguration config)
5050
m_isMainSimMotor = false;
5151
}
5252

53-
/** Creates the new TalonFX wrapper WITHOUT simulation support. */
53+
/** Creates the new TalonFX wrapper WITHOUT simulation support. */
5454
public ChaosTalonFx(CanId canId, CanBusName canBus) {
5555
this(canId, canBus, new TalonFXConfiguration());
5656
}

src/main/java/com/chaos131/ctre/ChaosTalonFxTuner.java

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.chaos131.util.DashboardNumber;
88
import com.ctre.phoenix6.configs.Slot0Configs;
99
import com.ctre.phoenix6.configs.TalonFXConfiguration;
10-
1110
import java.util.ArrayList;
1211
import java.util.List;
1312
import java.util.function.BiConsumer;
@@ -16,7 +15,8 @@
1615
public class ChaosTalonFxTuner {
1716
private String m_name;
1817
private ChaosTalonFx[] m_talons;
19-
private List<DashboardNumber> m_tunables = new ArrayList<>(); // Keep in list to prevent any garbage collection
18+
private List<DashboardNumber> m_tunables =
19+
new ArrayList<>(); // Keep in list to prevent any garbage collection
2020

2121
/**
2222
* Creates a tuner for modifying numeric values of TalonFxConfigs.
@@ -30,22 +30,18 @@ public ChaosTalonFxTuner(String name, ChaosTalonFx... talons) {
3030
}
3131

3232
/**
33-
* Creates a tunable value for the TalonFxConfiguration and will apply/burn the value to the motor
34-
* when it changes.
33+
* Creates tunables for the Slot0 number values
3534
*
36-
* @param valueName the name of the value (e.g., "SupplyCurrentLimit")
37-
* @param initialValue the value to start at (is not applied by default)
38-
* @param onUpdate the function to update the configuration
39-
* @return the Dashboard number
35+
* @param initialConfig the starting Slot0 values
4036
*/
4137
public void tunableSlot0(Slot0Configs initialConfig) {
42-
tunable("Slot0/kP", initialConfig.kP, (config, newValue) -> config.Slot0.kP = newValue);
43-
tunable("Slot0/kI", initialConfig.kI, (config, newValue) -> config.Slot0.kI = newValue);
44-
tunable("Slot0/kD", initialConfig.kD, (config, newValue) -> config.Slot0.kD = newValue);
45-
tunable("Slot0/kG", initialConfig.kG, (config, newValue) -> config.Slot0.kG = newValue);
46-
tunable("Slot0/kS", initialConfig.kS, (config, newValue) -> config.Slot0.kS = newValue);
47-
tunable("Slot0/kV", initialConfig.kV, (config, newValue) -> config.Slot0.kV = newValue);
48-
tunable("Slot0/kA", initialConfig.kA, (config, newValue) -> config.Slot0.kA = newValue);
38+
tunable("Slot0_kP", initialConfig.kP, (config, newValue) -> config.Slot0.kP = newValue);
39+
tunable("Slot0_kI", initialConfig.kI, (config, newValue) -> config.Slot0.kI = newValue);
40+
tunable("Slot0_kD", initialConfig.kD, (config, newValue) -> config.Slot0.kD = newValue);
41+
tunable("Slot0_kG", initialConfig.kG, (config, newValue) -> config.Slot0.kG = newValue);
42+
tunable("Slot0_kS", initialConfig.kS, (config, newValue) -> config.Slot0.kS = newValue);
43+
tunable("Slot0_kV", initialConfig.kV, (config, newValue) -> config.Slot0.kV = newValue);
44+
tunable("Slot0_kA", initialConfig.kA, (config, newValue) -> config.Slot0.kA = newValue);
4945
}
5046

5147
/**
@@ -59,17 +55,18 @@ public void tunableSlot0(Slot0Configs initialConfig) {
5955
*/
6056
public DashboardNumber tunable(
6157
String valueName, double initialValue, BiConsumer<TalonFXConfiguration, Double> onUpdate) {
62-
DashboardNumber dsNumber = new DashboardNumber(
63-
"TalonFxConfig/" + m_name + "/" + valueName,
64-
initialValue,
65-
true,
66-
false,
67-
newValue -> {
68-
for (ChaosTalonFx chaosTalonFx : m_talons) {
69-
onUpdate.accept(chaosTalonFx.Configuration, newValue);
70-
chaosTalonFx.applyConfig();
71-
}
72-
});
58+
DashboardNumber dsNumber =
59+
new DashboardNumber(
60+
"TalonFxConfig/" + m_name + "/" + valueName,
61+
initialValue,
62+
true,
63+
false,
64+
newValue -> {
65+
for (ChaosTalonFx chaosTalonFx : m_talons) {
66+
onUpdate.accept(chaosTalonFx.Configuration, newValue);
67+
chaosTalonFx.applyConfig();
68+
}
69+
});
7370
m_tunables.add(dsNumber);
7471
return dsNumber;
7572
}

src/main/java/com/chaos131/ctre/ChaosTalonFxsTuner.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
import com.chaos131.util.DashboardNumber;
88
import com.ctre.phoenix6.configs.Slot0Configs;
99
import com.ctre.phoenix6.configs.TalonFXSConfiguration;
10-
1110
import java.util.ArrayList;
1211
import java.util.List;
1312
import java.util.function.BiConsumer;
1413

15-
/** This creates a class to easily tune TalonFXConfigs for 1 or more motors. */
14+
/** This creates a class to easily tune TalonFXSConfigurations for 1 or more motors. */
1615
public class ChaosTalonFxsTuner {
1716
private String m_name;
1817
private ChaosTalonFxs[] m_talons;
19-
private List<DashboardNumber> m_tunables = new ArrayList<>(); // Keep in list to prevent any garbage collection
18+
private List<DashboardNumber> m_tunables =
19+
new ArrayList<>(); // Keep in list to prevent any garbage collection
2020

2121
/**
22-
* Creates a tuner for modifying numeric values of TalonFxConfigs.
22+
* Creates a tuner for modifying numeric values of TalonFXSConfigurations.
2323
*
2424
* @param name the name of the motor tuner
2525
* @param talons the list of talons to tune
@@ -30,27 +30,23 @@ public ChaosTalonFxsTuner(String name, ChaosTalonFxs... talons) {
3030
}
3131

3232
/**
33-
* Creates a tunable value for the TalonFxConfiguration and will apply/burn the value to the motor
34-
* when it changes.
33+
* Creates tunables for the Slot0 number values
3534
*
36-
* @param valueName the name of the value (e.g., "SupplyCurrentLimit")
37-
* @param initialValue the value to start at (is not applied by default)
38-
* @param onUpdate the function to update the configuration
39-
* @return the Dashboard number
35+
* @param initialConfig the starting Slot0 values
4036
*/
4137
public void tunableSlot0(Slot0Configs initialConfig) {
42-
tunable("Slot0/kP", initialConfig.kP, (config, newValue) -> config.Slot0.kP = newValue);
43-
tunable("Slot0/kI", initialConfig.kI, (config, newValue) -> config.Slot0.kI = newValue);
44-
tunable("Slot0/kD", initialConfig.kD, (config, newValue) -> config.Slot0.kD = newValue);
45-
tunable("Slot0/kG", initialConfig.kG, (config, newValue) -> config.Slot0.kG = newValue);
46-
tunable("Slot0/kS", initialConfig.kS, (config, newValue) -> config.Slot0.kS = newValue);
47-
tunable("Slot0/kV", initialConfig.kV, (config, newValue) -> config.Slot0.kV = newValue);
48-
tunable("Slot0/kA", initialConfig.kA, (config, newValue) -> config.Slot0.kA = newValue);
38+
tunable("Slot0_kP", initialConfig.kP, (config, newValue) -> config.Slot0.kP = newValue);
39+
tunable("Slot0_kI", initialConfig.kI, (config, newValue) -> config.Slot0.kI = newValue);
40+
tunable("Slot0_kD", initialConfig.kD, (config, newValue) -> config.Slot0.kD = newValue);
41+
tunable("Slot0_kG", initialConfig.kG, (config, newValue) -> config.Slot0.kG = newValue);
42+
tunable("Slot0_kS", initialConfig.kS, (config, newValue) -> config.Slot0.kS = newValue);
43+
tunable("Slot0_kV", initialConfig.kV, (config, newValue) -> config.Slot0.kV = newValue);
44+
tunable("Slot0_kA", initialConfig.kA, (config, newValue) -> config.Slot0.kA = newValue);
4945
}
5046

5147
/**
52-
* Creates a tunable value for the TalonFxConfiguration and will apply/burn the value to the motor
53-
* when it changes.
48+
* Creates a tunable value for the TalonFXSConfiguration and will apply/burn the value to the
49+
* motor when it changes.
5450
*
5551
* @param valueName the name of the value (e.g., "SupplyCurrentLimit")
5652
* @param initialValue the value to start at (is not applied by default)
@@ -59,17 +55,18 @@ public void tunableSlot0(Slot0Configs initialConfig) {
5955
*/
6056
public DashboardNumber tunable(
6157
String valueName, double initialValue, BiConsumer<TalonFXSConfiguration, Double> onUpdate) {
62-
DashboardNumber dsNumber = new DashboardNumber(
63-
"TalonFxConfig/" + m_name + "/" + valueName,
64-
initialValue,
65-
true,
66-
false,
67-
newValue -> {
68-
for (ChaosTalonFxs chaosTalonFxs : m_talons) {
69-
onUpdate.accept(chaosTalonFxs.Configuration, newValue);
70-
chaosTalonFxs.applyConfig();
71-
}
72-
});
58+
DashboardNumber dsNumber =
59+
new DashboardNumber(
60+
"TalonFxConfig/" + m_name + "/" + valueName,
61+
initialValue,
62+
true,
63+
false,
64+
newValue -> {
65+
for (ChaosTalonFxs chaosTalonFxs : m_talons) {
66+
onUpdate.accept(chaosTalonFxs.Configuration, newValue);
67+
chaosTalonFxs.applyConfig();
68+
}
69+
});
7370
m_tunables.add(dsNumber);
7471
return dsNumber;
7572
}

0 commit comments

Comments
 (0)