Skip to main content

Hub Shift Timer

Disclaimer: WIP and untested on 2026 hardware; validate timing and behavior on-robot and prefer FMS hub data when available. Custom code built on WPILib APIs (not official WPILib sample).

Purpose: Expose hub active/inactive state for drivers and commands, even if FMS data is missing.

What it does

  • Tracks match periods: 0:20 AUTO → 3 s buffer → TELEOP segments (TRANSITION 0:10, SHIFTS 1-4 at 0:25 each, END GAME 0:30).
  • Alternates hub-active flag each shift based on who won AUTO (pass in autoWinnerIsUs).
  • Publishes state to SmartDashboard and optional controller rumble.

Code (Java/WPILib)

public final class HubShiftTimer {
public enum HubState { ACTIVE, INACTIVE }
public record Status(double matchTimeSec, int shiftIndex, HubState ourHub, HubState oppHub) {}

private final Timer timer = new Timer();
private boolean autoWinnerIsUs = false;

public void start(boolean weWonAuto) {
autoWinnerIsUs = weWonAuto;
timer.reset(); timer.start();
}

public Status get() {
double t = timer.get();
if (t < 20.0) return new Status(t, -1, HubState.ACTIVE, HubState.ACTIVE); // AUTO
if (t < 23.0) return new Status(t, -1, HubState.ACTIVE, HubState.ACTIVE); // buffer
double tele = t - 23.0;
if (tele < 10.0) return new Status(t, 0, HubState.ACTIVE, HubState.ACTIVE); // TRANSITION
double shiftTime = tele - 10.0;
int shift = (int)(shiftTime / 25.0); // 0..3
if (shift >= 4) return new Status(t, 4, HubState.ACTIVE, HubState.ACTIVE); // END GAME
boolean ourActive = ((shift % 2 == 0) ? !autoWinnerIsUs : autoWinnerIsUs);
return new Status(t, shift + 1, ourActive ? HubState.ACTIVE : HubState.INACTIVE,
ourActive ? HubState.INACTIVE : HubState.ACTIVE);
}
}

Usage

HubShiftTimer shiftTimer = new HubShiftTimer();
// Call at match start with FMS auto result (fallback: false)
shiftTimer.start(autoWinnerIsUs);

// Periodic:
var status = shiftTimer.get();
SmartDashboard.putString("Hub State", status.ourHub().name());
SmartDashboard.putNumber("Shift Index", status.shiftIndex());

Parameters to tune

  • If FMS provides hub status directly, inject it and bypass timer.
  • Adjust buffer/segment durations if Team Updates change timings.

How to test

  • Simulate timeline: call start(true/false) and step timer to 0:00..2:40; verify shift states match Table 6-3.
  • On robot, display hub state and rumble controller when active to ensure drivers feel the transitions.

Pitfalls

  • Must reset at match start; stale timer gives wrong states.
  • If FMS hub data is available, prefer that over timer (timer is a fallback).