diff --git a/docs/allclasses-index.html b/docs/allclasses-index.html index 28f6827..4ae75ce 100644 --- a/docs/allclasses-index.html +++ b/docs/allclasses-index.html @@ -1,11 +1,11 @@
- +ChassisSpeeds based of raw speeds desired in meters/second and heading in radians.private double(package private) com.ctre.phoenix.motorcontrol.can.WPI_TalonFX(package private) com.ctre.phoenix.motorcontrol.can.WPI_TalonFXprivate doubleprivate doubleprivate booleanprivate final com.ctre.phoenix.motorcontrol.can.TalonSRXConfigurationprivate final booleanprivate doubleprivate doublevoidconfigureIntegratedEncoder(double positionConversionFactor) configureCANStatusFrames(int CANStatus1) voidconfigurePIDF(PIDFConfig config) configureIntegratedEncoder(double positionConversionFactor) voidconfigurePIDF(PIDFConfig config) voidconfigurePIDWrapping(double minInput,
+void
+configurePIDWrapping(double minInput,
double maxInput)
-
+
Configure the PID wrapping for the position closed loop controller.
-double
-convertToNativeSensorUnits(double setpoint)
-
+double
+convertToNativeSensorUnits(double setpoint)
+
Convert the setpoint into native sensor units.
-void
-
-
+void
+
+
Configure the factory defaults.
-
-getMotor()
-
+
+getMotor()
+
Get the motor object from the module.
-double
-
-
-Get the position of the integrated encoder.
-
double
-
+
-Get the raw position.
+Get the position of the integrated encoder.
double
@@ -298,6 +313,13 @@ loadScripts(document, 'script');
+
+configuration
+private final com.ctre.phoenix.motorcontrol.can.TalonSRXConfiguration configuration
+Current TalonFX configuration.
+
+
+
absoluteEncoder
private final boolean absoluteEncoder
@@ -323,7 +345,21 @@ loadScripts(document, 'script');
positionConversionFactor
private double positionConversionFactor
-The position conversion factor.
+The position conversion factor to convert raw sensor units to Meters Per 100ms, or Ticks to Degrees.
+
+
+
+
+configChanged
+private boolean configChanged
+If the TalonFX configuration has changed.
+
+
+
+
+nominalVoltage
+private double nominalVoltage
+Nominal voltage default to use with feedforward.
@@ -414,7 +450,28 @@ loadScripts(document, 'script');
Specified by:
configureIntegratedEncoder in class SwerveMotor
Parameters:
-positionConversionFactor - The conversion factor to apply for position.
+positionConversionFactor - The conversion factor to apply for position.
+
+ Degrees:
+
+ 360 / (angleGearRatio * encoderTicksPerRotation)
+
+
+ Meters:
+
+ (Math.PI * wheelDiameter) / (driveGearRatio * encoderTicksPerRotation)
+
+
+
+
+
+
+configureCANStatusFrames
+public void configureCANStatusFrames(int CANStatus1)
+Set the CAN status frames.
+
+- Parameters:
+CANStatus1 - Applied Motor Output, Fault Information, Limit Switch Information
@@ -497,6 +554,35 @@ loadScripts(document, 'script');
+
+placeInAppropriate0To360Scope
+private double placeInAppropriate0To360Scope(double scopeReference,
+ double newAngle)
+Put an angle within the the 360 deg scope of a reference. For example, given a scope reference of 756 degrees,
+ assumes the full scope is (720-1080), and places an angle of 22 degrees into it, returning 742 deg.
+
+- Parameters:
+scopeReference - Current Angle (deg)
+newAngle - Target Angle (deg)
+- Returns:
+- Closest angle within scope (deg)
+
+
+
+
+
+convertToNativeSensorUnits
+public double convertToNativeSensorUnits(double setpoint)
+Convert the setpoint into native sensor units.
+
+- Parameters:
+setpoint - Setpoint to mutate. In meters per second or degrees.
+- Returns:
+- Setpoint as native sensor units. Encoder ticks per 100ms, or Encoder tick.
+
+
+
+
setReference
public void setReference(double setpoint,
@@ -520,18 +606,7 @@ loadScripts(document, 'script');
Specified by:
getVelocity in class SwerveMotor
Returns:
-velocity
-
-
-
-
-
-getRawPosition
-public double getRawPosition()
-Get the raw position.
-
-- Returns:
-- Position in meters or degrees.
+- velocity in Meters Per Second, or Degrees per Second.
@@ -627,35 +702,6 @@ loadScripts(document, 'script');
-
-
-placeInAppropriate0To360Scope
-private double placeInAppropriate0To360Scope(double scopeReference,
- double newAngle)
-Put an angle within the the 360 deg scope of a reference. For example, given a scope reference of 756 degrees,
- assumes the full scope is (720-1080), and places an angle of 22 degrees into it, returning 742 deg.
-
-- Parameters:
-scopeReference - Current Angle (deg)
-newAngle - Target Angle (deg)
-- Returns:
-- Closest angle within scope (deg)
-
-
-
-
-
-convertToNativeSensorUnits
-public double convertToNativeSensorUnits(double setpoint)
-Convert the setpoint into native sensor units.
-
-- Parameters:
-setpoint - Setpoint to mutate. In meters per second or degrees.
-- Returns:
-- Setpoint as native sensor units. Encoder ticks per 100ms, or Encoder tick.
-
-
-
diff --git a/docs/swervelib/motors/package-summary.html b/docs/swervelib/motors/package-summary.html
index 4bffce1..2c0f410 100644
--- a/docs/swervelib/motors/package-summary.html
+++ b/docs/swervelib/motors/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.motors
-
+
diff --git a/docs/swervelib/motors/package-tree.html b/docs/swervelib/motors/package-tree.html
index b293f6d..83c7083 100644
--- a/docs/swervelib/motors/package-tree.html
+++ b/docs/swervelib/motors/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.motors Class Hierarchy
-
+
diff --git a/docs/swervelib/package-summary.html b/docs/swervelib/package-summary.html
index 49994fd..3176bcf 100644
--- a/docs/swervelib/package-summary.html
+++ b/docs/swervelib/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib
-
+
diff --git a/docs/swervelib/package-tree.html b/docs/swervelib/package-tree.html
index 84f1471..bd8bce6 100644
--- a/docs/swervelib/package-tree.html
+++ b/docs/swervelib/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib Class Hierarchy
-
+
diff --git a/docs/swervelib/parser/PIDFConfig.html b/docs/swervelib/parser/PIDFConfig.html
index 7e28095..b0b5c62 100644
--- a/docs/swervelib/parser/PIDFConfig.html
+++ b/docs/swervelib/parser/PIDFConfig.html
@@ -1,11 +1,11 @@
-
+
PIDFConfig
-
+
@@ -102,28 +102,23 @@ loadScripts(document, 'script');
Feedforward value for PID.
double
-
+
-Feedforward scalar for PID applied dynamically.
-
-double
-
-
Integral Gain for PID.
-double
-
-
+double
+
+
Integral zone of the PID.
-
-
-
+
+
+
The PIDF output range.
-double
-
-
@@ -232,13 +227,6 @@ loadScripts(document, 'script');
-
-fscalar
-public double fscalar
-Feedforward scalar for PID applied dynamically.
-
-
-
iz
public double iz
diff --git a/docs/swervelib/parser/SwerveControllerConfiguration.html b/docs/swervelib/parser/SwerveControllerConfiguration.html
index 9c8135a..2eb6f47 100644
--- a/docs/swervelib/parser/SwerveControllerConfiguration.html
+++ b/docs/swervelib/parser/SwerveControllerConfiguration.html
@@ -1,11 +1,11 @@
-
+
SwerveControllerConfiguration
-
+
diff --git a/docs/swervelib/parser/SwerveDriveConfiguration.html b/docs/swervelib/parser/SwerveDriveConfiguration.html
index 75bc186..34c44db 100644
--- a/docs/swervelib/parser/SwerveDriveConfiguration.html
+++ b/docs/swervelib/parser/SwerveDriveConfiguration.html
@@ -1,11 +1,11 @@
-
+
SwerveDriveConfiguration
-
+
diff --git a/docs/swervelib/parser/SwerveModuleConfiguration.html b/docs/swervelib/parser/SwerveModuleConfiguration.html
index f1c7e27..e9504de 100644
--- a/docs/swervelib/parser/SwerveModuleConfiguration.html
+++ b/docs/swervelib/parser/SwerveModuleConfiguration.html
@@ -1,11 +1,11 @@
-
+
SwerveModuleConfiguration
-
+
diff --git a/docs/swervelib/parser/SwerveModulePhysicalCharacteristics.html b/docs/swervelib/parser/SwerveModulePhysicalCharacteristics.html
index 761b773..f9f00ad 100644
--- a/docs/swervelib/parser/SwerveModulePhysicalCharacteristics.html
+++ b/docs/swervelib/parser/SwerveModulePhysicalCharacteristics.html
@@ -1,11 +1,11 @@
-
+
SwerveModulePhysicalCharacteristics
-
+
diff --git a/docs/swervelib/parser/SwerveParser.html b/docs/swervelib/parser/SwerveParser.html
index 281cc8b..92aa675 100644
--- a/docs/swervelib/parser/SwerveParser.html
+++ b/docs/swervelib/parser/SwerveParser.html
@@ -1,11 +1,11 @@
-
+
SwerveParser
-
+
diff --git a/docs/swervelib/parser/deserializer/PIDFRange.html b/docs/swervelib/parser/deserializer/PIDFRange.html
index a30fec5..0bf8ba6 100644
--- a/docs/swervelib/parser/deserializer/PIDFRange.html
+++ b/docs/swervelib/parser/deserializer/PIDFRange.html
@@ -1,11 +1,11 @@
-
+
PIDFRange
-
+
diff --git a/docs/swervelib/parser/deserializer/package-summary.html b/docs/swervelib/parser/deserializer/package-summary.html
index 531eace..23ee9e2 100644
--- a/docs/swervelib/parser/deserializer/package-summary.html
+++ b/docs/swervelib/parser/deserializer/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser.deserializer
-
+
diff --git a/docs/swervelib/parser/deserializer/package-tree.html b/docs/swervelib/parser/deserializer/package-tree.html
index b665c67..f0a8839 100644
--- a/docs/swervelib/parser/deserializer/package-tree.html
+++ b/docs/swervelib/parser/deserializer/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser.deserializer Class Hierarchy
-
+
diff --git a/docs/swervelib/parser/json/ControllerPropertiesJson.html b/docs/swervelib/parser/json/ControllerPropertiesJson.html
index 94a7913..00acea8 100644
--- a/docs/swervelib/parser/json/ControllerPropertiesJson.html
+++ b/docs/swervelib/parser/json/ControllerPropertiesJson.html
@@ -1,11 +1,11 @@
-
+
ControllerPropertiesJson
-
+
diff --git a/docs/swervelib/parser/json/DeviceJson.html b/docs/swervelib/parser/json/DeviceJson.html
index 5ddde45..d33efc9 100644
--- a/docs/swervelib/parser/json/DeviceJson.html
+++ b/docs/swervelib/parser/json/DeviceJson.html
@@ -1,11 +1,11 @@
-
+
DeviceJson
-
+
diff --git a/docs/swervelib/parser/json/ModuleJson.html b/docs/swervelib/parser/json/ModuleJson.html
index a696a6f..8a6b99b 100644
--- a/docs/swervelib/parser/json/ModuleJson.html
+++ b/docs/swervelib/parser/json/ModuleJson.html
@@ -1,11 +1,11 @@
-
+
ModuleJson
-
+
diff --git a/docs/swervelib/parser/json/MotorConfigDouble.html b/docs/swervelib/parser/json/MotorConfigDouble.html
index 3a19261..0f11fe5 100644
--- a/docs/swervelib/parser/json/MotorConfigDouble.html
+++ b/docs/swervelib/parser/json/MotorConfigDouble.html
@@ -1,11 +1,11 @@
-
+
MotorConfigDouble
-
+
diff --git a/docs/swervelib/parser/json/MotorConfigInt.html b/docs/swervelib/parser/json/MotorConfigInt.html
index 8d20138..ef0676f 100644
--- a/docs/swervelib/parser/json/MotorConfigInt.html
+++ b/docs/swervelib/parser/json/MotorConfigInt.html
@@ -1,11 +1,11 @@
-
+
MotorConfigInt
-
+
diff --git a/docs/swervelib/parser/json/PIDFPropertiesJson.html b/docs/swervelib/parser/json/PIDFPropertiesJson.html
index 0a8b911..7302d5e 100644
--- a/docs/swervelib/parser/json/PIDFPropertiesJson.html
+++ b/docs/swervelib/parser/json/PIDFPropertiesJson.html
@@ -1,11 +1,11 @@
-
+
PIDFPropertiesJson
-
+
diff --git a/docs/swervelib/parser/json/PhysicalPropertiesJson.html b/docs/swervelib/parser/json/PhysicalPropertiesJson.html
index 6b8a99d..f452c32 100644
--- a/docs/swervelib/parser/json/PhysicalPropertiesJson.html
+++ b/docs/swervelib/parser/json/PhysicalPropertiesJson.html
@@ -1,11 +1,11 @@
-
+
PhysicalPropertiesJson
-
+
diff --git a/docs/swervelib/parser/json/SwerveDriveJson.html b/docs/swervelib/parser/json/SwerveDriveJson.html
index 18427aa..8f588b7 100644
--- a/docs/swervelib/parser/json/SwerveDriveJson.html
+++ b/docs/swervelib/parser/json/SwerveDriveJson.html
@@ -1,11 +1,11 @@
-
+
SwerveDriveJson
-
+
diff --git a/docs/swervelib/parser/json/modules/BoolMotorJson.html b/docs/swervelib/parser/json/modules/BoolMotorJson.html
index 7398b00..00080e3 100644
--- a/docs/swervelib/parser/json/modules/BoolMotorJson.html
+++ b/docs/swervelib/parser/json/modules/BoolMotorJson.html
@@ -1,11 +1,11 @@
-
+
BoolMotorJson
-
+
diff --git a/docs/swervelib/parser/json/modules/LocationJson.html b/docs/swervelib/parser/json/modules/LocationJson.html
index bc00150..9bb2be9 100644
--- a/docs/swervelib/parser/json/modules/LocationJson.html
+++ b/docs/swervelib/parser/json/modules/LocationJson.html
@@ -1,11 +1,11 @@
-
+
LocationJson
-
+
diff --git a/docs/swervelib/parser/json/modules/package-summary.html b/docs/swervelib/parser/json/modules/package-summary.html
index 0ab8040..eb68109 100644
--- a/docs/swervelib/parser/json/modules/package-summary.html
+++ b/docs/swervelib/parser/json/modules/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser.json.modules
-
+
diff --git a/docs/swervelib/parser/json/modules/package-tree.html b/docs/swervelib/parser/json/modules/package-tree.html
index 14e409b..96c93cb 100644
--- a/docs/swervelib/parser/json/modules/package-tree.html
+++ b/docs/swervelib/parser/json/modules/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser.json.modules Class Hierarchy
-
+
diff --git a/docs/swervelib/parser/json/package-summary.html b/docs/swervelib/parser/json/package-summary.html
index 5098296..dcc42db 100644
--- a/docs/swervelib/parser/json/package-summary.html
+++ b/docs/swervelib/parser/json/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser.json
-
+
diff --git a/docs/swervelib/parser/json/package-tree.html b/docs/swervelib/parser/json/package-tree.html
index a7a5a1d..0eec26d 100644
--- a/docs/swervelib/parser/json/package-tree.html
+++ b/docs/swervelib/parser/json/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser.json Class Hierarchy
-
+
diff --git a/docs/swervelib/parser/package-summary.html b/docs/swervelib/parser/package-summary.html
index aa9ef3a..8acdafe 100644
--- a/docs/swervelib/parser/package-summary.html
+++ b/docs/swervelib/parser/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser
-
+
diff --git a/docs/swervelib/parser/package-tree.html b/docs/swervelib/parser/package-tree.html
index bed9405..7fc749b 100644
--- a/docs/swervelib/parser/package-tree.html
+++ b/docs/swervelib/parser/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.parser Class Hierarchy
-
+
diff --git a/docs/swervelib/simulation/SwerveIMUSimulation.html b/docs/swervelib/simulation/SwerveIMUSimulation.html
index ac6414e..28f7d08 100644
--- a/docs/swervelib/simulation/SwerveIMUSimulation.html
+++ b/docs/swervelib/simulation/SwerveIMUSimulation.html
@@ -1,11 +1,11 @@
-
+
SwerveIMUSimulation
-
+
diff --git a/docs/swervelib/simulation/SwerveModuleSimulation.html b/docs/swervelib/simulation/SwerveModuleSimulation.html
index 245a8c9..df18c20 100644
--- a/docs/swervelib/simulation/SwerveModuleSimulation.html
+++ b/docs/swervelib/simulation/SwerveModuleSimulation.html
@@ -1,11 +1,11 @@
-
+
SwerveModuleSimulation
-
+
diff --git a/docs/swervelib/simulation/ctre/PhysicsSim.SimProfile.html b/docs/swervelib/simulation/ctre/PhysicsSim.SimProfile.html
index 724a792..d22df89 100644
--- a/docs/swervelib/simulation/ctre/PhysicsSim.SimProfile.html
+++ b/docs/swervelib/simulation/ctre/PhysicsSim.SimProfile.html
@@ -1,11 +1,11 @@
-
+
PhysicsSim.SimProfile
-
+
diff --git a/docs/swervelib/simulation/ctre/PhysicsSim.html b/docs/swervelib/simulation/ctre/PhysicsSim.html
index 7fad908..8301446 100644
--- a/docs/swervelib/simulation/ctre/PhysicsSim.html
+++ b/docs/swervelib/simulation/ctre/PhysicsSim.html
@@ -1,11 +1,11 @@
-
+
PhysicsSim
-
+
diff --git a/docs/swervelib/simulation/ctre/TalonFXSimProfile.html b/docs/swervelib/simulation/ctre/TalonFXSimProfile.html
index bae4cdd..1bdeb41 100644
--- a/docs/swervelib/simulation/ctre/TalonFXSimProfile.html
+++ b/docs/swervelib/simulation/ctre/TalonFXSimProfile.html
@@ -1,11 +1,11 @@
-
+
TalonFXSimProfile
-
+
diff --git a/docs/swervelib/simulation/ctre/TalonSRXSimProfile.html b/docs/swervelib/simulation/ctre/TalonSRXSimProfile.html
index 3e85af8..753629a 100644
--- a/docs/swervelib/simulation/ctre/TalonSRXSimProfile.html
+++ b/docs/swervelib/simulation/ctre/TalonSRXSimProfile.html
@@ -1,11 +1,11 @@
-
+
TalonSRXSimProfile
-
+
diff --git a/docs/swervelib/simulation/ctre/VictorSPXSimProfile.html b/docs/swervelib/simulation/ctre/VictorSPXSimProfile.html
index cec8157..bf6d493 100644
--- a/docs/swervelib/simulation/ctre/VictorSPXSimProfile.html
+++ b/docs/swervelib/simulation/ctre/VictorSPXSimProfile.html
@@ -1,11 +1,11 @@
-
+
VictorSPXSimProfile
-
+
diff --git a/docs/swervelib/simulation/ctre/package-summary.html b/docs/swervelib/simulation/ctre/package-summary.html
index 6104030..607e096 100644
--- a/docs/swervelib/simulation/ctre/package-summary.html
+++ b/docs/swervelib/simulation/ctre/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.simulation.ctre
-
+
diff --git a/docs/swervelib/simulation/ctre/package-tree.html b/docs/swervelib/simulation/ctre/package-tree.html
index f772f3e..917f879 100644
--- a/docs/swervelib/simulation/ctre/package-tree.html
+++ b/docs/swervelib/simulation/ctre/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.simulation.ctre Class Hierarchy
-
+
diff --git a/docs/swervelib/simulation/package-summary.html b/docs/swervelib/simulation/package-summary.html
index 2be1fc3..868460d 100644
--- a/docs/swervelib/simulation/package-summary.html
+++ b/docs/swervelib/simulation/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.simulation
-
+
diff --git a/docs/swervelib/simulation/package-tree.html b/docs/swervelib/simulation/package-tree.html
index 5738d89..9382ef5 100644
--- a/docs/swervelib/simulation/package-tree.html
+++ b/docs/swervelib/simulation/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.simulation Class Hierarchy
-
+
diff --git a/docs/swervelib/telemetry/SwerveDriveTelemetry.TelemetryVerbosity.html b/docs/swervelib/telemetry/SwerveDriveTelemetry.TelemetryVerbosity.html
index 662b465..d7976e3 100644
--- a/docs/swervelib/telemetry/SwerveDriveTelemetry.TelemetryVerbosity.html
+++ b/docs/swervelib/telemetry/SwerveDriveTelemetry.TelemetryVerbosity.html
@@ -1,11 +1,11 @@
-
+
SwerveDriveTelemetry.TelemetryVerbosity
-
+
diff --git a/docs/swervelib/telemetry/SwerveDriveTelemetry.html b/docs/swervelib/telemetry/SwerveDriveTelemetry.html
index 70f3734..5c7872f 100644
--- a/docs/swervelib/telemetry/SwerveDriveTelemetry.html
+++ b/docs/swervelib/telemetry/SwerveDriveTelemetry.html
@@ -1,11 +1,11 @@
-
+
SwerveDriveTelemetry
-
+
diff --git a/docs/swervelib/telemetry/package-summary.html b/docs/swervelib/telemetry/package-summary.html
index f081a3d..ea37a39 100644
--- a/docs/swervelib/telemetry/package-summary.html
+++ b/docs/swervelib/telemetry/package-summary.html
@@ -1,11 +1,11 @@
-
+
swervelib.telemetry
-
+
diff --git a/docs/swervelib/telemetry/package-tree.html b/docs/swervelib/telemetry/package-tree.html
index 527e56b..e1de47d 100644
--- a/docs/swervelib/telemetry/package-tree.html
+++ b/docs/swervelib/telemetry/package-tree.html
@@ -1,11 +1,11 @@
-
+
swervelib.telemetry Class Hierarchy
-
+
diff --git a/swervelib/motors/TalonFXSwerve.java b/swervelib/motors/TalonFXSwerve.java
index 21c975e..19e1123 100644
--- a/swervelib/motors/TalonFXSwerve.java
+++ b/swervelib/motors/TalonFXSwerve.java
@@ -42,9 +42,9 @@ public class TalonFXSwerve extends SwerveMotor
*/
private boolean configChanged = true;
/**
- * Feedforward scalar value for the angle motor.
+ * Nominal voltage default to use with feedforward.
*/
- private double fscalar = 1;
+ private double nominalVoltage = 12.0;
/**
* Constructor for TalonFX swerve motor.
@@ -156,7 +156,7 @@ public class TalonFXSwerve extends SwerveMotor
{
motor.setStatusFramePeriod(StatusFrameEnhanced.Status_1_General, CANStatus1);
// TODO: Configure Status Frame 2 thru 21 if necessary
- // https://v5.docs.ctr-electronics.com/en/stable/ch18_CommonAPI.html#setting-status-frame-periods
+ // https://v5.docs.ctr-electronics.com/en/stable/ch18_CommonAPI.html#setting-status-frame-periods
}
/**
@@ -173,7 +173,6 @@ public class TalonFXSwerve extends SwerveMotor
configuration.slot0.kF = config.f;
configuration.slot0.integralZone = config.iz;
configuration.slot0.closedLoopPeakOutput = config.output.max;
- fscalar = config.fscalar;
configChanged = true;
}
@@ -312,8 +311,7 @@ public class TalonFXSwerve extends SwerveMotor
isDriveMotor ? ControlMode.Velocity : ControlMode.Position,
convertToNativeSensorUnits(setpoint),
DemandType.ArbitraryFeedForward,
- isDriveMotor ? feedforward : feedforward * fscalar);
- // Credit to Team 3181 for the -0.3, I'm not sure why it works, but it does.
+ feedforward / nominalVoltage);
}
/**
@@ -362,6 +360,7 @@ public class TalonFXSwerve extends SwerveMotor
{
configuration.voltageCompSaturation = nominalVoltage;
configChanged = true;
+ this.nominalVoltage = nominalVoltage;
}
/**
diff --git a/swervelib/motors/TalonSRXSwerve.java b/swervelib/motors/TalonSRXSwerve.java
index 013e3f8..6a7a650 100644
--- a/swervelib/motors/TalonSRXSwerve.java
+++ b/swervelib/motors/TalonSRXSwerve.java
@@ -4,10 +4,12 @@ import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.DemandType;
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
import com.ctre.phoenix.motorcontrol.NeutralMode;
-import com.ctre.phoenix.motorcontrol.SupplyCurrentLimitConfiguration;
+import com.ctre.phoenix.motorcontrol.StatusFrameEnhanced;
+import com.ctre.phoenix.motorcontrol.can.TalonSRXConfiguration;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import swervelib.encoders.SwerveAbsoluteEncoder;
import swervelib.parser.PIDFConfig;
+import swervelib.simulation.ctre.PhysicsSim;
import swervelib.telemetry.SwerveDriveTelemetry;
/**
@@ -19,19 +21,31 @@ public class TalonSRXSwerve extends SwerveMotor
/**
* Factory default already occurred.
*/
- private final boolean factoryDefaultOccurred = false;
+ private final boolean factoryDefaultOccurred = false;
+ /**
+ * Current TalonFX configuration.
+ */
+ private final TalonSRXConfiguration configuration = new TalonSRXConfiguration();
/**
* Whether the absolute encoder is integrated.
*/
- private final boolean absoluteEncoder = false;
+ private final boolean absoluteEncoder = false;
/**
* TalonSRX motor controller.
*/
WPI_TalonSRX motor;
/**
- * The position conversion factor.
+ * The position conversion factor to convert raw sensor units to Meters Per 100ms, or Ticks to Degrees.
*/
- private double positionConversionFactor = 1;
+ private double positionConversionFactor = 1;
+ /**
+ * If the TalonFX configuration has changed.
+ */
+ private boolean configChanged = true;
+ /**
+ * Nominal voltage default to use with feedforward.
+ */
+ private double nominalVoltage = 12.0;
/**
* Constructor for TalonSRX swerve motor.
@@ -47,6 +61,11 @@ public class TalonSRXSwerve extends SwerveMotor
factoryDefaults();
clearStickyFaults();
+
+ if (SwerveDriveTelemetry.isSimulation)
+ {
+ PhysicsSim.getInstance().addTalonSRX(motor, .25, 6800);
+ }
}
/**
@@ -90,6 +109,7 @@ public class TalonSRXSwerve extends SwerveMotor
@Override
public SwerveMotor setAbsoluteEncoder(SwerveAbsoluteEncoder encoder)
{
+ // Do not support.
return this;
}
@@ -97,11 +117,36 @@ public class TalonSRXSwerve extends SwerveMotor
* Configure the integrated encoder for the swerve module. Sets the conversion factors for position and velocity.
*
* @param positionConversionFactor The conversion factor to apply for position.
+ *
+ * Degrees:
+ *
+ * 360 / (angleGearRatio * encoderTicksPerRotation)
+ *
+ *
+ * Meters:
+ *
+ * (Math.PI * wheelDiameter) / (driveGearRatio * encoderTicksPerRotation)
+ *
*/
@Override
public void configureIntegratedEncoder(double positionConversionFactor)
{
this.positionConversionFactor = positionConversionFactor;
+ // Taken from democat's library.
+ // https://github.com/democat3457/swerve-lib/blob/7c03126b8c22f23a501b2c2742f9d173a5bcbc40/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500DriveControllerFactoryBuilder.java#L16
+ configureCANStatusFrames(250);
+ }
+
+ /**
+ * Set the CAN status frames.
+ *
+ * @param CANStatus1 Applied Motor Output, Fault Information, Limit Switch Information
+ */
+ public void configureCANStatusFrames(int CANStatus1)
+ {
+ motor.setStatusFramePeriod(StatusFrameEnhanced.Status_1_General, CANStatus1);
+ // TODO: Configure Status Frame 2 thru 21 if necessary
+ // https://v5.docs.ctr-electronics.com/en/stable/ch18_CommonAPI.html#setting-status-frame-periods
}
/**
@@ -112,13 +157,13 @@ public class TalonSRXSwerve extends SwerveMotor
@Override
public void configurePIDF(PIDFConfig config)
{
- int slotIdx = 0;
- motor.config_kP(slotIdx, config.p);
- motor.config_kI(slotIdx, config.i);
- motor.config_kD(slotIdx, config.d);
- motor.config_kF(slotIdx, config.f);
- motor.config_IntegralZone(slotIdx, config.iz);
- motor.configClosedLoopPeakOutput(slotIdx, config.output.max);
+ configuration.slot0.kP = config.p;
+ configuration.slot0.kI = config.i;
+ configuration.slot0.kD = config.d;
+ configuration.slot0.kF = config.f;
+ configuration.slot0.integralZone = config.iz;
+ configuration.slot0.closedLoopPeakOutput = config.output.max;
+ configChanged = true;
}
/**
@@ -161,7 +206,11 @@ public class TalonSRXSwerve extends SwerveMotor
@Override
public void burnFlash()
{
- // Do nothing
+ if (configChanged)
+ {
+ motor.configAllSettings(configuration, 250);
+ configChanged = false;
+ }
}
/**
@@ -175,133 +224,6 @@ public class TalonSRXSwerve extends SwerveMotor
motor.set(percentOutput);
}
- /**
- * Set the closed loop PID controller reference point.
- *
- * @param setpoint Setpoint in MPS or Angle in degrees.
- * @param feedforward Feedforward in volt-meter-per-second or kV.
- */
- @Override
- public void setReference(double setpoint, double feedforward)
- {
- burnFlash();
-
- motor.set(
- isDriveMotor ? ControlMode.Velocity : ControlMode.Position,
- convertToNativeSensorUnits(setpoint),
- DemandType.ArbitraryFeedForward,
- feedforward * -0.3);
- // Credit to Team 3181 for the -0.3, I'm not sure why it works, but it does.
- }
-
- /**
- * Get the velocity of the integrated encoder.
- *
- * @return velocity
- */
- @Override
- public double getVelocity()
- {
- return (motor.getSelectedSensorVelocity() * 10) * positionConversionFactor;
- }
-
- /**
- * Get the raw position.
- *
- * @return Position in meters or degrees.
- */
- public double getRawPosition()
- {
- return motor.getSelectedSensorPosition() * positionConversionFactor;
- }
-
- /**
- * Get the position of the integrated encoder.
- *
- * @return Position in Meters or Degrees.
- */
- @Override
- public double getPosition()
- {
- return isDriveMotor ? getRawPosition() : getRawPosition() % 360;
- }
-
- /**
- * Set the integrated encoder position.
- *
- * @param position Integrated encoder position. Should be angle in degrees or meters.
- */
- @Override
- public void setPosition(double position)
- {
- if (!absoluteEncoder && !SwerveDriveTelemetry.isSimulation)
- {
- motor.setSelectedSensorPosition(convertToNativeSensorUnits(position));
- }
- }
-
- /**
- * Set the voltage compensation for the swerve module motor.
- *
- * @param nominalVoltage Nominal voltage for operation to output to.
- */
- @Override
- public void setVoltageCompensation(double nominalVoltage)
- {
- motor.enableVoltageCompensation(true);
- motor.configVoltageCompSaturation(nominalVoltage);
- }
-
- /**
- * Set the current limit for the swerve drive motor, remember this may cause jumping if used in conjunction with
- * voltage compensation. This is useful to protect the motor from current spikes.
- *
- * @param currentLimit Current limit in AMPS at free speed.
- */
- @Override
- public void setCurrentLimit(int currentLimit)
- {
- SupplyCurrentLimitConfiguration config = new SupplyCurrentLimitConfiguration();
- motor.configSupplyCurrentLimit(config);
- config.currentLimit = currentLimit;
- config.enable = true;
- motor.configSupplyCurrentLimit(config);
- }
-
- /**
- * Set the maximum rate the open/closed loop output can change by.
- *
- * @param rampRate Time in seconds to go from 0 to full throttle.
- */
- @Override
- public void setLoopRampRate(double rampRate)
- {
- motor.configClosedloopRamp(rampRate);
- motor.configOpenloopRamp(rampRate);
- }
-
- /**
- * Get the motor object from the module.
- *
- * @return Motor object.
- */
- @Override
- public Object getMotor()
- {
- return motor;
- }
-
- /**
- * Queries whether the absolute encoder is directly attached to the motor controller.
- *
- * @return connected absolute encoder state.
- */
- @Override
- public boolean isAttachedAbsoluteEncoder()
- {
- return absoluteEncoder;
- }
-
/**
* Put an angle within the the 360 deg scope of a reference. For example, given a scope reference of 756 degrees,
* assumes the full scope is (720-1080), and places an angle of 22 degrees into it, returning 742 deg.
@@ -314,7 +236,7 @@ public class TalonSRXSwerve extends SwerveMotor
{
double lowerBound;
double upperBound;
- double lowerOffset = scopeReference % 360;
+ double lowerOffset = Math.IEEEremainder(scopeReference, 360);
// Create the interval from the reference angle.
if (lowerOffset >= 0)
@@ -355,7 +277,128 @@ public class TalonSRXSwerve extends SwerveMotor
public double convertToNativeSensorUnits(double setpoint)
{
setpoint =
- isDriveMotor ? setpoint * .1 : placeInAppropriate0To360Scope(getRawPosition(), setpoint);
+ isDriveMotor ? setpoint * .1 : placeInAppropriate0To360Scope(getPosition(), setpoint);
return setpoint / positionConversionFactor;
}
+
+ /**
+ * Set the closed loop PID controller reference point.
+ *
+ * @param setpoint Setpoint in MPS or Angle in degrees.
+ * @param feedforward Feedforward in volt-meter-per-second or kV.
+ */
+ @Override
+ public void setReference(double setpoint, double feedforward)
+ {
+ if (SwerveDriveTelemetry.isSimulation)
+ {
+ PhysicsSim.getInstance().run();
+ }
+
+ burnFlash();
+
+ motor.set(
+ isDriveMotor ? ControlMode.Velocity : ControlMode.Position,
+ convertToNativeSensorUnits(setpoint),
+ DemandType.ArbitraryFeedForward,
+ feedforward / nominalVoltage);
+ }
+
+ /**
+ * Get the velocity of the integrated encoder.
+ *
+ * @return velocity in Meters Per Second, or Degrees per Second.
+ */
+ @Override
+ public double getVelocity()
+ {
+ return (motor.getSelectedSensorVelocity() * 10) * positionConversionFactor;
+ }
+
+ /**
+ * Get the position of the integrated encoder.
+ *
+ * @return Position in Meters or Degrees.
+ */
+ @Override
+ public double getPosition()
+ {
+ return motor.getSelectedSensorPosition() * positionConversionFactor;
+ }
+
+ /**
+ * Set the integrated encoder position.
+ *
+ * @param position Integrated encoder position. Should be angle in degrees or meters.
+ */
+ @Override
+ public void setPosition(double position)
+ {
+ if (!absoluteEncoder && !SwerveDriveTelemetry.isSimulation)
+ {
+ motor.setSelectedSensorPosition(position / positionConversionFactor, 0, 250);
+ }
+ }
+
+ /**
+ * Set the voltage compensation for the swerve module motor.
+ *
+ * @param nominalVoltage Nominal voltage for operation to output to.
+ */
+ @Override
+ public void setVoltageCompensation(double nominalVoltage)
+ {
+ configuration.voltageCompSaturation = nominalVoltage;
+ configChanged = true;
+ this.nominalVoltage = nominalVoltage;
+ }
+
+ /**
+ * Set the current limit for the swerve drive motor, remember this may cause jumping if used in conjunction with
+ * voltage compensation. This is useful to protect the motor from current spikes.
+ *
+ * @param currentLimit Current limit in AMPS at free speed.
+ */
+ @Override
+ public void setCurrentLimit(int currentLimit)
+ {
+ configuration.continuousCurrentLimit = currentLimit;
+ configuration.peakCurrentLimit = currentLimit;
+ configChanged = true;
+ }
+
+ /**
+ * Set the maximum rate the open/closed loop output can change by.
+ *
+ * @param rampRate Time in seconds to go from 0 to full throttle.
+ */
+ @Override
+ public void setLoopRampRate(double rampRate)
+ {
+ configuration.closedloopRamp = rampRate;
+ configuration.openloopRamp = rampRate;
+ configChanged = true;
+ }
+
+ /**
+ * Get the motor object from the module.
+ *
+ * @return Motor object.
+ */
+ @Override
+ public Object getMotor()
+ {
+ return motor;
+ }
+
+ /**
+ * Queries whether the absolute encoder is directly attached to the motor controller.
+ *
+ * @return connected absolute encoder state.
+ */
+ @Override
+ public boolean isAttachedAbsoluteEncoder()
+ {
+ return absoluteEncoder;
+ }
}
diff --git a/swervelib/parser/PIDFConfig.java b/swervelib/parser/PIDFConfig.java
index 994e5b2..9da0684 100644
--- a/swervelib/parser/PIDFConfig.java
+++ b/swervelib/parser/PIDFConfig.java
@@ -25,10 +25,6 @@ public class PIDFConfig
* Feedforward value for PID.
*/
public double f;
- /**
- * Feedforward scalar for PID applied dynamically.
- */
- public double fscalar = 1;
/**
* Integral zone of the PID.
*/