Skip to content

Allow configuring maximum target count#2338

Merged
mcm001 merged 24 commits intoPhotonVision:mainfrom
2826WaveRobotics:configurable-max-targets
Feb 2, 2026
Merged

Allow configuring maximum target count#2338
mcm001 merged 24 commits intoPhotonVision:mainfrom
2826WaveRobotics:configurable-max-targets

Conversation

@2826WaveRobotics
Copy link
Contributor

@2826WaveRobotics 2826WaveRobotics commented Jan 28, 2026

Description

We wanted to track more than 10 objects in an Object Detection pipeline, so we added a "Maximum Targets" setting for when "Show Multiple Targets" is enabled. The default value is 10, so no existing configuration should change, though a "Show multiple targets" setting is redundant in theory.

None of the documentation mentioned this 10-object limit, so nothing there changed for now.

image

I also did some homework on if we can at present send more than 127 targets. Across our decode clients

So just confirming that the correct current upper limit is 127. Any change to our pack/unpack code and datatypes silently breaks older unpack versions. this is deeply terrifying to me mid season. I should have included a schemaVersion so we can handle this in the protocol, but I didn't and now we're stuck with this until 2027.

  • and change all our pack/unpacking code to use unsigned bytes instead of signed. this gets us 255 maximum,
  • Change the datatype to uint16_t. This incurs a couple bytes * number of targets worth of overhead. Someone should figure out how many bytes this ends up being. see point 1
  • Make the length type itself variable length. If the value of VLA[0]=0xff, then also read in the next byte. This adds a branch instruction but saves one byte

Changes

  • New "Maximum Targets" slider in the UI. For apriltag/aruco pipelines, this is disabled and forced to 127 in the UI. For other pipelines this is adjustable between 1 and 127
  • Apriltag/aruco pipelines are limited to 127 targets in the backend, and will print a warning if this is ever exceeded
  • Adds unit test that slider is respected for colored shape, and apriltag detections are limited to 127 regardless of setting
image

Meta

Merge checklist:

  • Pull Request title is short, imperative summary of proposed changes
  • The description documents the what and why
  • If this PR changes behavior or adds a feature, user documentation is updated
  • If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly
  • If this PR touches configuration, this is backwards compatible with settings back to v2025.3.2
  • If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated
  • If this PR addresses a bug, a regression test for it is added

@2826WaveRobotics 2826WaveRobotics requested a review from a team as a code owner January 28, 2026 00:40
@github-actions github-actions bot added frontend Having to do with PhotonClient and its related items backend Things relating to photon-core and photon-server labels Jan 28, 2026
@2826WaveRobotics
Copy link
Contributor Author

2826WaveRobotics commented Jan 28, 2026

Moving from #2319 to allow contributors to edit.

Copy link
Contributor

@mcm001 mcm001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any tests showing that the upgrade logic works as expected?

@samfreund samfreund force-pushed the configurable-max-targets branch from b085972 to af01e64 Compare January 28, 2026 17:42
@samfreund
Copy link
Member

I don't see any tests showing that the upgrade logic works as expected?

I'd like to get #2331 in, then I'll use that config to test.

@Jake-Schuler
Copy link

This may be sorta irrelevant as this was a week ago but we did test it and were able to detect ~78ish fuel and we also lowered it down to one and it would choose the closest one. Here's an image of the change working to detect more than 10 (at the time) fuel.
image

@samfreund samfreund force-pushed the configurable-max-targets branch 2 times, most recently from 383c711 to 5c56037 Compare January 29, 2026 00:17
@samfreund samfreund requested a review from mcm001 January 29, 2026 16:51
@samfreund samfreund force-pushed the configurable-max-targets branch from 864ca60 to 91aa4a3 Compare January 29, 2026 16:51
@samfreund samfreund force-pushed the configurable-max-targets branch from c899cf8 to 553168a Compare January 30, 2026 06:07
@samfreund samfreund force-pushed the configurable-max-targets branch from 553168a to c470cca Compare January 30, 2026 06:07
Copy link
Contributor

@mcm001 mcm001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also looks to be missing new unit tests showing that the limit is respected. Would accept test evidence instead

@samfreund samfreund force-pushed the configurable-max-targets branch from f026a65 to b912fef Compare January 30, 2026 19:20
@samfreund samfreund force-pushed the configurable-max-targets branch from b912fef to f6a2f2c Compare January 30, 2026 19:21
@mcm001
Copy link
Contributor

mcm001 commented Jan 30, 2026

Right now:

So just confirming that the correct current upper limit is 127. Any change to our pack/unpack code and datatypes silently breaks older unpack versions. this is deeply terrifying to me mid season. I should have included a schemaVersion so we can handle this in the protocol, but I didn't and now we're stuck with this until 2027.

  • and change all our pack/unpacking code to use unsigned bytes instead of signed. this gets us 255 maximum,
  • Change the datatype to uint16_t. This incurs a couple bytes * number of targets worth of overhead. Someone should figure out how many bytes this ends up being. see point 1
  • Make the length type itself variable length. If the value of VLA[0]=0xff, then also read in the next byte. This adds a branch instruction but saves one byte

@samfreund samfreund force-pushed the configurable-max-targets branch from 32b2d52 to b22d54c Compare January 30, 2026 20:43
@mcm001 mcm001 enabled auto-merge (squash) January 31, 2026 17:13
mcm001
mcm001 previously approved these changes Jan 31, 2026
mcm001
mcm001 previously approved these changes Jan 31, 2026
@mcm001 mcm001 disabled auto-merge January 31, 2026 20:37
Copy link
Member

@Gold856 Gold856 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a bunch of off-by-one errors.

So just confirming that the correct current upper limit is 127

Sort of incorrect. The max number of targets is 128. The max index, therefore, must be 127. There are several instances of List#size being (incorrectly) directly compared to Byte.MAX_VALUE. The list size should be subtracted by one first.

There's also a bunch of duplicated code checking the list size in various different pipelines. There must be a better place to do that...

@mcm001
Copy link
Contributor

mcm001 commented Feb 1, 2026

Concur wrt the duplicated code, but j do think that the pipeline is the correct place for the limit to live.

However, there is not an off by one in my implementation. Java bytes max value is 127. 0 means 0 targets, 1 means one target, and 127 means 127 targets. 128 is not representable by a Java byte. Therefore the length of the target list must be on [0,127]. QED

@mcm001 mcm001 merged commit 09e6d45 into PhotonVision:main Feb 2, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Things relating to photon-core and photon-server frontend Having to do with PhotonClient and its related items

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants