Skip to content

Commit

Permalink
Saraansh optimizations + further encapsulation
Browse files Browse the repository at this point in the history
  • Loading branch information
yamamara committed Jul 3, 2024
1 parent 4b94d75 commit 925d20d
Show file tree
Hide file tree
Showing 25 changed files with 16 additions and 18 deletions.
Binary file modified .gradle/8.4/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.4/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.4/checksums/sha1-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.4/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.4/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 011 - 0 - ext.dat
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 012 - 0 - ext.dat
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 013 - 0 - ext.dat
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 014 - 0 - ext.dat
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 021 - 0 - ext.dat
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 022 - 0 - ext.dat
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 023 - 0 - ext.dat
Binary file not shown.
Binary file added ctre_sim/Talon FX vers. C - 024 - 0 - ext.dat
Binary file not shown.
3 changes: 3 additions & 0 deletions simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
},
{
"guid": "Keyboard1"
},
{
"guid": "03000000ac0500004f02000011010000"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ class Drivetrain(private val gyroIO: GyroIO, val swerveModules: List<SwerveModul

private var isFieldOriented = true

private var targetedChassisSpeeds = edu.wpi.first.math.kinematics.ChassisSpeeds(0.0, 0.0, 0.0)
private var targetedChassisSpeeds =
ChassisSpeeds(0.0.meters.perSecond, 0.0.meters.perSecond, 0.0.radians.perSecond)
.chassisSpeedsWPILIB

private var targetedChassisAccels = edu.wpi.first.math.kinematics.ChassisSpeeds(0.0, 0.0, 0.0)
private var targetedChassisAccels =
ChassisSpeeds(0.0.meters.perSecond, 0.0.meters.perSecond, 0.0.radians.perSecond)
.chassisSpeedsWPILIB

private var isInAutonomous = false

Expand Down Expand Up @@ -484,6 +488,7 @@ class Drivetrain(private val gyroIO: GyroIO, val swerveModules: List<SwerveModul
chassisAccels: edu.wpi.first.math.kinematics.ChassisSpeeds =
edu.wpi.first.math.kinematics.ChassisSpeeds(0.0, 0.0, 0.0)
) {
// Allows parameter chassisSpeeds to have its value reassigned
var chassisSpeeds = chassisSpeeds

// If theres skew consider slowing down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import kotlin.math.abs
import kotlin.math.cos
import kotlin.math.withSign

class SwerveModule(val io: SwerveModuleIO) {
class SwerveModule(private val io: SwerveModuleIO) {

val inputs = SwerveModuleIO.SwerveModuleIOInputs()

Expand All @@ -56,8 +56,6 @@ class SwerveModule(val io: SwerveModuleIO) {

private var lastDrivePos = 0.0.meters

private var shouldInvert = false

private val steerkP =
LoggedTunableValue(
"Drivetrain/modulesteerkP", Pair({ it.inVoltsPerDegree }, { it.volts.perDegree })
Expand Down Expand Up @@ -150,12 +148,6 @@ class SwerveModule(val io: SwerveModuleIO) {
CustomLogger.recordDebugOutput("${io.label}/steeringSetpoint", steeringSetpoint.inDegrees)
CustomLogger.recordDebugOutput("${io.label}/lastDrivePos", lastDrivePos.inMeters)

posDeltas.add(
SwerveModulePosition(
(inputs.drivePosition - lastDrivePos).inMeters, inputs.steerPosition.inRotation2ds
)
)

lastDrivePos = inputs.drivePosition

modulePosition.distanceMeters = inputs.drivePosition.inMeters
Expand Down Expand Up @@ -183,7 +175,7 @@ class SwerveModule(val io: SwerveModuleIO) {
fun setOpenLoop(steering: Angle, speed: LinearVelocity, optimize: Boolean = true) {
var steeringDifference =
(steering - inputs.steerPosition).inRadians.IEEErem(2 * Math.PI).radians
shouldInvert = steeringDifference.absoluteValue > (Math.PI / 2).radians && optimize
val shouldInvert = steeringDifference.absoluteValue > (Math.PI / 2).radians && optimize
if (shouldInvert) {
steeringDifference -= Math.PI.withSign(steeringDifference.inRadians).radians
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.team4099.robot2023.subsystems.falconspin.MotorCollection
import com.team4099.robot2023.subsystems.falconspin.SimulatedMotor
import edu.wpi.first.math.MathUtil
import edu.wpi.first.math.system.plant.DCMotor
import edu.wpi.first.wpilibj.DriverStation
import edu.wpi.first.wpilibj.simulation.BatterySim
import edu.wpi.first.wpilibj.simulation.FlywheelSim
import edu.wpi.first.wpilibj.simulation.RoboRioSim
Expand Down Expand Up @@ -273,11 +274,11 @@ class SwerveModuleIOSim(override val label: String) : SwerveModuleIO {
}

override fun setDriveBrakeMode(brake: Boolean) {
println("Can't set brake mode in simulation")
DriverStation.reportError("Can't set brake mode in simulation", true)
}

override fun configSteerMotionMagic(maxVel: AngularVelocity, maxAccel: AngularAcceleration) {
println("Can't configure motion magic in simulation")
DriverStation.reportError("Can't configure motion magic in simulation", true)
}

override fun runCharacterization(input: ElectricalPotential) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ class SwerveModuleIOTalon(
DrivetrainConstants.WHEEL_DIAMETER.inMeters *
DrivetrainConstants.DRIVE_SENSOR_GEAR_RATIO
)
Logger.recordOutput("$label/drivePositionUnits", driveSensor.position.inMeters)
inputs.drivePosition = driveSensor.position
inputs.steerPosition = steeringSensor.position
Logger.recordOutput("$label/rawSteeringValue", steeringFalcon.position.value)
Logger.recordOutput("$label/rawSteeringValue", steeringFalcon.position.value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ sealed interface Request {

class ClosedLoop(
var chassisSpeeds: ChassisSpeeds,
val chassisAccels: ChassisSpeeds =
edu.wpi.first.math.kinematics.ChassisSpeeds(0.0, 0.0, 0.0)
val chassisAccels: ChassisSpeeds = ChassisSpeeds(0.0, 0.0, 0.0)
) : DrivetrainRequest

class ZeroSensors(val isInAutonomous: Boolean = false) : DrivetrainRequest
Expand Down

0 comments on commit 925d20d

Please sign in to comment.