For the complete documentation index, see llms.txt. This page is also available as Markdown.

How do I shoot with a shooter?

Goal: hold a button to spin the shooter up, and have the feeder push the game piece in only once the wheel is at speed.

A shot has three parts:

  1. Spin up: the shooter FlyWheel goes to a speed and holds it.

  2. Wait for speed: a Trigger turns true once the wheel has been near that speed for 0.1 seconds.

  3. Feed: the feeder FlyWheel pushes the game piece into the wheel while the trigger is true.

Before you start: build the shooter as in the Shooter/FlyWheels tutorial, and a feeder the same way as the intake in How do I set up an intake roller?, with its intake() command renamed feed(). The feeder keeps the intake's default command that stops it: stop() in Commands v2, idle() in Commands v3. The shooter and the feeder are separate subsystems, one YAMS mechanism each, so each can run its own command at the same time.

Animation of a flywheel spinning up to 3000 RPM and shooting two balls, with a band of 100 RPM around the setpoint. Each shot drops the speed by several hundred RPM, and it overshoots and rings as it recovers. A lane for the at speed trigger is true inside the band, including for an instant each time the speed passes through it. A lane for the feeder, which uses the trigger with a 0.1 second debounce, is only true once the speed has stayed in the band, so the second ball is not fed until the wheel has settled.
Each shot slows the wheel and it rings as it recovers. The tolerance band and a debounce keep the feeder off until it has settled.
1

Spin up

Use the tutorial's shooter config as it is. Its gearing and gains are what let the wheel reach the shot speed: a NEO through a 1.5:1 reduction tops out near 3800 RPM at the wheel, kV of 0.19 volts per rotation per second gets it close to the target on feedforward alone, and kP of 0.2 fixes the rest and recovers after each shot. If your shooter has different gearing, find your own kV as in the tutorial's Tune it step: a first guess is 12 volts divided by the wheel's free speed in rotations per second.

Add these two methods to the shooter class:

Declare both in ShooterSubsystem.hpp, as the tutorial's commands step does for Run and AtSpeed.

The tutorial's atSpeed uses a 50 RPM tolerance and no debounce, which is fine for watching the wheel. Feeding needs the wider tolerance and the debounce: see the next step.

Check it: the code builds.

2

Wait for speed

Every shot takes speed out of the wheel, and the speed overshoots and rings as the closed loop brings it back. The 100 RPM tolerance keeps ready false while the wheel is too slow or too fast. The speed still passes through the tolerance for an instant on each swing, and the 0.1 second debounce ignores that: ready only turns true once the speed has stayed inside the tolerance. Without the debounce, the feeder pulses while the wheel is still ringing.

For a plain boolean outside of a Trigger, FlyWheel also has isNear(speed, tolerance).

Check it: you know the shot speed you will use, and it is well below the wheel's top speed of about 3800 RPM.

3

Feed

Bind both to the same button. The shooter spins up as soon as the button is held, and the feeder only runs while the button is held and the shooter is ready.

Check it: the code builds, and holding the right trigger in simulation spins the shooter up.

Check it

  1. Start the simulation, and graph NT:/Mechanisms/Shooter/ShooterMotor/mechanism/velocity (rotations per second; 3000 RPM is 50) and the feeder's NT:/Mechanisms/Feeder/FeederMotor/motor/outputVoltage in AdvantageScope. Feeder and FeederMotor are the telemetry names you gave the feeder's configs.

  2. Hold the right trigger. The shooter's speed should rise to about 50 rotations per second.

  3. The feeder's voltage should go to 8 volts only after the shooter's speed has settled, not while it is still climbing.

If it did not work

  • The wheel settles below 3000 RPM and the feeder never runs. kV is too low (or 0). Raise it until the wheel gets close on its own, then tune kP.

  • The wheel never gets near 3000 RPM, even at full voltage. The gearing is too slow. Check withGearing: the motor's free speed divided by the reduction must be well above the shot speed.

  • The feeder pulses on and off. The tolerance is too tight, or the debounce is missing. Try 100 to 150 RPM and 0.1 seconds.

  • Something else. See Troubleshooting.

Last updated

Was this helpful?