Interpolating Double Tree Map

Woah that sounds scary

Using IDTM for Shooting Systems

In shooting games, adjusting shooter parameters dynamically based on the robot’s distance from the target is critical for accuracy and consistency. The InterpolatingDoubleTreeMap class provides a simple and effective way to map input values (like distance) to output parameters (like hood angle or flywheel speed) with smooth interpolation between known data points.


What is IDTM?

Think of it as a graph where you plot known data points (x, y), such as (distance, hood angle). The class connects these points with straight lines. When you query the map with any x (distance) value, it returns the corresponding interpolated y (parameter) value.

Example:

public static final InterpolatingDoubleTreeMap kMidOffsetMap = new InterpolatingDoubleTreeMap();
static {
    kMidOffsetMap.put(-0.112, -0.149804);
    kMidOffsetMap.put(0.0, 0.0);
}

This means when you ask for any value between -0.112 and 0.0, the map returns the corresponding y based on the line connecting these points.


Why is this useful in shooting games?

Distance to Hood Angle

The shooter’s hood angle needs to adjust depending on the target distance to achieve the correct projectile arc. Farther targets require a shallower angle, while closer ones need a steeper launch. By mapping distance to hood angle with an interpolating map, the robot can smoothly and automatically set the hood position without guesswork or hard-coded zones.

Distance to Shooter Wheel Velocity

Similarly, the flywheel velocity must increase as distance grows to maintain shot power. You can create another map from distance to flywheel RPM, ensuring your shooter spins up just enough for each shot.

Distance to Time for Moving Shots

For advanced shots while the robot is moving, it’s crucial to calculate the time it takes for the projectile to reach the target. By mapping distance to projectile travel time, you can:

  • Predict where the target will be when the ball arrives.

  • Adjust robot movement timing and shooting delay accordingly.

This allows your robot to move and shoot simultaneously with better accuracy, factoring in both robot velocity and ball flight time.


How to implement

  1. Collect Data Points: Measure optimal hood angles, flywheel speeds, and travel times at known distances.

  2. Build Maps: Use InterpolatingDoubleTreeMap to store these (distance, parameter) pairs. (Find examples in 2025/2024)

  3. Query Map: During runtime, get the robot’s current distance to target and retrieve interpolated values.

  4. Apply Outputs: Set hood angle, flywheel speed, or shooting delay dynamically based on the map output.

Example use for hood angle:

double distance = getDistanceToTarget();  // via vision or odometry
double hoodAngle = kDistanceToHoodAngle.getInterpolated(distance);
setHoodAngle(hoodAngle);

Benefits

  • Smooth transitions between discrete calibration points.

  • Reduces need for complex formulas or trial-and-error tuning.

  • Easily extendable by adding new calibration points.

  • Improves shooting accuracy by adapting continuously to distance.

  • Enables smarter shooting strategies while moving.

Last updated