Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,6 +70,8 @@ public Command arcadeDrive(DoubleSupplier forwardThrottle, DoubleSupplier rotati
}

public void periodic() {
drivetrainSim.periodic();
if (RobotBase.isSimulation()) {
drivetrainSim.periodic();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -60,6 +61,8 @@ public Command idle() {
}

public void periodic() {
sim.periodic();
if (RobotBase.isSimulation()) {
sim.periodic();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -63,6 +64,8 @@ public Command idle() {
}

public void periodic() {
sim.periodic();
if (RobotBase.isSimulation()) {
sim.periodic();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading