Skip to content

Commit 4973c6b

Browse files
committed
update GradleRIO version to beta-3 and refactor voltage calculations in simulation classes
1 parent e33b2a1 commit 4973c6b

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

build.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id "java"
3-
id "edu.wpi.first.GradleRIO" version "2025.1.1-beta-2"
3+
id "edu.wpi.first.GradleRIO" version "2025.1.1-beta-3"
44
id "com.peterabeles.gversion" version "1.10"
55
id "com.diffplug.spotless" version "6.25.0"
66
id "pmd"
@@ -151,15 +151,15 @@ tasks.withType(JavaCompile) {
151151
}
152152

153153
// Create version file
154-
// project.compileJava.dependsOn(createVersionFile)
155-
// gversion {
156-
// srcDir = "src/main/java/"
157-
// classPackage = "frc.robot"
158-
// className = "BuildConstants"
159-
// dateFormat = "yyyy-MM-dd HH:mm:ss z"
160-
// timeZone = "America/New_York"
161-
// indent = " "
162-
// }
154+
project.compileJava.dependsOn(createVersionFile)
155+
gversion {
156+
srcDir = "src/main/java/"
157+
classPackage = "frc.robot"
158+
className = "BuildConstants"
159+
dateFormat = "yyyy-MM-dd HH:mm:ss z"
160+
timeZone = "America/New_York"
161+
indent = " "
162+
}
163163

164164
// TODO: set this shit up
165165
// Create commit with working changes on event branches

src/main/java/frc/robot/Robot.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package frc.robot;
22

3+
import edu.wpi.first.wpilibj.Threads;
34
import edu.wpi.first.wpilibj2.command.Command;
45
import edu.wpi.first.wpilibj2.command.CommandScheduler;
56
import frc.robot.extras.simulation.field.SimulatedField;
@@ -74,7 +75,7 @@ public Robot() {
7475
public void robotPeriodic() {
7576
// TODO: test this!
7677
// Switch thread to high priority to improve loop timing
77-
// Threads.setCurrentThreadPriority(true, 99);
78+
Threads.setCurrentThreadPriority(true, 99);
7879

7980
// Runs the Scheduler. This is responsible for polling buttons, adding
8081
// newly-scheduled commands, running already-scheduled commands, removing
@@ -84,7 +85,7 @@ public void robotPeriodic() {
8485
CommandScheduler.getInstance().run();
8586

8687
// Return to normal thread priority
87-
// Threads.setCurrentThreadPriority(false, 10);
88+
Threads.setCurrentThreadPriority(false, 10);
8889
}
8990

9091
/** This function is called once when the robot is disabled. */
@@ -120,6 +121,7 @@ public void teleopInit() {
120121
if (m_autonomousCommand != null) {
121122
m_autonomousCommand.cancel();
122123
}
124+
m_robotContainer.teleopInit();
123125
}
124126

125127
/** This function is called periodically during operator control. */

src/main/java/frc/robot/extras/simulation/mechanismSim/swerve/BrushlessMotorSim.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,20 @@ public void update() {
359359
Voltage voltage =
360360
Volts.of(poseVoltController.calculate(getPosition().in(Radians), output));
361361
Voltage feedforwardVoltage =
362-
feedforward.calculate(getVelocity(), velocityForVolts(voltage));
362+
Volts.of(
363+
feedforward.calculate(
364+
getVelocity().in(RadiansPerSecond),
365+
velocityForVolts(voltage).in(RadiansPerSecond)));
363366
driveAtVoltage(feedforwardVoltage.plus(voltage));
364367
}
365368
case VELOCITY -> {
366369
Voltage voltage =
367370
Volts.of(veloVoltController.calculate(getVelocity().in(RadiansPerSecond), output));
368371
Voltage feedforwardVoltage =
369-
feedforward.calculate(getVelocity(), RadiansPerSecond.of(output));
372+
Volts.of(
373+
feedforward.calculate(
374+
getVelocity().in(RadiansPerSecond),
375+
RadiansPerSecond.of(output).in(RadiansPerSecond)));
370376
driveAtVoltage(voltage.plus(feedforwardVoltage));
371377
}
372378
}
@@ -381,14 +387,20 @@ public void update() {
381387
Amps.of(poseCurrentController.calculate(getPosition().in(Radians), output));
382388
Voltage voltage = voltsForAmps(current, getVelocity());
383389
Voltage feedforwardVoltage =
384-
feedforward.calculate(getVelocity(), velocityForVolts(voltage));
390+
Volts.of(
391+
feedforward.calculate(
392+
getVelocity().in(RadiansPerSecond),
393+
velocityForVolts(voltage).in(RadiansPerSecond)));
385394
driveAtVoltage(feedforwardVoltage.plus(voltage));
386395
}
387396
case VELOCITY -> {
388397
Current current =
389398
Amps.of(veloCurrentController.calculate(getPosition().in(Radians), output));
390399
Voltage feedforwardVoltage =
391-
feedforward.calculate(getVelocity(), RadiansPerSecond.of(output));
400+
Volts.of(
401+
feedforward.calculate(
402+
getVelocity().in(RadiansPerSecond),
403+
RadiansPerSecond.of(output).in(RadiansPerSecond)));
392404
Voltage voltage = voltsForAmps(current, getVelocity()).plus(feedforwardVoltage);
393405
driveAtVoltage(voltage);
394406
}

src/main/java/frc/robot/subsystems/swerve/moduleIO/SimulatedModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ public void setDesiredState(SwerveModuleState desiredState) {
108108
RadiansPerSecond.of(moduleSimulation.getDriveWheelFinalSpeedRadPerSec())
109109
.in(RotationsPerSecond),
110110
desiredDriveRPS))
111-
.plus(driveFF.calculate(RotationsPerSecond.of(desiredDriveRPS))));
111+
.plus(Volts.of(driveFF.calculate((desiredDriveRPS)))));
112112
moduleSimulation.requestTurnVoltageOut(
113113
Volts.of(
114114
turnPID.calculate(
115115
moduleSimulation.getTurnAbsolutePosition().getRotations(),
116116
desiredState.angle.getRotations()))
117-
.plus(turnFF.calculate(RotationsPerSecond.of(turnPID.getSetpoint().velocity))));
117+
.plus(Volts.of(turnFF.calculate(turnPID.getSetpoint().velocity))));
118118
}
119119

120120
@Override

0 commit comments

Comments
 (0)