Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to non static library loading for JNI #6911

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ThadHouse
Copy link
Member

Static library loading causes a lot of trouble for tools, and also some indeterminism. It's generally only useful for robot projects and tests. However, even for tests its not as useful because HAL.Initialize is generally required.

This PR changes the default to not load libraries on static initialization. It can still be enabled the same way old apps used to disable it.

For robot projects, this is basically not a behavior change. Right at the beginning of startRobot, we load the required libraries (ntcore, wpinet, wpimath, hal and wpiutil). We then set all the vision libraries (april tag, opencv and cscore) to load when statically requested. Since these libraries are resource intensive, we don't want to load them by default.

This broke most of our test projects. A test extension was added to force initialize the right things.

This also broke the example unit tests. All of these tests already have a call to Hal.initialize. That Hal.initialize call is magic, because it includes 2 magic numbers that we never change. To solve this, a new method has been added; RobotBase.loadLibrariesAndInitializeHal(). This returns a boolean like Hal.Initialize used to do, but also sets up the libraries exactly like a robot project does (in fact this is the method now called in robotbase). Users would change their manual calls to Hal.Initialize to this new method, and things would just work.

@ThadHouse ThadHouse requested review from PeterJohnson and a team as code owners August 2, 2024 06:53
Copy link
Contributor

github-actions bot commented Aug 2, 2024

This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR.

@ThadHouse
Copy link
Member Author

2 Open questions.

  1. Is AprilTagJni exclusively a vision library, or are there cases it would be called with just a Pose?
  2. Should we force load all the vision libraries on the roboRIO 2. We have the memory to do so, and it does solve a weird case that happens between CameraServer and Opencv.

@Gold856
Copy link
Contributor

Gold856 commented Aug 3, 2024

  1. Yes, AprilTagJNI is exclusively a vision library. It's a Java wrapper around the AprilTag detector (and offers functionality to create AprilTag images).
  2. I think most teams don't use OpenCV and just use a coprocessor. I think it's better to avoid using the extra memory for the majority of teams that don't do vision processing on the RIO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants