> For the complete documentation index, see [llms.txt](https://yams.yassrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yams.yassrobotics.com/documentation/tutorials/double-flywheel.md).

# Double FlyWheel

Learn how to program a double flywheel shooter, with a separate speed for each wheel.

## Intro

At the end of this tutorial you will have a **Double FlyWheel** shooter with two independently controlled flywheels that works in both real life and simulation with the same code! Double flywheels are used where the spin on the game piece matters: running one wheel faster than the other adds backspin or topspin to a shot.

{% hint style="info" %}
This tutorial does not use the `FlyWheel` class from the [Shooter/FlyWheels](https://yams.yassrobotics.com/documentation/tutorials/shooter-flywheels.md) tutorial. A `FlyWheel` drives one wheel, or several motors that always turn together, at one speed. Here each wheel needs its own speed, so the subsystem controls the two motor controllers directly. If you have not done the Shooter/FlyWheels tutorial, it is the easier place to start.
{% endhint %}

## What is a Double FlyWheel?

A double flywheel is a shooter with two separate flywheels, one on each side of the game piece:

* **Upper FlyWheel**: drives the top surface of the game piece
* **Lower FlyWheel**: drives the bottom surface of the game piece

<figure><img src="https://1354553280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZM0CFmYiQzcrY4zDcTtZ%2Fuploads%2Fgit-blob-82aa007e5ddc538d862713f91c45e15a014bd45d%2Ftutorial-double-flywheel-spin.gif?alt=media" alt="Animation of a ball passing between an upper and a lower flywheel, three times. With both at 3000 RPM the ball leaves with no spin and flies straight. With the lower flywheel faster, 3500 against 2500 RPM, it leaves with backspin and its path lifts. With the upper flywheel faster it leaves with topspin and its path dips."><figcaption><p>The faster wheel drags its side of the ball forward. Lower wheel faster is backspin; upper wheel faster is topspin.</p></figcaption></figure>

By running them at different speeds, you can:

* Add **backspin** (lower faster than upper)
* Add **topspin** (upper faster than lower)
* Shoot with **no spin** (equal speeds)

## Details

This double flywheel uses the following hardware and controls:

* Two `TalonFX` (Kraken X60), one for each flywheel
* No gearbox: each wheel is driven 1:1 from its motor. **Top speed = motor free speed / reduction**, so each wheel can reach about 6000 RPM (a Kraken X60's free speed) / 1 = 6000 RPM, comfortably above the 3500 RPM fastest preset. A 3:1 gearbox would cap it at 2000 RPM, too slow for these presets.
* 4 inch diameter, 1 pound flywheels
* Pressing the bottom face button (`A` on an Xbox controller) sets both flywheels to 3000 RPM (no spin)
* Pressing the right face button (`B` on an Xbox controller) sets the upper to 2500 RPM and the lower to 3500 RPM (backspin)
* Pressing the left face button (`X` on an Xbox controller) sets the upper to 3500 RPM and the lower to 2500 RPM (topspin)
* Pressing the top face button (`Y` on an Xbox controller) lets both flywheels coast to a stop

## The steps

<figure><img src="https://1354553280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZM0CFmYiQzcrY4zDcTtZ%2Fuploads%2Fgit-blob-566f3b4aca1e4516c9689be858992e904424ff9e%2Ftutorial-double-flywheel-steps.png?alt=media" alt="The three steps of the double flywheel tutorial. Step 1, two motor controllers: one config and one SmartMotorController for each flywheel. Step 2, commands and buttons: one command sets both speeds, with presets for no spin, backspin and topspin. Step 3, spin control and followers: a spin ratio between the wheels, and what to do when they share a shaft."><figcaption><p>Three steps, one page each. Then you tune it and run it on the robot.</p></figcaption></figure>

Every step has a tab for **Java with Commands v2**, **Java with Commands v3** and **C++**.

| Step                                                                                                                                | What you do                                                                                               |
| ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [Before you start](https://yams.yassrobotics.com/documentation/tutorials/project-setup.md)                                          | Create a WPILib project and install YAMS and Phoenix 6. Skip this if you already have a project.          |
| [Step 1: Two motor controllers](https://yams.yassrobotics.com/documentation/tutorials/double-flywheel/motor-controllers.md)         | One config and one `SmartMotorController` for each flywheel.                                              |
| [Step 2: Commands and buttons](https://yams.yassrobotics.com/documentation/tutorials/double-flywheel/commands.md)                   | One command that sets both speeds, presets for each kind of shot, the buttons, and a check in simulation. |
| [Step 3: Spin ratio and shared shafts](https://yams.yassrobotics.com/documentation/tutorials/double-flywheel/spin-and-followers.md) | A spin ratio between the wheels, and what to change when two motors drive one wheel.                      |
| [Step 4: Tune it](https://yams.yassrobotics.com/documentation/tutorials/double-flywheel/tune.md)                                    | Tune one wheel with the YAMS Live Tuner, copy its gains to the other, then put it on the robot.           |

{% hint style="info" %}
A subsystem should hold at most one YAMS mechanism class, so that live tuning keeps working. Both flywheels here are driven together by one subsystem, so this tutorial controls the two `SmartMotorController`s directly instead of creating two `FlyWheel` mechanisms. This is the same approach as the `DoubleFlyWheelSubsystem` in the YAMS examples.

If you would rather have a `FlyWheel` mechanism (with its `Mechanism2d` and Trigger factories) for each wheel, give each wheel its own subsystem and follow the [Shooter/FlyWheels](https://yams.yassrobotics.com/documentation/tutorials/shooter-flywheels.md) tutorial for both.
{% endhint %}

## Complete Example

The following files from the YAMS `simple_robot-2027` Commands v2 example show a complete double flywheel subsystem with two independent flywheels, and a hood pivot in its own subsystem. Its CAN IDs, gearing and gains differ from this tutorial's.

{% @github-files/github-code-block url="<https://github.com/Yet-Another-Software-Suite/YAMS/blob/master/examples/commands2/simple_robot-2027/src/main/java/first/robot/subsystems/doubleflywheel/DoubleFlyWheelSubsystem.java>" %}

{% @github-files/github-code-block url="<https://github.com/Yet-Another-Software-Suite/YAMS/blob/master/examples/commands2/simple_robot-2027/src/main/java/first/robot/subsystems/HoodSubsystem.java>" %}

The same subsystem in the other two flavors:

* **Java, Commands v3:** [`DoubleFlyWheelMechanism.java`](https://github.com/Yet-Another-Software-Suite/YAMS/blob/master/examples/commands3/simple_robot-2027/src/main/java/first/robot/mechanisms/doubleflywheel/DoubleFlyWheelMechanism.java) in `examples/commands3/simple_robot-2027`
* **C++:** [`DoubleFlyWheelSubsystem.h`](https://github.com/Yet-Another-Software-Suite/YAMS/blob/master/examples/cpptest/src/main/include/subsystems/doubleflywheel/DoubleFlyWheelSubsystem.h) and [`DoubleFlyWheelSubsystem.cpp`](https://github.com/Yet-Another-Software-Suite/YAMS/blob/master/examples/cpptest/src/main/cpp/subsystems/doubleflywheel/DoubleFlyWheelSubsystem.cpp) in `examples/cpptest`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://yams.yassrobotics.com/documentation/tutorials/double-flywheel.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
