diff --git a/examples/stage1/stage1b/snippets/src/main/java/sources/CommandBasedKitbot.java b/examples/stage1/stage1b/snippets/src/main/java/sources/CommandBasedKitbot.java index 196a2c4f..2ccc9080 100644 --- a/examples/stage1/stage1b/snippets/src/main/java/sources/CommandBasedKitbot.java +++ b/examples/stage1/stage1b/snippets/src/main/java/sources/CommandBasedKitbot.java @@ -10,6 +10,7 @@ import org.wpilib.command3.Scheduler; import org.wpilib.command3.button.CommandXboxController; import org.wpilib.framework.OpModeRobot; +import org.wpilib.framework.RobotBase; import org.wpilib.opmode.PeriodicOpMode; class CommandBasedKitbot { @@ -48,7 +49,9 @@ public MyTeleop(Robot robot) { private final SingleFlywheelSim sim = new SingleFlywheelSim(motor, "Feeder"); // Create a flywheel simulation public void periodic() { // Update the simulation - sim.periodic(); + if (RobotBase.isSimulation()) { + sim.periodic(); + } } // [/feederSim] diff --git a/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Drivetrain.java b/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Drivetrain.java index 33be5508..b754d478 100644 --- a/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Drivetrain.java +++ b/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Drivetrain.java @@ -16,6 +16,7 @@ import org.wpilib.command3.Command; import org.wpilib.command3.Mechanism; import org.wpilib.drive.DifferentialDrive; +import org.wpilib.framework.RobotBase; import org.wpilib.hardware.imu.OnboardIMU; import org.wpilib.hardware.imu.OnboardIMU.MountOrientation; @@ -69,6 +70,8 @@ public Command arcadeDrive(DoubleSupplier forwardThrottle, DoubleSupplier rotati } public void periodic() { - drivetrainSim.periodic(); + if (RobotBase.isSimulation()) { + drivetrainSim.periodic(); + } } } diff --git a/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Feeder.java b/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Feeder.java index 4e687920..cdfdcd81 100644 --- a/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Feeder.java +++ b/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Feeder.java @@ -10,6 +10,7 @@ import first.robot.simulation.SingleFlywheelSim; import org.wpilib.command3.Command; import org.wpilib.command3.Mechanism; +import org.wpilib.framework.RobotBase; public class Feeder implements Mechanism { private final TalonFX motor = new TalonFX(5, CANBus.systemcore(0)); @@ -60,6 +61,8 @@ public Command idle() { } public void periodic() { - sim.periodic(); + if (RobotBase.isSimulation()) { + sim.periodic(); + } } } diff --git a/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/IntakeLauncher.java b/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/IntakeLauncher.java index 7670eb00..6e977c06 100644 --- a/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/IntakeLauncher.java +++ b/examples/stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/IntakeLauncher.java @@ -12,6 +12,7 @@ import first.robot.simulation.SingleFlywheelSim; import org.wpilib.command3.Command; import org.wpilib.command3.Mechanism; +import org.wpilib.framework.RobotBase; public class IntakeLauncher implements Mechanism { private final TalonFX motor = new TalonFX(4, CANBus.systemcore(0)); @@ -63,6 +64,8 @@ public Command idle() { } public void periodic() { - sim.periodic(); + if (RobotBase.isSimulation()) { + sim.periodic(); + } } } diff --git a/src/content/docs/learning-course/stage1/stage1b/command-based-kitbot.mdx b/src/content/docs/learning-course/stage1/stage1b/command-based-kitbot.mdx index c6dcf3b2..e2a33281 100644 --- a/src/content/docs/learning-course/stage1/stage1b/command-based-kitbot.mdx +++ b/src/content/docs/learning-course/stage1/stage1b/command-based-kitbot.mdx @@ -160,6 +160,7 @@ to allow for simulation to work: ``` This code creates a `SingleFlywheelSim` object named `sim` that simulates the feeder by representing it as a single spinning flywheel, then updates the simulation in `sim.periodic()`. +The code checks if it is being simulated before updating the sim so the simulation code is not run when the robot is real. ### Task 3: The IntakeLauncher Mechanism