Skip to content

Commit

Permalink
sim swap
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonwatson committed Oct 14, 2024
1 parent 9acf39f commit 2f30d3f
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 236 deletions.
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2024.3.2"
id "com.peterabeles.gversion" version "1.10"
id "com.dorongold.task-tree" version "4.0.0"
}

java {
Expand Down Expand Up @@ -127,7 +128,6 @@ jar {
from sourceSets.main.allSource
manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
finalizedBy("addProfiling")
}

// Configure jar and deploy tasks
Expand Down Expand Up @@ -161,8 +161,12 @@ gversion {
indent = " "
}

task(addProfiling, dependsOn: "jar", type: JavaExec) {
mainClass = "frc.tools.AddProfiling"
classes {
finalizedBy("addProfiling")
}

task(addProfiling, dependsOn: "classes", type: JavaExec) {
mainClass = "frc.tools.ModifyClasses"
classpath = sourceSets.tools.runtimeClasspath
systemProperties["java.library.path"] = new File(project.projectDir, "build/jni/release")
}
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/frc/lib/sim/TalonFX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package frc.lib.sim;

import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;

public class TalonFX implements MotorController, Sendable, AutoCloseable {

Check warning on line 7 in src/main/java/frc/lib/sim/TalonFX.java

View workflow job for this annotation

GitHub Actions / Linting

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./src/main/java/frc/lib/sim/TalonFX.java:7:1: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck)

public TalonFX(int deviceId, String canbus) {

}

public TalonFX(int deviceId) {
this(deviceId, "*");
}

@Override
public void close() throws Exception {
throw new UnsupportedOperationException("Unimplemented method 'close'");
}

@Override
public void initSendable(SendableBuilder builder) {
throw new UnsupportedOperationException("Unimplemented method 'initSendable'");
}

@Override
public void set(double speed) {
throw new UnsupportedOperationException("Unimplemented method 'set'");
}

@Override
public double get() {
throw new UnsupportedOperationException("Unimplemented method 'get'");
}

@Override
public void setInverted(boolean isInverted) {
throw new UnsupportedOperationException("Unimplemented method 'setInverted'");
}

@Override
public boolean getInverted() {
throw new UnsupportedOperationException("Unimplemented method 'getInverted'");
}

@Override
public void disable() {
throw new UnsupportedOperationException("Unimplemented method 'disable'");
}

@Override
public void stopMotor() {
throw new UnsupportedOperationException("Unimplemented method 'stopMotor'");
}

}
2 changes: 2 additions & 0 deletions src/main/java/frc/lib/util/swerve/SwerveModuleReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public SwerveModuleReal(int moduleNumber, int driveMotorID, int angleMotorID, in
mDriveMotor = new TalonFX(driveMotorID, "canivore");
mAngleMotor = new TalonFX(angleMotorID, "canivore");

System.out.println(mDriveMotor.getClass().getCanonicalName());

configAngleEncoder();
configAngleMotor();
configDriveMotor();
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@ public void robotPeriodic() {
profiler.startTick();
profiler.push("robotPeriodic()");
profiler.push("draw_state_to_shuffleboard");
if (hasStarted) {
profiler.endTick();
if (profileTimer.advanceIfElapsed(1)) {
if (hasDoneSomething) {
profiler.save();
profiler.reset();
}
}
} else {
hasStarted = true;
}
profiler.startTick();
profiler.push("robotPeriodic()");
profiler.push("draw_state_to_shuffleboard");
robotContainer.operatorState.setString(OperatorState.getCurrentState().displayName);
robotContainer.operatorManualMode.setBoolean(OperatorState.manualModeEnabled());
robotContainer.matchTime.setDouble(Timer.getMatchTime());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public RobotContainer(RobotRunType runtimeType) {
elevatorWrist = new ElevatorWrist(new ElevatorWristReal(), operator);
break;
case kSimulation:
s_Swerve = new Swerve(new SwerveIO() {}, cameras);
s_Swerve = new Swerve(new SwerveReal(), cameras);
shooter = new Shooter(new ShooterIO() {});
intake = new Intake(new IntakeIO() {});
elevatorWrist = new ElevatorWrist(new ElevatorWristIO() {}, operator);
Expand Down
218 changes: 0 additions & 218 deletions src/tools/java/frc/tools/AddProfiling.java

This file was deleted.

39 changes: 39 additions & 0 deletions src/tools/java/frc/tools/ModifyClasses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package frc.tools;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import frc.tools.modify.ClassTransformer;
import frc.tools.modify.SimReplace;

/** Class file modifier that adds profiling commands, replaces hardware in sim mode. */
public class ModifyClasses {

/** Entrypoint */
public static void main(String[] args) throws IOException {
ClassTransformer transformer = new ClassTransformer();
if (true) {
transformer.add(SimReplace::new);
}

List<Path> result;
try (Stream<Path> walk = Files.walk(Path.of("build/classes/java/main"))) {
result = walk.filter(Files::isRegularFile)
.filter(p -> p.getFileName().toString().endsWith(".class"))
.filter(p -> !p.getFileName().toString().endsWith("Robot$1.class"))
.collect(Collectors.toList());
}

for (Path p : result) {
byte[] input = Files.readAllBytes(p);
byte[] output = transformer.transform(input);
Files.write(p, output, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
}

}

}
Loading

0 comments on commit 2f30d3f

Please sign in to comment.