Skip to content

Commit

Permalink
drive revamp finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Shom770 committed Jun 25, 2024
1 parent 301a332 commit bc9334f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public void run() {
signalsLock.lock();
try {
if (isCANFD && signals.length > 0) {
com.ctre.phoenix6.BaseStatusSignal.waitForAll(2.0 / com.team4099.robot2023.config.constants.DrivetrainConstants.OMOMETRY_UPDATE_FREQUENCY, signals);
com.ctre.phoenix6.BaseStatusSignal.waitForAll(2.0 / com.team4099.robot2023.config.constants.DrivetrainConstants.ODOMETRY_UPDATE_FREQUENCY, signals);
} else {
// "waitForAll" does not support blocking on multiple
// signals with a bus that is not CAN FD, regardless
// of Pro licensing. No reasoning for this behavior
// is provided by the documentation.
Thread.sleep((long) (1000.0 / com.team4099.robot2023.config.constants.DrivetrainConstants.OMOMETRY_UPDATE_FREQUENCY));
Thread.sleep((long) (1000.0 / com.team4099.robot2023.config.constants.DrivetrainConstants.ODOMETRY_UPDATE_FREQUENCY));
com.ctre.phoenix6.BaseStatusSignal.refreshAll(signals);
}
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static com.team4099.utils.threads.SparkMaxOdometryThread getInstance() {
private SparkMaxOdometryThread() {
notifier = new edu.wpi.first.wpilibj.Notifier(this::periodic);
notifier.setName("SparkMaxOdometryThread");
notifier.startPeriodic(1.0 / com.team4099.robot2023.config.constants.DrivetrainConstants.OMOMETRY_UPDATE_FREQUENCY );
notifier.startPeriodic(1.0 / com.team4099.robot2023.config.constants.DrivetrainConstants.ODOMETRY_UPDATE_FREQUENCY);
}

public java.util.Queue<Double> registerSignal(java.util.function.DoubleSupplier signal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SwerveModuleTuningCommand(val drivetrain: Drivetrain, val steeringPosition

override fun execute() {
for (module in drivetrain.swerveModules) {
module.closedLoop(
module.setPositionClosedLoop(
SwerveModuleState(0.0, steeringPosition().inRotation2ds),
SwerveModuleState(0.0, steeringPosition().inRotation2ds),
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object DrivetrainConstants {

const val TELEOP_TURNING_SPEED_PERCENT = 0.6

const val OMOMETRY_UPDATE_FREQUENCY = 250.0
const val ODOMETRY_UPDATE_FREQUENCY = 250.0

const val WHEEL_COUNT = 4
val WHEEL_DIAMETER = (2.083 * 2).inches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ class Drivetrain(private val gyroIO: GyroIO, swerveModuleIOs: DrivetrainIO) : Su
edu.wpi.first.math.kinematics.ChassisSpeeds(0.0, 0.0, 0.0)
) {
var chassisSpeeds = chassisSpeeds

// If theres skew consider slowing down
if (DrivetrainConstants.MINIMIZE_SKEW) {
chassisSpeeds =
Expand All @@ -519,8 +520,8 @@ class Drivetrain(private val gyroIO: GyroIO, swerveModuleIOs: DrivetrainIO) : Su
// Once we have all of our states obtained for both velocity and acceleration, apply these
// states to each swerve module
for (moduleIndex in 0 until DrivetrainConstants.WHEEL_COUNT) {
swerveModules[moduleIndex].closedLoop(
velSwerveModuleStates[moduleIndex], accelSwerveModuleStates[moduleIndex]
swerveModules[moduleIndex].setPositionClosedLoop(
accelSwerveModuleStates[moduleIndex], velSwerveModuleStates[moduleIndex]
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class SwerveModule(val io: SwerveModuleIO) {
)
}
}
fun closedLoop(
fun setPositionClosedLoop(
desiredAccelState: SwerveModuleState,
desiredVeloState: SwerveModuleState,
optimize: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ class SwerveModuleIOSim(override val label: String) : SwerveModuleIO {
) {
Logger.recordOutput("$label/desiredDriveSpeedMPS", speed.inMetersPerSecond)
val feedforward = driveFeedForward.calculate(speed, acceleration)
setDriveVoltage(feedforward + driveFeedback.calculate(driveVelocity, speed))

setDriveVoltage(feedforward + driveFeedback.calculate(driveVelocity, speed))
setSteeringSetpoint(steering)
}

Expand Down

0 comments on commit bc9334f

Please sign in to comment.