|
15 | 15 | import edu.wpi.first.util.WPIUtilJNI; |
16 | 16 | import edu.wpi.first.wpilibj.ADIS16470_IMU; |
17 | 17 | import frc.robot.Constants.DriveConstants; |
18 | | -import frc.robot.Constants.OIConstants; |
19 | 18 | import frc.utils.SwerveUtils; |
20 | 19 | import edu.wpi.first.wpilibj2.command.SubsystemBase; |
21 | 20 |
|
@@ -45,13 +44,13 @@ public class DriveSubsystem extends SubsystemBase { |
45 | 44 | private final ADIS16470_IMU m_gyro = new ADIS16470_IMU(); |
46 | 45 |
|
47 | 46 | // Slew rate filter variables for controlling lateral acceleration |
48 | | - private double currentRotation = 0.0; |
49 | | - private double currentTranslationDir = 0.0; |
50 | | - private double currentTranslationMag = 0.0; |
| 47 | + private double m_currentRotation = 0.0; |
| 48 | + private double m_currentTranslationDir = 0.0; |
| 49 | + private double m_currentTranslationMag = 0.0; |
51 | 50 |
|
52 | | - private SlewRateLimiter magLimiter = new SlewRateLimiter(OIConstants.kMagnitudeSlewRate); |
53 | | - private SlewRateLimiter rotLimiter = new SlewRateLimiter(OIConstants.kRotationalSlewRate); |
54 | | - double prevTime = WPIUtilJNI.now() * 1e-6; |
| 51 | + private SlewRateLimiter m_magLimiter = new SlewRateLimiter(DriveConstants.kMagnitudeSlewRate); |
| 52 | + private SlewRateLimiter m_rotLimiter = new SlewRateLimiter(DriveConstants.kRotationalSlewRate); |
| 53 | + private double m_prevTime = WPIUtilJNI.now() * 1e-6; |
55 | 54 |
|
56 | 55 | // Odometry class for tracking robot pose |
57 | 56 | SwerveDriveOdometry m_odometry = new SwerveDriveOdometry( |
@@ -128,51 +127,51 @@ public void drive(double xSpeed, double ySpeed, double rot, boolean fieldRelativ |
128 | 127 |
|
129 | 128 | // Calculate the direction slew rate based on an estimate of the lateral acceleration |
130 | 129 | double directionSlewRate; |
131 | | - if (currentTranslationMag != 0.0) { |
132 | | - directionSlewRate = Math.abs(OIConstants.kDirectionSlewRate / currentTranslationMag); |
| 130 | + if (m_currentTranslationMag != 0.0) { |
| 131 | + directionSlewRate = Math.abs(DriveConstants.kDirectionSlewRate / m_currentTranslationMag); |
133 | 132 | } else { |
134 | 133 | directionSlewRate = 500.0; //some high number that means the slew rate is effectively instantaneous |
135 | 134 | } |
136 | 135 |
|
137 | 136 |
|
138 | 137 | double currentTime = WPIUtilJNI.now() * 1e-6; |
139 | | - double elapsedTime = currentTime - prevTime; |
140 | | - double angleDif = SwerveUtils.AngleDifference(inputTranslationDir, currentTranslationDir); |
| 138 | + double elapsedTime = currentTime - m_prevTime; |
| 139 | + double angleDif = SwerveUtils.AngleDifference(inputTranslationDir, m_currentTranslationDir); |
141 | 140 | if (angleDif < 0.45*Math.PI) { |
142 | | - currentTranslationDir = SwerveUtils.StepTowardsCircular(currentTranslationDir, inputTranslationDir, directionSlewRate * elapsedTime); |
143 | | - currentTranslationMag = magLimiter.calculate(inputTranslationMag); |
| 141 | + m_currentTranslationDir = SwerveUtils.StepTowardsCircular(m_currentTranslationDir, inputTranslationDir, directionSlewRate * elapsedTime); |
| 142 | + m_currentTranslationMag = m_magLimiter.calculate(inputTranslationMag); |
144 | 143 | } |
145 | 144 | else if (angleDif > 0.85*Math.PI) { |
146 | | - if (currentTranslationMag > 1e-4) { //some small number to avoid floating-point errors with equality checking |
| 145 | + if (m_currentTranslationMag > 1e-4) { //some small number to avoid floating-point errors with equality checking |
147 | 146 | // keep currentTranslationDir unchanged |
148 | | - currentTranslationMag = magLimiter.calculate(0.0); |
| 147 | + m_currentTranslationMag = m_magLimiter.calculate(0.0); |
149 | 148 | } |
150 | 149 | else { |
151 | | - currentTranslationDir = SwerveUtils.WrapAngle(currentTranslationDir + Math.PI); |
152 | | - currentTranslationMag = magLimiter.calculate(inputTranslationMag); |
| 150 | + m_currentTranslationDir = SwerveUtils.WrapAngle(m_currentTranslationDir + Math.PI); |
| 151 | + m_currentTranslationMag = m_magLimiter.calculate(inputTranslationMag); |
153 | 152 | } |
154 | 153 | } |
155 | 154 | else { |
156 | | - currentTranslationDir = SwerveUtils.StepTowardsCircular(currentTranslationDir, inputTranslationDir, directionSlewRate * elapsedTime); |
157 | | - currentTranslationMag = magLimiter.calculate(0.0); |
| 155 | + m_currentTranslationDir = SwerveUtils.StepTowardsCircular(m_currentTranslationDir, inputTranslationDir, directionSlewRate * elapsedTime); |
| 156 | + m_currentTranslationMag = m_magLimiter.calculate(0.0); |
158 | 157 | } |
159 | | - prevTime = currentTime; |
| 158 | + m_prevTime = currentTime; |
160 | 159 |
|
161 | | - xSpeedCommanded = currentTranslationMag * Math.cos(currentTranslationDir); |
162 | | - ySpeedCommanded = currentTranslationMag * Math.sin(currentTranslationDir); |
163 | | - currentRotation = rotLimiter.calculate(rot); |
| 160 | + xSpeedCommanded = m_currentTranslationMag * Math.cos(m_currentTranslationDir); |
| 161 | + ySpeedCommanded = m_currentTranslationMag * Math.sin(m_currentTranslationDir); |
| 162 | + m_currentRotation = m_rotLimiter.calculate(rot); |
164 | 163 |
|
165 | 164 |
|
166 | 165 | } else { |
167 | 166 | xSpeedCommanded = xSpeed; |
168 | 167 | ySpeedCommanded = ySpeed; |
169 | | - currentRotation = rot; |
| 168 | + m_currentRotation = rot; |
170 | 169 | } |
171 | 170 |
|
172 | 171 | // Convert the commanded speeds into the correct units for the drivetrain |
173 | 172 | double xSpeedDelivered = xSpeedCommanded * DriveConstants.kMaxSpeedMetersPerSecond; |
174 | 173 | double ySpeedDelivered = ySpeedCommanded * DriveConstants.kMaxSpeedMetersPerSecond; |
175 | | - double rotDelivered = currentRotation * DriveConstants.kMaxAngularSpeed; |
| 174 | + double rotDelivered = m_currentRotation * DriveConstants.kMaxAngularSpeed; |
176 | 175 |
|
177 | 176 | var swerveModuleStates = DriveConstants.kDriveKinematics.toSwerveModuleStates( |
178 | 177 | fieldRelative |
|
0 commit comments