Skip to content
Open
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 @@ -21,6 +21,7 @@
import org.wpilib.hardware.imu.OnboardIMU;
import org.wpilib.hardware.imu.OnboardIMU.MountOrientation;

// [CheckUpDrivetrain]
public class Drivetrain implements Mechanism {
private static final int leftLeaderID = 0, rightLeaderID = 2;
private final TalonFX leftLeader = new TalonFX(leftLeaderID, new CANBus(CANPort.CAN_S0));
Expand Down Expand Up @@ -76,3 +77,4 @@ public void periodic() {
}
}
}
// [/CheckUpDrivetrain]
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.wpilib.framework.RobotBase;
import org.wpilib.hardware.bus.CANPort;

// [CheckupFeeder]
public class Feeder implements Mechanism {
private final TalonFX motor = new TalonFX(5, new CANBus(CANPort.CAN_S0));
private final SingleFlywheelSim sim = SingleFlywheelSim.forFeeder(motor);
Expand Down Expand Up @@ -67,3 +68,4 @@ public void periodic() {
}
}
}
// [/CheckupFeeder]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.wpilib.framework.RobotBase;
import org.wpilib.hardware.bus.CANPort;

// [CheckupIntake]
public class IntakeLauncher implements Mechanism {
private final TalonFX motor = new TalonFX(4, new CANBus(CANPort.CAN_S0));
private final SingleFlywheelSim sim = SingleFlywheelSim.forIntakeLauncher(motor);
Expand Down Expand Up @@ -70,3 +71,4 @@ public void periodic() {
}
}
}
// [/CheckupIntake]
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.wpilib.hardware.imu.OnboardIMU;
import org.wpilib.hardware.imu.OnboardIMU.MountOrientation;

// [CheckUpDrivetrain]
public class Drivetrain implements Mechanism {
private final SparkMax leftLeader = new SparkMax(CANPort.CAN_S0, 0, MotorType.kBrushless);
private final SparkMax leftFollower = new SparkMax(CANPort.CAN_S0, 1, MotorType.kBrushless);
Expand Down Expand Up @@ -79,3 +80,4 @@ public void periodic() {
}
}
}
// [/CheckUpDrivetrain]
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.wpilib.framework.RobotBase;
import org.wpilib.hardware.bus.CANPort;

// [CheckupFeeder]
public class Feeder implements Mechanism {
private final SparkMax motor = new SparkMax(CANPort.CAN_S0, 5, MotorType.kBrushless);
private final SingleFlywheelSim sim = SingleFlywheelSim.forFeeder(motor);
Expand Down Expand Up @@ -67,3 +68,4 @@ public void periodic() {
}
}
}
// [/CheckupFeeder]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.wpilib.framework.RobotBase;
import org.wpilib.hardware.bus.CANPort;

// [CheckupIntake]
public class IntakeLauncher implements Mechanism {
private final SparkMax motor = new SparkMax(CANPort.CAN_S0, 4, MotorType.kBrushless);
private final SingleFlywheelSim sim = SingleFlywheelSim.forIntakeLauncher(motor);
Expand Down Expand Up @@ -70,3 +71,4 @@ public void periodic() {
}
}
}
// [/CheckupIntake]
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ title: Exercise - Kitbot Rewrite, Pt. 2
description: Rewriting the kitbot code in stage 1A to command-based
codeRegionSources:
default: stage1/stage1b/snippets/src/main/java/sources/CommandBasedKitbotPt2.java
checkUpDrivetrainCTRE: stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Drivetrain.java
checkUpDrivetrainREV: stage1/stage1b/solutions/rev/src/main/java/first/robot/mechanisms/Drivetrain.java
---

import Aside from '@components/Aside.astro';
import { REV_CTRE_CHOOSER_KEY } from '@data/tabsSyncKeys.ts';
import { TabItem, Tabs } from '@astrojs/starlight/components';

### What You'll Accomplish

Expand Down Expand Up @@ -91,6 +95,26 @@ Now that we have a `Drivetrain` class, we need to set it up to be used in our ro
command set in the constructor (`idle()`) will apply.
</Aside>

### Check Up

By now your Drivetrain mechanism should look like this and VS code should not be giving you any errors.

<Aside type="answer" title="Solution">
<Tabs syncKey={REV_CTRE_CHOOSER_KEY}>
<TabItem label="CTRE">
```java {checkUpDrivetrainCTRE}#CheckUpDrivetrain
```

</TabItem>
<TabItem label="REV">
```java {checkUpDrivetrainREV}#CheckUpDrivetrain
```

</TabItem>
</Tabs>

</Aside>

### Task 4: Create Auto Mode Files

We need to create two new files to define our autonomous OpModes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ title: Exercise - Kitbot Rewrite, Pt. 1
description: Rewriting the kitbot code in stage 1A to command-based
codeRegionSources:
default: stage1/stage1b/snippets/src/main/java/sources/CommandBasedKitbot.java
checkUpFeederCTRE: stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/Feeder.java
checkUpFeederREV: stage1/stage1b/solutions/rev/src/main/java/first/robot/mechanisms/Feeder.java
checkUpIntakeCTRE: stage1/stage1b/solutions/ctre/src/main/java/first/robot/mechanisms/IntakeLauncher.java
checkUpIntakeREV: stage1/stage1b/solutions/rev/src/main/java/first/robot/mechanisms/IntakeLauncher.java
---

import Aside from '@components/Aside.astro';
Expand Down Expand Up @@ -42,7 +46,7 @@ Then, navigate to the `Robot` class under `src/main/java/first/robot`.
For commands to function, you must call `Scheduler.getDefault().run()` in
the robot class' `robotPeriodic()` method.

```java #robotDef
```java {default}#robotDef

```

Expand All @@ -64,7 +68,7 @@ The `Feeder` class should implement `Mechanism`.

<Aside type="hint">
A mechanism is defined as a class with the `implements Mechanism` keyword at the end.
```java #feederDef
```java {default}#feederDef

```

Expand Down Expand Up @@ -137,7 +141,7 @@ Then, add the following:
After completing all of that, copy-paste the following code into the `Feeder` class
to allow for simulation to work:

```java #feederSim
```java {default}#feederSim

```

Expand Down Expand Up @@ -259,6 +263,36 @@ Which method should it be?
What method in the `Robot` class has the word `periodic` in it?
</Aside>

### Check Up

By now your Feeder and IntakeLauncher mechanisms should look like this and VS code should not be giving you any errors.

<Aside type="answer" title="Solution: Feeder.java">
<Tabs syncKey={REV_CTRE_CHOOSER_KEY}>
<TabItem label="CTRE">
```java {checkUpFeederCTRE}#CheckupFeeder
```
</TabItem>
<TabItem label="REV">
```java {checkUpFeederREV}#CheckupFeeder
```
</TabItem>
</Tabs>
</Aside>

<Aside type="answer" title="Solution: IntakeLauncher.java">
<Tabs syncKey={REV_CTRE_CHOOSER_KEY}>
<TabItem label="CTRE">
```java {checkUpIntakeCTRE}#CheckupIntake
```
</TabItem>
<TabItem label="REV">
```java {checkUpIntakeREV}#CheckupIntake
```
</TabItem>
</Tabs>
</Aside>

### Task 5: Finish the teleop OpMode

In the constructor of the teleop OpMode (it should be in `MyTeleop.java`),
Expand Down
Loading