Gray Matter LogoGray Matter Workshop

Dynamic Flywheel Control

Vision-Based Shooting with Dynamic Velocity

Using odometry data with an interpolating lookup table, your robot can shoot accurately from anywhere on the field.

Key Concept: Use swerve odometry and velocity mapping to achieve consistent shooting from any position without manual adjustment.

Instead of fixed shooting speeds, dynamic flywheel control adapts in real-time, making your robot more versatile and competitive during matches.

Why Dynamic Velocity Control?

Fixed Velocity Problems

  • Only accurate from one specific distance
  • Requires driver to position robot precisely
  • Wastes time moving to "sweet spot" locations
  • Limited strategic positioning options
  • Multiple preset buttons needed for different zones

Dynamic Velocity Benefits

  • Shoot accurately from anywhere on the field
  • Automatic velocity adjustment—no driver input needed
  • Faster scoring cycles (shoot from current position)
  • More strategic flexibility during matches
  • Single button command handles all distances

Understanding Distance-to-Velocity Mapping

The core of dynamic flywheel control is an InterpolatingTreeMap—a data structure that stores known distance-velocity pairs and automatically calculates velocities for distances in between.

How InterpolatingTreeMap Works

You provide key distance-velocity pairs, and the map fills in the gaps automatically using linear interpolation.

Example Mapping:

Distance: 1.0 m→ Velocity: 10 RPS
Distance: 2.0 m→ Velocity: 30 RPS
Distance: 3.0 m→ Velocity: 60 RPS

📊 Automatic Interpolation:

If your robot is at 1.5 meters (between 1.0 and 2.0), the map automatically calculates:

Velocity = 10 + (30 - 10) × (1.5 - 1.0) / (2.0 - 1.0) = 20 RPS

Linear interpolation ensures smooth velocity transitions as the robot moves around the field.

Implementation Guide

1

Set Up the Lookup Table

Create an InterpolatingTreeMap and populate it with distance-velocity pairs based on testing.

Flywheel Subsystem ConstructorJAVA

Tuning Tip

Start with a few key distance points, then add more data through testing. You don't need every possible distance—interpolation handles the values in between!

2

Calculate Distance to Target

Use your swerve drivetrain's odometry to get the robot's position, then calculate distance to the target.

Periodic Distance UpdateJAVA

🎯 Target Position

The target is a fixed field position (e.g., speaker center). In this example, it's at coordinates (3, 5). Update this based on your field layout and game objectives.

3

Create the Distance Shoot Command

This command continuously queries the lookup table and adjusts flywheel velocity as the robot moves.

Dynamic Velocity CommandJAVA

✨ Automatic Adjustment

As the robot drives around, the periodic() method updates distance, and the command automatically queries the new velocity. No manual intervention required!

Workshop Implementation: Dynamic Flywheel

See the complete implementation in the Workshop-Code repository. The 4-DynamicFlywheel branch shows how all the pieces fit together in a real subsystem.

Loading file...

Tuning Your Velocity Map

📋 Step-by-Step Tuning Process
1

Start with closest or farthest distance

Put your robot at the closest or farthest distance from the target and manually tune the flywheel velocity until shots are accurate.

2

Test at Key Distances

Position your robot at specific distances (1m, 2m, 3m, etc.) and manually tune the flywheel velocity until shots are consistently successful.


Test Systematically

Test each distance multiple times to account for variability. Record the velocity that gives the best consistency, not just a single lucky shot.

3

Record Successful Velocities

Log the distance and corresponding velocity for each successful test. Create a table of proven data points.

Distance (m)Velocity (RPS)Success Rate
1.010.095%
2.030.090%
3.060.092%
4

Populate the TreeMap

Add your tested distance-velocity pairs to the lookup table in your code. Start with 3-5 key points.

Updated Lookup TableJAVA
5

Let Interpolation Fill the Gaps

Test at intermediate distances (1.5m, 2.5m, etc.) to verify that interpolation is giving good results. Fine-tune by adding more data points if needed.

Pro Tip: Try not to add too many points. It is only recommended to add points when you start missing.