Compare commits

...

1817 Commits

Author SHA1 Message Date
Tyler Veness
2f310a748c [wpimath] Fix DCMotor.getSpeed() (#5061)
This bug didn't occur in C++ because the units system caught it at
compile time.
2023-02-05 13:21:16 -08:00
Nick Hadley
b43ec87f57 [wpilib] ElevatorSim: Fix WouldHitLimit methods (#5057) 2023-02-05 11:58:53 -08:00
Peter Johnson
19267bef0c [ntcore] Output warning on property set on unpublished topic (#5059)
Previously this was a debug-level message. This can primarily impact
users who call SetPersistent() on an entry before calling SetDefault().
2023-02-05 11:57:29 -08:00
Peter Johnson
84cbd48d84 [ntcore] Handle excludeSelf on SetDefault (#5058) 2023-02-05 11:57:09 -08:00
Peter Johnson
1f35750865 [cameraserver] Add GetInstance() to all functions (#5054)
GetInstance() is required to start the event listener that creates the
network table entries.

This is a C++ only change; Java uses static's and thus doesn't need this.

The right fix is to implement cscore's AddListener() immediate notification,
but that's much too invasive of a change to do this year.

This fixes the common use cases, but doesn't fix all cases, as e.g. creating
a UsbCamera manually before calling any CameraServer functions will still
have the issue, but there's an easy workaround--call
CameraServer::SetSize() prior to creating any cameras.
2023-02-05 11:28:53 -08:00
Peter Johnson
8230fc631d [wpilib] Revert throw on nonexistent SimDevice name in SimDeviceSim (#5053)
This breaks current vendor use of SimDeviceSim.

This reverts commit d991f6e435 (#5041).
2023-02-05 11:27:55 -08:00
Peter Johnson
b879a6f8c6 [wpinet] WebSocket: When Close() is called, call closed immediately (#5047)
This provides the closed callback with the real reason for the
connection being closed.  Keep closed from being called twice by adding
a check in SetClosed().
2023-02-03 22:59:19 -08:00
Peter Johnson
49459d3e45 [ntcore] Change wire timeout to fixed 1 second (#5048)
Previously the timeout was 10 times the update rate, so with low update
rates it could be as small as 50 ms, causing spurious disconnects when
large or many topics were published.
2023-02-03 22:05:41 -08:00
Jordan McMichael
4079eabe9b [wpimath] Discard stale pose estimates (#5045)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2023-02-03 22:04:30 -08:00
Peter Johnson
fe5d226a19 [glass] Fix option for debug-level NT logging (#5049) 2023-02-03 22:03:45 -08:00
Peter Johnson
b7535252c2 [ntcore] Don't leak buffers in rare WS shutdown case (#5046)
If the request called the callback after the WebSocket had been
destroyed, the buffers were leaked.
2023-02-03 21:56:35 -08:00
Peter Johnson
b61ac6db33 [ntcore] Add client disconnect function (#5022)
As setServer doesn't disconnect, it's useful to have a function that
disconnects without needing to completely stop the client.
2023-02-03 15:28:00 -08:00
Ryan Blue
7b828ce84f [wpimath] Add nearest to Pose2d and Translation2d (#4882)
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
2023-02-03 15:27:16 -08:00
Michael Leong
08a536291b [examples] Improvements to Elevator Simulation Example (#4937)
Co-authored-by: Abhay Shukla <105139789+aboombadev@users.noreply.github.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
2023-02-03 15:23:06 -08:00
Peter Johnson
193a10d020 [wpigui] Limit frame rate to 120 fps by default (#5030)
Limiting with vsync is apparently unreliable on a number of systems;
this resulted in high CPU/GPU usage.

Also add current actual frame rate to about dialog of GUI tools.
2023-02-03 15:21:52 -08:00
sciencewhiz
7867bbde0e [wpilib] Clarify DS functions provided by FMS (NFC) (#5043) 2023-02-03 15:21:12 -08:00
Peter Johnson
fa7c01b598 [glass] Add option for debug-level NT logging (#5007) 2023-02-03 15:20:03 -08:00
truher
2b81610248 [wpiutil] Add msgpack to datalog Python example (#5032) 2023-02-03 15:19:44 -08:00
Tyler Veness
a4a369b8da CONTRIBUTING.md: Add unicodeit CLI to math docs guidelines (#5031) 2023-02-03 15:19:01 -08:00
Ryan Blue
d991f6e435 [wpilib] Throw on nonexistent SimDevice name in SimDeviceSim constructor (#5041)
Previously this would just create a object that was otherwise non-functional.
2023-02-03 15:18:31 -08:00
Peter Johnson
a27a047ae8 [hal] Check for null in getSimDeviceName JNI (#5038) 2023-02-01 23:25:55 -08:00
Starlight220
2f96cae31a [examples] Hatchbots: Add telemetry (#5011) 2023-01-31 23:44:18 -08:00
Peter Johnson
83ef8f9658 [simulation] GUI: Fix buffer overflow in joystick axes copy (#5036)
This was using an incorrect sizeof which would copy excessive data and
overwrite the button data.
2023-01-31 23:40:22 -08:00
Starlight220
4054893669 [commands] Fix C++ Select() factory (#5024)
Update example to use it.
2023-01-29 07:23:12 -08:00
Sriman Achanta
f75acd11ce [commands] Use Timer.restart() (#5023) 2023-01-29 07:21:07 -08:00
Tyler Veness
8bf67b1b33 [wpimath] PIDController::Calculate(double, double): update setpoint flag (#5021)
Fixes #5020.
2023-01-29 07:18:48 -08:00
Peter Johnson
49bb1358d8 [wpiutil] MemoryBuffer: Fix GetMemoryBufferForStream (#5017)
This would previously just write past the end of the buffer, smashing
the stack.  It's only called in the case when a non-file or block device
is used as the file.
2023-01-28 22:38:34 -08:00
Peter Johnson
9c4c07c0f9 [wpiutil] Remove NDEBUG check for debug-level logging (#5018)
This adds minimal overhead but is useful when debugging release
binaries.
2023-01-28 14:13:58 -08:00
Peter Johnson
1a47cc2e86 [ntcore] Use full handle when subscribing (#5013)
Just using the index is insufficient because of Subscriber overlap with
MultiSubscriber.
2023-01-27 09:14:38 -08:00
Ryan Blue
7cd30cffbc Ignore networktables.json (#5006) 2023-01-26 09:21:58 -08:00
DeltaDizzy
92aecab2ef [commands] Command controllers are not subclasses (NFC) (#5000) 2023-01-25 15:20:29 -08:00
Peter Johnson
8785bba080 [ntcore] Special-case default timestamps (#5003)
Previously, a setDefault() on the server could override a client doing a
real set() if the time offset between client and server was negative,
resulting in a negative timestamp from the client.  This is a not
uncommon situation with robot code, as the robot code always starts at
time 0, so any clients that set values earlier (in real time) would have
negative timestamps.

Also improve special casing of 0 in the transmit side to make sure a
normal timestamp will never get sent as 0.
2023-01-25 11:36:13 -08:00
Peter Johnson
9e5b7b8040 [ntcore] Handle topicsonly followed by value subscribe (#4991)
Previously this wouldn't send the last value on the value subscribe if a
topics only subscription already existed.

Also start adding server implementation unit tests.
2023-01-24 21:50:38 -08:00
Sriman Achanta
917906530a [wpilib] Add Timer::Restart() (#4963) 2023-01-23 14:50:46 -08:00
Tyler Veness
00aa66e4fd [wpimath] Remove extraneous assignments from DiscretizeAB() (#4967) 2023-01-23 09:46:12 -08:00
Starlight220
893320544a [examples] C++ RamseteCommand: Fix units (#4954)
Also fix the memory leak in the command-based auto.
2023-01-22 11:20:35 -08:00
Evan
b95d0e060d [wpilib] XboxController: Fix docs discrepancy (NFC) (#4993)
Comments for leftTrigger said they attach to the right trigger of the controller.
2023-01-21 22:09:55 -08:00
Peter Johnson
008232b43c [ntcore] Write empty persistent file if none found (#4996)
This avoids the warning appearing on every startup when persistent
values aren't used.

Also add note to message saying it can be ignored if persistent values
aren't expected.
2023-01-21 22:09:24 -08:00
Starlight220
522be348f4 [examples] Rewrite tags (NFC) (#4961) 2023-01-21 15:24:10 -08:00
Tyler Veness
d48a83dee2 [wpimath] Update Wikipedia links for quaternion to Euler angle conversion (NFC) (#4995) 2023-01-21 15:16:35 -08:00
Peter Johnson
504fa22143 [wpimath] Workaround intellisense Eigen issue (#4992)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2023-01-21 15:16:12 -08:00
Brady Schindler
b2b25bf09f [commands] Fix docs inconsistency for toggleOnFalse(Command) (NFC) (#4978) 2023-01-20 23:47:37 -08:00
Thad House
ce3dc4eb3b [hal] Properly use control word that is in sync with DS data (#4989) 2023-01-20 23:46:56 -08:00
Thad House
1ea48caa7d [wpilib] Fix C++ ADXRS450 and Java SPI gyro defs (#4988) 2023-01-20 13:25:13 -08:00
Thad House
fb101925a7 [build] Include wpimathjni in commands binaries (#4981) 2023-01-19 22:05:32 -08:00
Thad House
657951f6dd [starter] Add a process starter for use by the installer for launching tools (#4931) 2023-01-19 20:09:35 -08:00
Tyler Veness
a60ca9d71c [examples] Update AprilTag field load API usage (#4975) 2023-01-19 17:01:17 -08:00
Tyler Veness
f8a45f1558 [wpimath] Remove print statements from tests (#4977) 2023-01-19 17:00:35 -08:00
sciencewhiz
ecba8b99a8 [examples] Fix swapped arguments in MecanumControllerCommand example (#4976) 2023-01-18 21:25:49 -08:00
Berke Sinan Yetkin
e95e88fdf9 [examples] Add comment to drivedistanceoffboard example (#4877)
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
2023-01-18 20:46:41 -08:00
CarloWoolsey
371d15dec3 [examples] Add Computer Vision Pose Estimation and Latency Compensation Example (#4901)
This PR updates the existing differentialdriveposeestimator example to include computer vision pose estimation and latency compensation.

The example generates a simulated cameraToTarget transformation, which is then fed into ComputerVisionUtil.objectToRobotPose() to compute the robot's field-relative position exclusively from vision measurements. The vision measurements are applied through DifferentialDrivePoseEstimator.addVisionMeasurement().

The updated example constructs an AprilTagFieldLayout from JSON. This requires a deploy directory, something which isn't currently supported in wpilibjExamples and wpilibcExamples.
2023-01-18 20:46:05 -08:00
Peter Johnson
cb9b8938af [sim] Enable docking in the GUI (#4960) 2023-01-18 20:42:58 -08:00
Brennen Puth
3b084ecbe0 [apriltag] AprilTagFieldLayout: Improve API shape for loading builtin JSONs (#4949) 2023-01-18 20:42:39 -08:00
Matt
27ba096ea1 [wpilib] Fix MOI calculation error in SingleJointedArmSim (#4968)
Previous calculation derivation mixed up length and distance to CG.
2023-01-18 20:40:39 -08:00
Jordan McMichael
42c997a3c4 [wpimath] Fix Pose3d exponential and clean up Pose3d logarithm (#4970)
Implementation based on this paper: https://ethaneade.org/lie.pdf
2023-01-18 20:38:03 -08:00
Tyler Veness
5f1a025f27 [wpilibj] Fix typo in MecanumDrive docs (NFC) (#4969) 2023-01-18 13:47:27 -08:00
Tyler Veness
0ebf79b54c [wpimath] Fix typo in Pose3d::Exp() docs (NFC) (#4966) 2023-01-18 13:46:45 -08:00
Oliver W
a8c465f3fb [wpimath] HolonomicDriveController: Add getters for the controllers (#4948) 2023-01-16 08:33:15 -08:00
Starlight220
a7b1ab683d [wpilibc] Add unit test for fast deconstruction of GenericHID (#4953) 2023-01-16 08:28:06 -08:00
Starlight220
bd6479dc29 [build] Add Spotless for JSON (#4956) 2023-01-16 08:26:46 -08:00
Thad House
5cb0340a8c [hal, wpilib] Load joystick values upon code initialization (#4950)
During HAL_Initialize, wait up to 100ms for a DS packet to be received. Then in RobotBase, right after calling HAL_Initialize, call each language's RefreshData function to force a high level DS update. If the DS is connected, will get joystick data. If there is no data, nothing different will happen, but in that case there's no joysticks anyway.
2023-01-15 16:36:44 -08:00
sciencewhiz
ab0e8c37a7 [readme] Update build requirements (NFC) (#4947)
Change to adoptium, and add Xcode min version
2023-01-15 15:19:24 -08:00
Tyler Veness
b74ac1c645 [build] Add apriltag to C++ cmake example builds (#4944)
This fixes compilation of the apriltag vision example on my machine.
2023-01-13 23:24:14 -08:00
Doug Wegscheid
cf1a411acf [examples] Add example programs for AprilTags detection (#4932)
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2023-01-13 23:08:45 -08:00
sciencewhiz
1e05b21ab5 [wpimath] Fix PID atSetpoint to not return true prematurely (#4906)
Wait until setpoint and measurement have been set.
2023-01-13 22:26:30 -08:00
ohowe
e5a6197633 [wpimath] Fix SwerveDriveKinematics not initializing a new array each time (#4942)
This is problematic if you call it twice before utilizing the result.
2023-01-13 20:16:50 -08:00
Peter Johnson
039edcc23f [ntcore] Queue current value on subscriber creation (#4938)
This fixes a potential race condition in code that only uses readQueue.
2023-01-13 20:07:24 -08:00
Matt
f7f19207e0 [wpimath] Allow multiple vision measurements from same timestamp (#4917)
Co-authored-by: Jordan McMichael <jlmcmchl@gmail.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2023-01-11 23:04:30 -08:00
Starlight220
befd12911c [commands] Delete UB-causing rvalue variants of CommandPtr methods (#4923)
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
2023-01-11 22:53:04 -08:00
superpenguin612
34519de60a [commands] Fix spacing in command composition exception (#4924) 2023-01-11 11:46:33 -08:00
Ryan Blue
dc4355c031 [hal] Add handle constructor and name getters for sim devices (#4925) 2023-01-11 11:45:15 -08:00
Ryan Blue
53d8d33bca [hal, wpilibj] Add missing distance per pulse functions to EncoderSim (#4928)
Also fix C++ and Java EncoderSim.setDistancePerPulse() not propagating value to SimEncoderData.
2023-01-11 11:43:56 -08:00
bovlb
530ae40614 [apriltag] Explain what April tag poses represent (NFC) (#4930) 2023-01-11 11:42:30 -08:00
Starlight220
79f565191e [examples] DigitalCommunication, I2CCommunication: Add tests (#4865) 2023-01-08 16:33:53 -08:00
Starlight220
2cd9be413f [wpilib, examples] Cleanup PotentiometerPID, Ultrasonic, UltrasonicPID examples (#4893)
Fix C++ Ultrasonic to return correct units.
2023-01-08 16:33:07 -08:00
Matt
babb0c1fcf [apriltag] Add 2023 field layout JSON (#4912) 2023-01-08 16:30:45 -08:00
ohowe
330ba45f9c [wpimath] Fix swerve kinematics util classes equals function (#4907)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2023-01-08 16:29:35 -08:00
sciencewhiz
51272ef6b3 [fieldImages] Add 2023 field (#4915) 2023-01-08 16:28:25 -08:00
Starlight220
0d105ab771 [commands] Deduplicate command test utils (#4897) 2023-01-08 07:44:53 -08:00
Tyler Veness
cf4235ea36 [wpiutil] Guard MSVC pragma in SymbolExports.h (#4911)
MinGW gives an unknown pragma warning on Windows.
2023-01-07 16:41:40 -08:00
Ryan Blue
2d4b7b9147 [build] Update opencv version in opencv.gradle (#4909) 2023-01-06 18:09:58 -08:00
Peter Johnson
aec6f3d506 [ntcore] Fix client flush behavior (#4903)
We need to ignore per-publisher send periods when flushing.

Also fix NT4 client to use flush async's (same as NT3 client).
2023-01-04 23:36:26 -08:00
Peter Johnson
bfe346c76a [build] Fix cmake java resources (#4898)
These need to be relative paths, but GLOB generates absolute paths by
default.
2023-01-04 08:16:47 -08:00
Ryan Blue
83f1860047 [wpilib] Add/update documentation to PneumaticBase and subclasses (NFC) (#4881)
Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
2023-01-02 10:23:59 -08:00
Dustin Spicuzza
9872e676d8 [commands] Make Subsystem destructor virtual (#4892)
C++ best practice if there are other functions that are virtual.
2023-01-02 07:59:12 -08:00
Dustin Spicuzza
25db20e49d [hal] Fix segfault in various HAL functions (#4891) 2023-01-01 23:19:04 -08:00
ohowe
b0c6724eed [glass] Add hamburger menu icon to titlebars (#4874)
This does the same thing as right clicking, but provides a visual indicator.
The icon disappears if the window is too small or docked (right click keeps working).
2023-01-01 20:05:09 -08:00
Tyler Veness
f0fa8205ac Add missing compiler flags and fix warnings (#4889)
This makes the build fail on warnings. It caught two out-of-bounds reads
and a deprecation warning.
2023-01-01 08:14:19 -08:00
Dustin Spicuzza
42fc4cb6bc [wpiutil] SafeThread: Provide start/stop hooks (#4880)
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
2022-12-31 15:40:45 -08:00
Sriman Achanta
cc166c98d2 [templates] Add Command-based skeleton template (#4861)
Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
2022-12-31 13:18:43 -08:00
Thad House
3f51f10ad3 [build] Update to 2023v3 image (#4886) 2022-12-31 13:16:41 -08:00
Peter Johnson
1562eae74a [ntcore] Refactor meta-topic decoding from glass (#4809) 2022-12-31 12:01:51 -08:00
Thad House
b632b288a3 Fix usages of std::min and std::max to be windows safe (#4887) 2022-12-31 12:00:45 -08:00
Dustin Spicuzza
c11bd2720f [wpilibc] Add internal function to reset Shuffleboard instance (#4884)
Needed for RobotPy test framework.
2022-12-31 10:43:48 -08:00
Peter Johnson
f1151d375f [ntcore] Add method to get server time offset (#4847)
Also exposes this as an event signaled when the offset is updated due to
a ping response from the server.
2022-12-30 20:15:57 -08:00
Ryan Blue
fe1b62647f [hal,wpilib] Update documentation for getComments (NFC) (#4879) 2022-12-30 04:15:37 -08:00
Thad House
c49a45abbd [build] Fix examples linking in incorrect jni library (#4873) 2022-12-29 08:07:59 -06:00
Griffin Della Grotte
bc3d01a721 [build] Add platform check to doxygen plugin (#4862)
This allows the build to work on aarch64 and other platforms without downloadable doxygen binaries.
2022-12-27 22:43:21 -06:00
Ryan Blue
bc473240ae Add Jetbrains Fleet folder to .gitignore (#4872) 2022-12-27 22:41:13 -06:00
Tyler Veness
2121bd5fb8 [wpimath] Remove RKF45 (#4870)
RKDP is strictly better in terms of accuracy per unit of work. We used
RKF45 for sim physics in the 2021 season, but we transitioned to RKDP
before the 2022 season.
2022-12-27 19:29:59 -06:00
Griffin Della Grotte
835f8470d6 [build] Fix roborio cross-compiler on arm hosts (#4864) 2022-12-27 10:26:53 -08:00
Peter Johnson
6cfe5de00d [ntcore] Don't deadlock server on early destroy (#4863)
It was possible to deadlock on instance destroy if the server had started
but had not yet fully initialized its handles.
2022-12-27 10:25:48 -08:00
Ryan Blue
2ac41f3edc [hal, wpilib] Add RobotController.getComments() (#4463) 2022-12-26 11:39:51 -08:00
Sriman Achanta
26bdbf3d41 Java optimization and formatting fixes (#4857) 2022-12-26 11:37:53 -08:00
Sriman Achanta
92149efa11 Spelling and grammar cleanups (#4849) 2022-12-26 11:32:13 -08:00
Ryan Blue
176fddeb4c [commands] Add functions to HID classes to allow use of axes as BooleanEvents/Triggers (#4762) 2022-12-26 11:29:14 -08:00
Starlight220
87a34af367 [templates] Add bindings to command-based template (#4838) 2022-12-26 11:28:06 -08:00
Starlight220
4534e75787 [examples] Remove redundant MotorControl example (#4837)
The MotorControlEncoder had the exact same content, with the addition of an encoder. No point in having both examples.
2022-12-26 11:27:20 -08:00
Griffin Della Grotte
1cbebaa2f7 [commands] Remove final semicolon from test macro definition (#4859) 2022-12-26 00:14:59 -06:00
Ryan Blue
6efb9ee405 [commands] Add constructor for SwerveControllerCommand that takes a HolonomicDriveController (#4785)
Also adds copy and move constructors to HolonomicDriveController.
2022-12-25 18:48:27 -08:00
Thad House
1e7fcd5637 [cscore] Change run loop functions to not be mac specific (#4854) 2022-12-25 13:37:59 -06:00
Peter Johnson
1f940e2b60 [apriltag] Add C++ wrappers, rewrite Java/JNI to match (#4842)
This provides a consistent class-based interface to the underlying C
library from both C++ and Java.

Co-authored-by: Matt <matthew.morley.ca@gmail.com>
2022-12-25 08:15:43 -08:00
Starlight220
a6d127aedf [build] Add missing task dependency in wpilibjExamples (#4852) 2022-12-25 07:37:10 -08:00
Thad House
b893b3d6d3 [cscore] Add support for USB cameras on macOS (#4846)
The main restriction is there must be an event loop running on the main thread.
No special action is required for GUI applications, but for non-GUI applications, a
RunOsxRunLoop() function is provided that needs to be called from the main thread.
2022-12-25 07:36:00 -08:00
Peter Johnson
1696a490fa [glass] Add support for alternate NT ports (#4848) 2022-12-24 20:18:07 -06:00
Peter Johnson
40a22d69bc [glass] Add support for alternate NT ports (#4848) 2022-12-24 20:17:45 -06:00
Sriman Achanta
e84dbfede0 [wpilib] GenericHID: Add rumble both option (#4843) 2022-12-24 11:28:52 -08:00
CarloWoolsey
8aa9dbfa90 [examples] Link apriltag package in examples build.gradle (#4845) 2022-12-23 20:04:59 -06:00
Ryan Blue
eda2fa8a17 [build] Update Spotless (#4840)
Removes JVM args workaround needed for old version of spotless to run on JDK 17.

2 files had formatting updates.
2022-12-21 08:54:41 -06:00
sciencewhiz
d20594db0d Fix typos (#4839) 2022-12-21 08:53:00 -06:00
Ryan Blue
dd8ecfdd54 [commands] Fix typo in waitUntil docs (NFC) (#4841) 2022-12-21 08:24:25 -06:00
Thad House
17ceebfff4 [apriltag] Clean up apriltag JNI (#4823) 2022-12-19 21:06:36 -08:00
Ryan Blue
8b74ab389d [examples] RapidReactCommandBot: Fix array indices (#4833) 2022-12-18 16:54:37 -06:00
David Vo
1aad3489c2 [sim] Implement PD total current and power (#4830) 2022-12-18 08:00:31 -06:00
Ashray._.g
2744991771 [wpimath] Fix docs in SwerveModulePosition (#4825)
Changed m/s and speeds to m and distance.
2022-12-16 05:48:20 -08:00
Peter Johnson
ffbf6a1fa2 [commands] Disable regularly failing unit test (#4824) 2022-12-15 21:53:08 -08:00
Starlight220
fbabd0ef15 [commands] Enhance Command Sendable implementations (#4822) 2022-12-15 18:28:52 -08:00
Thad House
7713f68772 [hal] Use atomic rather then mutex for DS Data updates (#4787)
Using an atomic here means we are never going against a lock that is touchable from user code. That should make reading the DS data from the DS callback even safer.
2022-12-15 18:27:52 -08:00
Starlight220
701995d6cc [examples] Update Command-based starter project (#4778) 2022-12-15 09:40:14 -08:00
Thad House
bf7068ac27 [wpilibc] Add missing PPS implementation for C++ (#4821) 2022-12-15 09:28:42 -08:00
Peter Johnson
aae0f52ca6 [ntcore] NetworkTable: fix visibility of get/set value (#4820) 2022-12-14 19:43:53 -08:00
Thad House
ee02fb7ba7 [hal] Add support for Pulse-Per-Second signal (#4819) 2022-12-14 18:15:34 -08:00
Thad House
518916ba02 [wpilib] Fix DS mode thread event being manual reset accidentally (#4818)
These need to be automatic reset.
2022-12-14 10:17:13 -08:00
Thad House
3997c6635b [hal] Update to new image, use new TCP notify callback and new duty cycle API (#4774) 2022-12-13 22:37:42 -08:00
Michael Leong
cc8675a4e5 [examples] Add comment on how to view elevator sim (NFC) (#4482) 2022-12-13 22:34:00 -08:00
Peter Johnson
fb2c170b6e [ntcore] Simplify local startup (#4803)
The current approach was slightly more efficient but didn't correctly
handle meta-topic publishing for topics published before the server was
started.
2022-12-13 22:31:44 -08:00
shueja-personal
7ba8a9ee1f [wpimath] ProfiledPIDController: Add to SendableRegistry (#4656)
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
2022-12-13 22:31:06 -08:00
Sriman Achanta
c569d8e523 [wpilib] Joystick.getMagnitude(): use hypot() function (#4816) 2022-12-13 22:29:09 -08:00
bovlb
2a5e89fa97 [apriltag] Improve description of pose coordinates (NFC) (#4810)
The "bottom-left" language appears to be based on [a 2-D diagram  on another page](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/geometry/coordinate-systems.html) and doesn't seem very helpful here.
2022-12-13 22:27:43 -08:00
Drew Williams
cc003c6c38 [apriltag] Fix AprilTagFieldLayout JSON name (#4814) 2022-12-13 22:27:08 -08:00
Sriman Achanta
5522916123 [commands] CommandXBoxController bumper documentation fix (NFC) (#4815) 2022-12-13 22:26:35 -08:00
Peter Johnson
967b30de3a [glass] Fix NT view UpdateClients() bug (#4808)
If UpdateClients() was called in the same update batch as an entry
removal, it could crash in GetEntry() due to a null entry caused by
deletion before a removal erase pass was made.
2022-12-12 23:38:36 -08:00
Tyler Veness
3270d4fc86 [wpimath] Rewrite pose estimator docs (#4807) 2022-12-12 20:30:52 -08:00
Thad House
be39678447 [apriltag] Add test to ensure apriltagjni loads (#4805) 2022-12-12 20:30:25 -08:00
Starlight220
61c75deb2a [commands] Test no-op behavior of scheduling a scheduled command (#4806) 2022-12-12 20:29:47 -08:00
Peter Johnson
a865f48e96 [ntcore] Pass pub/sub options as a unified PubSubOptions struct (#4794)
In Java, PubSubOption is still used for passing options, but this
simplifies C++ use substantially, as it allows aggregate construction.
2022-12-12 19:28:15 -08:00
Ryan Blue
f66a667321 [commands] Fix incorrect Trigger docs (NFC) (#4792) 2022-12-12 15:38:29 -08:00
Peter Johnson
f8d4e9866e [ntcore] Clean up ntcore_test.h (#4804)
The RPC functions are no longer implemented.

Also make header C-safe.
2022-12-12 15:36:54 -08:00
Tyler Veness
7e84ea891f [wpimath] Fix ComputerVisionUtil transform example in parameter docs (NFC) (#4800) 2022-12-11 22:44:08 -08:00
Charlie
da3ec1be10 [wpimath] Change terminology for ArmFeedforward gravity gain (NFC) (#4791) 2022-12-11 22:43:44 -08:00
Ryan Blue
944dd7265d [wpilibc] Add C++ Notifier error handling, update java notifier error message (#4795) 2022-12-11 22:42:22 -08:00
Ryan Blue
6948cea67a [wpiutil] Fix MemoryBuffer initialization (#4797)
Dereferencing an end iterator is undefined behavior and causes a failed assertion when running in Windows debug.
2022-12-11 07:39:04 -08:00
Ryan Blue
a31459bce6 [wpiutil] Fix UnescapeCString overflow when inputSize < 2 (#4796)
Add tests for empty, small, and string without escapes.
2022-12-11 07:36:38 -08:00
ohowe
4a0ad6b48c [wpimath] Rotation2d: Add reference to angleModulus in docs (NFC) (#4786) 2022-12-09 23:35:15 -08:00
Peter Johnson
e6552d272e [ntcore] Remove table multi-subscriber (#4789)
This wasn't well thought out, and leaks horribly in Java.

Reverts part of #4640.
2022-12-09 21:25:29 -08:00
Ryan Blue
bde383f763 [hal] Replace const char* with std::string_view in Driver Station sim functions (#4532) 2022-12-09 13:10:23 -08:00
Ryan Blue
5a52b51443 [hal] Add RobotController.getSerialNumber() (#4783) 2022-12-08 21:58:55 -08:00
Thad House
69a66ec5ec [wpilib] Fix multiple motor safety issues (#4784)
Java was missing the motor safety thread entirely
C++ accidentally used a manual reset event, causing the motor safety thread to spin.
C++ PWMMotorController would not feed the watch kitty.
Both languages would call feed() from the StopMotor call, causing some ping ponging.
2022-12-08 19:47:47 -08:00
sciencewhiz
989c9fb29a [wpimath] Revert Rotation2D change that limits angles (#4781)
Reverts "[wpimath] Constrain Rotation2d range to -pi to pi (#4611)"
This reverts commit d1d458db2b.

This broke multiple teams code in beta. It is also easier to limit the angle externally, then reconstruct a larger angle that got limited. This additionally adds comments to clarify the behavior and retains tests that were added in the reverted commit, and fixes a javadoc comment angle reference.
2022-12-08 18:10:44 -08:00
Peter Johnson
0f5b08ec69 [wpigui] Update imgui to 1.89.1+ (#4780) 2022-12-08 00:24:27 -08:00
Starlight220
fba191099c [examples] AddressableLED: Add unit test (#4779) 2022-12-07 21:47:47 -08:00
Peter Johnson
b390cad095 [wpilibj] Consistently use ErrorMessages.requireNonNullParam (#4776)
Also remove wpilibj version of ErrorMessages and consistently use static import.
2022-12-07 21:46:26 -08:00
Peter Johnson
b9772214d9 [wpilib] Sendable: Don't call setter for getter changes 2022-12-07 21:29:51 -08:00
Peter Johnson
342c375a71 [ntcore] Add subscriber option to exclude single publisher
This enables limited self-exclusion for entries seeing their own changes
or similarly with a pub/sub pair.
2022-12-07 21:29:51 -08:00
Peter Johnson
b0e4053087 [ntcore] Use int for options instead of double
Periodic time is stored in milliseconds.
2022-12-07 21:29:51 -08:00
Peter Johnson
f3e666b7bb [cscore] Convert YUYV and UYVY directly to grayscale (#4777)
This is significantly more efficient than converting by way of BGR.
2022-12-07 10:36:40 -08:00
William Toth
b300518bd1 [hal] Add CAN Stream API to Java through JNI bindings (#4193)
The CAN Stream API allows defining an buffer to receive an
arbitrary set of CAN messages, based on an ID and a mask. Messages
are added to this queue separate of other CAN APIs. This means the
messages can be receive without impacting other APIs such as
vendor APIs.

This enables things like detection of what devices are on the
bus, or custom decoding, without using vendor APIs.

Co-authored-by: Thad House <thadhouse1@gmail.com>
2022-12-06 21:58:09 -08:00
Peter Johnson
be27171236 [wpilibj] Shuffleboard: Check for null sendable (#4772)
Adding a null sendable to a container could result in a delayed NullPointerException.
2022-12-06 21:14:09 -08:00
Starlight220
4bbdbdfb48 [commands] Move GroupedCommands to CommandScheduler (#4728)
Move the command group checking functionality from CommandGroupBase into CommandScheduler.
Update references to grouping as composition for clarity (because explicitly grouping isn't the only way to do it).
Deprecate the static factory methods parallel, race, and deadline in CommandGroupBase in favor of the identical ones in Commands.
2022-12-06 21:13:31 -08:00
Tyler Veness
f18fd41ac3 [wpimath] Remove broken and obsoleted ComputerVisionUtil functions (#4775)
The ComputerVisionUtil class was added before AprilTag support was
announced. Now that it has, the functions for estimating a pose from
range and yaw are no longer needed; it's just better to get the pose
directly from the AprilTag.

The coordinate system on some function arguments was confusing or didn't
match the NWU convention the rest of the library uses. It's easier to
remove the functions now and add them back after they're fixed since the
fixes aren't trivial.

The range function was removed because it uses pitch and yaw in the
camera's spherical coordinate system, which is obsoleted by AprilTags.
AprilTags give you a 6DOF pose directly, so range can be obtained via
Pose2d.getTranslation().getDistance().

Fixes #4757.
2022-12-06 21:11:27 -08:00
Peter Johnson
2d0faecf4f [glass] DataSource: Add spinlock to protect value (#4771)
A lock is needed here due to HAL async callbacks.
2022-12-06 21:09:14 -08:00
Peter Johnson
348bd107fc [hal] Add CANManufacturer for The Thrifty Bot (#4773) 2022-12-06 21:08:45 -08:00
Starlight220
3149dc64b8 [examples] HatchbotInlined: Use Subsystem factories (#4765) 2022-12-06 15:10:39 -08:00
Jordan McMichael
8618dd4160 [glass, wpilib] Replace remaining references to Speed Controller with Motor Controller (#4769) 2022-12-05 20:06:43 -08:00
Peter Johnson
72e21a1ed1 [apriltag] Use wpilibsuite fork of apriltag (#4764) 2022-12-05 19:59:24 -08:00
Ryan Blue
eab0d929e6 [commands] CommandGenericHID POV methods: Fix docs (NFC) (#4760) 2022-12-05 13:46:46 -08:00
Ryan Blue
6789869663 [wpilib] Call set(0) rather than disable for stopMotor (#4763)
For PWM motor controllers, this is going to be the fastest way to stop the motor,
as disabling the PWM output will have a small delay due to the motor controller
needing to detect the missing signal.

Note Set(0) is not a safe approach for CAN motor controllers, which may have closed
loop operation, non-% output set() calls, etc.
2022-12-05 13:33:54 -08:00
Dustin Spicuzza
c9dea2968d [cscore] Emit warning that USB Camera isn't supported on OSX (#4766)
Reduces user confusion, as right now there's really no indication that something is wrong other than there's no camera,
2022-12-05 13:30:13 -08:00
sciencewhiz
8f402645f5 [commands] Fix PIDSubsystem setSetpoint behavior (#4759)
No longer stores a temporary setpoint in PIDSubsystem, instead
immediately sending to PIDController. This fixes an issue where the
setpoint didn't take effect until the Subsystem Periodic method ran, and
could cause commands to finish early if they were scheduled after the
subsystem periodic method ran because it used the old setpoint.
2022-12-03 11:32:46 -08:00
Tyler Veness
f24ad1d715 [build] Upgrade to googletest 1.12.1 (#4752)
This fixes GCC 12 warnings for googletest internals.
2022-12-03 11:32:08 -08:00
Jaci Brunning
ff88756864 [wpimath] Add new DCMotor functions for alternative calculations and reduction calculation (#4749) 2022-12-03 09:47:16 -08:00
superpenguin612
f58873db8e [wpimath] Remove extra terms in matrix for pose estimator docs (#4756) 2022-12-03 09:46:34 -08:00
superpenguin612
37e969b41a [wpimath] Add constructors to pose estimators with default standard deviations (#4754) 2022-12-03 09:46:10 -08:00
Tyler Veness
13cdc29382 [ci] Rename comment command from "/wpiformat" to "/format" (#4755)
It now runs more than just wpiformat.
2022-12-02 18:24:06 -08:00
Tyler Veness
6e23985ae6 [examples] Add main include directory to test builds (#4751)
This fixes the following compilation errors:
```
/home/tav/frc/wpilib/allwpilib/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp:5:10: fatal error: subsystems/Intake.h: No such file or directory
    5 | #include "subsystems/Intake.h"
      |          ^~~~~~~~~~~~~~~~~~~~~

/home/tav/frc/wpilib/allwpilib/wpilibcExamples/src/test/cpp/examples/UnitTest/cpp/subsystems/IntakeTest.cpp:11:10: fatal error: Constants.h: No such file or directory
   11 | #include "Constants.h"
      |          ^~~~~~~~~~~~~
```
2022-12-02 10:37:49 -08:00
Starlight220
66bb0ffb2c [examples] Add unit testing infrastructure (#4646) 2022-12-02 08:40:14 -08:00
Tyler Veness
74cc86c4c5 [wpimath] Make transform tests use pose/transform equality operators (#4675)
Also add more nonzeros to Transform3d tests to make them more
comprehensive.
2022-12-02 08:36:57 -08:00
Jordan McMichael
e22d8cc343 [wpimath] Use Odometry for internal state in Pose Estimation (#4668)
This effectively replaces the Unscented Kalman Filter used for Pose Estimation with the Odometry model, and uses a recalculable Kalman gain matrix to update pose estimations whenever a vision measurement is added.

Notably, this change removes the need for the confusing generics used in Java, and the C++ implementation got quite a bit less complex as well.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-12-02 08:36:10 -08:00
Ryan Blue
68dba92630 [ci] Update mac and windows builds to Java 17 (#4750) 2022-12-02 08:31:38 -08:00
Tyler Veness
23bfc2d9ab [sim] Remove unmaintained Gazebo support (#4736) 2022-12-01 20:46:47 -08:00
Starlight220
1f1461e254 [wpilib] Add method to enable/disable LiveWindow in test mode (#4678) 2022-12-01 13:28:06 -08:00
Tyler Veness
eae68fc165 [wpimath] Add tolerance for Rotation3d rotation matrix special orthogonality (#4744) 2022-11-30 19:51:31 -08:00
Tyler Veness
4c4545fb4b [apriltag] Suppress warning (#4743) 2022-11-30 19:51:18 -08:00
Tyler Veness
16ffaa754d [docs] Generate docs for apriltag subproject (#4745) 2022-11-30 19:50:52 -08:00
Thad House
5e74ff26d8 [apriltag, build] Update native utils, add apriltag impl and JNI (#4733)
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2022-11-30 00:16:29 -08:00
Dustin Spicuzza
53875419a1 [hal] Allow overriding stderr printing by HAL_SendError (#4742) 2022-11-29 23:19:15 -08:00
Peter Johnson
aa6499e920 [ntcore] Fix special topic multi-subscriber handling (#4740)
It now matches server behavior, where "" doesn't match special topics.

Also fixes duplicate notification that could occur in some cases.
2022-11-29 21:58:57 -08:00
Peter Johnson
df70351107 [build] Fix cmake install of thirdparty includes (#4741) 2022-11-29 21:58:38 -08:00
Peter Johnson
e9bd50ff9b [glass] NT view: clear meta-topic info on disconnect (#4732) 2022-11-29 21:57:48 -08:00
Peter Johnson
9b319fd56b [ntcore] Add sub option for local vs remote changes (#4731)
This is the subscriber readQueue version of the local value listener flag.
2022-11-29 21:57:20 -08:00
Peter Johnson
18d28ec5e3 [ntcore] Remove duplicate value checking from ClientImpl
This is no longer required with the duplicate value checking in
LocalStorage.
2022-11-29 09:49:47 -08:00
Peter Johnson
bdfb625211 [ntcore] Send duplicate values to network if necessary
Essentially this separates duplicate value detection between network and
local.
2022-11-29 09:49:47 -08:00
Ryan Blue
21003e34eb [commands] Update Subsystem factories and example to return CommandBase (#4729)
Also update rapidreactcommandbot example factories to fit this convention (as in #4655).

C++ does not need an update as CommandPtr already uses CommandBase (#4677).
2022-11-28 19:47:18 -08:00
Starlight220
70080457d5 [commands] Refactor ProxyScheduleCommand, SelectCommand into ProxyCommand (#4534) 2022-11-28 14:43:10 -08:00
Colin Wong
e82cd5147b [wpilib] Tweak Color HSV formula and use in AddressableLED (#4724)
The Color algorithm was tweaked to:
a) not produce incorrect values if the user happens to input a hue outside the [0, 180) range, and
b) more accurately convert the hue remainder from range 0-30 to 0-255. The current conversion vastly overshoots the multiplier (converts 0-30 to 0-270) and relies on clamping the value when constructing the Color object to produce a slightly incorrect result.
2022-11-28 14:42:22 -08:00
Colin Wong
ec124bb662 [commands] Allow unsetting a subsystem's default command (#4621) 2022-11-28 14:03:14 -08:00
Ryan Blue
2b2aa8eef7 [examples] Update all examples to use NWU coordinate conventions (#4725) 2022-11-28 13:49:49 -08:00
Starlight220
cb38bacfe8 [commands] Revert to original Trigger implementation (#4673)
Trigger was refactored to use BooleanEvent when it was introduced in #4104.
This reverts to the original implementation until edge-based BooleanEvents can be fixed.
2022-11-28 13:48:48 -08:00
Starlight220
15561338d5 [commands] Remove one more default command isFinished check (#4727) 2022-11-28 13:44:37 -08:00
Ryan Blue
ca35a2e097 Add simgui files to .gitignore (#4726) 2022-11-28 08:57:57 -08:00
Starlight220
20dbae0cee [examples] Renovate command-based examples (#4409)
Refactor some examples to use newer features, such as HID factories, library-provided command factories, CommandPtr (C++), as well as new idioms such as static/instance command factories.
2022-11-28 08:55:13 -08:00
Eli Barnett
1a59737f40 [commands] Add convenience factories (#4460)
Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
2022-11-28 07:41:25 -08:00
Tyler Veness
42b6d4e3f7 Use defaulted comparison operators in C++ (#4723)
Comparison operators which compared against every class member variable
now use C++20's default comparison operators.

Also remove operator!= that in C++20 is now auto-generated from operator==.
2022-11-27 21:01:01 -08:00
Peter Johnson
135c13958f [wpigui] Add FontAwesome (#4713) 2022-11-27 20:00:17 -08:00
Peter Johnson
ffbfc61532 [ntcore] Add NetworkTable table-specific listeners (#4640)
These are similar, but not quite identical to, the NT3 NetworkTable
table listeners.

Also add table topic-only multi-subscriber to ensure functions like
getKeys() work properly regardless of other subscriptions.
2022-11-27 19:46:34 -08:00
Starlight220
8958b2a4da [commands] Add property tests for command compositions (#4715) 2022-11-27 16:23:56 -08:00
Starlight220
e4ac09077c [wpilib] Add link to MotorSafety article (#4720) 2022-11-27 16:23:06 -08:00
Starlight220
f40de0c120 [commands] Add C++ factory templates (#4686) 2022-11-27 11:27:44 -08:00
Peter Johnson
51fa3e851f [build] cmake: Use FetchContent instead of ExternalProject (#4714)
Also switch to using thirdparty-fonts instead of generating them.
2022-11-26 23:05:41 -08:00
Peter Johnson
1da84b2255 [wpigui] Reload fonts to scale rather than preloading (#4712) 2022-11-26 22:30:38 -08:00
Peter Johnson
e43e2fbc84 [wpiutil] StringExtras: Add UnescapeCString (#4707)
Based on implementation in glass but enhanced for generic use.
2022-11-26 18:21:45 -08:00
Peter Johnson
5804d8fa84 [ntcore] Server: Properly handle multiple subscribers (#4717)
Previously, only the first subscriber was actually matched to a topic
when a topic was created; this was a problem when later publishing
values as a client could have both a topic-only subscriber and a normal
subscriber, and only the first one would end up being subscribed to the
topic.
2022-11-26 17:02:22 -08:00
Peter Johnson
169ef5fabf [glass] Update NT view for topicsOnly and sendAll changes (#4718) 2022-11-26 17:01:40 -08:00
Starlight220
148759ef54 [examples] CANPDP: Expand properties shown (#4687) 2022-11-25 23:51:15 -08:00
Starlight220
58ed112b51 [commands] RepeatCommand: restart on following iteration (#4706)
This fixes InstantCommand.repeatedly().
2022-11-25 23:50:42 -08:00
Ryan Blue
dd1da77d20 [readme] Fix broken CI badge (#4710) 2022-11-25 23:49:47 -08:00
Ryan Blue
7cda85df20 [build] Check Gradle plugin repo last to fix CI (#4711) 2022-11-25 23:48:18 -08:00
Thad House
7ed9b13277 [build] Bump version plugin to fix null tag (#4705) 2022-11-24 22:10:59 -08:00
Tyler Veness
6b4f26225d [apriltag] Fix pluralization of apriltag artifacts (#4671) 2022-11-24 09:06:38 -08:00
Peter Johnson
b2d2924b72 [cscore] Add Y16 image support (#4702) 2022-11-24 09:06:06 -08:00
Peter Johnson
34ec89c041 [wpilibc] Shuffleboard SimpleWidget: Return pointer instead of reference (#4703)
Based on beta test feedback, returning a pointer is more intuitive, as
typically the return value is late bound to an instance variable.
2022-11-24 09:05:37 -08:00
Peter Johnson
e15200068d [ci] Disable HW testbench runs (#4704)
These are currently broken with no timetable to fix.
2022-11-24 09:04:57 -08:00
Starlight220
d5200db6cd [wpimath] Rename HolonomicDriveController.calculate params (#4683) 2022-11-23 23:13:50 -08:00
Tyler Veness
2ee3d86de4 [wpimath] Clarify Rotation3d roll-pitch-yaw direction (#4699) 2022-11-23 23:12:59 -08:00
Peter Johnson
9f0a8b930f [cscore] Use MFVideoFormat_L8 for Gray on Windows (#4701) 2022-11-23 22:15:56 -08:00
Peter Johnson
2bca43779e [cscore] Add UYVY image support (#4700) 2022-11-23 22:00:31 -08:00
ohowe
4307d0ee8b [glass] Plot: allow for more than 11 plots (#4685)
Since m_windows is sorted using the ascii, when "Plot <10>" is reached it will be before "Plot <2>" in `m_windows` which makes it so it will not add a new plot after the id 10 is reached. This also fixes a potential issue of someone manually changing an id in the file, which would break adding a new plot in some circumstances.
2022-11-23 13:57:29 -08:00
Starlight220
3fe8d355a1 [examples] StateSpaceDifferentialDriveSimulation: Use encoder reversed constants (#4682)
This matches the Java example.
2022-11-22 10:29:40 -08:00
Peter Johnson
b44034dadc [ntcore] Allow duplicate client IDs on server (#4676)
Currently, the server rejects duplicate client IDs. As we want to make
the client implementation as simple as possible, instead deduplicate the
name on the server side by appending "@" and a count.

NT4 spec has been updated for this change.
2022-11-22 10:27:49 -08:00
Starlight220
52d2c53888 [commands] Rename Java factory wait() to waitSeconds() (#4684)
This is needed to avoid a conflict with Object.wait() when using static imports.
C++ doesn't have this issue, and has units, so Wait() still makes sense there.
2022-11-22 10:16:27 -08:00
Thad House
76e918f71e [build] Fix JNI artifacts linking to incorrect libraries (#4680) 2022-11-21 20:33:46 -08:00
Starlight220
0bee875aff [commands] Change C++ CommandPtr to use CommandBase (#4677) 2022-11-21 09:45:50 -08:00
Peter Johnson
98e922313b [glass] Don't check IsConnected for NT widgets (#4674)
Checking this isn't required, and prevented these widgets from working
in the simulation GUI without another NT client connected.
2022-11-20 17:27:28 -08:00
amquake
9a36373b8f [apriltag] Switch 2022 apriltag layout length and width values (#4670) 2022-11-19 09:11:08 -08:00
Peter Johnson
cf8faa9e67 [wpilib] Update values on controllable sendables (#4667) 2022-11-18 23:50:41 -08:00
Peter Johnson
5ec067c1f8 [ntcore] Implement keep duplicates pub/sub flag (#4666)
Also don't save duplicate NT sets to data log (unless publish keep duplicates flag is set).
2022-11-18 23:50:08 -08:00
Peter Johnson
e962fd2916 [ntcore] Allow numeric-compatible value sets (#4620)
Also fix entry publishing behavior to allow numerically compatible set
default publish following a subscribe.
2022-11-18 22:46:24 -08:00
Ryan Blue
88bd67e7de [ci] Update clang repositories to jammy (#4665) 2022-11-18 20:42:55 -08:00
Jordan McMichael
902e8686d3 [wpimath] Rework odometry APIs to improve feature parity (#4645)
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
2022-11-18 20:42:00 -08:00
Thad House
e2d49181da Update to native utils 2023.8.0 (#4664) 2022-11-18 19:01:26 -08:00
Peter Johnson
149bac55b1 [cscore] Add Arducam OV9281 exposure quirk (#4663)
Reports exposure range as 1-5000 but real range is 1-75.
2022-11-18 14:15:30 -08:00
amquake
88f7a3ccb9 [wpimath] Fix Pose relativeTo documentation (#4661) 2022-11-18 14:07:50 -08:00
sciencewhiz
8acce443f0 [examples] Fix swerve examples to use getDistance for turning encoder (#4652) 2022-11-18 14:06:21 -08:00
Peter Johnson
295a1f8f3b [ntcore] Fix WaitForListenerQueue (#4662) 2022-11-18 14:01:52 -08:00
Dustin Spicuzza
388e7a4265 [ntcore] Provide mechanism to reset internals of NT instance (#4653) 2022-11-18 10:21:05 -08:00
Tyler Veness
13aceea8dc [apriltag] Fix FieldDimensions argument order (#4659) 2022-11-17 22:15:55 -08:00
Ryan Blue
c203f3f0a9 [apriltag] Fix documentation for AprilTagFieldLayout (#4657) 2022-11-17 19:40:51 -08:00
Thad House
f54d495c90 Fix non initialized hal functionality during motor safety init (#4658) 2022-11-17 18:54:45 -08:00
Starlight220
e6392a1570 [cmd] Change factories return type to CommandBase (#4655) 2022-11-17 15:44:16 -08:00
PJ Reiniger
53904e7cf4 [apriltag] Split AprilTag functionality to a separate library (#4578)
Add AprilTagFieldLayout JSON file and move class to edu.wpi.first.apriltag.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-11-17 14:29:29 -08:00
Drew Williams
2e88a496c2 [wpimath] Add support for swerve joystick normalization (#4516) 2022-11-17 10:53:49 -08:00
Jordan McMichael
ce4c45df13 [wpimath] Rework function signatures for Pose Estimation / Odometry (#4642)
Forcing the use of SwerveModulePostition[] and wpi::array<SwerveModulePosition, len> in place of variadic function signatures.
2022-11-17 10:36:33 -08:00
sciencewhiz
0401597d3b [readme] Add wpinet to MavenArtifacts.md (#4651)
Fixes #4639
2022-11-17 10:35:27 -08:00
Jordan McMichael
2e5f9e45bb [wpimath] Remove encoder reset comments on Swerve, Mecanum Odometry and Pose Estimation (#4643)
In both of these cases, encoder resets are not required for normal use.
2022-11-16 15:20:05 -08:00
sciencewhiz
e4b5795fc7 [docs] Disable Doxygen for memory to fix search (#4636) 2022-11-14 20:19:44 -08:00
Peter Johnson
03d0ea188c [build] cmake: Add missing wpinet to installed config file (#4637) 2022-11-14 20:19:13 -08:00
Thad House
3082bd236b [build] Move version file to its own source set (#4638) 2022-11-14 20:19:00 -08:00
Thad House
b7ca860417 [build] Use build cache for sign step (#4635)
The signing step does not get passed the username and password to the server, so it will just read from the build cache. Then to make sure the tasks are all updated correctly, use if developerid exists as a property to all sign tasks, so it will see the new variable value, and relink. Additionally only update the archives during signing, which will speed up signing.
2022-11-14 19:23:13 -08:00
Starlight220
64838e6367 [commands] Remove unsafe default command isFinished check (#4411) 2022-11-14 14:28:30 -08:00
Peter Johnson
1269d2b901 [myRobot] Disable spotbugs (#4565) 2022-11-14 14:26:41 -08:00
Tyler Veness
14d8506b72 [wpimath] Fix units docs for LinearSystemId::IdentifyDrivetrainSystem() (#4600) 2022-11-14 14:26:16 -08:00
ohowe
d1d458db2b [wpimath] Constrain Rotation2d range to -pi to pi (#4611)
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
2022-11-14 14:25:15 -08:00
Tyler Veness
f656e99245 [readme] Add links to development build documentation (#4481)
* Add links to development build documentation
* Use GitHub dev docs links in readme badges
2022-11-14 14:23:47 -08:00
Starlight220
6dd937cef7 [commands] Fix Trigger API docs (NFC) (#4599) 2022-11-14 14:21:35 -08:00
Starlight220
49047c85b9 [commands] Report error on C++ CommandPtr use-after-move (#4575) 2022-11-14 14:20:52 -08:00
Tyler Veness
d07267fed1 [ci] Upgrade containers to Ubuntu 22.04 and remove libclang installation (#4633) 2022-11-14 14:20:08 -08:00
Thad House
b53ce1d3f0 [build, wpiutil] Switch macos to universal binaries (#4628) 2022-11-14 10:36:33 -08:00
Ege Akman
5a320c326b [upstream_util, wpiutil] Refactor python scripts (#4614)
Co-authored-by: Sourcery AI <>
Co-authored-by: Vasista Vovveti <vasistavovveti@gmail.com>
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
2022-11-13 23:11:54 -08:00
Peter Johnson
c4e526d315 [glass] Fix NT Mechanism2D (#4626) 2022-11-13 23:09:23 -08:00
Ryan Blue
d122e4254f [ci] Run spotlessApply after wpiformat in comment command (#4623) 2022-11-13 14:07:26 -08:00
Peter Johnson
5a1e7ea036 [wpilibj] FieldObject2d: Add null check to close() (#4619) 2022-11-12 16:51:41 -08:00
Peter Johnson
179f569113 [ntcore] Notify locally on SetDefault (#4617)
This is necessary for the simulation GUI to pick up default publishes.
2022-11-12 06:33:10 -08:00
Peter Johnson
b0f6dc199d [wpilibc] ShuffleboardComponent.WithProperties: Update type (#4615)
ShuffleboardComponentBase::m_properties is now a StringMap<nt::Value>.
2022-11-11 15:08:05 -08:00
Tyler Veness
7836f661cd [wpimath] Add missing open curly brace to units/base.h (#4613) 2022-11-11 13:06:42 -08:00
CarloWoolsey
dbcc1de37f [wpimath] Add DifferentialDriveFeedforward classes which wrap LinearPlantInversionFeedforward (#4598)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-11-10 16:54:51 -08:00
Cory
93890c528b [wpimath] Add additional angular acceleration units (#4610)
Added Turns per second squared
Added Revolutions per minute squared
Added Revolutions per minute per second
2022-11-10 16:47:55 -08:00
Tyler Veness
3d8d5936f9 [wpimath] Add macro for disabling units fmt support (#4609) 2022-11-10 14:12:07 -08:00
Tyler Veness
2b04159dec [wpimath] Update units/base.h license header (#4608) 2022-11-10 14:11:44 -08:00
Thad House
2764004fad [wpinet] Fix incorrect jni definitions (#4605)
Also re-enables the check task that would have caught this.
2022-11-10 09:42:02 -08:00
Thad House
85f1bb8f2b [wpiutil] Reenable jni check task (#4606)
New option was added to JNI plugin to allow skipping specific symbols. This let us generally reenable the check task in wpiutil.
2022-11-10 09:33:26 -08:00
ohowe
231ae2c353 [glass] Plot: Fix Y-axis not being saved (#4594) 2022-11-08 21:33:02 -08:00
Tyler Veness
e92b6dd5f9 [wpilib] Fix AprilTagFieldLayout JSON property name typos (#4597) 2022-11-08 13:27:21 -08:00
Thad House
2a8e0e1cc8 Update all dependencies that use grgit (#4596) 2022-11-08 10:20:16 -08:00
Starlight220
7d06e517e9 [commands] Move SelectCommand factory impl to header (#4581)
It's templated, so it needs to be in the header.
2022-11-07 15:49:36 -08:00
Tyler Veness
323524fed6 [wpimath] Remove deprecated units/units.h header (#4572) 2022-11-07 10:18:36 -08:00
Starlight220
d426873ed1 [commands] Add missing PS4 triangle methods (#4576) 2022-11-07 10:15:54 -08:00
PJ Reiniger
5be5869b2f [apriltags] Use map as internal data model (#4577)
This leaves the file format as a list, but internally will transform the collection of tags into a map on de/serialization. The serialization will probably happen once on startup, but the tag lookup can happen 100s of times a second. This honestly probably doesn't make too much of a performance hit since N is small, but this is a simple O(n) -> O(1) change for lookups.
2022-11-07 10:09:06 -08:00
Griffin Della Grotte
b1b4c1e9e7 [wpimath] Fix Pose3d transformBy rotation type (#4545)
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
2022-11-07 09:57:33 -08:00
Dustin Spicuzza
a4054d702f [commands] Allow composing two triggers directly (#4580)
For backwards compatibility reasons.
2022-11-07 09:55:28 -08:00
Dustin Spicuzza
0190301e09 [wpilibc] Explicitly mark EventLoop as non-copyable/non-movable (#4579)
It's already not movable because m_bindings isn't copyable, but pybind11
isn't able to detect that
2022-11-07 09:30:03 -08:00
Peter Johnson
9d1ce6a6d9 [ntcore] Catch file open error when saving preferences (#4571) 2022-11-05 21:16:39 -07:00
Peter Johnson
5005e2ca04 [ntcore] Change Java event mask to EnumSet (#4564)
Also convert NetworkTableInstance.getNetworkMode() to return EnumSet.
2022-11-04 20:25:37 -07:00
PJ Reiniger
fa44a07938 [upstream-utils][mpack] Add upstream util for mpack (#4500) 2022-11-04 20:03:49 -07:00
Peter Johnson
4ba16db645 [ntcore] Various fixes and cleanups (#4544)
* NetworkTableInstance: set handle to 0 after destroy
* Fix multiple notifications of local values
* Detect mismatch between handles
* Server: fix setting min period when no topics
* Limit maximum number of subscribers/publishers/listeners
   This helps find resource leaks and prevents them from causing excessive
   slowdowns/crashes.  The limit on each is currently set to 512.
* Don't use std::swap in move operation
2022-11-04 20:01:21 -07:00
Thad House
837415abfd [hal] Fix joysticks either crashing or returning 0 (#4570) 2022-11-04 19:03:11 -07:00
amquake
2c20fd0d09 [wpilib] SingleJointedArmSim: Check angle equals limit on wouldHit (#4567) 2022-11-04 17:14:46 -07:00
Alex Ryker
64a7136e08 [wpimath] SwerveDrivePoseEstimator: Restore comment about encoder reset (#4569) 2022-11-04 15:03:49 -07:00
Brennen Puth
b2b473b24a [wpilib] Add AprilTag and AprilTagFieldLayout (#4421)
This is an API for looking up a Pose3d from a tag id, and includes functionality to load that map from a JSON file.

This also adds JSON support to Pose3d, Rotation3d. Translation3d, and Quaternion.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
Co-authored-by: AMereBagatelle <themerebagatelle@gmail.com>
2022-11-04 09:56:22 -07:00
Thad House
7aab8fa93a [build] Update to Native Utils 2023.6.0 (#4563) 2022-11-03 20:57:04 -07:00
Starlight220
12c2851856 [commands] WrapperCommand: inherit from CommandBase (#4561)
This makes WrapperCommand Sendable.
Only Java had this issue.
2022-11-03 06:27:23 -07:00
Tyler Veness
0da169dd84 [wpimath] Remove template argument from ElevatorFeedforward (#4554) 2022-11-02 22:54:32 -07:00
Tyler Veness
2416827c25 [wpimath] Fix docs for pose estimator local measurement models (#4558) 2022-11-02 22:53:21 -07:00
Michael Jansen
1177a3522e [wpilib] Fix Xbox/PS4 POV sim for port number constructors (#4548) 2022-11-02 22:52:26 -07:00
ohowe
102344e27a [commands] HID classes: Add missing methods, tweak return types (#4557)
- Make return type of getHID reflect the specific class
- Add getX and getY to CommandJoystick
2022-11-02 22:51:53 -07:00
Peter Johnson
1831ef3e19 [wpilib] Fix Shuffleboard SuppliedValueWidget (#4559)
It was creating duplicate publishers.
2022-11-02 22:49:52 -07:00
Starlight220
a9606ce870 [wpilib] Fix Xbox/PS4 POV sim (#4546) 2022-11-02 10:52:15 -07:00
Tyler Veness
6c80d5eab3 [wpimath] Remove unused SymbolExports.h include from units/base.h (#4541) 2022-11-01 17:18:24 -07:00
Peter Johnson
b114006543 [ntcore] Unify listeners (#4536)
This combines all 4 NT listener APIs (topic, value, connection, and
logging) into a single unified listener API.
2022-10-31 21:52:14 -07:00
Peter Johnson
32fbfb7da6 [build] cmake: Install ntcore generated include files (#4540) 2022-10-31 21:45:24 -07:00
Thad House
02465920fb [build] Update native utils to 2023.4.0 (#4539)
This has some decent changes to the toolchain plugin, so allwpilib is a great way to make sure nothing breaks.
2022-10-31 19:17:42 -07:00
David K Turner
3a5a376465 [wpimath] Increase constexpr support in geometry data types (#4231)
This uses std::is_constant_evaluated() to conditionally use the gcem library for constexpr calculations.
2022-10-31 09:17:00 -07:00
Peter Johnson
1c3c86e9f1 [ntcore] Cache GetEntry(name) values (#4531)
These are typically cached at higher levels anyway, but cache at lowest
C++ layer as well for consistency with NT3.
2022-10-27 23:34:58 -07:00
Starlight220
dcda09f90a [command] Rename trigger methods (#4210)
Motivation

Feedback from 2022 showed that the Trigger API is rather confusing, mostly due to the following:
- duplicate Trigger and Button APIs were available; users were confused searching for a nonexistent difference between them.
- the when terminology was ambiguous and unclear whether it refers to the high state or specifically the rising edge.
- the Active terminology didn't unambiguously refer to the high state; it wasn't unintuitive to understand it as "when the binding is active/polled".
- whileHeld vs whenHeld was very confusing, and the difference between them wasn't obvious. The parallel Trigger verbs, whileActiveContinuously and whileActiveOnce are much less confusing.

Solution

Deprecating Button and its binding methods. The rationale for deprecating Button (and not Trigger) is because Button uses terminology that is needlessly more specific and restricting to the button use case, making the use case of arbitrary trigger conditions unintuitive.

After consideration, deprecation of Button's subclasses was decided against:

- NetworkButton (a trigger condition based on a boolean NT entry/topic) is a use case that is not necessarily intuitive for teams to implement themselves, so it is an abstraction that should be provided in the library. A parallel class for the BooleanEvent level, NetworkBooleanEvent, was also added as part of NT4. NT listeners were considered as a alternative solution, but they require attention to thread safety, and aren't interoperable with the EventLoop API.
- JoystickButton/POVButton provide abstractions around HID buttons. The new Trigger-returning factories on the HID classes are an equal (if not more concise) alternative, but there is no reason not to keep them for those who find their use preferable.

At a later date in the deprecation cycle (perhaps for 2024), when Button is removed, these subclasses should be changed to inherit directly from Trigger.

Trigger's bindings are changed to use True/False terminology, as it should be unambiguous. Each binding type has both True and False variants; for brevity, only the True variants are listed here:

- onTrue (replaces whenActive): schedule on rising edge.
- whileTrue (replaces whileActiveOnce): schedule on rising edge, cancel on falling edge.
- toggleOnTrue (replaces toggleWhenActive): on rising edge, schedule if unscheduled and cancel if scheduled.

Two binding types are completely deprecated:

- cancelWhenActive: this is a fairly niche use case which is better described as having the trigger's rising edge (Trigger.rising()) as an end condition for the command (using Command.until()).
- whileActiveContinuously: however common, this relied on the no-op behavior of scheduling an already-scheduled command. The more correct way to repeat the command if it ends before the falling edge is using Command.repeatedly/RepeatCommand or a RunCommand -- the only difference is if the command is interrupted, but that is more likely to result in two commands perpetually canceling each other than achieve the desired behavior. Manually implementing a blindly-scheduling binding like whileActiveContinuously is still possible, though might not be intuitive.

Notes

It was considered to share BooleanEvent's digital signal terminology; however, once it was decided that Trigger should not inherit from BooleanEvent (due to overload incompatibility) the common terminology was not worth the unintuitiveness stemming from users' unfamiliarity with the signal processing terms.
2022-10-27 22:03:28 -07:00
Tyler Veness
66157397c1 [wpilib] Make drive classes follow NWU axes convention (#4079)
All trigonometric functions and vector classes assume North-West-Up axes
convention, so using North-East-Down convention with them is really
error-prone. We've broken something every time we touched the drive
classes.

We originally used North-East-Down to match the joystick convention, but
the volume of long-lived bugs has made this not worth it in retrospect.

The rest of WPILib also uses North-West-Up, so this makes things
consistent.

KilloughDrive was removed since no one uses it.
2022-10-27 21:59:11 -07:00
Peter Johnson
9e22ffbebf [ntcore] Fix null deref in NT3 client (#4530) 2022-10-27 21:56:15 -07:00
Thad House
648ab6115c [wpigui,dlt,glass,ov] Support arm in GUI tools (#4527) 2022-10-26 23:16:23 -07:00
Tyler Veness
8bc3b04f5b [wpimath] Make ComputerVisionUtil use 3D geometry classes (#4528)
Closes #4189.
2022-10-26 22:20:08 -07:00
Peter Johnson
cfb84a6083 [wpilibc] Don't hang waiting for NT server to start (#4524)
This matches Java behavior.
2022-10-26 10:29:56 -07:00
Tyler Veness
02c47726e1 [wpimath] Remove unused odometry instance from DifferentialDrivePoseEstimator test (#4522) 2022-10-25 22:19:44 -07:00
Peter Johnson
b2a0093294 [ci] Revert upgrade of github-pages-deploy-action (#4521)
It broke publishing
2022-10-25 19:20:30 -07:00
Justin
2a98d6b5d7 [wpimath] PIDController: Add getters for position & velocity tolerances (#4458) 2022-10-25 16:10:19 -07:00
Starlight220
9f36301dc8 [ci] Write wpiformat patch to job summary (#4519) 2022-10-25 12:30:43 -07:00
Jordan McMichael
901fc555f4 [wpimath] Position Delta Odometry for Mecanum (#4514) 2022-10-25 12:28:59 -07:00
Jordan McMichael
4170ec6107 [wpimath] Position Delta Odometry for Swerve (#4493) 2022-10-25 12:28:36 -07:00
sciencewhiz
fe400f68c5 [docs] Add wpinet to docs build (#4517)
Excludes libuv and libuv wrappers.
2022-10-25 08:47:28 -07:00
Peter Johnson
794669b346 [ntcore] Revamp listeners (#4511)
- In both C++ and Java, add listener functions to Instance class (same as NT3 provided)
- Add WaitForListenerQueue functions (same as NT3 provided)
- Move Java non-poller implementation to Instance (previously only handled single instance)
- Change C++ listeners to take non-const references for subscribers etc to help avoid footguns from use of temporary objects (also add doc comment)
- Fix Preferences making .type persistent
2022-10-24 23:27:24 -07:00
Peter Johnson
dcfa85a5d5 [ci] Build sanitizers with clang-14 (#4518) 2022-10-24 22:44:20 -07:00
Peter Johnson
15ad855f1d [ntcore] Add UnitTopic<T> (C++ only) (#4497)
This avoids the need for explicit value() calls (as compared to using
DoubleTopic).  The unit name is published as the "unit" property.

Implementation note: the test needs to be in wpilibc because ntcore does
not depend on wpimath.
2022-10-24 20:07:44 -07:00
Thad House
11244a49d9 [wpilib] Add IsConnected function to all gyros (#4465) 2022-10-24 20:04:16 -07:00
Thad House
1d2e8eb153 [build] Update myRobot deployment (#4515) 2022-10-24 20:03:39 -07:00
Thad House
ad53fb19b4 [hal] Use new HMB api for addressable LED (#4479)
Theres is now a built in HMB api, but you have to dlopen it to access it. Moved our existing infrastructure for this to its own class, added the new functions, then updated interrupts and LEDs to use it.
2022-10-24 18:26:07 -07:00
Thad House
ba850bac3b [hal] Add more shutdown checks and motor safety shutdown (#4510) 2022-10-23 21:59:04 -07:00
Peter Johnson
023a5989f8 [ntcore] Fix typo in NetworkServer client connect message (#4512) 2022-10-23 20:45:01 -07:00
sciencewhiz
c970011ccc [docs] Add Doxygen aliases used by Foonathan memory (#4509) 2022-10-23 18:12:24 -07:00
sciencewhiz
07a43c3d9a [readme] Document clang-format version and /wpiformat (#4503) 2022-10-23 15:59:33 -07:00
sciencewhiz
a05b212b04 [ci] Revert changes to wpiformat task from #4501 (#4508) 2022-10-23 15:49:59 -07:00
Starlight220
09faf31b67 [commands] Replace Command HID inheritance with delegation (#4470) 2022-10-23 12:09:44 -07:00
Starlight220
9e1f9c1133 [commands] Add command factories (#4476)
Co-authored-by: oblarg <emichaelbarnett@gmail.com>
2022-10-23 12:08:22 -07:00
Tyler Veness
f19d2b9b84 [ci] Add NUMBER environment variable to comment command commit script (#4507) 2022-10-23 11:34:03 -07:00
Tyler Veness
a28f93863c [ci] Push comment command commit directly to PR (#4506) 2022-10-23 11:17:52 -07:00
Tyler Veness
c9f61669b8 [ci] Fix comment command commit push (#4505) 2022-10-23 10:47:15 -07:00
Tyler Veness
dcce5ad3b3 [ci] Update github-script API usage (#4504) 2022-10-23 10:15:42 -07:00
Thad House
6836e5923d [wpilibc] Restore get duty cycle scale factor (#4502) 2022-10-23 07:05:09 -07:00
Peter Johnson
335188c652 [dlt] Add deselect/select all buttons to download view (#4499) 2022-10-22 22:12:47 -07:00
Peter Johnson
60a29dcb99 [glass] Field2D: Add "hidden" option for objects (#4498) 2022-10-22 22:12:25 -07:00
PJ Reiniger
b55d5b3034 [ci] Update deprecated github actions (#4501) 2022-10-22 21:09:44 -07:00
Peter Johnson
10ed4b3969 [ntcore] Various NT4 fixes (#4474)
* TopicListener: Fix Add() return values
* Update PubSubOption poll storage documentation
* Update NetworkTableEntry::GetValue() doc
* Add documentation regarding asynchronous callbacks
* Unpublish entry: set publisher to nullptr
* Implement ValueListenerPoller default constructor
* Remove SetNetworkIdentity, make parameter to StartClient
* URI-escape client ID, improve error message
* Add connected message with client id; also improve disconnected message a bit
* Handle SetServers either before or after StartClient
* Fix client use-after-free; also delay reconnect after disconnect to rate limit
* Don't re-announce to already subscribed client; we especially don't want to send the last value again
* Always accept in-order sets, only use timestamp for tiebreak
* Fix LocalStorage::StartNetwork race
* Remove unused/unimplemented function

Also:
* [glass] Remove debug print
* [glass] Fix mpack string decoding
* [cameraserver] Fix up startclient
2022-10-21 22:04:14 -07:00
Thad House
4a401b89d7 [hal, wpilib] New DS thread model and implementation (#3787)
The current DS thread model has some pretty major issues. It makes it difficult to know if all data is from the same remote packet, and if the data changes while the robot loop is running. Additionally, the DS thread is used for a few other things (MotorSafety and State Tracking for EducationalRobot). This also makes sim difficult, as user code has to wait for the thread to know it has new data.

This change completely rethinks how threading works in the driver station model.

First, the DS HAL system receives a new data callback, either from Netcomm or DriverStationSim. Inside the context of this callback, all the low latency data is read and put into a cache. Doing some investigation on the robot side, this is perfectly safe to do, and also ensures a ds packet will not be parsed before we finish reading the current packet data.

After all data is read, the cache is swapped with a 2nd buffer. This buffer just stores the data, none of the HAL DS calls read from this buffer. An event is then fired, stating there is new data ready to go.

Robot code calls HAL_UpdateDSData(). This swaps the 2nd buffer with a 3rd buffer, which always contains the current data. This data will not be updated until HAL_UpdateDSData is called again. Which solves the state problem.

The high level driver station classes have. an updateData() call, which calls HAL_UpdateDSData, and then update button state variables, then data log and update the NT FMS data table (Java also caches across the JNI boundary here, but that could trivially be removed). An extra event provider is provided, allowing other threads to know when this call has been completed.

IterativeRobotBase calls DS.updateData() at the beginning of each loop, and only once per loop. This means all commands will always have the same state.

All of this means there is no longer a DS thread. Everything happens synchronously. This means Sim and testing is easier, as you can just call DriverStationSim.NotifyNewData(), and then DriverStation.UpdateData(), and you can guarantee that all the DriverStation.*** data is up to date.

As for Motor Safety and Educational Robot State Handling, those can all be handled by their own threads. The Educational Thread only needs to run under EducationalRobot, and MotorSafety will only be started if there is a motor safety object enabled.
2022-10-21 22:01:55 -07:00
Tyler Veness
c195b4fc46 [wpimath] Clean up PoseEstimator nominal dt docs (#4496) 2022-10-21 19:53:58 -07:00
Tyler Veness
8f2e34c6a3 [build] Remove wpilib prefix from CMake flat install (#4492)
For system installs, `DESTDIR=/usr cmake --install buildfolder` installs
libraries to `/usr/lib` with the correct rpath. Example structure:
```
/usr/include/wpimath/frc/controller/LinearQuadraticRegulator.h
/usr/lib/libwpimath.so
```

Users need to provide `-I/usr/include/wpimath` in their projects. This
is an artifact of the install() commands being in the subdirectory CMake
files.

For other locations, `DESTDIR=/opt/wpilib cmake --install buildfolder`
installs libraries to `/opt/wpilib/lib`. Example structure:
```
/opt/wpilib/include/wpimath/frc/controller/LinearQuadraticRegulator.h
/opt/wpilib/lib/libwpimath.so
```
2022-10-21 19:23:56 -07:00
Tyler Veness
150d692df7 [wpimath] Remove unused private PoseEstimator function (#4495) 2022-10-21 19:22:37 -07:00
shueja-personal
3e5bfff1b5 [wpimath] FromFieldRelativeSpeeds: Add ChassisSpeeds overload (#4494) 2022-10-21 18:58:23 -07:00
Starlight220
9c7e66a27d [commands] C++: Add CommandPtr overload for SetDefaultCommand (#4488) 2022-10-21 06:35:58 -07:00
Tyler Veness
0ca274866b [build] Fix CMake system library opt-ins (#4487)
-DUSE_SYSTEM_EIGEN now only removes include paths for Eigen instead of
drake as well.

The USE_VCPKG flags were renamed to USE_SYSTEM since they seem general
enough for that to work (the find_package() commands work the same way
on Arch).

The system libuv CMake build now works with Linux libuv as well.
2022-10-20 19:47:12 -07:00
Starlight220
dc037f8d41 [commands] Remove EndlessCommand (#4483) 2022-10-20 17:24:54 -07:00
Tyler Veness
16cdc741cf [wpimath] Add Pose3d(Pose2d) constructor (#4485) 2022-10-20 17:23:00 -07:00
Tyler Veness
9d5055176d [build] cmake: Allow disabling ntcore build (#4486) 2022-10-20 17:21:31 -07:00
Thad House
d1e66e1296 [build] Compile all java code with inline string concatenation (#4490)
Workaround identified in https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8278540
2022-10-20 17:20:36 -07:00
Tyler Veness
1fc098e696 Enable log macros to work with no args (#4475)
This is enabled by the C++20 __VA_OPT__ feature.
Uses of "{}" format string were updated.
Some warning suppressions were required for older clang versions.
Also improve codegen of wpi::Logger::Log(), frc::ReportError(), and frc::MakeError();
these generate better and less redundant code if they use fmt::string_view for the
format string instead of templating on it.
2022-10-19 10:49:27 -07:00
Peter Johnson
878cc8defb [wpilib] LiveWindow: Add enableAllTelemetry() (#4480) 2022-10-17 14:39:57 -07:00
Thad House
8153911160 [build] Fix MSVC runtime archiver to grab default runtime (#4478) 2022-10-16 15:37:13 -07:00
Tyler Veness
fbdc810887 Upgrade to C++20 (#4239)
* Use explicit this capture required by C++20
* Use C++20 span
* Replace wpi::numbers with std::numbers
* Fix C++20 clang-tidy warning false positive in fmt
* Remove ciso646 include since C++20 removed that header
* Fix global-buffer-overflow asan warnings in ntcore tests
* Add DIOSetProxy constructor to HAL

* Upgrade MSVC compiler to 2022
* Bump native-utils to 2023.2.7 (changes to std=c++20)

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2022-10-15 16:33:14 -07:00
Thad House
396143004c [ntcore] Add ntcoreffi binary (#4471)
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2022-10-15 01:02:38 -07:00
Peter Johnson
1f45732700 [build] Update to 2023.2.4 native-utils and new dependencies (#4473)
* Disable class-memaccess warning in Eigen
* Shim NiFpga_OpenHostMemoryBuffer
* Don't deploy .debug files in integration tests
2022-10-14 23:36:47 -07:00
Peter Johnson
574cb41c18 [ntcore] Various fixes (#4469)
* Fix C++ Publisher and Subscriber move assignment 
* Fix Publisher comment typo.
* Publish: check that properties is an object.
Print a warning, but still publish, just with empty properties.
Add error print for unassigned type publish.
* Return boolean from SetProperties
* Document exception-throw in Java for invalid JSON.
2022-10-14 20:50:55 -07:00
Thad House
d9d6c425e7 [build] Force Java 11 source compatibility (#4472)
We want to have the option of falling back to a Java 11 runtime, at least for this year.
2022-10-14 19:39:54 -07:00
Thad House
58b6484dbe Switch away from NI interrupt manager to custom implementation (#3705)
* Switch away from NI interrupt manager to custom implementation

* Formatting

* Fix tidy

* Formatting

* Fix loading

* Make interrupt api public

* Add multiple wait api

* Formatting

* Fix build

* Fix review comments

* wpiformat

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-10-13 17:25:54 -07:00
Tyler Veness
ca43fe2798 [wpimath] Use Units conversions in ComputerVisionUtil docs (NFC) (#4464) 2022-10-12 13:54:15 -07:00
Thad House
87a64ccedc [hal] Convert DutyCycle Raw output to be a high time measurement (#4466)
The existing raw time has an issue where it jumps around, as in the FPGA if the frequency is not a multiple or divisor of 25 Mhz it jumps around by 1 every second. While waiting on an FPGA change, update the API to make raw output give nanoseconds rather then a scaled value. This does a longer read cycle to get the correct value, but in the future if a fast FPGA function is added this can be easily changed.
2022-10-12 10:15:09 -07:00
Starlight220
89a3d00297 [commands] Add FinallyDo and HandleInterrupt decorators (#4412) 2022-10-11 09:53:27 -07:00
Starlight220
1497665f96 [commands] Add C++ versions of Java-only decorators (#4457) 2022-10-10 09:00:11 -07:00
Ryan Blue
27b173374e [wpimath] Add minLinearAccel parameter to DifferentialDriveAccelerationLimiter (#4422) 2022-10-10 08:57:37 -07:00
Ryan Blue
2a13dba8ac [wpilib] TrajectoryUtil: Fix ambiguous documentation (NFC) (#4461) 2022-10-10 08:56:40 -07:00
Peter Johnson
77301b126c [ntcore] NetworkTables 4 (#3217) 2022-10-08 10:01:31 -07:00
Peter Johnson
90cfa00115 [build] cmake: Fix libssh include directory order (#4459)
This broke the build if the directory where libssh was installed also
contained a system libuv install.
2022-10-07 22:53:22 -07:00
Starlight220
5cf961edb9 [commands] Refactor lambda-based commands to inherit FunctionalCommand (#4451) 2022-10-06 17:49:27 -05:00
Starlight220
b2276e47de [wpimath] Enable continuous angle input for HolonomicDriveController (#4453) 2022-10-06 17:46:22 -05:00
PJ Reiniger
893b46139a [fieldImages] Add utilities to simplify loading of fields (#4456) 2022-10-06 17:45:07 -05:00
Starlight220
60e29627c0 [commands] C++ unique_ptr migration (#4319)
Add a CommandPtr with an internal unique_ptr to enable not needing to move the underlying classes, which is error-prone due to the potential for lambda captures.
2022-10-05 17:19:28 -05:00
Starlight220
3b81cf6c35 [wpilib] Improve Color.toString (#4450) 2022-10-04 14:36:51 -05:00
Peter Johnson
5c067d30a0 [wpinet] WebSocket: Add SendFrames() (#4445) 2022-10-03 08:04:08 -05:00
Peter Johnson
ceaf493811 [wpiutil] MakeJByteArray: Use span<uint8> instead of string_view (#4446) 2022-10-02 08:28:50 -05:00
Starlight220
10e04e2b13 [examples] FrisbeeBot: Fix reference capture (#4449)
The parameter should be passed by value.
2022-10-02 08:18:43 -05:00
Peter Johnson
726f67c64b [build] Add exeSplitSetup (#4444) 2022-10-02 08:13:08 -05:00
Peter Johnson
c7b7624c1c [wpiutil] Add MessagePack utility functions (#4448)
Also add mpack to srcDirs.
2022-10-02 08:11:42 -05:00
Peter Johnson
d600529ec0 [wpinet] uv::Async: Add UnsafeSend() (#4447)
This version assumes the loop still exists, avoiding some overhead.
2022-10-02 08:10:54 -05:00
Tyler Veness
b53b3526a2 [wpimath] Add CoordinateSystem conversion for Transform3d (#4443)
I also refactored Pose3d's conversion implementation to use the
Translation3d and Rotation3d conversions, thereby giving Translation3d
and Rotation3d test coverage. No changes were made to the expected
values of the Pose3d conversion tests.

The expected values of the Transform3d conversion tests were copied from
the Pose3d conversion tests without modification.
2022-10-01 21:09:04 -07:00
Tyler Veness
38bb23eb18 [wpimath] Add scalar multiply and divide operators to all geometry classes (#4438)
Closes #4435.
2022-09-28 21:34:29 -07:00
Tyler Veness
3937ff8221 [wpilib] Remove deprecated Controller class (#4440)
Now that old command-based has been removed, this base class can be
removed too.
2022-09-28 21:33:55 -07:00
Oliver W
abbfe244b5 [wpilib] Improve Color FromHSV (#4439) 2022-09-28 21:33:33 -07:00
Dustin Spicuzza
4ddb8aa0dd [sim] Provide function that resets all simulation data (#4016)
Fixes #3867
2022-09-26 14:38:38 -07:00
Tyler Veness
a791470de7 Clean up Java warning suppressions (#4433)
Checkstyle naming conventions were changed to allow most of what's in
wpimath. Naming rules were disabled completely in wpimath since almost
all suppressions are for math notation.
2022-09-24 00:13:55 -07:00
Thad House
17f504f548 [hal,wpilib] Fix SPI Mode Setting (#4434)
SPI Mode setting was very broken. MSB and LSB sets did not work (MSB is the only one supported)
and if LSB was set (which was the default) the ioct to set clock phase would fail. This
deprecates all the individual functions, the LSB/MSB functions, and adds an SPI mode selection
function. This is usually more understandable, and shows up in a lot more documentation
2022-09-24 00:11:37 -07:00
Tyler Veness
773198537c [wpiutil] Add wpi::scope_exit (#4432)
This is based on std::scope_exit in the C++ library fundamentals TS v3.
2022-09-23 14:48:59 -07:00
Peter Johnson
5ac658c8f0 [wpiutil] Logger: Conditionalize around WPI_LOG (#4431)
The FMT_STRING() call used in the macro does formatter initialization,
overhead that's not required if Log() is not going to be called.
2022-09-22 23:14:46 -07:00
Peter Johnson
8767e4a941 [wpiutil] DataLog: Fix SetMetadata output (#4430) 2022-09-22 21:54:55 -07:00
Peter Johnson
8c4af073f4 [wpiutil] Synchronization: shutdown race protection (#4429) 2022-09-22 21:53:51 -07:00
Thad House
c79f38584a [build] Fix Java integration tests (#4428)
The new jni libraries for the libraries were never added, so they never get deployed.
2022-09-21 23:15:35 -07:00
Starlight220
36c08dd97c [build] Fix cmake install of fmtlib (#4426) 2022-09-20 09:48:44 -07:00
Peter Johnson
69b7b3dd7d [ci] Remove the Windows cmake job (#4425)
This currently is running into space issues due to vcpkg that are
difficult to fix.
2022-09-18 18:24:55 -07:00
Ryan Blue
738c75fed8 [readme] Fix formatting/linting link (#4423) 2022-09-18 15:12:28 -07:00
Tyler Veness
4eb1d03fb3 [wpimath] Document C++ LinearFilter exception (#4417) 2022-09-17 00:24:35 -07:00
Tyler Veness
ba4ec6c967 [build] Fix clang-tidy false positive on Linux (#4406)
* Fix clang-tidy false positive on Linux

```
== clang-tidy /home/tav/frc/wpilib/allwpilib/wpiutil/src/main/native/windows/StackTrace.cpp ==
/home/tav/frc/wpilib/allwpilib/wpiutil/src/main/native/windows/StackTrace.cpp:12:33: error: expected class name [clang-diagnostic-error]
class StackTraceWalker : public StackWalker {
                                ^
/home/tav/frc/wpilib/allwpilib/wpiutil/src/main/native/windows/StackTrace.cpp:16:17: error: unknown type name 'LPCTSTR' [clang-diagnostic-error]
  void OnOutput(LPCTSTR szText) override;
                ^
/home/tav/frc/wpilib/allwpilib/wpiutil/src/main/native/windows/StackTrace.cpp:23:33: error: unknown type name 'LPCTSTR' [clang-diagnostic-error]
void StackTraceWalker::OnOutput(LPCTSTR szText) {
                                ^
```

* Fix false positives for macOS code
2022-09-17 00:23:59 -07:00
Ryan Blue
97836f0e55 [commands] Fix ProfiledPIDSubsystem setGoal behavior (#4414)
Remove m_goal from ProfiledPIDSubsystem

Delegate setGoal to backing controller
2022-09-17 00:22:45 -07:00
Tyler Veness
fdfb85f695 [wpimath] Remove Java LQR constructor that takes a controller gain matrix (#4419)
The controller gain matrix K should be computed from the solution to the
DARE, but this constructor does not do that. It effectively violates a
postcondition enforced by the other constructors by letting the user
throw in a controller gain matrix that didn't come from an LQR.

Removing this constructor is a breaking change, but it never should have
been included in the class in the first place. There's also no valid
reason to use it. I assume it was originally added for debugging the
class internals.

This constructor does not exist in C++.
2022-09-17 00:18:08 -07:00
Tyler Veness
ab1baf4832 [wpimath] Add rotation matrix constructor to Rotation3d (#4413) 2022-09-17 00:17:30 -07:00
Tyler Veness
9730032866 [wpimath] Document LQR and KalmanFilter exceptions (#4418) 2022-09-17 00:16:40 -07:00
Brandon Parsons
5b656eecf6 [wpimath] Fix HTML5 entity (#4420)
Replace &top; with \u22a4, since Unicode references are supported
but HTML5 entities are not. Should be fixed if JDK is ever
moved forward.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-09-17 00:15:40 -07:00
Starlight220
9ae38eaa7c [commands] Add owning overload to ProxyScheduleCommand (#4405) 2022-09-13 18:33:19 -07:00
Starlight220
cb33bd71df [commands] deprecate withInterrupt decorator (#4407)
until() was recently added as a more intuitive alias for this. At this point, keeping this decorator will just cause confusion, given the functionally-equivalent until() alias and the similarly-named getInterruptionBehavior/withInterruptBehavior
2022-09-11 10:37:55 -07:00
Starlight220
d9b4e7b8bf [commands] Revert "Change grouping decorator impl to flatten nested group structures (#3335)" (#4402)
This reverts commit ef4ea84cb5.
2022-09-07 09:04:21 -07:00
T Grinch
0389bf5214 [hal] REVPH: Improve handling of disconnected CAN Bus (#4169)
Force the status to be 0 (no error) upon initialization of the REV PneumaticHub.
This prevents a program crash in the case of a robot code restart with no CAN Bus present.
2022-09-07 09:01:55 -07:00
T Grinch
4267fa08d1 [wpilibc] ADIS IMUs: Fix memory leak (#4170) 2022-09-06 13:10:33 -07:00
Peter Johnson
65c8fbd452 [wpilib] MotorControllerGroup: Override setVoltage (#4403)
This causes setVoltage to be called on the lower level motor contollers,
which is benefical in cases when they are smart motor controllers.
Previously, the default implementation (using the bus voltage and
calling set()) was used in this case.

This does slightly pessimize the case when the lower level motor
controllers use the default setVoltage implementation, but given the
prevalence of smart motor controllers, this seems like an overall win.
2022-09-06 08:18:33 -07:00
Tyler Veness
f36162fddc [wpimath] Improve Discretization internal docs (#4400) 2022-09-04 17:24:38 -07:00
Tyler Veness
5149f7d894 [wpimath] Add two-vector Rotation3d constructor (#4398)
This is useful for turning a 3D vector into an orientation relative a
coordinate system vector.
2022-09-04 13:16:29 -07:00
Tyler Veness
20b5bed1cb [wpimath] Clean up Java Quaternion class (#4399)
Vector.norm() and Vector.dot() were added to make the implementation
simpler and match the C++ version more closely.
2022-09-04 09:45:02 -07:00
Peter Johnson
f18dd1905d [build] Include all thirdparty sources in distribution (#4397)
Was missing several.
2022-09-03 09:23:51 -07:00
Peter Johnson
aa9d7f1cdc [wpiutil] Import foonathan memory (#4306) 2022-09-02 20:32:21 -07:00
Peter Johnson
2742662254 [ci] Remove a couple of obsolete clang-tidy checks (#4396)
We no longer use LLVM StringRef or Twine.
2022-09-02 20:31:27 -07:00
Thad House
a5df391166 [hal, wpilib] Fix up DIO pulse API (#4387)
The FPGA API takes microseconds directly, instead of a scaled value. Also add a new HAL level API to trigger multiple DIOs with the same pulse at once.
2022-09-02 16:49:42 -07:00
Peter Johnson
59e6706b75 [glass] Turn on docking by default
This uses a full-viewport dockspace and shift to enable docking.
2022-09-02 15:43:54 -07:00
Peter Johnson
8461bb1e03 [glass] Add support for saving docking info 2022-09-02 15:43:54 -07:00
Peter Johnson
b873e208b4 [wpigui] Add support for imgui config flags 2022-09-02 15:43:54 -07:00
Peter Johnson
873e72df8c [build] Update imgui to 1.88 docking branch 2022-09-02 15:43:54 -07:00
Peter Johnson
c8bd6fc5b4 [ci] Fix comment-command (take 2) (#4395) 2022-09-02 08:51:07 -07:00
Peter Johnson
fed68b83b4 [ci] Fix comment-command action not running runners (#4393)
Triggering runners from a push from a runner requires use of a PAT.
https://stackoverflow.com/questions/67550727/push-event-doesnt-trigger-workflow-on-push-paths-github-actions
2022-09-02 08:16:31 -07:00
Tyler Veness
0ef8a4e1df [wpimath] Support formatting more Eigen types (#4391)
Added an Eigen::SparseMatrix formatter.

Also modified the Eigen::Matrix formatter to support Eigen::MatrixXd.
Eigen::MatrixXd sets both dimension template arguments to -1, so they
can't be used for iteration. rows() and cols() are now used instead.

rows() and cols() are constexpr for statically sized matrices, so
there's no performance loss there.
2022-09-02 01:00:05 -07:00
Thad House
c393b3b367 [build] Update to native utils 2023.1.0 and Gradle 7.5.1 (#4392) 2022-09-02 00:59:47 -07:00
ohowe
b5a17f762c [wpimath] Add direction to slew rate limiter (#4377) 2022-09-01 14:46:46 -07:00
Tyler Veness
fafc81ed1a [wpiutil] Upgrade to fmt 9.1.0 (#4389) 2022-09-01 14:45:18 -07:00
Peter Johnson
cc56bdc787 [wpiutil] SafeThread: Add Synchronization object variant (#4382)
This enables use of SafeThread with Synchronization's WaitForObjects() blocking.
2022-08-31 11:29:57 -07:00
Starlight220
4254438d8d [commands] Mark command group lifecycle methods as final (#4385)
This prevents accidental footguns due to overriding of command group lifecycle methods.
2022-08-31 09:15:28 -07:00
CarloWoolsey
97c15af238 [wpimath] LinearSystemId: Fix docs, move C++ impls out of header (#4388)
- Fix inaccuracies and inconsistencies in Java & C++ LinearSystemId documentation.
- Move LinearSystemId function definitions to LinearSystemId.cpp
2022-08-31 09:12:48 -07:00
Peter Johnson
d22ff8a158 [wpiutil] Add JNI access to C++ stderr (#4381)
This is useful in some debugging scenarios.  System.err is separately buffered, so when e.g. debugging test cases it doesn't interleave correctly with the C++ stdout/stderr logging. Even using flush() doesn't seem to help, I think because Gradle does its own buffering.
2022-08-30 20:40:16 -07:00
Peter Johnson
fdb5a2791f [wpiutil] jni_util: Add Mac-friendly MakeJLongArray/JArrayRef (#4383)
Mac has jlong == long long and int64_t = long, so the types are
incompatible despite being the same size.
2022-08-30 20:39:42 -07:00
Starlight220
c3a93fb995 [commands] Revamp Interruptible (#4192) 2022-08-29 21:53:47 -07:00
OmegaMetor
f2a8d38d2a [commands] Rename Command.repeat to repeatedly (#4379) 2022-08-29 15:20:17 -07:00
Peter Johnson
9e24c6eac0 [wpiutil] Logger: paren-protect instance usage in macro (#4384) 2022-08-29 13:25:53 -07:00
Tyler Veness
fe4d12ce22 [wpimath] Add LTV controller derivations and make enums private (#4380)
The LTV differential drive controller derivation wasn't included inline
because it's too long.
2022-08-28 23:04:52 -07:00
Brandon Parsons
eb08486039 [build] Fix MacOS binary rpath generation (#4376)
For RPATH on MacOS use '@loader_path' instead of '$ORIGIN' to reference the directory where the executable is located. The latter is the mechanism used on Linux.

I think this was exposed due to newer OS X ignoring $DYLD_LIBRARY_PATH for security reasons.
2022-08-25 18:17:16 -07:00
Tyler Veness
ccf83c634a [build] Use native-utils platform names instead of raw strings (#4375) 2022-08-25 12:54:11 -07:00
Peter Johnson
3fd69749e7 [docs] Upgrade to doxygen 1.9.4 (#4370)
Doxygen 1.9.2 requires libclang-9, which is no longer available on
Ubuntu 22.04.
2022-08-21 18:49:04 -07:00
Peter Johnson
594df5fc08 [wpinet] uv/util.h: Pull in ws2_32.lib on Windows for ntohs (#4371) 2022-08-21 18:48:49 -07:00
Tyler Veness
539070820d [ci] Enable asan for wpinet and wpiutil (#4369) 2022-08-21 14:59:07 -07:00
Peter Johnson
564a56d99b [wpinet] Fix memory leak in WorkerThreadTest (#4368) 2022-08-21 10:29:31 -07:00
Tyler Veness
5adf50d93c [upstream_utils] Refactor upstream_utils scripts (#4367)
* Root folder variable names are now more descriptive
* clone_repo() now restores the current working directory
* Removed setup_upstream_repo() since it's now identical to clone_repo()
* Moved am_patches()'s for loop into user scripts so the filename prefix
  doesn't need to be included in every patch filename
* Renamed am_patches() to git_am() since its only job now is to run "git am"
* Removed unused apply_patches() function
* Fixed typo in git_am()'s ignore_whitespace arg name
2022-08-20 07:26:34 -07:00
Tyler Veness
d80e8039d7 [wpiutil] Suppress fmtlib clang-tidy warning in C++20 consteval contexts (#4364) 2022-08-19 23:52:19 -07:00
Tyler Veness
0e6d67b23b [upstream_utils] Remove yapf format disable comment (#4366) 2022-08-19 23:51:57 -07:00
Tyler Veness
be5270697a [build] Suppress enum-enum deprecation warning in OpenCV (#4365) 2022-08-19 23:51:43 -07:00
Tyler Veness
8d28851263 Add Rosetta install command to build requirements (#4363) 2022-08-18 19:58:43 -07:00
Tyler Veness
3d2115c93e [wpinet] include-what-you-use in MulticastTest (#4360)
This fixes an MSVC compilation error with C++20.
2022-08-18 14:03:55 -07:00
Tyler Veness
91002ae3cc [wpimath] Upgrade to Drake 1.6.0 (#4361) 2022-08-18 14:03:28 -07:00
Tyler Veness
148c18e658 [wpinet] Upgrade to libuv 1.44.2 (#4362) 2022-08-18 13:57:49 -07:00
Tyler Veness
a2a5c926b6 Fix clang-tidy warnings (#4359)
The warnings included recommendations of braces for if statement
readability, a recommendation for default initialization of an int
array, and include-what-you-use (indirectly through clang-tidy reporting
undefined symbols).
2022-08-17 19:53:56 -07:00
Tyler Veness
ea6b1d8449 [wpiutil] Remove unused ManagedStatic class (#4358)
We migrated to magic statics for lazy construction like the following:
```cpp
class Singleton {
  static Singleton& GetSingleton() {
    static Singleton instance;
    return instance;
  }
};
```
2022-08-17 18:04:42 -07:00
Tyler Veness
ac9be78e27 Use stricter C++ type conversions (#4357)
Now, implicit narrowing conversions are only used with wpi::Now(). This
also fixes clang-tidy warnings about C-style casts. For example:
```
== clang-tidy /__w/allwpilib/allwpilib/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc ==
/__w/allwpilib/allwpilib/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc:95:18: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting]
  auto curTime = units::second_t(m_timer.Get());
                 ^
```
In that case at least, the cast was removed entirely since Get() already
returns a units::second_t.
2022-08-17 13:42:36 -07:00
Tyler Veness
151dabb2af [wpiutil] Upgrade to fmt 9.0.0 (#4337)
fmt removed fmt::make_args_checked since it's no longer needed for
constexpr format string checks.

fmt deprecated implicit conversions from enums to integers in format
arguments, so I added explicit static casts.
2022-08-16 15:35:26 -07:00
Tyler Veness
340465c929 [ci] Upgrade to clang-format and clang-tidy 14 (NFC) (#4347) 2022-08-16 15:25:04 -07:00
Michael Leong
d45bcddd15 [examples] Add comments to StateSpaceDifferentialDrive (#4341) 2022-08-15 06:26:20 -07:00
Tyler Veness
0e0786331a Update LLVM libraries to 14.0.6 (#4350)
The main noticeable change is the SmallString conversion operator to std::string is now explicit instead of implicit.
2022-08-15 05:38:15 -07:00
Tyler Veness
c5db23f296 [wpimath] Add Eigen sparse matrix and iterative solver support (#4349)
These are useful for efficiently solving huge, but sparse systems of
equations that occur often in optimization problems.
2022-08-13 18:32:02 -07:00
Tyler Veness
44abc8dfa6 [upstream_utils] Remove git version from upstream patches (#4351)
This reduces commit noise when other git versions are used. The version
was removed by passing `--no-signature` to `git format-patch` which is
now documented in the readme.
2022-08-13 18:31:26 -07:00
Tyler Veness
3fdb2f767d [wpimath] Add comments with Ramsete equations (#4348) 2022-08-11 07:09:16 -07:00
Tyler Veness
0485f05da9 [wpilibjExamples] Upgrade jacoco to match allwpilib (#4346) 2022-08-05 10:21:40 -07:00
Thad House
0a5eb65231 [wpinet] Handle empty txt block for mdns announcer (#4072) 2022-08-03 11:15:56 -07:00
sciencewhiz
19ffebaf3e [wpilib] Add reference to I2C Lockup to API Docs (NFC) (#4340) 2022-07-29 21:01:21 -07:00
Tyler Veness
ce1a90d639 [hal] Replace SerialHelper "goto done" with continue (#4342)
The logic is already correct for closing all the objects. So we should just be continuing on error.
2022-07-27 14:37:32 -07:00
Tyler Veness
d25af48797 [ci] Make upstream_utils CI fail on untracked files (#4339)
This catches issues like update scripts putting new files in a different
directory from the old ones.
2022-07-24 19:34:16 -07:00
Jeffrey Morris
ebb836dacb [examples] Fix negations in event loop examples (#4334) 2022-07-24 19:33:52 -07:00
Tyler Veness
d83e202f00 [upstream_utils] Update paths in update_fmt.py (#4338) 2022-07-22 18:08:36 -07:00
Tyler Veness
3ccf806064 [wpimath] Remove redundant LinearFilter.finiteDifference() argument (#4335)
The number of samples is already determined by the length of the stencil
list.
2022-07-22 12:50:30 -05:00
Tyler Veness
6f1e01f8bd [wpimath] Document example of online filtering for LinearFilter.finiteDifference() (#4336) 2022-07-22 12:46:33 -05:00
sciencewhiz
1023c34b1c [readme] Update location of ni-libraries (#4333)
Fixes #4321
2022-07-09 17:44:03 -05:00
Tyler Veness
faa29d596c [wpilib] Improve Notifier docs (NFC) (#4326) 2022-07-01 06:45:00 -07:00
Tyler Veness
add00a96ed [wpimath] Improve DifferentialDriveAccelerationLimiter docs (NFC) (#4323)
Defined trackwidth, added skipped steps to the algorithm's internal
proof, and grouped the algorithm steps more logically with blank lines.
2022-07-01 06:43:57 -07:00
Tyler Veness
82fac41244 [wpimath] Better document trackwidth parameters (NFC) (#4324) 2022-07-01 06:42:49 -07:00
Tyler Veness
5eb44e22a9 Format Python scripts with black (NFC) (#4325) 2022-07-01 06:41:44 -07:00
Peter Johnson
2e09fa7325 [build] Fix mpack cmake (#4322) 2022-06-24 19:35:13 -07:00
Starlight220
fe3c24b1ee [command] Add ignoringDisable decorator (#4305) 2022-06-24 10:52:53 -07:00
Thad House
aa221597bc [build] Add M1 builds, change arm name, update to 2023 deps (#4315) 2022-06-20 12:28:46 -06:00
Tyler Veness
579a8ee229 [ci] Use one worker for Windows release Gradle build (#4318)
It was running out of heap space.
2022-06-18 22:45:12 -07:00
Justus
5105c5eab6 [wpilibj] Change "final" to "exit" in the IterativeRobotBase JavaDoc (NFC) (#4317)
"exit" is used in every other instance.
2022-06-18 15:02:36 -07:00
PJ Reiniger
787fe6e7a5 [wpiutil] Separate third party libraries (#4190) 2022-06-18 08:08:31 -07:00
ohowe
6671f8d099 [wpigui] Update portable file dialogs (#4316)
All commits from March 16, 2022 to June 1, 2022
This fixes the save button in sysid on macOS.
2022-06-17 22:47:22 -07:00
Starlight220
9ac9b69aa2 [command] Reorder Scheduler operations (#4261)
Fixes several cases where calling scheduler operations from a command callback could result in NPEs or other issues.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-06-15 23:32:16 -07:00
Tyler Veness
e61028cb18 [build] halsim_gui: Add wpinet dependency (#4313) 2022-06-15 23:14:31 -07:00
ohowe
661d23eaf5 [glass] Add precision setting for NetworkTable view (#4311) 2022-06-15 21:21:52 -07:00
Tyler Veness
666040e3e5 [hal] Throw exceptions for invalid sizes in I2C and SPI JNI (#4312)
GCC's static analyzer is correctly reporting that resize() requires an
unsigned integer, but the argument provided in the JNI function could be
negative since it's a signed byte. Throwing an exception if the argument
is negative fixes the warning.
2022-06-15 21:20:52 -07:00
Tyler Veness
aebc272449 [build] Upgrade to spotbugs Gradle plugin 5.0.8 (#4310)
This fixes a SecurityManager deprecation warning generated by spotbugs.
2022-06-14 20:26:53 -07:00
Starlight220
fd884581e4 [wpilib] Add BooleanEvent/Trigger factories on HID classes (#4247) 2022-06-13 22:48:16 -07:00
Tyler Veness
9b1bf5c7f1 [wpimath] Move Drake and Eigen to thirdparty folders (#4307) 2022-06-11 21:07:15 -07:00
Starlight220
c9e620a920 [wpilibc] Change EventLoop data structure to vector (#4304) 2022-06-10 05:38:54 -07:00
Peter Johnson
41d40dd62f [wpinet] Fix libuv unused variable warning on Mac (#4299) 2022-06-09 23:30:16 -07:00
PJ Reiniger
30f5b68264 [wpinet] Fix JNI loading error (#4295) 2022-06-08 22:21:22 -07:00
DeltaDizzy
f7b3f4b90e [examples] Getting Started: Change Joystick to XboxController (#4194) 2022-06-08 22:20:33 -07:00
Connor Worley
a99c11c14c [wpimath] Replace UKF implementation with square root form (#4168)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-06-08 22:19:01 -07:00
Starlight220
45b7fc445b [wpilib] Add EventLoop (#4104)
This is a generic expansion of the command-based Trigger framework.
2022-06-08 22:16:51 -07:00
Peter Johnson
16a4888c52 [wpilib] Default off LiveWindow telemetry (#4301)
The original idea of LiveWindow telemetry was to automatically make
telemetry data visible to users.  This has proved increasingly
problematic in recent years due to the "spooky action at a distance"
of telemetry happening for objects that are only constructed but not
used, and blocking or slow object reads resulting in hard-to-debug
loop overrun conditions.
2022-06-08 22:13:00 -07:00
Thad House
17752f1337 [ci] Split debug and release Windows builds (#4277)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-06-06 17:25:02 -07:00
Starlight220
abb45a68db [commands] Remove custom test wrappers (#4296)
Use AtomicBoolean and AtomicInteger instead of
custom ConditionHolder and Counter classes.
2022-06-06 17:13:11 -07:00
Peter Johnson
1280a54ef3 [upstream_utils]: Make work with Python 3.8 (#4298)
str.removesuffix() is only available in Python 3.9, which is not in many
Linux installations.
2022-06-06 17:07:16 -07:00
Starlight220
f2d243fa68 [build] Change defaults for Java lints (#4300)
Removes the need to individually suppress the "serial" warning.
2022-06-06 17:06:43 -07:00
sciencewhiz
a4787130f4 Update using development build to work with 2023 gradlerio (#4294) 2022-06-04 13:58:51 -07:00
Prateek Machiraju
af7985e46c [wpiutil] Use invoke_result_t instead of result_of in future.h (#4293)
std::result_of is deprecated in C++17.
2022-06-02 23:04:20 -07:00
Tyler Veness
e9d1b5c2d0 [hal] Remove deprecated SimDevice functions (#4209) 2022-06-02 22:53:02 -07:00
Prateek Machiraju
45b598d236 [wpilibj] Add toString() methods to Color and Color8Bit (#4286) 2022-06-02 21:23:11 -07:00
Prateek Machiraju
fc37265da5 [wpimath] Add angle measurement convention to ArmFeedforward docs (NFC) (#4285) 2022-06-02 21:22:47 -07:00
Prateek Machiraju
a4ec13eb0e [wpilibjexamples] Remove unnecessary voltage desaturation 2022-06-02 21:22:19 -07:00
Prateek Machiraju
2fa52007af [wpilibc] Use GetBatteryVoltage() in MotorController::SetVoltage
This avoids having to cast to units::voltage_t
2022-06-02 21:22:19 -07:00
Prateek Machiraju
d9f9cd1140 [wpimath] Reset prev_time on pose estimator reset (#4283) 2022-06-02 21:21:42 -07:00
truher
8b6df88783 [wpilibj] Tachometer.getFrequency(): Fix bug (#4281)
Now it returns 1/period (like Tachometer.cpp); before it just returned period.
2022-06-01 10:13:19 -07:00
Tyler Veness
345cff08c0 [wpiutil] Make wpi::array constexpr (#4278) 2022-05-31 20:21:29 -07:00
Tyler Veness
57428112ac [wpimath] Upgrade to Drake v1.3.0 (#4279) 2022-05-31 20:20:01 -07:00
Thad House
a18d4ff154 [build] Fix tools not being copied when built with -Ponly* (#4276) 2022-05-29 22:09:00 -07:00
Peter Johnson
d1cd07b9f3 [wpigui] Add OpenURL (#4273)
This function opens a URL using the default browser.
2022-05-29 18:45:39 -07:00
Peter Johnson
e67f8e917a [glass] Use glfwSetKeyCallback for Enter key remap (#4275)
The imgui internals methods break with imgui >= 0.87.
2022-05-29 18:44:52 -07:00
Tyler Veness
be2fedfe50 [wpimath] Add stdexcept include for std::invalid_argument (IWYU) (#4274) 2022-05-29 15:33:19 -07:00
Peter Johnson
7ad2be172e [build] Update native-utils to 2023.0.1 (#4272)
Also remove x86 build bits.
2022-05-28 11:12:59 -07:00
Peter Johnson
abc605c9c9 [ci] Update workflows to 20.04 base image (#4271) 2022-05-27 23:33:33 -07:00
PJ Reiniger
3e94805220 [wpiutil] Reduce llvm collections patches (#4268) 2022-05-27 13:41:28 -07:00
Tyler Veness
db2e1d170e [upstream_utils] Document how to update thirdparty libraries (#4253)
Also, add a CI job to ensure the sources in the repo are consistent with
the update scripts.
2022-05-26 09:02:32 -07:00
Tyler Veness
96ebdcaf16 [wpimath] Remove unused Eigen AutoDiff module (#4267)
Drake's tests used to include it, but it's commented out since it's not
used.
2022-05-26 09:01:45 -07:00
PJ Reiniger
553b2a3b12 [upstream_utils] Fix stackwalker (#4265) 2022-05-24 21:51:32 -07:00
Tyler Veness
3e13ef42eb [wpilibc] Add missing std::array #include (include-what-you-use) (#4266) 2022-05-24 21:49:22 -07:00
Tyler Veness
d651a1fcec Fix internal deprecation warnings (#4257)
This allows us to error out on deprecation warnings for thirdparty
libraries and standard library features.

Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
2022-05-24 13:56:48 -07:00
ohowe
b193b318c1 [commands] Add unless() decorator (#4244) 2022-05-24 09:22:19 -07:00
bovlb
ef3714223b [commands] Remove docs reference to obsolete interrupted() method (NFC) (#4262) 2022-05-24 09:19:38 -07:00
Dalton Smith
3d8dbbbac3 [readme] Add quickstart (#4225) 2022-05-22 20:19:50 -07:00
Peter Johnson
013efdde25 [wpinet] Wrap a number of newer libuv features (#4260) 2022-05-22 20:18:23 -07:00
Starlight220
816aa4e465 [wpilib] Add Pneumatics sim classes (#4033) 2022-05-22 07:21:40 -07:00
Tyler Veness
046c2c8972 [wpilibc] Rename SpeedControllerGroupTest.cpp (#4258)
Also move motor controller test files into motorcontrol folder to match
Java.
2022-05-21 16:20:26 -07:00
Tyler Veness
d80e9cdf64 [upstream_utils] Use shallow clones for thirdparty repos (#4255)
This makes update_llvm.py in particular much faster because the full
repo requires fetching 2 GB.
2022-05-20 18:59:33 -07:00
Tyler Veness
7576136b4a [upstream_utils] Make update_llvm.py executable (#4254) 2022-05-20 17:16:19 -07:00
PJ Reiniger
c3b223ce60 [wpiutil] Vendor llvm and update to 13.0.0 (#4224) 2022-05-20 15:59:53 -07:00
Tyler Veness
5aa67f56e6 [wpimath] Clean up math comments (#4252) 2022-05-20 15:16:56 -07:00
Tyler Veness
fff4d1f44e [wpimath] Extend Eigen warning suppression to GCC 12 (#4251)
It originally only applied to GCC 11. The CMake build passed without
this change, but not the Gradle build.
2022-05-19 18:50:29 -07:00
Tyler Veness
0d9956273c [wpimath] Add CoordinateSystem.convert() translation and rotation overloads (#4227) 2022-05-18 20:41:15 -07:00
Tyler Veness
3fada4e0b4 [wpinet] Update to libuv 1.44.1 (#4232) 2022-05-18 20:40:27 -07:00
Tyler Veness
65b23ac45e [wpilibc] Fix return value of DriverStation::GetJoystickAxisType() (#4230)
It was returning a pointer to the axis type array cast to a bool (always
1) instead of returning the desired axis type.
2022-05-18 14:36:11 -07:00
Tyler Veness
4ac34c0141 [upstream_utils] Cleanup update_libuv.py (#4249) 2022-05-18 14:34:34 -07:00
Tyler Veness
8bd614bb1e [upstream_utils] Use "git am" instead of "git apply" for patches (#4248)
This creates actual commits in the thirdparty repo, which makes rebasing
them onto new versions much easier.
2022-05-18 12:23:15 -07:00
Tyler Veness
4253d6d5f0 [upstream_utils] Apply "git am" patches individually (#4250)
Also, giving am_patches() zero patches isn't an error. The function will
just be a no-op.
2022-05-18 12:22:31 -07:00
Tyler Veness
6a4752dcdc Fix GCC 12.1 warning false positives (#4246) 2022-05-18 12:22:10 -07:00
Tyler Veness
5876b40f08 [wpimath] Memoize CoordinateSystem and CoordinateAxis statics (#4241) 2022-05-18 10:47:46 -07:00
Tyler Veness
5983434a70 [cameraserver] Replace IterativeRobot in comment sample code with TimedRobot (#4238) 2022-05-15 20:47:50 -07:00
Max Gordon
a3d44a1e69 [wpimath] Add Translation2d.getAngle() (#4217)
Co-authored-by: Max Gordon <tonald.drump2.0@gamil.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-05-14 21:22:00 -07:00
Tyler Veness
d364bbd5a7 [upstream_utils] Give vendor update scripts execute permissions (#4226) 2022-05-14 15:31:51 -07:00
Tyler Veness
f341e1b2be [wpimath] Document standard coordinate systems better (NFC) (#4228) 2022-05-14 15:31:06 -07:00
Peter Johnson
9af389b200 [wpinet] AddrToName: Initialize name (#4229) 2022-05-14 06:55:22 -07:00
Austin Shalit
2ae4adf2d7 [ci] Add wpiformat command to PRs (#4223) 2022-05-11 22:06:11 -07:00
sciencewhiz
178b2a1e88 Contributing.md: Correct version of clang-format used (#4222) 2022-05-10 23:48:08 -07:00
PJ Reiniger
18db343cdc [wpiutil, wpinet] Vendor libuv, stack walker (#4219) 2022-05-08 22:21:54 -07:00
Austin Shalit
f0c821282a [build] Use artifactory mirror (#4220) 2022-05-08 13:59:58 -07:00
Peter Johnson
d673ead481 [wpinet] Move network portions of wpiutil into new wpinet library (#4077) 2022-05-07 10:54:14 -07:00
Tyler Veness
b33715db15 [wpimath] Add CoordinateSystem class (#4214) 2022-05-07 10:25:19 -07:00
Dustin Spicuzza
99424ad562 [sim] Allow creating a PWMSim object from a PWMMotorController (#4039) 2022-05-06 08:44:59 -07:00
Tommy Beadle
dc6f641fd2 [wpimath] PIDController: Reset position and velocity error when reset() is called. (#4064)
In addition to m_prevError and m_totalError, m_positionError and
m_velocityError need to be reset to 0 when reset() is called.
Otherwise, the next time calculate() is called, the old values will be
used as the previous error, but this is inaccurate since the caller
wanted to reset the state of the PID controller.
2022-05-06 08:44:08 -07:00
Tyler Veness
f20a20f3f1 [wpimath] Add 3D geometry classes (#4175)
Also clean up 2D geometry documentation.
2022-05-06 08:41:23 -07:00
Kaitlyn Kenwell
708a4bc3bc [wpimath] Conserve previously calculated swerve module angles when updating states for stationary ChassisSpeeds (#4208)
* Calculated swerve module states now stored in a member variable
* If ChassisSpeeds(0, 0, 0) is converted to module speeds, the
previously calculated module angle will be conserved, with forward speed
set to 0
* New tests added
2022-05-06 08:38:20 -07:00
chen perach
ef7ed21a9d [wpimath] Improve accuracy of ComputerVisionUtil.calculateDistanceToTarget() (#4215) 2022-05-06 08:36:58 -07:00
Tyler Veness
b1abf455c1 [wpimath] LTVUnicycleController: Use LUT, provide default hyperparameters (#4213) 2022-05-04 22:04:08 -07:00
Tyler Veness
d5456cf278 [wpimath] LTVDifferentialDriveController: Remove unused variable (#4212) 2022-05-04 22:03:15 -07:00
Tyler Veness
99343d40ba [command] Remove old command-based framework (#4211) 2022-05-04 22:02:53 -07:00
Tyler Veness
ee03a7ad3b Remove most 2022 deprecations (#4205)
Excludes "old" commands and SimDevice functions.
2022-05-04 20:37:27 -07:00
Tyler Veness
ce1a7d698a [wpimath] Refactor WheelVoltages inner class to a separate file (#4203) 2022-05-01 11:01:20 -07:00
Tyler Veness
87bf70fa8e [wpimath] Add LTV controllers (#4094)
This adds a unicycle controller that's a drop-in replacement for Ramsete
and a differential drive controller that controls the full pose and
outputs voltages. The main benefit is LQR-like tuning knobs using a
system model.
2022-04-30 22:54:22 -07:00
Tyler Veness
ebd2a303bf [wpimath] Remove deprecated MakeMatrix() function (#4202) 2022-04-30 22:52:05 -07:00
Peter Johnson
e28776d361 [wpimath] LinearSystemLoop: Add extern templates for common cases 2022-04-30 20:38:55 -07:00
Peter Johnson
dac1429aa9 [wpimath] LQR: Use extern template instead of Impl class 2022-04-30 20:38:55 -07:00
Peter Johnson
e767605e94 [wpimath] Add typedefs for common types
This makes complex code significantly easier to read.

frc::Vectord<Size> = Eigen::Vector<double, Size>
frc::Matrixd<Rows, Cols> = Eigen::Matrix<double, Rows, Cols>
2022-04-30 20:38:55 -07:00
Peter Johnson
97c493241f [wpimath] UnscentedKalmanFilter: Move implementation out-of-line 2022-04-30 20:38:55 -07:00
Peter Johnson
8ea90d8bc9 [wpimath] ExtendedKalmanFilter: Move implementation out-of-line 2022-04-30 20:38:55 -07:00
Peter Johnson
ae7b1851ec [wpimath] KalmanFilter: Use extern template instead of Impl class 2022-04-30 20:38:55 -07:00
Peter Johnson
e3d62c22d3 [wpimath] Add extern templates for common cases
This helps reduce compile times and memory usage.
2022-04-30 20:38:55 -07:00
Peter Johnson
7200c4951d [wpiutil] SymbolExports: Add WPILIB_IMPORTS for dllimport 2022-04-30 20:38:55 -07:00
Peter Johnson
84056c9347 [wpiutil] SymbolExports: Add EXPORT_TEMPLATE_DECLARE/DEFINE 2022-04-30 20:38:55 -07:00
Oblarg
09cf6eeecb [wpimath] ApplyDeadband: add a scale param (#3865)
Also templates it in C++ so it can work with both doubles and units.
2022-04-30 20:29:48 -07:00
Austin Shalit
03230fc842 [build,ci] Enable artifactory build cache (#4200) 2022-04-30 20:27:23 -07:00
Jason Daming
63cf3aaa3f [examples] Don't square ArcadeDrive inputs in auto (#4201) 2022-04-30 20:19:32 -07:00
Starlight220
18ff694f02 [wpimath] Add Rotation2d.fromRadians factory (#4178) 2022-04-30 00:19:29 -07:00
Tyler Veness
4f79ceedd9 [wpilibc] Add missing #include (#4198) 2022-04-30 00:07:37 -07:00
Starlight220
f7ca72fb41 [command] Rename PerpetualCommand to EndlessCommand (#4177) 2022-04-28 09:38:38 -07:00
bovlb
a06b3f0307 [hal] Correct documentation on updateNotifierAlarm (#4156)
The previous documentation suggested that `triggerTime` is the interval until the next alarm, but the implementation is that it is the absolute alarm time.
2022-04-26 21:53:30 -07:00
Tyler Veness
d926dd1610 [wpimath] Fix pose estimator performance (#4111)
Fixes #4087.
2022-04-26 18:43:59 -07:00
ysthakur
51bc893bc5 [wpiutil] CircularBuffer: Change Java package-private methods to public (#4181)
The `size`, `getFirst`, `getLast`, and `resize` methods were all package-private.

Also make `size` return an `int` instead of a `double`.
2022-04-25 14:58:12 -07:00
Tyler Veness
fbe761f7f6 [build] Increase Gradle JVM heap size (#4172)
wpimath artifact publishing was running out of heap
2022-04-24 23:13:57 -07:00
Tyler Veness
5ebe911933 [wpimath] Add DifferentialDriveAccelerationLimiter (#4091) 2022-04-24 07:21:40 -07:00
Tyler Veness
3919250da2 [wpilibj] Remove finalizers (#4158)
They were deprecated for removal in Java 18 because they're error-prone.
Prefer AutoCloseable and Cleaner instead.

https://openjdk.java.net/jeps/421
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ref/Cleaner.html
2022-04-24 07:21:08 -07:00
ohowe
b3aee28388 [commands] Allow BooleanSupplier for Trigger operations (#4103) 2022-04-24 07:20:46 -07:00
Tyler Veness
9d20ab3024 [wpilib] Allow disabling ElevatorSim gravity (#4145)
Closes #4144.
2022-04-24 07:19:18 -07:00
Peter Johnson
aaa69f6717 [ci] Remove 32-bit Windows builds (#4078) 2022-04-24 07:18:49 -07:00
Tyler Veness
355a11a414 Update Java linters and fix new PMD errors (#4157)
PMD requires that variables only initialized in the constructor be
final. The compiler errors if those final variables aren't guaranteed to
be initialized, so extra else branches were added to ensure that.

PMD also requires that classes with only private constructors be final.
The equivalent C++ classes were finalized as well, except for
TimeInterpolatableBuffer because it doesn't expose factory functions.
2022-04-24 07:18:05 -07:00
Jason Daming
ffc69d406c [examples] Reduce suggested acceleration in Ramsete example (#4171)
This value mirrors the update to the documentation in wpilibsuite/frc-docs#1792.
2022-04-19 17:10:11 -07:00
camaj
922d50079a [wpimath] Units: fix comment in degreesToRotations (NFC) (#4159) 2022-04-13 22:32:55 -07:00
Jonah Snider
dd163b62ae [wpimath] Rotation2d: Add factory method that uses rotations (#4166)
Rotation2d.fromRotations(1).equals(new Rotation2d(2 * Math.PI)); // true

Also adds a member method to get the value of the Rotation2d in rotations.
2022-04-13 22:31:43 -07:00
Tyler Veness
bd80e220b9 [ci] Upgrade CMake actions (#4161) 2022-04-12 19:00:00 -07:00
Tyler Veness
aef4b16d4c [wpimath] Remove unnecessary NOLINT in LinearPlantInversionFeedforward (NFC) (#4155) 2022-04-08 21:31:42 -07:00
Spud
975171609e [wpilib] Compressor: Rename enabled to isEnabled (#4147)
This is a less confusing name, as enabled() can imply it enables the compressor.
2022-04-08 21:31:08 -07:00
Tyler Veness
5bf46a9093 [wpimath] Add ComputerVisionUtil (#4124)
Closes #4108.
2022-04-08 21:20:53 -07:00
ohowe
f27a1f9bfb [commands] Fix JoystickButton.getAsBoolean (#4131)
This previously always returned false; the get method it inherited was not used in the getAsBoolean defined in the Trigger class. The fix is to swap get() and getAsBoolean() implementations in the Trigger class.
2022-04-08 21:20:23 -07:00
Excalibur FRC | 6738
1b26e2d5da [commands] Add RepeatCommand (#4009)
Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
2022-04-07 22:02:08 -07:00
apple
88222daa3d [hal] Fix misspelling in AnalogInput/Output docs (NFC) (#4153)
value -> valid
(NFC)
2022-04-07 21:57:01 -07:00
Tyler Veness
81c5b41ce1 [wpilibj] Document MechanismLigament2d angle unit (NFC) (#4142) 2022-03-31 00:29:44 -07:00
Peter Johnson
9650e6733e [wpiutil] DataLog: Document finish and thread safety (NFC) (#4140) 2022-03-29 12:28:59 -07:00
Tyler Veness
c8905ec29a [wpimath] Remove ImplicitModelFollower dt argument (#4119)
The math works just fine without model discretization.
2022-03-29 11:29:06 -07:00
Tyler Veness
b4620f01f9 [wpimath] Fix Rotation2d interpolation in Java (#4125)
Fixes #4112.
2022-03-29 08:42:43 -07:00
Tyler Veness
2e462a19d3 [wpimath] Constexprify units unary operators (#4138)
Fixes #4137.
2022-03-29 08:42:08 -07:00
Peter Johnson
069f932e59 [build] Fix gl3w cmake build (#4139) 2022-03-28 22:31:51 -07:00
Tyler Veness
126e3de91a [wpilibc] Remove unused SetPriority() call from Ultrasonic (#4123) 2022-03-24 07:24:12 -07:00
Tyler Veness
ba0dccaae4 [wpimath] Fix reference to Rotation2d.fromRadians() (#4118)
Rotation2d.fromRadians() doesn't exist. The constructor should be used
instead.
2022-03-20 21:57:03 -07:00
sciencewhiz
e1b6e5f212 [wpilib] Improve MotorSafety documentation (NFC) (#4120)
Remove OBE RobotDrive porting guide from MecanumDrive
2022-03-20 21:54:43 -07:00
Tyler Veness
8d79dc8738 [wpimath] Add ImplicitModelFollower (#4056) 2022-03-20 00:36:12 -07:00
Tyler Veness
78108c2aba [wpimath] Fix PIDController having incorrect error after calling SetSetpoint() (#4070) 2022-03-19 23:59:00 -07:00
Tyler Veness
cdafc723fb [examples] Remove unused LinearPlantInversionFeedforward includes (#4069) 2022-03-19 20:47:09 -07:00
Ashray._.g
0d70884dce [wpimath] Add InterpolatedTreeMap (#4073)
- Add InterpolatedTreeMap for Java from team 254's 2016 MIT licensed code
- Add InterpolatedMap for C++ from team 3512's code with @calcmogul (original author) permission

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2022-03-19 20:46:42 -07:00
Tyler Veness
765efa325e [wpimath] Remove redundant column index from vectors (#4116) 2022-03-19 20:44:14 -07:00
Tyler Veness
89ffcbbe41 [wpimath] Update TrapezoidProfile class name in comment (NFC) (#4107) 2022-03-19 20:41:53 -07:00
Tyler Veness
95ae23b0e7 [wpimath] Improve EKF numerical stability (#4093)
The Joseph form of the error covariance update equation is more
numerically stable when the Kalman gain isn't optimal. Numerical
instability and filter divergence can occur if the user goes long time
periods between updates and the error covariance becomes ill-conditioned
(the ratio between the largest and smallest eigenvalue gets too large).
2022-03-19 20:41:28 -07:00
Tyler Veness
d5cb6fed67 [wpimath] Support zero cost entries in MakeCostMatrix() (#4100)
The existing implementation will produce a cost of NaN if a tolerance of
infinity is entered, but the limit approaches zero. Being able to
specify that a state has no cost is useful, so this change adds support for
that.
2022-03-19 20:40:26 -07:00
Tyler Veness
d0fef18378 [wpimath] Remove redundant this. from ExtendedKalmanFilter.java (#4115) 2022-03-19 20:39:10 -07:00
Tyler Veness
d640c0f41f [wpimath] Fix pose estimator local measurement standard deviation docs (NFC) (#4113) 2022-03-19 20:38:32 -07:00
Dustin Spicuzza
a2fa5e3ff7 [wpilibc] BatterySim: Provide non-initializer list versions of Calculate (#4076) 2022-03-14 10:09:55 -07:00
sciencewhiz
a3eea9958e [hal] Add link to FRC CAN Spec (NFC) (#4086) 2022-03-14 10:07:44 -07:00
Tyler Veness
db27331d7b [wpilib] Update DifferentialDrive docs (NFC) (#4085)
Fixes #4084.
2022-03-14 10:07:06 -07:00
Peter Johnson
fdfb31f164 [dlt] Export boolean[] values (#4082) 2022-03-14 10:05:50 -07:00
Dustin Spicuzza
f93c3331b3 [wpigui] disable changing directory when initializing on MacOS (#4092)
- Seems to be intended for resource bundles in MacOS apps, which we don't use
2022-03-14 10:05:22 -07:00
Thad House
ab7ac4fbb9 [build] Fix various warnings in cmake builds (#4081) 2022-03-07 22:36:42 -08:00
Thad House
bc39a1a293 [wpilibc] Fix moved pneumatics objects not destructing properly (#4068) 2022-03-01 11:10:45 -08:00
Tyler Veness
2668130e70 [wpimath] Remove SwerveDrivePoseEstimator encoder reset warning (#4066)
SwerveDrivePoseEstimator uses velocities, so position resets aren't
needed.

Closes #4065.
2022-02-28 17:40:25 -08:00
Austin Shalit
d27ed3722b [ci] Set actions workflow concurrency (#4060)
This sets the workflow concurrency to 1 for all workflows. For PRs this means if you push an additional commit older jobs will be cancelled.

The documentation workflow already only runs on tags or merges to main. For this, we cancel previous runs if they are to the same destination (tag or main) but still prevent 2 jobs from running at once if they are spawned from different refs.
2022-02-27 20:13:58 -08:00
shueja-personal
dae18308c9 [wpimath] Minor fixes to Rotation2d docs (NFC) (#4055)
Fixed incorrect examples on .plus(), and a missing word.

Make example code snippets closer to actual use.
2022-02-27 16:56:56 -08:00
Peter Johnson
d66555e42f [datalogtool] Add datalogtool
This is a support tool for datalog file conversion (and eventually
download/remote datalog file management).
2022-02-26 09:49:34 -08:00
Peter Johnson
9f52d8a3b1 [wpilib] DriverStation: Add DataLog support for modes and joystick data 2022-02-26 09:49:34 -08:00
Peter Johnson
757ea91932 [wpilib] Add DataLogManager
This creates a default log file that captures NT changes and
automatically renames the log file based on time and match info.

DriverStation joystick logging will be implemented by the DriverStation
class instead.
2022-02-26 09:49:34 -08:00
Peter Johnson
02a804f1c5 [ntcore] Add DataLog support 2022-02-26 09:49:34 -08:00
Peter Johnson
9b500df0d9 [wpiutil] Add high speed data logging 2022-02-26 09:49:34 -08:00
Peter Johnson
5a89575b3a [wpiutil] Import customized LLVM MemoryBuffer 2022-02-26 09:49:34 -08:00
Peter Johnson
b8c4d7527b [wpiutil] Add MappedFileRegion 2022-02-26 09:49:34 -08:00
Alberto Jahuey Moncada
ac5d46cfa7 [wpilibc] Fix ProfiledPID SetTolerance default velocity value (#4054)
When trying to set the tolerance of a ProfiledPID, it fails if you don't give it a velocity value. It was missing a conversion from double to the appropiate unit.
2022-02-25 20:27:56 -08:00
Thad House
bc9e96e86f [wpilib] Absolute Encoder API and behavior fixes (#4052)
SetPositionOffset was added. Been requested multiple times, and easy to implement.

The javadocs mentioned GetPositionInRotation. It has tripped up many people how to get the absolute position from the encoder (You currently have to have precreated the DutyCycle object). Add this method (as GetAbsolutePostition) to make this easier to do.

The checks for making sure a matching set of values was read was doing direct double comparisions. This worked ok in the DutyCycle case, but has problems in the analog case. Solve this by using an epsilon comparison.

And finally, scale AnalogEncoders analog input to 0-1 instead of 0-5. This was reported a few years ago, but the issue was missed. This caused the encoder to count from 0-5, then 1-6, then 2-7 etc. This is solved and now works correctly.

Closes #3188
Closes #4046
Closes #4051

And fixes the following issue on CD
https://www.chiefdelphi.com/t/wpilib-analogencoder-java/372649
2022-02-24 22:45:15 -08:00
Dustin Spicuzza
f88c435dd0 [hal] Add mechanism to cancel all periodic callbacks (#4049) 2022-02-23 09:46:01 -08:00
Leonard Abbas
e4b91005cf [examples] Update SwerveModule constructor doc (NFC) (#4042)
Renamed "port" to "channel" for consistency.
2022-02-22 09:26:16 -08:00
Leonard Abbas
a260bfd83b [examples] Remove "this" keyword from SwerveModule (#4043) 2022-02-21 09:27:00 -08:00
Leonard Abbas
18e262a100 [examples] Fix multiple doc typos in SwerveControllerCommand example (NFC) (#4044) 2022-02-21 09:26:20 -08:00
Dustin Spicuzza
4bd1f526ab [wpilibc] Prevent StopMotor from terminating robot during MotorSafety check (#4038)
- Nothing else in that function can throw, so protecting StopMotor should be sufficient
- Fixes #4036
2022-02-19 20:42:10 -08:00
Dustin Spicuzza
27847d7eb2 [sim] Expose GUI control functions via HAL_RegisterExtension (#4034) 2022-02-19 20:40:25 -08:00
Dustin Spicuzza
b2a8d3f0f3 [wpilibc] Add mechanism to reset MotorSafety list (#4037) 2022-02-19 20:38:30 -08:00
Tyler Veness
49adac9564 [wpilib] Check for signedness in ArcadeDriveIK() (#4028)
If xSpeed == -0.0 and zRotation > 0, the algorithm assumes it's in the
third quadrant instead of the first since +0.0 == -0.0.

Also added tests for inverse kinematic functions, fixed some
MecanumDrive test bugs, and added Java MecanumDrive.driveCartesianIK()
and KilloughDrive.driveCartesianIK() overloads with defaulted gyro angle
that C++ already had.

Fixes #4022.
2022-02-17 18:03:59 -08:00
Peter Johnson
a19d1133b1 [wpiutil] libuv: Fix sign compare warnings in gcc 11.2 (#4031) 2022-02-13 16:56:53 -08:00
Peter Johnson
dde91717e4 [build] cmake: Add ability to customize target warnings (#4032) 2022-02-13 16:53:55 -08:00
Peter Johnson
e9050afd67 [sim] Update sim match time to match real robot (#4024)
The real robot has match time set to -1.0 until it's enabled, and then
counts down. Disabling the robot sets the time to -1.0.

The sim GUI has been updated to add preset buttons for auto and teleop
match times. The enable match timing checkbox has been removed as it's
no longer required.

The DS socket plugin has also been fixed to properly initialize
matchTime to -1.0 and reset it to -1.0 on disable.
2022-02-12 22:31:10 -08:00
sciencewhiz
165d2837cf [wpilib] Preferences: Set Persistent in Init methods (#4025)
Fixes #4018
2022-02-12 22:30:02 -08:00
Peter Johnson
ac7549edca [glass] Fix snprintf truncation warning (#4029) 2022-02-12 22:29:26 -08:00
Jonah Snider
4d96bc72e0 [wpilibj] Fix typos in error messages for non-null assertions (#4014) 2022-02-11 18:11:15 -08:00
Dustin Spicuzza
3411eee20f [hal] Replace hardcoded sim array sizes with constants (#4015) 2022-02-10 00:12:07 -08:00
Dustin Spicuzza
74de97eeca [wpilibc] Add mechanism to reset various global structures (#4007) 2022-02-09 22:14:12 -08:00
sciencewhiz
4e3cc25012 [examples] Fix periodic function rate comment (NFC) (#4013)
Fixes #3979
2022-02-08 13:19:31 -08:00
Dustin Spicuzza
90c1db393e [sim] Add exported functions to control the sim GUI (#3995) 2022-02-07 00:39:45 -08:00
sciencewhiz
2f43274aa4 [wpilibj] MechanismRoot2d: Add flush to setPosition (#4011)
Fixes #4010.
2022-02-06 22:47:33 -08:00
Peter Johnson
aeca09db09 [glass] Support remapping of Enter key (#3994)
This is useful for editing of values without disabling the DS.
2022-02-06 00:11:37 -08:00
Peter Johnson
c107f22c67 [sim] Sim GUI: don't force-show Timing and Other Devices (#4001)
Instead preserve their saved visible state.
2022-02-06 00:11:12 -08:00
Peter Johnson
68fe51e8da [wpigui] Update PFD to latest, fix kdialog multiselect (#4005) 2022-02-06 00:10:43 -08:00
modelmat
8d08d67cf1 [wpigui] PFD: Add console warning if file chooser unavailable (#4003)
Also remove iostream use.
2022-02-06 00:10:20 -08:00
Dustin Spicuzza
4f1782f66e [wpilibc] Only call HAL_Report when initializing SmartDashboard (#4006) 2022-02-06 00:07:55 -08:00
Tyler Veness
3f77725cd3 Remove uses of iostream (#4004)
Most of these were unused, the IMU ones were just debug messages.

The only one that wasn't removed is in portable-file-dialogs.cpp since
the replacement looks less trivial.
2022-02-05 23:00:31 -08:00
Peter Johnson
5635f33a32 [glass] Increase plot depth to 20K points (#3993)
2K was sufficient for simulation because it's possible to pause time,
but isn't quite enough for looking at real robot data. 20K points
is 400 seconds at 50 Hz which should make pausing plots much more
useful.

As every point is looped over, this does increase CPU utilization
somewhat but doesn't seem to have much of an impact for typical
use cases. Increasing this further will necessitate some greater
optimizations (e.g. an initial cull using binary search).
2022-02-04 22:20:38 -08:00
Peter Johnson
bca4b7111b [glass] Fix PlotSeries::SetSource() (#3991)
This can be called in a delayed manner, so it's possible for
m_size to already be at maximum, which results in writing past
the end of the array. Instead, just call AppendValue().
2022-02-04 20:47:11 -08:00
Oblarg
6a6366b0d6 [commands] Add until() as alias for withInterrupt() (#3981)
This is a clearer description for the functionality.
Will deprecate withInterrupt next year.
2022-02-03 22:14:52 -08:00
Thad House
16bf2c70c5 [wpilib] Fix joystick out of range error messages (#3988) 2022-02-03 22:10:44 -08:00
Thad House
4b3edb742c [wpilib] Fix ADIS16448 IMU default constructor not working in Java (#3989)
Also fixes a few related uninitialized variables in C++.
2022-02-03 22:09:12 -08:00
Thad House
fcf23fc9e9 [hal] Fix potential gamedata out of bounds read (#3983)
The size was uninitialized.  If the size is smaller than the data,
NetComm just updates the size and does not initialize the data.
2022-02-01 22:22:48 -08:00
Jan-Felix Abellera
af5ef510c5 [wpilibc] Fix REV PH pulse duration units (#3982) 2022-02-01 20:28:48 -08:00
Jan-Felix Abellera
05401e2b81 [wpilib] Write REV PH firmware version to roboRIO to display on driver station (#3977) 2022-02-01 20:27:43 -08:00
Thad House
9fde0110b6 Update to 2022 v4.0 image (#3944) 2022-01-31 23:26:05 -08:00
sciencewhiz
b03f8ddb2e [examples] fix incorrect variable in Arm Simulation Pref (#3980) 2022-01-31 22:01:31 -08:00
sciencewhiz
a26df2a022 [examples] Update ArmSimulation example to use Preferences (#3976)
This shows more real world usage then hardcoding the setpoint and PID
gains. There were no current examples using Preferences. This will also
be used to update frc-docs article for Preferences.
2022-01-31 00:17:04 -08:00
Oblarg
d68d6674e8 [examples] Armbot: rename kCos to kG (#3975) 2022-01-31 00:16:26 -08:00
sciencewhiz
a8f0f6bb90 [wpilibj] Fix ADIS16448 getRate to return rate instead of angle (#3974) 2022-01-29 20:17:57 -08:00
Thad House
dd9c92d5bf [build] Remove debug info from examples (#3971)
They take up a LOT of disk space.
2022-01-27 20:59:13 -08:00
Thad House
84df14dd70 [rtns] Fix icons (#3972) 2022-01-27 20:58:07 -08:00
sciencewhiz
560094ad92 [examples] Correct Mecanum example axes (#3955) 2022-01-27 20:57:41 -08:00
Jan-Felix Abellera
7ea1be9c01 [wpilibc] Fix typo in hardware version for REV PDH (#3969) 2022-01-27 17:54:38 -08:00
Jan-Felix Abellera
700f13bffd [wpilibj] Make methods public for Java REV PDH (#3970) 2022-01-27 17:54:14 -08:00
Jan-Felix Abellera
b6aa7c1aa9 [wpilibj] Make methods public for Java REVPH (#3968) 2022-01-27 17:53:45 -08:00
Tyler Veness
eb4d183e48 [wpimath] Fix clang-tidy bugprone-integer-division warning (#3966)
The integer conversion is deliberate.
2022-01-26 18:38:45 -08:00
Thad House
77e4e81e1e [wpilib] Add Field widget to BuiltInWidgets in shuffleboard (#3961) 2022-01-24 20:33:11 -08:00
Thad House
88f5cb6eb0 [build] Publish PDBs with C++ tools (#3960) 2022-01-24 20:32:17 -08:00
Tyler Veness
efae552f3e [wpimath] Remove DifferentialDriveKinematics include from odometry (#3958) 2022-01-24 16:02:00 -08:00
sciencewhiz
46b277421a [glass] Update Speed Controller Type name for 2022 WPILib (#3952) 2022-01-21 21:30:44 -08:00
modelmat
42908126b9 [wpilib] Add DCMotorSim (#3910) 2022-01-21 20:42:06 -08:00
Peter Johnson
a467392cbd [wpiutil] StackTrace: Add ability to override default implementation (#3951) 2022-01-21 17:22:41 -08:00
modelmat
78d0bcf49d [templates] Add SimulationInit()/SimulationPeriodic() to robot templates (#3943) 2022-01-21 16:23:46 -08:00
sciencewhiz
02a0ced9b0 [wpilib] MecanumDrive: update docs for axis to match implementation (NFC) (#3942)
Added note that implementation may change in the future, #3930.
2022-01-21 16:22:17 -08:00
shueja-personal
4ccfe1c9f2 [wpilib] Added docs clarification on units for drive class WheelSpeeds (NFC) (#3939) 2022-01-21 15:51:28 -08:00
Peter Johnson
830c0c5c2f [wpilib] MechanismLigament2d: Add getters for color and line weight (#3947)
Also add missing locking in C++.
2022-01-21 15:47:44 -08:00
Peter Johnson
5548a37465 [wpilib] PowerDistribution: Add module type getter (#3948) 2022-01-21 15:46:44 -08:00
Thad House
2f9a600de2 [hal] Fix PCM one shot (#3949) 2022-01-21 15:46:08 -08:00
Thad House
559db11a20 [myRobot] Skip deploying debug libraries for myRobot deploys (#3950) 2022-01-21 15:45:47 -08:00
Lenny Abbas
76c78e295b [examples] Reorder SwerveModules in SwerveControllerCommand example odometry update (#3934) 2022-01-21 11:04:43 -08:00
sciencewhiz
debbd5ff4b [wpilib] Improve PowerDistribution docs (NFC) (#3925)
Add docs for switchable channel.
Use PDP/PDH appropriately and clarify differences.
Fix typos.
2022-01-20 23:33:01 -08:00
Tyler Veness
841174f302 [commands] Change command vendordep JSON version number to 1.0.0 (#3938)
While the number doesn't matter, it being old is confusing a lot of
people.  We never increment the internal vendordep versions, so using a year
version number was a poor choice.

Closes #3921.
2022-01-20 23:32:02 -08:00
sciencewhiz
8c55844f91 [wpilib] Remove comment about Mecanum right side inverted (NFC) (#3929) 2022-01-18 01:00:55 -08:00
Thad House
0b990bf0f5 [hal] Fix PCM sticky faults clear function crashing (#3932)
A call to the PCM clear function was using the wrong handle passed down to the CAN layer, causing an error.
2022-01-18 00:59:51 -08:00
Thad House
104d7e2abc [hal] Don't throw exceptions in PCM JNI (#3933)
Since the CAN bus can easily become disconnected, we don't want this to crash. Instead, we just want this to report errors. This matches previous behavior.
2022-01-18 00:58:26 -08:00
Lenny Abbas
5ba69e1af1 [examples] Updated type in Java SwerveModule (#3928)
Changed turnOutput from var to double in SwerveModule. It doesn't make sense for driveOutput and turnOutput to have different types so they should both be doubles.
2022-01-17 12:20:55 -08:00
Chirag Kaushik
f3a0b5c7d7 [wpimath] Fix Java SimpleMotorFeedforward Docs (NFC) (#3926) 2022-01-17 09:59:04 -08:00
Tyler Veness
7f4265facc [wpimath] Add LinearFilter::FiniteDifference() (#3900)
This allows making more general finite difference filters, like central
finite difference. SysId uses this for acceleration filtering.
2022-01-15 20:18:11 -08:00
Tyler Veness
63d1fb3bed [wpiutil] Modify fmt to not throw on write failure (#3919)
This was causing issues with tools, as the launchers would close stdout/stderr, resulting in write failures.
2022-01-15 20:10:32 -08:00
Tyler Veness
36af6d25a5 [wpimath] Fix input vector in pose estimator docs (NFC) (#3923) 2022-01-15 20:03:39 -08:00
Thad House
8f387f7255 [wpilibj] Switch ControlWord mutex to actual reentrant mutex (#3922)
It seems like the JVM does not handle recursive calls to object monitor based locks correctly. A few bugs in the past have been reported to have caused deadlocks if this occurs. It looks like the version of Java we use is fixed, but there could be other bugs, and it seems like this area of the code isn't tested much. Based on the stacks reported in #3896, it really seems like this is occurring. So we're going to attempt to switch to explicit mutex based classes, which shouldn't have bugs like this, and we will see if that fixes the issue.
2022-01-15 15:24:06 -08:00
David Vo
792e735e08 [wpimath] Move TrajectoryGenerator::SetErrorHandler definition to .cpp (#3920)
Otherwise this function causes linking errors when used on Windows.
2022-01-15 08:58:49 -08:00
Tyler Veness
3b76de83eb [commands] Fix ProfiledPIDCommand use-after-free (#3904)
Fixes #3903.
2022-01-14 23:56:48 -08:00
PJ Reiniger
ad9f738cfa [fieldimages] Fix maven publishing (#3897) 2022-01-14 23:55:10 -08:00
modelmat
49455199e5 [examples] Use left/rightGroup.Get() for simulator inputs to fix inversions (#3908) 2022-01-14 23:54:20 -08:00
modelmat
64426502ea [wpimath] Fix arm -> flywheel typo (NFC) (#3911) 2022-01-14 23:53:45 -08:00
Tyler Veness
8cc112d196 [wpiutil] Fix wpi::array for move-only types (#3917)
Fixes #3916.
2022-01-14 23:53:12 -08:00
Tyler Veness
e78cd49861 [build] Upgrade Java formatter plugins (#3894) 2022-01-11 22:24:16 -08:00
Tyler Veness
cfb4f756d6 [build] Upgrade to shadow 7.1.2 (#3893) 2022-01-11 21:10:15 -08:00
Tyler Veness
ba0908216c [wpimath] Fix crash in KF latency compensator (#3888)
It would crash in C++ if the global measurement was sooner than all the
snapshots.

Align Java with the changes and better document computation approach.
2022-01-09 23:01:04 -08:00
Peter Johnson
a3a0334fad [build] cmake: Move fieldImages to WITH_GUI (#3885)
This will only ever be used by GUI applications, and the jar build
method it uses can misbehave in some cross-compile scenarios.
2022-01-09 20:26:54 -08:00
sciencewhiz
cf7460c3a8 [fieldImages] Add 2022 field (#3883) 2022-01-08 23:24:24 -08:00
Tyler Veness
db0fbb6448 [wpimath] Fix LQR matrix constructor overload for Q, R, and N (#3884)
It was using the continuous B matrix to compute the feedback gain
instead of the discrete B matrix.

Tests were added for the matrix constructor overloads.
2022-01-08 23:23:53 -08:00
sciencewhiz
8ac45f20bb [commands] Update Command documentation (NFC) (#3881)
Add reference to which VendorDep the class is included in.
Add missing OldCommands C++ Documentation (copied from Java).
2022-01-08 11:11:34 -08:00
Tyler Veness
b3707cca0b [wpiutil] Upgrade to fmt 8.1.1 (#3879)
The changes to PneumaticsBase.cpp were to fix errors like the following
from enum classes not being formattable:
```
allwpilib/wpilibc/src/main/native/cpp/PneumaticsBase.cpp:36:9:   required from here
allwpilib/wpiutil/src/main/native/fmtlib/include/fmt/core.h:2672:12: error: use of deleted function ‘fmt::v8::detail::fallback_formatter<T, Char, Enable>::fallback_formatter() [with T = frc::PneumaticsModuleType; Char = char; Enable = void]’
 2672 |   auto f = conditional_t<has_formatter<mapped_type, context>::value,
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2673 |                          formatter<mapped_type, char_type>,
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2674 |                          fallback_formatter<T, char_type>>();
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
2022-01-08 11:10:42 -08:00
Tyler Veness
a69ee3ece9 [wpimath] Const-qualify Twist2d scalar multiply (#3882)
Fixes #3880.
2022-01-08 11:09:29 -08:00
Drew Williams
750d9a30c9 [examples] Fix Eigen out of range error when running example (#3877)
Simple typo fix.
2022-01-08 00:15:26 -08:00
Peter Johnson
41c5b2b5ac [rtns] Add cmake build (#3866)
This needs libssh to build, so on Linux systems it's necessary to
install libssh-dev.
2022-01-08 00:14:48 -08:00
Tyler Veness
6cf3f9b28e [build] Upgrade to Gradle 7.3.3 (#3878)
This is the same version robot projects currently use.
2022-01-08 00:14:27 -08:00
Starlight220
269cf03472 [examples] Add communication examples (e.g. arduino) (#2500)
Co-authored-by: Andrew Dassonville <dassonville.andrew@gmail.com>
2022-01-06 18:08:57 -08:00
sciencewhiz
5ccfc4adbd [oldcommands] Deprecate PIDWrappers, since they use deprecated interfaces (#3868) 2022-01-06 18:05:24 -08:00
Peter Johnson
b6f44f98be [hal] Add warning about onboard I2C (#3871)
Adds HAL layer warning for #3842. This is needed in the case when a
vendor uses the HAL directly rather than using the WPILib I2C class.

This should not result in a duplicate warning for WPILib I2C users due
to the duplicate message checking performed in HAL_SendError().

We don't want to remove the WPILib I2C warning because it gives stack
trace information while the HAL layer one can't.
2022-01-06 17:44:27 -08:00
Peter Johnson
0dca57e9ec [templates] romieducational: Invert drivetrain and disable motor safety (#3869) 2022-01-06 11:29:15 -08:00
Tyler Veness
22c4da152e [wpilib] Add GetRate() to ADIS classes (#3864)
The angular rate is treated somewhat like an angle during calibration,
but the datasheet says it's angular rate. The variables were renamed to
make this clearer.
2022-01-04 22:26:23 -08:00
Peter Johnson
05d66f862d [templates] Change the template ordering to put command based first (#3863)
Previously it was a bit buried.
2022-01-04 21:23:57 -08:00
Dustin Spicuzza
b09f5b2cf2 [wpilibc] Add virtual dtor for LinearSystemSim (#3861) 2022-01-03 21:25:02 -08:00
Tyler Veness
a2510aaa0e [wpilib] Make ADIS IMU classes unit-safe (#3860)
The gyro rate getters were removed since that data isn't available.
2022-01-03 20:00:53 -08:00
Tyler Veness
947f589916 [wpilibc] Rename ADIS_16470_IMU.cpp to match class name (#3859) 2022-01-03 17:53:57 -08:00
Peter Johnson
bbd8980a20 [myRobot] Fix cameraserver library order (#3858) 2022-01-03 11:59:29 -08:00
Tyler Veness
831052f118 [wpilib] Add simulation support to ADIS classes (#3857) 2022-01-03 11:44:12 -08:00
Noah Andrews
c137569f91 [wpilib] Throw exception if the REV Pneumatic Hub firmware version is older than 22.0.0 (#3853) 2022-01-03 11:09:30 -08:00
sciencewhiz
dae61226fa Fix Maven Artifacts readme (#3856)
Add wpiutil to wpimath
Add wpimath to wpilibj and wpilibc
2022-01-03 10:18:49 -08:00
sciencewhiz
3ad4594a88 Update Maven artifacts readme for 2022 (#3855) 2022-01-01 13:28:36 -08:00
Matteo Kimura
112acb9a62 [wpilibc] Move ADIS IMU constants to inside class (#3852) 2022-01-01 11:40:28 -08:00
Peter Johnson
ecee224e81 [wpilib] Allow SendableCameraWrappers to take arbitrary URLs (#3850)
Useful for adding cameras that are streamed from a coprocessor

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: Sam Carlberg <sam.carlberg@gmail.com>
2022-01-01 10:10:37 -08:00
Peter Johnson
a3645dea34 LICENSE: Bump year range to include 2022 (#3854) 2022-01-01 00:00:16 -08:00
Jan-Felix Abellera
7c09f44898 [wpilib] Use PSI for compressor config and sensor reading (#3847)
This adds the REV Analog Pressure Sensor PSI to volt (and vice versa) conversion to allow setting the compressor config in PSI and getting the sensor reading in PSI. Also adds input validation for pressure values at the higher level.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-12-31 21:04:56 -08:00
Peter Johnson
f401ea9aae [wpigui] Remove wpiutil linkage (#3851)
It was only being used for fs::remove() (added in #3463), which is easily
replaced by std::remove().

The code change does not affect the WPILib tools, as this code is not used when JSON save files are used.
2021-12-31 07:56:31 -08:00
Peter Johnson
bf8517f1e6 [wpimath] TimeInterpolatableBufferTest: Fix lint warnings (#3849) 2021-12-31 00:06:08 -08:00
David Vo
528087e308 [hal] Use enums with fixed underlying type in clang C (#3297)
This will allow static analysis tools that use clang to always determine the correct intended parameter types for HAL functions.
2021-12-30 21:20:05 -08:00
Thad House
1f59ff72f9 [wpilib] Add ADIS IMUs (#3777)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
Co-authored-by: Matteo Kimura <mateus.sakata@gmail.com>
2021-12-30 19:43:53 -08:00
Matt
315be873c4 [wpimath] Add TimeInterpolatableBuffer (#2695)
These classes are useful for storing previous robot positions to use in conjunction with the upcoming pose estimators.

Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
Co-authored-by: cttew <cttewari@gmail.com>
2021-12-30 19:08:05 -08:00
Oblarg
b8d019cdb4 [wpilib] Rename NormalizeWheelSpeeds to DesaturateWheelSpeeds (#3791) 2021-12-30 18:30:08 -08:00
Peter Johnson
102f23bbdb [wpilibj] DriverStation: Set thread interrupted state (#3846)
This is a Java best practice when catching InterruptedException.
2021-12-30 13:13:52 -08:00
Kevin-OConnor
b85c24a79c [wpilib] Add warning about onboard I2C (#3842) 2021-12-30 13:13:03 -08:00
Oblarg
eee29daaf9 [newCommands] Trigger: Allow override of debounce type (#3845)
Previously Trigger could only be debounced on rising edges.
This change preserves the default behavior but adds the capability to override it.
2021-12-29 16:10:43 -08:00
Oblarg
aa9dfabde2 [wpimath] Move debouncer to filters (#3838) 2021-12-28 09:49:41 -08:00
Peter Johnson
5999a26fba [wpiutil] Add GetSystemTime() (#3840)
This portably gets the time in microseconds since the Unix epoch.
2021-12-27 23:06:31 -08:00
sciencewhiz
1e82595ffb [examples] Fix arcade inversions (#3841)
Accounts for differences between ArcadeDrive and the methods used
in some other examples.
2021-12-27 23:05:42 -08:00
Peter Johnson
e373fa476b [wpiutil] Add disableMockTime to JNI (#3839)
This exposes the equivalent of SetNowImpl(nullptr) to Java.
2021-12-27 09:51:32 -08:00
sciencewhiz
dceb5364f4 [examples] Ensure right side motors are inverted (#3836)
Fixes #3827
Adds MotorController inversion for right side, removes inversion in
setVoltage methods.

Also fixes various XboxController negations (was inconsistent throughout examples).
2021-12-26 19:25:26 -08:00
Oblarg
baacbc8e24 [wpilib] Tachometer: Add function to return RPS (#3833) 2021-12-26 15:52:18 -08:00
Austin Shalit
84b15f0883 [templates] Add Java Romi Educational template (#3837)
This is a combination of a Romi Gradle project and Educational robot (added in #3309)
2021-12-26 15:46:22 -08:00
Dalton Smith
c0da9d2d35 [examples] Invert Right Motor in Romi Java examples (#3828) 2021-12-26 15:42:53 -08:00
sciencewhiz
0fe0be2733 [build] Change project year to intellisense (#3835)
This means VSCode won't prompt to upgrade (added in beta 4)
2021-12-25 20:50:06 -06:00
Tyler Veness
eafa947338 [wpimath] Make copies of trajectory constraint arguments (#3832)
This avoids stack-use-after-scope bugs in code like the following when
the original argument goes out of scope:
```cpp
frc2::Command* RobotContainer::GetAutonomousCommand() {
  // Create a voltage constraint to ensure we don't accelerate too fast
  frc::DifferentialDriveVoltageConstraint autoVoltageConstraint(
      frc::SimpleMotorFeedforward<units::meters>(
          DriveConstants::ks, DriveConstants::kv, DriveConstants::ka),
      DriveConstants::kDriveKinematics, 10_V);
```
2021-12-25 07:19:43 -06:00
sciencewhiz
9d13ae8d01 [wpilib] Add notes for Servo get that it only returns cmd (NFC) (#3820)
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2021-12-23 22:22:18 -08:00
Tyler Veness
2a64e4bae5 [wpimath] Give drivetrain a more realistic width in TrajectoryJsonTest.java (#3822)
Fixes #3819.
2021-12-22 22:28:23 -08:00
Tyler Veness
c3fd20db59 [wpilib] Fix trajectory sampling in DifferentialDriveSim test (#3821)
Also rename C++ test file to match class name.

Fixes #3818.
2021-12-22 22:27:51 -08:00
WarrenReynolds
6f91f37cd0 [examples] Fix SwerveControllerCommand order of Module States (#3815)
DriveSubsystem::SetModulesStates applies module state to incorrect modules.

Fixes #3814.
2021-12-22 12:26:02 -08:00
Peter Johnson
5158730b81 [wpigui] Upgrade to imgui 1.86, GLFW 3.3.6 (#3817)
The GLFW upgrade fixes gamepads not being mapped at startup.
2021-12-22 12:24:36 -08:00
Thad House
2ad2d2ca96 [wpiutil] MulticastServiceResolver: Fix C array returning functions (#3816) 2021-12-22 09:52:57 -08:00
Starlight220
b5fd29774f [wpilibj] Trigger: implement BooleanSupplier interface (#3811) 2021-12-21 11:33:16 -08:00
sciencewhiz
9f8f330e96 [wpilib] Fix Mecanum and SwerveControllerCommand when desired rotation passed (#3808) 2021-12-19 20:08:28 -08:00
Tyler Veness
1ad3b1b333 [hal] Don't copy byte to where null terminator goes (#3807)
Fixes the following compiler warning:
```
/__w/allwpilib/allwpilib/hal/src/main/native/sim/Notifier.cpp:323:21: error: 'char* strncpy(char*, const char*, size_t)' specified bound 64 equals destination size [-Werror=stringop-truncation]
         std::strncpy(arr[num].name, notifier->name.c_str(),
         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      sizeof(arr[num].name));
                      ~~~~~~~~~~~~~~~~~~~~~~
```
2021-12-19 16:46:12 -08:00
Thad House
dfc24425c3 [build] Fix gazebo gradle IDE warnings (#3806)
Also add note on how to generate all files for the IDE.
2021-12-19 14:20:08 -08:00
Thad House
c02577bb51 [glass] Configure delay loading for windows camera server support (#3803)
We don't currently support cameras in glass, but it's something we want to do in the future. However, when we do this, glass will completely stop working on N builds of windows, and it would fail to load at all with no messages. To solve this, we can delayload the media foundation dlls that are missing. The executable will then launch even without the dlls present, and we can attempt to load them at runtime and dynamically disable camera support.

When we get around to implementing it, we can just call HasCameraSupport, and dynamically hide all camera related code behind that flag.
2021-12-19 14:19:24 -08:00
sciencewhiz
c9e6a96a61 [wpilib] Document range of Servo angle (NFC) (#3796) 2021-12-19 13:53:31 -08:00
Thad House
9778626f34 [wpilib, hal] Add support for getting faults and versions from power distribution (#3794) 2021-12-19 13:42:49 -08:00
Thad House
34b2d0dae1 [wpilib, hal] High Level REV PH changes (#3792)
More functionality was implemented at the HAL level, so expose that to the wpilib level.

This also does units changes for all the PH related functionality.
2021-12-19 13:41:35 -08:00
Thad House
59a7528fd6 [cscore] Fix crash when usbcamera is deleted before message pump thread fully starts (#3804)
shared_from_this will assert if the shared pointer is in the middle of being destructed. Because we access shared_from_this in the message pump, this can easily occur. The solution is to grab the weak pointer, manually attempt to lock it, and only continue if that succeeds. The message pump is already synchronized to the usb camera being destructed, so this is a fine behavior.
2021-12-19 13:39:23 -08:00
Thad House
11d9859ef1 [build] Update plugins to remove log4j vulnerabilities (#3805) 2021-12-19 13:38:48 -08:00
Peter Johnson
e44ed752ad [glass] Fix CollapsingHeader in Encoder, PCM, and DeviceTree (#3797)
The new storage approach was attempting to save both the name and the
open status to the same storage key.
2021-12-19 07:35:12 -08:00
Thad House
52b2dd5b89 [build] Bump native utils to remove log4j (#3802) 2021-12-19 07:33:12 -08:00
sciencewhiz
c46636f218 [wpilib] Improve new counter classes documentation (NFC) (#3801) 2021-12-18 21:40:03 -08:00
sciencewhiz
dc531462e1 [build] Update to gradle 7.3.2 (#3800) 2021-12-18 21:34:35 -08:00
Tyler Veness
92ba98621c [wpimath] Add helper variable templates for units type traits (#3790) 2021-12-18 11:32:32 -08:00
sciencewhiz
d41d051f1b [wpilibc] Fix Mecanum & Swerve ControllerCommand lambda capture (#3795)
Fixes #3765
Also fixes SwerveControllerCommand example calling command twice.
2021-12-18 11:30:57 -08:00
sciencewhiz
c5ae0effac OtherVersions.md: Add one missing case of useLocal (#3788) 2021-12-15 20:30:34 -08:00
Tyler Veness
b3974c6ed3 [wpimath] Upgrade to Drake v0.37.0 (#3786) 2021-12-14 06:41:38 -08:00
Peter Johnson
589a00e379 [wpilibc] Start DriverStation thread from RobotBase (#3785)
With the change from GetInstance to static functions, many functions
don't call DriverStation::GetInstance(), so the DS thread wasn't
getting started by default.  Call InDisabled() to make sure this
happens.
2021-12-12 22:23:13 -08:00
Tyler Veness
8d9836ca02 [wpilib] Improve curvature drive documentation (NFC) (#3783) 2021-12-12 17:59:04 -08:00
Peter Johnson
8b5bf8632e [myRobot] Add wpimath and wpiutil JNI (#3784) 2021-12-12 17:57:52 -08:00
sciencewhiz
1846114491 [examples] Update references from characterization to SysId (NFC) (#3782) 2021-12-11 21:25:43 -08:00
Thad House
2c461c794e [build] Update to gradle 7.3 (#3778) 2021-12-10 21:26:28 -08:00
Jan-Felix Abellera
109363daa4 [hal] Add remaining driver functions for REVPH (#3776)
Add the remaining HAL functions needed to fully support the Pneumatic Hub and its latest firmware.

- Clear sticky faults
- Get device voltage
- Get 5v supply voltage (used for analog to PSI calculation)
- Get solenoid voltage
- Get solenoid current
- Get device firmware and hardware version

Some minor refactoring was done for naming of some internal functions for consistency purposes.
2021-12-09 12:29:09 -08:00
Jan-Felix Abellera
41d26bee8d [hal] Refactor REV PDH (#3775)
Refactors retrieving the faults from the device to match the implementation that we have for the Pneumatic Hub. Instead of having a getter function for each fault, there is a single function to get all faults (sticky or normal) for use with the higher level API

Renames functions to be consistent

Removes some functions that don't need to be included in wpilib:
- Identify device - this just flashes the module LED on the device and has no use in wpilib
- Is PDH enabled - the PDH does not change state depending on robot enabled state

PDH frame and signal names were updated in our DBC, and this PR makes use of the newly generated CAN frame helper functions
2021-12-09 12:27:06 -08:00
Tyler Veness
7269a170fb Upgrade maven deps to latest versions and fix new linter errors (#3772)
This also makes the Gradle build work with JDK 17.

The extra JVM args in gradle.properties works around a bug with spotless
and JDK 17: https://github.com/diffplug/spotless/issues/834

PMD.CloseResource was ignored because it's almost always a false
positive, and there are many of them.
2021-12-09 12:20:08 -08:00
Thad House
441f2ed9b0 [build] actions: use fixed image versions instead latest (#3761) 2021-12-09 12:12:59 -08:00
Modelmat
15275433d4 [examples] Fix duplicate port allocations in C++ SwerveBot/SwerveDrivePoseEstimator/RomiReference (#3773)
- Remove duplicate motor port (2) from C++ SwerveBot/SwerveDrivePoseEstimator

Java has the correct motor ports.

- Fix duplicate port allocation in C++ RomiReference by correcting if/else check

Java logic was already correct, and confirms this change.
2021-12-06 21:08:34 -08:00
Jason Daming
1ac02d2f58 [examples] Fix drive Joystick axes in several examples (#3769) 2021-12-06 16:40:10 -08:00
Jason Daming
8ee6257e92 [wpilib] DifferentialDrivetrainSim.KitbotMotor: Add NEO and Falcon 500 (#3762) 2021-12-06 14:46:58 -08:00
Prateek Machiraju
d81ef2bc5c [wpilib] Fix deadlocks in Mechanism2d et al. (#3770)
UpdateEntries() and Flush() are called from methods that lock the mutex,
so locking it again will cause deadlocks. This also updates the Java
code to make MechanismObject2d::update synchronized like in the C++
version.
2021-12-06 14:42:02 -08:00
Tyler Veness
acb64dff97 [wpimath] Make RamseteController::Calculate() more concise (#3763) 2021-12-06 12:57:42 -08:00
Jan-Felix Abellera
3f6cf76a8c [hal] Refactor REV PH CAN frames (#3756) 2021-12-06 10:08:57 -08:00
Peter Johnson
3ef2dab465 [wpilib] DutyCycleEncoder: add setting of duty cycle range (#3759)
As the sensor needs to maintain an actual duty cycle, it can't go all
the way from 0-100, so provide a way to set the min and max and linearly
map between the two.
2021-12-05 14:28:08 -08:00
sciencewhiz
a5a56dd067 Readme: Add Visual Studio 2022 (#3760) 2021-12-05 14:27:37 -08:00
Tyler Veness
04957a6d30 [wpimath] Fix units of RamseteController's b and zeta (#3757)
Fixes #3755.
2021-12-03 18:21:30 -08:00
Peter Johnson
5da54888f8 [glass] Upgrade imgui to 0.85, implot to HEAD, glfw to 3.3.5 (#3754)
This in particular upgrades the plot widget with a few new features
and makes more plot configuration persistent.
2021-12-03 17:23:18 -08:00
Thad House
6c93365b0f [wpiutil] MulticastService cleanup (#3750)
Fix duplicated constructors, and also use simpler utf conversion API on windows.
2021-12-02 21:06:55 -08:00
Thad House
1c4a8bfb66 [cscore] Cleanup Windows USB camera impl (#3751)
- Use wpiutil string conversion rather than codecvt (which is deprecated).
- Force A function types.
2021-12-02 13:48:03 -08:00
Thad House
d51a1d3b3d [rtns] Fix icon (#3749) 2021-11-30 21:58:58 -08:00
Thad House
aced2e7da6 Add roboRIO Team Number Setter tool (#3744) 2021-11-30 11:17:30 -08:00
Thad House
fa1ceca83a [wpilibj] Use DS cache for iterative robot control word cache (#3748)
The root cause of #3747 is CommandScheduler's ds state checks are behind iterative robots checks. This means that the iterative robot state could return enabled, but the DS cache could still be reporting disabled. This results in a race in the Disabled -> Enabled transition, which manifests in commands not running.

Previously, iterative robot base pulled from the DS cache. This meant that the ds cache was always updated before an iterative robot base loop could run. This still had a race, but this could only occur on the Enabled -> Disable transition, which is much less noticeable and would usually just result in a command running for an extra loop.

We can move back to the old behavior by grabbing the new iterative robot base check variables to use the DS cache.
2021-11-29 20:56:58 -08:00
sciencewhiz
0ea05d34e6 [build] Update to gradle 7.2 (#3746) 2021-11-29 20:53:26 -08:00
Thad House
09db4f672b [build] Update to native utils 2022.6.1 (#3745) 2021-11-29 13:04:08 -08:00
Thad House
4ba80a3a8c [wpigui] Don't recursively render frames in size callback (#3743)
WindowSizeCallback can sometimes be called while doing a render. If this occurs, imgui asserts. Avoid this case.
2021-11-28 01:03:40 -08:00
Peter Johnson
ae208d2b17 [wpiutil] StringExtras: Add substr() (#3742)
Unlike std::string and std::string_view, this substr() allows a start
greater than the length of the string, in which case an empty string
is returned.  This matches llvm::StringRef behavior.
2021-11-27 21:31:40 -08:00
Thad House
6f51cb3b98 [wpiutil] MulticastResolver: make event manual reset, change to multiple read (#3736) 2021-11-27 11:16:24 -08:00
Peter Johnson
f6159ee1a2 [glass] Fix Drive widget handling of negative rotation (#3739)
This would crash in debug mode due to an imgui assertion in PathArcTo.
2021-11-27 10:58:45 -08:00
Thad House
7f401ae895 [build] Update NI libraries to 2022.2.3 (#3738) 2021-11-27 09:43:07 -08:00
Peter Johnson
0587b7043a [glass] Use JSON files for storage instead of imgui ini
Storage is now nested.

Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.

ImGui's ini (for window position) is mapped to JSON.

You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.

Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.

Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.

Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.

Workspace | Save As Global: "save as" to the global system location

Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-27 00:12:13 -08:00
Peter Johnson
0bbf51d566 [wpigui] Change maximized to bool 2021-11-27 00:12:13 -08:00
Peter Johnson
92c6eae6b0 [wpigui] PFD: Add explicit to constructors 2021-11-27 00:12:13 -08:00
Peter Johnson
141354cd79 [wpigui] Add hooks for custom load/save settings
Add GetPlatformSaveFileDir().
2021-11-27 00:12:13 -08:00
Thad House
f6e9fc7d71 [wpiutil] Handle multicast service collision on linux (#3734) 2021-11-26 23:20:54 -08:00
Peter Johnson
d8418be7d1 [glass, outlineviewer] Return 0 from WinMain (#3735)
While this is implicit in main(), WinMain() requires an explicit return.
2021-11-26 23:19:45 -08:00
Thad House
82066946e5 [wpiutil] Add mDNS resolver and announcer (#3733) 2021-11-25 22:08:26 -08:00
Thad House
4b1defc8d8 [wpilib] Remove automatic PD type from module type enum (#3732)
Using automatic type doesn't work with any module number, so the API was confusing.
2021-11-23 23:03:45 -08:00
Oblarg
da90c1cd2c [wpilib] Add bang-bang controller (#3676)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-11-23 20:34:46 -08:00
Thad House
3aa54fa027 [wpilib] Add new counter implementations (#2447) 2021-11-23 20:33:36 -08:00
Thad House
b156db400d [hal, wpilib] Incorporate pneumatic control type into wpilibc/j (#3728) 2021-11-23 20:32:02 -08:00
sciencewhiz
9aba2b7583 [oldCommands] Add wrappers for WPILib objects to work with old PID Controller (#3710) 2021-11-23 20:30:30 -08:00
Jan-Felix Abellera
a9931223f0 [hal] Add REV PH faults (#3729) 2021-11-22 21:15:32 -08:00
Tyler Veness
aacf9442e4 [wpimath] Fix units typo in LinearSystemId source comment (#3730) 2021-11-22 21:14:38 -08:00
Tyler Veness
7db10ecf00 [wpilibc] Make SPI destructor virtual since SPI contains virtual functions (#3727) 2021-11-20 11:21:02 -08:00
Tyler Veness
a0a5b2aea5 [wpimath] Upgrade to EJML 0.41 (#3726) 2021-11-20 01:02:37 -08:00
Jan-Felix Abellera
eb835598a4 [hal] Add HAL functions for compressor config modes on REV PH (#3724) 2021-11-20 01:02:23 -08:00
Tyler Veness
f0ab6df5b6 [wpimath] Upgrade to Drake v0.36.0 (#3722) 2021-11-16 14:37:29 -08:00
sciencewhiz
075144faa3 [docs] Parse files without extensions with Doxygen (#3721)
Fixes inclusion of wpi::numbers and some Eigen files
2021-11-16 11:22:34 -08:00
Thad House
32468a40cb [hal] Remove use of getDmaDescriptor from autospi (#3717)
It’s not necessary, as the index equals the channel.
2021-11-13 08:55:21 -08:00
Vasista Vovveti
38611e9dd7 [hal] Fix REVPH Analog Pressure channel selection (#3716) 2021-11-10 18:22:18 -08:00
sciencewhiz
4d78def31e [wpilib] Add DeadbandElimination forwarding to PWMMotorController (#3714) 2021-11-09 21:24:47 -08:00
Tyler Veness
3be0c1217a [wpilibcExamples] Make GearsBot use idiomatic C++ (#3711)
Replace pointer constructor arguments with references, and const qualify
getters where possible.

Also remove redundant simulation P gain.

Fixes #1146.
2021-11-09 20:11:50 -08:00
Tyler Veness
42d3a50aa2 [hal] Check error codes during serial port initialization (#3712)
Throw if serial port init fails.

Fixes #2036.
2021-11-09 20:10:48 -08:00
PJ Reiniger
52f1464029 Add project with field images and their json config files (#3668) 2021-11-08 22:48:16 -08:00
Thad House
68ce62e2e9 [hal] Add autodetect for power modules (#3706)
Default autodetect to REV if no devices are found, as only the REV devices have control functionality (the switchable output).
2021-11-07 13:53:38 -08:00
Thad House
3dd41c0d37 [wpilib] Don't print PD errors for LiveWindow reads (#3708)
If something happens with the PD connection, these would have spammed messages continuously.
This wasn't the case previously, and we don't want this behavior now.
2021-11-07 13:45:28 -08:00
Thad House
7699a1f827 [hal] Fix sim not working with automatic PD type and default module (#3707) 2021-11-05 23:30:10 -07:00
Peter Johnson
e473a00f97 [wpiutil] Base64: Add unsigned span/vector variants (#3702) 2021-11-01 07:48:26 -07:00
Peter Johnson
52f2d580eb [wpiutil] raw_uv_ostream: Add reset() (#3701)
This enables reuse of a raw_uv_ostream object.
2021-11-01 07:47:13 -07:00
Peter Johnson
d7b1e3576f [wpiutil] WebSocket: move std::function (#3700) 2021-11-01 07:46:15 -07:00
sciencewhiz
93799fbe9d [examples] Fix description of TrapezoidProfileSubsystem (#3699) 2021-11-01 00:08:53 -07:00
Tyler Veness
b84644740d [wpimath] Document pose estimator states, inputs, and outputs (#3698)
Fixes #3244.
2021-10-29 17:37:13 -07:00
Tyler Veness
2dc35c1399 [wpimath] Fix classpaths for JNI class loads (#3697)
Found by inspecting the results of the following rg commands:
`rg --multiline 'FindClass\(\s*"'`
`rg 'JClass' -A 1`

Fixes #3660.
2021-10-29 16:23:46 -07:00
Tyler Veness
2cb171f6f5 [docs] Set Doxygen extract_all to true and fix Doxygen failures (#3695)
The template argument order for UnscentedTransform was reversed to match
all the other UKF classes. Since UnscentedTransform is intended as a
class for internal use only, this shouldn't cause much breakage.
2021-10-29 15:07:05 -07:00
Tyler Veness
a939cd9c89 [wpimath] Print uncontrollable/unobservable models in LQR and KF (#3694)
IsDetectable() was added to make the code easier to read.
2021-10-29 00:03:02 -07:00
Tyler Veness
d5270d113b [wpimath] Clean up C++ StateSpaceUtil tests (#3692) 2021-10-29 00:02:03 -07:00
Tyler Veness
b20903960b [wpimath] Remove redundant discretization tests from StateSpaceUtilTest (#3689)
DiscretizationTest already does these.
2021-10-29 00:01:41 -07:00
Tyler Veness
c0cb545b41 [wpilibc] Add deprecated Doxygen attribute to SpeedController (#3691)
Fixes #3690.
2021-10-29 00:01:04 -07:00
Tyler Veness
35c9f66a75 [wpilib] Rename PneumaticsHub to PneumaticHub (#3686)
Fixes #3684.
2021-10-29 00:00:31 -07:00
Tyler Veness
796d03d105 [wpiutil] Remove unused LLVM header (#3688) 2021-10-28 00:18:26 -07:00
Tyler Veness
8723caf78d [wpilibj] Make Java TrapezoidProfile.Constraints an immutable class (#3687) 2021-10-28 00:17:36 -07:00
Tyler Veness
187f50a344 [wpimath] Catch incorrect parameters to state-space models earlier (#3680)
This allows giving more descriptive exceptions than if they are thrown
later in KalmanFilter, for example.

Fixes #3678.
2021-10-27 20:18:57 -07:00
Tyler Veness
8d04606c4d Replace instances of frc-characterization with SysId (NFC) (#3681) 2021-10-27 06:40:17 -07:00
Peter Johnson
b82d4f6e58 [hal, cscore, ntcore] Use WPI common handle type base 2021-10-26 23:39:11 -07:00
Peter Johnson
87e34967ef [wpiutil] Add synchronization primitives
These enable more consistent use of synchronization across the
native libraries.  Users can create Event and Semaphore primitives, but
in addition, libraries can set up any handle as an Event-type signal.
2021-10-26 23:39:11 -07:00
Peter Johnson
e32499c546 [wpiutil] Add ParallelTcpConnector (#3655)
This is a libuv-based parallel, repeating TCP connector for making
multiple parallel DNS resolution and TCP connection attempts to a
network server.
2021-10-26 23:37:58 -07:00
Tyler Veness
aa0b49228d [wpilib] Remove redundant "quick turn" docs for curvature drive (NFC) (#3674)
The parameter docs for allowTurnInPlace say the same thing, and it's no
longer called "quick turn".
2021-10-26 23:37:11 -07:00
Noah Andrews
57301a7f9c [hal] REVPH: Start closed-loop compressor control on init (#3673)
Similar to the PCM, we're going to make the PH not do anything with the compressor until the PH HAL object has been initialized. The mechanism we're going to use to signal to the PH that that has happened is to begin sending the state of the solenoids (which will all be set to off at this point).
2021-10-26 23:36:47 -07:00
sciencewhiz
d1842ea8fb [wpilib] Improve interrupt docs (NFC) (#3679) 2021-10-26 23:35:01 -07:00
Peter Johnson
558151061e [wpiutil] Add DsClient (#3654)
This is a libuv-based implementation of the Driver Station client
for getting robot IPs from the Driver Station port 1742 server.
2021-10-26 23:34:27 -07:00
Tyler Veness
181723e573 Replace .to<double>() and .template to<double>() with .value() (#3667)
It's a less verbose way to do the same thing.
2021-10-25 08:58:12 -07:00
sciencewhiz
6bc1db44bc [commands] Add pointer overload of AddRequirements (artf6003) (#3669)
Also update documentation in CommandBase.
2021-10-25 08:57:22 -07:00
Tyler Veness
737b57ed5f [wpimath] Update to drake v0.35.0 (#3665) 2021-10-22 23:02:08 -07:00
Austin Shalit
4d287d1ae2 [build] Upgrade WPIJREArtifact to JRE 2022-11.0.12u5 (#3666) 2021-10-22 23:01:09 -07:00
apple
f26eb5ada4 [hal] Fix another typo (get -> gets) (NFC) (#3663) 2021-10-22 11:49:21 -07:00
apple
94ed275ba6 [hal] Fix misspelling (numer -> number) (NFC) (#3662) 2021-10-22 07:23:13 -07:00
Peter Johnson
ac2f44da33 [wpiutil] uv: use move for std::function (#3653)
Also use function_ref for Loop::Walk().
2021-10-20 23:24:59 -07:00
Peter Johnson
75fa1fbfbf [wpiutil] json::serializer: Optimize construction (#3647)
Remove unused locale pointer.
2021-10-20 21:09:04 -07:00
Peter Johnson
5e689faea8 [wpiutil] Import MessagePack implementation (mpack) (#3650) 2021-10-20 21:08:31 -07:00
Peter Johnson
649a50b401 [wpiutil] Add LEB128 byte-by-byte reader (#3652)
This is needed for compatibility with streaming data (e.g. libuv) where partial data
may be received.  Also add raw_ostream writer.
2021-10-20 18:50:20 -07:00
Peter Johnson
e94397a97d [wpiutil] Move json_serializer.h to public headers (#3646)
This makes it possible to do "manual" JSON-compliant serialization more efficiently
(e.g. without needing to construct a full json object).
2021-10-20 11:18:13 -07:00
Peter Johnson
4ec58724d7 [wpiutil] uv::Tcp: Clarify SetNoDelay documentation (#3649) 2021-10-20 08:46:44 -07:00
Peter Johnson
8cb294aa4a [wpiutil] WebSocket: Make Shutdown() public (#3651) 2021-10-20 08:45:58 -07:00
Peter Johnson
2b3a9a52b3 [wpiutil] json: Fix map iterator key() for std::string_view (#3645) 2021-10-20 08:45:16 -07:00
Peter Johnson
138cbb94b2 [wpiutil] uv::Async: Add direct call for no-parameter specialization (#3648) 2021-10-20 08:44:33 -07:00
sciencewhiz
e56d6dea81 [ci] Update testbench pool image to ubuntu-latest (#3643) 2021-10-18 21:39:43 -07:00
sciencewhiz
43f30e44e4 [build] Enable comments in doxygen source files (#3644) 2021-10-18 21:39:22 -07:00
sciencewhiz
9e6db17ef4 [build] Enable doxygen preprocessor expansion of WPI_DEPRECATED (#3642)
This fixes documentation for SpeedController and SpeedControllerGroup
2021-10-18 21:29:23 -07:00
sciencewhiz
0e631ad2f2 Add WPILib version to issue template (#3641) 2021-10-18 09:09:57 -07:00
Austin Shalit
6229d8d2ff [build] Docs: set case_sense_names to false (#3392)
This means the output will be consistent for all 3 major os and prevent case issues when sharing files.
2021-10-15 00:37:59 -07:00
Tyler Veness
4647d09b50 [docs] Fix Doxygen warnings, add CI docs lint job (#3639)
The CI docs lint build is configured to fail on Doxygen warnings.
2021-10-14 18:09:38 -07:00
sciencewhiz
4ad3a54026 [hal] Fix PWM allocation channel (#3637)
Previously it showed 31 when 0 was doubly allocated
2021-10-14 07:28:49 -07:00
sciencewhiz
05e5feac41 [docs] Fix brownout docs (NFC) (#3638) 2021-10-14 07:28:21 -07:00
Prateek Machiraju
67df469c58 [examples] Remove old command-based templates and examples (#3263)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-10-13 19:17:58 -07:00
Thad House
689e9ccfb5 [hal, wpilib] Add brownout voltage configuration (#3632) 2021-10-13 19:14:27 -07:00
sciencewhiz
9cd4bc407a [docs] Add useLocal to avoid using installer artifacts (#3634) 2021-10-13 10:38:33 -07:00
Peter Johnson
61996c2bbf [cscore] Fix Java direct callback notifications (#3631)
These relied on the OnStart and OnExit callbacks which were not present
in the wpiutil common CallbackManager code.  Add support for these and
fix up other use cases.

Also fixes notifications to correctly filter on event kind.

This fixes a breakage caused by #3133.
2021-10-13 08:46:07 -07:00
Thad House
6d3dd99eb2 [build] Update to newest native-utils (#3633) 2021-10-13 07:47:10 -07:00
Tyler Veness
f0b484892c [wpiutil] Fix StringMap iterator equality check (#3629)
This fixes the following warning.
The member function operator== only works in C++17, and the friend operator== only works in C++20.

```
 /Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:1847:46: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'const typename json::object_t::iterator' (aka 'const StringMapIterator<wpi::json>') and 'const typename json::object_t::iterator') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
                return (m_it.object_iterator == other.m_it.object_iterator);
                        ~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:1863:20: note: in instantiation of member function 'wpi::detail::iter_impl<const wpi::json>::operator==' requested here
        return not operator==(other);
                   ^
/Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:5008:20: note: in instantiation of member function 'wpi::detail::iter_impl<const wpi::json>::operator!=' requested here
            if (it != end())
                   ^
/Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:5025:16: note: in instantiation of function template specialization 'wpi::json::value<std::basic_string<char>, 0>' requested here
        return value(key, std::string(default_value));
               ^
/Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/StringMap.h:442:8: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
  bool operator==(const DerivedTy &RHS) const { return Ptr == RHS.Ptr; }
       ^
```
2021-10-12 23:28:26 -07:00
Lucas
8352cbb7a3 Update development build instructions for 2022 (#3616)
Updates the instructions for development and local WPILib builds as per the GradleRIO 2022 updates.
2021-10-12 22:47:16 -07:00
sciencewhiz
6da08b71dc [examples] Fix Intermediate Vision Java Example description (#3628)
Copy from C++
2021-10-11 22:55:33 -07:00
Peter Johnson
5d99059bf9 [wpiutil] Remove optional.h (#3627)
This has been replaced fully by std::optional and deprecated for a year.
2021-10-11 22:54:33 -07:00
Tyler Veness
fa41b106ab [glass, wpiutil] Add missing format args (#3626)
These were caught by compile-time format string parsing in C++20.
2021-10-11 22:54:20 -07:00
Thad House
4e3fd7d420 [build] Enable Zc:__cplusplus for Windows (#3625)
This makes the version actually be correct.
2021-10-11 20:30:22 -07:00
Starlight220
791d8354da [build] Suppress deprecation/removal warnings for old commands (#3618) 2021-10-10 20:07:12 -07:00
Thad House
10f19e6fc3 [hal, wpilib] Add REV PneumaticsHub (#3600) 2021-10-10 20:04:50 -07:00
Peter Johnson
4c61a13057 [ntcore] Revert to per-element copy for toNative() (#3621)
arraycopy() does not unbox values, so throws an exception.

This was broken in #3419 due to a false positive in PMD
(see https://sourceforge.net/p/pmd/bugs/804/).
2021-10-10 15:53:35 -07:00
Peter Johnson
7b3f62244f [wpiutil] SendableRegistry: Print exception stacktrace (#3620) 2021-10-10 15:53:11 -07:00
Thad House
d347928e4d [hal] Use better error for when console out is enabled while attempting to use onboard serial port (#3622) 2021-10-10 15:52:50 -07:00
Tyler Veness
cc31079a11 [hal] Use setcap instead of setuid for setting thread priorities (#3613)
We originally moved to setuid admin so user programs could do other
things requiring admin if they wanted. However, these things, like
setting RT priorities of other processes, can usually be done instead as
admin during the GradleRIO 2022 deploy process, or adding commands to
the robotCommand script. By going back to setcap, we can simplify the
HAL code.
2021-10-04 09:49:34 -07:00
Tyler Veness
4676648b78 [wpimath] Upgrade to Drake v0.34.0 (#3607) 2021-09-29 15:39:47 -07:00
Thad House
c7594c9111 [build] Allow building wpilibc in cmake without cscore and opencv (#3605)
The hard dependency on cscore was removed a while ago in gradle, so make it not a hard requirement in cmake.
2021-09-27 21:37:04 -07:00
Tyler Veness
173cb7359d [wpilib] Add TimesliceRobot (#3502) 2021-09-26 13:56:33 -07:00
Tyler Veness
af295879fb [hal] Set error status for I2C port out of range (#3603)
Closes #1369.
2021-09-26 10:38:17 -07:00
Tyler Veness
95dd20a151 [build] Enable spotbugs (#3601)
Benign spotbugs warnings were suppressed, and all others were fixed. Bug
descriptions are documented here:
https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html

Co-authored-by: Austin Shalit <austinshalit@gmail.com>
2021-09-24 16:04:02 -07:00
Tyler Veness
b65fce86bf [wpilib] Remove Timer lock in wpilibj and update docs (#3602)
Timer reports a negative duration if the sim timing is restarted. This
can be worked around by calling Reset(). Other options included:

1. Have RestartTiming() call Timer::Reset() on a list of instantiated
   Timers.
2. Have Timer::Get() reset the timer if it notices time went backwards.
   This requires dropping const qualification though, which is a
   breaking change that only fixes a minor edge case.

Closes #2732.
2021-09-24 16:01:13 -07:00
Tyler Veness
3b8d3bbcbf Remove unused and add missing deprecated.h includes (#3599)
I generated lists of includes and uses via
`rg -l deprecated.h | sort -u` and `rg -l WPI_DEPRECATED | sort -u`
respectively. If a file was in the first list but not the second, the
include was unused. If a file was in the second list but not the first,
the include needed to be added.
2021-09-22 18:29:57 -07:00
Tyler Veness
f9e976467f [examples] Rename DriveTrain classes to Drivetrain (#3594)
Drivetrain is one word, not two.
2021-09-22 13:27:26 -07:00
Tyler Veness
118a27be2f [wpilib] Add Timer tests (#3595) 2021-09-22 13:26:58 -07:00
Tyler Veness
59c89428e5 [wpilib] Deprecate Timer::HasPeriodPassed() (#3598)
AdvanceIfElapsed() is safer to use, as it has less surprising side effects.
2021-09-22 13:01:37 -07:00
Tyler Veness
202ca5e782 Force C++17 in .clang-format (#3597) 2021-09-22 10:04:03 -07:00
Tyler Veness
d6f185d8e5 Rename tests for consistency (#3592)
I started with the output of styleguide#217, then renamed a few classes
to fix compilation.

ntcore's StorageTest needed some manual renaming since it put the Test
word in the middle instead of at the end.

One limitation of wpiformat is test cases that were only named "Test"
were unmodified, and an error was generated. These test cases were
manually given more descriptive names:

* TimedRobotTest mode test cases had "Mode" appended to the name. Java
  tests were renamed to match.
* UvAsyncTest and UvAsyncFunctionTest cases were given alternate names
2021-09-21 06:12:50 -07:00
Tyler Veness
54ca474dba [ci] Enable asan and tsan in CI for tests that pass (#3591)
ctest's -E flag skips tests that match a regular expression.
2021-09-19 20:03:40 -07:00
Tyler Veness
1ca383b23b Add Debouncer (#3590)
Supersedes #2358 with updates and cleanups.

Closes #2482 and closes #2487 because we shouldn't support both
time-based and count-based debouncing approaches.

Co-authored-by: oblarg <emichaelbarnett@gmail.com>
2021-09-19 19:58:16 -07:00
Thad House
179fde3a7b [build] Update to 2022 native utils and gradle 7 (#3588) 2021-09-19 17:59:14 -07:00
sciencewhiz
50198ffcf1 [examples] Add Mechanism2d visualization to Elevator Sim (#3587) 2021-09-18 22:06:14 -07:00
sciencewhiz
a446c25598 [examples] Synchronize C++ and Java Mechanism2d examples (#3589)
- Synchronize dimensions
- Make both joints different colors for clarity
2021-09-18 22:05:35 -07:00
Tyler Veness
a7fb831035 [ci] clang-tidy: Generate compilation commands DB with Gradle (#3585) 2021-09-18 10:19:34 -07:00
sciencewhiz
4f5e0c9f85 [examples] Update ArmSimulation example to use Mechanism2d (#3572)
- Correct several comments that referenced elevator
- Changed noise to be 1 encoder tick instead of half a degree
- Changed gear ratio and PID value to be better tuned
- Updated bounds to be similar to a single jointed arm
2021-09-17 22:55:31 -07:00
Tyler Veness
8164b91dc4 [CI] Print CMake test output on failure (#3583) 2021-09-17 22:54:47 -07:00
sciencewhiz
4d5fca27ef [wpilib] Impove Mechanism2D documentation (NFC) (#3584) 2021-09-17 22:54:10 -07:00
Tyler Veness
fe59e4b9fe Make C++ test names more consistent (#3586)
Inconsistent names were found using the following regular expressions.

* `rg "TEST(_F|_P)?\(\w+,\s+\w+Test\)"`
* `rg "TEST(_F|_P)?\(\w+,\s+Test\w+\)"`
* `rg "TEST(_F|_P)?\(\w+Tests,\s+\w+\)"`

Fixes #3495.
2021-09-17 22:51:51 -07:00
sciencewhiz
5c88685495 [wpilibc] Fix C++ MechanisimRoot2D to use same NT entries as Java/Glass (#3582)
Fixes #3578
2021-09-17 12:13:36 -07:00
Tyler Veness
9359431bad [wpimath] Clean up Eigen usage
* Replace Matrix<> with Vector<> where vectors are explicitly intended.
  I found these via `rg "Eigen::Matrix<double, \w+, 1>"`.
* Pass all Eigen matrices by const reference. I found these via `rg
  "\(Eigen"` on main (the initializer list constructors make more false
  positives).
* Replace MakeMatrix() and operator<< usage with initializer list
  constructors. I found these via `rg MakeMatrix` and `rg "<<"`
  respectively.
* Deprecate MakeMatrix()
2021-09-17 12:12:19 -07:00
Tyler Veness
72716f51ce [wpimath] Upgrade to Eigen 3.4 2021-09-17 12:12:19 -07:00
Thad House
382deef750 [wpimath] Explicitly export wpimath symbols
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-09-17 12:12:19 -07:00
Peter Johnson
161e211734 [ntcore] Match standard handle layout, only allow 16 instances (#3577)
Now that there are only 16 instances, store them all statically.

Make tests more reliable by using different ports for each connection in listener tests.
2021-09-17 12:11:00 -07:00
Peter Johnson
263a248119 [wpimath] Use jinja for codegen (#3574)
While not really needed for wpimath, it will make more complex codegen
in the future significantly easier.
2021-09-17 00:10:29 -07:00
Tyler Veness
725251d294 [wpilib] Increase tolerances of DifferentialDriveSimTest (#3581) 2021-09-16 23:42:46 -07:00
Tyler Veness
4dff873013 [wpimath] Make LinearFilter::Factorial() constexpr (#3579)
Since BackwardFiniteDifference() gives it a compile-time constant, it
can be evaluated in a constexpr context.
2021-09-16 20:45:24 -07:00
Thad House
60ede67abd [hal, wpilib] Switch PCM to be a single object that is allowed to be duplicated (#3475)
Having PCM as a singleton is a problem, as multiple things need to use it, and that gets really ugly. This changes PCM's to be a reference counted object, that can be passed around and constructed from multiple places.

In Java, this is using a map to hold a data store with a ref count, and allocating new objects any time a duplicate is requested.

In C++, this uses a trick constructor to store a PCM instance in the data store itself. This instance can then be passed to base objects using std::shared_ptr's aliasing constructor, which means constructing a solenoid from a PCM is not allocating after the 1st one.

This did require removing sendable from PCM. A compressor class was added back in to act as sendable for the PCM.

After this change is finished, the only change RobotBuilder and Team Code would require is passing a module type to solenoid constructors.

Co-authored-by: sciencewhiz <sciencewhiz@users.noreply.github.com>
2021-09-16 18:50:27 -07:00
Tyler Veness
906bfc8464 [build] Add CMake build support for sanitizers (#3576)
* Address sanitizer uses -DCMAKE_BUILD_TYPE=Asan
* Thread sanitizer uses -DCMAKE_BUILD_TYPE=Tsan
* Undefined behavior sanitizer uses -DCMAKE_BUILD_TYPE=Ubsan

Only ubsan is enabled in CI for now because asan and tsan report
failures.
2021-09-16 18:48:41 -07:00
Ryan Hirasaki
0d4f08ad9c [hal] Simplify string copy of joystick name (#3575) 2021-09-16 09:32:57 -07:00
Peter Johnson
a52bf87b7d [wpiutil] Add Java function package (#3570)
The standard Java package is missing BooleanConsumer as well as Float classes.

Update SendableBuilder to use it instead of internal BooleanConsumer
interface.
2021-09-15 21:36:11 -07:00
Peter Johnson
40c7645d6e [wpiutil] UidVector: Return old object from erase() (#3571)
This makes it possible to erase and then do additional cleanup (e.g. on a unique_ptr).
2021-09-15 21:35:20 -07:00
Peter Johnson
5b886a23fd [wpiutil] jni_util: Add size, operator[] to JArrayRef (#3569)
These make it usable more like a standard container.
2021-09-15 21:34:16 -07:00
Tyler Veness
65797caa7b [sim] Fix halsim_ds_socket stringop overflow warning from GCC 10 (#3568)
Fixes #3567.
2021-09-14 20:49:02 -07:00
Thad House
66abb39880 [hal] Update runtime enum to allow selecting roborio 2 (#3565)
In some cases, knowing roborio 2 might be useful. This also creates a higher level enum that might be usable later for the discussion on more complex runtime types.
2021-09-13 22:05:38 -07:00
Thad House
95a12e0ee8 [hal] UidSetter: Don't revert euid if its already current value (#3566)
When running from admin account, this hangs for 5-10 seconds.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-09-13 21:08:39 -07:00
Tyler Veness
27951442b8 [wpimath] Use external Eigen headers only (#3564)
Internal headers are no longer allowed as of
https://gitlab.com/libeigen/eigen/-/merge_requests/631. Based on
benchmarking I conducted in that thread, there doesn't seem to be a
performance penalty for including the full headers anymore.
2021-09-13 14:31:01 -07:00
Austin Shalit
c42e053ae9 [docs] Update to doxygen 1.9.2 (#3562) 2021-09-12 15:19:04 -07:00
sciencewhiz
e7048c8c8b [docs] Disable doxygen linking for common words that are also classes (#3563)
Add % in front of name in order to suppress doxygen link creation. https://www.doxygen.nl/manual/autolink.html
2021-09-12 15:18:45 -07:00
Thad House
d8e0b6c977 [wpilibj] Fix java async interrupts (#3559) 2021-09-11 09:21:02 -07:00
Thad House
5e6c34c61c Update to 2022 roborio image (#3537) 2021-09-10 13:00:58 -07:00
Tyler Veness
828f073ebd [wpiutil] Fix uv::Buffer memory leaks caught by asan (#3555) 2021-09-09 23:14:10 -07:00
Tyler Veness
2dd5701ac0 [cscore] Fix mutex use-after-free in cscore test (#3557)
Fixes #3546.
2021-09-09 23:13:56 -07:00
Tyler Veness
531439198e [ntcore] Fix NetworkTables memory leaks caught by asan (#3556)
Closes #3543.
2021-09-09 23:13:36 -07:00
Tyler Veness
3d9a4d585e [wpilibc] Fix AnalogTriggerOutput memory leak reported by asan (#3554)
Fixes #3542.

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2021-09-09 19:32:00 -07:00
Tyler Veness
54eda59286 [wpiutil] Ignore ubsan vptr upcast warning in SendableHelper moves (#3553)
The move ctor is trying to cast from e.g. SendableHelper to PIDController before PIDController has been constructed, which is potentially UB. We don't actually use anything in PIDController though, so it's OK in our case.
2021-09-09 12:33:50 -07:00
sciencewhiz
5a4f75c9f8 [wpilib] Replace Speed controller comments with motor controller (NFC) (#3551)
Makes comments consistent with #3302
2021-09-08 22:09:08 -07:00
Tyler Veness
7810f665f1 [wpiutil] Fix bug in uleb128 (#3540)
Caused by UB in left shift; identified by ubsan.
2021-09-08 16:24:28 -07:00
sciencewhiz
697e2dd330 [wpilib] Fix errant jaguar reference in comments (NFC) (#3550) 2021-09-08 14:18:37 -07:00
sciencewhiz
936c64ff51 [docs] Enable -linksource for javadocs (#3549)
Embeds source in javadocs.
Fixes #3547
2021-09-07 22:46:09 -07:00
Tyler Veness
1ea6549548 [build] Upgrade CMake build to googletest 1.11.0 (#3548)
This upgrade uncovered two issues:

ntcore wasn't forcing C++17, which caused a linker error with googletest
Matcher symbols:
```
undefined reference to `testing::Matcher<std::basic_string_view<char, std::char_traits<char> > >::Matcher(std::basic_string_view<char, std::char_traits<char> >)'
```

test_span.cpp wasn't including <algorithm> to use std::sort() and
std::is_sorted().
2021-09-07 13:29:31 -07:00
Tyler Veness
32d9949e4d [wpimath] Move controller tests to wpimath (#3541) 2021-09-06 17:00:13 -07:00
Ryan Hirasaki
01ba56a8a6 [hal] Replace strncpy with memcpy (#3539) 2021-09-05 20:47:40 -07:00
Tyler Veness
e109c42515 [build] Rename makeSim flag to forceGazebo to better describe what it does (#3535) 2021-09-05 17:40:54 -07:00
Noam Zaks
e4c7091647 [docs] Use a doxygen theme and add logo (#3533) 2021-09-02 21:59:16 -07:00
Tyler Veness
960b6e5897 [wpimath] Fix Javadoc warning (#3532) 2021-08-28 22:43:38 -07:00
Jan-Felix Abellera
82eef8d5ee [hal] Remove over current fault HAL functions from REV PDH (#3526) 2021-08-28 20:52:46 -07:00
Tyler Veness
aa3848b2c8 [wpimath] Move RobotDriveBase::ApplyDeadband() to MathUtil (#3529)
It's a useful function outside of the drive classes.

For backwards compatibility, deprecate (rather than remove) RobotDriveBase.applyDeadband()
2021-08-28 20:52:05 -07:00
Tyler Veness
3b5d0d141a [wpimath] Add LinearFilter::BackwardFiniteDifference() (#3528)
This is an alternative to #2344 that handles arbitrary order derivatives
of arbitrary precision. The downside is that since it's part of
LinearFilter, it can't utilize the units type system in the same way to
make Calculate()'s input type different from its output type.
2021-08-28 20:50:18 -07:00
Tyler Veness
c8fc715fe2 [wpimath] Upgrade drake files to v0.33.0 (#3531) 2021-08-28 20:49:19 -07:00
Tyler Veness
e5fe3a8e16 [build] Treat javadoc warnings as errors in CI and fix warnings (#3530) 2021-08-28 20:48:47 -07:00
Tyler Veness
e0c6cd3dcc [wpimath] Add an operator for composing two Transform2ds (#3527) 2021-08-23 20:22:48 -07:00
PJ Reiniger
2edd510ab7 [sim] Add sim wrappers for sensors that use SimDevice (#3517) 2021-08-20 23:19:59 -07:00
Tyler Veness
2b3e2ebc11 [hal] Fix HAL Notifier thread priority setting (#3522)
The HAL Notifier thread is started when the first Notifier is created
and stopped when the last Notifier is destroyed. Currently,
HAL_SetNotifierThreadPriority() will cause a segfault if the Notifier thread
hasn't been started yet (that is, if no Notifier have been created yet).

This change makes HAL_SetNotifierThreadPriority() store the RT and
priority setting. If the thread has already been started, it will set
the priority immediately. If it hasn't, HAL_InitializeNotifier() will
set the priority when it starts the thread.
2021-08-20 23:19:25 -07:00
PJ Reiniger
ab4cb59326 [gitignore] Update gitignore to ignore bazel / clion files (#3524) 2021-08-20 23:18:37 -07:00
PJ Reiniger
57c8615af3 [build] Generate spotless patch on failure (#3523) 2021-08-20 23:18:10 -07:00
Tyler Veness
b903173211 Replace std::cout and std::cerr with fmt::print() (#3519) 2021-08-19 20:31:14 -07:00
Thad House
10cc8b89c4 [hal] [wpilib] Add initial support for the REV PDH (#3503) 2021-08-14 11:44:56 -07:00
Tyler Veness
5d9ae3cdb4 [hal] Set HAL Notifier thread as RT by default (#3482)
This PR gives the Notifier HAL thread RT priority 40 in RobotBase after
HAL initialization and before the user code is run. This drastically
improves scheduling jitter for TimedRobot's AddPeriodic() functions (in
3512's experience).

It's too risky to set user code as RT because badly behaved code
will lock up the Rio (potentially requiring safe mode to recover).

This needs the user program to be setuid admin to succeed.
2021-08-14 11:42:35 -07:00
Tyler Veness
192d251ee8 [wpilibcIntegrationTests] Properly disable DMA integration tests (#3514)
"DISABLED_" must be a prefix, not a suffix.
2021-08-14 10:01:12 -07:00
Starlight220
031962608b [wpilib] Add PS4Controller, remove Hand from GenericHID/XboxController (#3345)
- GenericHID is now concrete, and has only getRawAxis/Button(int) functionality
- getXxx() has been moved into Joystick as that's the only place where it makes sense
- Hand (and therefore getXxx(Hand)) has been removed, replaced by specific getLeft/RightXxx() methods in XboxController and the new PS4Controller class
- C++ ::Button:: and ::Axis:: enums have been converted to identically-namespaced static constexpr ints
2021-08-14 10:00:46 -07:00
Tyler Veness
25f6f478a5 [wpilib] Rename DriverStation::IsOperatorControl() to IsTeleop() (#3505) 2021-08-11 23:04:43 -07:00
PJ Reiniger
e80f09f849 [wpilibj] Add unit tests (#3501) 2021-08-11 23:04:14 -07:00
Tyler Veness
c159f91f06 [wpilib] Only read DS control word once in IterativeRobotBase (#3504) 2021-08-11 18:05:07 -07:00
Thad House
eb790a74d2 Add rio development docs documenting myRobot deploy tasks (#3508)
Co-authored-by: sciencewhiz <sciencewhiz@users.noreply.github.com>
2021-08-11 18:04:20 -07:00
Matteo Kimura
e47451f5a0 [wpimath] Replace auto with Eigen types (#3511)
This fixes a bug regarding temporary Eigen values caused by the usage of auto.
2021-08-11 06:58:19 -07:00
Tyler Veness
252b8c83bf Remove Java formatting from build task in CI (#3507)
This saves time in CI spent performing the same source-level checks in
every build job. Checkstyle, PMD, and Spotless are now run once in the
"Lint and Format" job.

The -PskipPMD flag was replaced with a -PskipJavaFormat flag that
disables Checkstyle, PMD, and Spotless.
2021-08-07 20:39:14 -07:00
Tyler Veness
09666ff294 Shorten Gazebo CI build (#3506)
Only build the Gazebo simulation projects instead of all of WPILib.
2021-08-07 20:37:57 -07:00
sciencewhiz
baf2e501dc Update myRobot to use 2021 java (#3509) 2021-08-07 20:36:11 -07:00
Tyler Veness
5ac60f0a20 [wpilib] Remove IterativeRobotBase mode init prints (#3500)
They don't provide much utility for the end user. A print at the call to
HAL_ObserveUserProgramStarting() was added in their place so it's still
clear when constructors have finished running.
2021-08-05 23:54:50 -07:00
Tyler Veness
fb2ee8ec34 [wpilib] Add TimedRobot functions for running code on mode exit (#3499)
Currently, we have functions like TeleopInit() for running code on mode
entry, but no such functions for running code on mode exit, and it's
cumbersome to add those in user code without making a custom robot
class. This PR adds exit functions to TimedRobot.

Some example use cases include DisabledExit() for operations when the
robot enables (whether that be into teleop, autonomous, or test) and
AutonomousExit() for disabling feedback controllers.
2021-08-05 19:08:29 -07:00
PJ Reiniger
94e0db7963 [wpilibc] Add more unit tests (#3494) 2021-08-05 19:04:51 -07:00
sciencewhiz
b253246959 [wpilibj] Add units to parameter names (NFC) (#3497) 2021-08-05 18:04:20 -07:00
Thad House
1ac73a247e [hal] Rename PowerDistributionPanel to PowerDistribution (#3466)
Makes HAL more generic for the PDP, to enable the Rev PDH in the future.
2021-08-04 20:31:17 -07:00
sciencewhiz
2014115bca [examples] frisbeebot: Fix typo and reflow comments (NFC) (#3498) 2021-08-01 07:17:51 -07:00
liorsagy
4a944dc397 [examples] Consistently use 0 for controller port (#3496) 2021-07-31 20:39:50 -07:00
Tyler Veness
3838cc4ec4 Use unicode characters in docs equations (#3487)
javac and javadoc needed the encoding set to UTF-8.
2021-07-29 22:42:43 -07:00
Aditya Tomar
85748f2e6f [examples] Add C++ TankDrive example (#3493)
This is a basic C++ example that demonstrates a simple differential drive implementation using “tank”-style controls through the DifferentialDrive class and an ordinary joystick.
2021-07-28 21:52:14 -07:00
Tyler Veness
d7b8aa56dc [wpilibj] Rename DriverStation In[Mode] functions to follow style guide (#3488) 2021-07-26 07:29:54 -07:00
Tyler Veness
16e096cf86 [build] Fix CMake Windows CI (#3490) 2021-07-26 07:28:52 -07:00
Tyler Veness
50af74c38f [wpimath] Clean up NumericalIntegration and add Discretization tests (#3489)
* Rename Butcher tableau sections in NumericalIntegration such that
  top-left is c, top-right is A, and bottom-right is b
* Move edu.wpi.first.math.Discretization to
  edu.wpi.first.math.system.Discretization
* Sort Java Discretization to match C++ function order
* Add tests for Java Discretization
  * Required adding Runge-Kutta time-varying impl to tests
* Move C++ Runge-Kutta time-varying impl to tests only
  * Users don't need it
2021-07-25 07:42:59 -07:00
Tyler Veness
bfc209b120 Automate fmt update (#3486)
Also refactored upstream_utils to make writing and maintaining new
upstream repo extractions easier.
2021-07-23 09:01:44 -07:00
Austin Shalit
e7f9331e4b [build] Update to Doxygen 1.9.1 (#3008) 2021-07-22 18:33:15 -07:00
Tyler Veness
ab8e8aa2a1 [wpimath] Update drake with upstream (#3484)
Our patches for the DARE and [[noreturn]] attributes were merged
upstream. We missed their monthly release window by a day, so we'll use
a commit hash for now.
2021-07-22 17:48:48 -07:00
Lucas
1ef826d1da [wpimath] Fix IOException path in WPIMath JNI (#3485)
The current 2021.3.1 release refers to `java/lang/IOException` which causes the following exception when using `toPathweaverJson` or `fromPathweaverJson`:

```
java.lang.NoClassDefFoundError: java/lang/IOException
    at edu.wpi.first.math.WPIMathJNI.fromPathweaverJson(Native Method)
    at edu.wpi.first.wpilibj.trajectory.TrajectoryUtil.fromPathweaverJson(TrajectoryUtil.java:79)
```
2021-07-22 17:48:33 -07:00
Tyler Veness
52bddaa97b [wpimath] Disable iostream support for units and enable fmtlib (#3481)
Supersedes #2497.
2021-07-13 13:41:07 -05:00
Tyler Veness
e4dc3908bb [wpiutil] Upgrade to fmtlib 8.0.1 (#3483) 2021-07-13 13:39:14 -05:00
Tyler Veness
1daadb812f [wpimath] Implement Dormand-Prince integration method (#3476)
Also refactored RKF45 implementation to match the new style, which is
easier to read.

The tests were switched from RKF45 to RKDP since it's more accurate.
2021-07-11 09:42:33 -05:00
Tyler Veness
9c2723391b [cscore] Add [[nodiscard]] to GrabFrame functions (#3479)
Closes #3086.
2021-07-11 09:41:12 -05:00
Tyler Veness
7a8796414c [wpilib] Add Notifier integration tests (#3480)
Closes #2610.
2021-07-11 09:39:42 -05:00
Tyler Veness
f8f13c536f [wpilibcExamples] Prefix decimal numbers with 0 (#3478) 2021-07-11 09:38:13 -05:00
Tyler Veness
1adb69c0fd [ntcore] Use "NetworkTables" instead of "Network Tables" in NT specs (#3477)
Closes #3280.
2021-07-11 09:37:27 -05:00
Tyler Veness
5f5830b960 Upload wpiformat diff if one exists (#3474)
This means users will be able to apply it locally with "git apply".
2021-07-09 21:42:20 -05:00
Tyler Veness
9fb4f35bb6 [wpimath] Add tests for DARE overload with Q, R, and N matrices (#3472)
The autodiff headers weren't used by the tests, so they were removed.
2021-07-09 21:41:33 -05:00
Tyler Veness
c002e6f926 Run wpiformat (#3473)
A recent PR had an earlier version of wpiformat ran on it with more
lenient rules.
2021-07-09 20:49:13 -05:00
Thad House
c154e5262e [wpilib] Make solenoids exclusive use, PCM act like old sendable compressor (#3464) 2021-07-09 15:11:12 -07:00
Thad House
6ddef1cca6 [hal] JNI setDIO: use a boolean and not a short (#3469) 2021-07-08 23:42:31 -05:00
Tyler Veness
9d68d95825 Remove extra newlines after open curly braces (NFC) (#3471) 2021-07-08 23:41:30 -05:00
Tyler Veness
a4233e1a16 [wpimath] Add script for updating Drake (#3470)
Common functionality between the Drake and Eigen update scripts was
refactored into a library.
2021-07-08 22:36:01 -05:00
Prateek Machiraju
39373c6d2d Update README.md for new GCC version requirement (#3467) 2021-07-02 19:06:30 -07:00
Prateek Machiraju
d29acc90a2 [wpigui] Add option to reset UI on exit (#3463)
Also add wpiutil as a dependency for wpigui.
2021-06-26 22:48:54 -07:00
Peter Johnson
a371235b0d [ntcore] Fix dangling pointer in logger (#3465)
This is a breaking change (it changes LogMessage::filename from const
char* to std::string) but there should be few users of it.
2021-06-26 22:47:52 -07:00
Tyler Veness
53b4891a5e [wpilibcintegrationtests] Fix deprecated Preferences usage (#3461) 2021-06-23 21:58:27 -07:00
Prateek Machiraju
646ded9123 [wpimath] Remove incorrect discretization in pose estimators (#3460) 2021-06-23 21:57:52 -07:00
Peter Johnson
ea0b8f48e6 Fix some deprecation warnings due to fmtlib upgrade (#3459) 2021-06-23 21:57:32 -07:00
Prateek Machiraju
2067d7e300 [wpilibjexamples] Add wpimathjni, wpiutiljni to library path (#3455) 2021-06-22 06:33:24 -07:00
Tyler Veness
866571ab41 [wpiutil] Upgrade to fmtlib 8.0.0 (#3457) 2021-06-21 20:57:42 -07:00
Thad House
4e1fa03087 [build] Skip PDB copy on windows build servers (#3458) 2021-06-21 20:56:42 -07:00
Peter Johnson
b45572167d [build] Change CI back to 18.04 docker images (#3456)
This reverts commit d068fb321f (#3420).

The 18.04 docker images now use GCC 8, which was the original reason for
updating.  20.04 uses a much more recent libc, so staying with 18.04
enables more Linux platforms to use the binaries.
2021-06-20 23:03:29 -07:00
Tyler Veness
57a160f1b3 [wpilibc] Fix LiveWindow deprecation warning in RobotBase skeleton template (#3454) 2021-06-19 20:45:56 -07:00
Thad House
29ae8640d9 [HLT] Implement duty cycle cross connect tests (#3453) 2021-06-19 20:11:52 -07:00
Thad House
ee6377e54b [HLT] Add relay and analog cross connects (#3452) 2021-06-19 13:03:58 -07:00
Peter Johnson
b0f1ae7ea3 [build] CMake: Build the HAL even if WITH_CSCORE=OFF (#3449)
Also handle the case of WITH_WPILIB=OFF WITH_SIMULATION_MODULES=ON.
2021-06-19 09:30:49 -07:00
Tyler Veness
7aae2b72dc Replace std::to_string() with fmt::format() (#3451) 2021-06-19 09:30:01 -07:00
Thad House
73fcbbd748 [HLT] Add relay digital cross connect tests (#3450) 2021-06-19 01:21:56 -07:00
Thad House
e7bedde835 [HLT] Add PWM tests that use DMA as the back end (#3447)
Both a decent DMA test, and slightly more reliable PWM test.
2021-06-19 01:21:07 -07:00
Peter Johnson
7253edb1e1 [wpilibc] Timer: Fix deprecated warning (#3446) 2021-06-18 21:00:26 -07:00
Tyler Veness
efa28125c6 [wpilibc] Add message to RobotBase on how to read stacktrace (#3444)
Also make stacktrace info an error instead of a warning in both C++ and Java.
2021-06-17 23:52:48 -07:00
Thad House
9832fcfe14 [hal] Fix DIO direction getter (#3445)
Unset means input, where the code was assuming set means input.
2021-06-17 23:03:00 -07:00
Ryan Hirasaki
49c71f9f2d [wpilibj] Clarify robot quit message (#3364)
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
2021-06-16 13:24:06 -07:00
Noam Zaks
791770cf6e [wpimath] Move controller from wpilibj to wpimath (#3439) 2021-06-16 07:45:51 -07:00
Noam Zaks
9ce9188ff6 [wpimath] Add ReportWarning to MathShared (#3441) 2021-06-16 00:52:24 -07:00
Peter Johnson
362066a9b7 [wpilib] Deprecate getInstance() in favor of static functions (#3440)
Co-authored-by: Noam Zaks <imnoamzaks@gmail.com>
2021-06-15 23:06:03 -07:00
Thad House
26ff9371d9 Initial commit of cross connect integration test project (#3434)
Adding as a separate project so current integration tests stay working.
2021-06-14 20:08:11 -07:00
Thad House
4a36f86c81 [hal] Add support for DMA to Java (#3158) 2021-06-14 19:56:42 -07:00
Peter Johnson
85144e47ff [commands] Unbreak build (#3438) 2021-06-14 07:35:21 -07:00
Peter Johnson
b417d961ec Split Sendable into NT and non-NT portions (#3432)
The non-NT portion has been moved to wpiutil.
The NT portion has been moved to ntcore (as NTSendable).

SendableBuilder similarly split and moved.

SendableRegistry moved to wpiutil.

In C++, SendableHelper also moved to wpiutil.

This enables use of Sendable from wpimath and also enables
moving several classes from wpilib to wpimath.
2021-06-13 16:38:05 -07:00
Starlight220
ef4ea84cb5 [commands] Change grouping decorator impl to flatten nested group structures (#3335) 2021-06-13 16:05:14 -07:00
Prateek Machiraju
b422665a3c [examples] Invert right side of drive subsystems (#3437)
The right motors of a DifferentialDrive are no longer automatically
inverted (#3340) so it needs to be done explicitly.
2021-06-13 15:43:16 -07:00
Thad House
186dadf14d [hal] Error if attempting to set DIO output on an input port (#3436) 2021-06-13 15:00:43 -07:00
Tyler Veness
04e64db945 Remove redundant C++ lambda parentheses (NFC) (#3433) 2021-06-12 08:06:45 -07:00
Peter Johnson
f60994ad24 [wpiutil] Rename Java package to edu.wpi.first.util (#3431)
This is more consistent with wpimath being edu.wpi.first.math.
2021-06-12 01:17:09 -07:00
Peter Johnson
cfa1ca96f2 [wpilibc] Make ShuffleboardValue non-copyable (#3430)
This avoids the possibility of it being accidentally sliced by users.
2021-06-11 20:16:35 -07:00
Tyler Veness
4d9ff76433 Fix documentation warnings generated by JavaDoc (NFC) (#3428)
Some C++ Doxygen comments were updated to reflect any wording changes.

See `rg "(@return|@param \w+) TODO" | less` for list of incomplete docs.
2021-06-10 20:46:47 -07:00
Peter Johnson
9e1b7e0464 [build] Fix clang-tidy and clang-format (#3429)
Use the official ubuntu packages on 20.04; don't use ubuntu-latest.
2021-06-10 20:46:21 -07:00
Tyler Veness
a77c6ff3a2 [build] Upgrade clang-format and clang-tidy (NFC) (#3422) 2021-06-10 11:13:09 -07:00
Tyler Veness
099fde97d5 [wpilib] Improve PDP comments (NFC) (#3427)
Also remove HAL doxygen comments from sources;
these functions already had more descriptive comments in their
corresponding headers.
2021-06-10 00:02:51 -07:00
Tyler Veness
f8fc2463ee [wpilibc, wpiutil] Clean up includes (NFC) (#3426) 2021-06-10 00:00:06 -07:00
Tyler Veness
e246b78846 [wpimath] Clean up member initialization in feedforward classes (#3425) 2021-06-09 23:59:31 -07:00
Tyler Veness
c1e128bd5a Disable frivolous PMD warnings and enable PMD in ntcore (#3419)
Some valid warnings like throwing NullPointerException or using a for
loop instead of System.arraycopy() were fixed.

Abstract classes marked with PMD.AbstractClassWithoutAbstractMethod were
made concrete because they already had protected constructors.

Fixes #1697.
2021-06-09 07:01:00 -07:00
Tyler Veness
8284075ee4 Run "Lint and Format" CI job on push as well as pull request (#3412)
This makes the formatter run when pushing to local forks before a pull
request is made.

This is not run on the main branch.
2021-06-08 23:22:40 -07:00
Tyler Veness
f7db09a128 [wpimath] Move C++ filters into filter folder to match Java (#3417) 2021-06-08 21:21:01 -07:00
Tyler Veness
f9c3d54bd1 [wpimath] Reset error covariance in pose estimator ResetPosition() (#3418)
This also fixes a member function name inconsistency between languages
and adds missing documentation to C++'s KalmanFilterLatencyCompensator.

Fixes #3229.
2021-06-08 21:20:43 -07:00
Tyler Veness
0773f4033e [hal] Ensure HAL status variables are initialized to zero (#3421)
HAL functions don't set the status variable on success, so it's possible
to use the status variable in an uninitialized state.
2021-06-08 21:18:59 -07:00
Peter Johnson
d068fb321f [build] Upgrade CI to use 20.04 docker images (#3420) 2021-06-08 12:27:22 -07:00
Peter Johnson
8d054c940c [wpiutil] Remove STLExtras.h
This is a very inefficient header, and it's good to remove to discourage
its use.  Only a handful of use cases remained, and of only array_lengthof.
2021-06-06 21:35:50 -07:00
Peter Johnson
80f1d79218 [wpiutil] Split function_ref to a separate header 2021-06-06 21:35:50 -07:00
Peter Johnson
64f5413253 Use wpi::span instead of wpi::ArrayRef across all libraries (#3414)
- Remove ArrayRef.h
- Add SpanExtras.h for a couple of convenience functions
2021-06-06 19:51:14 -07:00
Peter Johnson
2abbbd9e70 [build] clang-tidy: Remove bugprone-exception-escape (#3415)
This generates warnings for using fmt::print() in main(), which is a
case we're okay with.
2021-06-06 17:47:14 -07:00
Tyler Veness
a5c471af7e [wpimath] Add LQR template specialization for 2x2 system
A differential drive has this dimensionality (2 velocity states and 2
voltage inputs).
2021-06-06 16:45:12 -07:00
Tyler Veness
edd2f0232c [wpimath] Add DARE solver for Q, R, and N with LQR ctor overloads
This is useful for implementing implicit model following.
2021-06-06 16:45:12 -07:00
Peter Johnson
b2c3b2dd8e Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed
- Logging now uses fmtlib style formatting
- Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or
std::puts()/std::fputs() (for unformatted strings).
- A wpi/fmt/raw_ostream.h header has been added to enable
fmt::print() with wpi::raw_ostream
2021-06-06 16:13:58 -07:00
Peter Johnson
4f1cecb8e7 [wpiutil] Remove Path.h (#3413)
This was missed in the std::filesystem change.
2021-06-06 15:50:28 -07:00
Prateek Machiraju
b336eac343 [build] Publish halsim_ws_core to Maven 2021-06-06 15:04:25 -07:00
Prateek Machiraju
2a09f6fa45 [build] Also build sim modules as static libraries
This allows sim modules to be statically linked into an executable to
create a "perfectly static" simulated desktop program. The entry point
was changed to be unique when building static libraries to avoid symbol
collisions.
2021-06-06 15:04:25 -07:00
Thad House
0e702eb799 [hal] Add a unified PCM object (#3331) 2021-06-05 22:36:39 -07:00
Tyler Veness
dea841103d [wpimath] Add fmtlib formatter overloads for Eigen::Matrix and units (#3409)
This allows using Eigen matrices or units natively with fmt::format() or
fmt::print().
2021-06-05 21:10:41 -07:00
Tyler Veness
82856cf816 [wpiutil] Improve wpi::circular_buffer iterators (#3410)
The implementation of wpi::circular_buffer has been effectively replaced
with a dynamically sized copy of wpi::static_circular_buffer with a
resize() member function.
2021-06-05 21:08:12 -07:00
Tyler Veness
8aecda03ed [wpilib] Fix a documentation typo (#3408)
"indicated" was misspelled.
2021-06-05 13:35:03 -07:00
Thad House
5c817082a0 [wpilib] Remove InterruptableSensorBase and replace with interrupt classes (#2410) 2021-06-05 11:25:21 -07:00
Tyler Veness
15c521a7fe [wpimath] Fix drivetrain system identification (#3406)
The units for angular Kv and Ka were inconsistent with the derivation. A
second factory function overload was added for angular units that uses a
trackwidth to convert to the other form.

Notice how section 15.2 of https://file.tavsys.net/control/controls-engineering-in-frc.pdf
defines the angular feedforward as u = Kv,angular v instead of u = Kv,angular + omega.
The units cancel for elements of A but not B, so just the B matrix was incorrect in our code.

This breaks existing C++ code since the units are part of the function
signature.
2021-06-05 11:22:05 -07:00
Thad House
989de4a1bf [build] Force all linker warnings to be fatal for rio builds (#3407)
This will make sure we catch any bugs for missing runtime dependencies before they become bigger problems.
2021-06-05 11:20:09 -07:00
Tyler Veness
d9eeb45b03 [wpilibc] Add units to Ultrasonic class API (#3403) 2021-06-01 21:54:56 -07:00
Peter Johnson
fe570e000c [wpiutil] Replace llvm filesystem with C++17 filesystem (#3401)
Use ghc::filesystem as fill on older GCC (e.g. RoboRIO).
This can be removed once all GCC platforms have upgraded to 8.1 or later.

File open functionality has been retained from LLVM but moved to "fs" namespace
and tweaked for improved consistency with std::filesystem (e.g. error_code is
passed by reference instead of returned).

Also update WPILibC's Filesystem functions to return std::string.
2021-06-01 21:50:35 -07:00
Tyler Veness
01dc0249de [wpimath] Move SlewRateLimiter from wpilib to wpimath (#3399)
Timer was replaced with wpi::Now() to avoid a dependency on other wpilib
classes.
2021-05-31 10:35:54 -07:00
Tyler Veness
93523d572e [wpilibc] Clean up integration tests (#3400)
The command and shuffleboard integration tests were removed because
their unit tests counterparts already provide adequate coverage. Java
already removed these.
2021-05-31 10:21:34 -07:00
Peter Johnson
4f7a4464df [wpiutil] Rewrite StringExtras for std::string_view (#3394)
Remove unused functions and add StringRef-like convenience functions.
Minimize header dependencies.
2021-05-28 23:42:58 -07:00
Tyler Veness
e09293a15e [wpilibc] Transition C++ classes to units::second_t (#3396)
A lot of these are breaking changes. frc::Timer was replaced with the
contents of frc2::Timer. The others were in-place argument changes or
removing deprecated non-unit overloads.
2021-05-28 22:06:59 -07:00
Prateek Machiraju
827b17a52b [build] Create run tasks for Glass and OutlineViewer (#3397) 2021-05-28 22:04:58 -07:00
Peter Johnson
a610379965 [wpiutil] Avoid MSVC warning on span include (#3393) 2021-05-26 23:14:04 -07:00
Peter Johnson
4e2c3051be [wpilibc] Use std::string_view instead of Twine (#3380)
Use fmtlib where needed for string formatting into std::string_view.
2021-05-26 17:44:18 -07:00
Peter Johnson
50915cb7ed [wpilibc] MotorSafety::GetDescription(): Return std::string (#3390)
This is only called in an error condition, so it's not necessary to over
optimize it.
2021-05-26 07:25:32 -07:00
Tyler Veness
f4e2d26d58 [wpilibc] Move NullDeleter from frc/Base.h to wpi/NullDeleter.h (#3387)
frc/Base.h was also deleted because it's now empty.
2021-05-26 07:24:53 -07:00
Peter Johnson
cb0051ae60 [wpilibc] SimDeviceSim: use fmtlib (#3389)
Also clean up several sim classes to use the channel constructor.
2021-05-26 07:23:13 -07:00
Tyler Veness
a238cec12b [wpiutil] Deprecate wpi::math constants in favor of wpi::numbers (#3383)
The constants were moved from std::math to std::numbers before
ratification in C++20.
2021-05-26 00:09:36 -07:00
Tyler Veness
393bf23c0c [ntcore, cscore, wpiutil] Standardize template impl files on .inc extension (NFC) (#3124) 2021-05-25 22:19:30 -07:00
Tyler Veness
e7d9ba135c [sim] Disable flaky web server integration tests (#3388)
The digital output test sometimes fails on Linux and the digital input
test sometimes fails on macOS.
2021-05-25 20:56:35 -07:00
Tyler Veness
0a0003c110 [wpilibjExamples] Fix name of Java swerve drive pose estimator example (#3382) 2021-05-25 20:55:24 -07:00
Tyler Veness
7e1b27554c [wpilibc] Use default copies and moves when possible (#3381)
The removal of ErrorBase allowed the defaults to be used in more places.
2021-05-25 20:54:39 -07:00
Tyler Veness
fb2a56e2d6 [wpilibc] Remove START_ROBOT_CLASS macro (#3384) 2021-05-25 20:53:26 -07:00
Tyler Veness
84218bfb45 [wpilibc] Remove frc namespace shim (#3385) 2021-05-25 20:52:50 -07:00
Tyler Veness
dd78243406 [wpilibc] Remove C++ compiler version static asserts (#3386)
frc/Base.h isn't the first header included basically anywhere, so the
compiler will fail on C++17 things before the asserts in this header are
processed.
2021-05-25 20:52:23 -07:00
Tyler Veness
484cf9c0e8 [wpimath] Suppress the -Wmaybe-uninitialized warning in Eigen (#3378)
GCC 11 emits a false positive when compiling Eigen and breaks the
build.

Fixes #3363.
2021-05-25 10:05:41 -07:00
Peter Johnson
a04d1b4f97 [wpilibc] DriverStation: Remove ReportError and ReportWarning
Change use cases to directly call FRC_ReportError.
2021-05-25 10:04:32 -07:00
Peter Johnson
831c10bdfc [wpilibc] Errors: Use fmtlib 2021-05-25 10:04:32 -07:00
Peter Johnson
87603e400d [wpiutil] Import fmtlib (#3375)
HEAD as of 5/23/2021 (dd8f38fcbbb6eedecd4d451b03ca7d817e8ae67d).
2021-05-24 23:59:35 -07:00
Peter Johnson
4426216725 [wpiutil] Add ArrayRef/std::span/wpi::span implicit conversions 2021-05-23 15:27:40 -07:00
Peter Johnson
bc15b953b4 [wpiutil] Add std::span implementation
Imported from https://github.com/tcbrindle/span with ifdef's removed
(as we require C++17).
2021-05-23 15:27:40 -07:00
Peter Johnson
6d20b12043 [wpiutil] StringRef, Twine, raw_ostream: Add std::string_view support (#3373) 2021-05-23 15:26:28 -07:00
Peter Johnson
2385c2a430 [wpilibc] Remove Utility.h (#3376)
Change last 2 uses of wpi_assert to throw error instead.
2021-05-23 15:25:08 -07:00
Tyler Veness
87384ea684 [wpilib] Fix PIDController continuous range error calculations (#3170)
The inputs should all be errors, so the range should be symmetric.

Fixes #3168.
Fixes #3304.
2021-05-21 23:52:30 -07:00
Tyler Veness
04dae799a2 [wpimath] Add SimpleMotorFeedforward::Calculate(velocity, nextVelocity) overload (#3183)
This is often more convenient than using the overload with velocity and
acceleration.

Fixes #3160.
2021-05-21 23:44:10 -07:00
Tyler Veness
0768c39036 [wpilib] DifferentialDrive: Remove right side inversion (#3340)
Also refactor drive inverse kinematics into separate functions.
This allows composing them with operations separate from the drive
class.
2021-05-21 22:34:16 -07:00
Tyler Veness
8dd8d4d2d4 [wpimath] Fix redundant nested math package introduced by #3316 (#3368) 2021-05-21 22:29:52 -07:00
Dalton Smith
49b06beedf [examples] Add Field2d to RamseteController example (#3371) 2021-05-21 22:28:29 -07:00
Tyler Veness
4c562a4457 [wpimath] Fix typo in comment of update_eigen.py (#3369)
NonMPL2.h clearly doesn't contain MPL2 code.
2021-05-21 21:39:33 -07:00
Tyler Veness
fdbbf11887 [wpimath] Add script for updating Eigen 2021-05-20 18:52:11 -07:00
Tyler Veness
f1e64b349a [wpimath] Move Eigen unsupported folder into eigeninclude
This fixes relative includes in development versions of Eigen.
2021-05-20 18:52:11 -07:00
Ryan Hirasaki
224f3a05cf [sim] Fix build error when building with GCC 11.1 (#3361) 2021-05-19 14:39:18 -07:00
Peter Johnson
ff56d6861d [wpilibj] Fix SpeedController deprecated warnings (#3360)
set() and other functions also need to be repeated on the MotorController
interface to avoid deprecation warnings from vscode.
2021-05-16 19:13:54 -07:00
sciencewhiz
1873fbefba [examples] Fix Swerve and Mecanum examples (#3359)
Fix encoder allocation and default command.
Fixes #3349
2021-05-15 21:39:00 -07:00
sciencewhiz
80b479e502 [examples] Fix SwerveBot example to use unique encoder ports (#3358)
Fixes #3089
2021-05-15 14:15:18 -07:00
PJ Reiniger
1f7c9adeeb [wpilibjExamples] Fix pose estimator examples (#3356) 2021-05-14 11:10:47 -07:00
Peter Johnson
9ebc3b058d [outlineviewer] Change default size to 600x400 (#3353) 2021-05-11 23:34:16 -07:00
Prateek Machiraju
e21b443a45 [build] Gradle: Make C++ examples runnable (#3348) 2021-05-11 19:54:53 -07:00
Peter Johnson
da590120c4 [wpilibj] Add MotorController.setVoltage default (#3347)
This avoids a vscode deprecation warning.
2021-05-11 19:53:55 -07:00
Peter Johnson
561d53885e [build] Update opencv to 4.5.2, imgui/implot to latest (#3344)
Also update native-utils to 2022.0.0 to start pulling 2022 artifacts.
2021-05-10 18:59:14 -07:00
Peter Johnson
44ad67ca8c [wpilibj] Preferences: Add missing Deprecated annotation (#3343) 2021-05-09 18:20:42 -07:00
Peter Johnson
3fe8fc75aa [wpilibc] Revert "Return reference from GetInstance" (#3342)
This reverts commit a79faace1b.

This change will be superseded in a non-breaking way by changing to static functions and deprecating GetInstance() entirely.
2021-05-09 18:16:07 -07:00
Peter Johnson
3cc2da3328 Merge branch '2022' 2021-05-09 14:15:40 -07:00
Tyler Veness
a3cd90dd71 [wpimath] Fix classpath used by generate_numbers.py (#3339) 2021-05-09 00:01:03 -07:00
Noam Zaks
d6cfdd3bae [wpilib] Preferences: Deprecate Put* in favor of Set* (#3337)
This naming is more consistent with other APIs.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-05-06 08:25:37 -07:00
Tyler Veness
ba08baabb9 [wpimath] Update Drake DARE solver to v0.29.0 (#3336)
This version incorporated the patch we were manually applying, so we're
synced back up with upstream now except for some minor #include changes
to reduce header bloat.
2021-05-05 09:16:55 -07:00
Tyler Veness
497b712f67 [wpilib] Make IterativeRobotBase::m_period private with getter 2021-05-04 13:41:36 -07:00
Tyler Veness
f00dfed7ac [wpilib] Remove IterativeRobot base class
TimedRobot supersedes it (see commit 81498e6 for reasoning).
2021-05-04 13:41:36 -07:00
Thad House
3c08461685 [hal] Use last error reporting instead of PARAMETER_OUT_OF_RANGE (#3328)
Makes the error messages much more specific to each error.
2021-05-01 13:22:08 -07:00
Tyler Veness
5ef2b4fdc0 [wpilibj] Fix @deprecated warning for SerialPort constructor (#3329)
The javadoc @deprecated tag didn't have corresponding @Deprecated
attribute.
2021-05-01 13:20:53 -07:00
Thad House
23d2326d1d [hal] Report previous allocation location for indexed resource duplicates (#3322) 2021-05-01 10:28:30 -07:00
Thad House
e338f9f190 [build] Fix wpilibc runCpp task (#3327) 2021-05-01 10:26:33 -07:00
Noam Zaks
c8ff626fe2 [wpimath] Move Java classes to edu.wpi.first.math (#3316) 2021-05-01 08:53:30 -07:00
Noam Zaks
4e424d51f4 [wpilibj] DifferentialDrivetrainSim: Rename constants to match the style guide (#3312) 2021-05-01 07:09:23 -07:00
Thad House
6b50323b07 [cscore] Use Lock2DSize if possible for Windows USB cameras (#3326)
Can remove a memory copy in many cases. This also fixes a bug where any mjpeg cameras on windows wouldn't work if the fast path was taken.
2021-05-01 07:07:37 -07:00
Tyler Veness
65c148536d [wpilibc] Fix "control reaches end of non-void function" warning (#3324) 2021-05-01 07:05:21 -07:00
Peter Johnson
f99f62bee4 [wpiutil] uv Handle: Use malloc/free instead of new/delete (#3325)
This avoids asan warnings for deleting a different pointer type.
2021-05-01 07:04:14 -07:00
Tyler Veness
365f5449ca [wpimath] Fix MecanumDriveKinematics (#3266) 2021-04-30 15:50:16 -07:00
Starlight220
ff52f207cc [glass, wpilib] Rewrite Mechanism2d (#3281)
Substantially improves Mechanism2d by moving it to NetworkTables and adding
a robot API to create the mechanism elements, instead of requiring a JSON file.

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2021-04-30 13:43:59 -07:00
Tyler Veness
ee0eed143a [wpimath] Add DCMotor factory function for Romi motors (#3319) 2021-04-29 09:59:35 -07:00
Thad House
5127380727 [hal] Add HAL_GetLastError to enable better error messages from HAL calls (#3320)
This uses thread local storage so a full error string can be provided, not just an error code.
2021-04-29 09:56:54 -07:00
Noam Zaks
ced654880c [glass, outlineviewer] Update Mac icons to macOS 11 style (#3313) 2021-04-25 17:30:45 -07:00
Peter Johnson
936d3b9f83 [templates] Add Java template for educational robot (#3309)
Educational robot is a very minimal template designed for educational use
(rather than competition).
2021-04-24 20:22:39 -07:00
Jeff Hutchison
6e31230adc [examples] Fix odometry update in SwerveControllerCommand example (#3310)
The Drive Subsystem was supplying an incorrectly constructed
Rotation2d to the odometry update method. Rotation2d constructor
was being called with heading in degrees, not radians as required.
2021-04-24 20:07:04 -07:00
Peter Johnson
05ebe93180 Merge branch 'main' into 2022 2021-04-19 18:45:31 -07:00
Prateek Machiraju
aaf24e2552 [wpilib] Fix initial heading behavior in HolonomicDriveController (#3290) 2021-04-18 21:00:11 -07:00
Peter Johnson
8d961dfd25 [wpilibc] Remove ErrorBase (#3306)
Replace with new exception-based error reporting, consistent with Java.
This also builds stacktraces into the reporting/exceptions.
2021-04-18 20:35:29 -07:00
Peter Johnson
659b37ef9d [wpiutil] StackTrace: Include offset on Linux (#3305) 2021-04-18 20:34:39 -07:00
Peter Johnson
0abf6c9045 [wpilib] Move motor controllers to motorcontrol package (#3302)
Also deprecate SpeedController in favor of motorcontrol.MotorController and
SpeedControllerGroup in favor of motorcontrol.MotorControllerGroup.

The MotorController interface is derived from the SpeedController interface
so that code such as SpeedController x = new VictorSP(1) continues to
compile (just with a warning).

SpeedControllerGroup and MotorControllerGroup are independent classes;
both implement the MotorController interface.
2021-04-17 11:27:16 -07:00
Tyler Veness
4630191fa4 [wpiutil] circular_buffer: Use value initialization instead of passing zero (#3303)
This enables use of types that have a no-args constructor rather than one that takes an explicit zero value.
For numeric types, value initialization will result in a zero value, so this is not a functional change.
2021-04-15 11:50:07 -07:00
Peter Johnson
b7b178f49c [wpilib] Remove Potentiometer interface 2021-04-13 22:40:55 -07:00
Peter Johnson
687066af3d [wpilib] Remove GyroBase 2021-04-13 22:40:55 -07:00
Peter Johnson
6b168ab0c8 [wpilib] Remove PIDController, PIDOutput, PIDSource
Move them to the old commands vendordep so that PIDCommand and PIDSubsystem
continue to work.

This also removes Filter and LinearDigitalFilter.
2021-04-13 22:40:55 -07:00
Tyler Veness
948625de9d [wpimath] Document conversion from filter cutoff frequency to time constant (#3299) 2021-04-12 11:12:52 -07:00
Modelmat
3848eb8b16 [wpilibc] Fix flywhel -> flywheel typo in FlywheelSim (#3298) 2021-04-12 11:12:04 -07:00
Peter Johnson
3abe0b9d49 [cscore] Move java package to edu.wpi.first.cscore (#3294)
This is more consistent with the other Java packages, and also is more
correct, as we own the first.wpi.edu domain but not the full wpi.edu domain.
2021-04-10 11:42:41 -07:00
Peter Johnson
d7fabe81fe [wpilib] Remove RobotDrive (#3295)
This has been deprecated for several years, and its functionality has been
completely superseded by other drive classes (DifferentialDrive et al).
2021-04-10 10:28:32 -07:00
Peter Johnson
1dc81669c2 [wpilib] Remove GearTooth (#3293)
This sensor has had zero usage for many years and was last in the KOP
over a decade ago.  There are much better rotation sensors available,
and it's no longer worth maintaining this class.
2021-04-10 10:28:05 -07:00
Peter Johnson
01d0e12603 [wpilib] Revert move of RomiGyro into main wpilibc/j (#3296)
This reverts commit 69e8d0b65d (#3143).

We haven't released a version with this yet, and plan to make a vendor
library instead.
2021-04-10 10:27:44 -07:00
Peter Johnson
397e569aaf [ntcore] Remove "using wpi" from nt namespace
This removes the nt::ArrayRef, nt::StringRef, and nt::Twine aliases.
2021-04-08 22:35:28 -07:00
Peter Johnson
79267f9e60 [ntcore] Remove NetworkTable -> nt::NetworkTable shim 2021-04-08 22:35:28 -07:00
Peter Johnson
48ebe5736a [ntcore] Remove deprecated Java interfaces and classes 2021-04-08 22:35:28 -07:00
Peter Johnson
c2064c78b2 [ntcore] Remove deprecated ITable interfaces 2021-04-08 22:35:28 -07:00
Peter Johnson
36608a283b [ntcore] Remove deprecated C++ APIs 2021-04-08 22:35:28 -07:00
Starlight220
a1c87e1e15 [glass] LogView: Add "copy to clipboard" button (#3274) 2021-04-06 13:19:49 -07:00
Prateek Machiraju
fa7240a501 [wpimath] Fix typo in quintic spline basis matrix 2021-04-03 16:03:38 -07:00
Prateek Machiraju
ffb4d38e24 [wpimath] Add derivation for spline basis matrices 2021-04-03 16:03:38 -07:00
Starlight220
f57c188f2e [wpilib] Add AnalogEncoder(int) ctor (#3273) 2021-04-02 08:26:41 -07:00
Prateek Machiraju
8471c4fb26 [wpilib] FieldObject2d: Add setTrajectory() method (#3277) 2021-04-01 22:08:07 -07:00
Peter Johnson
c97acd18e7 [glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability

Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
Prateek Machiraju
ffb590bfcc [wpilib] Fix Compressor sendable properties (#3269) 2021-03-26 21:20:54 -07:00
Peter Johnson
6137f98eb5 [hal] Rename SimValueCallback2 to SimValueCallback (#3212) 2021-03-21 23:22:04 -07:00
Peter Johnson
a6f6539691 [hal] Move registerSimPeriodic functions to HAL package (#3211)
This enables the static lists to be private.
2021-03-21 23:21:47 -07:00
Peter Johnson
10c038d9bf [glass] Plot: Fix window creation after removal (#3264)
Previously the following sequence was broken:
- Add two plot windows (creates Plot<0> and Plot<1>)
- Delete Plot<0>
- Try to create a plot window

This failed because it would try to create Plot<1>, which already existed.
It was necessary to also destroy Plot<1> before another plot could be added.

This change fixes this case by trying all 0-N cases.
2021-03-21 18:06:18 -07:00
Peter Johnson
2d2eaa3eff [wpigui] Ensure window will be initially visible (#3256)
Only set the initial window position if the window X/Y postion is within one
of the connected monitor work areas.
2021-03-21 12:39:33 -07:00
Prateek Machiraju
4d28b1f0cd [wpimath] Use JNI for trajectory serialization (#3257) 2021-03-21 12:38:23 -07:00
Peter Johnson
3de800a607 [wpimath] TrajectoryUtil.h: Comment formatting (NFC) (#3262) 2021-03-21 11:40:15 -07:00
Peter Johnson
eff5923778 [glass] Plot: Don't overwrite series ID (#3260) 2021-03-21 11:14:25 -07:00
Peter Johnson
a79faace1b [wpilibc] Return reference from GetInstance (#3247)
Improves consistency across all classes.

Affects Preferences, LiveWindow, and CameraServer.

Old commands Scheduler::GetInstance() was not updated as this is already
deprecated.
2021-03-21 11:13:49 -07:00
Peter Johnson
9550777b9d [wpilib] PWMSpeedController: Use PWM by composition (#3248)
This cleans up the user experience by removing lower-level functions from the
interface.

Also remove MotorSafety from "raw" PWM.
2021-03-21 11:12:49 -07:00
Peter Johnson
c8521a3c33 [glass] Plot: Set reasonable default window size (#3261) 2021-03-21 10:50:41 -07:00
Peter Johnson
d71eb2cf39 [glass] Plot: Show full source name as tooltip and in popup (#3255) 2021-03-20 20:59:31 -07:00
Peter Johnson
160fb740f4 [hal] Use std::lround() instead of adding 0.5 and truncating (#3012) 2021-03-19 14:24:46 -07:00
Peter Johnson
48e9f39513 [wpilibj] Remove wpilibj package CameraServer (#3213) 2021-03-19 13:51:53 -07:00
Peter Johnson
8afa596fdf [wpilib] Remove deprecated Sendable functions and SendableBase (#3210) 2021-03-19 13:41:11 -07:00
Prateek Machiraju
d3e45c297c [wpimath] Make C++ geometry classes immutable (#3249) 2021-03-19 13:38:54 -07:00
Peter Johnson
2c98939c18 [glass] StringChooser: Don't call SameLine() at end 2021-03-19 13:15:26 -07:00
Peter Johnson
a18a7409fb [glass] NTStringChooser: Clear value of deleted entries 2021-03-19 13:15:26 -07:00
Peter Johnson
2f19cf4524 [glass] NetworkTablesHelper: listen to delete events 2021-03-19 13:15:26 -07:00
Peter Johnson
da96707dca Merge branch 'main' into 2022 2021-03-19 09:22:02 -07:00
Peter Johnson
c3a8bdc240 [build] Fix clang-tidy action (#3246)
Manually install python3.8, as actions/setup-python now needs Ubuntu 20.04.
2021-03-19 08:59:14 -07:00
Peter Johnson
21624ef273 Add ImGui OutlineViewer (#3220) 2021-03-16 22:05:41 -07:00
Peter Johnson
1032c9b917 [wpiutil] Unbreak wpi::Format on Windows (#3242)
This function relies on the behavior of snprintf returning an error value
when the buffer is too small.  By default, _snprintf_s aborts on Windows
instead of returning an error value.

This caused Glass to fail when trying to print a large NT value to a string.
2021-03-16 22:04:55 -07:00
Peter Johnson
2e07902d76 [glass] NTField2D: Fix name lookup (#3233)
This was causing incorrect detection of duplicate names.
2021-03-12 16:54:26 -08:00
Peter Johnson
6e23e1840a [wpilibc] Remove WPILib.h (#3235)
It's been deprecated for several years, is often broken as it's not tested
frequently, and dramatically increases compile times.
2021-03-12 15:58:47 -08:00
Prateek Machiraju
3e22e45066 [wpilib] Make KoP drivetrain simulation weight 60 lbs (#3228) 2021-03-07 22:54:40 -08:00
Peter Johnson
79d1bd6c8f [glass] NetworkTablesSetting: Allow disable of server option (#3227) 2021-03-07 21:24:59 -08:00
Prateek Machiraju
fe341a16f5 [examples] Use more logical elevator setpoints in GearsBot (#3198) 2021-03-07 16:00:00 -08:00
Peter Johnson
62abf46b3f [glass] NetworkTablesSettings: Don't block GUI (#3226)
On some systems, StopClient et al can take a long time to execute.
Instead run these on a separate thread to avoid blocking the GUI.

Also add option to get IP from DS (default on).
2021-03-07 15:40:05 -08:00
Peter Johnson
a95a5e0d9b [glass] Move NetworkTablesSettings to libglassnt (#3224) 2021-03-06 22:19:00 -08:00
Prateek Machiraju
d6f6ceaba5 [build] Run Spotless formatter (NFC) (#3221)
The original PR (#2934) was created before we moved to Spotless so the
formatting check was never run.
2021-03-04 08:24:05 -08:00
Blake Bourque
0922f8af59 [commands] CommandScheduler.requiring(): Note return can be null (NFC) (#2934) 2021-03-03 23:56:57 -08:00
Prateek Machiraju
6812302ff9 [examples] Make DriveDistanceOffboard example work in sim (#3199)
Adds some basic functionality to the ExampleMotorController so that
controller inputs show up in LiveWindow widgets in simulation.
2021-03-03 23:38:13 -08:00
Prateek Machiraju
f3f86b8e78 [wpimath] Add pose estimator overload for vision + std dev measurement (#3200) 2021-03-03 23:37:18 -08:00
Matt Soucy
1a2680b9e5 [wpilibj] Change CommandBase.withName() to return CommandBase (#3209)
Doing this retains the Sendable portion of the type.
2021-03-03 23:35:37 -08:00
Starlight220
435bbb6a8c [command] RamseteCommand: Output 0 if interrupted (#3216) 2021-02-28 22:06:34 -08:00
Tyler Veness
3cf44e0a53 [hal] Add function for changing HAL Notifier thread priority (#3218) 2021-02-28 22:05:26 -08:00
Prateek Machiraju
40b367513f [wpimath] Units.java: Add kg-lb conversions (#3203) 2021-02-27 10:12:41 -08:00
Prateek Machiraju
9f563d584a [glass] NT: Fix return value in StringToDoubleArray (#3208) 2021-02-26 08:43:12 -08:00
Peter Johnson
af4adf5379 [glass] Auto-size plots to fit window (#3193)
Plots can still be set to have a fixed height, in which case the remaining
space is distributed amongst the auto-sized plots.
2021-02-21 16:38:06 -08:00
Peter Johnson
2560146da3 [sim] GUI: Add option to show prefix in Other Devices (#3186)
Also disable rename popup for this window.
2021-02-21 16:35:49 -08:00
Peter Johnson
eae3a6397a gitignore: Ignore .cache directory (#3196)
This is used by newer clangd versions.
2021-02-21 16:35:01 -08:00
Starlight220
959611420b [wpilib] Require non-zero positive value for PIDController.period (#3175) 2021-02-16 18:07:29 -08:00
Prateek Machiraju
9522f2e8c7 [wpimath] Add methods to concatenate trajectories (#3139)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-02-16 18:06:36 -08:00
Zachary Orr
e42a0b6cf0 [wpimath] Rotation2d comment formatting (NFC) (#3162) 2021-02-16 18:06:01 -08:00
Claudius Tewari
d1c7032dec [wpimath] Fix order of setting gyro offset in pose estimators (#3176)
The gyro offset should be determined from the desired initial pose, not the current pose. This fix reflects the behavior of the odometry classes and the C++ holonomic pose estimators.
2021-02-16 18:04:38 -08:00
Starlight220
d241bc81ae [sim] Add DoubleSolenoidSim and SolenoidSim classes (#3177) 2021-02-16 18:03:57 -08:00
Tyler Veness
cb7f39afa1 [wpilibc] Add RobotController::GetBatteryVoltage() to C++ (#3179)
This function already exists in Java.
2021-02-16 18:03:25 -08:00
Thad House
99b5ad9ebb [wpilibj] Fix warnings that are not unused variables or deprecation (#3161)
Fix all warnings given by intellisense that are not unused variables or deprecation.
2021-02-12 22:22:11 -08:00
Thad House
c14b237757 [build] Fixup doxygen generated include dirs to match what users would need (#3154) 2021-02-12 22:17:39 -08:00
Starlight220
d447c7dc32 [sim] Add SimDeviceSim ctor overloads (#3134)
Better parallelism with SimDevice.create(), so teams don't have to mess with concatenating the index/channel themselves.
2021-02-12 22:17:13 -08:00
Austin Shalit
247420c9c1 [build] Remove jcenter repo (#3157) 2021-02-12 22:15:52 -08:00
Peter Johnson
04b112e004 [build] Include debug info in plugin published artifacts (#3149) 2021-02-12 22:15:16 -08:00
Prateek Machiraju
be0ce99007 [examples] Use PWMSparkMax instead of PWMVictorSPX (#3156)
This accurately reflects the motor controllers that are distributed in
the Kit of Parts.
2021-02-12 22:14:56 -08:00
Zhiquan Yeo
69e8d0b65d [wpilib] Move RomiGyro into main wpilibc/j (#3143) 2021-02-12 22:14:29 -08:00
Tyler Veness
94e685e1bd [wpimath] Add custom residual support to EKF (#3148)
Fixes #3145.

Co-authored-by: Declan Freeman-Gleason <declanfreemangleason@gmail.com>
2021-02-12 22:13:36 -08:00
Peter Johnson
5899f3dd28 [sim] GUI: Make keyboard settings loading more robust (#3167)
Check values during load and operation to avoid potential crashes due to
ini file errors or corruption.
2021-02-12 22:12:20 -08:00
Prateek Machiraju
f82aa1d564 [wpilib] Fix HolonomicDriveController atReference() behavior (#3163)
The atReference() method previously used the rotation error between the
desired trajectory state and the current pose. This was a bug because we
allow teams to use custom rotation setpoints and that wasn't being taken
into account.
2021-02-12 22:11:57 -08:00
Tyler Veness
fe5c2cf4b7 [wpimath] Remove ControllerUtil.java (#3169)
This was already removed from C++ in the offseason and replaced with
MathUtil.inputModulus(). We just neglected to do that for Java; it was
never intended to see a season release. Its implementation is incorrect
compared to inputModulus() as well.

See https://github.com/wpilibsuite/allwpilib/issues/3168 for discussion.
2021-02-12 22:10:58 -08:00
Thad House
43d40c6e9e [wpiutil] Suppress unchecked cast in CombinedRuntimeLoader (#3155)
Because of Java's type system, it is actually literally impossible to check for this cast at runtime. So instead, the only option is to suppress it. Only suppressed for the specific function.
2021-02-07 08:20:33 -08:00
Tyler Veness
3d44d8f79c [wpimath] Fix argument order in UKF docs (NFC) (#3147) 2021-02-01 23:36:32 -08:00
Peter Johnson
ba6fe8ff2e [cscore] Add USB camera change event (#3123) 2021-01-31 18:52:48 -08:00
Peter Johnson
5337258888 [build] Tweak OpenCV cmake search paths to work better on Linux (#3144)
With this change, cmake finds OpenCV Java on Ubuntu with no additional search options.
2021-01-31 18:52:21 -08:00
Peter Johnson
29bf9d6ef1 [cscore] Add polled support to listener
Change Java VideoListener to use polling.
2021-01-31 17:06:37 -08:00
Peter Johnson
483beb6361 [ntcore] Move CallbackManager to wpiutil 2021-01-31 17:06:37 -08:00
Prateek Machiraju
fdaec77594 [examples] Instantiate m_ramseteController in example (#3142) 2021-01-31 17:04:16 -08:00
Peter Johnson
8494a5761b Rename default branch to main (#3140) 2021-01-30 13:46:56 -08:00
Prateek Machiraju
45590eea22 [wpigui] Hardcode window scale to 1 on macOS (#3135)
This fixes an issue with scaling on Retina displays where the frame
buffer size was double that of the window size, resulting in a content
scale factor of 2. This scale factor caused elements to appear too
large, even on the smallest zoom setting.

This change does not affect external monitors on macOS because the
reported content scale was 1 anyway.
2021-01-28 21:52:13 -08:00
Prateek Machiraju
834a64920b [build] Publish libglass and libglassnt to Maven (#3127) 2021-01-25 21:42:38 -08:00
Tyler Veness
2c2ccb3618 [wpimath] Fix Rotation2d equality operator (#3128) 2021-01-25 21:41:34 -08:00
Prateek Machiraju
fb5c8c39ae [wpigui] clang-tidy: readability-braces-around-statements 2021-01-25 09:25:39 -08:00
Prateek Machiraju
f7d39193a4 [wpigui] Fix copyright in pfd and wpigui_metal.mm 2021-01-25 09:25:39 -08:00
Tyler Veness
aec796b212 [ntcore] Fix conditional jump on uninitialized value (#3125)
`m_last_flush` should be initialized before it's used at
Dispatcher.cpp:243.
2021-01-25 08:15:08 -08:00
Peter Johnson
fb13bb2393 [sim] GUI: Add right click popup for keyboard joystick settings (#3119) 2021-01-23 09:10:58 -08:00
Prateek Machiraju
c517ec6779 [build] Update thirdparty-imgui to 1.79-2 (#3118) 2021-01-22 19:48:49 -08:00
David Vo
e8cbf2a717 [wpimath] Fix typo in SwerveDrivePoseEstimator doc (NFC) (#3112) 2021-01-21 09:31:37 -08:00
Prateek Machiraju
e9c86df468 [wpimath] Add tests for swerve module optimization (#3100) 2021-01-20 20:44:37 -08:00
Modelmat
6ba8c289c5 [examples] Remove negative of ArcadeDrive(fwd, ..) in the C++ Getting Started Example (#3102) 2021-01-20 20:43:34 -08:00
Peter Johnson
3f1672e89f [hal] Add SimDevice createInt() and createLong() (#3110) 2021-01-20 20:42:39 -08:00
Prateek Machiraju
15be5cbf1f [examples] Fix segfault in GearsBot C++ example (#3111)
This fixes a dangling this pointer in the DriveStraight and
SetDistanceToBox commands by directly capturing the
drivetrain pointer by value instead.
2021-01-20 20:38:45 -08:00
Evan Pratten
4cf0e5e6db Add quick links to API documentation in README (#3082) 2021-01-19 23:00:54 -08:00
Tyler Veness
6b1898f12e Fix RT priority docs (NFC) (#3098)
The ranges and which value was specified as highest were incorrect on
some of them. On Linux, the range is 1 to 99 with 99 being highest.

From `man 7 sched`:
```
Processes scheduled under one of the real-time policies (SCHED_FIFO,
SCHED_RR) have a sched_priority value in the range 1 (low) to 99 (high).
```

Also clean up the relevant javadoc and doxygen comments.
2021-01-19 22:59:18 -08:00
David Vo
b3426e9c0d [wpimath] Fix missing whitespace in pose estimator doc (#3097) 2021-01-19 22:58:08 -08:00
Modelmat
38c1a1f3e0 [examples] Fix feildRelative -> fieldRelative typo in XControllerCommand examples (#3104)
* MecanumControllerCommand
* SwerveControllerCommand
2021-01-19 22:57:41 -08:00
Peter Johnson
4488e25f16 [glass] Shorten SmartDashboard window names (#3096)
Instead of "/SmartDashboard/name" they now default to "name (SmartDashboard)".
This allows for smaller windows while preserving the name without requiring
user customization.
2021-01-17 20:33:42 -08:00
CoolSpy3
cfdb3058ee [wpilibj] Update SimDeviceSimTest (#3095) 2021-01-17 13:48:25 -08:00
Mark Vedder
64adff5fea [examples] Fix typo in ArcadeDrive constructor parameter name (#3092)
Removed extra 'p' in "Supplier" in the parameter name `zaxisRotateSuppplier` of the  ArcadeDrive constructor of the Romi Reference example.
2021-01-16 20:27:29 -08:00
Thad House
6efc58e3db [build] Fix issues with build on windows, deprecations, and native utils (#3090) 2021-01-16 20:26:52 -08:00
Tyler Veness
f393989a5b [wpimath, wpiutil] Add wpi::array for compile time size checking (#3087)
The wpimath APIs use std::array, which doesn't do size checking. Passing
an array with the wrong size can result in uninitialized elements
instead of a compilation error.

This is a breaking change but is worthwhile to avoid hard-to-debug errors.
2021-01-16 20:26:17 -08:00
Prateek Machiraju
d6ed20c1e4 [build] Set macOS deployment target to 10.14 (#3088) 2021-01-14 21:20:38 -08:00
Tyler Veness
7c524014c8 [hal] Add [[nodiscard]] to HAL_WaitForNotifierAlarm() (#3085)
As this is a C-compatible header, add a WPI_NODISCARD macro for
compiler-specific C-compatible nodiscard attributes.
2021-01-14 20:00:55 -08:00
Matt
406d055f07 [wpilib] Fixup wouldHitLowerLimit in elevator and arm simulation classes. (#3076)
Closes #3050.
2021-01-14 00:28:00 -08:00
sciencewhiz
04a90b5dd1 [examples] Don't continually set setpoint in PotentiometerPID Examples (#3084) 2021-01-13 20:09:08 -08:00
Prateek Machiraju
8c5bfa0132 [sim] GUI: Add max value setting for keyboard joysticks (#3083) 2021-01-12 19:57:04 -08:00
Peter Johnson
bc80c55353 [hal] Add SimValue reset() function (#3064)
This enables correct behavior for resetting incremental sensor values like
encoder counts or gyro accumulated angle with WebSockets.
2021-01-12 00:38:58 -08:00
Peter Johnson
9c3b51ca0f [wpilib] Document simulation APIs (#3079)
- Remove sim checkstyle suppression
- Add [[nodiscard]] to C++ register callback functions
- Add a couple of missing sim functions

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: Starlight220 <yotamshlomi@gmail.com>
2021-01-11 21:55:45 -08:00
Prateek Machiraju
26584ff145 [wpimath] Add model description to LinearSystemId Javadocs (#3080) 2021-01-11 20:08:55 -08:00
Prateek Machiraju
42c3d52863 [examples] Sync Java and C++ trajectories in sim example (#3081)
This also shifts the trajectory up and to the right so that the robot is
always visible in the Field GUI during traversal. Some drive constants
and trajectory constraints were also synced between the two languages.
2021-01-11 20:08:22 -08:00
Dustin Spicuzza
64e72f7103 [wpilibc] Add missing function RoboRioSim::ResetData (#3073) 2021-01-10 22:50:25 -08:00
Matt
e955037980 [wpimath] Add optimize() to SwerveModuleState (#3065)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-01-10 22:49:46 -08:00
Peter Johnson
fb99910c23 [hal] Add SimInt and SimLong wrappers for int/long SimValue (#3066) 2021-01-09 23:26:19 -08:00
CoolSpy3
e620bd4d3f [doc] Add machine-readable websocket specification (#3059)
Co-authored-by: Vasista Vovveti <vasistavovveti@gmail.com>
2021-01-09 23:24:57 -08:00
Peter Johnson
a44e761d9e [glass] Add support for plot Y axis labels 2021-01-08 11:37:35 -08:00
Peter Johnson
ea1974d576 [wpigui] Update imgui and implot to latest 2021-01-08 11:37:35 -08:00
Matt
85a0bd43c2 [wpimath] Add RKF45 integration (#3047)
This is more stable than Runge-Kutta for systems with large elements in their A or B matrices.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2021-01-06 21:40:25 -08:00
Prateek Machiraju
278e0f126e [glass] Use .controllable to set widgets' read-only state (#3035)
This modifies the mecanum drive, differential drive, speed controller,
and PID controller widgets to only be writeable when .controllable is
set to true.
2021-01-05 18:33:05 -08:00
Tyler Veness
d8652cfd4f [wpimath] Make Java DCMotor API consistent with C++ and fix motor calcs (#3046)
The stall torque, stall current, and free current are now multiplied by
the number of motors instead of just the stall torque. This produces the
same values for Kt and Kv regardless of the number of motors; the motor
resistance still affects the system response.

For an elevator model, the response should be the same as before since a
factor of "number of motors" shows up in the same place in the
acceleration calculation, but the current calculation will also be
correct now.
2021-01-05 18:28:57 -08:00
Peter Johnson
377b7065aa [build] Add toggleOffOn to Java spotless (#3053)
This allows custom formatting where desired (e.g. of table values).

Also upgrade spotless to 5.5.0.
2021-01-05 17:56:45 -08:00
Prateek Machiraju
1e9c79c587 [sim] Use plant output to retrieve simulated position (#3043)
Using the plant output means that measurement noise can be incorporated.
SingleJointedArmSim (in C++ and Java) and ElevatorSim (in C++) used the
state instead of the measurement.

Closes #3042
2021-01-05 17:55:44 -08:00
Peter Johnson
78147aa342 [sim] GUI: Fix Keyboard Joystick (#3052)
This was broken by #3010.

Also fix a few unknown key cases and a nullptr return that could cause a crash.
2021-01-05 17:55:11 -08:00
Peter Johnson
cd4a2265b9 [ntcore] Fix NetworkTableEntry::GetRaw() (#3051)
It was calling value->GetString() instead of GetRaw(), which would assert.
2021-01-04 22:07:50 -08:00
Austin Shalit
767ac1de10 [build] Use deploy key for doc publish (#3048)
This allows us to limit the scope of personal access tokens
2021-01-04 15:21:47 -08:00
Austin Shalit
d762215d13 [build] Add publish documentation script (#3040) 2021-01-04 13:59:19 -08:00
sciencewhiz
1fd09593cf [examples] Add missing TestInit method to GettingStarted Example (#3039) 2021-01-02 22:00:25 -08:00
Zhiquan Yeo
e45a0f6ce2 [examples] Add RomiGyro to the Romi Reference example (#3037) 2021-01-02 21:59:57 -08:00
sciencewhiz
94f8525721 Update imaging link and fix typo (#3038) 2021-01-02 19:57:39 -08:00
Zhiquan Yeo
d73cf64e54 [examples] Update RomiReference to match motor directions (#3036)
Flip the TeleopArcadeDrive axis directions so that positive
values for x-axis speed result in the Romi driving forward (in the
direction of the Raspberry Pi USB ports).
2021-01-02 17:21:07 -08:00
Peter Johnson
f945462bab Bump copyright year to 2021 (#3033) 2021-01-01 21:54:00 -08:00
Tyler Veness
b05946175b [wpimath] Catch Drake JNI exceptions and rethrow them (#3032)
This gives an informative error in Java instead of crashing the JVM.
2021-01-01 17:09:50 -08:00
Tyler Veness
62f0f8190d [wpimath] Deduplicate angle modulus functions (#2998)
frc::NormalizeAngle(), units::math::NormalizeAngle(), and
frc::GetModulusError() were replaced with frc::InputModulus() and
frc::AngleModulus().

They were placed in wpimath/src/main/native/include/frc/MathUtil.h for
C++ and wpimath/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java
for Java.
2021-01-01 16:22:00 -08:00
Prateek Machiraju
bf8c0da4be [glass] Add "About" popup with version number (#3031) 2021-01-01 15:59:00 -08:00
Prateek Machiraju
dfdd6b3891 [build] Increase Gradle heap size in Gazebo build (#3028)
Builds have been intermittently failing due to Gradle running out of memory.
2021-01-01 10:29:55 -08:00
Peter Johnson
f5e0fc3e9a Finish clang-tidy cleanups (#3003)
* Add .clang-tidy configuration.
* A separate .clang-tidy is used for hal includes to suppress modernize-use-using
  (as these are C headers).
* Add NOLINT where necessary for a clean run.
* Add clang-tidy job to lint-format workflow.  This workflow is now only run on PRs.
  To reduce runtime, clang-tidy is only run on files changed in the PR.

Two wpilibc changes; both are unlikely to break user code:
* BuiltInAccelerometer: Make SetRange() final
* Counter: Make SetMaxPeriod() final

After these cleanups, the only file that does not run cleanly is
cscore_raw_cv.h due to it not being standalone.
2021-01-01 10:27:49 -08:00
Peter Johnson
d741101fe3 [sim] Revert accidental commit of WSProvider_PDP.h (#3027) 2021-01-01 00:44:31 -08:00
Starlight220
e1620799c7 [examples] Add C++ RomiReference example (#2969)
Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
Co-authored-by: sciencewhiz <sciencewhiz@users.noreply.github.com>
2020-12-31 20:37:20 -08:00
Prateek Machiraju
749c7adb13 [command] Fix use-after-free in CommandScheduler (#3024) 2020-12-31 20:35:17 -08:00
Peter Johnson
921a733911 [sim] Add WS providers for AddressableLED, PCM, and Solenoid (#3026)
Co-authored-by: PJ Reiniger <pj.reiniger@gmail.com>
2020-12-31 20:34:34 -08:00
Austin Shalit
26d0004fe1 [build] Split Actions into different yml files (#3025) 2020-12-31 20:33:39 -08:00
Austin Shalit
948af6d5b5 [wpilib] PWMSpeedController.get(): Apply Inversion (#3016)
This makes get() return the value actually sent to the motor.

This is a breaking change.
2020-12-31 14:35:10 -08:00
Peter Johnson
670a187a3c [wpilibc] SuppliedValueWidget.h: Forward declare ShuffleboardContainer (#3021)
This is needed to break the include loop between SuppliedValueWidget.h and ShuffleboardContainer.h.
2020-12-31 12:35:56 -08:00
Peter Johnson
be9f725023 [ntcore] NetworkTableValue: Use std::forward instead of std::move (#3022)
Because these are forwarding references, they could unexpectedly move a
passed lvalue.  Using std::forward() makes a copy if an lvalue is passed.
2020-12-31 12:35:02 -08:00
Peter Johnson
daf3f4cb1a [cscore] cscore_raw_cv.h: Fix error in PutFrame() (#3019) 2020-12-31 12:34:37 -08:00
Peter Johnson
5acda4cc71 [wpimath] ElevatorFeedforward.h: Add time.h include 2020-12-31 12:18:06 -08:00
Peter Johnson
8452af606b [wpimath] units/radiation.h: Add mass.h include 2020-12-31 12:18:06 -08:00
Peter Johnson
630d449520 [hal] ErrorsInternal.h: Add stdint.h include 2020-12-31 12:18:06 -08:00
Peter Johnson
7372cf7d99 [cscore] Windows NetworkUtil.cpp: Add missing include 2020-12-31 12:18:06 -08:00
Peter Johnson
b7e46c558f Include .h from .inc/.inl files (NFC) (#3017)
This helps both IDEs and linting tools.

Also add some missing braces.
2020-12-31 11:26:53 -08:00
jpokornyiii
bf8f8710ea [examples] Update Romi template and example (#2996)
Updated the RomiReference example to have autonomous example.
Updated RomiReference and both Romi templates to use Encoder.getDistance().
Removed motor inversion.
2020-12-30 22:45:04 -08:00
Austin Shalit
6ffe5b775d [glass] Ensure NetworkTableTree parent context menu has an id (#3015) 2020-12-30 22:43:35 -08:00
Austin Shalit
be0805b85b [build] Update to WPILibVersioningPlugin 4.1.0 (#3014) 2020-12-30 22:40:38 -08:00
Austin Shalit
65b2359b27 [build] Add spotless for other files (#3007)
Adds spotless formatting for Gradle, xml, md, and gitignore files.

yml linting is not performed as it requires a dependency on npm.
2020-12-30 16:17:20 -08:00
Prateek Machiraju
8651aa73e8 [examples] Enable NT Flush in Field2d examples (#3013) 2020-12-30 16:12:15 -08:00
Austin Shalit
78b542737a [build] Add Gazebo build to Actions CI (#3004) 2020-12-30 11:38:49 -08:00
Peter Johnson
fccf86532f [sim] DriverStationGui: Fix two bugs (#3010)
- Slicing of GlfwKeyboardJoystick
- Potential null pointer deref
2020-12-30 11:37:54 -08:00
Peter Johnson
1857417601 [sim] WSProvider_Joystick: Fix off-by-1 in incoming buttons (#3011) 2020-12-30 11:37:20 -08:00
Prateek Machiraju
ee7114a58c [glass] Add drive class widgets (#2975)
This adds widgets for DifferentialDrive and MecanumDrive.
2020-12-30 08:51:55 -08:00
Prateek Machiraju
00fa91d0d6 [glass] Use ImGui style for gyro widget colors (#3009)
This ensures that the colors are properly visible in light mode or any
other custom user styles.
2020-12-30 08:42:26 -08:00
Peter Johnson
b7a25bfc33 ThirdPartyNotices: Add portable file dialogs license (#3005) 2020-12-29 22:46:44 -08:00
Austin Shalit
a2e46b9a1b [glass] modernize-use-nullptr (NFC) (#3006) 2020-12-29 22:46:11 -08:00
Peter Johnson
a751fa22d2 [build] Apply spotless for java formatting (#1768)
Update checkstyle config to be compatible with spotless.

Co-authored-by: Austin Shalit <austinshalit@gmail.com>
2020-12-29 22:45:16 -08:00
Tyler Veness
e563a0b7db [wpimath] Make LinearSystemLoop move-constructible and move-assignable (#2967) 2020-12-29 20:50:26 -08:00
Austin Shalit
49085ca943 [glass] Add context menus to remove and add NetworkTables values (#2979) 2020-12-29 20:49:29 -08:00
Peter Johnson
560a850a2b [glass] Add NetworkTables Log window (#2997)
This moves NetworkTable log messages out of the console (which is hidden on some platforms).
2020-12-29 20:47:58 -08:00
PJ Reiniger
66782e2317 [sim] Create Left/Right drivetrain current accessors (#3001) 2020-12-29 20:46:51 -08:00
Peter Johnson
b60eb1544b clang-tidy: bugprone-virtual-near-miss
A few virtual functions are called by constructors or destructors, which is
dangerous in C++ (as an overridden virtual impl won't be called, only the
one in the current class).  Fix by either marking the function final or
not calling at all (if possible).
2020-12-29 14:26:19 -08:00
Peter Johnson
cbe59fa3bf clang-tidy: google-explicit-constructor 2020-12-29 14:26:19 -08:00
Peter Johnson
c97c6dc065 clang-tidy: google-readability-casting (NFC) 2020-12-29 14:26:19 -08:00
Peter Johnson
32fa97d68d clang-tidy: modernize-use-nullptr (NFC) 2020-12-29 14:26:19 -08:00
Peter Johnson
aee4603269 clang-tidy: modernize-pass-by-value 2020-12-29 14:26:19 -08:00
Peter Johnson
29c7da5f1a clang-tidy: modernize-make-unique 2020-12-29 14:26:19 -08:00
Peter Johnson
6131f4e32b clang-tidy: modernize-concat-nested-namespaces (NFC) 2020-12-29 14:26:19 -08:00
Peter Johnson
67e03e625d clang-tidy: modernize-use-equals-default 2020-12-29 14:26:19 -08:00
Peter Johnson
b124f9101b clang-tidy: modernize-use-default-member-init 2020-12-29 14:26:19 -08:00
Peter Johnson
d11a3a6380 clang-tidy: modernize-use-override (NFC)
Add NOLINT to CommandTestBase due to gmock not adding "override" keyword,
which causes warnings on clang.
2020-12-29 14:26:19 -08:00
Peter Johnson
4cc0706b06 clang-tidy: modernize-use-using (NFC)
Excludes C-compatible headers
2020-12-29 14:26:19 -08:00
Tyler Veness
885f5a9781 [wpilibc] Speed up ScopedTracerTest (#2999)
ScopedTracerTest now uses simulation time instead of wall clock time, so
it doesn't have to actually wait 1.5 seconds.
2020-12-29 10:30:23 -08:00
sciencewhiz
60b5964577 [wpilibj] Fix typos (NFC) (#3000) 2020-12-29 10:29:39 -08:00
Austin Shalit
6e1919414e [build] Bring naming checkstyle rules up to date with Google Style guide (#1781)
Also update Checkstyle to 8.38.

Google changed their style guide from the last time we imported it. This PR brings in those naming changes. The change they made is allowing single letter member, parameter, and local variable names. They also added a lambda naming scheme and I thought it would be good to bring that in too.
2020-12-29 09:27:48 -08:00
Tyler Veness
8c8ec5e63e [wpilibj] Suppress unchecked cast warnings (#2995) 2020-12-28 17:13:34 -08:00
Peter Johnson
b8413ddd5b [wpiutil] Add noexcept to timestamp static functions (#2994)
This silences a clang-tidy warning.
2020-12-28 17:12:51 -08:00
Austin Shalit
5d976b6e18 [glass] Load NetworkTableView settings on first draw (#2993)
Before this change, user settings were not loaded until after the first time they opened the settings context menu.
2020-12-28 15:29:25 -08:00
Tyler Veness
2b4317452b Replace NOLINT(runtime/explicit) comments with NOLINT (NFC) (#2992)
cpplint.py can accept either, but clang-tidy requires NOLINT.
2020-12-28 15:10:31 -08:00
Peter Johnson
1c3011ba4b [glass] Fix handling of "/" NetworkTables key (#2991) 2020-12-28 14:36:30 -08:00
Peter Johnson
574a42f3b4 [hal] Fix UnsafeManipulateDIO status check (#2987) 2020-12-28 13:04:21 -08:00
Matt
9005cd59e5 [wpilib] Clamp input voltage in sim classes (#2955) 2020-12-28 13:03:31 -08:00
Peter Johnson
dd494d4ab7 [glass] NetworkTablesModel::Update(): Avoid use-after-move (#2988) 2020-12-28 13:02:24 -08:00
Peter Johnson
7cca469a12 [wpimath] NormalizeAngle: Make inline, remove unnamed namespace (#2986) 2020-12-28 13:00:26 -08:00
Peter Johnson
2aed432b4b Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
2020-12-28 12:58:06 -08:00
Peter Johnson
0291a3ff56 [wpiutil] StringRef: Add noexcept to several constructors (#2984) 2020-12-28 11:34:50 -08:00
Peter Johnson
5d7315280a [wpimath] Update UnitsTest.cpp copyright (#2985) 2020-12-28 10:40:20 -08:00
Matt
254931b9a8 [wpimath] Remove LinearSystem from LinearSystemLoop (#2968)
The system wasn't being used internally, and as LinearSystem is stateless, it doesn't need to be held by LinearSystemLoop.
2020-12-28 10:35:51 -08:00
Prateek Machiraju
aa89744c95 Update OtherVersions.md to include wpimath info (#2983)
This also updates occurrences of 2020 to 2021.
2020-12-28 10:34:19 -08:00
Peter Johnson
1cda3f5ad7 [glass] Fix styleguide (#2976) 2020-12-26 14:31:24 -08:00
Peter Johnson
8f1f64ffb6 Remove year from file copyright message (NFC) (#2972)
Also update copyright to include "and other WPILib contributors" and clarify
license referral language to not be restricted to FIRST teams.
2020-12-26 14:12:05 -08:00
Peter Johnson
2bc0a7795c [examples] Fix wpiformat warning about utility include (#2971) 2020-12-26 09:34:21 -08:00
Peter Johnson
4204da6ad4 [glass] Add application icon 2020-12-25 22:08:37 -08:00
Peter Johnson
7ac39b10f7 [wpigui] Add icon support 2020-12-25 22:08:37 -08:00
Matt
6b567e0066 [wpimath] Add support for varying vision standard deviations in pose estimators (#2956)
Exposes the R passed to vision correct to users.
2020-12-24 16:05:07 -08:00
Tyler Veness
df299d6edd [wpimath] Add UnscentedKalmanFilter::Correct() overload (#2966)
This adds an overload of UnscentedKalmanFilter::Correct() that takes a
custom measurement covariance but uses default mean and residual
calculation functions.

Closes #2965.
2020-12-24 16:00:36 -08:00
Prateek Machiraju
4e34f05238 [examples] Use ADXRS450_GyroSim class in simulation example (#2964)
This class did not exist when the original example was written. This
also changes the C++ example to use ADXRS450_Gyro for the sake of
consistency.
2020-12-24 15:42:46 -08:00
Tyler Veness
9962f6fd79 [wpilib] Give Field2d a default Sendable name (#2953) 2020-12-24 12:26:03 -08:00
Peter Johnson
f9d492f4b1 [sim] GUI: Show "Other Devices" window by default (#2961) 2020-12-24 12:24:36 -08:00
Peter Johnson
a8bb2ef1c3 [sim] Fix ADXRS450_GyroSim and DutyCycleEncoderSim (#2963)
These were broken by #2952.

Also fix Java ADXRS450_Gyro angle/rate SimValue names.
2020-12-24 12:23:38 -08:00
Peter Johnson
240c629cda [sim] Try to guess "Map Gamepad" setting (#2960)
Looks to see if the joystick name starts with "Xbox" or contains "pad".
2020-12-23 20:38:28 -08:00
Tyler Veness
952567dd3c [wpilibc] Add missing move constructors and assignment operators (#2959)
- Field2d
- FieldObject2d
- AnalogGyro
2020-12-23 20:36:51 -08:00
Peter Johnson
10b396b4c2 [sim] Various WebSockets fixes and enhancements (#2952)
This is a breaking change to the WebSockets layer to align it with
recent specification documentation work.

To support this, HAL SimValue changed readonly to a direction enum.
This allows specifying bidirectional in addition to input and output.

The SimValue change is specifically designed to avoid API and ABI breakage.
This is completely transparent in C++; in Java a new callback class was added,
and the old readonly functions have been marked deprecated.

A new SimValue creation function for enums allows specifying double values
for each enum value, not just strings.  This allows mapping enum values to
doubles in the WebSockets layer.

A ":" in the SimDevice name now maps it to different WebSocket types (e.g.
"Accel:Name" becomes type "Accel", device "Name").  The type is hidden
in the GUI.

Other WebSockets changes:
* Implemented match_time and game_data
* Added joystick rumble data
* Added builtin accelerometer support
* SimValue enums are mapped to string and double value on WS interface
* Added WebSockets protocol specification
* Added READMEs
2020-12-23 15:54:11 -08:00
sciencewhiz
699bbe21a4 [examples] Fix comments in Gearsbot to match implementation (NFC) (#2957) 2020-12-22 22:26:54 -08:00
Prateek Machiraju
27b67deca6 [glass] Add more widgets (#2947)
This adds the following widgets:
- Speed Controller
- Gyroscope
- Command
- Subsystem
- PIDController
- Scheduler
2020-12-22 21:07:44 -08:00
Peter Johnson
581b7ec553 [wpilib] Add option to flush NetworkTables every iterative loop
This functionality is disabled by default, but can be enabled by the user
program by calling setNetworkTablesFlushEnabled.
2020-12-21 09:53:45 -08:00
Peter Johnson
acfbb1a44a [ntcore] DispatcherBase::Flush: Use wpi::Now()
This is faster on some platforms than steady_clock, and will more
consistently support simulation timing.
2020-12-21 09:53:45 -08:00
Peter Johnson
d85a6d8fe4 [ntcore] Reduce limit on flush and update rate to 5 ms 2020-12-21 09:53:45 -08:00
Tyler Veness
20fbb5c63b [sim] Fix stringop truncation warning from GCC 10 (#2945)
If the strncpy() bound is equal to the destination size and the source
string is longer than 256 bytes, strncpy() won't write a null terminator
for the destination string.
2020-12-17 21:51:57 -08:00
Peter Johnson
1051a06a76 [glass] Show NT timestamps in seconds (#2944) 2020-12-17 07:29:00 -08:00
Peter Johnson
98dfc26208 [glass] Fix plots (#2943) 2020-12-17 07:27:29 -08:00
Peter Johnson
1ba0a2cedd [sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.

Default keyboard mappings:

    Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
    Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
    Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn

Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
Tyler Veness
4afb13f98b [examples] Replace M_PI with wpi::math::pi (#2938) 2020-12-17 00:15:02 -08:00
Zhiquan Yeo
b27d33675d [examples] Enhance Romi templates (#2931)
Add motors and encoders so they are more usable out of the box.
2020-12-10 21:38:27 -08:00
Peter Johnson
00b9ae77f9 [sim] Change default WS port number to 3300 (#2932) 2020-12-10 20:39:14 -08:00
Prateek Machiraju
65219f3093 [examples] Update Field2d position in periodic() (#2928)
This ensures that the robot position will be updated in dashboards like Glass when running on real hardware.
2020-12-10 20:36:20 -08:00
Peter Johnson
f78d1d4340 [sim] Process WS Encoder reset internally (#2927)
Currently, Encoder.reset() must make a round trip to the sensor and back
in order for the count to be updated for the user program.  As the sim layer
also resets the internal encoder count, this creates a race condition (a WS
message with a new count can be "in flight" during a reset and update the
count).

This changes the WS layer to not put reset on the wire, but instead keep an
offset count internal to the robot program.  The value on the wire is not
reset, but rather all sends and receives are adjusted as necessary to the
internal robot count.

This approach is straightforward, but does result in the value on the wire
not matching the value in the user program.  A future improvement will fix
this, but this change fixes the immediate race condition problem.
2020-12-10 20:30:12 -08:00
Peter Johnson
941edca597 [hal] Add Java SimDeviceDataJNI.getSimDeviceName (#2924)
This was mistakenly omitted from the Java interface.
2020-12-08 20:42:46 -08:00
Matt
a699435ede [wpilibj] Fix FlywheelSim argument order in constructor (#2922) 2020-12-07 22:34:17 -08:00
Prateek Machiraju
66d6417189 [examples] Add tasks to run Java examples (#2920)
Example: ./gradlew :wpilibjExamples:runstatespacedifferentialdrivesimulation
2020-12-07 22:33:17 -08:00
Prateek Machiraju
558e37c412 [examples] Add simple differential drive simulation example (#2918)
This provides an example of using the differential drive simulator without needing to use the command-based library.
2020-12-07 22:32:42 -08:00
Thad House
4f40d991ea [glass] Switch name of Glass back to glass (#2919)
On Unix systems, most executables are lowercase.
2020-12-07 22:32:15 -08:00
Prateek Machiraju
549af99007 [build] Update native-utils to 2021.0.6 (#2914)
This fixes the Glass publishing classifier
2020-12-05 23:58:42 -08:00
Thad House
b336930093 [glass] Change basename of glass to Glass (#2915)
Was glassApp, which makes building an extraction setup much harder.
2020-12-05 23:56:12 -08:00
Prateek Machiraju
c9a0edfb8b [glass] Package macOS application bundle 2020-12-05 23:23:35 -08:00
Prateek Machiraju
2c5668af46 [wpigui] Add platform-specific preferences save 2020-12-05 23:23:35 -08:00
Peter Johnson
751dea32ae [wpilibc] Try to work around ABI break introduced in #2901 (#2917)
The change to SendableBuilder to add GetTable() added a virtual function
early in the class definition.  This is an ABI break for vendor libraries.
Attempt to workaround this breakage by moving GetTable() to the end of the
class definition.
2020-12-05 23:19:15 -08:00
Thad House
cd8f4bfb1f [build] Package up msvc runtime into maven artifact (#2913)
This will make is so we can get the right artifact to the installer, and we can do it automatically and its guaranteed to match what built the artifacts.
2020-12-05 20:14:03 -08:00
Tyler Veness
a6cfcc6866 [wpilibc] Move SendableChooser Doxygen comments to header (NFC) (#2911) 2020-12-05 20:04:44 -08:00
Tyler Veness
b8c4f603db [wpimath] Upgrade to Eigen 3.3.9 (#2910)
It fixes some compilation errors with C++20.
2020-12-05 20:03:47 -08:00
Prateek Machiraju
0075e4b391 [wpilibj] Fix NPE in Field2d (#2909) 2020-12-05 08:46:54 -08:00
Peter Johnson
125af556ce [simulation] Fix halsim_gui ntcore and wpiutil deps (#2908)
They were being linked out of order, so ntcore wasn't being linked.
2020-12-04 23:30:17 -08:00
Matt
963ad5c255 [wpilib] Add noise to Differential Drive simulator (#2903)
Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
2020-12-04 18:46:50 -08:00
Peter Johnson
387f56cb7b [examples] Add Romi reference Java example and templates (#2905) 2020-12-04 17:34:54 -08:00
Prateek Machiraju
b3deda38c9 [examples] Zero motors on disabledInit() in sim physics examples (#2906)
This ensures that mechanisms will stop moving if the robot is disabled while motors are in motion
2020-12-04 17:34:16 -08:00
Peter Johnson
2a5ca77454 [glass] Add glass: an application for display of robot data
This reuses many pieces of the current simulation GUI.  The common pieces have
been refactored into the libglass library.

The libglass library is designed to be usable for other standalone data
visualization applications (e.g. viewing data logs).

The name "glass" comes from "glass cockpit", as the application features
several multi-function displays that can be adjusted to display robot
information as needed.
2020-12-04 00:36:55 -08:00
Peter Johnson
727940d847 [wpilib] Move Field2d to SmartDashboard 2020-12-04 00:36:55 -08:00
Peter Johnson
8cd42478e1 [wpilib] SendableBuilder: Make GetTable() visible 2020-12-04 00:36:55 -08:00
Prateek Machiraju
c11d34b26c [command] Use addCommands in command group templates (#2900)
This makes the Java templates consistent with the C++ templates as well as the documentation

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-12-01 20:52:45 -08:00
Peter Johnson
339d7445b3 [sim] Add HAL hooks for simulationPeriodic (#2881)
This allows vendor libs to hook into the begin or end of simulationPeriodic().
2020-11-30 23:55:36 -08:00
Peter Johnson
d16f05f2c8 [wpilib] Fix SmartDashboard update order (#2896)
We need to execute listener tasks first, then execute value updates.
Otherwise local changes can fight with dashboard-made changes.
2020-11-30 19:24:12 -08:00
Peter Johnson
5427b32a40 [wpiutil] unique_function: Restrict implicit conversion (#2899)
Only implicitly convert from invocable objects.  This avoids potential
ambiguity in higher-level overloaded functions.
2020-11-30 19:21:10 -08:00
Peter Johnson
f73701239d [ntcore] Add missing SetDefault initializer_list functions (#2898) 2020-11-30 19:20:40 -08:00
Peter Johnson
f5a6fc0703 [sim] Add initialized flag for all solenoids on a PCM (#2897)
This allows much easier/faster checking for whether any solenoid has been
initialized on a particular PCM.
2020-11-30 19:20:16 -08:00
Prateek Machiraju
bdf5ba91a4 [wpilibj] Fix typo in ElevatorSim (#2895)
This caused an illegal argument exception whenever the simulated elevator velocity was retrieved.
2020-11-29 22:28:11 -08:00
Declan Freeman-Gleason
bc8f338771 [wpilib] Add pose estimators (#2867)
Pose and state estimators can filter latency-compensated global measurements and fuse them with state-space drivetrain model information to estimate robot position. They are drop-in replacements for the existing odometry classes.

Co-authored-by: Declan Freeman-Gleason <declanfreemangleason@gmail.com>
Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
Co-authored-by: Claudius Tewari <cttewari@gmail.com>
Co-authored-by: Matt <matthew.morley.ca@gmail.com>
2020-11-28 14:35:35 -08:00
Tyler Veness
3413bfc06a [wpilib] PIDController: Recompute the error in AtSetpoint() (#2822)
This makes AtSetpoint() return false after the setpoint is changed with
SetSetpoint().

Closes #2821.

Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
2020-11-28 14:33:17 -08:00
Prateek Machiraju
2056f0ce09 [wpilib] Fix bugs in Hatchbot examples (#2893)
This fixes an issue with some commands not correctly requiring their
subsytems. Furthermore, an execute() method was added to the
DriveDistance command to continuously update the voltage command.
2020-11-28 14:01:56 -08:00
Peter Johnson
5eb8cfd691 [wpilibc] Fix MatchDataSender (#2892)
The is_convertible test was always treating the input as bool.
Use is_same on T instead.
2020-11-27 22:06:08 -08:00
Thad House
e6a4254488 [build] Delete test folders after tests execute (#2891)
Also deletes object files.

Both of these things are only done on the build server (-PbuildServer flag).

This will remove all test folders, which removes lots of copies of dependencies.

This also fixes an issue where gtest exectubables were installed for cross builds, even though they should not have been.
2020-11-27 21:44:47 -08:00
Prateek Machiraju
d478ad00d0 [imgui] Allow usage of imgui_stdlib (#2889)
This bumps the version number of thirdparty-imgui in Gradle and adds
imgui_stdlib.cpp into the sources in CMake, as well as adding a new
include directory.
2020-11-26 19:28:24 -08:00
Prateek Machiraju
53eda861de [build] Add unit-testing infrastructure to examples (#2863)
This also adds CMake capabilities to the command-based libraries as well
as wpilibExamples.
2020-11-26 11:47:35 -08:00
Prateek Machiraju
cc1d86ba63 [sim] Add title to simulator GUI window (#2888) 2020-11-26 11:46:14 -08:00
Prateek Machiraju
f0528f00e7 [build] CMake: Use project-specific binary and source dirs (#2886)
This ensures that allwpilib will still build correctly when added as a CMake external project.
2020-11-24 20:25:44 -08:00
Tyler Veness
5cd2ad124d [wpilibc] Add Color::operator!= (#2887) 2020-11-24 19:26:00 -08:00
Tyler Veness
6c00e7a902 [build] CI CMake: build with GUI enabled (#2884) 2020-11-24 13:37:39 -08:00
Tyler Veness
53170bbb58 Update roboRIO toolchain installation instructions (#2883)
There were conflicting instructions: install via the archive on
the releases page, and install using a gradlew command.
2020-11-23 19:48:26 -08:00
Dean Brettle
467258e050 [sim] GUI: Add option to not zero disconnected joysticks (#2876)
This allows team sim code to set the joystick values and not have them overwritten by the GUI.
2020-11-23 19:46:27 -08:00
Tyler Veness
129be23c9e Clarify JDK installation instructions in readme (#2882) 2020-11-23 19:45:14 -08:00
Prateek Machiraju
8e9290e86e [build] Add separate CMake setting for wpimath (#2885)
This allows external CMake projects to only depend on wpimath instead of
having to build the entire library.
2020-11-23 19:44:20 -08:00
Starlight220
7cf5bebf8e [wpilibj] Cache NT writes from DriverStation (#2780)
This reduces malloc traffic.
2020-11-21 14:35:43 -08:00
Prateek Machiraju
f7f9087fb5 [command] Fix timing issue in RamseteCommand (#2871)
This issue only existed on the initial iteration. When timing is paused and stepped,
initialize() and execute() get called with the same timestamp the first time, which
would result in a divide by zero. All subsequent steps advance timing and only
call execute() so the time deltas are all set correctly.
2020-11-21 10:03:01 -08:00
CoolSpy3
256e7904fd [wpilibj] SimDeviceSim: Fix sim value changed callback (#2880) 2020-11-20 21:02:23 -08:00
Tyler Veness
c8ea1b6c38 [wpilib] Add function to adjust LQR controller gain for pure time delay (#2878)
There were three options for where to put this function:

1. A free function in LinearQuadraticRegulator.h. Returning a K matrix
   means the user can't use the LinearQuadraticRegulator in a loop
   anymore.
2. A default argument added to ctors in LinearQuadraticRegulator for a
   time delay (default of 0). This has the smallest API footprint from
   the user perspective, but it bloats the already substantial
   constructor overload set of LinearQuadraticRegulator.
3. A member function in LinearQuadraticRegulator that modifies the
   internal K. This would still have to take in a LinearSystem or (A, B)
   pair because the ctor doesn't store it. Storing it internally feels
   like paying for what we don't use most of the time.

I went with option 3.

I verified the tests's expected values in Python with
scipy.linalg.fractional_matrix_power().

Closes #2877.
2020-11-20 15:28:00 -08:00
Peter Johnson
2816b06c05 [sim] HAL_GetControlWord: Fully zero output (#2873)
This ensures the padding is zero'ed.  We already do this on Athena, we just didn't in sim.
2020-11-20 15:11:11 -08:00
Tyler Veness
4c695ea088 Add toolchain installation instructions to README (#2875) 2020-11-19 13:09:09 -08:00
Starlight220
a14d51806d [wpimath] DCMotor: fix doc typo (NFC) (#2868) 2020-11-16 08:04:46 -08:00
Vasista Vovveti
0170977914 [build] CMake: build sim extensions as shared libs (#2866)
This builds sim extensions as dylib's instead of so's on macOS.
2020-11-15 22:50:30 -08:00
Vasista Vovveti
f61726b5ae [build] Fix cmake-config files (#2865)
In the cmake config files, SELF_DIR was being overwritten and was therefore incorrect.

This also adds wpimath as a dependency to wpilibc.
2020-11-15 22:38:55 -08:00
Kevin Jaget
fc27fdac57 [wpilibc] Cache NT values from driver station (#2768)
This significantly reduces malloc traffic by avoiding NT data allocations.
2020-11-15 10:48:54 -08:00
Peter Johnson
47c59859ee [sim] Make SimDevice callbacks synchronous (#2861)
Asynchronous callbacks are more efficient but pose synchronization challenges;
other sim callbacks are synchronous but SimDevice ones were not.
2020-11-14 21:04:51 -08:00
Peter Johnson
6e76ab9c09 [build] Turn on WITH_GUI for Windows cmake CI 2020-11-14 21:03:22 -08:00
Peter Johnson
5f78b76702 [build] Set GLFW_INSTALL to OFF 2020-11-14 21:03:22 -08:00
Peter Johnson
5e0808c848 [wpigui] Fix Windows cmake build 2020-11-14 21:03:22 -08:00
Peter Johnson
508f05a47e [imgui] Fix typo in Windows CMake target sources 2020-11-14 21:03:22 -08:00
Prateek Machiraju
66b57f0323 [wpimath] Copy child constraint in region constraints (#2831) 2020-11-14 12:03:26 -08:00
Prateek Machiraju
cfac22b4c0 [wpilib] Reset odometry in path following examples (#2859) 2020-11-14 12:01:45 -08:00
Prateek Machiraju
2ef67f20a7 [wpilib] Add way to silence joystick connection warnings (#2845)
Warnings cannot be silenced when connected to FMS.
2020-11-14 12:00:56 -08:00
Peter Johnson
7a73946ce1 [build] Update OpenCV to remove WITH_GTK (#2856)
This avoids a false dependency on libgthread on Mac.
2020-11-13 21:18:30 -08:00
Peter Johnson
6d22b5a3c6 [wpigui] Render during resize events (#2857)
This fixes scaling and black window artifacts on Mac.
2020-11-13 21:18:08 -08:00
Prateek Machiraju
50050a0e53 [wpilibc] Update C++ DiffDriveSim example to match Java (#2839) 2020-11-13 11:12:03 -08:00
Austin Shalit
de17422793 [wpilib] Add IsJoystickConnected method (#2847) 2020-11-13 11:11:10 -08:00
Starlight220
6b5e83ce1d [wpilibj] DrivetrainSim: Initialize m_u to default value (#2854)
m_u wasn't being initialized, so if user called update() before setInputs() the program would crash with an NPE.
2020-11-13 11:06:46 -08:00
CoolSpy3
17d75d8a3b [wpilibj] SimDeviceSim: Make register device callbacks static (#2835) 2020-11-11 22:39:18 -08:00
Prateek Machiraju
616405f7ae [wpilib] Fix DiffDriveSim pose reset and example (#2837)
Calling the resetPosition method on an odometry instance expects encoder positions to be reset to zero.
2020-11-11 22:37:14 -08:00
sciencewhiz
5c2dc043cd [wpilib] Update examples to export NewCommands (#2841)
Update all examples to export NewCommands vendor dep except for pacgoat,
which still uses old commands.
2020-11-11 22:36:18 -08:00
sciencewhiz
24a3c12f31 [wpilib] Fix names and descriptions of examples (#2846) 2020-11-11 22:35:28 -08:00
Prateek Machiraju
3e544282ff [hal] Use FPGA time in HAL_SendError (#2849) 2020-11-11 22:34:36 -08:00
Prateek Machiraju
3c85a40648 [sim] Use units for voltage and current in RoboRioSim (#2853) 2020-11-11 22:33:49 -08:00
Prateek Machiraju
ac3c336b98 [wpimath] Use units for LinearSystemId Kv and Ka (#2852) 2020-11-11 22:33:04 -08:00
Prateek Machiraju
f24f282442 [build] Disable Gazebo builds when -PmakeSim is not set (#2810) 2020-11-09 11:37:10 -05:00
Peter Johnson
0dfee4745c [wpiutil] netconsoleTee: Add option to specify port (#2840) 2020-11-08 19:54:57 -08:00
Peter Johnson
eb80f7a787 [wpilibc] SendableRegistry: Add range and null checks (#2830)
If a Sendable like SendableChooser is destroyed and recreated, it leaves
a stale object in the Sendable registry. Using this object results in a
crash. This patch avoids using the stale object.

We should remove stale objects from the global registry upon object
destruction, but this fixes the crashing issue for now.

Closes #2818.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-11-02 18:12:40 -08:00
Peter Johnson
68fed2a1a6 [build] Update NativeUtils to 2021.0.4 (#2828)
This pulls in the 2021 versions of thirdparty libs.
2020-11-02 16:33:30 -08:00
sciencewhiz
10d118a8d0 Fix C++ gradle in OtherVersions.md (#2826) 2020-11-01 20:44:39 -08:00
Peter Johnson
e021c33191 [wpilib] Set AnalogPotentiometer dashboard type (#2825)
There's not a specific dashboard type for potentiometers, so use analog input.
2020-11-01 20:44:04 -08:00
cpapplefamily
7b7548196a [wpilib] AnalogPotentiometer: provide scaled value to Dashboard (#2824)
Previously this sent just the raw analog value; the scaled value is likely what users expect.

Co-authored-by: Corey Applegate <coreya@centralmcgowan.com>
2020-10-31 22:27:05 -07:00
Prateek Machiraju
e019c735e1 [build] Update compiler to 2021 (#2823) 2020-10-31 22:24:04 -07:00
sciencewhiz
c253f2c7e2 Update Readme to match current practice (NFC) (#2820)
- Add link to code of conduct
- Update clang version used to 10 to match CI
- Update pull request format to match current practice
- Change Azure references to Actions
2020-10-30 17:28:20 -07:00
Claudius Tewari
0ce9133b55 [wpimath] Address issues with LinearSystemLoop reset() and matrix initialization (#2819)
This address some problems with the LinearSystemLoop class that were discovered through testing.

The initial state estimate of the observer was set to the provided initial state rather than zero as previously, a non zero initial state passed into reset() would lead to a discrepancy between the current state estimate and the actual system state.
2020-10-29 18:10:48 -07:00
Prateek Machiraju
6ac9683a32 [build] Fix Gradle flags for CI documentation job (#2817) 2020-10-26 19:05:31 -07:00
Prateek Machiraju
1d7739d8da [build] Build with -PreleaseMode on tag push (#2816) 2020-10-26 09:20:10 -07:00
Peter Johnson
1de2a6d85c [build] Fix release versioning (#2815)
The way GitHub actions checks out tags checks them out as non-annotated.
2020-10-26 09:13:04 -07:00
Austin Shalit
0a723a50dc [build] Use fetch-depth: 0 to get all history (#2812) 2020-10-25 19:56:52 -07:00
Prateek Machiraju
34b91318f4 [build] Add Developer ID signing workflow (#2779) 2020-10-25 19:41:45 -07:00
Peter Johnson
b11a7114a5 [build] Bump thirdparty-opencv to 3.4.7-4 (#2811) 2020-10-25 17:40:18 -07:00
Tyler Veness
2ca5e1c8d6 Update requirements in README to include full VS install and JDK (#2808) 2020-10-25 10:44:25 -07:00
Tyler Veness
7ae8c7b247 [sim] Use DutyCycleEncoder FPGA index for sim device number (#2803)
The source channel doesn't necessarily correspond with the HALSIM device
index.
2020-10-24 20:18:58 -07:00
Austin Shalit
1e17e40868 [build] Add a javaFormat Gradle task (#2805)
This task allows developers to run all of the Java code quality tools at once.
2020-10-24 20:18:19 -07:00
Tyler Veness
1069019fd2 [wpilib] Add DutyCycleEncoderSim (#2798) 2020-10-23 20:18:49 -07:00
Peter Johnson
4422904a2e [build] Add WITH_GUI cmake option 2020-10-23 07:13:01 -07:00
Peter Johnson
5d085b78bd [build] Fix cmake shared library build
BUILD_SHARED_LIBS is a cmake built-in and must be this name.

Also check for BUILD_SHARED_LIBS with WITH_SIMULATION_MODULES.
2020-10-23 07:13:01 -07:00
Thad House
0927c73b13 [build] Update NativeUtils to latest version (#2797)
Updates compiler folder for Gradle install, and fixes a bug in the sourcelink task.
2020-10-22 21:53:16 -07:00
Prateek Machiraju
5fe8f9017f [build] Refactor CMake flags (#2788)
The CMake enable/disable flags as currently structured are a confusing mix of
WITH, WITHOUT, and USE with odd defaults.  This changes the flags to consistently
use WITH and default the build options to everything enabled.
2020-10-22 21:52:24 -07:00
Tyler Veness
5cdffeaba1 [sim] StepTiming(): incrementally step Notifiers in sequence (#2794)
Currently, StepTiming() advances the time by the given delta, then runs
any Notifiers that expired within that timeframe until their expiration
times are in the future. This doesn't reflect how the Notifiers would
actually run on a real robot. For example, if a Notifier measures the
time between calls for state-space model advancement, it would measure
a large jump in time once, then zero for subsequent runs until the
Notifier was caught up to the current time.

With this change, the time is incremented by the full delta or until the
soonest Notifier, whichever has the smaller delta, then Notifiers set to
expire at that time are run. This is repeated until the time has been
advanced by the full delta. For the state-space model Notifier situation
mentioned before, it would measure multiple small time jumps instead of
one big one.
2020-10-22 20:55:12 -07:00
Austin Shalit
6e7c7374fd [build] Globally Exclude PMD.TooManyMethods (#2793)
This was not a useful check, as every time we hit it, we simply excluded it.
2020-10-22 20:53:48 -07:00
Tyler Veness
fb7b41793b [wpilib] Add ADXRS450_GyroSim (#2800)
Closes #2760.
2020-10-22 20:40:27 -07:00
Tyler Veness
abbf9f01ab [wpilib] Fix typos in simulation classes (#2799) 2020-10-22 20:38:12 -07:00
Prateek Machiraju
17698af5e3 [wpimath] Add distance/angle constructor to Translation2d (#2791) 2020-10-20 21:22:41 -07:00
Peter Johnson
b66fcdb3f7 [sim] Fix Field2D GUI crash when collapsed (#2786)
Collapsed windows result in a vertical content size of 0.
2020-10-19 22:03:06 -07:00
sciencewhiz
7fc48b75dd [command] Add PIDSubsystem PIDController as child (#2784)
Previously, the PIDSubsystem's PID Controller would show as ungrouped in
LiveWindow.

Fixes wpilibsuite/RobotBuilder#260
2020-10-19 20:04:18 -07:00
Prateek Machiraju
07ac5370d8 [wpimath] Fix m_nextR instantiation in LinearSystemLoop ctor (#2783) 2020-10-17 16:44:55 -07:00
Tyler Veness
7c8f1cf7af [wpilib] Support scheduling functions more often than robot loop (#2766)
Currently, teams have to make a Notifier to run feedback controllers
more often than the TimedRobot loop period of 20ms (running TimedRobot
more often than this is not advised). This lets users add callbacks to
the main robot loop that run at a user-defined period. This allows
running feedback controllers more often, but does so synchronously with
TimedRobot so there aren't any thread safety issues.
2020-10-16 17:56:37 -07:00
Tyler Veness
57a97e3fb3 [wpilib] Remove WatchdogTest print statements (#2781) 2020-10-16 16:49:33 -07:00
Prateek Machiraju
061432147d [wpilib] Clean up physics simulation class APIs (#2763) 2020-10-15 21:00:45 -07:00
Tyler Veness
8f3e5794b3 [wpilib] Add TimedRobot unit tests (#2771)
To make the tests reliable, the synchronization in simulation Notifiers
had to be reworked. StepTiming() now waits for all Notifiers to reach
HAL_WaitForNotifierAlarm(), then steps the time, then lets any expired
Notifiers run.

While there, we made some variable names more descriptive and added more
comments.
2020-10-15 20:18:15 -07:00
Tyler Veness
a112b5e231 [wpilib] Fix ProfiledPIDController continuous input (#2652)
There were three bugs:

1. The input range variables used in ProfiledPIDController::Calculate()
   weren't being updated
2. The modulus error calculation was incorrect.
3. The setpoint wasn't being wrapped like the goal, so the invariant
   that the error remains less than half the input range was violated.
   (Thanks to @CptJJ for pointing this out and suggesting a fix.)
2020-10-15 20:05:23 -07:00
Austin Shalit
67859aea44 [build] Split documentation into its own job (#2775)
This also allows us to update the version of java used to build documentation.
2020-10-15 18:52:49 -07:00
Prateek Machiraju
37643ab0b2 [wpimath] Use std::lower_bound in Trajectory::Sample() calculation (#2774) 2020-10-08 20:09:30 -07:00
Austin Shalit
b0ee11f7cc [build] Update vcpkg actions to latest (#2776) 2020-10-08 20:09:02 -07:00
Dalton Smith
7647e29b21 Add docs for building robot projects with other WPILib versions (#2756) 2020-10-07 22:04:52 -07:00
Prateek Machiraju
a3e672f863 [wpimath] C++: Assign zero in MakeWhiteNoiseVector if std-dev is zero (#2773)
A std-dev of zero is UB in C++. Java does not have this issue.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-10-07 21:59:34 -07:00
sciencewhiz
9058fe803d [wpilib] Update docs link to stable (NFC) (#2772) 2020-10-07 21:57:50 -07:00
Tyler Veness
32f429a819 [wpimath] Move DiscretizeR() in EKF and UKF from Predict() to Correct() (#2753)
By storing the previous dt, it can be moved into Correct() where it is
actually used. This lets us take the continuous R as an argument in the
user-provided R overload.
2020-10-07 21:54:38 -07:00
Prateek Machiraju
bf26656547 [wpimath] Fix quintic spline generation from control vectors (#2762)
This does not introduce any breaking changes for teams that used the TrajectoryGenerator API for
quintic splines with poses.

The GetQuinticControlVectorsFromWaypoints() method was removed because it is not possible for us (or
would require breaking changes to the shape of the splines) to generate only one quintic control vector
per Pose2d.  Users who actually have control vectors directly (i.e. not from Pose2d objects, but a
dashboard such as PathWeaver) should have the number of control vectors correspond to the number of
"waypoints" and can call GetQuinticSplinesFromControlVectors() directly.
2020-10-04 12:51:48 -07:00
Tyler Veness
96e26247d7 [wpiutil] Add custom priority queue implementation (#2770)
This returns the removed object from pop() to avoid copies.
2020-10-04 12:49:23 -07:00
Tyler Veness
8e538aa82f [wpilibc] Make IsSimulation() checks constexpr (#2769) 2020-10-03 22:26:19 -07:00
Kevin Jaget
fa809b2c4b [wpilibc] Clean up include files (#2708)
Based on run of include-what-you-use.org to identify unused include files in various .h and .cpp files.

The changes mostly fall into 3 categories:
- Actually unused includes - copy-paste errors, not removing includes after cleaning up code, etc
- A too-broad include used where a more specific (and hopefully smaller) header will do
- Interface .h files including headers only needed by the .cpp implementation - moving from .h to .cpp
  will mean that code which uses the .h doesn't pay the price of processing the header file they don't need
2020-10-03 09:21:03 -07:00
Tyler Veness
9a63cd36cd [wpilibc] Const-qualify Watchdog comparison operator (#2767) 2020-10-03 08:36:51 -07:00
Matt
21d949daa8 [wpilibc] Add LinearSystemLoop C++ ctor to match Java (#2755)
Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
2020-10-02 17:37:26 -07:00
Prateek Machiraju
330b90e046 [wpilib] Enable ArmSubsystem in ArmBot example (#2752) 2020-10-01 20:03:50 -07:00
Tyler Veness
693daafe29 [wpilib] Rename LinearSystemSim's ResetState() to SetState() (#2750)
This makes it more consistent with all other simulation classes,
including the differential drive simulation class.
2020-09-27 15:26:50 -07:00
Peter Johnson
c3b3fb8b74 [sim] Change StepTiming to wait for notifiers (#2603)
Old behavior is available via StepTimingAsync.

This makes it significantly easier to use simulation timing with notifiers.

Also update tests to use simulation framework.  This also speeds up the
timing-dependent tests by using simulation timing.  ResourceLock is used
in the Java tests to prevent parallel execution.

While we're here, tweak HAL Notifier implementation:
- Use wait_for instead of wait_until in WaitForNotifierAlarm
- Check for triggerTime = UINT64_MAX in UpdateNotifierAlarm
2020-09-27 13:27:53 -07:00
Tyler Veness
62731bea20 [wpilib] Add set functions to differential drive simulation (#2746)
All the other simulation objects already have functions like this
through LinearSystemSim.
2020-09-27 13:26:47 -07:00
Peter Johnson
c55fb583b8 [wpilibj] Watchdog: Implement equals and hashCode (#2743) 2020-09-27 13:25:56 -07:00
Prateek Machiraju
9725aff83b [wpilib] Clean up DifferentialDrivetrainSim API (#2747)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-09-27 13:25:17 -07:00
Tyler Veness
1320691eb4 [wpilib] Shorten differential drive simulation stability test (#2745)
If the model is unstable, it will almost always diverge within 10
seconds, and the results are rather dramatic. We're also reducing the
threshold to 100 meters because the drivetrain is moving in a small
circle. The translation norm is also used for this reason; the X
component alone regularly crosses zero since the drivetrain moves in a
circle.
2020-09-27 09:31:29 -07:00
Peter Johnson
451f67c63d [hal] SimDevice class: remove HAL_SimDeviceHandle constructor (#2744)
This isn't appropriate for a RAII class.  In particular, it can cause
foot-shooting in simulation mode if the result of
HALSIM_GetSimDeviceHandle is passed instead of HAL_CreateSimDevice.
2020-09-27 09:28:52 -07:00
Prateek Machiraju
43b1b128b1 Improve README-CMAKE.md (#2737) 2020-09-27 09:18:49 -07:00
Tyler Veness
fc991cb59c [wpilib] Clean up simulation physics API (#2739)
Some vestigial functions were never removed, and C++ single-jointed arm
sim was missing a flag for disabling gravity simulation. This is useful
for mechanisms like turrets.

Fixes #2738.
2020-09-27 00:13:59 -07:00
Prateek Machiraju
17d3d2f754 [wpilibc] Add ScopedTracer class (#2724)
This makes it easier for C++ teams to log a certain piece of code using RAII.
2020-09-27 00:10:11 -07:00
Starlight220
73950b9857 [wpilibc] RobotBase::IsReal, IsSimulation: Add doxygen comments (#2735) 2020-09-27 00:08:53 -07:00
Tyler Veness
61ee331f11 [build] Double gradle build max heap size to 2G (#2689)
The Gradle heap size is currently set to 1G, and that's becoming too
small for our Linux build.

Developers who want to override this without editing the project's
build.gradle can override these settings with gradle.properties in
GRADLE_USER_HOME (see
https://docs.gradle.org/current/userguide/build_environment.html for
details).
2020-09-27 00:07:40 -07:00
Tyler Veness
651319589c [wpilibc] Fix a use-after-free in DifferentialDrivetrainSim (#2741)
In the second constructor, a new LinearSystem is created and set to
m_plant. This takes a const ref though, so it's storing a reference to a
temporary object. After the constructor finishes, m_plant points to an
invalid object. When Update() is called, it will crash with a
segmentation fault.

This patch fixes the use-after-free by making m_plant a LinearSystem
value type. The first constructor will generate a copy, but that only
happens once.
2020-09-27 00:02:04 -07:00
Tyler Veness
5479948bd4 Update filepaths in thirdparty notices (#2713) 2020-09-24 20:51:23 -07:00
Kaitlyn Kenwell
1ec145ec87 [imgui] Add IMGUI_IMPL_OPENGL_LOADER_GL3W to cmake compile defs (#2728)
If compiled on a system with a glew header installed, it would autodetect that first and fail to link.
2020-09-24 20:21:44 -07:00
Prateek Machiraju
8ab47cb075 [wpilib] Add C++ diff-drive sim tests and fix Java test name (#2729) 2020-09-24 20:05:27 -07:00
Tyler Veness
b7b3dcf3ea Reorganize build documentation (#2712)
FasterBuilds.md was merged into README.md since it's so useful.
2020-09-24 20:03:47 -07:00
Tyler Veness
f7da0b4525 Improve list of build requirements in README (#2709)
The bulleted list was reworded to address excessive wordiness, and links
are now provided for Windows C++ compiler options.
2020-09-24 20:02:52 -07:00
Austin Shalit
f9a3380184 [build] Add macOS CMake CI (#2711) 2020-09-20 15:15:27 -07:00
Matt
b61f08d3fa [wpilib] Add physics simulation support with state-space (#2615)
This includes physics simulation support for arms/elevator models, as well as differential drivetrains.

Swerve might be added at a later date.

Co-authored-by: Claudius Tewari <cttewari@gmail.com>
Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-09-20 09:39:52 -07:00
Prateek Machiraju
0503225928 [build] CMake: Fix Metal linking on macOS (#2725) 2020-09-20 09:31:20 -07:00
Peter Johnson
d4d0b5501b [wpilib] Use more inclusive terminology (NFC) (#2723) 2020-09-19 10:35:38 -07:00
Austin Shalit
6c5726c96f Add CODE_OF_CONDUCT (#2716)
This uses the contributor covenant but with an additional line about Gracious Professionalism
2020-09-17 07:47:51 -04:00
Peter Johnson
56972447b2 [wpigui] Only build static for both gradle and cmake (#2703)
Final use of wpigui is essentially always the static library.
2020-09-13 00:34:28 -07:00
Peter Johnson
67e1796ef6 [wpimath] Fix Eigen rule-of-three violations (#2707)
This avoids deprecated-copy warnings on recent clang and GCC compilers.

Applied from https://gitlab.com/libeigen/eigen/-/merge_requests/29/diffs
2020-09-12 23:01:15 -07:00
Peter Johnson
1ae8da3b3f [wpigui] Move portable-file-dialogs.h to wpigui and upgrade it (#2704)
Also split source and implementation to avoid platform headers in header.
2020-09-12 21:15:02 -07:00
Peter Johnson
3ed97f45fb [cscore] Properly init variable in usbviewer (#2702) 2020-09-12 13:48:04 -07:00
Tyler Veness
ae2809cad4 [wpimath] Update KalmanFilter C++ class docs based on Java (NFC) (#2699) 2020-09-10 14:21:04 -07:00
Tyler Veness
b0a296477e [wpimath] Use newer link to controls book in comments (NFC) (#2700) 2020-09-10 14:20:06 -07:00
Peter Johnson
629a4574db [wpimath] Include Eigen headers in cppHeadersZip (#2696) 2020-09-06 20:53:57 -07:00
Tyler Veness
4be809499d [wpimath] Use more specific Eigen includes in headers (#2693)
This helps reduce compilation overhead. I tried slimming down includes
of <Eigen/QR>, but the householderQr() function we use from there
requires including dependency headers from Eigen that don't fit with
lexographic ordering. It didn't seem worth the effort to work around.

This won't affect user code at all since all the Eigen feature usage
here is internal only; users generally only need <Eigen/Core>.
2020-09-04 20:52:03 -07:00
Peter Johnson
b10063da9a [sim] Set Encoder reset to false when count set (#2692) 2020-09-04 20:51:08 -07:00
Peter Johnson
5e54e13140 [sim] Ignore incoming websocket DS/Joystick when real DS connected 2020-09-04 16:26:46 -07:00
Peter Johnson
8f87c56312 [sim] Automatically turn off GUI DS when real DS connected 2020-09-04 16:26:46 -07:00
Peter Johnson
1b18560e90 [sim] ds_socket: Remove iostream 2020-09-04 16:26:46 -07:00
Peter Johnson
f86a5f9b09 [sim] WebSockets: don't override HAL_Main
Also clean up some other implementation aspects for cleaner shutdown and
reduce peak memory allocation.
2020-09-04 16:26:09 -07:00
Peter Johnson
f1b1bdb121 [hal] Add HAL_Shutdown and simulation shutdown callbacks
This is useful for clean shutdown of simulation extensions.
2020-09-04 16:26:09 -07:00
Peter Johnson
0365557b25 [sim] Make extension registry thread-safe 2020-09-04 16:26:09 -07:00
Peter Johnson
883d962838 [wpiutil] SimpleBufferPool: Deallocate on destruction 2020-09-04 16:26:09 -07:00
Tyler Veness
35790a8990 [wpimath] Remove rho overload from LinearQuadraticRegulator constructors (#2687)
It was added as part of Bryson's rule described in
https://file.tavsys.net/control/controls-engineering-in-frc.pdf. It
doesn't really simplify usage though, and the same thing can be
replicated by multiplying the elements of Q by rho manually. It's easier
to do it that way, it's how 3512 has been doing controller debugging for
a while, and it's probably what other teams will do as well instead of
using the "more structured" way.

Removing these unhelpful overloads also simplifies the LQR interface.
2020-09-03 20:53:17 -07:00
Matt
8edc17dac9 [wpimath] Add Vector overload for times and div (#2686) 2020-09-03 20:48:43 -07:00
Matt
502f5c8b5f [wpimath] Make LinearPlantInversionFeedforward's A and B matrices final (#2688) 2020-09-03 19:07:36 -07:00
Matt
bc28fb187c [wpimath] Remove print from LinearSystemIDTest (#2684) 2020-09-03 19:06:52 -07:00
Peter Johnson
de0277713b [sim] Add API for extensions to discover each other (#2681) 2020-09-03 10:09:01 -07:00
Peter Johnson
1593eb4d47 [sim] Add plotting to simulation GUI 2020-09-02 21:13:38 -07:00
Peter Johnson
70ba92f917 [sim] GUI: Show DS info even when GUI DS disabled 2020-09-02 21:13:38 -07:00
Peter Johnson
47cc71ea01 [hal] Add HALSIM_GetJoystickCounts 2020-09-02 21:13:38 -07:00
Peter Johnson
9453d67273 [sim] Output more error details on extension load failure (#2680) 2020-09-02 20:07:03 -07:00
sciencewhiz
f758af826d [wpilib] Use misspell to find more spelling errors (NFC) (#2679) 2020-09-02 19:41:05 -07:00
Peter Johnson
6a1e5385e5 [sim] WS: Don't call virtual function from destructor 2020-09-01 22:54:05 -07:00
Peter Johnson
63487dca76 [sim] Fix WS blank device messages (e.g. DriverStation) 2020-09-01 22:54:05 -07:00
Peter Johnson
7d6f09f5c7 [sim] SimDataValue: Fix cancellation
The uid was getting incremented by 1 during registration but not decremented
by 1 during cancellation, so cancellation didn't work correctly.

As the underlying registration ensures a non-zero result, don't increment
the result.
2020-09-01 21:32:21 -07:00
Peter Johnson
148eed3cdc [sim] Make sure NotifyListener members are initialized 2020-09-01 21:32:21 -07:00
Thad House
05701317b4 [build] Make loading sim extensions from MyRobot easier (#2671) 2020-08-31 00:34:34 -07:00
Thad House
7548fdae5d [hal] Fix InitialzeInterrupts naming (#2673)
Closes #2605
2020-08-31 00:33:49 -07:00
sciencewhiz
3e41d92c18 [wpilib] Use misspell to fix spelling errors (NFC) (#2674) 2020-08-31 00:33:11 -07:00
sciencewhiz
ad6c8b882e [hal] Fix PDP Energy Calculation (#2672)
Fixes #2642
2020-08-31 00:31:30 -07:00
Tyler Veness
947ff655c5 [wpimath] Refactor KalmanFilter to be steady-state only (#2657)
I didn't notice a performance difference between the original
implementation and this one for a flywheel simulation, so this
simplifies a lot of internals.

This class can no longer implement KalmanTypeFilter because that class
allows setting the error covariance for use in the
KalmanFilterLatencyCompensator class. This won't impact the holonomic pose
estimators that use KalmanFilterLatencyCompensator because they all use an EKF.
2020-08-30 11:46:57 -07:00
Peter Johnson
183b7c85a1 [wpigui] Handle Direct3D framebuffer resize 2020-08-30 06:48:52 -07:00
Peter Johnson
4cf6947af7 [cscore] Add wpigui-based USB camera viewer 2020-08-30 06:48:52 -07:00
Peter Johnson
b83709b269 [wpigui] Add GetDistSquared and MaxFit functions
These utility functions were moved from halsim_gui.
2020-08-30 06:48:52 -07:00
Peter Johnson
c699d55175 [wpigui] Build dev executable in cmake build 2020-08-30 06:48:52 -07:00
Peter Johnson
781afaa852 [wpigui] Refactor texture handling
The platform-specific code now only has create, update, and delete texture.
Image reading functions have been moved to common code.

Also add pixel data functions and image data functions in addition to image
file loading.
2020-08-30 06:48:52 -07:00
Peter Johnson
007b03a2c2 [hal] Fix wpiformat errors (#2670)
These were introduced in the previous commit.
2020-08-29 23:25:41 -07:00
Thad House
ed18693345 [hal] Add no throw/error version of CAN Write methods (#2063) 2020-08-29 23:07:22 -07:00
Thad House
7c99224bb7 Create maintainers.md (#1937) 2020-08-29 20:47:28 -07:00
Prateek Machiraju
c2c4090902 [build] Fix CMake imgui and wpigui on macOS (#2669) 2020-08-29 20:40:50 -07:00
Prateek Machiraju
416288061a [build] Fix Gradle build on macOS 11.0 Big Sur (#2656) 2020-08-29 20:29:49 -07:00
Thad House
83376bc231 [build] Add sourcelink support for windows pdbs (#2592)
SourceLink embeds the git repo and hash into the pdbs, which allows VS to get the source files exactly matching a pdb directly from github.

Only VS and WinDbg are supported currently, but there are issues in the vscode tools repo to enable it there.
2020-08-29 20:27:20 -07:00
Peter Johnson
c0de98f9f2 [sim] Fix GUI scaling of window sizes (#2668)
Also tweak initial sizes, positions, and visibility.
2020-08-29 15:07:12 -07:00
Peter Johnson
70db0db221 [build] Don't unconditionally regenerate wpimath numbers (#2665)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-08-29 15:06:49 -07:00
Prateek Machiraju
526f26685d [wpilib] Add methods to check game and enabled state together (#2661)
This avoids users having to call both IsOperatorControl() and IsEnabled() to figure out if their robot is
enabled and in the teleop state. The expression above involves calling two methods that each have their
own lock.

These new methods should only involve locking one mutex, since only one call is made to HAL_GetControlWord().
2020-08-29 13:32:19 -07:00
Peter Johnson
5d1220e629 [sim] Use wpigui for simulator GUI 2020-08-27 21:05:17 -07:00
Peter Johnson
b80fde4388 [wpigui] Add wpigui wrappers for GLFW+imgui
These hide the platform specifics behind a common C++ API.  Platforms:
 - Windows: DirectX 11 (with 10 backwards compatibility)
 - Linux: OpenGL 3
 - Mac: Metal
2020-08-27 21:05:17 -07:00
Tyler Veness
148f43b4a5 [wpilibc] Use LLVM containers in ShuffleboardInstance (#2658) 2020-08-27 20:45:14 -07:00
Austin Shalit
0d88213de5 [sim] Add missing new line to extension loader message (#2663) 2020-08-27 20:39:40 -07:00
Austin Shalit
36b8d74faa [build] Revert "[build] Apply temporary JDK arch fix (#2643)" (#2655)
This reverts commit e680ba85fa.
2020-08-27 10:25:33 -07:00
Tyler Veness
5021f28159 [wpilibc] Fix InterruptableSensorBase comment (#2659)
Fixes #2355.
2020-08-27 09:42:43 -07:00
Prateek Machiraju
ee6a814576 [wpilib] Enable continuous input on theta controller in swerve examples (#2651)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-08-24 19:28:20 -07:00
Prateek Machiraju
807de9a0a9 [build] Fix Eigen include path for CMake install (#2649) 2020-08-22 11:55:12 -07:00
Matt
9398b6b55b [sim] Add AnalogEncoderSim (#2647) 2020-08-19 22:59:52 -07:00
Zhiquan Yeo
932bfcf374 [sim] Add WebSocket extension (client/server) (#2589)
This allows access to HAL-level simulation data via a WebSocket connection.

The server additionally serves local files.

The following environment variables can be used for configuration:
HALSIMWS_USERROOT (server) - local directory to use for file serving for /user/ URIs, defaults to ./sim/user
HALSIMWS_SYSROOT (server) - local directory to use for file serving for all other URIs, defaults to ./sim
HALSIMWS_URI (client or server) - WebSocket URI, defaults to /wpilibws
HALSIMWS_PORT (client or server) - port number, defaults to 8080
HALSIMWS_HOST (client) - host to connect to, defaults to localhost

Co-authored-by: Zhiquan Yeo <zyeo8@bloomberg.net>
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: jpokornyiii <jpokornyiii@gmail.com>
2020-08-19 22:14:03 -07:00
Peter Johnson
e127bac7fd [sim] Properly initialize AnalogTrigger (#2646) 2020-08-19 21:58:07 -07:00
Prateek Machiraju
bccf13bf67 [build] Run unit tests in CMake build (#2644) 2020-08-19 20:47:26 -07:00
David Vo
950bbd6dc2 [wpilibj] Fix joystick button edge synchronisation (#2433) 2020-08-19 19:46:51 -07:00
Austin Shalit
e680ba85fa [build] Apply temporary JDK arch fix (#2643) 2020-08-19 19:43:53 -07:00
Prateek Machiraju
b23ede7d50 [wpimath] Remove unnecessary copying in constraints (#2645) 2020-08-19 19:36:58 -07:00
Matt
73047d8b35 [wpiutil] Fix WPIUtilJNI.now() implementation (#2640) 2020-08-16 19:40:11 -07:00
Matt
ef5e0c2e75 [wpimath] Remove duplicate WPIMathJNI class (#2639) 2020-08-16 17:16:53 -07:00
Peter Johnson
dc9e560f9b [sim] Add callback for NotifyNewData 2020-08-15 13:47:30 -07:00
Peter Johnson
ae5b07ba01 [hal] Add stubs for sim joysticks and match info on Rio 2020-08-15 13:47:30 -07:00
Austin Shalit
3384c23a56 [build] Specify --tags on fetch and add version sanity check (#2638) 2020-08-15 13:46:41 -07:00
Tyler Veness
c2259d42a8 [wpilib] Add Toggle() function to solenoid classes (#2635)
Toggling a solenoid on a button press is a common idiom, so this
provides a more readable way of accomplishing that.
2020-08-15 08:16:32 -07:00
Austin Shalit
370e9d089f [build] Remove Azure Pipelines CI 2020-08-15 06:14:51 -07:00
Austin Shalit
cab8b18c68 [build] Add GitHub Actions CI Workflow
Testing Actions

use home env variable

Use ~ instead of home

update upload-artifact to v2

Do not specifiy branch glob

Fix architecture typo

Simplify on block

Add apt-get update step

Revert tolerance increase

Add publishing

Add vcpkg
2020-08-15 06:14:51 -07:00
Matt
3b283ab9aa [wpimath] Add core State-space classes (#2614)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
Co-authored-by: Claudius Tewari <cttewari@gmail.com>
Co-authored-by: Declan Freeman-Gleason <declanfreemangleason@gmail.com>
2020-08-14 23:40:33 -07:00
Matt
e5b84e2f87 [wpimath] Use project includes for units, Drake, Eigen (#2634) 2020-08-08 11:54:03 -07:00
Peter Johnson
f86417d791 [wpimath] Move MathShared.h to wpimath/ directory
It was confusing to have it in math/ when the std <math> header exists.
2020-08-07 12:02:02 -07:00
Peter Johnson
8dc3d23831 [wpimath] Move DrakeJNI to edu.wpi.first.math.WPIMathJNI 2020-08-07 12:02:02 -07:00
Peter Johnson
42993b15c6 [wpimath] Move math functionality into new wpimath library (#2629)
The wpimath library is a new library designed to separate the reusable math functionality
from the common utility library (wpiutil) and the hardware-dependent library (wpilibc/j).

Package names / include file names were NOT changed to minimize breakage.  In a future year
it would be good to revamp these for a more uniform user experience and to reduce the risk
of accidental naming conflicts.

While theoretically all of this functionality could be placed into wpiutil, several pieces
of this library (e.g. DARE) are very time-consuming to compile, so it's nice to avoid this
expense for users who only want cscore or ntcore.  It also allows for easy future separation
of build tasks vs number of workers on memory-constrained machines.

This moves the following functionality from wpiutil into wpimath:
- Eigen
- ejml
- Drake
- DARE
- wpiutil.math package (Matrix etc)
- units

And the following functionality from wpilibc/j into wpimath:
- Geometry
- Kinematics
- Spline
- Trajectory
- LinearFilter
- MedianFilter
- Feed-forward controllers
2020-08-06 23:57:39 -07:00
Peter Johnson
ad817d4f23 [sim] Map wpi::Now() to simulated FPGA time (#2631)
This matches on-robot behavior for things like NetworkTables timestamps.
2020-08-06 23:03:42 -07:00
Peter Johnson
77954bb3dd [wpiutil] Add JNI wrapper for wpi::Now() (#2632) 2020-08-06 21:37:38 -07:00
Banks T
52f7a62e1e [wpiutil] Allow aarch64 platform on any OS (#2625) 2020-08-05 13:45:09 -07:00
Peter Johnson
1b8ceb36fc [sim] Add callbacks for joysticks and match info (#2628) 2020-08-03 22:38:48 -07:00
Gabe Deml
ceea1f9d44 [sim] Add Mechanism2D to Simulation GUI (#2607) 2020-08-03 22:38:12 -07:00
Tyler Veness
2f81f2b78a [wpilib] Fix timestamp slew in SlewRateLimiter (#2627)
Fixes #2626.
2020-08-02 00:06:52 -07:00
Prateek Machiraju
aba035eb3d [command] Modify swerve and mecanum commands to use new controller 2020-08-02 00:03:21 -07:00
Prateek Machiraju
5ca2702083 [wpilib] Add HolonomicDriveController class and tests 2020-08-02 00:03:21 -07:00
Prateek Machiraju
af588adce5 [wpiutil] Add angle normalization method 2020-08-02 00:03:21 -07:00
carbotaniuman
399684a58f [wpilibc] Make SendableChooser movable (#2621)
SendableChooserBase was movable; it was an oversight that SendableChooser was not.
2020-07-30 11:34:07 -07:00
Peter Johnson
5cf4c16f5b [wpilibj] Suppress serialVersionUID warnings (#2618)
These are all classes (e.g. Exception classes) which will never be serialized.
2020-07-26 17:06:17 -07:00
Peter Johnson
0fe2319dfc [wpilibj] Use try with resources for Java tests (#2612) 2020-07-24 13:07:11 -07:00
Matt
e759dad019 [wpiutil] Add Drake and Drake JNI (#2613)
Drake is a collection of tools for analyzing robot dynamics and building control systems.
See https://drake.mit.edu/ for details.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-07-24 08:34:30 -07:00
Austin Shalit
0c18abed33 [build] Double gradle build max heap size to 1G (#2616)
The Gradle heap size default is 512M, and that's becoming too small for our builds.

Developers who want to override this without editing the project's build.gradle can
override these settings with gradle.properties in GRADLE_USER_HOME (see
https://docs.gradle.org/current/userguide/build_environment.html for details).
2020-07-24 08:30:22 -07:00
Austin Shalit
89dad2fd84 [build] Use artifactory doxygen mirror (#2600)
This avoids the occasional failures we've seen in downloading doxygen during CI.

Also update to doxygen 1.8.18.
2020-07-23 18:10:32 -07:00
Thad House
a6a71f8c76 [hal] Fix RoboRIO notifier never starting (#2611) 2020-07-23 18:09:00 -07:00
Zhiquan Yeo
1fee190fd0 [wpiutil] Add MIME type utility (#2608)
Co-authored-by: Zhiquan Yeo <zyeo8@bloomberg.net>
2020-07-23 10:00:47 -07:00
Peter Johnson
23ba3ca19e [wpilib] Change Watchdog to use HAL notifier (#2602)
This makes it follow simulation timing instead of wall clock time.
2020-07-21 22:58:16 -07:00
Peter Johnson
33d8363297 [sim] Fix HAL notifier race condition (#2606)
WaitForNotifierAlarm was waiting on the CV without first checking to see if
the exit condition was met.
2020-07-20 23:30:14 -07:00
Tyler Veness
49dcf7cf59 [command] Speed up MecanumControllerCommand and SwerveControllerCommand tests (#2604)
Currently, these two tests take several seconds to complete and fail
intermittently in Windows CI. This is caused by relying on wall clock
time.

Sampling the trajectory with wall clock time means the simulation must
run for several seconds to reach the end of the trajectory. Also, the
controller can become unstable when Windows CI experiences process
scheduling delays of several hundred milliseconds. Feedback controllers
don't cope well with large delays on systems with fast dynamics.

This patch uses the mocking functionality of frc::Timer to advance the
clock by 5ms at every timestep instead of using the wall clock time.
This has two benefits:

1. The tests complete much faster because the simulation can step
   forward faster than real time.
2. The controller is more stable because the sample period is uniform,
   which should fix the occasional failures.
2020-07-18 21:58:37 -07:00
Peter Johnson
9778445a74 [sim] Change stepTiming to take seconds (#2599)
This is consistent with other WPILib timer functions.
2020-07-16 22:15:59 -07:00
Peter Johnson
c2cc90b27d [sim] Move WPILib C++ sim implementations out of line (#2598)
This makes the sim classes consistent with the rest of the WPILibC classes.
2020-07-15 23:48:09 -07:00
Peter Johnson
b9feb81226 [sim] Add joystick simulation support (#2595)
This adds joystick functions to DriverStationSim, and new GenericHIDSim,
JoystickSim, and XboxControllerSim classes.
2020-07-15 00:33:57 -07:00
sciencewhiz
b06ddcdd86 [wpilib] Improve and sync AnalogPotentiometer docs (NFC) (#2580) 2020-07-13 22:00:53 -07:00
Peter Johnson
16ef372b53 [hal] Merge WaitForCachedData into WaitForDSData (#2587)
Remove WaitForCachedData as it's no longer required.

Also properly handle caching / transition detection logic that occurs at the
WPILib level.

This also changes DriverStation::IsNewControlData() to check for WPILib-level
caching instead of wrapping the HAL function.
2020-07-13 21:57:54 -07:00
sciencewhiz
f0a34ea64e [wpilib] Remove Analog Gyro specific docs from Gyro interface (#2596) 2020-07-12 15:34:28 -07:00
Prateek Machiraju
33f7dec5cf [wpilibj] Fix Gyro.getRotation2d() units bug (#2594)
The new getRotation2d() method in the Gyro interface was passing
an angle in degrees to a constructor that accepts radians.
Use fromDegrees() factory function instead.
2020-07-12 09:31:15 -07:00
Thad House
3005803598 [build] Update to latest native utils (#2591)
By default, release projects do not include symbols in the new version.
This updates that to now work correctly.
2020-07-11 23:00:18 -07:00
Thad House
eeaaf5d258 [build] Add Azure build using cmake on Windows (#2588)
More people are starting to use this build, so make sure it doesn't break.
Also tests that build succeeds with OpenCV 4.
2020-07-11 13:54:15 -07:00
sciencewhiz
15819cc981 [command] Add SimulationPeriodic to templates (#2582) 2020-07-10 21:21:31 -07:00
Thad House
fe6bfb1ba2 [cscore] Provide USB Camera VID and PID in Windows (#2585) 2020-07-10 13:16:14 -07:00
Thad House
5c8d7b2423 [build] Remove install prefix from CMakeLists.txt for Windows (#2584)
The default actually works much better.
2020-07-10 08:34:53 -07:00
sciencewhiz
ff0801d783 [build] Revert change to DeriveLineEnding made in #1961 (#2581)
Fixes windows with git autocrlf
2020-07-09 21:29:50 -07:00
Prateek Machiraju
ac4b0a3118 [wpilib] AnalogPotentiometer: Use average voltage (#2583)
Using GetAverageVoltage will reduce the noise in potentiometer reading. Potentiometers are unlikely to be used where the minimal lag averaging introduces would impact control loop stability.
2020-07-09 21:29:23 -07:00
Peter Johnson
227084e92e [hal] Implement stub mockdata on RoboRIO (#2575)
This makes it much more user-friendly to use simulation classes without needing
to ifdef for C++ to avoid linker errors or be very careful about construction
to avoid runtime errors in Java.
2020-07-07 21:49:05 -07:00
Matt
a175f6e862 [command] Add simulationPeriodic method to Subsystem (#2577)
This method is run periodically during simulation, after periodic().
2020-07-06 23:32:18 -07:00
Peter Johnson
4043c461d7 [wpiutil] HttpServerConnection: Make more functions virtual (#2576)
This allows easier customization of responses.
2020-07-06 10:12:03 -07:00
Prateek Machiraju
b3b2aa6359 [wpilib] Fix SplineHelper cubic spline bug (#2572) 2020-07-05 22:13:28 -07:00
Peter Johnson
5bd2dca463 [sim] Move HAL_LoadExtensions to end of HAL_Initialize (#2571)
Previously, HAL_InitializeDriverStation would reset any callbacks set in
extensions during load.
2020-07-05 22:12:12 -07:00
Thad House
21740fd2c5 [build] Add PDBs to jnicvstatic archives (#2573)
The tools plugin won't include them in the binary, but it will be easy to look them up if needed.
2020-07-05 22:11:42 -07:00
Peter Johnson
c11ef442fb [wpiutil] Add HttpWebSocketServerConnection (#2505)
This is a derived class of HttpServerConnection that implements the
WebSocket upgrade pieces.  This combination is pretty common so is
worth refactoring here.
2020-07-05 22:10:30 -07:00
Peter Johnson
b5a38001dd [cscore] Add support for changing the USB camera path (#2547) 2020-07-05 22:09:44 -07:00
Tyler Veness
5b6f68cf72 [wpilib] Add parentheses to MSVC #pragma message (#2569) 2020-07-05 15:24:44 -07:00
Peter Johnson
3050e935a1 [sim] Add WPILib-class-taking constructors (#2538)
When not direct mapped, make index constructors private and add factory
functions for channel and index.

Co-authored-by: GabrielDeml <gabrielddeml@gmail.com>
2020-07-04 10:10:43 -07:00
Peter Johnson
80a1fa9ece [sim] Add support for disabling SimDevices (#2568)
This allows disabling/enabling SimDevices via prefix matching.  This can be
used to force devices that normally use SimDevice in simulation mode to
instead talk directly to the hardware as in normal operation.
2020-07-04 01:09:49 -07:00
Peter Johnson
1851ba1434 [sim] Remove index from RoboRIO simulation interface (#2567) 2020-07-04 00:44:56 -07:00
Peter Johnson
c4b8a2505d [sim] Add Java wrapper for getProgramStarted (#2566)
Also move SimHooks to wpilibj (to match wpilibc).
2020-07-04 00:44:37 -07:00
Prateek Machiraju
a1d2d40ad3 [wpilib] Add RamseteController examples (#2553)
This is different from the RamseteCommand examples in that they don't use the command-based library.
2020-07-03 21:59:42 -07:00
Tyler Veness
a3881bb452 [wpilibc] Add implicit conversion from degree_t to Rotation2d (#2564)
There's already an implicit conversion for radian_t, but there's no
implicit conversion from degree_t to radian_t.
2020-07-03 21:58:19 -07:00
Thad House
6e4ee8da2b [cscore] Limit jnicvstatic exports to only C and JNI symbols (#2565)
Reduces risk even more about accidentally interfering with OpenCV.
2020-07-03 21:53:56 -07:00
Tyler Veness
2a0f79b90f [wpilib] Add X and Y component getters to Pose2d and Transform2d (#2563)
pose.Translation().X() and pose.Translation.Y() are common operations,
so shortening them to pose.X() and pose.Y() would be convenient.

Java uses the getX() convention so that is used instead of X() for Java.
2020-07-02 18:09:36 -07:00
Tyler Veness
5ccc98bc14 [wpiutil] Add angular acceleration units (#2562)
We already have predefined linear acceleration units and angular
velocity units. This makes defining acceleration constraints for angular
trapezoid profiles more convenient.

No tests were added for this because the base unit conversions are
already tested. Angular acceleration just adds another time dimension.
2020-07-01 17:16:08 -07:00
Thad House
b1353e4d6e [cscore] Fix jnicvstatic classifier (#2561)
The archive needed to be zip, additionally the library needed to statically link to cscore. All better now
2020-06-30 22:50:02 -07:00
Thad House
9f4de91554 [cscore] Add new jnicvstatic artifact type (#2560)
With the new extraction method, we would need to provide an opencv. However, all of our tools that use opencv use an alternate version of OpenCV, so that would interfere.

This adds an artifact where opencv is statically linked into cscore, but wpiutil is a shared dependency. This solves some shared state hacks, and the extraction works so much better, so its worth making this change to allow that
2020-06-30 20:39:52 -07:00
Tyler Veness
d30d1088da [wpiutil] Split units.h into separate headers for each unit (#2551)
Closes #2508.

Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
2020-06-29 22:25:09 -07:00
Peter Johnson
c6e6346642 [sim] Support StepTiming() even when timing is not paused (#2558) 2020-06-29 21:52:23 -07:00
Tyler Veness
e08c8a1fc9 [wpiutil] Add circular buffer class with static size (#2542)
This complements wpi::circular_buffer which supports dynamic resizing.
2020-06-29 21:51:05 -07:00
Tyler Veness
e50dbe0c43 [wpilib] Add Gyro::GetRotation2d() (#2555) 2020-06-29 19:10:07 -07:00
Thad House
d9c7bbd046 [wpiutil] Restore existing dll directory when setting dll directory (#2559)
* Allow getting existing dll directory when setting dll directory
2020-06-29 16:33:26 -07:00
Vasista Vovveti
dac0e5b133 [sim] Set Windows timer precision to 1ms (#2557) 2020-06-28 17:45:40 -07:00
Peter Johnson
ce3bc91946 [sim] Move Sim classes from HAL to wpilibc/j (#2549)
Also move some things in HAL for consistency.

WAS:
C++:
- C APIs: #include "mockdata/AccelerometerData.h"
- User side class: #include "simulation/AccelerometerSim.h"
Java:
- JNI APIs: hal.sim.mockdata.AccelerometerData (and a few classes in hal.sim)
- User side classes: hal.sim.AccelerometerSim

IS:
C++:
- C APIs: #include "hal/simulation/AccelerometerData.h"
- C++ class: #include "frc/simulation/AccelerometerSim.h"
Java:
- JNI APIs: hal.simulation.AccelerometerData
- User side class: wpilibj.simulation.AccelerometerSim
2020-06-27 22:11:24 -07:00
Tyler Veness
22c0e2813a [build] Upgrade CI to clang-format 10.0 (#1961)
MacOS no longer ships 6.0, and Arch Linux's mesa GPU drivers are no longer compatible with LLVM 6.0.
2020-06-27 20:39:00 -07:00
Thad House
9796987d59 [wpiutil] Add new combined native class loader (#2554)
* Add new combined native class loader

Allows us to extract a list of binaries that depend on each other, and load them successfully

It is correct that there is no implementation in wpiutil for the new native method. That is a requirement, because its needed to load the libraries, and we cant load the wpiutiljni native library since it depends on wpiutil. Instead we have a separate library built with the tools plugin that handles everything
2020-06-27 18:05:14 -07:00
Peter Johnson
4d275e4767 [cscore] Fix USB camera test failure (#2556)
Introduced by camera filtering in #2532.
2020-06-27 16:14:18 -07:00
Peter Johnson
492d6c2826 [sim] Update thirdparty-imgui (#2552)
Updates the following dependencies:
- glfw to latest 3.3-stable
- imgui to 1.76
- stb to latest master

Removes libvulkan dependency.

Also adds implot.
2020-06-27 16:02:40 -07:00
Peter Johnson
765f009350 [wpiutil] Add HttpQueryMap and HttpPath/HttpPathRef (#2544) 2020-06-27 10:47:41 -07:00
Peter Johnson
629e8b41f2 [sim] Provide method to set the runtime type (#2539)
This is needed for extensions that effectively access real hardware and
want to disable the "simulation" parts of user code.
2020-06-26 20:46:13 -07:00
Peter Johnson
71c187a1ed [hal] Add GetIndex() to handles classes (#2548)
This provides a lock-free way to get just the handle index.
2020-06-26 19:56:05 -07:00
Peter Johnson
00e991e2a0 [wpiutil] Add dual-IPv4/IPv6 uv::AddrToName() (#2545) 2020-06-26 17:14:26 -07:00
Peter Johnson
8a80f97c06 [hal] Move JNI helpers and sim namespace to hal namespace (#2543) 2020-06-26 17:12:55 -07:00
Thad House
3cbec411c7 [build] Add package declaration check to checkstyle (#2446)
Co-authored-by: Austin Shalit <austinshalit@gmail.com>
2020-06-26 11:10:34 -07:00
Thad House
3bcb89fb84 Set rpath on all unix platforms to $ORIGIN (#2299)
* Set rpath on all unix platforms to $ORIGIN

Will make it possible to extract JNI libraries easier
2020-06-23 21:03:04 -07:00
Peter Johnson
62b8a36ce9 [sim] Wrap timing functions in C++ SimHooks (#2540)
These are present in Java but were missed for C++.
2020-06-20 23:47:55 -07:00
sciencewhiz
27566abb06 [command] PIDSubsystem: Add GetSetpoint (#2534)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-06-20 16:30:21 -07:00
sciencewhiz
dfb130270a [wpilib] Use inclusive language where practical (#2533)
Co-authored-by: Austin Shalit <austinshalit@gmail.com>
2020-06-19 23:06:34 -07:00
Thad House
1ba616f843 [build] Fix 32-bit Windows builds (#2537) 2020-06-18 21:29:48 -07:00
Peter Johnson
11fb0a4cb7 [cscore] EnumerateUsbCameras(): Only list capture devices (#2532)
Previously this would list ALL /dev/video* devices.  In recent versions of
Linux this leads to listing duplicate devices, as many USB cameras provide
both a video device and a metadata device, and only the video device can
actually be used for streaming.
2020-06-13 20:51:46 -07:00
Peter Johnson
1557a4c3b0 [sim] Make SimDeviceInfo/SimValueInfo data members public (#2531) 2020-06-13 20:50:34 -07:00
sciencewhiz
ab28a7d65f [build] Run Gradle Wrapper validation on PRs (#2527) 2020-06-11 18:28:11 -07:00
Thad House
d58a5e124a [sim] Name DSCommJoystickPacket structure (#2525)
This fixes a C++ standards compliance issue that broke the build on Windows.
2020-06-08 21:28:21 -07:00
Prateek Machiraju
762347f005 [wpilibj] Throw separate exception for constraint misbehavior (#2510)
The most common mistake users (including contributors to WPILib) seem to make while creating new constraints is ignoring some sort of edge case that causes the calculated minimum acceleration to be greater than the calculated maximum acceleration.

This specialized exception, with its detailed error message, should make it easier and quicker for said users to debug and fix bugs within their constraints.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-06-08 10:38:47 -07:00
sciencewhiz
4b76adf15b [wpilibc] Remove incorrect timer rollover (#2523)
If the 64 bit FPGA timer rolls over, a 32 bit value is added for
the rollover, an artifact of when it was a 32 bit timer.
The 64 bit microsecond timer won't rollover for 500k years so remove the
check for simplicity.
Fixes #2504
2020-06-08 10:37:27 -07:00
Prateek Machiraju
6be1b95241 [wpilibj] Trajectory: Add zero-arg constructor (#2513)
C++ already has this.
2020-05-29 09:18:42 -07:00
sciencewhiz
38ad790612 CONTRIBUTING.md: Change Travis to Azure (#2520)
Co-authored-by: Austin Shalit <austinshalit@gmail.com>
2020-05-29 09:17:23 -07:00
sciencewhiz
86acb27e24 [wpilibc] Fix doxygen comments (#2519)
Apply doxygen comments to class instead of frc namespace.
Correct references to differential drive.
2020-05-29 09:15:46 -07:00
Starlight220
1b395fa21d [wpilib] Implement Trajectory.equals() (#2517) 2020-05-27 20:43:32 -07:00
Starlight220
92380485c8 [command] Make cancel safe to call from initialize (#2440)
Fixes #2388.
2020-05-20 21:00:34 -07:00
Starlight220
27f9a21a2c [wpilib] Moved Watchdog output to reportWarning() (#2413) 2020-05-20 20:57:06 -07:00
Claudius Tewari
cf7088a462 [wpilibj] RamseteController: Fix units typo in javadocs (#2515) 2020-05-20 20:55:08 -07:00
Peter Johnson
67554ef3b0 [build] Add .inl files to styleguide (NFC) (#2506)
No functional changes.
2020-05-05 18:17:50 -07:00
Thad House
cf20b068ca [sim] Map HAL_GetSystemActive to HALSIM_GetDriverStationEnabled (#2501)
Vendors have requested this for testing purposes.
2020-05-01 09:05:54 -07:00
Thad House
0b9316d94a [build] Revert workaround for azure windows library loading issue (#2481) (#2499) 2020-05-01 08:56:18 -07:00
Tyler Veness
3011ebe547 [wpilibc] Fix uninitialized variable in Trajectory class (#2495)
Valgrind caught this one. If you default initialize a Trajectory, it
doesn't initialize m_totalTime. This means a subsequent call to
Trajectory::TotalTime() returns the value of an uninitialized variable.
3512's software was using 0_s as a sentinel value for when a trajectory
was empty. We didn't notice a problem before because Linux zero-inits
memory.
2020-04-26 08:03:17 -07:00
Starlight220
4b77b0773e [wpilibj] SensorUtil: change exception type (#2490)
Use IllegalArgumentException instead of IndexOutOfBoundsException.
2020-04-23 21:27:48 -07:00
Prateek Machiraju
e5935a4737 [wpilibc] Fix const-qualification in kinematics and constraints (#2478) 2020-04-13 22:32:25 -07:00
Prateek Machiraju
a3a8472b82 [wpilib] Trajectory: Add MaxVelocity and Region constraints (#2466)
Co-Authored-By: Tyler Veness <calcmogul@gmail.com>
2020-04-12 10:39:43 -07:00
Peter Johnson
212182d991 [wpilibj] Remove getSimObject (#2479)
This approach to getting the simulation object doesn't work in C++ and
creates coupling that doesn't need to be present.
2020-04-12 10:37:27 -07:00
Thad House
c82b8546bc [build] Work around azure windows library loading issue (#2481)
Temporary fix until actions/virtual-environments#707 is deployed.
2020-04-12 10:36:25 -07:00
Tyler Veness
fac4e3fcfc [wpilibc] Add real-time priority constructor to Notifier (#2303)
Using this overload makes the thread backing the Notifier run at
real-time priority. This improves scheduling jitter substantially (5ms
+- 2ms down to 5ms +- 1ms).

A version isn't provided for Java because making threads real-time can
cause GC deadlocks.
2020-04-05 23:26:23 -07:00
Peter Johnson
5b0122fed4 [sim] Add NetworkTables view to Simulation GUI (#2327)
This enables seeing the tables locally, including update timestamps and
external connections.
2020-04-05 23:09:50 -07:00
Peter Johnson
b46b5df16a [wpilibc] Output Tracer to DriverStation by default (#2469)
This matches the Java behavior.

Also optimizes Java to only create a StringBuffer and call
DriverStation.reportWarning if there is data to output.
2020-04-05 23:09:21 -07:00
Prateek Machiraju
cb51029335 [wpilib] Add Color.fromHSV() static helper (#2461)
Keep AddressableLEDBuffer.setHSV() implementation separate in Java
for performance reasons.
2020-04-05 23:08:52 -07:00
Austin Shalit
e504b3ecbd [command] Add NetworkButton (#2373)
Closes #2371
2020-04-05 23:07:17 -07:00
Austin Shalit
0ad0ec0985 [wpilibj] Move button tests to button package (#2472)
Also make CommandTestBase public to facilitate this.
2020-04-05 23:05:53 -07:00
Austin Shalit
d1d32ada00 [build] Fix artifact publishing (#2471)
Add back variables block that was removed in #2457.
2020-04-05 23:05:13 -07:00
Peter Johnson
8058daa982 [sim] Add encoder rate and distance to Simulation GUI (#2470) 2020-04-05 19:53:39 -07:00
Starlight220
f4c5c0f5b5 [command] Add withName inline decorator to Java (#2420)
This is an inline decorator for setting the name of a command
(equivalent to calling setName()).

It's not possible to implement this for C++, as it would slice the derived
class to return it by value.
2020-04-05 16:11:23 -07:00
Connell Torek
2ecb8dab7d Add issue templates (#2189)
Co-authored-by: Connell Torek <51520860+ctorek@users.noreply.github.com>
2020-04-03 08:42:33 -07:00
Peter Johnson
576d427f03 [wpilib] SpeedControllerGroup: Add vector-taking constructor (#2194)
This allows the list to be constructed dynamically.

Co-authored-by: Thad House <thadhouse1@gmail.com>
2020-04-03 08:39:57 -07:00
Thad House
21aafea098 [hal] Use std::thread for Notifier thread on Rio (#2152)
This gives us more control over the thread than using the NI manager.
2020-04-03 08:38:00 -07:00
Thad House
3ed2908563 [sim] Add HALSIM accessors for encoder rate and distance (#2467) 2020-04-03 08:33:38 -07:00
Thad House
2b188b54d8 [ntcore] Always show StartLocal instances as connected (#2462)
This is useful for testing things that check IsConnected().
2020-04-02 17:58:07 -07:00
Austin Shalit
306720e63e [build] Split build logic into separate files (#2457)
This allows us to share build logic between Azure hosted and WPI hosted hardware.
2020-04-01 21:33:04 -07:00
Prateek Machiraju
a308dd4471 [wpilib] Fix SplineHelper quintic spline generation bug (#2429) 2020-04-01 20:31:29 -07:00
Prateek Machiraju
8f33d21bc2 [wpilib] Add init methods to Preferences (#2443) 2020-04-01 20:26:49 -07:00
Prateek Machiraju
b9ee3ae030 [wpilibc] Refactor Tracer functionality out of Watchdog class (#2456) 2020-04-01 20:10:28 -07:00
Starlight220
c14b87b228 [wpilibj] Refactor Tracer functionality out of Watchdog class (#2452) 2020-04-01 20:09:40 -07:00
David Vo
8a279aaf20 [build] Check SHA-256 of downloaded Gradle distribution (#2169)
https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:verification
2020-03-31 20:44:12 -07:00
sciencewhiz
3a5e541b2d [wpilibc] Add doxygen deprecated tag to deprecated methods (#2336) 2020-03-31 20:43:04 -07:00
Austin Shalit
43574128b3 Add a CODEOWNERS file (#2431) 2020-03-31 20:35:36 -07:00
sciencewhiz
e4a9903844 [build] Fix generateJavadoc dependencies (#2458)
This would previously not be correct on a clean repo (before a build was performed).
2020-03-30 16:50:58 -07:00
Armeen Mahdian
0d30108dcb [wpiutil] Endian.h: minor cleanup and improvements (#2454)
- Make use of if constexpr when possible for byte_swap
- Remove unnecessary make_unsigned_t alias (added to STL in C++14)
2020-03-28 10:35:47 -07:00
Prateek Machiraju
b7a79c70cc C++: Add Watchdog to CommandScheduler (#2437)
C++ counterpart to #2319
2020-03-28 09:29:51 -07:00
Daniel Z
6e6f28d1ac Add watchdog and epoch reporting to CommandScheduler (#2319) 2020-03-28 09:29:15 -07:00
Starlight220
d14978e549 New commands: add docs to end() (#2450)
Added documentation to prevent looping end() by scheduling commands.
2020-03-28 09:18:06 -07:00
Prateek Machiraju
1c28b729ad Move curvature_t to units namespace (#2444)
Note: this is a breaking change.
2020-03-22 22:57:52 -07:00
Thad House
303194b08b Add missing CAN definition for IO Breakout (#2394)
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
2020-03-22 22:56:07 -07:00
Prateek Machiraju
2ee3bfaa25 Make SlewRateLimiter unit declarations public (#2445) 2020-03-22 22:55:10 -07:00
Peter Johnson
029a94dd33 Remove old simulation bits (ds_nt, lowfi, print) (#2432)
These are little used, not actively maintained, and the simulation GUI
and alternative plans for physics simulation replace the functionality.
2020-03-22 22:52:19 -07:00
Prateek Machiraju
f6df9217b6 Remove static import usage in SelectCommand example (#2442) 2020-03-22 16:32:20 -07:00
Peter Johnson
184fae4ba5 DutyCycleEncoder: Set ownsDutyCycle for channel constructor (#2436)
Also close dutyCycle before closing digitalInput.
2020-03-21 10:36:31 -07:00
Prateek Machiraju
35b236651e Timer.start(): Match C++ behavior in Java (#2434) 2020-03-20 21:54:46 -07:00
Peter Johnson
c926770550 DutyCycleEncoder: Close created DigitalInput (#2435) 2020-03-20 21:47:32 -07:00
Joshua Shannon
272eaf184f DutyCycleEncoder: Fix simulation support (#2387)
The DutyCycleEncoder class initializes AnalogTrigger, which is not supported in simulation.

To avoid this, do not use AnalogTrigger (or Counter) in simulation mode.

Fixes #2367

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2020-03-20 14:32:52 -07:00
Starlight220
56fbb1fc33 Make Ultrasonic.setAuto() static (#2419)
Ultrasonic.setAuto() has static behavior and is static in C++. Tweak docs to be clear about this.
Fixes #2417
2020-03-19 23:25:21 -07:00
Kiefer
33f6bf947e DriverStation (Java): Make getStickButton functions public (#2424)
getStickButtonPressed and getStickButtonReleased were public in C++ but not Java.
2020-03-19 23:23:33 -07:00
Peter Johnson
07326edb6b Sim GUI: Add user rename support to SimDevice list (#2426) 2020-03-19 23:21:29 -07:00
Thad House
144610151c Bump NativeUtils to enable bigobj (#2430) 2020-03-19 23:20:57 -07:00
Tyler Veness
4228d3609e Fix Watchdog epoch prints being off by three orders of magnitude (#2414)
This was caused by m_epochs storing the timestamps as nanoseconds while
the epoch printing code expects microseconds. Adding a duration cast
fixes this.

Java stores the epoch timestamps in a double as microseconds, so it
doesn't exhibit this bug. The comments were updated to make this more
obvious.

Fixes #2392.
2020-03-15 19:56:08 -07:00
Prateek Machiraju
510936a2a0 Improve Button API documentation in GenericHID (#2421) 2020-03-15 19:54:23 -07:00
Dan Katzuv
5854e284ea Convert license file to Markdown (#2190) 2020-03-14 22:18:33 -07:00
Oblarg
a732606e55 Geometry classes: remove explicit serializers/deserializers (#2312)
Jackson can do this with much less code overhead.
2020-03-14 22:15:15 -07:00
Tyler Veness
84e300739c Fix ProfiledPIDController profile direction for continuous input (#2279)
Previously, it could take the long way around. This recomputes the
profile goal with the shortest error, thus taking the shortest path.

Also removed the setpoint clamping from PIDController::SetSetpoint()
because it's unnecessary to make PIDController behave correctly for
a modular arithmetic input, and it breaks the setpoint calculation in
ProfiledPIDController otherwise.

Fixes #2277.
2020-03-14 22:13:57 -07:00
Oblarg
8edf9282c3 Timer: synchronize on lock object (#2352) 2020-03-14 22:13:04 -07:00
Peter Johnson
5a1acaaefc Update copyright dates for #2121 (#2415) 2020-03-14 22:11:36 -07:00
Joshua Shannon
4fd7c210d8 Shuffleboard: Fixed mix up of title and type parameters (#2121) 2020-03-14 22:06:57 -07:00
sciencewhiz
a26a7d217d Remove references to percent tolerance (#2380)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-03-14 22:04:47 -07:00
Thad House
7b7f44d937 Use netcomm function to get target class rather then hardcoded (#2391)
It reports the correct value now, and helps for future proofing
2020-03-14 22:04:12 -07:00
Thad House
6cf89aa0f3 Fix interrupt cancellation (#2406) 2020-03-14 22:03:04 -07:00
Tyler Veness
3be83784cd Add Transform2d::Inverse() (#2407)
This is useful for undoing transformations. One application my FRC team
found was converting perspective n-point data from a "camera to target"
coordinate frame transformation to a "target to camera" coordinate frame
transformation.
2020-03-14 22:01:52 -07:00
Tyler Veness
b6c163acd7 Const-qualify frc2::Timer::HasElapsed() (#2397) 2020-02-29 20:12:31 -08:00
Thad House
05a26b7279 Fix missing Field2d package (#2386) 2020-02-21 20:50:53 -08:00
Tyler Veness
35eb90c135 Fix "'dimensionless' ambiguous symbol" error (#2382)
A typedef for units::dimensionless::dimensionless is defined, which
conflicted with the namespace when we added "using namespace
dimensionless". This patch reverts the "using namespace" directive.
"using" directives were added to pull three of the four relevant
typedefs but avoid the "dimensionless" type conflict.

This issue was first introduced in #2301.
2020-02-21 00:41:50 -08:00
Dustin Spicuzza
761f79385a Add SimulationInit and SimulationPeriodic functions (#2377)
Fixes #2375
2020-02-18 23:05:16 -08:00
Thad House
554bda3332 HAL: Expose NetComm SendConsoleLine (#2337)
This can be use to synchronize writes between threads, assuming writes all go through this and not stdout.
2020-02-18 20:44:40 -08:00
Thad House
2a968df779 Add method for releasing a waiting interrupt (#2347)
Useful for a new high level interrupt implementation.
2020-02-18 20:41:42 -08:00
sciencewhiz
30ccd13b69 Add methods for getting color of an LED (#2366)
Also fix rounding in Color.
2020-02-18 20:40:03 -08:00
Thad House
60c09ea51f Fix notifier race happening with very fast notifiers (#2370)
What would happen is the Stop() call would happen between the notifier loop being triggered and calling UpdateAlarm(). This would cause the Update to overwrite the stop.
2020-02-18 20:38:05 -08:00
Oblarg
65eab93527 Fix DifferentialDriveVoltageConstraint for tight turns w/ zero velocity (#2341) 2020-02-15 12:36:16 -08:00
sciencewhiz
a226ad8509 Set a default option for Sendable Chooser in examples (#2361) 2020-02-15 09:54:12 -08:00
Peter Johnson
31f4fd70ce Sim GUI: Fix crash when field/robot image load is canceled (#2362) 2020-02-15 09:53:21 -08:00
Dustin Spicuzza
7275ab9837 Add headerpad_max_install_names to Mac builds (#2333)
This allows dylib paths to be rewritten to a larger size by downstream tools.
2020-02-10 21:52:58 -08:00
Dustin Spicuzza
5b3facc63b TrapezoidProfile: Make units public (#2342) 2020-02-10 21:44:21 -08:00
CircuitCraft42
0f313fb9ab cmake: Improved portability of OpenCV Java binding search (#2348)
The CMake option OPENCV_JAVA_INSTALL_DIR can be set to the location
to search for the jar file. Note that the file name cannot be
changed, as, after checking several Linux package repositories,
that seems to be constant across all of them.

Fixes #2346.
2020-02-10 17:30:54 -08:00
Oblarg
05b7593e66 C++ circular_buffer: support types not implicitly convertible from int (#2350)
Also fixes two cases of returning a reference to a constant.
2020-02-08 13:35:21 -08:00
sciencewhiz
1b85066d26 Fix C++ ParallelRaceGroup multiple calls behavior (#2339)
The Java version was correct, but the C++ version would only run once.
2020-02-08 10:26:06 -08:00
sciencewhiz
e93b64f58d Add note that only a single instance of ADXRS450 is supported (#2349) 2020-02-08 10:24:18 -08:00
Oblarg
f0a18f31e7 Timer: add hasElapsed, advanceIfElapsed (#2322)
The current hasPeriodPassed() function is confusing.  In preparation for deprecating it,
add new advanceIfElapsed() function with same functionality and hasElapsed() function
which only checks that the time period has elapsed and does not advance the timer.

Also fix a couple of incorrect usages of hasPeriodPassed().
2020-02-08 10:23:29 -08:00
Vasista Vovveti
29c82527a5 Fix typo in ADXL sim double creation (#2332)
Sets m_simY to the virtual Y acceleration.
2020-02-04 20:15:25 -08:00
Peter Johnson
c165dc5e50 Simulation GUI: Add 2D field view (#2261)
The field image and robot image can be loaded or just a wireframe used.
The robot can be moved and rotated with a mouse click + drag.
The robot position is settable in robot code via the Field2d class.
2020-02-01 21:30:23 -08:00
sciencewhiz
42da07396c Add missing references to f in PIDSubsystem javadoc (#2318) 2020-01-31 19:18:17 -08:00
Jonathan Noyola
20e6c04059 Fix cmake install of hal generated files (#2320) 2020-01-31 19:18:00 -08:00
Declan Freeman-Gleason
ff5d3e5b36 RamseteController: Add setEnabled method (#2313) 2020-01-27 21:53:00 -08:00
sciencewhiz
6cc68ab503 Update MavenArtifacts.md (#2289) 2020-01-27 19:45:53 -08:00
Thad House
068465146b Fix null check order in SendableRegistry (#2314) 2020-01-27 19:43:31 -08:00
Thad House
3bcf8057d4 Add more detail to RuntimeLoader failure message (#2309)
Now specifies the C++ runtime is needed, along with more detail to make it easier to troubleshoot and not lose exception information.
2020-01-27 14:10:46 -08:00
David Vo
8039a6c525 Add missing include to ShuffleboardEventImportance (#2310) 2020-01-26 21:03:15 -08:00
Prateek Machiraju
558c020cca Fix duplicated state when using quintic splines (#2307)
Generating a trajectory using quintic splines caused a duplicated state at all knot points.
2020-01-24 23:10:28 -08:00
Prateek Machiraju
7797da78f5 Add missing methods to Timed and TimedSkeleton templates (#2306) 2020-01-24 20:01:23 -08:00
Oblarg
0ab81d768f Add feed-forward and slew rate limiting to advanced drive examples (#2301) 2020-01-23 18:07:38 -08:00
Oblarg
1cee5ccb93 Feed RobotDrive watchdog in RamseteCommand example (#2298) 2020-01-23 17:41:45 -08:00
Dan Katzuv
3ce01b5ac2 Fix DriveSubsystem.getHeading Java documentation (#2282) 2020-01-23 16:46:53 -08:00
sciencewhiz
e6aa8f3ff4 Update toolchain link in readme (#2304) 2020-01-23 16:43:06 -08:00
Peter Johnson
9d7b087972 Simulation GUI: Add support for custom names (#2292)
This allows users to right click on just about any name in the GUI (e.g. "PWM[0]") and rename it (e.g. "Left Motor [0]"). The index portion is not editable. The name is saved into imgui.ini so it's persistent.
2020-01-20 22:47:36 -08:00
Peter Johnson
bb184ed481 Simulation GUI: Refactor ini saving (#2291) 2020-01-20 21:49:03 -08:00
Peter Johnson
b9b31069cc Fix C++ POVButton (#2294)
Also add unit test.
2020-01-20 21:35:19 -08:00
Peter Johnson
d0cf4e8882 Change sim Filesystem.getDeployDirectory() to src/main/deploy (#2293) 2020-01-19 16:34:45 -08:00
sciencewhiz
02fb850761 Add new speed controllers to shuffleboard docs (#2288)
Also fix java links in C++ docs and a few typos.
2020-01-19 14:26:44 -08:00
sciencewhiz
ac8177e10d Fix GearsBot log methods not being called periodically (#2280)
Add logging for C++ Wrist and Claw
2020-01-17 20:18:15 -08:00
Tyler Veness
2eb5c54476 TrapezoidProfile: Fix aliasing of m_initial to result in calculate() (#2284)
Fixes #2283.
2020-01-17 20:17:21 -08:00
Peter Johnson
0e206e69cf Remove Set Camera Server Shared message (#2285) 2020-01-17 20:16:24 -08:00
5498 changed files with 503584 additions and 231388 deletions

View File

@@ -1,26 +1,30 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
@@ -29,6 +33,7 @@ BraceWrapping:
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
@@ -38,6 +43,7 @@ BraceWrapping:
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
@@ -50,6 +56,7 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
@@ -58,15 +65,25 @@ ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
- Regex: '^<.*'
Priority: 2
SortPriority: 0
- Regex: '.*'
Priority: 3
SortPriority: 0
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
@@ -76,32 +93,73 @@ MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
SpaceBeforeSquareBrackets: false
Standard: c++17
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...

71
.clang-tidy Normal file
View File

@@ -0,0 +1,71 @@
Checks:
'bugprone-assert-side-effect,
bugprone-bool-pointer-implicit-conversion,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-virtual-near-miss,
cert-dcl58-cpp,
cert-err52-cpp,
cert-err60-cpp,
cert-mem57-cpp,
cert-oop57-cpp,
cert-oop58-cpp,
clang-diagnostic-*,
-clang-diagnostic-deprecated-declarations,
-clang-diagnostic-#warnings,
-clang-diagnostic-pedantic,
clang-analyzer-*,
cppcoreguidelines-slicing,
google-build-namespaces,
google-explicit-constructor,
google-global-names-in-headers,
google-readability-avoid-underscore-in-googletest-name,
google-readability-casting,
google-runtime-operator,
misc-definitions-in-headers,
misc-misplaced-const,
misc-new-delete-overloads,
misc-non-copyable-objects,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-use-default-member-init,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-using,
readability-braces-around-statements'
FormatStyle: file

4
.gitattributes vendored Normal file
View File

@@ -0,0 +1,4 @@
*.gradle text eol=lf
*.java text eol=lf
*.md text eol=lf
*.xml text eol=lf

38
.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1,38 @@
# Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.
# More details are here: https://help.github.com/articles/about-codeowners/
# The '*' pattern is global owners.
# Order is important. The last matching pattern has the most precedence.
# The folders are ordered as a tree: by depth then alphabetically.
# This should make it easy to add new rules without breaking existing ones.
# Global rule:
* @wpilibsuite/wpilib
/cameraserver/ @wpilibsuite/camera-server
/cscore/ @wpilibsuite/camera-server
/hal/ @wpilibsuite/hardware
/hal/src/main/java/**/sim/ @wpilibsuite/simulation
/hal/src/main/native/include/mockdata/ @wpilibsuite/simulation
/hal/src/main/native/include/simulation/ @wpilibsuite/simulation
/hal/src/main/native/sim/ @wpilibsuite/simulation
/ntcore/ @wpilibsuite/network-tables
/simulation/ @wpilibsuite/simulation
/wpilibNewCommands/ @wpilibsuite/commandbased
/wpilibOldCommands/ @wpilibsuite/commandbased
/wpilibcExamples/ @wpilibsuite/wpilib @wpilibsuite/documentation
/wpilibjExamples/ @wpilibsuite/wpilib @wpilibsuite/documentation
/wpiutil/ @PeterJohnson

31
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. ...
2. ...
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- WPILib Version: [e.g. 2021.3.1]
- OS: [e.g. Windows 11]
- Java version [e.g. 1.10.2]
- C++ version [e.g. 17]
**Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

20
.github/ISSUE_TEMPLATE/question.md vendored Normal file
View File

@@ -0,0 +1,20 @@
---
name: Question
about: Ask about features or parts of this project
title: ''
labels: ''
assignees: ''
---
**Describe the question you have.**
A clear and concise description of what you want clarification on.
**Describe the reason for your confusion.**
A clear and concise description of why the question requires clarification and what's confusing.
**Is your question related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Additional context**
Add any other context or screenshots about the question here.

56
.github/workflows/cmake.yml vendored Normal file
View File

@@ -0,0 +1,56 @@
name: CMake
on: [pull_request, push]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
name: Linux
container: wpilib/roborio-cross-ubuntu:2023-22.04
flags: ""
- os: macOS-11
name: macOS
container: ""
flags: "-DWITH_JAVA=OFF"
name: "Build - ${{ matrix.name }}"
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libopencv-dev libopencv4.5-java python-is-python3
- name: Install opencv (macOS)
run: brew install opencv
if: runner.os == 'macOS'
- name: Set up Python 3.8 (macOS)
if: runner.os == 'macOS'
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install jinja
run: python -m pip install jinja2
- name: configure
run: mkdir build && cd build && cmake ${{ matrix.flags }} ..
- name: build
working-directory: build
run: cmake --build . --parallel $(nproc)
- name: test
working-directory: build
run: ctest --output-on-failure

64
.github/workflows/comment-command.yml vendored Normal file
View File

@@ -0,0 +1,64 @@
name: Comment Commands
on:
issue_comment:
types: [ created ]
jobs:
format:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/format')
runs-on: ubuntu-22.04
steps:
- name: React Rocket
uses: actions/github-script@v4
with:
script: |
const {owner, repo} = context.issue
github.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "rocket",
});
- uses: actions/checkout@v3
with:
token: ${{ secrets.COMMENT_COMMAND_PAT_TOKEN }}
- name: Fetch all history and metadata
run: |
git fetch --prune --unshallow
git checkout -b pr
git branch -f main origin/main
- name: Checkout PR
run: |
gh pr checkout $NUMBER
env:
GITHUB_TOKEN: "${{ secrets.COMMENT_COMMAND_PAT_TOKEN }}"
NUMBER: ${{ github.event.issue.number }}
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
- name: Install clang-format
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo sh -c "echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main' >> /etc/apt/sources.list.d/proposed-repositories.list"
sudo apt-get update -q
sudo apt-get install -y clang-format-14
- name: Install wpiformat
run: pip3 install wpiformat
- name: Run wpiformat
run: wpiformat -clang 14
- name: Run spotlessApply
run: ./gradlew spotlessApply
- name: Commit
run: |
# Set credentials
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Commit
git commit -am "Formatting fixes"
git push

64
.github/workflows/documentation.yml vendored Normal file
View File

@@ -0,0 +1,64 @@
name: Documentation
on: [push, workflow_dispatch]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
BASE_PATH: allwpilib/docs
jobs:
publish:
name: "Documentation - Publish"
runs-on: ubuntu-22.04
if: github.repository_owner == 'wpilibsuite' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
concurrency: ci-docs-publish
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 13
- name: Set environment variables (Development)
run: |
echo "TARGET_FOLDER=$BASE_PATH/development" >> $GITHUB_ENV
if: github.ref == 'refs/heads/main'
- name: Set environment variables (Tag)
run: |
echo "EXTRA_GRADLE_ARGS=-PreleaseMode" >> $GITHUB_ENV
echo "TARGET_FOLDER=$BASE_PATH/beta" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/v')
- name: Set environment variables (Release)
run: |
echo "EXTRA_GRADLE_ARGS=-PreleaseMode" >> $GITHUB_ENV
echo "TARGET_FOLDER=$BASE_PATH/release" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'alpha') && !contains(github.ref, 'beta')
- name: Build with Gradle
run: ./gradlew docs:generateJavaDocs docs:doxygen -PbuildServer ${{ env.EXTRA_GRADLE_ARGS }}
- name: Install SSH Client 🔑
uses: webfactory/ssh-agent@v0.7.0
with:
ssh-private-key: ${{ secrets.GH_DEPLOY_KEY }}
- name: Deploy Java 🚀
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
SSH: true
REPOSITORY_NAME: wpilibsuite/wpilibsuite.github.io
BRANCH: main
CLEAN: true
FOLDER: docs/build/docs/javadoc
TARGET_FOLDER: ${{ env.TARGET_FOLDER }}/java
- name: Deploy C++ 🚀
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
SSH: true
REPOSITORY_NAME: wpilibsuite/wpilibsuite.github.io
BRANCH: main
CLEAN: true
FOLDER: docs/build/docs/doxygen/html
TARGET_FOLDER: ${{ env.TARGET_FOLDER }}/cpp

View File

@@ -1,10 +1,14 @@
name: "Validate Gradle Wrapper"
on: [push]
on: [pull_request, push]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation-action@v1

194
.github/workflows/gradle.yml vendored Normal file
View File

@@ -0,0 +1,194 @@
name: Gradle
on: [pull_request, push]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build-docker:
strategy:
fail-fast: false
matrix:
include:
- container: wpilib/roborio-cross-ubuntu:2023-22.04
artifact-name: Athena
build-options: "-Ponlylinuxathena"
- container: wpilib/raspbian-cross-ubuntu:bullseye-22.04
artifact-name: Arm32
build-options: "-Ponlylinuxarm32"
- container: wpilib/aarch64-cross-ubuntu:bullseye-22.04
artifact-name: Arm64
build-options: "-Ponlylinuxarm64"
- container: wpilib/ubuntu-base:22.04
artifact-name: Linux
build-options: "-Ponlylinuxx86-64"
name: "Build - ${{ matrix.artifact-name }}"
runs-on: ubuntu-22.04
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set release environment variable
run: echo "EXTRA_GRADLE_ARGS=-PreleaseMode" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/v')
- name: Build with Gradle
run: ./gradlew build --build-cache -PbuildServer -PskipJavaFormat ${{ matrix.build-options }} ${{ env.EXTRA_GRADLE_ARGS }}
env:
ARTIFACTORY_PUBLISH_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PUBLISH_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifact-name }}
path: build/allOutputs
build-host:
env:
MACOSX_DEPLOYMENT_TARGET: 10.15
strategy:
fail-fast: false
matrix:
include:
- os: windows-2022
artifact-name: Win64Debug
architecture: x64
task: "build"
build-options: "-PciDebugOnly --max-workers 1"
outputs: "build/allOutputs"
- os: windows-2022
artifact-name: Win64Release
architecture: x64
build-options: "-PciReleaseOnly --max-workers 1"
task: "copyAllOutputs"
outputs: "build/allOutputs"
- os: macOS-11
artifact-name: macOS
architecture: x64
task: "build"
outputs: "build/allOutputs"
- os: windows-2022
artifact-name: Win32
architecture: x86
task: ":ntcoreffi:build"
outputs: "ntcoreffi/build/outputs"
name: "Build - ${{ matrix.artifact-name }}"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
architecture: ${{ matrix.architecture }}
- name: Import Developer ID Certificate
uses: wpilibsuite/import-signing-certificate@v1
with:
certificate-data: ${{ secrets.APPLE_CERTIFICATE_DATA }}
certificate-passphrase: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
keychain-password: ${{ secrets.APPLE_KEYCHAIN_PASSWORD }}
if: |
matrix.artifact-name == 'macOS' && (github.repository_owner == 'wpilibsuite' &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
- name: Set Keychain Lock Timeout
run: security set-keychain-settings -lut 3600
if: |
matrix.artifact-name == 'macOS' && (github.repository_owner == 'wpilibsuite' &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
- name: Set release environment variable
run: echo "EXTRA_GRADLE_ARGS=-PreleaseMode" >> $GITHUB_ENV
shell: bash
if: startsWith(github.ref, 'refs/tags/v')
- name: Set Java Heap Size
run: sed -i 's/-Xmx2g/-Xmx1g/g' gradle.properties
if: matrix.artifact-name == 'Win32'
- name: Build with Gradle
run: ./gradlew ${{ matrix.task }} --build-cache -PbuildServer -PskipJavaFormat ${{ matrix.build-options }} ${{ env.EXTRA_GRADLE_ARGS }}
env:
ARTIFACTORY_PUBLISH_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PUBLISH_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
- name: Sign Libraries with Developer ID
run: ./gradlew copyAllOutputs --build-cache -PbuildServer -PskipJavaFormat -PdeveloperID=${{ secrets.APPLE_DEVELOPER_ID }} ${{ matrix.build-options }} ${{ env.EXTRA_GRADLE_ARGS }}
if: |
matrix.artifact-name == 'macOS' && (github.repository_owner == 'wpilibsuite' &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifact-name }}
path: ${{ matrix.outputs }}
build-documentation:
name: "Build - Documentation"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 13
- name: Set release environment variable
run: echo "EXTRA_GRADLE_ARGS=-PreleaseMode" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/v')
- name: Build with Gradle
run: ./gradlew docs:zipDocs --build-cache -PbuildServer ${{ env.EXTRA_GRADLE_ARGS }}
env:
ARTIFACTORY_PUBLISH_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PUBLISH_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
- uses: actions/upload-artifact@v3
with:
name: Documentation
path: docs/build/outputs
combine:
name: Combine
needs: [build-docker, build-host, build-documentation]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
repository: wpilibsuite/build-tools
- uses: actions/download-artifact@v3
with:
path: combiner/products/build/allOutputs
- name: Flatten Artifacts
run: rsync -a --delete combiner/products/build/allOutputs/*/* combiner/products/build/allOutputs/
- name: Check version number exists
run: |
cat combiner/products/build/allOutputs/version.txt
test -s combiner/products/build/allOutputs/version.txt
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
- name: Combine
if: |
!startsWith(github.ref, 'refs/tags/v') &&
github.ref != 'refs/heads/main'
run: cd combiner && ./gradlew publish -Pallwpilib
- name: Combine (Master)
if: |
github.repository_owner == 'wpilibsuite' &&
github.ref == 'refs/heads/main'
run: cd combiner && ./gradlew publish -Pallwpilib
env:
RUN_AZURE_ARTIFACTORY_RELEASE: "TRUE"
ARTIFACTORY_PUBLISH_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PUBLISH_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
- name: Combine (Release)
if: |
github.repository_owner == 'wpilibsuite' &&
startsWith(github.ref, 'refs/tags/v')
run: cd combiner && ./gradlew publish -Pallwpilib -PreleaseRepoPublish
env:
RUN_AZURE_ARTIFACTORY_RELEASE: "TRUE"
ARTIFACTORY_PUBLISH_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PUBLISH_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
- uses: actions/upload-artifact@v3
with:
name: Maven
path: ~/releases

118
.github/workflows/lint-format.yml vendored Normal file
View File

@@ -0,0 +1,118 @@
name: Lint and Format
on:
pull_request:
push:
branches-ignore:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
wpiformat:
name: "wpiformat"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Fetch all history and metadata
run: |
git config --global --add safe.directory /__w/allwpilib/allwpilib
git fetch --prune --unshallow
git checkout -b pr
git branch -f main origin/main
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install clang-format
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo sh -c "echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main' >> /etc/apt/sources.list.d/proposed-repositories.list"
sudo apt-get update -q
sudo apt-get install -y clang-format-14
- name: Install wpiformat
run: pip3 install wpiformat
- name: Run
run: wpiformat -clang 14
- name: Check output
run: git --no-pager diff --exit-code HEAD
- name: Generate diff
run: git diff HEAD > wpiformat-fixes.patch
if: ${{ failure() }}
- uses: actions/upload-artifact@v3
with:
name: wpiformat fixes
path: wpiformat-fixes.patch
if: ${{ failure() }}
- name: Write to job summary
run: |
echo '```diff' >> $GITHUB_STEP_SUMMARY
cat wpiformat-fixes.patch >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
if: ${{ failure() }}
tidy:
name: "clang-tidy"
runs-on: ubuntu-22.04
container: wpilib/roborio-cross-ubuntu:2023-22.04
steps:
- uses: actions/checkout@v3
- name: Fetch all history and metadata
run: |
git config --global --add safe.directory /__w/allwpilib/allwpilib
git fetch --prune --unshallow
git checkout -b pr
git branch -f main origin/main
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install clang-tidy
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo sh -c "echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main' >> /etc/apt/sources.list.d/proposed-repositories.list"
sudo apt-get update -q
sudo apt-get install -y clang-tidy-14 clang-format-14
- name: Install wpiformat
run: pip3 install wpiformat
- name: Create compile_commands.json
run: ./gradlew generateCompileCommands -Ptoolchain-optional-roboRio
- name: List changed files
run: wpiformat -list-changed-files
- name: Run clang-tidy
run: wpiformat -clang 14 -no-format -tidy-changed -compile-commands=build/compile_commands/linuxx86-64 -vv
javaformat:
name: "Java format"
runs-on: ubuntu-22.04
container: wpilib/ubuntu-base:22.04
steps:
- uses: actions/checkout@v3
- name: Fetch all history and metadata
run: |
git config --global --add safe.directory /__w/allwpilib/allwpilib
git fetch --prune --unshallow
git checkout -b pr
git branch -f main origin/main
- name: Run Java format
run: ./gradlew javaFormat spotbugsMain spotbugsTest spotbugsDev
- name: Check output
run: git --no-pager diff --exit-code HEAD
- name: Generate diff
run: git diff HEAD > javaformat-fixes.patch
if: ${{ failure() }}
documentation:
name: "Documentation"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 13
- name: Build with Gradle
run: ./gradlew docs:zipDocs -PbuildServer -PdocWarningsAsErrors ${{ env.EXTRA_GRADLE_ARGS }}

48
.github/workflows/sanitizers.yml vendored Normal file
View File

@@ -0,0 +1,48 @@
name: Sanitizers
on: [pull_request, push]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- name: asan
cmake-flags: "-DCMAKE_BUILD_TYPE=Asan"
ctest-env: ""
ctest-flags: "-E 'wpilibc'"
- name: tsan
cmake-flags: "-DCMAKE_BUILD_TYPE=Tsan"
ctest-env: "TSAN_OPTIONS=second_deadlock_stack=1"
ctest-flags: "-E 'cscore|cameraserver|wpilibc|wpilibNewCommands'"
- name: ubsan
cmake-flags: "-DCMAKE_BUILD_TYPE=Ubsan"
ctest-env: ""
ctest-flags: ""
name: "${{ matrix.name }}"
runs-on: ubuntu-22.04
container: wpilib/roborio-cross-ubuntu:2023-22.04
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y libopencv-dev libopencv4.5-java python-is-python3 clang-14
- name: Install jinja
run: python -m pip install jinja2
- name: configure
run: mkdir build && cd build && cmake -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-14 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++-14 ${{ matrix.cmake-flags }} ..
- name: build
working-directory: build
run: cmake --build . --parallel $(nproc)
- name: test
working-directory: build
run: ${{ matrix.ctest-env }} ctest --output-on-failure ${{ matrix.ctest-flags }}

67
.github/workflows/upstream-utils.yml vendored Normal file
View File

@@ -0,0 +1,67 @@
name: Upstream utils
on:
pull_request:
push:
branches-ignore:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
update:
name: "Update"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Fetch all history and metadata
run: |
git fetch --prune --unshallow
git checkout -b pr
git branch -f main origin/main
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Configure committer identity
run: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- name: Run update_drake.py
run: |
cd upstream_utils
./update_drake.py
- name: Run update_eigen.py
run: |
cd upstream_utils
./update_eigen.py
- name: Run update_fmt.py
run: |
cd upstream_utils
./update_fmt.py
- name: Run update_libuv.py
run: |
cd upstream_utils
./update_libuv.py
- name: Run update_llvm.py
run: |
cd upstream_utils
./update_llvm.py
- name: Run update_mpack.py
run: |
cd upstream_utils
./update_mpack.py
- name: Run update_stack_walker.py
run: |
cd upstream_utils
./update_stack_walker.py
- name: Run update_memory.py
run: |
cd upstream_utils
./update_memory.py
- name: Add untracked files to index so they count as changes
run: git add -A
- name: Check output
run: git --no-pager diff --exit-code HEAD

18
.gitignore vendored
View File

@@ -5,6 +5,12 @@ doxygen.log
build*/
!buildSrc/
simgui-ds.json
simgui-window.json
simgui.json
networktables.json
# Created by the jenkins test script
test-reports
@@ -15,6 +21,9 @@ test-reports
.idea/
out/
# Fleet
.fleet
# Created by http://www.gitignore.io
### Linux ###
@@ -222,3 +231,12 @@ compile_commands.json
# clang configuration and clangd cache
.clang
.clangd/
.cache/
imgui.ini
# Bazel
/.ijwb/
/bazel-*
user.bazelrc
coverage_report/

View File

@@ -2,15 +2,23 @@ cppHeaderFileInclude {
\.h$
\.hpp$
\.inc$
\.inl$
}
cppSrcFileInclude {
\.cpp$
}
modifiableFileExclude {
\.patch$
gradlew
}
generatedFileExclude {
FRCNetComm\.java$
simulation/gz_msgs/src/include/simulation/gz_msgs/msgs\.h$
fieldImages/src/main/native/resources/
apriltag/src/test/resources/
}
repoRootNameOverride {
@@ -18,16 +26,24 @@ repoRootNameOverride {
}
includeOtherLibs {
^Eigen/
^cameraserver/
^cscore
^drake/
^fmt/
^hal/
^imgui
^implot
^mockdata/
^networktables/
^ntcore
^opencv2/
^support/
^units/
^unsupported/
^vision/
^wpi/
^wpigui
^wpimath/
^wpinet/
}

View File

@@ -1,6 +1,3 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) {year} FIRST. All Rights Reserved.{padding}*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

View File

@@ -1,6 +1,6 @@
{
"enableCppIntellisense": true,
"currentLanguage": "cpp",
"projectYear": "2020",
"projectYear": "intellisense",
"teamNumber": 0
}

View File

@@ -1,29 +1,33 @@
# Disable in-source builds to prevent source tree corruption.
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
if(" ${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL " ${CMAKE_CURRENT_BINARY_DIR}")
message(FATAL_ERROR "
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
")
endif()
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
set(CMAKE_SYSTEM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE)
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE)
endif()
project(allwpilib)
cmake_minimum_required(VERSION 3.3.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
message(STATUS "Platform version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
set(WPILIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
INCLUDE(CPack)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND MSVC)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install dir on windows" FORCE)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${CMAKE_BINARY_DIR}/jar)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/bin)
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${WPILIB_BINARY_DIR}/jar)
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
@@ -32,77 +36,242 @@ SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/wpilib/lib" isSystemDir)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
option(WITHOUT_JAVA "don't include java and JNI in the build" OFF)
option(BUILD_SHARED_LIBS "build with shared libs (needed for JNI)" ON)
option(WITHOUT_CSCORE "Don't build cscore (removes OpenCV requirement)" OFF)
option(WITHOUT_ALLWPILIB "Don't build allwpilib (removes OpenCV requirement)" ON)
option(WITH_TESTS "build unit tests (requires internet connection)" OFF)
option(USE_EXTERNAL_HAL "Use a separately built HAL" OFF)
set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File")
option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF)
option(USE_VCPKG_EIGEN "Use vcpkg eigen" OFF)
option(FLAT_INSTALL_WPILIB "Use a flat install directory" OFF)
option(WITH_SIMULATION_MODULES "build simulation modules" OFF)
# Options for building certain parts of the repo. Everything is built by default.
option(BUILD_SHARED_LIBS "Build with shared libs (needed for JNI)" ON)
option(WITH_JAVA "Include java and JNI in the build" ON)
option(WITH_CSCORE "Build cscore (needs OpenCV)" ON)
option(WITH_NTCORE "Build ntcore" ON)
option(WITH_WPIMATH "Build wpimath" ON)
option(WITH_WPILIB "Build hal, wpilibc/j, and myRobot (needs OpenCV)" ON)
option(WITH_EXAMPLES "Build examples" OFF)
option(WITH_TESTS "Build unit tests (requires internet connection)" ON)
option(WITH_GUI "Build GUI items" ON)
option(WITH_SIMULATION_MODULES "Build simulation modules" ON)
if (NOT WITHOUT_JAVA AND NOT BUILD_SHARED_LIBS)
# Options for external HAL.
option(WITH_EXTERNAL_HAL "Use a separately built HAL" OFF)
set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File")
# Options for using a package manager (e.g., vcpkg) for certain dependencies.
option(USE_SYSTEM_FMTLIB "Use system fmtlib" OFF)
option(USE_SYSTEM_LIBUV "Use system libuv" OFF)
option(USE_SYSTEM_EIGEN "Use system eigen" OFF)
# Options for installation.
option(WITH_FLAT_INSTALL "Use a flat install directory" OFF)
# Options for location of OpenCV Java.
set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file")
# Set default build type to release with debug info (i.e. release mode optimizations
# are performed, but debug info still exists).
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
endif()
# We always want flat install with MSVC.
if (MSVC)
set(WITH_FLAT_INSTALL ON)
endif()
if (WITH_JAVA AND NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "
FATAL: Cannot build static libs with Java enabled.
Static libs requires both BUILD_SHARED_LIBS=OFF and
WITHOUT_JAVA=ON
WITH_JAVA=OFF
")
endif()
set( wpilib_dest wpilib)
set( include_dest wpilib/include )
set( main_lib_dest wpilib/lib )
set( java_lib_dest wpilib/java )
set( jni_lib_dest wpilib/jni )
if (WITH_SIMULATION_MODULES AND NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "
FATAL: Cannot build static libs with simulation modules enabled.
Static libs requires both BUILD_SHARED_LIBS=OFF and
WITH_SIMULATION_MODULES=OFF
")
endif()
if (MSVC OR FLAT_INSTALL_WPILIB)
if (NOT WITH_JAVA OR NOT WITH_CSCORE)
if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "")
message(WARNING "
WARNING: OpenCV Java dir set but java is not enabled!
It will be ignored.
")
endif()
endif()
if (NOT WITH_WPILIB AND WITH_SIMULATION_MODULES)
message(FATAL_ERROR "
FATAL: Cannot build simulation modules with wpilib disabled.
Enable wpilib by setting WITH_WPILIB=ON
")
endif()
if (NOT WITH_NTCORE AND WITH_CSCORE)
message(FATAL_ERROR "
FATAL: Cannot build cameraserver without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
")
endif()
if (NOT WITH_NTCORE AND WITH_GUI)
message(FATAL_ERROR "
FATAL: Cannot build GUI modules without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
")
endif()
if (NOT WITH_NTCORE AND WITH_SIMULATION_MODULES)
message(FATAL_ERROR "
FATAL: Cannot build simulation modules without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
")
endif()
if (NOT WITH_NTCORE AND WITH_WPILIB)
message(FATAL_ERROR "
FATAL: Cannot build wpilib without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
")
endif()
if (NOT WITH_WPIMATH AND WITH_WPILIB)
message(FATAL_ERROR "
FATAL: Cannot build wpilib without wpimath.
Enable wpimath by setting WITH_WPIMATH=ON
")
endif()
set( wpilib_dest "")
set( include_dest include )
set( main_lib_dest lib )
set( java_lib_dest java )
set( jni_lib_dest jni )
if (WITH_FLAT_INSTALL)
set (wpilib_config_dir ${wpilib_dest})
else()
set (wpilib_config_dir share/wpilib)
endif()
if (USE_VCPKG_LIBUV)
set (LIBUV_VCPKG_REPLACE "find_package(unofficial-libuv CONFIG)")
if (USE_SYSTEM_LIBUV)
set (LIBUV_SYSTEM_REPLACE "
find_package(PkgConfig REQUIRED)
pkg_check_modules(libuv REQUIRED IMPORTED_TARGET libuv)
")
endif()
if (USE_VCPKG_EIGEN)
set (EIGEN_VCPKG_REPLACE "find_package(Eigen3 CONFIG)")
if (USE_SYSTEM_EIGEN)
set (EIGEN_SYSTEM_REPLACE "find_package(Eigen3 CONFIG)")
endif()
if (MSVC OR FLAT_INSTALL_WPILIB)
find_package(LIBSSH 0.7.1)
if (WITH_FLAT_INSTALL)
set(WPIUTIL_DEP_REPLACE "include($\{SELF_DIR\}/wpiutil-config.cmake)")
set(WPINET_DEP_REPLACE "include($\{SELF_DIR\}/wpinet-config.cmake)")
set(NTCORE_DEP_REPLACE "include($\{SELF_DIR\}/ntcore-config.cmake)")
set(CSCORE_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cscore-config.cmake)")
set(CAMERASERVER_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cameraserver-config.cmake)")
set(HAL_DEP_REPLACE_IMPL "include(\${SELF_DIR}/hal-config.cmake)")
set(WPIMATH_DEP_REPLACE "include($\{SELF_DIR\}/wpimath-config.cmake)")
set(WPILIBC_DEP_REPLACE_IMPL "include(\${SELF_DIR}/wpilibc-config.cmake)")
set(WPILIBNEWCOMMANDS_DEP_REPLACE "include(\${SELF_DIR}/wpilibNewcommands-config.cmake)")
else()
set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
set(WPINET_DEP_REPLACE "find_dependency(wpinet)")
set(NTCORE_DEP_REPLACE "find_dependency(ntcore)")
set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)")
set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)")
set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)")
set(WPIMATH_DEP_REPLACE "find_dependency(wpimath)")
set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)")
set(WPILIBNEWCOMMANDS_DEP_REPLACE "find_dependency(wpilibNewCommands)")
endif()
set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)")
set(SELF_DIR "$\{SELF_DIR\}")
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
endif()
if(NOT "Tsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Tsan)
endif()
if(NOT "Ubsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Ubsan)
endif()
else()
set(allowedBuildTypes Asan Tsan Ubsan Debug Release RelWithDebInfo MinSizeRel)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()
set(CMAKE_C_FLAGS_ASAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler for Asan build type or configuration." FORCE)
set(CMAKE_CXX_FLAGS_ASAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C++ compiler for Asan build type or configuration." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING
"Linker flags to be used to create executables for Asan build type." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING
"Linker lags to be used to create shared libraries for Asan build type." FORCE)
set(CMAKE_C_FLAGS_TSAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler for Tsan build type or configuration." FORCE)
set(CMAKE_CXX_FLAGS_TSAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C++ compiler for Tsan build type or configuration." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_TSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" CACHE STRING
"Linker flags to be used to create executables for Tsan build type." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_TSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" CACHE STRING
"Linker lags to be used to create shared libraries for Tsan build type." FORCE)
set(CMAKE_C_FLAGS_UBSAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler for Ubsan build type or configuration." FORCE)
set(CMAKE_CXX_FLAGS_UBSAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C++ compiler for Ubsan build type or configuration." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_UBSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all" CACHE STRING
"Linker flags to be used to create executables for Ubsan build type." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_UBSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING
"Linker lags to be used to create shared libraries for Ubsan build type." FORCE)
if (WITH_TESTS)
enable_testing()
add_subdirectory(googletest)
@@ -110,27 +279,55 @@ if (WITH_TESTS)
endif()
add_subdirectory(wpiutil)
add_subdirectory(ntcore)
if (NOT WITHOUT_CSCORE)
if (WITH_NTCORE)
add_subdirectory(wpinet)
add_subdirectory(ntcore)
endif()
if (WITH_WPIMATH)
add_subdirectory(wpimath)
endif()
if (WITH_GUI)
add_subdirectory(fieldImages)
add_subdirectory(imgui)
add_subdirectory(wpigui)
add_subdirectory(glass)
add_subdirectory(outlineviewer)
if (LIBSSH_FOUND)
add_subdirectory(roborioteamnumbersetter)
add_subdirectory(datalogtool)
endif()
endif()
if (WITH_WPILIB OR WITH_SIMULATION_MODULES)
set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL})
add_subdirectory(hal)
endif()
if (WITH_CSCORE)
set(CSCORE_DEP_REPLACE ${CSCORE_DEP_REPLACE_IMPL})
set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL})
add_subdirectory(cscore)
add_subdirectory(cameraserver)
if (NOT WITHOUT_ALLWPILIB)
set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL})
set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL})
add_subdirectory(hal)
add_subdirectory(wpilibj)
add_subdirectory(wpilibc)
add_subdirectory(myRobot)
endif()
endif()
if (WITH_SIMULATION_MODULES AND NOT USE_EXTERNAL_HAL)
add_subdirectory(imgui)
if (WITH_WPILIB)
set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL})
add_subdirectory(apriltag)
add_subdirectory(wpilibj)
add_subdirectory(wpilibc)
add_subdirectory(wpilibNewCommands)
if (WITH_EXAMPLES)
add_subdirectory(wpilibcExamples)
endif()
add_subdirectory(myRobot)
endif()
if (WITH_SIMULATION_MODULES AND NOT WITH_EXTERNAL_HAL)
add_subdirectory(simulation)
endif()
configure_file(wpilib-config.cmake.in ${CMAKE_BINARY_DIR}/wpilib-config.cmake )
install(FILES ${CMAKE_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir})
configure_file(wpilib-config.cmake.in ${WPILIB_BINARY_DIR}/wpilib-config.cmake )
install(FILES ${WPILIB_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir})

131
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,131 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Exhibiting Gracious Professionalism® at all times. Gracious Professionalism
is a way of doing things that encourages high-quality work, emphasizes the
value of others, and respects individuals and the community.
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[conduct@wpilib.org](mailto:conduct@wpilib.org).
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.

View File

@@ -1,6 +1,6 @@
# Contributing to WPILib
So you want to contribute your changes back to WPILib. Great! We have a few contributing rules that will help you make sure your changes will be accepted into the project. Please remember to follow the rules written here, and behave with Gracious Professionalism.
So you want to contribute your changes back to WPILib. Great! We have a few contributing rules that will help you make sure your changes will be accepted into the project. Please remember to follow the rules in the [code of conduct](https://github.com/wpilibsuite/allwpilib/blob/main/CODE_OF_CONDUCT.md), and behave with Gracious Professionalism.
- [General Contribution Rules](#general-contribution-rules)
- [What to Contribute](#what-to-contribute)
@@ -37,20 +37,52 @@ So you want to contribute your changes back to WPILib. Great! We have a few cont
## Coding Guidelines
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system. We currently use clang-format 6.0 with wpiformat.
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system.
While the library should be fully formatted according to the styles, additional elements of the style guide were not followed when the library was initially created. All new code should follow the guidelines. If you are looking for some easy ramp-up tasks, finding areas that don't follow the style guide and fixing them is very welcome.
### Math documentation
When writing math expressions in documentation, use https://www.unicodeit.net/ to convert LaTeX to a Unicode equivalent that's easier to read. Not all expressions will translate (e.g., superscripts of superscripts) so focus on making it readable by someone who isn't familiar with LaTeX. If content on multiple lines needs to be aligned in Doxygen/Javadoc comments (e.g., integration/summation limits, matrices packed with square brackets and superscripts for them), put them in @verbatim/@endverbatim blocks in Doxygen or `<pre>` tags in Javadoc so they render with monospace font.
The LaTeX to Unicode conversions can also be done locally via the unicodeit Python package. To install it, execute:
```bash
pip install --user unicodeit
```
Here's example usage:
```bash
$ python -m unicodeit.cli 'x_{k+1} = Ax_k + Bu_k'
xₖ₊₁ = Axₖ + Buₖ
```
On Linux, this process can be streamlined further by adding the following Bash function to your .bashrc (requires `wl-clipboard` on Wayland or `xclip` on X11):
```bash
# Converts LaTeX to Unicode, prints the result, and copies it to the clipboard
uc() {
if [ $WAYLAND_DISPLAY ]; then
python -m unicodeit.cli $@ | tee >(wl-copy -n)
else
python -m unicodeit.cli $@ | tee >(xclip -sel)
fi
}
```
Here's example usage:
```bash
$ uc 'x_{k+1} = Ax_k + Bu_k'
xₖ₊₁ = Axₖ + Buₖ
```
## Submitting Changes
### Pull Request Format
Changes should be submitted as a Pull Request against the master branch of WPILib. For most changes, we ask that you squash your changes down to a single commit. For particularly large changes, multiple commits are ok, but assume one commit unless asked otherwise. No change will be merged unless it is up to date with the current master. We will also not merge any changes with merge commits in them; please rebase off of master before submitting a pull request. We do this to make sure that the git history isn't too cluttered.
Changes should be submitted as a Pull Request against the main branch of WPILib. For most changes, commits will be squashed upon merge. For particularly large changes, multiple commits are ok, but assume one commit unless asked otherwise. We may ask you to break a PR into multiple standalone PRs or commits for rebase within one PR to separate unrelated changes. No change will be merged unless it is up to date with the current main branch. We do this to make sure that the git history isn't too cluttered.
### Merge Process
When you first submit changes, Travis-CI will attempt to run `./gradlew check` on your change. If this fails, you will need to fix any issues that it sees. Once Travis passes, we will begin the review process in more earnest. One or more WPILib team members will review your change. This will be a back-and-forth process with the WPILib team and the greater community. Once we are satisfied that your change is ready, we will allow our Jenkins instance to test it. This will run the full gamut of checks, including integration tests on actual hardware. Once all tests have passed and the team is satisfied, we will merge your change into the WPILib repository.
When you first submit changes, GitHub Actions will attempt to run `./gradlew check` on your change. If this fails, you will need to fix any issues that it sees. Once Actions passes, we will begin the review process in more earnest. One or more WPILib team members will review your change. This will be a back-and-forth process with the WPILib team and the greater community. Once we are satisfied that your change is ready, we will allow our hosted instance to test it. This will run the full gamut of checks, including integration tests on actual hardware. Once all tests have passed and the team is satisfied, we will merge your change into the WPILib repository.
## Licensing
By contributing to WPILib, you agree that your code will be distributed with WPILib, and licensed under the license for the WPILib project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as WPILib is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](LICENSE.txt).
By contributing to WPILib, you agree that your code will be distributed with WPILib, and licensed under the license for the WPILib project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as WPILib is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](LICENSE.md).

98
DevelopmentBuilds.md Normal file
View File

@@ -0,0 +1,98 @@
# Installing Development Builds
This article contains instructions on building projects using a development build and a local WPILib build.
**Note:** This only applies to Java/C++ teams.
## Development Build
Development builds are the per-commit build hosted every time a commit is pushed to the [allwpilib](https://github.com/wpilibsuite/allwpilib/) repository. These builds are then hosted on [artifactory](https://frcmaven.wpi.edu/artifactory/webapp/#/home).
To build a project using a development build, find the build.gradle file and open it. Then, add the following code below the plugin section and replace YEAR with the year of the development version. It is also necessary to use a 2023 GradleRIO version, ie `2023.0.0-alpha-1`
```groovy
wpi.maven.useLocal = false
wpi.maven.useDevelopment = true
wpi.versions.wpilibVersion = 'YEAR.+'
wpi.versions.wpimathVersion = 'YEAR.+
```
The top of your ``build.gradle`` file should now look similar to the code below. Ignore any differences in versions.
Java
```groovy
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2023.0.0-alpha-1"
}
wpi.maven.useLocal = false
wpi.maven.useDevelopment = true
wpi.versions.wpilibVersion = '2023.+'
wpi.versions.wpimathVersion = '2023.+'
```
C++
```groovy
plugins {
id "cpp"
id "google-test-test-suite"
id "edu.wpi.first.GradleRIO" version "2023.0.0-alpha-1"
}
wpi.maven.useLocal = false
wpi.maven.useDevelopment = true
wpi.versions.wpilibVersion = '2023.+'
wpi.versions.wpimathVersion = '2023.+'
```
### Development Build Documentation
* C++: https://github.wpilib.org/allwpilib/docs/development/cpp/
* Java: https://github.wpilib.org/allwpilib/docs/development/java/
## Local Build
Building with a local build is very similar to building with a development build. Ensure you have built and published WPILib by following the instructions attached [here](https://github.com/wpilibsuite/allwpilib#building-wpilib). Next, find the ``build.gradle`` file in your robot project and open it. Then, add the following code below the plugin section and replace ``YEAR`` with the year of the local version.
Java
```groovy
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2023.0.0-alpha-1"
}
wpi.maven.useLocal = false
wpi.maven.useFrcMavenLocalDevelopment = true
wpi.versions.wpilibVersion = 'YEAR.424242.+'
wpi.versions.wpimathVersion = 'YEAR.424242.+'
```
C++
```groovy
plugins {
id "cpp"
id "google-test-test-suite"
id "edu.wpi.first.GradleRIO" version "2023.0.0-alpha-1"
}
wpi.maven.useLocal = false
wpi.maven.useFrcMavenLocalDevelopment = true
wpi.versions.wpilibVersion = 'YEAR.424242.+'
wpi.versions.wpimathVersion = 'YEAR.424242.+'
```
# roboRIO Development
This repo contains a myRobot project built in way to do full project development without needing to do a full publish into GradleRIO. These also only require building the minimum amount of binaries for the roboRIO, so the builds are much faster as well.
The setup only works if the roboRIO is USB connected. If an alternate IP address is preferred, the `address` block in myRobot\build.gradle can be changed to point to another address.
The following 3 tasks can be used for deployment:
* `:myRobot:deployShared` deploys the C++ project using shared dependencies. Prefer this one for most C++ development.
* `:myRobot:deployStatic` deploys the C++ project with all dependencies statically linked.
* `:myRobot:deployJava` deploys the Java project and all required dependencies. Also installs the JRE if not currently installed.
Deploying any of these to the roboRIO will disable the current startup project until it is redeployed.
From here, ssh into the roboRIO using the `lvuser` account and run `frcRunRobot.sh` (It's in path).

View File

@@ -1,15 +0,0 @@
# Faster Builds for Developers
When you run `./gradlew build`, it builds EVERYTHING. This means debug and release builds for desktop and all installed cross compilers. For many developers, this is way too much, and causes much developer pain.
To help with some of these things, common tasks have shortcuts to only build necessary things for common development and testing tasks.
## Development (Desktop)
For projects `wpiutil`, `ntcore`, `cscore`, `hal` `wpilibOldCommands`, `wpilibNewCommands` and `cameraserver`, a `testDesktopJava` and a `testDesktopCpp` task exists. These can be ran with `./gradlew :projectName:task`, and will only build the minimum things required to run those tests.
For `wpilibc`, a `testDesktopCpp` task exists. For `wpilibj`, a `testDesktopJava` task exists.
For `wpilibcExamples`, a `buildDesktopCpp` task exists (These can't be ran, but they can compile).
For `wpilibjExamples`, a `buildDesktopJava` task exists.

24
LICENSE.md Normal file
View File

@@ -0,0 +1,24 @@
Copyright (c) 2009-2022 FIRST and other WPILib contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of FIRST, WPILib, nor the names of other WPILib
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY FIRST AND OTHER WPILIB CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,24 +0,0 @@
Copyright (c) 2009-2018 FIRST
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the FIRST nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY FIRST AND CONTRIBUTORS``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

27
MAINTAINERS.md Normal file
View File

@@ -0,0 +1,27 @@
## Publishing Third Party Dependencies
Currently the 3rd party deps are imgui, opencv, and google test
For publishing these dependencies, the version needs to be manually updated in the publish.gradle file of their respective repository.
Then, in the azure build for the dependency you want to build for, manually start a pipeline build (As of current, this is the `Run Pipeline` button).
A variable needs to be added called `RUN_AZURE_ARTIFACTORY_RELEASE`, with a value of `true`. Then when the pipeline gets started, the final build outputs will be updated to artifactory.
To use newer versions of C++ dependencies, in `shared/config.gradle`, update the version related to the specific dependency.
For Java dependencies, there is likely a file related to the specific dependency in the shared folder. Update the version in there.
Note, changing artifact locations (This includes changing the artifact year currently, I have an issue open to change this) requires updating the `native-utils` plugin
## Publishing allwpilib
allwpilib publishes to the development repo on every push to main. To publish a release build, upload a new tag, and a release will automatically be built and published.
## Publishing desktop tools
Desktop tools publish to the development repo on every push to main. To publish a release build, upload a new tag, and a release will automatically be built and published.
## Publishing VS Code
Before publishing, make sure to update the gradlerio version in `vscode-wpilib/resources/gradle/version.txt` Also make sure the gradle wrapper version matches the wrapper required by gradlerio.
Upon pushing a tag, a release will be built, and the files will be uploaded to the releases on GitHub. For publishing to the marketplace, you need a Microsoft account and to be added as a maintainer.
## Publishing GradleRIO
Before publishing, make sure to update the version in build.gradle. Publishing must happen locally, using the command `./gradlew publishPlugin`. This does require your API key for publishing to be set.
## Building the installer
Update the GradleRIO version in gradle.properties, and in the scripts folder in vscode, update the vscode extension. Then push, it will build the installer on azure.

View File

@@ -9,7 +9,7 @@ We provide two repositories. These repositories are:
* (Development) https://frcmaven.wpi.edu/artifactory/development/
The release repository is where official WPILib releases are pushed.
The development repository is where development releases of every commit to [master](https://github.com/wpilibsuite/allwpilib/tree/master) is pushed.
The development repository is where development releases of every commit to [main](https://github.com/wpilibsuite/allwpilib/tree/main) is pushed.
## Artifact classifiers
We provide two base types of artifacts.
@@ -69,34 +69,90 @@ All artifacts are based at `edu.wpi.first.artifactname` in the repository.
* wpiutil
* hal
* wpigui
* imgui
* wpimath
* wpiutil
* wpinet
* wpiutil
* ntcore
* wpiutil
* wpinet
* glass/libglass
* wpiutil
* wpimath
* wpigui
* glass/libglassnt
* wpiutil
* wpinet
* ntcore
* wpimath
* wpigui
* hal
* wpiutil
* halsim
* wpiutil
* wpinet
* ntcore
* wpimath
* wpigui
* libglass
* libglassnt
* cscore
* opencv
* wpinet
* wpiutil
* cameraserver
* ntcore
* cscore
* opencv
* wpinet
* wpiutil
* wpilibj
* hal
* cameraserver
* ntcore
* cscore
* wpinet
* wpiutil
* wpilibc
* hal
* cameraserver
* ntcore
* cscore
* wpimath
* wpinet
* wpiutil
* wpilibNewCommands
* wpilibc
* hal
* cameraserver
* ntcore
* cscore
* wpimath
* wpinet
* wpiutil
### Third Party Artifacts
This repository provides the builds of the following third party software.
All artifacts are based at `edu.wpi.first.thirdparty.frcYEAR` in the repository.
* googletest
* imgui
* opencv
* libssh

View File

@@ -1,6 +1,6 @@
# WPILib CMake Support
WPILib is normally built with Gradle, however for some systems, such a linux based coprocessors, Gradle doesn't work correctly, especially if cscore is needed, which requires OpenCV. We provide the CMake build for these cases. Although it is supported on Windows, these docs will only go over linux builds.
WPILib is normally built with Gradle, however for some systems, such as Linux based coprocessors, Gradle doesn't work correctly, especially if cscore is needed, which requires OpenCV. Furthermore, the CMake build can be used for C++ development because it provides better build caching compared to Gradle. We provide the CMake build for these cases. Although it is supported on Windows, these docs will only go over Linux builds.
## Libraries that get built
* wpiutil
@@ -9,56 +9,75 @@ WPILib is normally built with Gradle, however for some systems, such a linux bas
* cameraserver
* hal
* wpilib
* halsim
* wpigui
* wpimath
By default, all libraries except for the HAL and WPILib get built with a default cmake setup. The libraries are built as shared libraries, and include the JNI libraries as well as building the Java jars.
By default, all libraries except for the HAL and WPILib get built with a default CMake setup. The libraries are built as shared libraries, and include the JNI libraries as well as building the Java JARs.
## Prerequisites
The most common prerequisite is going to be OpenCV. OpenCV needs to be findable by cmake. On systems like the Jetson, this is installed by default. Otherwise, you will need to build cmake from source and install it.
The most common prerequisite is going to be OpenCV. OpenCV needs to be findable by CMake. On systems like the Jetson, this is installed by default. Otherwise, you will need to build OpenCV from source and install it.
In addition, if you want JNI and Java, you will need a JDK of at least version 8 installed. In addition, you need a `JAVA_HOME` environment variable set properly and set to the jdk directory.
In addition, if you want JNI and Java, you will need a JDK of at least version 11 installed. In addition, you need a `JAVA_HOME` environment variable set properly and set to the JDK directory.
If you are building with unit tests or simulation modules, you will also need an Internet connection for the initial setup process, as CMake will clone google-test and imgui from GitHub.
## Build Options
The following build options are available:
* WITHOUT_JAVA (OFF Default)
* Enabling this option will disable Java and JNI builds. If this is off, `BUILD_SHARED_LIBS` must be on. Otherwise cmake will error.
* BUILD_SHARED_LIBS (ON Default)
* Disabling this option will cause cmake to build static libraries instead of shared libraries. If this is off, `WITHOUT_JAVA` must be on. Otherwise cmake will error.
* WITHOUT_CSCORE (OFF Default)
* Enabling this option will cause cscore to not be built. This will also implicitly disable cameraserver, the hal and wpilib as well, irrespective of their specific options. If this is on, the opencv build requirement is removed.
* WITHOUT_ALLWPILIB (ON Default)
* Disabling this option will build the hal and wpilib during the build. The HAL is the simulator hal, unless the external hal options are used. The cmake build has no capability to build for the RoboRIO.
* USE_EXTERNAL_HAL (OFF Default)
* `WITH_JAVA` (ON Default)
* This option will enable Java and JNI builds. If this is on, `WITH_SHARED_LIBS` must be on. Otherwise CMake will error.
* `WITH_SHARED_LIBS` (ON Default)
* This option will cause cmake to build static libraries instead of shared libraries. If this is off, `WITH_JAVA` must be off. Otherwise CMake will error.
* `WITH_CSCORE` (ON Default)
* This option will cause cscore to be built. Turning this off will implicitly disable cameraserver, the hal and wpilib as well, irrespective of their specific options. If this is off, the OpenCV build requirement is removed.
* `WITH_NTCORE` (ON Default)
* This option will cause ntcore to be built. Turning this off will implicitly disable wpinet and wpilib as well, irrespective of their specific options.
* `WITH_WPIMATH` (ON Default)
* This option will build the wpimath library. This option must be on to build wpilib.
* `WITH_WPILIB` (ON Default)
* This option will build the hal and wpilibc/j during the build. The HAL is the simulator hal, unless the external hal options are used. The cmake build has no capability to build for the RoboRIO.
* `WITH_EXAMPLES` (ON Default)
* This option will build C++ examples.
* `WITH_TESTS` (ON Default)
* This option will build C++ unit tests. These can be run via `make test`.
* `WITH_GUI` (ON Default)
* This option will build GUI items.
* `WITH_SIMULATION_MODULES` (ON Default)
* This option will build simulation modules, including wpigui and the HALSim plugins.
* `WITH_EXTERNAL_HAL` (OFF Default)
* TODO
* EXTERNAL_HAL_FILE
* `EXTERNAL_HAL_FILE`
* TODO
* `OPENCV_JAVA_INSTALL_DIR`
* Set this option to the location of the archive of the OpenCV Java bindings (it should be called opencv-xxx.jar, with the x'es being version numbers). NOTE: set it to the LOCATION of the file, not the file itself!
## Build Setup
The WPILib CMake build does not allow in source builds. Because the `build` directory is used by gradle, we recommend a `buildcmake` directory in the root. This folder is included in the gitignore.
The WPILib CMake build does not allow in source builds. Because the `build` directory is used by Gradle, we recommend a `build-cmake` directory in the root. This folder is included in the gitignore.
Once you have a build folder, run cmake configuration in that build directory with the following command.
Once you have a build folder, run CMake configuration in that build directory with the following command.
```
cmake path/to/allwpilib/root
```
If you want to change any of the options, add `-DOPTIONHERE=VALUE` to the cmake command. This will check for any dependencies. If everything works properly this will succeed. If not, please check out the troubleshooting section for help.
If you want to change any of the options, add `-DOPTIONHERE=VALUE` to the `cmake` command. This will check for any dependencies. If everything works properly this will succeed. If not, please check out the troubleshooting section for help.
If you want, you can also use `ccmake` in order to visually set these properties as well.
https://cmake.org/cmake/help/v3.0/manual/ccmake.1.html
Here is the link to the documentation for that program.
If you want, you can also use `ccmake` in order to visually set these properties as well. [Here](https://cmake.org/cmake/help/v3.0/manual/ccmake.1.html) is the link to the documentation for that program.
## Building
Once you have cmake setup. run `make` from the directory you configured cmake in. This will build all libraries possible. If you have a multicore system, we recommend running make with multiple jobs. The usual rule of thumb is 1.5x the number of cores you have. To run a multiple job build, run the following command with x being the number of jobs you want.
Once you have cmake setup. run `make` from the directory you configured CMake in. This will build all libraries possible. If you have a multicore system, we recommend running `make` with multiple jobs. The usual rule of thumb is 1.5x the number of cores you have. To run a multiple job build, run the following command with x being the number of jobs you want.
```
make -jx
```
The `ninja` generator is also supported, and can be enabled by passing `-GNinja` to the initial `cmake` command.
## Installing
After build, the easiest way to use the libraries is to install them. Run the following command to install the libraries. This will install them so that they can be used from external cmake projects.
@@ -79,7 +98,7 @@ project(vision_app) # Project Name Here
find_package(wpilib REQUIRED)
add_executable(my_vision_app main.cpp) # exectuable name as first parameter
add_executable(my_vision_app main.cpp) # executable name as first parameter
target_link_libraries(my_vision_app cameraserver ntcore cscore wpiutil)
```
@@ -135,4 +154,4 @@ CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:
If this happens, make sure you have a JDK of at least version 8 installed, and that your JAVA_HOME variable is set properly to point to the JDK.
In addition, if you do not need Java, you can disable it with `-DWITHOUT_JAVA=ON`.
In addition, if you do not need Java, you can disable it with `-DWITH_JAVA=OFF`.

122
README.md
View File

@@ -1,21 +1,38 @@
# WPILib Project
[![Build Status](https://dev.azure.com/wpilib/wpilib/_apis/build/status/wpilibsuite.allwpilib)](https://dev.azure.com/wpilib/wpilib/_build/latest?definitionId=1)
[![Gradle](https://github.com/wpilibsuite/allwpilib/actions/workflows/gradle.yml/badge.svg?branch=main)](https://github.com/wpilibsuite/allwpilib/actions/workflows/gradle.yml)
[![C++ Documentation](https://img.shields.io/badge/documentation-c%2B%2B-blue)](https://github.wpilib.org/allwpilib/docs/development/cpp/)
[![Java Documentation](https://img.shields.io/badge/documentation-java-orange)](https://github.wpilib.org/allwpilib/docs/development/java/)
Welcome to the WPILib project. This repository contains the HAL, WPILibJ, and WPILibC projects. These are the core libraries for creating robot programs for the roboRIO.
- [WPILib Mission](#wpilib-mission)
- [WPILib Project](#wpilib-project)
- [WPILib Mission](#wpilib-mission)
- [Building WPILib](#building-wpilib)
- [Requirements](#requirements)
- [Setup](#setup)
- [Building](#building)
- [Publishing](#publishing)
- [Structure and Organization](#structure-and-organization)
- [Requirements](#requirements)
- [Setup](#setup)
- [Building](#building)
- [Faster builds](#faster-builds)
- [Using Development Builds](#using-development-builds)
- [Custom toolchain location](#custom-toolchain-location)
- [Formatting/Linting](#formattinglinting)
- [CMake](#cmake)
- [Publishing](#publishing)
- [Structure and Organization](#structure-and-organization)
- [Contributing to WPILib](#contributing-to-wpilib)
## WPILib Mission
The WPILib Mission is to enable FIRST Robotics teams to focus on writing game-specific software rather than focusing on hardware details - "raise the floor, don't lower the ceiling". We work to enable teams with limited programming knowledge and/or mentor experience to be as successful as possible, while not hampering the abilities of teams with more advanced programming capabilities. We support Kit of Parts control system components directly in the library. We also strive to keep parity between major features of each language (Java, C++, and NI's LabVIEW), so that teams aren't at a disadvantage for choosing a specific programming language. WPILib is an open source project, licensed under the BSD 3-clause license. You can find a copy of the license [here](LICENSE.txt).
The WPILib Mission is to enable FIRST Robotics teams to focus on writing game-specific software rather than focusing on hardware details - "raise the floor, don't lower the ceiling". We work to enable teams with limited programming knowledge and/or mentor experience to be as successful as possible, while not hampering the abilities of teams with more advanced programming capabilities. We support Kit of Parts control system components directly in the library. We also strive to keep parity between major features of each language (Java, C++, and NI's LabVIEW), so that teams aren't at a disadvantage for choosing a specific programming language. WPILib is an open source project, licensed under the BSD 3-clause license. You can find a copy of the license [here](LICENSE.md).
# Quick Start
Below is a list of instructions that guide you through cloning, building, publishing and using local allwpilib binaries in a robot project. This quick start is not intended as a replacement for the information further listed in this document.
1. Clone the repository with `git clone https://github.com/wpilibsuite/allwpilib.git`
2. Build the repository with `./gradlew build` or `./gradlew build --build-cache` if you have an internet connection
3. Publish the artifacts locally by running `./gradlew publish`
4. [Update your](DevelopmentBuilds.md) `build.gradle` [to use the artifacts](DevelopmentBuilds.md)
# Building WPILib
@@ -23,19 +40,28 @@ Using Gradle makes building WPILib very straightforward. It only has a few depen
## Requirements
- A C++ compiler
- On Linux, GCC works fine
- On Windows, you need Visual Studio 2019 (the free community edition works fine).
Make sure to select the C++ Programming Language for installation
- [ARM Compiler Toolchain](https://github.com/wpilibsuite/toolchain-builder/releases)
* Note that for 2020 and beyond, you should use version 7 or greater of GCC
- Doxygen (Only required if you want to build the C++ documentation)
- [JDK 11](https://adoptium.net/temurin/releases/?version=11)
- Note that the JRE is insufficient; the full JDK is required
- On Ubuntu, run `sudo apt install openjdk-11-jdk`
- On Windows, install the JDK 11 .msi from the link above
- On macOS, install the JDK 11 .pkg from the link above
- C++ compiler
- On Linux, install GCC 11 or greater
- On Windows, install [Visual Studio Community 2022](https://visualstudio.microsoft.com/vs/community/) and select the C++ programming language during installation (Gradle can't use the build tools for Visual Studio)
- On macOS, install the Xcode command-line build tools via `xcode-select --install`. Xcode 13 or later is required.
- ARM compiler toolchain
- Run `./gradlew installRoboRioToolchain` after cloning this repository
- If the WPILib installer was used, this toolchain is already installed
- Raspberry Pi toolchain (optional)
- Run `./gradlew installArm32Toolchain` after cloning this repository
On macOS ARM, run `softwareupdate --install-rosetta`. This is necessary to be able to use the macOS x86 roboRIO toolchain on ARM.
## Setup
Clone the WPILib repository. If the toolchains are not installed, install them, and make sure they are available on the system PATH.
Clone the WPILib repository and follow the instructions above for installing any required tooling.
See the [styleguide README](https://github.com/wpilibsuite/styleguide/blob/master/README.md) for wpiformat setup instructions.
See the [styleguide README](https://github.com/wpilibsuite/styleguide/blob/main/README.md) for wpiformat setup instructions. We use clang-format 14.
## Building
@@ -51,33 +77,57 @@ To build a specific subproject, such as WPILibC, you must access the subproject
./gradlew :wpilibc:build
```
The gradlew wrapper only exists in the root of the main project, so be sure to run all commands from there. All of the subprojects have build tasks that can be run. Gradle automatically determines and rebuilds dependencies, so if you make a change in the HAL and then run `./gradlew :wpilibc:build`, the HAL will be rebuilt, then WPILibC.
There are a few tasks other than `build` available. To see them, run the meta-task `tasks`. This will print a list of all available tasks, with a description of each task.
If opening from a fresh clone, generated java dependencies will not exist. Most IDEs will not run the generation tasks, which will cause lots of IDE errors. Manually run `./gradlew compileJava` from a terminal to run all the compile tasks, and then refresh your IDE's configuration (In VS Code open settings.gradle and save).
### Faster builds
`./gradlew build` builds _everything_, which includes debug and release builds for desktop and all installed cross compilers. Many developers don't need or want to build all of this. Therefore, common tasks have shortcuts to only build necessary components for common development and testing tasks.
`./gradlew testDesktopCpp` and `./gradlew testDesktopJava` will build and run the tests for `wpilibc` and `wpilibj` respectively. They will only build the minimum components required to run the tests.
`testDesktopCpp` and `testDesktopJava` tasks also exist for the projects `wpiutil`, `ntcore`, `cscore`, `hal` `wpilibNewCommands` and `cameraserver`. These can be ran with `./gradlew :projectName:task`.
`./gradlew buildDesktopCpp` and `./gradlew buildDesktopJava` will compile `wpilibcExamples` and `wpilibjExamples` respectively. The results can't be ran, but they can compile.
### Build Cache
Run with `--build-cache` on the command-line to use the shared [build cache](https://docs.gradle.org/current/userguide/build_cache.html) artifacts generated by the continuous integration server. Example:
```bash
./gradlew build --build-cache
```
### Using Development Builds
Please read the documentation available [here](DevelopmentBuilds.md)
### Custom toolchain location
If you have installed the FRC Toolchain to a directory other than the default, or if the Toolchain location is not on your System PATH, you can pass the `toolChainPath` property to specify where it is located. Example:
```bash
./gradlew build -PtoolChainPath=some/path/to/frc/toolchain/bin
```
If you also want simulation to be built, add -PmakeSim. This requires gazebo_transport. We have tested on 14.04 and 15.05, but any correct install of Gazebo should work, even on Windows if you build Gazebo from source. Correct means CMake needs to be able to find gazebo-config.cmake. See [The Gazebo website](https://gazebosim.org/) for installation instructions.
### Formatting/linting
```bash
./gradlew build -PmakeSim
```
Once a PR has been submitted, formatting can be run in CI by commenting `/format` on the PR. A new commit will be pushed with the formatting changes.
If you prefer to use CMake directly, the you can still do so.
The common CMake tasks are wpilibcSim, frc_gazebo_plugins, and gz_msgs
#### wpiformat
```bash
mkdir build #run this in the root of allwpilib
cd build
cmake ..
make
```
wpiformat can be executed anywhere in the repository via `py -3 -m wpiformat -clang 14` on Windows or `python3 -m wpiformat -clang 14` on other platforms.
The gradlew wrapper only exists in the root of the main project, so be sure to run all commands from there. All of the subprojects have build tasks that can be run. Gradle automatically determines and rebuilds dependencies, so if you make a change in the HAL and then run `./gradlew :wpilibc:build`, the HAL will be rebuilt, then WPILibC.
#### Java Code Quality Tools
There are a few tasks other than `build` available. To see them, run the meta-task `tasks`. This will print a list of all available tasks, with a description of each task.
The Java code quality tools Checkstyle, PMD, and Spotless can be run via `./gradlew javaFormat`. SpotBugs can be run via the `spotbugsMain`, `spotbugsTest`, and `spotbugsDev` tasks. These tools will all be run automatically by the `build` task. To disable this behavior, pass the `-PskipJavaFormat` flag.
wpiformat can be executed anywhere in the repository via `py -3 -m wpiformat` on Windows or `python3 -m wpiformat` on other platforms.
If you only want to run the Java autoformatter, run `./gradlew spotlessApply`.
### CMake
CMake is also supported for building. See [README-CMAKE.md](README-CMAKE.md).
@@ -94,13 +144,13 @@ The maven artifacts are described in [MavenArtifacts.md](MavenArtifacts.md)
## Structure and Organization
The main WPILib code you're probably looking for is in WPILibJ and WPILibC. Those directories are split into shared, sim, and athena. Athena contains the WPILib code meant to run on your roboRIO. Sim is WPILib code meant to run on your computer with Gazebo, and shared is code shared between the two. Shared code must be platform-independent, since it will be compiled with both the ARM cross-compiler and whatever desktop compiler you are using (g++, msvc, etc...).
The Simulation directory contains extra simulation tools and libraries, such as gz_msgs and JavaGazebo. See sub-directories for more information.
The main WPILib code you're probably looking for is in WPILibJ and WPILibC. Those directories are split into shared, sim, and athena. Athena contains the WPILib code meant to run on your roboRIO. Sim is WPILib code meant to run on your computer, and shared is code shared between the two. Shared code must be platform-independent, since it will be compiled with both the ARM cross-compiler and whatever desktop compiler you are using (g++, msvc, etc...).
The integration test directories for C++ and Java contain test code that runs on our test-system. When you submit code for review, it is tested by those programs. If you add new functionality you should make sure to write tests for it so we don't break it in the future.
The hal directory contains more C++ code meant to run on the roboRIO. HAL is an acronym for "Hardware Abstraction Layer", and it interfaces with the NI Libraries. The NI Libraries contain the low-level code for controlling devices on your robot. The NI Libraries are found in the ni-libraries folder.
The hal directory contains more C++ code meant to run on the roboRIO. HAL is an acronym for "Hardware Abstraction Layer", and it interfaces with the NI Libraries. The NI Libraries contain the low-level code for controlling devices on your robot. The NI Libraries are found in the [ni-libraries](https://github.com/wpilibsuite/ni-libraries) project.
The upstream_utils directory contains scripts for updating copies of thirdparty code in the repository.
The [styleguide repository](https://github.com/wpilibsuite/styleguide) contains our style guides for C++ and Java code. Anything submitted to the WPILib project needs to follow the code style guides outlined in there. For details about the style, please see the contributors document [here](CONTRIBUTING.md#coding-guidelines).

View File

@@ -17,34 +17,35 @@ Program Locations
------- ---------
RoboRIO Libraries ni-libraries
Google Test gtest
LLVM wpiutil/src/main/native/include/wpi/{various files}
wpiutil/src/main/native/cpp/llvm/
wpiutil/src/main/native/cpp/leb128.cpp
wpiutil/src/test/native/cpp/leb128Test.cpp
JSON for Modern C++ wpiutil/src/main/native/include/wpi/json.h
wpiutil/src/main/native/cpp/json_*.cpp
LLVM wpiutil/src/main/native/thirdparty/llvm
wpiutil/src/test/native/cpp/llvm/
JSON for Modern C++ wpiutil/src/main/native/thirdparty/json
wpiutil/src/test/native/cpp/json/
libuv wpiutil/src/main/native/include/uv.h
wpiutil/src/main/native/include/uv/
wpiutil/src/main/native/libuv/
sigslot wpiutil/src/main/native/include/wpi/Signal.h
wpiutil/src/test/native/cpp/sigslot/
tcpsockets wpiutil/src/main/native/cpp/TCP{Stream,Connector,Acceptor}.cpp
wpiutil/src/main/native/include/wpi/TCP*.h
Bootstrap wpiutil/src/main/native/resources/bootstrap-*
CoreUI wpiutil/src/main/native/resources/coreui-*
Feather Icons wpiutil/src/main/native/resources/feather-*
jQuery wpiutil/src/main/native/resources/jquery-*
popper.js wpiutil/src/main/native/resources/popper-*
units wpiutil/src/main/native/include/units/units.h
Eigen wpiutil/src/main/native/eigeninclude/
libuv wpinet/src/main/native/thirdparty/libuv/
fmtlib wpiutil/src/main/native/thirdparty/fmtlib/
sigslot wpiutil/src/main/native/thirdparty/sigslot
tcpsockets wpinet/src/main/native/thirdparty/tcpsockets
MPack wpiutil/src/main/native/thirdparty/mpack
Bootstrap wpinet/src/main/native/resources/bootstrap-*
CoreUI wpinet/src/main/native/resources/coreui-*
Feather Icons wpinet/src/main/native/resources/feather-*
jQuery wpinet/src/main/native/resources/jquery-*
popper.js wpinet/src/main/native/resources/popper-*
units wpimath/src/main/native/include/units/
Eigen wpimath/src/main/native/thirdparty/eigen/include/
StackWalker wpiutil/src/main/native/windows/StackWalker.*
GHC filesystem wpiutil/src/main/native/thirdparty/include/wpi/ghc/
Team 254 Library wpilibj/src/main/java/edu/wpi/first/wpilibj/spline/SplineParameterizer.java
wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryParameterizer.java
wpilibc/src/main/native/include/spline/SplineParameterizer.h
wpilibc/src/main/native/include/trajectory/TrajectoryParameterizer.h
wpilibc/src/main/native/cpp/trajectory/TrajectoryParameterizer.cpp
Portable File Dialogs wpigui/src/main/native/include/portable-file-dialogs.h
Drake wpimath/src/main/native/thirdparty/drake/
wpimath/src/test/native/cpp/drake/
wpimath/src/test/native/include/drake/
V8 export-template wpiutil/src/main/native/include/wpi/SymbolExports.h
GCEM wpimath/src/main/native/thirdparty/gcem/include/
==============================================================================
Google Test License
@@ -80,12 +81,247 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==============================================================================
LLVM Release License
The LLVM Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
---- LLVM Exceptions to the Apache 2.0 License ----
As an exception, if, as a result of your compiling your source code, portions
of this Software are embedded into an Object form of such source code, you
may redistribute such embedded portions in such Object form without complying
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
In addition, if you combine or link compiled forms of this Software with
software that is licensed under the GPLv2 ("Combined Software") and if a
court of competent jurisdiction determines that the patent provision (Section
3), the indemnity provision (Section 9) or other Section of the License
conflicts with the conditions of the GPLv2, you may retroactively and
prospectively choose to deem waived or otherwise exclude such Section(s) of
the License, but only in their entirety and only with respect to the Combined
Software.
==============================================================================
Software from third parties included in the LLVM Project:
==============================================================================
The LLVM Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
==============================================================================
Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy):
==============================================================================
University of Illinois/NCSA
Open Source License
Copyright (c) 2003-2017 University of Illinois at Urbana-Champaign.
Copyright (c) 2003-2019 University of Illinois at Urbana-Champaign.
All rights reserved.
Developed by:
@@ -227,6 +463,32 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================
MPacks License
==============================================================================
The MIT License (MIT)
Copyright (c) 2015-2021 Nicholas Fraser and the MPack authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================
Bootstrap License
==============================================================================
@@ -806,3 +1068,177 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=============
Drake Library
=============
All components of Drake are licensed under the BSD 3-Clause License
shown below. Where noted in the source code, some portions may
be subject to other permissive, non-viral licenses.
Copyright 2012-2016 Robot Locomotion Group @ CSAIL
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Massachusetts Institute of Technology nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=====================
Portable File Dialogs
=====================
Copyright © 2018—2020 Sam Hocevar <sam@hocevar.net>
This library is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What the **** You Want
to Public License, Version 2, as published by the WTFPL Task Force.
See http://www.wtfpl.net/ for more details.
======================
Boost Software License
======================
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
======
fmtlib
======
Copyright (c) 2012 - present, Victor Zverovich
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- Optional exception to the license ---
As an exception, if, as a result of your compiling your source code, portions
of this Software are embedded into a machine-executable object form of such
source code, you may redistribute such embedded portions in such object form
without including the above copyright and permission notices.
==============
GHC filesystem
==============
Copyright (c) 2018, Steffen Schümann <s.schuemann@pobox.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==================
V8 export-template
==================
Copyright 2014, the V8 project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
============
GCEM License
============
Copyright 2022 - ktholer (https://github.com/kthohr/gcem)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

118
apriltag/CMakeLists.txt Normal file
View File

@@ -0,0 +1,118 @@
project(apriltag)
include(CompileWarnings)
include(GenResources)
include(FetchContent)
FetchContent_Declare(
apriltaglib
GIT_REPOSITORY https://github.com/wpilibsuite/apriltag.git
GIT_TAG ad31e33d20f9782b7239cb15cde57c56c91383ad
)
# Don't use apriltag's CMakeLists.txt due to conflicting naming and JNI
FetchContent_GetProperties(apriltaglib)
if(NOT apriltaglib_POPULATED)
FetchContent_Populate(apriltaglib)
endif()
aux_source_directory(${apriltaglib_SOURCE_DIR}/common APRILTAGLIB_COMMON_SRC)
file(GLOB TAG_FILES ${apriltaglib_SOURCE_DIR}/tag*.c)
set(APRILTAGLIB_SRCS ${apriltaglib_SOURCE_DIR}/apriltag.c ${apriltaglib_SOURCE_DIR}/apriltag_pose.c ${apriltaglib_SOURCE_DIR}/apriltag_quad_thresh.c)
file(GLOB apriltag_jni_src src/main/native/cpp/jni/AprilTagJNI.cpp)
if (WITH_JAVA)
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
include(UseJava)
set(CMAKE_JAVA_COMPILE_FLAGS "-encoding" "UTF8" "-Xlint:unchecked")
set(CMAKE_JNI_TARGET true)
file(GLOB EJML_JARS "${WPILIB_BINARY_DIR}/wpimath/thirdparty/ejml/*.jar")
file(GLOB JACKSON_JARS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson/*.jar")
find_file(OPENCV_JAR_FILE
NAMES opencv-${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.jar
PATHS ${OPENCV_JAVA_INSTALL_DIR} ${OpenCV_INSTALL_PATH}/bin ${OpenCV_INSTALL_PATH}/share/java
NO_DEFAULT_PATH)
set(CMAKE_JAVA_INCLUDE_PATH apriltag.jar ${EJML_JARS} ${JACKSON_JARS})
file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java)
file(GLOB_RECURSE JAVA_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/main/native/resources/*.json)
add_jar(apriltag_jar
SOURCES ${JAVA_SOURCES}
RESOURCES NAMESPACE "edu/wpi/first/apriltag" ${JAVA_RESOURCES}
INCLUDE_JARS wpimath_jar ${EJML_JARS} wpiutil_jar ${OPENCV_JAR_FILE}
OUTPUT_NAME apriltag
GENERATE_NATIVE_HEADERS apriltag_jni_headers)
get_property(APRILTAG_JAR_FILE TARGET apriltag_jar PROPERTY JAR_FILE)
install(FILES ${APRILTAG_JAR_FILE} DESTINATION "${java_lib_dest}")
set_property(TARGET apriltag_jar PROPERTY FOLDER "java")
add_library(apriltagjni ${apriltag_jni_src})
wpilib_target_warnings(apriltagjni)
target_link_libraries(apriltagjni PUBLIC apriltag)
set_property(TARGET apriltagjni PROPERTY FOLDER "libraries")
target_link_libraries(apriltagjni PRIVATE apriltag_jni_headers)
add_dependencies(apriltagjni apriltag_jar)
if (MSVC)
install(TARGETS apriltagjni RUNTIME DESTINATION "${jni_lib_dest}" COMPONENT Runtime)
endif()
install(TARGETS apriltagjni EXPORT apriltagjni DESTINATION "${main_lib_dest}")
endif()
GENERATE_RESOURCES(src/main/native/resources/edu/wpi/first/apriltag generated/main/cpp APRILTAG frc apriltag_resources_src)
file(GLOB apriltag_native_src src/main/native/cpp/*.cpp)
add_library(apriltag ${apriltag_native_src} ${apriltag_resources_src} ${APRILTAGLIB_SRCS} ${APRILTAGLIB_COMMON_SRC} ${TAG_FILES})
set_target_properties(apriltag PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET apriltag PROPERTY FOLDER "libraries")
target_compile_features(apriltag PUBLIC cxx_std_20)
wpilib_target_warnings(apriltag)
# disable warnings that apriltaglib can't handle
if (MSVC)
target_compile_options(apriltag PRIVATE /wd4018)
else()
target_compile_options(apriltag PRIVATE -Wno-sign-compare -Wno-gnu-zero-variadic-macro-arguments)
endif()
target_link_libraries(apriltag wpimath)
target_include_directories(apriltag PUBLIC
$<BUILD_INTERFACE:${apriltaglib_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
$<INSTALL_INTERFACE:${include_dest}/apriltag>)
install(TARGETS apriltag EXPORT apriltag DESTINATION "${main_lib_dest}")
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/apriltag")
if (WITH_JAVA AND MSVC)
install(TARGETS apriltag RUNTIME DESTINATION "${jni_lib_dest}" COMPONENT Runtime)
endif()
if (WITH_FLAT_INSTALL)
set (apriltag_config_dir ${wpilib_dest})
else()
set (apriltag_config_dir share/apriltag)
endif()
configure_file(apriltag-config.cmake.in ${WPILIB_BINARY_DIR}/apriltag-config.cmake )
install(FILES ${WPILIB_BINARY_DIR}/apriltag-config.cmake DESTINATION ${apriltag_config_dir})
install(EXPORT apriltag DESTINATION ${apriltag_config_dir})
if (WITH_TESTS)
wpilib_add_test(apriltag src/test/native/cpp)
target_include_directories(apriltag_test PRIVATE src/test/native/include)
target_link_libraries(apriltag_test apriltag gmock_main)
endif()

View File

@@ -0,0 +1,7 @@
include(CMakeFindDependencyMacro)
@FILENAME_DEP_REPLACE@
@WPIMATH_DEP_REPLACE@
@WPIUTIL_DEP_REPLACE@
@FILENAME_DEP_REPLACE@
include(${SELF_DIR}/apriltag.cmake)

88
apriltag/build.gradle Normal file
View File

@@ -0,0 +1,88 @@
apply from: "${rootDir}/shared/resources.gradle"
ext {
nativeName = 'apriltag'
devMain = 'edu.wpi.first.apriltag.DevMain'
useJava = true
useCpp = true
sharedCvConfigs = [
apriltagDev : [],
apriltagTest: []]
staticCvConfigs = []
def generateTask = createGenerateResourcesTask('main', 'APRILTAG', 'frc', project)
tasks.withType(CppCompile) {
dependsOn generateTask
}
splitSetup = {
it.sources {
resourcesCpp(CppSourceSet) {
source {
srcDirs "$buildDir/generated/main/cpp", "$rootDir/shared/singlelib"
include '*.cpp'
}
}
}
}
}
evaluationDependsOn(':wpimath')
apply from: "${rootDir}/shared/jni/setupBuild.gradle"
apply from: "${rootDir}/shared/apriltaglib.gradle"
apply from: "${rootDir}/shared/opencv.gradle"
dependencies {
implementation project(':wpimath')
devImplementation project(':wpimath')
}
sourceSets {
main {
resources {
srcDirs 'src/main/native/resources'
}
}
}
model {
components {}
binaries {
all {
if (!it.buildable || !(it instanceof NativeBinarySpec)) {
return
}
it.cppCompiler.define 'WPILIB_EXPORTS'
if (it.component.name == "${nativeName}JNI") {
lib project: ':wpimath', library: 'wpimath', linkage: 'static'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
} else {
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
}
nativeUtils.useRequiredLibrary(it, 'apriltaglib')
}
}
tasks {
def c = $.components
def found = false
def systemArch = getCurrentArch()
c.each {
if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
it.binaries.each {
if (!found) {
def arch = it.targetPlatform.name
if (arch == systemArch) {
def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
found = true
}
}
}
}
}
}
}

View File

@@ -0,0 +1,20 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
public final class DevMain {
/** Main entry point. */
public static void main(String[] args) {
System.out.println("Hello World!");
AprilTagDetector detector = new AprilTagDetector();
detector.addFamily("tag16h5");
AprilTagDetector.Config config = new AprilTagDetector.Config();
config.refineEdges = false;
detector.setConfig(config);
detector.close();
}
private DevMain() {}
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagDetector.h"
int main() {
frc::AprilTagDetector detector;
detector.AddFamily("tag16h5");
detector.SetConfig({.refineEdges = false});
}

View File

@@ -0,0 +1,47 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.math.geometry.Pose3d;
import java.util.Objects;
@SuppressWarnings("MemberName")
public class AprilTag {
@JsonProperty(value = "ID")
public int ID;
@JsonProperty(value = "pose")
public Pose3d pose;
@SuppressWarnings("ParameterName")
@JsonCreator
public AprilTag(
@JsonProperty(required = true, value = "ID") int ID,
@JsonProperty(required = true, value = "pose") Pose3d pose) {
this.ID = ID;
this.pose = pose;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof AprilTag) {
var other = (AprilTag) obj;
return ID == other.ID && pose.equals(other.pose);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(ID, pose);
}
@Override
public String toString() {
return "AprilTag(ID: " + ID + ", pose: " + pose + ")";
}
}

View File

@@ -0,0 +1,190 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import edu.wpi.first.math.MatBuilder;
import edu.wpi.first.math.Matrix;
import edu.wpi.first.math.Nat;
import edu.wpi.first.math.numbers.N3;
import java.util.Arrays;
/** A detection of an AprilTag tag. */
public class AprilTagDetection {
/**
* Gets the decoded tag's family name.
*
* @return Decoded family name
*/
public String getFamily() {
return m_family;
}
/**
* Gets the decoded ID of the tag.
*
* @return Decoded ID
*/
public int getId() {
return m_id;
}
/**
* Gets how many error bits were corrected. Note: accepting large numbers of corrected errors
* leads to greatly increased false positive rates. NOTE: As of this implementation, the detector
* cannot detect tags with a hamming distance greater than 2.
*
* @return Hamming distance (number of corrected error bits)
*/
public int getHamming() {
return m_hamming;
}
/**
* Gets a measure of the quality of the binary decoding process: the average difference between
* the intensity of a data bit versus the decision threshold. Higher numbers roughly indicate
* better decodes. This is a reasonable measure of detection accuracy only for very small tags--
* not effective for larger tags (where we could have sampled anywhere within a bit cell and still
* gotten a good detection.)
*
* @return Decision margin
*/
public float getDecisionMargin() {
return m_decisionMargin;
}
/**
* Gets the 3x3 homography matrix describing the projection from an "ideal" tag (with corners at
* (-1,1), (1,1), (1,-1), and (-1, -1)) to pixels in the image.
*
* @return Homography matrix data
*/
@SuppressWarnings("PMD.MethodReturnsInternalArray")
public double[] getHomography() {
return m_homography;
}
/**
* Gets the 3x3 homography matrix describing the projection from an "ideal" tag (with corners at
* (-1,1), (1,1), (1,-1), and (-1, -1)) to pixels in the image.
*
* @return Homography matrix
*/
public Matrix<N3, N3> getHomographyMatrix() {
return new MatBuilder<>(Nat.N3(), Nat.N3()).fill(m_homography);
}
/**
* Gets the center of the detection in image pixel coordinates.
*
* @return Center point X coordinate
*/
public double getCenterX() {
return m_centerX;
}
/**
* Gets the center of the detection in image pixel coordinates.
*
* @return Center point Y coordinate
*/
public double getCenterY() {
return m_centerY;
}
/**
* Gets a corner of the tag in image pixel coordinates. These always wrap counter-clock wise
* around the tag.
*
* @param ndx Corner index (range is 0-3, inclusive)
* @return Corner point X coordinate
*/
public double getCornerX(int ndx) {
return m_corners[ndx * 2];
}
/**
* Gets a corner of the tag in image pixel coordinates. These always wrap counter-clock wise
* around the tag.
*
* @param ndx Corner index (range is 0-3, inclusive)
* @return Corner point Y coordinate
*/
public double getCornerY(int ndx) {
return m_corners[ndx * 2 + 1];
}
/**
* Gets the corners of the tag in image pixel coordinates. These always wrap counter-clock wise
* around the tag.
*
* @return Corner point array (X and Y for each corner in order)
*/
@SuppressWarnings("PMD.MethodReturnsInternalArray")
public double[] getCorners() {
return m_corners;
}
private final String m_family;
private final int m_id;
private final int m_hamming;
private final float m_decisionMargin;
private final double[] m_homography;
private final double m_centerX;
private final double m_centerY;
private final double[] m_corners;
/**
* Constructs a new detection result. Used from JNI.
*
* @param family family
* @param id id
* @param hamming hamming
* @param decisionMargin dm
* @param homography homography
* @param centerX centerX
* @param centerY centerY
* @param corners corners
*/
@SuppressWarnings("PMD.ArrayIsStoredDirectly")
public AprilTagDetection(
String family,
int id,
int hamming,
float decisionMargin,
double[] homography,
double centerX,
double centerY,
double[] corners) {
m_family = family;
m_id = id;
m_hamming = hamming;
m_decisionMargin = decisionMargin;
m_homography = homography;
m_centerX = centerX;
m_centerY = centerY;
m_corners = corners;
}
@Override
public String toString() {
return "DetectionResult [centerX="
+ m_centerX
+ ", centerY="
+ m_centerY
+ ", corners="
+ Arrays.toString(m_corners)
+ ", decisionMargin="
+ m_decisionMargin
+ ", hamming="
+ m_hamming
+ ", homography="
+ Arrays.toString(m_homography)
+ ", family="
+ m_family
+ ", id="
+ m_id
+ "]";
}
}

View File

@@ -0,0 +1,281 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import edu.wpi.first.apriltag.jni.AprilTagJNI;
import org.opencv.core.Mat;
/**
* An AprilTag detector engine. This is expensive to set up and tear down, so most use cases should
* only create one of these, add a family to it, set up any other configuration, and repeatedly call
* Detect().
*/
public class AprilTagDetector implements AutoCloseable {
/** Detector configuration. */
@SuppressWarnings("MemberName")
public static class Config {
/**
* How many threads should be used for computation. Default is single-threaded operation (1
* thread).
*/
public int numThreads = 1;
/**
* Quad decimation. Detection of quads can be done on a lower-resolution image, improving speed
* at a cost of pose accuracy and a slight decrease in detection rate. Decoding the binary
* payload is still done at full resolution. Default is 2.0.
*/
public float quadDecimate = 2.0f;
/**
* What Gaussian blur should be applied to the segmented image (used for quad detection). Very
* noisy images benefit from non-zero values (e.g. 0.8). Default is 0.0.
*/
public float quadSigma;
/**
* When true, the edges of the each quad are adjusted to "snap to" strong gradients nearby. This
* is useful when decimation is employed, as it can increase the quality of the initial quad
* estimate substantially. Generally recommended to be on (true). Default is true.
*
* <p>Very computationally inexpensive. Option is ignored if quad_decimate = 1.
*/
public boolean refineEdges = true;
/**
* How much sharpening should be done to decoded images. This can help decode small tags but may
* or may not help in odd lighting conditions or low light conditions. Default is 0.25.
*/
public double decodeSharpening = 0.25;
/**
* Debug mode. When true, the decoder writes a variety of debugging images to the current
* working directory at various stages through the detection process. This is slow and should
* *not* be used on space-limited systems such as the RoboRIO. Default is disabled (false).
*/
public boolean debug;
public Config() {}
Config(
int numThreads,
float quadDecimate,
float quadSigma,
boolean refineEdges,
double decodeSharpening,
boolean debug) {
this.numThreads = numThreads;
this.quadDecimate = quadDecimate;
this.quadSigma = quadSigma;
this.refineEdges = refineEdges;
this.decodeSharpening = decodeSharpening;
this.debug = debug;
}
@Override
public int hashCode() {
return numThreads
+ Float.hashCode(quadDecimate)
+ Float.hashCode(quadSigma)
+ Boolean.hashCode(refineEdges)
+ Double.hashCode(decodeSharpening)
+ Boolean.hashCode(debug);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Config)) {
return false;
}
Config other = (Config) obj;
return numThreads == other.numThreads
&& quadDecimate == other.quadDecimate
&& quadSigma == other.quadSigma
&& refineEdges == other.refineEdges
&& decodeSharpening == other.decodeSharpening
&& debug == other.debug;
}
}
/** Quad threshold parameters. */
@SuppressWarnings("MemberName")
public static class QuadThresholdParameters {
/** Threshold used to reject quads containing too few pixels. Default is 5 pixels. */
public int minClusterPixels = 5;
/**
* How many corner candidates to consider when segmenting a group of pixels into a quad. Default
* is 10.
*/
public int maxNumMaxima = 10;
/**
* Critical angle, in radians. The detector will reject quads where pairs of edges have angles
* that are close to straight or close to 180 degrees. Zero means that no quads are rejected.
* Default is 10 degrees.
*/
public double criticalAngle = 10 * Math.PI / 180.0;
/**
* When fitting lines to the contours, the maximum mean squared error allowed. This is useful in
* rejecting contours that are far from being quad shaped; rejecting these quads "early" saves
* expensive decoding processing. Default is 10.0.
*/
public float maxLineFitMSE = 10.0f;
/**
* Minimum brightness offset. When we build our model of black &amp; white pixels, we add an
* extra check that the white model must be (overall) brighter than the black model. How much
* brighter? (in pixel values, [0,255]). Default is 5.
*/
public int minWhiteBlackDiff = 5;
/**
* Whether the thresholded image be should be deglitched. Only useful for very noisy images.
* Default is disabled (false).
*/
public boolean deglitch;
public QuadThresholdParameters() {}
QuadThresholdParameters(
int minClusterPixels,
int maxNumMaxima,
double criticalAngle,
float maxLineFitMSE,
int minWhiteBlackDiff,
boolean deglitch) {
this.minClusterPixels = minClusterPixels;
this.maxNumMaxima = maxNumMaxima;
this.criticalAngle = criticalAngle;
this.maxLineFitMSE = maxLineFitMSE;
this.minWhiteBlackDiff = minWhiteBlackDiff;
this.deglitch = deglitch;
}
@Override
public int hashCode() {
return minClusterPixels
+ maxNumMaxima
+ Double.hashCode(criticalAngle)
+ Float.hashCode(maxLineFitMSE)
+ minWhiteBlackDiff
+ Boolean.hashCode(deglitch);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof QuadThresholdParameters)) {
return false;
}
QuadThresholdParameters other = (QuadThresholdParameters) obj;
return minClusterPixels == other.minClusterPixels
&& maxNumMaxima == other.maxNumMaxima
&& criticalAngle == other.criticalAngle
&& maxLineFitMSE == other.maxLineFitMSE
&& minWhiteBlackDiff == other.minWhiteBlackDiff
&& deglitch == other.deglitch;
}
}
public AprilTagDetector() {
m_native = AprilTagJNI.createDetector();
}
@Override
public void close() {
if (m_native != 0) {
AprilTagJNI.destroyDetector(m_native);
}
m_native = 0;
}
/**
* Sets detector configuration.
*
* @param config Configuration
*/
public void setConfig(Config config) {
AprilTagJNI.setDetectorConfig(m_native, config);
}
/**
* Gets detector configuration.
*
* @return Configuration
*/
public Config getConfig() {
return AprilTagJNI.getDetectorConfig(m_native);
}
/**
* Sets quad threshold parameters.
*
* @param params Parameters
*/
public void setQuadThresholdParameters(QuadThresholdParameters params) {
AprilTagJNI.setDetectorQTP(m_native, params);
}
/**
* Gets quad threshold parameters.
*
* @return Parameters
*/
public QuadThresholdParameters getQuadThresholdParameters() {
return AprilTagJNI.getDetectorQTP(m_native);
}
/**
* Adds a family of tags to be detected.
*
* @param fam Family name, e.g. "tag16h5"
* @throws IllegalArgumentException if family name not recognized
*/
public void addFamily(String fam) {
addFamily(fam, 2);
}
/**
* Adds a family of tags to be detected.
*
* @param fam Family name, e.g. "tag16h5"
* @param bitsCorrected maximum number of bits to correct
* @throws IllegalArgumentException if family name not recognized
*/
public void addFamily(String fam, int bitsCorrected) {
if (!AprilTagJNI.addFamily(m_native, fam, bitsCorrected)) {
throw new IllegalArgumentException("unknown family name '" + fam + "'");
}
}
/**
* Removes a family of tags from the detector.
*
* @param fam Family name, e.g. "tag16h5"
*/
public void removeFamily(String fam) {
AprilTagJNI.removeFamily(m_native, fam);
}
/** Unregister all families. */
public void clearFamilies() {
AprilTagJNI.clearFamilies(m_native);
}
/**
* Detect tags from an 8-bit image.
*
* @param img 8-bit OpenCV Mat image
* @return Results (array of AprilTagDetection)
*/
public AprilTagDetection[] detect(Mat img) {
return AprilTagJNI.detect(m_native, img.cols(), img.rows(), img.cols(), img.dataAddr());
}
private long m_native;
}

View File

@@ -0,0 +1,241 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Translation3d;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* Class for representing a layout of AprilTags on a field and reading them from a JSON format.
*
* <p>The JSON format contains two top-level objects, "tags" and "field". The "tags" object is a
* list of all AprilTags contained within a layout. Each AprilTag serializes to a JSON object
* containing an ID and a Pose3d. The "field" object is a descriptor of the size of the field in
* meters with "width" and "length" values. This is to account for arbitrary field sizes when
* transforming the poses.
*
* <p>Pose3ds in the JSON are measured using the normal FRC coordinate system, NWU with the origin
* at the bottom-right corner of the blue alliance wall. {@link #setOrigin(OriginPosition)} can be
* used to change the poses returned from {@link AprilTagFieldLayout#getTagPose(int)} to be from the
* perspective of a specific alliance.
*
* <p>Tag poses represent the center of the tag, with a zero rotation representing a tag that is
* upright and facing away from the (blue) alliance wall (that is, towards the opposing alliance).
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.NONE)
public class AprilTagFieldLayout {
public enum OriginPosition {
kBlueAllianceWallRightSide,
kRedAllianceWallRightSide,
}
private final Map<Integer, AprilTag> m_apriltags = new HashMap<>();
@JsonProperty(value = "field")
private FieldDimensions m_fieldDimensions;
private Pose3d m_origin;
/**
* Construct a new AprilTagFieldLayout with values imported from a JSON file.
*
* @param path Path of the JSON file to import from.
* @throws IOException If reading from the file fails.
*/
public AprilTagFieldLayout(String path) throws IOException {
this(Path.of(path));
}
/**
* Construct a new AprilTagFieldLayout with values imported from a JSON file.
*
* @param path Path of the JSON file to import from.
* @throws IOException If reading from the file fails.
*/
public AprilTagFieldLayout(Path path) throws IOException {
AprilTagFieldLayout layout =
new ObjectMapper().readValue(path.toFile(), AprilTagFieldLayout.class);
m_apriltags.putAll(layout.m_apriltags);
m_fieldDimensions = layout.m_fieldDimensions;
setOrigin(OriginPosition.kBlueAllianceWallRightSide);
}
/**
* Construct a new AprilTagFieldLayout from a list of {@link AprilTag} objects.
*
* @param apriltags List of {@link AprilTag}.
* @param fieldLength Length of the field the layout is representing in meters.
* @param fieldWidth Width of the field the layout is representing in meters.
*/
public AprilTagFieldLayout(List<AprilTag> apriltags, double fieldLength, double fieldWidth) {
this(apriltags, new FieldDimensions(fieldLength, fieldWidth));
}
@JsonCreator
private AprilTagFieldLayout(
@JsonProperty(required = true, value = "tags") List<AprilTag> apriltags,
@JsonProperty(required = true, value = "field") FieldDimensions fieldDimensions) {
// To ensure the underlying semantics don't change with what kind of list is passed in
for (AprilTag tag : apriltags) {
m_apriltags.put(tag.ID, tag);
}
m_fieldDimensions = fieldDimensions;
setOrigin(OriginPosition.kBlueAllianceWallRightSide);
}
/**
* Returns a List of the {@link AprilTag AprilTags} used in this layout.
*
* @return The {@link AprilTag AprilTags} used in this layout.
*/
@JsonProperty("tags")
public List<AprilTag> getTags() {
return new ArrayList<>(m_apriltags.values());
}
/**
* Sets the origin based on a predefined enumeration of coordinate frame origins. The origins are
* calculated from the field dimensions.
*
* <p>This transforms the Pose3d objects returned by {@link #getTagPose(int)} to return the
* correct pose relative to a predefined coordinate frame.
*
* @param origin The predefined origin
*/
@JsonIgnore
public void setOrigin(OriginPosition origin) {
switch (origin) {
case kBlueAllianceWallRightSide:
setOrigin(new Pose3d());
break;
case kRedAllianceWallRightSide:
setOrigin(
new Pose3d(
new Translation3d(m_fieldDimensions.fieldLength, m_fieldDimensions.fieldWidth, 0),
new Rotation3d(0, 0, Math.PI)));
break;
default:
throw new IllegalArgumentException("Unsupported enum value");
}
}
/**
* Sets the origin for tag pose transformation.
*
* <p>This transforms the Pose3d objects returned by {@link #getTagPose(int)} to return the
* correct pose relative to the provided origin.
*
* @param origin The new origin for tag transformations
*/
@JsonIgnore
public void setOrigin(Pose3d origin) {
m_origin = origin;
}
/**
* Gets an AprilTag pose by its ID.
*
* @param ID The ID of the tag.
* @return The pose corresponding to the ID passed in or an empty optional if a tag with that ID
* was not found.
*/
@SuppressWarnings("ParameterName")
public Optional<Pose3d> getTagPose(int ID) {
AprilTag tag = m_apriltags.get(ID);
if (tag == null) {
return Optional.empty();
}
return Optional.of(tag.pose.relativeTo(m_origin));
}
/**
* Serializes a AprilTagFieldLayout to a JSON file.
*
* @param path The path to write to.
* @throws IOException If writing to the file fails.
*/
public void serialize(String path) throws IOException {
serialize(Path.of(path));
}
/**
* Serializes a AprilTagFieldLayout to a JSON file.
*
* @param path The path to write to.
* @throws IOException If writing to the file fails.
*/
public void serialize(Path path) throws IOException {
new ObjectMapper().writeValue(path.toFile(), this);
}
/**
* Deserializes a field layout from a resource within a internal jar file.
*
* <p>Users should use {@link AprilTagFields#loadAprilTagLayoutField()} to load official layouts
* and {@link #AprilTagFieldLayout(String)} for custom layouts.
*
* @param resourcePath The absolute path of the resource
* @return The deserialized layout
* @throws IOException If the resource could not be loaded
*/
public static AprilTagFieldLayout loadFromResource(String resourcePath) throws IOException {
try (InputStream stream = AprilTagFieldLayout.class.getResourceAsStream(resourcePath);
InputStreamReader reader = new InputStreamReader(stream)) {
return new ObjectMapper().readerFor(AprilTagFieldLayout.class).readValue(reader);
}
}
@Override
public boolean equals(Object obj) {
if (obj instanceof AprilTagFieldLayout) {
var other = (AprilTagFieldLayout) obj;
return m_apriltags.equals(other.m_apriltags) && m_origin.equals(other.m_origin);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(m_apriltags, m_origin);
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.NONE)
private static class FieldDimensions {
@SuppressWarnings("MemberName")
@JsonProperty(value = "length")
public double fieldLength;
@SuppressWarnings("MemberName")
@JsonProperty(value = "width")
public double fieldWidth;
@JsonCreator()
FieldDimensions(
@JsonProperty(required = true, value = "length") double fieldLength,
@JsonProperty(required = true, value = "width") double fieldWidth) {
this.fieldLength = fieldLength;
this.fieldWidth = fieldWidth;
}
}
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import java.io.IOException;
public enum AprilTagFields {
k2022RapidReact("2022-rapidreact.json"),
k2023ChargedUp("2023-chargedup.json");
public static final String kBaseResourceDir = "/edu/wpi/first/apriltag/";
/** Alias to the current game. */
public static final AprilTagFields kDefaultField = k2023ChargedUp;
public final String m_resourceFile;
AprilTagFields(String resourceFile) {
m_resourceFile = kBaseResourceDir + resourceFile;
}
/**
* Get a {@link AprilTagFieldLayout} from the resource JSON.
*
* @return AprilTagFieldLayout of the field
* @throws IOException If the layout does not exist
*/
public AprilTagFieldLayout loadAprilTagLayoutField() throws IOException {
return AprilTagFieldLayout.loadFromResource(m_resourceFile);
}
}

View File

@@ -0,0 +1,55 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import edu.wpi.first.math.geometry.Transform3d;
/** A pair of AprilTag pose estimates. */
@SuppressWarnings("MemberName")
public class AprilTagPoseEstimate {
/**
* Constructs a pose estimate.
*
* @param pose1 first pose
* @param pose2 second pose
* @param error1 error of first pose
* @param error2 error of second pose
*/
public AprilTagPoseEstimate(Transform3d pose1, Transform3d pose2, double error1, double error2) {
this.pose1 = pose1;
this.pose2 = pose2;
this.error1 = error1;
this.error2 = error2;
}
/**
* Get the ratio of pose reprojection errors, called ambiguity. Numbers above 0.2 are likely to be
* ambiguous.
*
* @return The ratio of pose reprojection errors.
*/
public double getAmbiguity() {
double min = Math.min(error1, error2);
double max = Math.max(error1, error2);
if (max > 0) {
return min / max;
} else {
return -1;
}
}
/** Pose 1. */
public final Transform3d pose1;
/** Pose 2. */
public final Transform3d pose2;
/** Object-space error of pose 1. */
public final double error1;
/** Object-space error of pose 2. */
public final double error2;
}

View File

@@ -0,0 +1,190 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import edu.wpi.first.apriltag.jni.AprilTagJNI;
import edu.wpi.first.math.geometry.Transform3d;
/** Pose estimators for AprilTag tags. */
public class AprilTagPoseEstimator {
/** Configuration for the pose estimator. */
@SuppressWarnings("MemberName")
public static class Config {
/**
* Creates a pose estimator configuration.
*
* @param tagSize tag size, in meters
* @param fx camera horizontal focal length, in pixels
* @param fy camera vertical focal length, in pixels
* @param cx camera horizontal focal center, in pixels
* @param cy camera vertical focal center, in pixels
*/
public Config(double tagSize, double fx, double fy, double cx, double cy) {
this.tagSize = tagSize;
this.fx = fx;
this.fy = fy;
this.cx = cx;
this.cy = cy;
}
public double tagSize;
public double fx;
public double fy;
public double cx;
public double cy;
@Override
public int hashCode() {
return Double.hashCode(tagSize)
+ Double.hashCode(fx)
+ Double.hashCode(fy)
+ Double.hashCode(cx)
+ Double.hashCode(cy);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Config)) {
return false;
}
Config other = (Config) obj;
return tagSize == other.tagSize
&& fx == other.fx
&& fy == other.fy
&& cx == other.cx
&& cy == other.cy;
}
}
/**
* Creates estimator.
*
* @param config Configuration
*/
public AprilTagPoseEstimator(Config config) {
m_config = new Config(config.tagSize, config.fx, config.fy, config.cx, config.cy);
}
/**
* Sets estimator configuration.
*
* @param config Configuration
*/
public void setConfig(Config config) {
m_config.tagSize = config.tagSize;
m_config.fx = config.fx;
m_config.fy = config.fy;
m_config.cx = config.cx;
m_config.cy = config.cy;
}
/**
* Gets estimator configuration.
*
* @return Configuration
*/
public Config getConfig() {
return new Config(m_config.tagSize, m_config.fx, m_config.fy, m_config.cx, m_config.cy);
}
/**
* Estimates the pose of the tag using the homography method described in [1].
*
* @param detection Tag detection
* @return Pose estimate
*/
public Transform3d estimateHomography(AprilTagDetection detection) {
return estimateHomography(detection.getHomography());
}
/**
* Estimates the pose of the tag using the homography method described in [1].
*
* @param homography Homography 3x3 matrix data
* @return Pose estimate
*/
public Transform3d estimateHomography(double[] homography) {
return AprilTagJNI.estimatePoseHomography(
homography, m_config.tagSize, m_config.fx, m_config.fy, m_config.cx, m_config.cy);
}
/**
* Estimates the pose of the tag. This returns one or two possible poses for the tag, along with
* the object-space error of each.
*
* <p>This uses the homography method described in [1] for the initial estimate. Then Orthogonal
* Iteration [2] is used to refine this estimate. Then [3] is used to find a potential second
* local minima and Orthogonal Iteration is used to refine this second estimate.
*
* <p>[1]: E. Olson, “Apriltag: A robust and flexible visual fiducial system,” in 2011 IEEE
* International Conference on Robotics and Automation, May 2011, pp. 34003407.
*
* <p>[2]: Lu, G. D. Hager and E. Mjolsness, "Fast and globally convergent pose estimation from
* video images," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 22, no.
* 6, pp. 610-622, June 2000. doi: 10.1109/34.862199
*
* <p>[3]: Schweighofer and A. Pinz, "Robust Pose Estimation from a Planar Target," in IEEE
* Transactions on Pattern Analysis and Machine Intelligence, vol. 28, no. 12, pp. 2024-2030, Dec.
* 2006. doi: 10.1109/TPAMI.2006.252
*
* @param detection Tag detection
* @param nIters Number of iterations
* @return Initial and (possibly) second pose estimates
*/
public AprilTagPoseEstimate estimateOrthogonalIteration(AprilTagDetection detection, int nIters) {
return estimateOrthogonalIteration(detection.getHomography(), detection.getCorners(), nIters);
}
/**
* Estimates the pose of the tag. This returns one or two possible poses for the tag, along with
* the object-space error of each.
*
* @param homography Homography 3x3 matrix data
* @param corners Corner point array (X and Y for each corner in order)
* @param nIters Number of iterations
* @return Initial and (possibly) second pose estimates
*/
public AprilTagPoseEstimate estimateOrthogonalIteration(
double[] homography, double[] corners, int nIters) {
return AprilTagJNI.estimatePoseOrthogonalIteration(
homography,
corners,
m_config.tagSize,
m_config.fx,
m_config.fy,
m_config.cx,
m_config.cy,
nIters);
}
/**
* Estimates tag pose. This method is an easier to use interface to
* EstimatePoseOrthogonalIteration(), running 50 iterations and returning the pose with the lower
* object-space error.
*
* @param detection Tag detection
* @return Pose estimate
*/
public Transform3d estimate(AprilTagDetection detection) {
return estimate(detection.getHomography(), detection.getCorners());
}
/**
* Estimates tag pose. This method is an easier to use interface to
* EstimatePoseOrthogonalIteration(), running 50 iterations and returning the pose with the lower
* object-space error.
*
* @param homography Homography 3x3 matrix data
* @param corners Corner point array (X and Y for each corner in order)
* @return Pose estimate
*/
public Transform3d estimate(double[] homography, double[] corners) {
return AprilTagJNI.estimatePose(
homography, corners, m_config.tagSize, m_config.fx, m_config.fy, m_config.cx, m_config.cy);
}
private final Config m_config;
}

View File

@@ -0,0 +1,90 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag.jni;
import edu.wpi.first.apriltag.AprilTagDetection;
import edu.wpi.first.apriltag.AprilTagDetector;
import edu.wpi.first.apriltag.AprilTagPoseEstimate;
import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.util.RuntimeLoader;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
public class AprilTagJNI {
static boolean libraryLoaded = false;
static RuntimeLoader<AprilTagJNI> loader = null;
public static class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
public static boolean getExtractOnStaticLoad() {
return extractOnStaticLoad.get();
}
public static void setExtractOnStaticLoad(boolean load) {
extractOnStaticLoad.set(load);
}
}
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader =
new RuntimeLoader<>(
"apriltagjni", RuntimeLoader.getDefaultExtractionRoot(), AprilTagJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
libraryLoaded = true;
}
}
public static native long createDetector();
public static native void destroyDetector(long det);
public static native void setDetectorConfig(long det, AprilTagDetector.Config config);
public static native AprilTagDetector.Config getDetectorConfig(long det);
public static native void setDetectorQTP(
long det, AprilTagDetector.QuadThresholdParameters params);
public static native AprilTagDetector.QuadThresholdParameters getDetectorQTP(long det);
public static native boolean addFamily(long det, String fam, int bitsCorrected);
public static native void removeFamily(long det, String fam);
public static native void clearFamilies(long det);
public static native AprilTagDetection[] detect(
long det, int width, int height, int stride, long bufAddr);
public static native Transform3d estimatePoseHomography(
double[] homography, double tagSize, double fx, double fy, double cx, double cy);
public static native AprilTagPoseEstimate estimatePoseOrthogonalIteration(
double[] homography,
double[] corners,
double tagSize,
double fx,
double fy,
double cx,
double cy,
int nIters);
public static native Transform3d estimatePose(
double[] homography,
double[] corners,
double tagSize,
double fx,
double fy,
double cx,
double cy);
}

View File

@@ -0,0 +1,18 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTag.h"
#include <wpi/json.h>
using namespace frc;
void frc::to_json(wpi::json& json, const AprilTag& apriltag) {
json = wpi::json{{"ID", apriltag.ID}, {"pose", apriltag.pose}};
}
void frc::from_json(const wpi::json& json, AprilTag& apriltag) {
apriltag.ID = json.at("ID").get<int>();
apriltag.pose = json.at("pose").get<Pose3d>();
}

View File

@@ -0,0 +1,37 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagDetection.h"
#include <type_traits>
#ifdef _WIN32
#pragma warning(disable : 4200)
#elif defined(__clang__)
#pragma clang diagnostic ignored "-Wc99-extensions"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include "apriltag.h"
using namespace frc;
static_assert(sizeof(AprilTagDetection) == sizeof(apriltag_detection_t),
"structure sizes don't match");
static_assert(std::is_standard_layout_v<AprilTagDetection>,
"AprilTagDetection is not standard layout?");
std::string_view AprilTagDetection::GetFamily() const {
return static_cast<const apriltag_family_t*>(family)->name;
}
std::span<const double, 9> AprilTagDetection::GetHomography() const {
return std::span<const double, 9>{static_cast<matd_t*>(H)->data, 9};
}
Eigen::Matrix3d AprilTagDetection::GetHomographyMatrix() const {
return Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>>{
static_cast<matd_t*>(H)->data};
}

View File

@@ -0,0 +1,200 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagDetector.h"
#include <cmath>
#include <numbers>
#ifdef _WIN32
#pragma warning(disable : 4200)
#elif defined(__clang__)
#pragma clang diagnostic ignored "-Wc99-extensions"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include "apriltag.h"
#include "tag16h5.h"
#include "tag25h9.h"
#include "tag36h11.h"
#include "tagCircle21h7.h"
#include "tagCircle49h12.h"
#include "tagCustom48h12.h"
#include "tagStandard41h12.h"
#include "tagStandard52h13.h"
using namespace frc;
AprilTagDetector::Results::Results(void* impl, const private_init&)
: span{reinterpret_cast<AprilTagDetection**>(
static_cast<zarray_t*>(impl)->data),
static_cast<size_t>(static_cast<zarray_t*>(impl)->size)},
m_impl{impl} {}
AprilTagDetector::Results& AprilTagDetector::Results::operator=(Results&& rhs) {
Destroy();
m_impl = rhs.m_impl;
rhs.m_impl = nullptr;
return *this;
}
void AprilTagDetector::Results::Destroy() {
if (m_impl) {
apriltag_detections_destroy(static_cast<zarray_t*>(m_impl));
}
}
AprilTagDetector::AprilTagDetector() : m_impl{apriltag_detector_create()} {}
AprilTagDetector& AprilTagDetector::operator=(AprilTagDetector&& rhs) {
Destroy();
m_impl = rhs.m_impl;
rhs.m_impl = nullptr;
m_families = std::move(rhs.m_families);
rhs.m_families.clear();
m_qtpCriticalAngle = rhs.m_qtpCriticalAngle;
return *this;
}
void AprilTagDetector::SetConfig(const Config& config) {
auto& impl = *static_cast<apriltag_detector_t*>(m_impl);
impl.nthreads = config.numThreads;
impl.quad_decimate = config.quadDecimate;
impl.quad_sigma = config.quadSigma;
impl.refine_edges = config.refineEdges;
impl.decode_sharpening = config.decodeSharpening;
impl.debug = config.debug;
}
AprilTagDetector::Config AprilTagDetector::GetConfig() const {
auto& impl = *static_cast<apriltag_detector_t*>(m_impl);
return {
.numThreads = impl.nthreads,
.quadDecimate = impl.quad_decimate,
.quadSigma = impl.quad_sigma,
.refineEdges = impl.refine_edges,
.decodeSharpening = impl.decode_sharpening,
.debug = impl.debug,
};
}
void AprilTagDetector::SetQuadThresholdParameters(
const QuadThresholdParameters& params) {
auto& qtp = static_cast<apriltag_detector_t*>(m_impl)->qtp;
qtp.min_cluster_pixels = params.minClusterPixels;
qtp.max_nmaxima = params.maxNumMaxima;
qtp.critical_rad = params.criticalAngle.value();
qtp.cos_critical_rad = std::cos(params.criticalAngle.value());
qtp.max_line_fit_mse = params.maxLineFitMSE;
qtp.min_white_black_diff = params.minWhiteBlackDiff;
qtp.deglitch = params.deglitch;
m_qtpCriticalAngle = params.criticalAngle;
}
AprilTagDetector::QuadThresholdParameters
AprilTagDetector::GetQuadThresholdParameters() const {
auto& qtp = static_cast<apriltag_detector_t*>(m_impl)->qtp;
return {
.minClusterPixels = qtp.min_cluster_pixels,
.maxNumMaxima = qtp.max_nmaxima,
.criticalAngle = m_qtpCriticalAngle,
.maxLineFitMSE = qtp.max_line_fit_mse,
.minWhiteBlackDiff = qtp.min_white_black_diff,
.deglitch = qtp.deglitch != 0,
};
}
bool AprilTagDetector::AddFamily(std::string_view fam, int bitsCorrected) {
auto& data = m_families[fam];
if (data) {
return true; // already detecting
}
// create the family
if (fam == "tag16h5") {
data = tag16h5_create();
} else if (fam == "tag25h9") {
data = tag25h9_create();
} else if (fam == "tag36h11") {
data = tag36h11_create();
} else if (fam == "tagCircle21h7") {
data = tagCircle21h7_create();
} else if (fam == "tagCircle49h12") {
data = tagCircle49h12_create();
} else if (fam == "tagStandard41h12") {
data = tagStandard41h12_create();
} else if (fam == "tagStandard52h13") {
data = tagStandard52h13_create();
} else if (fam == "tagCustom48h12") {
data = tagCustom48h12_create();
}
if (!data) {
m_families.erase(fam); // don't keep null value
return false; // can't add
}
apriltag_detector_add_family_bits(static_cast<apriltag_detector_t*>(m_impl),
static_cast<apriltag_family_t*>(data),
bitsCorrected);
return true;
}
void AprilTagDetector::RemoveFamily(std::string_view fam) {
auto it = m_families.find(fam);
if (it != m_families.end()) {
apriltag_detector_remove_family(
static_cast<apriltag_detector_t*>(m_impl),
static_cast<apriltag_family_t*>(it->second));
DestroyFamily(it->getKey(), it->second);
m_families.erase(it);
}
}
void AprilTagDetector::ClearFamilies() {
apriltag_detector_clear_families(static_cast<apriltag_detector_t*>(m_impl));
DestroyFamilies();
m_families.clear();
}
AprilTagDetector::Results AprilTagDetector::Detect(int width, int height,
int stride, uint8_t* buf) {
image_u8_t img{width, height, stride, buf};
return {
apriltag_detector_detect(static_cast<apriltag_detector_t*>(m_impl), &img),
Results::private_init{}};
}
void AprilTagDetector::Destroy() {
if (m_impl) {
apriltag_detector_destroy(static_cast<apriltag_detector_t*>(m_impl));
}
DestroyFamilies();
}
void AprilTagDetector::DestroyFamilies() {
for (auto&& entry : m_families) {
DestroyFamily(entry.getKey(), entry.second);
}
}
void AprilTagDetector::DestroyFamily(std::string_view name, void* data) {
auto fam = static_cast<apriltag_family_t*>(data);
if (name == "tag16h5") {
tag16h5_destroy(fam);
} else if (name == "tag25h9") {
tag25h9_destroy(fam);
} else if (name == "tag36h11") {
tag36h11_destroy(fam);
} else if (name == "tagCircle21h7") {
tagCircle21h7_destroy(fam);
} else if (name == "tagCircle49h12") {
tagCircle49h12_destroy(fam);
} else if (name == "tagStandard41h12") {
tagStandard41h12_destroy(fam);
} else if (name == "tagStandard52h13") {
tagStandard52h13_destroy(fam);
} else if (name == "tagCustom48h12") {
tagCustom48h12_destroy(fam);
}
}

View File

@@ -0,0 +1,107 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagFieldLayout.h"
#include <system_error>
#include <units/angle.h>
#include <units/length.h>
#include <wpi/json.h>
#include <wpi/raw_istream.h>
#include <wpi/raw_ostream.h>
using namespace frc;
AprilTagFieldLayout::AprilTagFieldLayout(std::string_view path) {
std::error_code error_code;
wpi::raw_fd_istream input{path, error_code};
if (error_code) {
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
}
wpi::json json;
input >> json;
for (const auto& tag : json.at("tags").get<std::vector<AprilTag>>()) {
m_apriltags[tag.ID] = tag;
}
m_fieldWidth = units::meter_t{json.at("field").at("width").get<double>()};
m_fieldLength = units::meter_t{json.at("field").at("length").get<double>()};
}
AprilTagFieldLayout::AprilTagFieldLayout(std::vector<AprilTag> apriltags,
units::meter_t fieldLength,
units::meter_t fieldWidth)
: m_fieldLength(std::move(fieldLength)),
m_fieldWidth(std::move(fieldWidth)) {
for (const auto& tag : apriltags) {
m_apriltags[tag.ID] = tag;
}
}
void AprilTagFieldLayout::SetOrigin(OriginPosition origin) {
switch (origin) {
case OriginPosition::kBlueAllianceWallRightSide:
SetOrigin(Pose3d{});
break;
case OriginPosition::kRedAllianceWallRightSide:
SetOrigin(Pose3d{Translation3d{m_fieldLength, m_fieldWidth, 0_m},
Rotation3d{0_deg, 0_deg, 180_deg}});
break;
default:
throw std::invalid_argument("Invalid origin");
}
}
void AprilTagFieldLayout::SetOrigin(const Pose3d& origin) {
m_origin = origin;
}
std::optional<frc::Pose3d> AprilTagFieldLayout::GetTagPose(int ID) const {
const auto& it = m_apriltags.find(ID);
if (it == m_apriltags.end()) {
return std::nullopt;
}
return it->second.pose.RelativeTo(m_origin);
}
void AprilTagFieldLayout::Serialize(std::string_view path) {
std::error_code error_code;
wpi::raw_fd_ostream output{path, error_code};
if (error_code) {
throw std::runtime_error(fmt::format("Cannot open file: {}", path));
}
wpi::json json = *this;
output << json;
output.flush();
}
void frc::to_json(wpi::json& json, const AprilTagFieldLayout& layout) {
std::vector<AprilTag> tagVector;
tagVector.reserve(layout.m_apriltags.size());
for (const auto& pair : layout.m_apriltags) {
tagVector.push_back(pair.second);
}
json = wpi::json{{"field",
{{"length", layout.m_fieldLength.value()},
{"width", layout.m_fieldWidth.value()}}},
{"tags", tagVector}};
}
void frc::from_json(const wpi::json& json, AprilTagFieldLayout& layout) {
layout.m_apriltags.clear();
for (const auto& tag : json.at("tags").get<std::vector<AprilTag>>()) {
layout.m_apriltags[tag.ID] = tag;
}
layout.m_fieldLength =
units::meter_t{json.at("field").at("length").get<double>()};
layout.m_fieldWidth =
units::meter_t{json.at("field").at("width").get<double>()};
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagFields.h"
#include <wpi/json.h>
namespace frc {
// C++ generated from resource files
std::string_view GetResource_2022_rapidreact_json();
std::string_view GetResource_2023_chargedup_json();
AprilTagFieldLayout LoadAprilTagLayoutField(AprilTagField field) {
std::string_view fieldString;
switch (field) {
case AprilTagField::k2022RapidReact:
fieldString = GetResource_2022_rapidreact_json();
break;
case AprilTagField::k2023ChargedUp:
fieldString = GetResource_2023_chargedup_json();
break;
case AprilTagField::kNumFields:
throw std::invalid_argument("Invalid Field");
}
wpi::json json = wpi::json::parse(fieldString);
return json.get<AprilTagFieldLayout>();
}
} // namespace frc

View File

@@ -0,0 +1,20 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagPoseEstimate.h"
#include <algorithm>
using namespace frc;
double AprilTagPoseEstimate::GetAmbiguity() const {
auto min = (std::min)(error1, error2);
auto max = (std::max)(error1, error2);
if (max > 0) {
return min / max;
} else {
return -1;
}
}

View File

@@ -0,0 +1,154 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagPoseEstimator.h"
#include <Eigen/QR>
#include "frc/apriltag/AprilTagDetection.h"
#ifdef _WIN32
#pragma warning(disable : 4200)
#elif defined(__clang__)
#pragma clang diagnostic ignored "-Wc99-extensions"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include "apriltag.h"
#include "apriltag_pose.h"
using namespace frc;
static Eigen::Matrix3d OrthogonalizeRotationMatrix(
const Eigen::Matrix3d& input) {
Eigen::HouseholderQR<Eigen::Matrix3d> qr{input};
Eigen::Matrix3d Q = qr.householderQ();
Eigen::Matrix3d R = qr.matrixQR().triangularView<Eigen::Upper>();
// Fix signs in R if they're < 0 so it's close to an identity matrix
// (our QR decomposition implementation sometimes flips the signs of
// columns)
for (int colR = 0; colR < 3; ++colR) {
if (R(colR, colR) < 0) {
for (int rowQ = 0; rowQ < 3; ++rowQ) {
Q(rowQ, colR) = -Q(rowQ, colR);
}
}
}
return Q;
}
static Transform3d MakePose(const apriltag_pose_t& pose) {
if (!pose.R || !pose.t) {
return {};
}
return {Translation3d{units::meter_t{pose.t->data[0]},
units::meter_t{pose.t->data[1]},
units::meter_t{pose.t->data[2]}},
Rotation3d{OrthogonalizeRotationMatrix(
Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>>{
pose.R->data})}};
}
static apriltag_detection_info_t MakeDetectionInfo(
const apriltag_detection_t* det,
const AprilTagPoseEstimator::Config& config) {
return {const_cast<apriltag_detection_t*>(det),
config.tagSize.value(),
config.fx,
config.fy,
config.cx,
config.cy};
}
static apriltag_detection_t MakeBasicDet(
std::span<const double, 9> homography,
const std::span<const double, 8>* corners) {
apriltag_detection_t detection;
detection.H = matd_create(3, 3);
std::memcpy(detection.H->data, homography.data(), 9 * sizeof(double));
if (corners) {
for (int i = 0; i < 4; i++) {
detection.p[i][0] = (*corners)[i * 2];
detection.p[i][1] = (*corners)[i * 2 + 1];
}
}
return detection;
}
static Transform3d DoEstimateHomography(
const apriltag_detection_t* detection,
const AprilTagPoseEstimator::Config& config) {
auto info = MakeDetectionInfo(detection, config);
apriltag_pose_t pose;
estimate_pose_for_tag_homography(&info, &pose);
return MakePose(pose);
}
Transform3d AprilTagPoseEstimator::EstimateHomography(
const AprilTagDetection& detection) const {
return DoEstimateHomography(
reinterpret_cast<const apriltag_detection_t*>(&detection), m_config);
}
Transform3d AprilTagPoseEstimator::EstimateHomography(
std::span<const double, 9> homography) const {
auto detection = MakeBasicDet(homography, nullptr);
auto rv = DoEstimateHomography(&detection, m_config);
matd_destroy(detection.H);
return rv;
}
static AprilTagPoseEstimate DoEstimateOrthogonalIteration(
const apriltag_detection_t* detection,
const AprilTagPoseEstimator::Config& config, int nIters) {
auto info = MakeDetectionInfo(detection, config);
apriltag_pose_t pose1, pose2;
double err1, err2;
estimate_tag_pose_orthogonal_iteration(&info, &err1, &pose1, &err2, &pose2,
nIters);
return {MakePose(pose1), MakePose(pose2), err1, err2};
}
AprilTagPoseEstimate AprilTagPoseEstimator::EstimateOrthogonalIteration(
const AprilTagDetection& detection, int nIters) const {
return DoEstimateOrthogonalIteration(
reinterpret_cast<const apriltag_detection_t*>(&detection), m_config,
nIters);
}
AprilTagPoseEstimate AprilTagPoseEstimator::EstimateOrthogonalIteration(
std::span<const double, 9> homography, std::span<const double, 8> corners,
int nIters) const {
auto detection = MakeBasicDet(homography, &corners);
auto rv = DoEstimateOrthogonalIteration(&detection, m_config, nIters);
matd_destroy(detection.H);
return rv;
}
static Transform3d DoEstimate(const apriltag_detection_t* detection,
const AprilTagPoseEstimator::Config& config) {
auto info = MakeDetectionInfo(detection, config);
apriltag_pose_t pose;
estimate_tag_pose(&info, &pose);
return MakePose(pose);
}
Transform3d AprilTagPoseEstimator::Estimate(
const AprilTagDetection& detection) const {
return DoEstimate(reinterpret_cast<const apriltag_detection_t*>(&detection),
m_config);
}
Transform3d AprilTagPoseEstimator::Estimate(
std::span<const double, 9> homography,
std::span<const double, 8> corners) const {
auto detection = MakeBasicDet(homography, &corners);
auto rv = DoEstimate(&detection, m_config);
matd_destroy(detection.H);
return rv;
}

View File

@@ -0,0 +1,595 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <cstdio>
#include <cstring>
#include <wpi/jni_util.h>
#include "edu_wpi_first_apriltag_jni_AprilTagJNI.h"
#include "frc/apriltag/AprilTagDetector.h"
#include "frc/apriltag/AprilTagPoseEstimator.h"
using namespace frc;
using namespace wpi::java;
static JavaVM* jvm = nullptr;
static JClass detectionCls;
static JClass detectorConfigCls;
static JClass detectorQTPCls;
static JClass poseEstimateCls;
static JClass quaternionCls;
static JClass rotation3dCls;
static JClass transform3dCls;
static JClass translation3dCls;
static JException illegalArgEx;
static JException nullPointerEx;
static const JClassInit classes[] = {
{"edu/wpi/first/apriltag/AprilTagDetection", &detectionCls},
{"edu/wpi/first/apriltag/AprilTagDetector$Config", &detectorConfigCls},
{"edu/wpi/first/apriltag/AprilTagDetector$QuadThresholdParameters",
&detectorQTPCls},
{"edu/wpi/first/apriltag/AprilTagPoseEstimate", &poseEstimateCls},
{"edu/wpi/first/math/geometry/Quaternion", &quaternionCls},
{"edu/wpi/first/math/geometry/Rotation3d", &rotation3dCls},
{"edu/wpi/first/math/geometry/Transform3d", &transform3dCls},
{"edu/wpi/first/math/geometry/Translation3d", &translation3dCls}};
static const JExceptionInit exceptions[] = {
{"java/lang/IllegalArgumentException", &illegalArgEx},
{"java/lang/NullPointerException", &nullPointerEx}};
extern "C" {
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
jvm = vm;
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return JNI_ERR;
}
// Cache references to classes
for (auto& c : classes) {
*c.cls = JClass(env, c.name);
if (!*c.cls) {
std::fprintf(stderr, "could not load class %s\n", c.name);
return JNI_ERR;
}
}
for (auto& c : exceptions) {
*c.cls = JException(env, c.name);
if (!*c.cls) {
std::fprintf(stderr, "could not load exception %s\n", c.name);
return JNI_ERR;
}
}
return JNI_VERSION_1_6;
}
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return;
}
// Delete global references
for (auto& c : classes) {
c.cls->free(env);
}
for (auto& c : exceptions) {
c.cls->free(env);
}
jvm = nullptr;
}
} // extern "C"
//
// Conversions from Java to C++ objects
//
static AprilTagDetector::Config FromJavaDetectorConfig(JNIEnv* env,
jobject jconfig) {
if (!jconfig) {
return {};
}
#define FIELD(name, sig) \
static jfieldID name##Field = nullptr; \
if (!name##Field) { \
name##Field = env->GetFieldID(detectorConfigCls, #name, sig); \
}
FIELD(numThreads, "I");
FIELD(quadDecimate, "F");
FIELD(quadSigma, "F");
FIELD(refineEdges, "Z");
FIELD(decodeSharpening, "D");
FIELD(debug, "Z");
#undef FIELD
#define FIELD(ctype, jtype, name) \
.name = static_cast<ctype>(env->Get##jtype##Field(jconfig, name##Field))
return {
FIELD(int, Int, numThreads),
FIELD(float, Float, quadDecimate),
FIELD(float, Float, quadSigma),
FIELD(bool, Boolean, refineEdges),
FIELD(double, Double, decodeSharpening),
FIELD(bool, Boolean, debug),
};
#undef GET
#undef FIELD
}
static AprilTagDetector::QuadThresholdParameters FromJavaDetectorQTP(
JNIEnv* env, jobject jparams) {
if (!jparams) {
return {};
}
#define FIELD(name, sig) \
static jfieldID name##Field = nullptr; \
if (!name##Field) { \
name##Field = env->GetFieldID(detectorQTPCls, #name, sig); \
}
FIELD(minClusterPixels, "I");
FIELD(maxNumMaxima, "I");
FIELD(criticalAngle, "D");
FIELD(maxLineFitMSE, "F");
FIELD(minWhiteBlackDiff, "I");
FIELD(deglitch, "Z");
#undef FIELD
#define FIELD(ctype, jtype, name) \
.name = static_cast<ctype>(env->Get##jtype##Field(jparams, name##Field))
return {
FIELD(int, Int, minClusterPixels),
FIELD(int, Int, maxNumMaxima),
.criticalAngle = units::radian_t{static_cast<double>(
env->GetDoubleField(jparams, criticalAngleField))},
FIELD(float, Float, maxLineFitMSE),
FIELD(int, Int, minWhiteBlackDiff),
FIELD(bool, Boolean, deglitch),
};
#undef GET
#undef FIELD
}
//
// Conversions from C++ to Java objects
//
static jobject MakeJObject(JNIEnv* env, const AprilTagDetection& detect) {
static jmethodID constructor = env->GetMethodID(
detectionCls, "<init>", "(Ljava/lang/String;IIF[DDD[D)V");
if (!constructor) {
return nullptr;
}
JLocal<jstring> fam{env, MakeJString(env, detect.GetFamily())};
auto homography = detect.GetHomography();
JLocal<jdoubleArray> harr{
env, MakeJDoubleArray(
env, {reinterpret_cast<const jdouble*>(homography.data()),
homography.size()})};
double cornersBuf[8];
auto corners = detect.GetCorners(cornersBuf);
JLocal<jdoubleArray> carr{
env,
MakeJDoubleArray(env, {reinterpret_cast<const jdouble*>(corners.data()),
corners.size()})};
auto center = detect.GetCenter();
return env->NewObject(detectionCls, constructor, fam.obj(),
static_cast<jint>(detect.GetId()),
static_cast<jint>(detect.GetHamming()),
static_cast<jfloat>(detect.GetDecisionMargin()),
harr.obj(), static_cast<jdouble>(center.x),
static_cast<jdouble>(center.y), carr.obj());
}
static jobjectArray MakeJObject(JNIEnv* env,
std::span<const AprilTagDetection* const> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), detectionCls, nullptr);
if (!jarr) {
return nullptr;
}
for (size_t i = 0; i < arr.size(); ++i) {
JLocal<jobject> elem{env, MakeJObject(env, *arr[i])};
env->SetObjectArrayElement(jarr, i, elem.obj());
}
return jarr;
}
static jobject MakeJObject(JNIEnv* env,
const AprilTagDetector::Config& config) {
static jmethodID constructor =
env->GetMethodID(detectorConfigCls, "<init>", "(IFFZDZ)V");
if (!constructor) {
return nullptr;
}
return env->NewObject(detectorConfigCls, constructor,
static_cast<jint>(config.numThreads),
static_cast<jfloat>(config.quadDecimate),
static_cast<jfloat>(config.quadSigma),
static_cast<jboolean>(config.refineEdges),
static_cast<jdouble>(config.decodeSharpening),
static_cast<jboolean>(config.debug));
}
static jobject MakeJObject(
JNIEnv* env, const AprilTagDetector::QuadThresholdParameters& params) {
static jmethodID constructor =
env->GetMethodID(detectorQTPCls, "<init>", "(IIDFIZ)V");
if (!constructor) {
return nullptr;
}
return env->NewObject(detectorQTPCls, constructor,
static_cast<jint>(params.minClusterPixels),
static_cast<jint>(params.maxNumMaxima),
static_cast<jdouble>(params.criticalAngle),
static_cast<jfloat>(params.maxLineFitMSE),
static_cast<jint>(params.minWhiteBlackDiff),
static_cast<jboolean>(params.deglitch));
}
static jobject MakeJObject(JNIEnv* env, const Translation3d& xlate) {
static jmethodID constructor =
env->GetMethodID(translation3dCls, "<init>", "(DDD)V");
if (!constructor) {
return nullptr;
}
return env->NewObject(
translation3dCls, constructor, static_cast<jdouble>(xlate.X()),
static_cast<jdouble>(xlate.Y()), static_cast<jdouble>(xlate.Z()));
}
static jobject MakeJObject(JNIEnv* env, const Quaternion& q) {
static jmethodID constructor =
env->GetMethodID(quaternionCls, "<init>", "(DDDD)V");
if (!constructor) {
return nullptr;
}
return env->NewObject(quaternionCls, constructor, static_cast<jdouble>(q.W()),
static_cast<jdouble>(q.X()),
static_cast<jdouble>(q.Y()),
static_cast<jdouble>(q.Z()));
}
static jobject MakeJObject(JNIEnv* env, const Rotation3d& rot) {
static jmethodID constructor = env->GetMethodID(
rotation3dCls, "<init>", "(Ledu/wpi/first/math/geometry/Quaternion;)V");
if (!constructor) {
return nullptr;
}
JLocal<jobject> q{env, MakeJObject(env, rot.GetQuaternion())};
return env->NewObject(rotation3dCls, constructor, q.obj());
}
static jobject MakeJObject(JNIEnv* env, const Transform3d& xform) {
static jmethodID constructor =
env->GetMethodID(transform3dCls, "<init>",
"(Ledu/wpi/first/math/geometry/Translation3d;"
"Ledu/wpi/first/math/geometry/Rotation3d;)V");
if (!constructor) {
return nullptr;
}
JLocal<jobject> xlate{env, MakeJObject(env, xform.Translation())};
JLocal<jobject> rot{env, MakeJObject(env, xform.Rotation())};
return env->NewObject(transform3dCls, constructor, xlate.obj(), rot.obj());
}
static jobject MakeJObject(JNIEnv* env, const AprilTagPoseEstimate& est) {
static jmethodID constructor =
env->GetMethodID(poseEstimateCls, "<init>",
"(Ledu/wpi/first/math/geometry/Transform3d;"
"Ledu/wpi/first/math/geometry/Transform3d;DD)V");
if (!constructor) {
return nullptr;
}
JLocal<jobject> pose1{env, MakeJObject(env, est.pose1)};
JLocal<jobject> pose2{env, MakeJObject(env, est.pose2)};
return env->NewObject(poseEstimateCls, constructor, pose1.obj(), pose2.obj(),
static_cast<jdouble>(est.error1),
static_cast<jdouble>(est.error2));
}
extern "C" {
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: createDetector
* Signature: ()J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_createDetector
(JNIEnv* env, jclass)
{
return reinterpret_cast<jlong>(new AprilTagDetector);
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: destroyDetector
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_destroyDetector
(JNIEnv* env, jclass, jlong det)
{
delete reinterpret_cast<AprilTagDetector*>(det);
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: setDetectorConfig
* Signature: (JLjava/lang/Object;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_setDetectorConfig
(JNIEnv* env, jclass, jlong det, jobject config)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return;
}
reinterpret_cast<AprilTagDetector*>(det)->SetConfig(
FromJavaDetectorConfig(env, config));
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: getDetectorConfig
* Signature: (J)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_getDetectorConfig
(JNIEnv* env, jclass, jlong det)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return nullptr;
}
return MakeJObject(env,
reinterpret_cast<AprilTagDetector*>(det)->GetConfig());
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: setDetectorQTP
* Signature: (JLjava/lang/Object;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_setDetectorQTP
(JNIEnv* env, jclass, jlong det, jobject params)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return;
}
reinterpret_cast<AprilTagDetector*>(det)->SetQuadThresholdParameters(
FromJavaDetectorQTP(env, params));
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: getDetectorQTP
* Signature: (J)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_getDetectorQTP
(JNIEnv* env, jclass, jlong det)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return nullptr;
}
return MakeJObject(
env,
reinterpret_cast<AprilTagDetector*>(det)->GetQuadThresholdParameters());
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: addFamily
* Signature: (JLjava/lang/String;I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_addFamily
(JNIEnv* env, jclass, jlong det, jstring fam, jint bitsCorrected)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return false;
}
if (!fam) {
nullPointerEx.Throw(env, "fam cannot be null");
return false;
}
return reinterpret_cast<AprilTagDetector*>(det)->AddFamily(
JStringRef{env, fam}, bitsCorrected);
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: removeFamily
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_removeFamily
(JNIEnv* env, jclass, jlong det, jstring fam)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return;
}
if (!fam) {
nullPointerEx.Throw(env, "fam cannot be null");
return;
}
reinterpret_cast<AprilTagDetector*>(det)->RemoveFamily(JStringRef{env, fam});
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: clearFamilies
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_clearFamilies
(JNIEnv* env, jclass, jlong det)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return;
}
reinterpret_cast<AprilTagDetector*>(det)->ClearFamilies();
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: detect
* Signature: (JIIIJ)[Ljava/lang/Object;
*/
JNIEXPORT jobjectArray JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_detect
(JNIEnv* env, jclass, jlong det, jint width, jint height, jint stride,
jlong bufAddr)
{
if (det == 0) {
nullPointerEx.Throw(env, "det cannot be null");
return nullptr;
}
if (bufAddr == 0) {
nullPointerEx.Throw(env, "bufAddr cannot be null");
return nullptr;
}
return MakeJObject(
env, reinterpret_cast<AprilTagDetector*>(det)->Detect(
width, height, stride, reinterpret_cast<uint8_t*>(bufAddr)));
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: estimatePoseHomography
* Signature: ([DDDDDD)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_estimatePoseHomography
(JNIEnv* env, jclass, jdoubleArray homography, jdouble tagSize, jdouble fx,
jdouble fy, jdouble cx, jdouble cy)
{
if (!homography) {
nullPointerEx.Throw(env, "homography cannot be null");
return nullptr;
}
JDoubleArrayRef harr{env, homography};
if (harr.size() != 9) {
illegalArgEx.Throw(env, "homography array must be size 9");
return nullptr;
}
AprilTagPoseEstimator estimator({units::meter_t{tagSize}, fx, fy, cx, cy});
return MakeJObject(env, estimator.EstimateHomography(
std::span<const double, 9>{harr.array()}));
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: estimatePoseOrthogonalIteration
* Signature: ([D[DDDDDDI)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_estimatePoseOrthogonalIteration
(JNIEnv* env, jclass, jdoubleArray homography, jdoubleArray corners,
jdouble tagSize, jdouble fx, jdouble fy, jdouble cx, jdouble cy, jint nIters)
{
// homography
if (!homography) {
nullPointerEx.Throw(env, "homography cannot be null");
return nullptr;
}
JDoubleArrayRef harr{env, homography};
if (harr.size() != 9) {
illegalArgEx.Throw(env, "homography array must be size 9");
return nullptr;
}
// corners
if (!corners) {
nullPointerEx.Throw(env, "corners cannot be null");
return nullptr;
}
JDoubleArrayRef carr{env, corners};
if (carr.size() != 8) {
illegalArgEx.Throw(env, "corners array must be size 8");
return nullptr;
}
AprilTagPoseEstimator estimator({units::meter_t{tagSize}, fx, fy, cx, cy});
return MakeJObject(env,
estimator.EstimateOrthogonalIteration(
std::span<const double, 9>{harr.array()},
std::span<const double, 8>{carr.array()}, nIters));
}
/*
* Class: edu_wpi_first_apriltag_jni_AprilTagJNI
* Method: estimatePose
* Signature: ([D[DDDDDD)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL
Java_edu_wpi_first_apriltag_jni_AprilTagJNI_estimatePose
(JNIEnv* env, jclass, jdoubleArray homography, jdoubleArray corners,
jdouble tagSize, jdouble fx, jdouble fy, jdouble cx, jdouble cy)
{
// homography
if (!homography) {
nullPointerEx.Throw(env, "homography cannot be null");
return nullptr;
}
JDoubleArrayRef harr{env, homography};
if (harr.size() != 9) {
illegalArgEx.Throw(env, "homography array must be size 9");
return nullptr;
}
// corners
if (!corners) {
nullPointerEx.Throw(env, "corners cannot be null");
return nullptr;
}
JDoubleArrayRef carr{env, corners};
if (carr.size() != 8) {
illegalArgEx.Throw(env, "corners array must be size 8");
return nullptr;
}
AprilTagPoseEstimator estimator({units::meter_t{tagSize}, fx, fy, cx, cy});
return MakeJObject(
env, estimator.Estimate(std::span<const double, 9>{harr.array()},
std::span<const double, 8>{carr.array()}));
}
} // extern "C"

View File

@@ -0,0 +1,34 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <wpi/SymbolExports.h>
#include "frc/geometry/Pose3d.h"
namespace wpi {
class json;
} // namespace wpi
namespace frc {
struct WPILIB_DLLEXPORT AprilTag {
int ID;
Pose3d pose;
/**
* Checks equality between this AprilTag and another object.
*/
bool operator==(const AprilTag&) const = default;
};
WPILIB_DLLEXPORT
void to_json(wpi::json& json, const AprilTag& apriltag);
WPILIB_DLLEXPORT
void from_json(const wpi::json& json, AprilTag& apriltag);
} // namespace frc

View File

@@ -0,0 +1,160 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <stdint.h>
#include <span>
#include <string_view>
#include <wpi/SymbolExports.h>
#include "frc/EigenCore.h"
namespace frc {
/**
* A detection of an AprilTag tag.
*/
class WPILIB_DLLEXPORT AprilTagDetection final {
public:
AprilTagDetection() = delete;
AprilTagDetection(const AprilTagDetection&) = delete;
AprilTagDetection& operator=(const AprilTagDetection&) = delete;
/** A point. Used for center and corner points. */
struct Point {
double x;
double y;
};
/**
* Gets the decoded tag's family name.
*
* @return Decoded family name
*/
std::string_view GetFamily() const;
/**
* Gets the decoded ID of the tag.
*
* @return Decoded ID
*/
int GetId() const { return id; }
/**
* Gets how many error bits were corrected. Note: accepting large numbers of
* corrected errors leads to greatly increased false positive rates.
* NOTE: As of this implementation, the detector cannot detect tags with
* a hamming distance greater than 2.
*
* @return Hamming distance (number of corrected error bits)
*/
int GetHamming() const { return hamming; }
/**
* Gets a measure of the quality of the binary decoding process: the
* average difference between the intensity of a data bit versus
* the decision threshold. Higher numbers roughly indicate better
* decodes. This is a reasonable measure of detection accuracy
* only for very small tags-- not effective for larger tags (where
* we could have sampled anywhere within a bit cell and still
* gotten a good detection.)
*
* @return Decision margin
*/
float GetDecisionMargin() const { return decision_margin; }
/**
* Gets the 3x3 homography matrix describing the projection from an
* "ideal" tag (with corners at (-1,1), (1,1), (1,-1), and (-1,
* -1)) to pixels in the image.
*
* @return Homography matrix data
*/
std::span<const double, 9> GetHomography() const;
/**
* Gets the 3x3 homography matrix describing the projection from an
* "ideal" tag (with corners at (-1,1), (1,1), (1,-1), and (-1,
* -1)) to pixels in the image.
*
* @return Homography matrix
*/
Eigen::Matrix3d GetHomographyMatrix() const;
/**
* Gets the center of the detection in image pixel coordinates.
*
* @return Center point
*/
const Point& GetCenter() const { return *reinterpret_cast<const Point*>(c); }
/**
* Gets a corner of the tag in image pixel coordinates. These always
* wrap counter-clock wise around the tag.
*
* @param ndx Corner index (range is 0-3, inclusive)
* @return Corner point
*/
const Point& GetCorner(int ndx) const {
return *reinterpret_cast<const Point*>(p[ndx]);
}
/**
* Gets the corners of the tag in image pixel coordinates. These always
* wrap counter-clock wise around the tag.
*
* @param cornersBuf Corner point array (X and Y for each corner in order)
* @return Corner point array (copy of cornersBuf span)
*/
std::span<double, 8> GetCorners(std::span<double, 8> cornersBuf) const {
for (int i = 0; i < 4; i++) {
cornersBuf[i * 2] = p[i][0];
cornersBuf[i * 2 + 1] = p[i][1];
}
return cornersBuf;
}
private:
// This class *must* be standard-layout-compatible with apriltag_detection
// as we use reinterpret_cast from that structure. This means the below
// members must exactly match the contents of the apriltag_detection struct.
// The tag family.
void* family;
// The decoded ID of the tag.
int id;
// How many error bits were corrected? Note: accepting large numbers of
// corrected errors leads to greatly increased false positive rates.
// NOTE: As of this implementation, the detector cannot detect tags with
// a hamming distance greater than 2.
int hamming;
// A measure of the quality of the binary decoding process: the
// average difference between the intensity of a data bit versus
// the decision threshold. Higher numbers roughly indicate better
// decodes. This is a reasonable measure of detection accuracy
// only for very small tags-- not effective for larger tags (where
// we could have sampled anywhere within a bit cell and still
// gotten a good detection.)
float decision_margin;
// The 3x3 homography matrix describing the projection from an
// "ideal" tag (with corners at (-1,1), (1,1), (1,-1), and (-1,
// -1)) to pixels in the image.
void* H;
// The center of the detection in image pixel coordinates.
double c[2];
// The corners of the tag in image pixel coordinates. These always
// wrap counter-clock wise around the tag.
double p[4][2];
};
} // namespace frc

View File

@@ -0,0 +1,260 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <stdint.h>
#include <memory>
#include <span>
#include <string_view>
#include <utility>
#include <units/angle.h>
#include <wpi/StringMap.h>
#include <wpi/SymbolExports.h>
#include "frc/apriltag/AprilTagDetection.h"
namespace frc {
/**
* An AprilTag detector engine. This is expensive to set up and tear down, so
* most use cases should only create one of these, add a family to it, set up
* any other configuration, and repeatedly call Detect().
*/
class WPILIB_DLLEXPORT AprilTagDetector {
public:
/** Detector configuration. */
struct Config {
bool operator==(const Config&) const = default;
/**
* How many threads should be used for computation. Default is
* single-threaded operation (1 thread).
*/
int numThreads = 1;
/**
* Quad decimation. Detection of quads can be done on a lower-resolution
* image, improving speed at a cost of pose accuracy and a slight decrease
* in detection rate. Decoding the binary payload is still done at full
* resolution. Default is 2.0.
*/
float quadDecimate = 2.0f;
/**
* What Gaussian blur should be applied to the segmented image (used for
* quad detection). Very noisy images benefit from non-zero values (e.g.
* 0.8). Default is 0.0.
*/
float quadSigma = 0.0f;
/**
* When true, the edges of the each quad are adjusted to "snap to" strong
* gradients nearby. This is useful when decimation is employed, as it can
* increase the quality of the initial quad estimate substantially.
* Generally recommended to be on (true). Default is true.
*
* Very computationally inexpensive. Option is ignored if
* quad_decimate = 1.
*/
bool refineEdges = true;
/**
* How much sharpening should be done to decoded images. This can help
* decode small tags but may or may not help in odd lighting conditions or
* low light conditions. Default is 0.25.
*/
double decodeSharpening = 0.25;
/**
* Debug mode. When true, the decoder writes a variety of debugging images
* to the current working directory at various stages through the detection
* process. This is slow and should *not* be used on space-limited systems
* such as the RoboRIO. Default is disabled (false).
*/
bool debug = false;
};
/** Quad threshold parameters. */
struct QuadThresholdParameters {
bool operator==(const QuadThresholdParameters&) const = default;
/**
* Threshold used to reject quads containing too few pixels. Default is 5
* pixels.
*/
int minClusterPixels = 5;
/**
* How many corner candidates to consider when segmenting a group of pixels
* into a quad. Default is 10.
*/
int maxNumMaxima = 10;
/**
* Critical angle. The detector will reject quads where pairs of edges have
* angles that are close to straight or close to 180 degrees. Zero means
* that no quads are rejected. Default is 10 degrees.
*/
units::radian_t criticalAngle = 10_deg;
/**
* When fitting lines to the contours, the maximum mean squared error
* allowed. This is useful in rejecting contours that are far from being
* quad shaped; rejecting these quads "early" saves expensive decoding
* processing. Default is 10.0.
*/
float maxLineFitMSE = 10.0f;
/**
* Minimum brightness offset. When we build our model of black & white
* pixels, we add an extra check that the white model must be (overall)
* brighter than the black model. How much brighter? (in pixel values,
* [0,255]). Default is 5.
*/
int minWhiteBlackDiff = 5;
/**
* Whether the thresholded image be should be deglitched. Only useful for
* very noisy images. Default is disabled (false).
*/
bool deglitch = false;
};
/**
* Array of detection results. Each array element is a pointer to an
* AprilTagDetection.
*/
class WPILIB_DLLEXPORT Results
: public std::span<AprilTagDetection const* const> {
struct private_init {};
friend class AprilTagDetector;
public:
Results() = default;
Results(void* impl, const private_init&);
~Results() { Destroy(); }
Results(const Results&) = delete;
Results& operator=(const Results&) = delete;
Results(Results&& rhs) : span{std::move(rhs)}, m_impl{rhs.m_impl} {
rhs.m_impl = nullptr;
}
Results& operator=(Results&& rhs);
private:
void Destroy();
void* m_impl = nullptr;
};
AprilTagDetector();
~AprilTagDetector() { Destroy(); }
AprilTagDetector(const AprilTagDetector&) = delete;
AprilTagDetector& operator=(const AprilTagDetector&) = delete;
AprilTagDetector(AprilTagDetector&& rhs)
: m_impl{rhs.m_impl},
m_families{std::move(rhs.m_families)},
m_qtpCriticalAngle{rhs.m_qtpCriticalAngle} {
rhs.m_impl = nullptr;
}
AprilTagDetector& operator=(AprilTagDetector&& rhs);
/**
* @{
* @name Configuration functions
*/
/**
* Sets detector configuration.
*
* @param config Configuration
*/
void SetConfig(const Config& config);
/**
* Gets detector configuration.
*
* @return Configuration
*/
Config GetConfig() const;
/**
* Sets quad threshold parameters.
*
* @param params Parameters
*/
void SetQuadThresholdParameters(const QuadThresholdParameters& params);
/**
* Gets quad threshold parameters.
*
* @return Parameters
*/
QuadThresholdParameters GetQuadThresholdParameters() const;
/** @} */
/**
* @{
* @name Tag family functions
*/
/**
* Adds a family of tags to be detected.
*
* @param fam Family name, e.g. "tag16h5"
* @param bitsCorrected
* @return False if family can't be found
*/
bool AddFamily(std::string_view fam, int bitsCorrected = 2);
/**
* Removes a family of tags from the detector.
*
* @param fam Family name, e.g. "tag16h5"
*/
void RemoveFamily(std::string_view fam);
/**
* Unregister all families.
*/
void ClearFamilies();
/** @} */
/**
* Detect tags from an 8-bit image.
*
* @param width width of the image
* @param height height of the image
* @param stride number of bytes between image rows (often the same as width)
* @param buf image buffer
* @return Results (array of AprilTagDetection pointers)
*/
Results Detect(int width, int height, int stride, uint8_t* buf);
/**
* Detect tags from an 8-bit image.
*
* @param width width of the image
* @param height height of the image
* @param buf image buffer
* @return Results (array of AprilTagDetection pointers)
*/
Results Detect(int width, int height, uint8_t* buf) {
return Detect(width, height, width, buf);
}
private:
void Destroy();
void DestroyFamilies();
void DestroyFamily(std::string_view name, void* data);
void* m_impl;
wpi::StringMap<void*> m_families;
units::radian_t m_qtpCriticalAngle = 10_deg;
};
} // namespace frc

View File

@@ -0,0 +1,18 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <opencv2/core/mat.hpp>
#include "frc/apriltag/AprilTagDetector.h"
namespace frc {
inline AprilTagDetector::Results AprilTagDetect(AprilTagDetector& detector,
cv::Mat& image) {
return detector.Detect(image.cols, image.rows, image.data);
}
} // namespace frc

View File

@@ -0,0 +1,129 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <optional>
#include <string_view>
#include <unordered_map>
#include <vector>
#include <units/length.h>
#include <wpi/SymbolExports.h>
#include "frc/apriltag/AprilTag.h"
#include "frc/geometry/Pose3d.h"
namespace wpi {
class json;
} // namespace wpi
namespace frc {
/**
* Class for representing a layout of AprilTags on a field and reading them from
* a JSON format.
*
* The JSON format contains two top-level objects, "tags" and "field".
* The "tags" object is a list of all AprilTags contained within a layout. Each
* AprilTag serializes to a JSON object containing an ID and a Pose3d. The
* "field" object is a descriptor of the size of the field in meters with
* "width" and "length" values. This is to account for arbitrary field sizes
* when transforming the poses.
*
* Pose3ds in the JSON are measured using the normal FRC coordinate system, NWU
* with the origin at the bottom-right corner of the blue alliance wall.
* SetOrigin(OriginPosition) can be used to change the poses returned from
* GetTagPose(int) to be from the perspective of a specific alliance.
*
* Tag poses represent the center of the tag, with a zero rotation representing
* a tag that is upright and facing away from the (blue) alliance wall (that is,
* towards the opposing alliance). */
class WPILIB_DLLEXPORT AprilTagFieldLayout {
public:
enum class OriginPosition {
kBlueAllianceWallRightSide,
kRedAllianceWallRightSide,
};
AprilTagFieldLayout() = default;
/**
* Construct a new AprilTagFieldLayout with values imported from a JSON file.
*
* @param path Path of the JSON file to import from.
*/
explicit AprilTagFieldLayout(std::string_view path);
/**
* Construct a new AprilTagFieldLayout from a vector of AprilTag objects.
*
* @param apriltags Vector of AprilTags.
* @param fieldLength Length of field the layout is representing.
* @param fieldWidth Width of field the layout is representing.
*/
AprilTagFieldLayout(std::vector<AprilTag> apriltags,
units::meter_t fieldLength, units::meter_t fieldWidth);
/**
* Sets the origin based on a predefined enumeration of coordinate frame
* origins. The origins are calculated from the field dimensions.
*
* This transforms the Pose3ds returned by GetTagPose(int) to return the
* correct pose relative to a predefined coordinate frame.
*
* @param origin The predefined origin
*/
void SetOrigin(OriginPosition origin);
/**
* Sets the origin for tag pose transformation.
*
* This tranforms the Pose3ds returned by GetTagPose(int) to return the
* correct pose relative to the provided origin.
*
* @param origin The new origin for tag transformations
*/
void SetOrigin(const Pose3d& origin);
/**
* Gets an AprilTag pose by its ID.
*
* @param ID The ID of the tag.
* @return The pose corresponding to the ID that was passed in or an empty
* optional if a tag with that ID is not found.
*/
std::optional<Pose3d> GetTagPose(int ID) const;
/**
* Serializes an AprilTagFieldLayout to a JSON file.
*
* @param path The path to write the JSON file to.
*/
void Serialize(std::string_view path);
/*
* Checks equality between this AprilTagFieldLayout and another object.
*/
bool operator==(const AprilTagFieldLayout&) const = default;
private:
std::unordered_map<int, AprilTag> m_apriltags;
units::meter_t m_fieldLength;
units::meter_t m_fieldWidth;
Pose3d m_origin;
friend WPILIB_DLLEXPORT void to_json(wpi::json& json,
const AprilTagFieldLayout& layout);
friend WPILIB_DLLEXPORT void from_json(const wpi::json& json,
AprilTagFieldLayout& layout);
};
WPILIB_DLLEXPORT
void to_json(wpi::json& json, const AprilTagFieldLayout& layout);
WPILIB_DLLEXPORT
void from_json(const wpi::json& json, AprilTagFieldLayout& layout);
} // namespace frc

View File

@@ -0,0 +1,32 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <string_view>
#include <wpi/SymbolExports.h>
#include "frc/apriltag/AprilTagFieldLayout.h"
namespace frc {
enum class AprilTagField {
k2022RapidReact,
k2023ChargedUp,
// This is a placeholder for denoting the last supported field. This should
// always be the last entry in the enum and should not be used by users
kNumFields,
};
/**
* Loads an AprilTagFieldLayout from a predefined field
*
* @param field The predefined field
*/
WPILIB_DLLEXPORT AprilTagFieldLayout
LoadAprilTagLayoutField(AprilTagField field);
} // namespace frc

View File

@@ -0,0 +1,36 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <wpi/SymbolExports.h>
#include "frc/geometry/Transform3d.h"
namespace frc {
/** A pair of AprilTag pose estimates. */
struct WPILIB_DLLEXPORT AprilTagPoseEstimate {
/** Pose 1. */
Transform3d pose1;
/** Pose 2. */
Transform3d pose2;
/** Object-space error of pose 1. */
double error1;
/** Object-space error of pose 2. */
double error2;
/**
* Gets the ratio of pose reprojection errors, called ambiguity. Numbers
* above 0.2 are likely to be ambiguous.
*
* @return The ratio of pose reprojection errors.
*/
double GetAmbiguity() const;
};
} // namespace frc

View File

@@ -0,0 +1,145 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <span>
#include <units/length.h>
#include <wpi/SymbolExports.h>
#include "frc/apriltag/AprilTagPoseEstimate.h"
#include "frc/geometry/Transform3d.h"
namespace frc {
class AprilTagDetection;
/** Pose estimators for AprilTag tags. */
class WPILIB_DLLEXPORT AprilTagPoseEstimator {
public:
/** Configuration for the pose estimator. */
struct Config {
bool operator==(const Config&) const = default;
/** The tag size. */
units::meter_t tagSize;
/** Camera horizontal focal length, in pixels. */
double fx;
/** Camera vertical focal length, in pixels. */
double fy;
/** Camera horizontal focal center, in pixels. */
double cx;
/** Camera vertical focal center, in pixels. */
double cy;
};
/**
* Creates estimator.
*
* @param config Configuration
*/
explicit AprilTagPoseEstimator(const Config& config) : m_config{config} {}
/**
* Sets estimator configuration.
*
* @param config Configuration
*/
void SetConfig(const Config& config) { m_config = config; }
/**
* Gets estimator configuration.
*
* @return Configuration
*/
const Config& GetConfig() const { return m_config; }
/**
* Estimates the pose of the tag using the homography method described in [1].
*
* @param detection Tag detection
* @return Pose estimate
*/
Transform3d EstimateHomography(const AprilTagDetection& detection) const;
/**
* Estimates the pose of the tag using the homography method described in [1].
*
* @param homography Homography 3x3 matrix data
* @return Pose estimate
*/
Transform3d EstimateHomography(std::span<const double, 9> homography) const;
/**
* Estimates the pose of the tag. This returns one or two possible poses for
* the tag, along with the object-space error of each.
*
* This uses the homography method described in [1] for the initial estimate.
* Then Orthogonal Iteration [2] is used to refine this estimate. Then [3] is
* used to find a potential second local minima and Orthogonal Iteration is
* used to refine this second estimate.
*
* [1]: E. Olson, “Apriltag: A robust and flexible visual fiducial system,” in
* 2011 IEEE International Conference on Robotics and Automation,
* May 2011, pp. 34003407.
* [2]: Lu, G. D. Hager and E. Mjolsness, "Fast and globally convergent pose
* estimation from video images," in IEEE Transactions on Pattern
* Analysis and Machine Intelligence, vol. 22, no. 6, pp. 610-622, June 2000.
* doi: 10.1109/34.862199
* [3]: Schweighofer and A. Pinz, "Robust Pose Estimation from a Planar
* Target," in IEEE Transactions on Pattern Analysis and Machine Intelligence,
* vol. 28, no. 12, pp. 2024-2030, Dec. 2006. doi: 10.1109/TPAMI.2006.252
*
* @param detection Tag detection
* @param nIters Number of iterations
* @return Initial and (possibly) second pose estimates
*/
AprilTagPoseEstimate EstimateOrthogonalIteration(
const AprilTagDetection& detection, int nIters) const;
/**
* Estimates the pose of the tag. This returns one or two possible poses for
* the tag, along with the object-space error of each.
*
* @param homography Homography 3x3 matrix data
* @param corners Corner point array (X and Y for each corner in order)
* @param nIters Number of iterations
* @return Initial and (possibly) second pose estimates
*/
AprilTagPoseEstimate EstimateOrthogonalIteration(
std::span<const double, 9> homography, std::span<const double, 8> corners,
int nIters) const;
/**
* Estimates tag pose. This method is an easier to use interface to
* EstimatePoseOrthogonalIteration(), running 50 iterations and returning the
* pose with the lower object-space error.
*
* @param detection Tag detection
* @return Pose estimate
*/
Transform3d Estimate(const AprilTagDetection& detection) const;
/**
* Estimates tag pose. This method is an easier to use interface to
* EstimatePoseOrthogonalIteration(), running 50 iterations and returning the
* pose with the lower object-space error.
*
* @param homography Homography 3x3 matrix data
* @param corners Corner point array (X and Y for each corner in order)
* @return Pose estimate
*/
Transform3d Estimate(std::span<const double, 9> homography,
std::span<const double, 8> corners) const;
private:
Config m_config;
};
} // namespace frc

View File

@@ -0,0 +1,440 @@
{
"tags": [
{
"ID": 0,
"pose": {
"translation": {
"x": -0.0035306,
"y": 7.578928199999999,
"z": 0.8858503999999999
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
},
{
"ID": 1,
"pose": {
"translation": {
"x": 3.2327088,
"y": 5.486654,
"z": 1.7254728
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
},
{
"ID": 2,
"pose": {
"translation": {
"x": 3.067812,
"y": 5.3305202,
"z": 1.3762228
},
"rotation": {
"quaternion": {
"W": 0.7071067811865476,
"X": 0.0,
"Y": 0.0,
"Z": -0.7071067811865475
}
}
}
},
{
"ID": 3,
"pose": {
"translation": {
"x": 0.0039878,
"y": 5.058536999999999,
"z": 0.80645
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
},
{
"ID": 4,
"pose": {
"translation": {
"x": 0.0039878,
"y": 3.5124898,
"z": 0.80645
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
},
{
"ID": 5,
"pose": {
"translation": {
"x": 0.12110719999999998,
"y": 1.7178274,
"z": 0.8906002000000001
},
"rotation": {
"quaternion": {
"W": 0.9196502204050923,
"X": 0.0,
"Y": 0.0,
"Z": 0.39273842708457407
}
}
}
},
{
"ID": 6,
"pose": {
"translation": {
"x": 0.8733027999999999,
"y": 0.9412985999999999,
"z": 0.8906002000000001
},
"rotation": {
"quaternion": {
"W": 0.9196502204050923,
"X": 0.0,
"Y": 0.0,
"Z": 0.39273842708457407
}
}
}
},
{
"ID": 7,
"pose": {
"translation": {
"x": 1.6150844,
"y": 0.15725139999999999,
"z": 0.8906002000000001
},
"rotation": {
"quaternion": {
"W": 0.9196502204050923,
"X": 0.0,
"Y": 0.0,
"Z": 0.39273842708457407
}
}
}
},
{
"ID": 10,
"pose": {
"translation": {
"x": 16.4627306,
"y": 0.6506718,
"z": 0.8858503999999999
},
"rotation": {
"quaternion": {
"W": 6.123233995736766E-17,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 11,
"pose": {
"translation": {
"x": 13.2350002,
"y": 2.743454,
"z": 1.7254728
},
"rotation": {
"quaternion": {
"W": 6.123233995736766E-17,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 12,
"pose": {
"translation": {
"x": 13.391388000000001,
"y": 2.8998418,
"z": 1.3762228
},
"rotation": {
"quaternion": {
"W": 0.7071067811865476,
"X": 0.0,
"Y": 0.0,
"Z": 0.7071067811865475
}
}
}
},
{
"ID": 13,
"pose": {
"translation": {
"x": 16.4552122,
"y": 3.1755079999999998,
"z": 0.80645
},
"rotation": {
"quaternion": {
"W": 6.123233995736766E-17,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 14,
"pose": {
"translation": {
"x": 16.4552122,
"y": 4.7171356,
"z": 0.80645
},
"rotation": {
"quaternion": {
"W": 6.123233995736766E-17,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 15,
"pose": {
"translation": {
"x": 16.3350194,
"y": 6.5149729999999995,
"z": 0.8937752
},
"rotation": {
"quaternion": {
"W": -0.37298778257580906,
"X": -0.0,
"Y": 0.0,
"Z": 0.9278362538989199
}
}
}
},
{
"ID": 16,
"pose": {
"translation": {
"x": 15.5904946,
"y": 7.292695599999999,
"z": 0.8906002000000001
},
"rotation": {
"quaternion": {
"W": -0.37298778257580906,
"X": -0.0,
"Y": 0.0,
"Z": 0.9278362538989199
}
}
}
},
{
"ID": 17,
"pose": {
"translation": {
"x": 14.847188999999998,
"y": 8.0691228,
"z": 0.8906002000000001
},
"rotation": {
"quaternion": {
"W": -0.37298778257580906,
"X": -0.0,
"Y": 0.0,
"Z": 0.9278362538989199
}
}
}
},
{
"ID": 40,
"pose": {
"translation": {
"x": 7.874127,
"y": 4.9131728,
"z": 0.7032752
},
"rotation": {
"quaternion": {
"W": 0.5446390350150271,
"X": 0.0,
"Y": 0.0,
"Z": 0.838670567945424
}
}
}
},
{
"ID": 41,
"pose": {
"translation": {
"x": 7.4312271999999995,
"y": 3.759327,
"z": 0.7032752
},
"rotation": {
"quaternion": {
"W": -0.20791169081775934,
"X": -0.0,
"Y": 0.0,
"Z": 0.9781476007338057
}
}
}
},
{
"ID": 42,
"pose": {
"translation": {
"x": 8.585073,
"y": 3.3164272,
"z": 0.7032752
},
"rotation": {
"quaternion": {
"W": 0.838670567945424,
"X": 0.0,
"Y": 0.0,
"Z": -0.5446390350150271
}
}
}
},
{
"ID": 43,
"pose": {
"translation": {
"x": 9.0279728,
"y": 4.470273,
"z": 0.7032752
},
"rotation": {
"quaternion": {
"W": 0.9781476007338057,
"X": 0.0,
"Y": 0.0,
"Z": 0.20791169081775934
}
}
}
},
{
"ID": 50,
"pose": {
"translation": {
"x": 7.6790296,
"y": 4.3261534,
"z": 2.4177244
},
"rotation": {
"quaternion": {
"W": 0.17729273396782605,
"X": -0.22744989571511945,
"Y": 0.04215534644161733,
"Z": 0.9565859910053995
}
}
}
},
{
"ID": 51,
"pose": {
"translation": {
"x": 8.0182466,
"y": 3.5642296,
"z": 2.4177244
},
"rotation": {
"quaternion": {
"W": -0.5510435465842192,
"X": -0.19063969497246985,
"Y": -0.13102303230819815,
"Z": 0.8017733354717242
}
}
}
},
{
"ID": 52,
"pose": {
"translation": {
"x": 8.7801704,
"y": 3.9034466,
"z": 2.4177244
},
"rotation": {
"quaternion": {
"W": -0.9565859910053994,
"X": -0.04215534644161739,
"Y": -0.22744989571511942,
"Z": 0.17729273396782633
}
}
}
},
{
"ID": 53,
"pose": {
"translation": {
"x": 8.4409534,
"y": 4.6653704,
"z": 2.4177244
},
"rotation": {
"quaternion": {
"W": 0.8017733354717241,
"X": -0.1310230323081982,
"Y": 0.19063969497246983,
"Z": 0.5510435465842194
}
}
}
}
],
"field": {
"length": 16.4592,
"width": 8.2296
}
}

View File

@@ -0,0 +1,152 @@
{
"tags": [
{
"ID": 1,
"pose": {
"translation": {
"x": 15.513558,
"y": 1.071626,
"z": 0.462788
},
"rotation": {
"quaternion": {
"W": 0.0,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 2,
"pose": {
"translation": {
"x": 15.513558,
"y": 2.748026,
"z": 0.462788
},
"rotation": {
"quaternion": {
"W": 0.0,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 3,
"pose": {
"translation": {
"x": 15.513558,
"y": 4.424426,
"z": 0.462788
},
"rotation": {
"quaternion": {
"W": 0.0,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 4,
"pose": {
"translation": {
"x": 16.178784,
"y": 6.749796,
"z": 0.695452
},
"rotation": {
"quaternion": {
"W": 0.0,
"X": 0.0,
"Y": 0.0,
"Z": 1.0
}
}
}
},
{
"ID": 5,
"pose": {
"translation": {
"x": 0.36195,
"y": 6.749796,
"z": 0.695452
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
},
{
"ID": 6,
"pose": {
"translation": {
"x": 1.02743,
"y": 4.424426,
"z": 0.462788
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
},
{
"ID": 7,
"pose": {
"translation": {
"x": 1.02743,
"y": 2.748026,
"z": 0.462788
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
},
{
"ID": 8,
"pose": {
"translation": {
"x": 1.02743,
"y": 1.071626,
"z": 0.462788
},
"rotation": {
"quaternion": {
"W": 1.0,
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
}
}
],
"field": {
"length": 16.54175,
"width": 8.0137
}
}

View File

@@ -0,0 +1,264 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.util.RuntimeLoader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
@SuppressWarnings("PMD.MutableStaticState")
class AprilTagDetectorTest {
@SuppressWarnings("MemberName")
AprilTagDetector detector;
static RuntimeLoader<Core> loader;
@BeforeAll
static void beforeAll() {
try {
loader =
new RuntimeLoader<>(
Core.NATIVE_LIBRARY_NAME, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
loader.loadLibrary();
} catch (IOException ex) {
fail(ex);
}
}
@BeforeEach
void beforeEach() {
detector = new AprilTagDetector();
}
@AfterEach
void afterEach() {
detector.close();
}
@Test
void testConfigDefaults() {
var config = detector.getConfig();
assertEquals(new AprilTagDetector.Config(), config);
}
@Test
void testQtpDefaults() {
var params = detector.getQuadThresholdParameters();
assertEquals(new AprilTagDetector.QuadThresholdParameters(), params);
}
@Test
void testSetConfigNumThreads() {
var newConfig = new AprilTagDetector.Config();
newConfig.numThreads = 2;
detector.setConfig(newConfig);
var config = detector.getConfig();
assertEquals(2, config.numThreads);
}
@Test
void testQtpMinClusterPixels() {
var newParams = new AprilTagDetector.QuadThresholdParameters();
newParams.minClusterPixels = 8;
detector.setQuadThresholdParameters(newParams);
var params = detector.getQuadThresholdParameters();
assertEquals(8, params.minClusterPixels);
}
@Test
void testAdd16h5() {
assertDoesNotThrow(() -> detector.addFamily("tag16h5"));
// duplicate addition is also okay
assertDoesNotThrow(() -> detector.addFamily("tag16h5"));
}
@Test
void testAdd25h9() {
assertDoesNotThrow(() -> detector.addFamily("tag25h9"));
}
@Test
void testAdd36h11() {
assertDoesNotThrow(() -> detector.addFamily("tag36h11"));
}
@Test
void testAddMultiple() {
assertDoesNotThrow(() -> detector.addFamily("tag16h5"));
assertDoesNotThrow(() -> detector.addFamily("tag36h11"));
}
@Test
void testRemoveFamily() {
// okay to remove non-existent family
detector.removeFamily("tag16h5");
// add and remove
detector.addFamily("tag16h5");
detector.removeFamily("tag16h5");
}
@SuppressWarnings("PMD.AssignmentInOperand")
public Mat loadImage(String resource) throws IOException {
Mat encoded;
try (InputStream is = getClass().getResource(resource).openStream()) {
try (ByteArrayOutputStream os = new ByteArrayOutputStream(is.available())) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
encoded = new Mat(1, os.size(), CvType.CV_8U);
encoded.put(0, 0, os.toByteArray());
}
}
Mat image = Imgcodecs.imdecode(encoded, Imgcodecs.IMREAD_COLOR);
encoded.release();
Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2GRAY);
return image;
}
@Test
void testDecodeAndPose() {
detector.addFamily("tag16h5");
detector.addFamily("tag36h11");
Mat image;
try {
image = loadImage("tag1_640_480.jpg");
} catch (IOException ex) {
fail(ex);
return;
}
try {
AprilTagDetection[] results = detector.detect(image);
assertEquals(1, results.length);
assertEquals("tag36h11", results[0].getFamily());
assertEquals(1, results[0].getId());
assertEquals(0, results[0].getHamming());
var estimator =
new AprilTagPoseEstimator(new AprilTagPoseEstimator.Config(0.2, 500, 500, 320, 240));
AprilTagPoseEstimate est = estimator.estimateOrthogonalIteration(results[0], 50);
assertEquals(new Transform3d(), est.pose2);
Transform3d pose = estimator.estimate(results[0]);
assertEquals(est.pose1, pose);
} finally {
image.release();
}
}
/**
* This tag is rotated such that the top is closer to the camera than the bottom. In the camera
* frame, with +x to the right, this is a rotation about +X by 45 degrees.
*/
@Test
void testPoseRotatedX() {
detector.addFamily("tag16h5");
Mat image;
try {
image = loadImage("tag2_45deg_X.png");
} catch (IOException ex) {
fail(ex);
return;
}
try {
AprilTagDetection[] results = detector.detect(image);
assertEquals(1, results.length);
var estimator =
new AprilTagPoseEstimator(
new AprilTagPoseEstimator.Config(
0.2, 500, 500, image.cols() / 2.0, image.rows() / 2.0));
AprilTagPoseEstimate est = estimator.estimateOrthogonalIteration(results[0], 50);
assertEquals(Units.degreesToRadians(45), est.pose1.getRotation().getX(), 0.1);
assertEquals(Units.degreesToRadians(0), est.pose1.getRotation().getY(), 0.1);
assertEquals(Units.degreesToRadians(0), est.pose1.getRotation().getZ(), 0.1);
} finally {
image.release();
}
}
/**
* This tag is rotated such that the right is closer to the camera than the left. In the camera
* frame, with +y down, this is a rotation of 45 degrees about +y.
*/
@Test
void testPoseRotatedY() {
detector.addFamily("tag16h5");
Mat image;
try {
image = loadImage("tag2_45deg_y.png");
} catch (IOException ex) {
fail(ex);
return;
}
try {
AprilTagDetection[] results = detector.detect(image);
assertEquals(1, results.length);
var estimator =
new AprilTagPoseEstimator(
new AprilTagPoseEstimator.Config(
0.2, 500, 500, image.cols() / 2.0, image.rows() / 2.0));
AprilTagPoseEstimate est = estimator.estimateOrthogonalIteration(results[0], 50);
assertEquals(Units.degreesToRadians(0), est.pose1.getRotation().getX(), 0.1);
assertEquals(Units.degreesToRadians(45), est.pose1.getRotation().getY(), 0.1);
assertEquals(Units.degreesToRadians(0), est.pose1.getRotation().getZ(), 0.1);
} finally {
image.release();
}
}
/** This tag is facing right at the camera -- no rotation should be observed. */
@Test
void testPoseStraightOn() {
detector.addFamily("tag16h5");
Mat image;
try {
image = loadImage("tag2_16h5_straight.png");
} catch (IOException ex) {
fail(ex);
return;
}
try {
AprilTagDetection[] results = detector.detect(image);
assertEquals(1, results.length);
var estimator =
new AprilTagPoseEstimator(
new AprilTagPoseEstimator.Config(
0.2, 500, 500, image.cols() / 2.0, image.rows() / 2.0));
AprilTagPoseEstimate est = estimator.estimateOrthogonalIteration(results[0], 50);
assertEquals(Units.degreesToRadians(0), est.pose1.getRotation().getX(), 0.1);
assertEquals(Units.degreesToRadians(0), est.pose1.getRotation().getY(), 0.1);
assertEquals(Units.degreesToRadians(0), est.pose1.getRotation().getZ(), 0.1);
} finally {
image.release();
}
}
}

View File

@@ -0,0 +1,46 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Translation3d;
import edu.wpi.first.math.util.Units;
import java.util.List;
import org.junit.jupiter.api.Test;
class AprilTagPoseSetOriginTest {
@Test
void transformationMatches() {
var layout =
new AprilTagFieldLayout(
List.of(
new AprilTag(1, new Pose3d(new Translation3d(0, 0, 0), new Rotation3d(0, 0, 0))),
new AprilTag(
2,
new Pose3d(
new Translation3d(
Units.feetToMeters(4.0), Units.feetToMeters(4), Units.feetToMeters(4)),
new Rotation3d(0, 0, Units.degreesToRadians(180))))),
Units.feetToMeters(54.0),
Units.feetToMeters(27.0));
layout.setOrigin(AprilTagFieldLayout.OriginPosition.kRedAllianceWallRightSide);
assertEquals(
new Pose3d(
new Translation3d(Units.feetToMeters(54.0), Units.feetToMeters(27.0), 0.0),
new Rotation3d(0.0, 0.0, Units.degreesToRadians(180.0))),
layout.getTagPose(1).orElse(null));
assertEquals(
new Pose3d(
new Translation3d(
Units.feetToMeters(50.0), Units.feetToMeters(23.0), Units.feetToMeters(4)),
new Rotation3d(0.0, 0.0, 0)),
layout.getTagPose(2).orElse(null));
}
}

View File

@@ -0,0 +1,38 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.util.Units;
import java.util.List;
import org.junit.jupiter.api.Test;
class AprilTagSerializationTest {
@Test
void deserializeMatches() {
var layout =
new AprilTagFieldLayout(
List.of(
new AprilTag(1, new Pose3d(0, 0, 0, new Rotation3d(0, 0, 0))),
new AprilTag(3, new Pose3d(0, 1, 0, new Rotation3d(0, 0, 0)))),
Units.feetToMeters(54.0),
Units.feetToMeters(27.0));
var objectMapper = new ObjectMapper();
var deserialized =
assertDoesNotThrow(
() ->
objectMapper.readValue(
objectMapper.writeValueAsString(layout), AprilTagFieldLayout.class));
assertEquals(layout, deserialized);
}
}

View File

@@ -0,0 +1,71 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.apriltag;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.util.Units;
import java.io.IOException;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
class LoadConfigTest {
@ParameterizedTest
@EnumSource(AprilTagFields.class)
void testLoad(AprilTagFields field) {
AprilTagFieldLayout layout = Assertions.assertDoesNotThrow(field::loadAprilTagLayoutField);
assertNotNull(layout);
}
@Test
void test2022RapidReact() throws IOException {
AprilTagFieldLayout layout = AprilTagFields.k2022RapidReact.loadAprilTagLayoutField();
// Blue Hangar Truss - Hub
Pose3d expectedPose =
new Pose3d(
Units.inchesToMeters(127.272),
Units.inchesToMeters(216.01),
Units.inchesToMeters(67.932),
new Rotation3d(0, 0, 0));
Optional<Pose3d> maybePose = layout.getTagPose(1);
assertTrue(maybePose.isPresent());
assertEquals(expectedPose, maybePose.get());
// Blue Terminal Near Station
expectedPose =
new Pose3d(
Units.inchesToMeters(4.768),
Units.inchesToMeters(67.631),
Units.inchesToMeters(35.063),
new Rotation3d(0, 0, Math.toRadians(46.25)));
maybePose = layout.getTagPose(5);
assertTrue(maybePose.isPresent());
assertEquals(expectedPose, maybePose.get());
// Upper Hub Blue-Near
expectedPose =
new Pose3d(
Units.inchesToMeters(332.321),
Units.inchesToMeters(183.676),
Units.inchesToMeters(95.186),
new Rotation3d(0, Math.toRadians(26.75), Math.toRadians(69)));
maybePose = layout.getTagPose(53);
assertTrue(maybePose.isPresent());
assertEquals(expectedPose, maybePose.get());
// Doesn't exist
maybePose = layout.getTagPose(54);
assertFalse(maybePose.isPresent());
}
}

View File

@@ -0,0 +1,67 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagDetector.h"
#include "gtest/gtest.h"
using namespace frc;
TEST(AprilTagDetectorTest, ConfigDefaults) {
AprilTagDetector detector;
auto config = detector.GetConfig();
ASSERT_EQ(config, AprilTagDetector::Config{});
}
TEST(AprilTagDetectorTest, QtpDefaults) {
AprilTagDetector detector;
auto params = detector.GetQuadThresholdParameters();
ASSERT_EQ(params, AprilTagDetector::QuadThresholdParameters{});
}
TEST(AprilTagDetectorTest, SetConfigNumThreads) {
AprilTagDetector detector;
detector.SetConfig({.numThreads = 2});
auto config = detector.GetConfig();
ASSERT_EQ(config.numThreads, 2);
}
TEST(AprilTagDetectorTest, QtpMinClusterPixels) {
AprilTagDetector detector;
detector.SetQuadThresholdParameters({.minClusterPixels = 8});
auto params = detector.GetQuadThresholdParameters();
ASSERT_EQ(params.minClusterPixels, 8);
}
TEST(AprilTagDetectorTest, Add16h5) {
AprilTagDetector detector;
ASSERT_TRUE(detector.AddFamily("tag16h5"));
// duplicate addition is also okay
ASSERT_TRUE(detector.AddFamily("tag16h5"));
}
TEST(AprilTagDetectorTest, Add25h9) {
AprilTagDetector detector;
ASSERT_TRUE(detector.AddFamily("tag25h9"));
}
TEST(AprilTagDetectorTest, Add36h11) {
AprilTagDetector detector;
ASSERT_TRUE(detector.AddFamily("tag36h11"));
}
TEST(AprilTagDetectorTest, AddMultiple) {
AprilTagDetector detector;
ASSERT_TRUE(detector.AddFamily("tag16h5"));
ASSERT_TRUE(detector.AddFamily("tag36h11"));
}
TEST(AprilTagDetectorTest, RemoveFamily) {
AprilTagDetector detector;
// okay to remove non-existent family
detector.RemoveFamily("tag16h5");
// add and remove
detector.AddFamily("tag16h5");
detector.RemoveFamily("tag16h5");
}

View File

@@ -0,0 +1,27 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <vector>
#include <wpi/json.h>
#include "frc/apriltag/AprilTag.h"
#include "frc/apriltag/AprilTagFieldLayout.h"
#include "frc/geometry/Pose3d.h"
#include "gtest/gtest.h"
using namespace frc;
TEST(AprilTagJsonTest, DeserializeMatches) {
auto layout = AprilTagFieldLayout{
std::vector{
AprilTag{1, Pose3d{}},
AprilTag{3, Pose3d{0_m, 1_m, 0_m, Rotation3d{0_deg, 0_deg, 0_deg}}}},
54_ft, 27_ft};
AprilTagFieldLayout deserialized;
wpi::json json = layout;
EXPECT_NO_THROW(deserialized = json.get<AprilTagFieldLayout>());
EXPECT_EQ(layout, deserialized);
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <vector>
#include <wpi/json.h>
#include "frc/apriltag/AprilTag.h"
#include "frc/apriltag/AprilTagFieldLayout.h"
#include "frc/geometry/Pose3d.h"
#include "gtest/gtest.h"
using namespace frc;
TEST(AprilTagPoseSetOriginTest, TransformationMatches) {
auto layout = AprilTagFieldLayout{
std::vector<AprilTag>{
AprilTag{1,
Pose3d{0_ft, 0_ft, 0_ft, Rotation3d{0_deg, 0_deg, 0_deg}}},
AprilTag{
2, Pose3d{4_ft, 4_ft, 4_ft, Rotation3d{0_deg, 0_deg, 180_deg}}}},
54_ft, 27_ft};
layout.SetOrigin(
AprilTagFieldLayout::OriginPosition::kRedAllianceWallRightSide);
auto mirrorPose =
Pose3d{54_ft, 27_ft, 0_ft, Rotation3d{0_deg, 0_deg, 180_deg}};
EXPECT_EQ(mirrorPose, *layout.GetTagPose(1));
mirrorPose = Pose3d{50_ft, 23_ft, 4_ft, Rotation3d{0_deg, 0_deg, 0_deg}};
EXPECT_EQ(mirrorPose, *layout.GetTagPose(2));
}

View File

@@ -0,0 +1,61 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/apriltag/AprilTagFields.h"
#include "gtest/gtest.h"
namespace frc {
std::vector<AprilTagField> GetAllFields() {
std::vector<AprilTagField> output;
for (int i = 0; i < static_cast<int>(AprilTagField::kNumFields); ++i) {
output.push_back(static_cast<AprilTagField>(i));
}
return output;
}
TEST(AprilTagFieldsTest, TestLoad2022RapidReact) {
AprilTagFieldLayout layout =
LoadAprilTagLayoutField(AprilTagField::k2022RapidReact);
// Blue Hangar Truss - Hub
auto expectedPose =
Pose3d{127.272_in, 216.01_in, 67.932_in, Rotation3d{0_deg, 0_deg, 0_deg}};
auto maybePose = layout.GetTagPose(1);
EXPECT_TRUE(maybePose);
EXPECT_EQ(expectedPose, *maybePose);
// Blue Terminal Near Station
expectedPose = Pose3d{4.768_in, 67.631_in, 35.063_in,
Rotation3d{0_deg, 0_deg, 46.25_deg}};
maybePose = layout.GetTagPose(5);
EXPECT_TRUE(maybePose);
EXPECT_EQ(expectedPose, *maybePose);
// Upper Hub Blue-Near
expectedPose = Pose3d{332.321_in, 183.676_in, 95.186_in,
Rotation3d{0_deg, 26.75_deg, 69_deg}};
maybePose = layout.GetTagPose(53);
EXPECT_TRUE(maybePose);
EXPECT_EQ(expectedPose, *maybePose);
// Doesn't exist
maybePose = layout.GetTagPose(54);
EXPECT_FALSE(maybePose);
}
// Test all of the fields in the enum
class AllFieldsFixtureTest : public ::testing::TestWithParam<AprilTagField> {};
TEST_P(AllFieldsFixtureTest, CheckEntireEnum) {
AprilTagField field = GetParam();
EXPECT_NO_THROW(LoadAprilTagLayoutField(field));
}
INSTANTIATE_TEST_SUITE_P(ValuesEnumTestInstTests, AllFieldsFixtureTest,
::testing::ValuesIn(GetAllFields()));
} // namespace frc

View File

@@ -0,0 +1,11 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "gtest/gtest.h"
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -4,88 +4,89 @@ trigger:
batch: true
branches:
include:
- master
- master
stages:
- stage: Build
jobs:
- job: IntegrationTests
displayName: Integration Tests
pool:
vmImage: 'Ubuntu 16.04'
- stage: Build
jobs:
- job: IntegrationTests
displayName: Integration Tests
pool:
vmImage: 'ubuntu-latest'
container:
image: wpilib/roborio-cross-ubuntu:2020-18.04
container:
image: wpilib/roborio-cross-ubuntu:2023-22.04
timeoutInMinutes: 0
timeoutInMinutes: 0
steps:
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'copyWpilibJIntegrationTestJarToOutput copyWpilibCTestLibrariesToOutput'
options: '-Ponlylinuxathena -PbuildServer'
steps:
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ""
gradleWrapperFile: "gradlew"
gradleOptions: "-Xmx3072m"
publishJUnitResults: false
testResultsFiles: "**/TEST-*.xml"
tasks: "copyWpilibJIntegrationTestJarToOutput copyWpilibCTestLibrariesToOutput"
options: "-Ponlylinuxathena -PbuildServer -PskipJavaFormat"
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Integration Tests'
targetPath: 'build/integrationTestFiles'
- task: PublishPipelineArtifact@0
inputs:
artifactName: "Integration Tests"
targetPath: "build/integrationTestFiles"
- stage: TestBench
displayName: Test Bench
jobs:
- job: Cpp
displayName: C++
pool: RoboRioConnections
timeoutInMinutes: 30
workspace:
clean: all
steps:
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Integration Tests'
targetPath: 'build/integrationTestFiles'
- stage: TestBench
displayName: Test Bench
condition: false
jobs:
- job: Cpp
displayName: C++
pool: RoboRioConnections
timeoutInMinutes: 30
workspace:
clean: all
steps:
- task: DownloadPipelineArtifact@0
inputs:
artifactName: "Integration Tests"
targetPath: "build/integrationTestFiles"
- task: ShellScript@2
displayName: Run C++ Tests
inputs:
scriptPath: test-scripts/deploy-and-run-test-on-robot.sh
args: 'cpp -A "--gtest_output=xml:/home/admin/testResults/cppreport.xml"'
- task: ShellScript@2
displayName: Run C++ Tests
inputs:
scriptPath: test-scripts/deploy-and-run-test-on-robot.sh
args: 'cpp -A "--gtest_output=xml:/home/admin/testResults/cppreport.xml"'
- task: PublishTestResults@2
displayName: Publish C++ Test Results
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
testRunTitle: 'C++ Test Report'
searchFolder: '$(System.DefaultWorkingDirectory)/test-reports'
- task: PublishTestResults@2
displayName: Publish C++ Test Results
inputs:
testResultsFormat: "JUnit"
testResultsFiles: "*.xml"
testRunTitle: "C++ Test Report"
searchFolder: "$(System.DefaultWorkingDirectory)/test-reports"
- job: Java
pool: RoboRioConnections
timeoutInMinutes: 30
workspace:
clean: all
steps:
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Integration Tests'
targetPath: 'build/integrationTestFiles'
- job: Java
pool: RoboRioConnections
timeoutInMinutes: 30
workspace:
clean: all
steps:
- task: DownloadPipelineArtifact@0
inputs:
artifactName: "Integration Tests"
targetPath: "build/integrationTestFiles"
- task: ShellScript@2
displayName: Run Java Tests
inputs:
scriptPath: test-scripts/deploy-and-run-test-on-robot.sh
args: 'java'
- task: ShellScript@2
displayName: Run Java Tests
inputs:
scriptPath: test-scripts/deploy-and-run-test-on-robot.sh
args: "java"
- task: PublishTestResults@2
displayName: Publish Java Test Results
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
testRunTitle: 'Java Test Report'
searchFolder: '$(System.DefaultWorkingDirectory)/test-reports'
- task: PublishTestResults@2
displayName: Publish Java Test Results
inputs:
testResultsFormat: "JUnit"
testResultsFiles: "*.xml"
testRunTitle: "Java Test Report"
searchFolder: "$(System.DefaultWorkingDirectory)/test-reports"

View File

@@ -1,417 +0,0 @@
# Gradle
# Build your Java projects and run tests with Gradle using a Gradle wrapper script.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/vsts/pipelines/languages/java
resources:
containers:
- container: wpilib2020
image: wpilib/roborio-cross-ubuntu:2020-18.04
- container: raspbian
image: wpilib/raspbian-cross-ubuntu:10-18.04
- container: aarch64
image: wpilib/aarch64-cross-ubuntu:bionic-18.04
- container: ubuntu
image: wpilib/ubuntu-base:18.04
variables:
- group: Artifactory-Package-Publish
trigger:
batch: true
branches:
include:
- master
stages:
- stage: Build
jobs:
- job: Linux_Arm
pool:
vmImage: 'Ubuntu 16.04'
container: wpilib2020
timeoutInMinutes: 0
steps:
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-Ponlylinuxathena -PbuildServer'
- task: Gradle@2
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-Ponlylinuxathena -PreleaseMode -PbuildServer'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Athena'
targetPath: 'build/allOutputs'
- job: Linux_Raspbian
pool:
vmImage: 'Ubuntu 16.04'
container: raspbian
timeoutInMinutes: 0
steps:
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-Ponlylinuxraspbian -PbuildServer'
- task: Gradle@2
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-Ponlylinuxraspbian -PreleaseMode -PbuildServer'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Raspbian'
targetPath: 'build/allOutputs'
- job: Linux_Aarch64
pool:
vmImage: 'Ubuntu 16.04'
container: aarch64
timeoutInMinutes: 0
steps:
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-Ponlylinuxaarch64bionic -PbuildServer'
- task: Gradle@2
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-Ponlylinuxaarch64bionic -PreleaseMode -PbuildServer'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Aarch64'
targetPath: 'build/allOutputs'
- job: Linux
pool:
vmImage: 'Ubuntu 16.04'
container: ubuntu
timeoutInMinutes: 0
steps:
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PbuildServer'
- task: Gradle@2
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PreleaseMode -PbuildServer'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Linux'
targetPath: 'build/allOutputs'
- job: Styleguide
pool:
vmImage: 'Ubuntu 16.04'
container: ubuntu
timeoutInMinutes: 0
steps:
- script: |
sudo pip3 install wpiformat
displayName: 'Install wpiformat'
- script: |
git checkout -b master
wpiformat -clang 6.0
displayName: 'Run wpiformat'
- script: |
# Ensure formatter made no changes
git --no-pager diff --exit-code HEAD
displayName: 'Check wpiformat Output'
- job: CMakeBuild
pool:
vmImage: 'Ubuntu 16.04'
container: wpilib2020
timeoutInMinutes: 0
steps:
- task: CMake@1
inputs:
cmakeArgs: '-DWITHOUT_ALLWPILIB=OFF ..'
- script: |
make -j3
workingDirectory: 'build'
displayName: 'Build'
- job: Windows_64_Bit
pool:
vmImage: 'windows-2019'
timeoutInMinutes: 0
steps:
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
jdkVersionOption: '1.11'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PskipPMD -PbuildServer'
- task: Gradle@2
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
jdkVersionOption: '1.11'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PskipPMD -PreleaseMode -PbuildServer'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Win64'
targetPath: 'build/allOutputs'
- job: Windows_32_Bit
pool:
vmImage: 'windows-2019'
timeoutInMinutes: 0
steps:
- powershell: |
mkdir build
$ProgressPreference = 'SilentlyContinue'
wget "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.4%2B11/OpenJDK11U-jdk_x86-32_windows_hotspot_11.0.4_11.zip" -O "build\jdk.zip"
displayName: 'Download JDK'
- task: JavaToolInstaller@0
inputs:
jdkSourceOption: localDirectory
jdkFile: 'build/jdk.zip'
jdkDestinationDirectory: 'build/jdkinst'
jdkArchitectureOption: x86
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx1024m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PskipPMD -PbuildServer'
- task: Gradle@2
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx1024m'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PskipPMD -PreleaseMode -PbuildServer'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Win32'
targetPath: 'build/allOutputs'
- job: Mac
pool:
vmImage: 'macOS-10.14'
timeoutInMinutes: 0
steps:
- script: |
mkdir build
export JAVA_HOME=`/usr/libexec/java_home -v 11`
displayName: 'Setup JDK'
- task: Gradle@2
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
jdkVersionOption: '1.11'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PbuildServer'
- task: Gradle@2
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
jdkVersionOption: '1.11'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
options: '-PreleaseMode -PbuildServer'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Mac'
targetPath: 'build/allOutputs'
- stage: Combine
jobs:
- job: CombineJob
pool:
vmImage: 'macOS-10.14'
timeoutInMinutes: 0
steps:
- checkout: none
- script: |
git clone https://github.com/wpilibsuite/build-tools
displayName: 'Clone Combiner'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Mac'
targetPath: 'build-tools/combiner/products/build/allOutputs'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Win32'
targetPath: 'build-tools/combiner/products/build/allOutputs'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Win64'
targetPath: 'build-tools/combiner/products/build/allOutputs'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Linux'
targetPath: 'build-tools/combiner/products/build/allOutputs'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Raspbian'
targetPath: 'build-tools/combiner/products/build/allOutputs'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Athena'
targetPath: 'build-tools/combiner/products/build/allOutputs'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'Aarch64'
targetPath: 'build-tools/combiner/products/build/allOutputs'
# PR Builds
- task: Gradle@2
inputs:
workingDirectory: 'build-tools/combiner'
gradleWrapperFile: 'build-tools/combiner/gradlew'
gradleOptions: '-Xmx3072m'
tasks: 'publish '
options: '-Pallwpilib'
condition: and(succeeded(), and(ne(variables['Build.SourceBranch'], 'refs/heads/master'), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))))
# Master Builds
- task: Gradle@2
inputs:
workingDirectory: 'build-tools/combiner'
gradleWrapperFile: 'build-tools/combiner/gradlew'
gradleOptions: '-Xmx3072m'
tasks: 'publish '
options: '-Pallwpilib'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
env:
RUN_AZURE_ARTIFACTORY_RELEASE: 'TRUE'
ARTIFACTORY_PUBLISH_USERNAME: $(PublishUserName)
ARTIFACTORY_PUBLISH_PASSWORD: $(PublishPassword)
# Tagged Builds
- task: Gradle@2
inputs:
workingDirectory: 'build-tools/combiner'
gradleWrapperFile: 'build-tools/combiner/gradlew'
gradleOptions: '-Xmx3072m'
tasks: 'publish '
options: '-Pallwpilib -PreleaseRepoPublish'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
env:
RUN_AZURE_ARTIFACTORY_RELEASE: 'TRUE'
ARTIFACTORY_PUBLISH_USERNAME: $(PublishUserName)
ARTIFACTORY_PUBLISH_PASSWORD: $(PublishPassword)
- script: |
echo "##vso[task.setvariable variable=UserHome]$HOME"
displayName: 'Set Home Variable'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Maven'
targetPath: $(UserHome)/releases

View File

@@ -1,29 +1,39 @@
import edu.wpi.first.toolchain.*
buildscript {
repositories {
maven {
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
}
dependencies {
classpath 'com.hubspot.jinjava:jinjava:2.6.0'
}
}
plugins {
id 'base'
id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '4.0.1'
id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '2023.0.1'
id 'edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin' version '2020.2'
id 'edu.wpi.first.NativeUtils' apply false
id 'edu.wpi.first.GradleJni' version '0.10.1'
id 'edu.wpi.first.GradleVsCode' version '0.11.0'
id 'edu.wpi.first.GradleJni' version '1.1.0'
id 'edu.wpi.first.GradleVsCode'
id 'idea'
id 'visual-studio'
id 'net.ltgt.errorprone' version '1.1.1' apply false
id 'com.github.johnrengelman.shadow' version '5.2.0' apply false
id 'net.ltgt.errorprone' version '2.0.2' apply false
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'com.diffplug.spotless' version '6.12.0' apply false
id 'com.github.spotbugs' version '5.0.8' apply false
}
if (project.hasProperty('buildServer')) {
wpilibVersioning.buildServerMode = true
}
if (project.hasProperty('releaseMode')) {
wpilibVersioning.releaseMode = true
}
wpilibVersioning.buildServerMode = project.hasProperty('buildServer')
wpilibVersioning.releaseMode = project.hasProperty('releaseMode')
allprojects {
repositories {
mavenCentral()
maven {
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
}
if (project.hasProperty('releaseMode')) {
wpilibRepositories.addAllReleaseRepositories(it)
@@ -39,7 +49,7 @@ buildScan {
publishAlways()
}
ext.licenseFile = files("$rootDir/LICENSE.txt", "$rootDir/ThirdPartyNotices.txt")
ext.licenseFile = files("$rootDir/LICENSE.md", "$rootDir/ThirdPartyNotices.txt")
if (project.hasProperty("publishVersion")) {
wpilibVersioning.version.set(project.publishVersion)
@@ -77,7 +87,12 @@ task copyAllOutputs(type: Copy) {
build.dependsOn copyAllOutputs
copyAllOutputs.dependsOn outputVersions
def copyReleaseOnly = project.hasProperty('ciReleaseOnly')
ext.addTaskToCopyAllOutputs = { task ->
if (copyReleaseOnly && task.name.contains('debug')) {
return
}
copyAllOutputs.dependsOn task
copyAllOutputs.inputs.file task.archivePath
copyAllOutputs.from task.archivePath
@@ -93,6 +108,11 @@ subprojects {
subproj.apply plugin: MultiBuilds
}
plugins.withType(JavaPlugin) {
sourceCompatibility = 11
targetCompatibility = 11
}
apply from: "${rootDir}/shared/java/javastyle.gradle"
// Disables doclint in java 8.
@@ -103,6 +123,43 @@ subprojects {
}
}
}
tasks.withType(JavaCompile) {
options.compilerArgs.add '-XDstringConcat=inline'
}
// Enables UTF-8 support in Javadoc
tasks.withType(Javadoc) {
options.addStringOption("charset", "utf-8")
options.addStringOption("docencoding", "utf-8")
options.addStringOption("encoding", "utf-8")
}
// Sign outputs with Developer ID
tasks.withType(AbstractLinkTask) { task ->
task.inputs.property "HasDeveloperId", project.hasProperty("developerID")
if (project.hasProperty("developerID")) {
// Don't sign any executables because codesign complains
// about relative rpath.
if (!(task instanceof LinkExecutable)) {
doLast {
// Get path to binary.
String path = task.getLinkedFile().getAsFile().get().getAbsolutePath()
exec {
workingDir rootDir
def args = [
"sh",
"-c",
"codesign --force --strict --timestamp --options=runtime " +
"--verbose -s ${project.findProperty("developerID")} ${path}"
]
commandLine args
}
}
}
}
}
}
ext.getCurrentArch = {
@@ -110,5 +167,5 @@ ext.getCurrentArch = {
}
wrapper {
gradleVersion = '6.0'
gradleVersion = '7.5.1'
}

View File

@@ -1,9 +1,13 @@
repositories {
maven {
url "https://plugins.gradle.org/m2/"
mavenLocal()
maven {
url = 'https://frcmaven.wpi.edu/artifactory/ex-gradle'
}
mavenCentral()
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation "edu.wpi.first:native-utils:2020.7.2"
implementation "edu.wpi.first:native-utils:2023.11.1"
}

View File

@@ -1,48 +0,0 @@
import groovy.transform.CompileStatic
import javax.inject.Inject
import jaci.gradle.deploy.artifact.MavenArtifact
import jaci.gradle.deploy.context.DeployContext
import org.gradle.api.Project
import jaci.gradle.ActionWrapper
import java.util.function.Function
@CompileStatic
class JREArtifact extends MavenArtifact {
Function<DeployContext, Boolean> buildRequiresJre = (Function<DeployContext, Boolean>){ true }
void setJreDependency(String dep) {
dependency = project.dependencies.add(configuration(), dep)
}
@Inject
JREArtifact(String name, Project project) {
super(name, project)
configuration = project.configurations.create(configuration())
onlyIf = { DeployContext ctx ->
(buildRequiresJre.apply(ctx) && jreMissing(ctx)) || project.hasProperty("force-redeploy-jre")
}
predeploy << new ActionWrapper({ DeployContext ctx ->
ctx.logger.log('Deploying RoboRIO JRE (this will take a while)...')
})
directory = '/tmp'
filename = 'frcjre.ipk'
postdeploy << new ActionWrapper({ DeployContext ctx ->
ctx.logger.log('Installing JRE...')
ctx.execute('opkg remove frc2020-openjdk*; opkg install /tmp/frcjre.ipk; rm /tmp/frcjre.ipk')
ctx.logger.log('JRE Deployed!')
})
}
String configuration() {
return name + 'frcjre'
}
boolean jreMissing(DeployContext ctx) {
return ctx.execute('if [[ -f "/usr/local/frc/JRE/bin/java" ]]; then echo OK; else echo MISSING; fi').result.contains("MISSING")
}
}

View File

@@ -6,10 +6,14 @@ import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import org.gradle.api.tasks.Delete
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.Copy;
import org.gradle.api.file.CopySpec;
import org.gradle.api.file.FileTree;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.language.base.internal.ProjectLayout;
@@ -32,6 +36,8 @@ import org.gradle.nativeplatform.toolchain.internal.ToolType;
import org.gradle.nativeplatform.toolchain.internal.gcc.AbstractGccCompatibleToolChain;
import org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppToolChain;
import org.gradle.nativeplatform.toolchain.internal.tools.ToolRegistry;
import org.gradle.nativeplatform.tasks.CreateStaticLibrary;
import org.gradle.nativeplatform.tasks.AbstractLinkTask;
import org.gradle.platform.base.BinarySpec;
import org.gradle.platform.base.ComponentSpec;
import org.gradle.platform.base.ComponentSpecContainer;
@@ -40,7 +46,7 @@ import org.gradle.platform.base.ComponentType;
import org.gradle.platform.base.TypeBuilder;
import org.gradle.nativeplatform.tasks.ObjectFilesToBinary;
import groovy.transform.CompileStatic;
import edu.wpi.first.nativeutils.tasks.ExportsGenerationTask
import edu.wpi.first.nativeutils.exports.ExportsGenerationTask
@CompileStatic
class SingleNativeBuild implements Plugin<Project> {
@@ -79,10 +85,18 @@ class SingleNativeBuild implements Plugin<Project> {
components.each { component ->
if (component.name == "${nativeName}Base") {
base = (NativeLibrarySpec) component
} else if (component.name == "${nativeName}" || component.name == "${nativeName}JNI") {
} else if (component.name == "${nativeName}" || component.name == "${nativeName}JNI" || component.name == "${nativeName}JNICvStatic") {
subs << component
}
}
Delete deleteObjects = null
if (project.hasProperty('buildServer')) {
deleteObjects = project.tasks.create('deleteObjects', Delete)
project.tasks.named('build').configure { Task t ->
t.dependsOn deleteObjects
return
}
}
subs.each {
((NativeLibrarySpec) it).binaries.each { oBinary ->
if (oBinary.buildable == false) {
@@ -100,6 +114,23 @@ class SingleNativeBuild implements Plugin<Project> {
baseBin = tmpBaseBin
}
}
if (binary instanceof StaticLibraryBinarySpec) {
File intoDir = ((CreateStaticLibrary)((StaticLibraryBinarySpec)binary).tasks.createStaticLib).outputFile.get().asFile.parentFile
File fromDir = ((CreateStaticLibrary)((StaticLibraryBinarySpec)baseBin).tasks.createStaticLib).outputFile.get().asFile.parentFile
def copyBasePdbName = "copyBasePdbFor" + binary.buildTask.name
def copyTask = project.tasks.register(copyBasePdbName, Copy) { Copy t ->
t.from (fromDir)
t.include '*.pdb'
t.into intoDir
t.dependsOn (((StaticLibraryBinarySpec)baseBin).tasks.createStaticLib)
}
((CreateStaticLibrary)((StaticLibraryBinarySpec)binary).tasks.createStaticLib).dependsOn(copyTask)
}
baseBin.tasks.withType(AbstractNativeSourceCompileTask) { oCompileTask ->
def compileTask = (AbstractNativeSourceCompileTask) oCompileTask
if (binary instanceof SharedLibraryBinarySpec) {
@@ -115,6 +146,10 @@ class SingleNativeBuild implements Plugin<Project> {
tree.include '**/*.o'
tree.include '**/*.obj'
link.source tree
if (project.hasProperty('buildServer')) {
deleteObjects.dependsOn link
deleteObjects.delete tree
}
} else if (binary instanceof StaticLibraryBinarySpec) {
def sBinary = (StaticLibraryBinarySpec) binary
ObjectFilesToBinary assemble = (ObjectFilesToBinary) sBinary.tasks.createStaticLib
@@ -124,6 +159,10 @@ class SingleNativeBuild implements Plugin<Project> {
tree.include '**/*.o'
tree.include '**/*.obj'
assemble.source tree
if (project.hasProperty('buildServer')) {
deleteObjects.dependsOn assemble
deleteObjects.delete tree
}
}
}
}

View File

@@ -0,0 +1,77 @@
import groovy.transform.CompileStatic;
import javax.inject.Inject;
import org.gradle.api.Project;
import edu.wpi.first.deployutils.deploy.CommandDeployResult;
import edu.wpi.first.deployutils.deploy.artifact.MavenArtifact;
import edu.wpi.first.deployutils.deploy.context.DeployContext;
import edu.wpi.first.deployutils.deploy.target.RemoteTarget;
import edu.wpi.first.deployutils.PredicateWrapper;
import edu.wpi.first.deployutils.ActionWrapper;
@CompileStatic
public class WPIJREArtifact extends MavenArtifact {
private final String configName;
public String getConfigName() {
return configName;
}
public boolean isCheckJreVersion() {
return checkJreVersion;
}
public void setCheckJreVersion(boolean checkJreVersion) {
this.checkJreVersion = checkJreVersion;
}
private boolean checkJreVersion = true;
private final String artifactLocation = "edu.wpi.first.jdk:roborio-2023:17.0.5u7-1"
@Inject
public WPIJREArtifact(String name, RemoteTarget target) {
super(name, target);
String configName = name + "frcjre";
this.configName = configName;
Project project = target.getProject();
getConfiguration().set(project.getConfigurations().create(configName));
getDependency().set(project.getDependencies().add(configName, artifactLocation));
setOnlyIf(new PredicateWrapper({ DeployContext ctx ->
return jreMissing(ctx) || jreOutOfDate(ctx) || project.hasProperty("force-redeploy-jre");
}));
getDirectory().set("/tmp");
getFilename().set("frcjre.ipk");
getPostdeploy().add(new ActionWrapper({ DeployContext ctx ->
ctx.getLogger().log("Installing JRE...");
ctx.execute("opkg remove frc*-openjdk*; opkg install /tmp/frcjre.ipk; rm /tmp/frcjre.ipk");
ctx.getLogger().log("JRE Deployed!");
}));
}
private boolean jreMissing(DeployContext ctx) {
return ctx.execute("if [[ -f \"/usr/local/frc/JRE/bin/java\" ]]; then echo OK; else echo MISSING; fi").getResult().contains("MISSING");
}
private boolean jreOutOfDate(DeployContext ctx) {
if (!checkJreVersion) {
return false;
}
String version = getDependency().get().getVersion();
CommandDeployResult cmdResult = ctx.execute("opkg list-installed | grep openjdk");
if (cmdResult.getExitCode() != 0) {
ctx.getLogger().log("JRE not found");
return false;
}
String result = cmdResult.getResult().trim();
ctx.getLogger().log("Searching for JRE " + version);
ctx.getLogger().log("Found JRE " + result);
boolean matches = result.contains(version);
ctx.getLogger().log(matches ? "JRE Is Correct Version" : "JRE is mismatched. Reinstalling");
return !matches;
}
}

View File

@@ -12,6 +12,7 @@ repoRootNameOverride {
}
includeOtherLibs {
^fmt/
^hal/
^networktables/
^opencv2/

View File

@@ -6,10 +6,10 @@ include(AddTest)
find_package( OpenCV REQUIRED )
# Java bindings
if (NOT WITHOUT_JAVA)
if (WITH_JAVA)
find_package(Java REQUIRED)
include(UseJava)
set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint:unchecked")
set(CMAKE_JAVA_COMPILE_FLAGS "-encoding" "UTF8" "-Xlint:unchecked")
#find java files, copy them locally
@@ -43,18 +43,18 @@ set_property(TARGET cameraserver PROPERTY FOLDER "libraries")
install(TARGETS cameraserver EXPORT cameraserver DESTINATION "${main_lib_dest}")
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/cameraserver")
if (NOT WITHOUT_JAVA AND MSVC)
if (WITH_JAVA AND MSVC)
install(TARGETS cameraserver RUNTIME DESTINATION "${jni_lib_dest}" COMPONENT Runtime)
endif()
if (MSVC OR FLAT_INSTALL_WPILIB)
if (WITH_FLAT_INSTALL)
set (cameraserver_config_dir ${wpilib_dest})
else()
set (cameraserver_config_dir share/cameraserver)
endif()
configure_file(cameraserver-config.cmake.in ${CMAKE_BINARY_DIR}/cameraserver-config.cmake )
install(FILES ${CMAKE_BINARY_DIR}/cameraserver-config.cmake DESTINATION ${cameraserver_config_dir})
configure_file(cameraserver-config.cmake.in ${WPILIB_BINARY_DIR}/cameraserver-config.cmake )
install(FILES ${WPILIB_BINARY_DIR}/cameraserver-config.cmake DESTINATION ${cameraserver_config_dir})
install(EXPORT cameraserver DESTINATION ${cameraserver_config_dir})
file(GLOB multiCameraServer_src multiCameraServer/src/main/native/cpp/*.cpp)

View File

@@ -11,18 +11,20 @@ apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
dependencies {
implementation project(':wpiutil')
implementation project(':wpinet')
implementation project(':ntcore')
implementation project(':cscore')
devImplementation project(':wpiutil')
devImplementation project(':wpinet')
devImplementation project(':ntcore')
devImplementation project(':cscore')
}
ext {
sharedCvConfigs = [cameraserver : [],
cameraserverBase: [],
cameraserverDev : [],
cameraserverTest: []]
cameraserverBase: [],
cameraserverDev : [],
cameraserverTest: []]
staticCvConfigs = [:]
useJava = true
useCpp = true
@@ -32,14 +34,19 @@ apply from: "${rootDir}/shared/opencv.gradle"
nativeUtils.exportsConfigs {
cameraserver {
x86ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
'_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
'_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
'_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
x64ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
'_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
'_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
'_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
x64ExcludeSymbols = [
'_CT??_R0?AV_System_error',
'_CT??_R0?AVexception',
'_CT??_R0?AVfailure',
'_CT??_R0?AVruntime_error',
'_CT??_R0?AVsystem_error',
'_CTA5?AVfailure',
'_TI5?AVfailure',
'_CT??_R0?AVout_of_range',
'_CTA3?AVout_of_range',
'_TI3?AVout_of_range',
'_CT??_R0?AVbad_cast'
]
}
}
@@ -50,8 +57,9 @@ model {
if (!it.buildable || !(it instanceof NativeBinarySpec)) {
return
}
lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
project(':ntcore').addNtcoreDependency(it, 'shared')
lib project: ':cscore', library: 'cscore', linkage: 'shared'
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
}
}

View File

@@ -5,4 +5,5 @@ include(CMakeFindDependencyMacro)
@CSCORE_DEP_REPLACE@
find_dependency(OpenCV)
@FILENAME_DEP_REPLACE@
include(${SELF_DIR}/cameraserver.cmake)

View File

@@ -18,18 +18,21 @@ ext {
apply from: "${rootDir}/shared/opencv.gradle"
mainClassName = 'Main'
mainClassName = 'edu.wpi.Main'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
mavenCentral()
maven {
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.code.gson:gson:2.8.9'
implementation project(':wpiutil')
implementation project(':wpinet')
implementation project(':ntcore')
implementation project(':cscore')
implementation project(':cameraserver')
@@ -38,7 +41,6 @@ dependencies {
model {
components {
multiCameraServerCpp(NativeExecutableSpec) {
targetBuildTypes 'release'
sources {
cpp {
source {
@@ -52,10 +54,11 @@ model {
}
}
binaries.all { binary ->
lib project: ':cameraserver', library: 'cameraserver', linkage: 'static'
lib project: ':ntcore', library: 'ntcore', linkage: 'static'
lib project: ':cscore', library: 'cscore', linkage: 'static'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
lib project: ':cameraserver', library: 'cameraserver', linkage: 'static'
project(':ntcore').addNtcoreDependency(binary, 'static')
lib project: ':cscore', library: 'cscore', linkage: 'static'
lib project: ':wpinet', library: 'wpinet', linkage: 'static'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
}
}
}

View File

@@ -1,211 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import edu.wpi.cscore.VideoSource;
import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.networktables.NetworkTableInstance;
/*
JSON format:
{
"team": <team number>,
"ntmode": <"client" or "server", "client" if unspecified>
"cameras": [
{
"name": <camera name>
"path": <path, e.g. "/dev/video0">
"pixel format": <"MJPEG", "YUYV", etc> // optional
"width": <video mode width> // optional
"height": <video mode height> // optional
"fps": <video mode fps> // optional
"brightness": <percentage brightness> // optional
"white balance": <"auto", "hold", value> // optional
"exposure": <"auto", "hold", value> // optional
"properties": [ // optional
{
"name": <property name>
"value": <property value>
}
]
}
]
}
*/
public final class Main {
private static String configFile = "/boot/frc.json";
@SuppressWarnings("MemberName")
public static class CameraConfig {
public String name;
public String path;
public JsonObject config;
}
public static int team;
public static boolean server;
public static List<CameraConfig> cameras = new ArrayList<>();
private Main() {
}
/**
* Report parse error.
*/
public static void parseError(String str) {
System.err.println("config error in '" + configFile + "': " + str);
}
/**
* Read single camera configuration.
*/
public static boolean readCameraConfig(JsonObject config) {
CameraConfig cam = new CameraConfig();
// name
JsonElement nameElement = config.get("name");
if (nameElement == null) {
parseError("could not read camera name");
return false;
}
cam.name = nameElement.getAsString();
// path
JsonElement pathElement = config.get("path");
if (pathElement == null) {
parseError("camera '" + cam.name + "': could not read path");
return false;
}
cam.path = pathElement.getAsString();
cam.config = config;
cameras.add(cam);
return true;
}
/**
* Read configuration file.
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
public static boolean readConfig() {
// parse file
JsonElement top;
try {
top = new JsonParser().parse(Files.newBufferedReader(Paths.get(configFile)));
} catch (IOException ex) {
System.err.println("could not open '" + configFile + "': " + ex);
return false;
}
// top level must be an object
if (!top.isJsonObject()) {
parseError("must be JSON object");
return false;
}
JsonObject obj = top.getAsJsonObject();
// team number
JsonElement teamElement = obj.get("team");
if (teamElement == null) {
parseError("could not read team number");
return false;
}
team = teamElement.getAsInt();
// ntmode (optional)
if (obj.has("ntmode")) {
String str = obj.get("ntmode").getAsString();
if ("client".equalsIgnoreCase(str)) {
server = false;
} else if ("server".equalsIgnoreCase(str)) {
server = true;
} else {
parseError("could not understand ntmode value '" + str + "'");
}
}
// cameras
JsonElement camerasElement = obj.get("cameras");
if (camerasElement == null) {
parseError("could not read cameras");
return false;
}
JsonArray cameras = camerasElement.getAsJsonArray();
for (JsonElement camera : cameras) {
if (!readCameraConfig(camera.getAsJsonObject())) {
return false;
}
}
return true;
}
/**
* Start running the camera.
*/
public static void startCamera(CameraConfig config) {
System.out.println("Starting camera '" + config.name + "' on " + config.path);
VideoSource camera = CameraServer.getInstance().startAutomaticCapture(
config.name, config.path);
Gson gson = new GsonBuilder().create();
camera.setConfigJson(gson.toJson(config.config));
}
/**
* Main.
*/
public static void main(String... args) {
if (args.length > 0) {
configFile = args[0];
}
// read configuration
if (!readConfig()) {
return;
}
// start NetworkTables
NetworkTableInstance ntinst = NetworkTableInstance.getDefault();
if (server) {
System.out.println("Setting up NetworkTables server");
ntinst.startServer();
} else {
System.out.println("Setting up NetworkTables client for team " + team);
ntinst.startClientTeam(team);
}
// start cameras
for (CameraConfig camera : cameras) {
startCamera(camera);
}
// loop forever
for (;;) {
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
return;
}
}
}
}

View File

@@ -0,0 +1,196 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.cscore.VideoSource;
import edu.wpi.first.networktables.NetworkTableInstance;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/*
JSON format:
{
"team": <team number>,
"ntmode": <"client" or "server", "client" if unspecified>
"cameras": [
{
"name": <camera name>
"path": <path, e.g. "/dev/video0">
"pixel format": <"MJPEG", "YUYV", etc> // optional
"width": <video mode width> // optional
"height": <video mode height> // optional
"fps": <video mode fps> // optional
"brightness": <percentage brightness> // optional
"white balance": <"auto", "hold", value> // optional
"exposure": <"auto", "hold", value> // optional
"properties": [ // optional
{
"name": <property name>
"value": <property value>
}
]
}
]
}
*/
public final class Main {
private static String configFile = "/boot/frc.json";
@SuppressWarnings("MemberName")
public static class CameraConfig {
public String name;
public String path;
public JsonObject config;
}
private static int team;
private static boolean server;
private static List<CameraConfig> cameras = new ArrayList<>();
private Main() {}
/** Report parse error. */
public static void parseError(String str) {
System.err.println("config error in '" + configFile + "': " + str);
}
/** Read single camera configuration. */
public static boolean readCameraConfig(JsonObject config) {
CameraConfig cam = new CameraConfig();
// name
JsonElement nameElement = config.get("name");
if (nameElement == null) {
parseError("could not read camera name");
return false;
}
cam.name = nameElement.getAsString();
// path
JsonElement pathElement = config.get("path");
if (pathElement == null) {
parseError("camera '" + cam.name + "': could not read path");
return false;
}
cam.path = pathElement.getAsString();
cam.config = config;
cameras.add(cam);
return true;
}
/** Read configuration file. */
public static boolean readConfig() {
// parse file
JsonElement top;
try {
top = new JsonParser().parse(Files.newBufferedReader(Paths.get(configFile)));
} catch (IOException ex) {
System.err.println("could not open '" + configFile + "': " + ex);
return false;
}
// top level must be an object
if (!top.isJsonObject()) {
parseError("must be JSON object");
return false;
}
JsonObject obj = top.getAsJsonObject();
// team number
JsonElement teamElement = obj.get("team");
if (teamElement == null) {
parseError("could not read team number");
return false;
}
team = teamElement.getAsInt();
// ntmode (optional)
if (obj.has("ntmode")) {
String str = obj.get("ntmode").getAsString();
if ("client".equalsIgnoreCase(str)) {
server = false;
} else if ("server".equalsIgnoreCase(str)) {
server = true;
} else {
parseError("could not understand ntmode value '" + str + "'");
}
}
// cameras
JsonElement camerasElement = obj.get("cameras");
if (camerasElement == null) {
parseError("could not read cameras");
return false;
}
JsonArray cameras = camerasElement.getAsJsonArray();
for (JsonElement camera : cameras) {
if (!readCameraConfig(camera.getAsJsonObject())) {
return false;
}
}
return true;
}
/** Start running the camera. */
public static void startCamera(CameraConfig config) {
System.out.println("Starting camera '" + config.name + "' on " + config.path);
VideoSource camera = CameraServer.startAutomaticCapture(config.name, config.path);
Gson gson = new GsonBuilder().create();
camera.setConfigJson(gson.toJson(config.config));
}
/** Main. */
public static void main(String... args) {
if (args.length > 0) {
configFile = args[0];
}
// read configuration
if (!readConfig()) {
return;
}
// start NetworkTables
NetworkTableInstance ntinst = NetworkTableInstance.getDefault();
if (server) {
System.out.println("Setting up NetworkTables server");
ntinst.startServer();
} else {
System.out.println("Setting up NetworkTables client for team " + team);
ntinst.setServerTeam(team);
ntinst.startClient4("multicameraserver");
}
// start cameras
for (CameraConfig camera : cameras) {
startCamera(camera);
}
// loop forever
for (; ; ) {
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
return;
}
}
}
}

View File

@@ -1,16 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <cstdio>
#include <string>
#include <string_view>
#include <thread>
#include <vector>
#include <networktables/NetworkTableInstance.h>
#include <wpi/StringRef.h>
#include <wpi/StringExtras.h>
#include <wpi/fmt/raw_ostream.h>
#include <wpi/json.h>
#include <wpi/raw_istream.h>
#include <wpi/raw_ostream.h>
@@ -108,7 +108,7 @@ bool ReadConfig() {
try {
j = wpi::json::parse(is);
} catch (const wpi::json::parse_error& e) {
ParseError() << "byte " << e.byte << ": " << e.what() << '\n';
fmt::print(ParseError(), "byte {}: {}\n", e.byte, e.what());
return false;
}
@@ -130,10 +130,9 @@ bool ReadConfig() {
if (j.count("ntmode") != 0) {
try {
auto str = j.at("ntmode").get<std::string>();
wpi::StringRef s(str);
if (s.equals_lower("client")) {
if (wpi::equals_lower(str, "client")) {
server = false;
} else if (s.equals_lower("server")) {
} else if (wpi::equals_lower(str, "server")) {
server = true;
} else {
ParseError() << "could not understand ntmode value '" << str << "'\n";
@@ -146,7 +145,9 @@ bool ReadConfig() {
// cameras
try {
for (auto&& camera : j.at("cameras")) {
if (!ReadCameraConfig(camera)) return false;
if (!ReadCameraConfig(camera)) {
return false;
}
}
} catch (const wpi::json::exception& e) {
ParseError() << "could not read cameras: " << e.what() << '\n';
@@ -157,34 +158,42 @@ bool ReadConfig() {
}
void StartCamera(const CameraConfig& config) {
wpi::outs() << "Starting camera '" << config.name << "' on " << config.path
<< '\n';
auto camera = frc::CameraServer::GetInstance()->StartAutomaticCapture(
config.name, config.path);
fmt::print("Starting camera '{}' on {}\n", config.name, config.path);
auto camera =
frc::CameraServer::StartAutomaticCapture(config.name, config.path);
camera.SetConfigJson(config.config);
}
} // namespace
int main(int argc, char* argv[]) {
if (argc >= 2) configFile = argv[1];
if (argc >= 2) {
configFile = argv[1];
}
// read configuration
if (!ReadConfig()) return EXIT_FAILURE;
if (!ReadConfig()) {
return EXIT_FAILURE;
}
// start NetworkTables
auto ntinst = nt::NetworkTableInstance::GetDefault();
if (server) {
wpi::outs() << "Setting up NetworkTables server\n";
std::puts("Setting up NetworkTables server");
ntinst.StartServer();
} else {
wpi::outs() << "Setting up NetworkTables client for team " << team << '\n';
ntinst.StartClientTeam(team);
fmt::print("Setting up NetworkTables client for team {}\n", team);
ntinst.StartClient4("multicameraserver");
ntinst.SetServerTeam(team);
}
// start cameras
for (auto&& camera : cameras) StartCamera(camera);
for (auto&& camera : cameras) {
StartCamera(camera);
}
// loop forever
for (;;) std::this_thread::sleep_for(std::chrono::seconds(10));
for (;;) {
std::this_thread::sleep_for(std::chrono::seconds(10));
}
}

View File

@@ -1,17 +1,11 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.cameraserver;
public final class DevMain {
public static void main(String[] args) {
public static void main(String[] args) {}
}
private DevMain() {
}
private DevMain() {}
}

View File

@@ -1,8 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
int main() {}

View File

@@ -1,13 +1,9 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.cameraserver;
public interface CameraServerShared {
/**
* get the main thread id func.

View File

@@ -1,56 +1,48 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.cameraserver;
public final class CameraServerSharedStore {
private static CameraServerShared cameraServerShared;
private CameraServerSharedStore() {
}
private CameraServerSharedStore() {}
/**
* get the CameraServerShared object.
* Get the CameraServerShared object.
*
* @return The CameraServerSharedObject
*/
public static synchronized CameraServerShared getCameraServerShared() {
if (cameraServerShared == null) {
cameraServerShared = new CameraServerShared() {
cameraServerShared =
new CameraServerShared() {
@Override
public void reportVideoServer(int id) {}
@Override
public void reportVideoServer(int id) {
@Override
public void reportUsbCamera(int id) {}
}
@Override
public void reportDriverStationError(String error) {}
@Override
public void reportUsbCamera(int id) {
@Override
public void reportAxisCamera(int id) {}
}
@Override
public void reportDriverStationError(String error) {
}
@Override
public void reportAxisCamera(int id) {
}
@Override
public Long getRobotMainThreadId() {
return null;
}
};
@Override
public Long getRobotMainThreadId() {
return null;
}
};
}
return cameraServerShared;
}
/**
* set the CameraServerShared object.
* Set the CameraServerShared object.
*
* @param shared The CameraServerShared object.
*/
public static synchronized void setCameraServerShared(CameraServerShared shared) {
cameraServerShared = shared;

View File

@@ -1,26 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.vision;
import org.opencv.core.Mat;
/**
* A vision pipeline is responsible for running a group of
* OpenCV algorithms to extract data from an image.
* A vision pipeline is responsible for running a group of OpenCV algorithms to extract data from an
* image.
*
* @see VisionRunner
* @see VisionThread
*/
public interface VisionPipeline {
/**
* Processes the image input and sets the result objects.
* Implementations should make these objects accessible.
* Processes the image input and sets the result objects. Implementations should make these
* objects accessible.
*
* @param image The image to process.
*/
void process(Mat image);
}

View File

@@ -1,22 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.vision;
import edu.wpi.first.cameraserver.CameraServerSharedStore;
import edu.wpi.first.cscore.CvSink;
import edu.wpi.first.cscore.VideoSource;
import org.opencv.core.Mat;
import edu.wpi.cscore.CvSink;
import edu.wpi.cscore.VideoSource;
import edu.wpi.first.cameraserver.CameraServerSharedStore;
/**
* A vision runner is a convenient wrapper object to make it easy to run vision pipelines
* from robot code. The easiest way to use this is to run it in a {@link VisionThread}
* and use the listener to take snapshots of the pipeline's outputs.
* A vision runner is a convenient wrapper object to make it easy to run vision pipelines from robot
* code. The easiest way to use this is to run it in a {@link VisionThread} and use the listener to
* take snapshots of the pipeline's outputs.
*
* @see VisionPipeline
* @see VisionThread
@@ -45,17 +41,16 @@ public class VisionRunner<P extends VisionPipeline> {
* @param pipeline the vision pipeline that ran
*/
void copyPipelineOutputs(P pipeline);
}
/**
* Creates a new vision runner. It will take images from the {@code videoSource}, send them to
* the {@code pipeline}, and call the {@code listener} when the pipeline has finished to alert
* user code when it is safe to access the pipeline's outputs.
* Creates a new vision runner. It will take images from the {@code videoSource}, send them to the
* {@code pipeline}, and call the {@code listener} when the pipeline has finished to alert user
* code when it is safe to access the pipeline's outputs.
*
* @param videoSource the video source to use to supply images for the pipeline
* @param pipeline the vision pipeline to run
* @param listener a function to call after the pipeline has finished running
* @param pipeline the vision pipeline to run
* @param listener a function to call after the pipeline has finished running
*/
public VisionRunner(VideoSource videoSource, P pipeline, Listener<? super P> listener) {
this.m_pipeline = pipeline;
@@ -64,15 +59,15 @@ public class VisionRunner<P extends VisionPipeline> {
}
/**
* Runs the pipeline one time, giving it the next image from the video source specified
* in the constructor. This will block until the source either has an image or throws an error.
* If the source successfully supplied a frame, the pipeline's image input will be set,
* the pipeline will run, and the listener specified in the constructor will be called to notify
* it that the pipeline ran.
* Runs the pipeline one time, giving it the next image from the video source specified in the
* constructor. This will block until the source either has an image or throws an error. If the
* source successfully supplied a frame, the pipeline's image input will be set, the pipeline will
* run, and the listener specified in the constructor will be called to notify it that the
* pipeline ran.
*
* <p>This method is exposed to allow teams to add additional functionality or have their own
* ways to run the pipeline. Most teams, however, should just use {@link #runForever} in its own
* thread using a {@link VisionThread}.</p>
* <p>This method is exposed to allow teams to add additional functionality or have their own ways
* to run the pipeline. Most teams, however, should just use {@link #runForever} in its own thread
* using a {@link VisionThread}.
*/
public void runOnce() {
Long id = CameraServerSharedStore.getCameraServerShared().getRobotMainThreadId();
@@ -98,11 +93,11 @@ public class VisionRunner<P extends VisionPipeline> {
}
/**
* A convenience method that calls {@link #runOnce()} in an infinite loop. This must
* be run in a dedicated thread, and cannot be used in the main robot thread because
* it will freeze the robot program.
* A convenience method that calls {@link #runOnce()} in an infinite loop. This must be run in a
* dedicated thread, and cannot be used in the main robot thread because it will freeze the robot
* program.
*
* <p><strong>Do not call this method directly from the main thread.</strong></p>
* <p><strong>Do not call this method directly from the main thread.</strong>
*
* @throws IllegalStateException if this is called from the main robot thread
* @see VisionThread
@@ -119,9 +114,7 @@ public class VisionRunner<P extends VisionPipeline> {
}
}
/**
* Stop a RunForever() loop.
*/
/** Stop a RunForever() loop. */
public void stop() {
m_enabled = false;
}

View File

@@ -1,18 +1,15 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.vision;
import edu.wpi.cscore.VideoSource;
import edu.wpi.first.cscore.VideoSource;
/**
* A vision thread is a special thread that runs a vision pipeline. It is a <i>daemon</i> thread;
* it does not prevent the program from exiting when all other non-daemon threads
* have finished running.
* A vision thread is a special thread that runs a vision pipeline. It is a <i>daemon</i> thread; it
* does not prevent the program from exiting when all other non-daemon threads have finished
* running.
*
* @see VisionPipeline
* @see VisionRunner
@@ -34,14 +31,12 @@ public class VisionThread extends Thread {
* equivalent to {@code new VisionThread(new VisionRunner<>(videoSource, pipeline, listener))}.
*
* @param videoSource the source for images the pipeline should process
* @param pipeline the pipeline to run
* @param listener the listener to copy outputs from the pipeline after it runs
* @param <P> the type of the pipeline
* @param pipeline the pipeline to run
* @param listener the listener to copy outputs from the pipeline after it runs
* @param <P> the type of the pipeline
*/
public <P extends VisionPipeline> VisionThread(VideoSource videoSource,
P pipeline,
VisionRunner.Listener<? super P> listener) {
public <P extends VisionPipeline> VisionThread(
VideoSource videoSource, P pipeline, VisionRunner.Listener<? super P> listener) {
this(new VisionRunner<>(videoSource, pipeline, listener));
}
}

View File

@@ -1,22 +1,19 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
/**
* Classes in the {@code edu.wpi.first.vision} package are designed to
* simplify using OpenCV vision processing code from a robot program.
* Classes in the {@code edu.wpi.first.vision} package are designed to simplify using OpenCV vision
* processing code from a robot program.
*
* <p>An example use case for grabbing a yellow tote from 2015 in autonomous: <br>
*
* <p>An example use case for grabbing a yellow tote from 2015 in autonomous:
* <br>
* <pre><code>
* public class Robot extends IterativeRobot
* public class Robot extends TimedRobot
* implements VisionRunner.Listener&lt;MyFindTotePipeline&gt; {
*
* // A USB camera connected to the roboRIO.
* private {@link edu.wpi.cscore.VideoSource VideoSource} usbCamera;
* private {@link edu.wpi.first.cscore.VideoSource VideoSource} usbCamera;
*
* // A vision pipeline. This could be handwritten or generated by GRIP.
* // This has to implement {@link edu.wpi.first.vision.VisionPipeline}.
@@ -47,7 +44,7 @@
*
* {@literal @}Override
* public void robotInit() {
* usbCamera = CameraServer.getInstance().startAutomaticCapture(0);
* usbCamera = CameraServer.startAutomaticCapture(0);
* findTotePipeline = new MyFindTotePipeline();
* findToteThread = new VisionThread(usbCamera, findTotePipeline, this);
* }

View File

@@ -1,23 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "cameraserver/CameraServer.h"
#include <atomic>
#include <vector>
#include <fmt/format.h>
#include <networktables/BooleanTopic.h>
#include <networktables/IntegerTopic.h>
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableInstance.h>
#include <networktables/StringArrayTopic.h>
#include <networktables/StringTopic.h>
#include <wpi/DenseMap.h>
#include <wpi/ManagedStatic.h>
#include <wpi/SmallString.h>
#include <wpi/StringExtras.h>
#include <wpi/StringMap.h>
#include <wpi/mutex.h>
#include <wpi/raw_ostream.h>
#include "cameraserver/CameraServerShared.h"
#include "ntcore_cpp.h"
@@ -26,9 +27,43 @@ using namespace frc;
static constexpr char const* kPublishName = "/CameraPublisher";
struct CameraServer::Impl {
Impl();
std::shared_ptr<nt::NetworkTable> GetSourceTable(CS_Source source);
namespace {
struct Instance;
struct PropertyPublisher {
PropertyPublisher(nt::NetworkTable& table, const cs::VideoEvent& event);
void Update(const cs::VideoEvent& event);
nt::BooleanEntry booleanValueEntry;
nt::IntegerEntry integerValueEntry;
nt::StringEntry stringValueEntry;
nt::IntegerPublisher minPublisher;
nt::IntegerPublisher maxPublisher;
nt::IntegerPublisher stepPublisher;
nt::IntegerPublisher defaultPublisher;
nt::StringArrayTopic choicesTopic;
nt::StringArrayPublisher choicesPublisher;
};
struct SourcePublisher {
SourcePublisher(Instance& inst, std::shared_ptr<nt::NetworkTable> table,
CS_Source source);
std::shared_ptr<nt::NetworkTable> table;
nt::StringPublisher sourcePublisher;
nt::StringPublisher descriptionPublisher;
nt::BooleanPublisher connectedPublisher;
nt::StringArrayPublisher streamsPublisher;
nt::StringEntry modeEntry;
nt::StringArrayPublisher modesPublisher;
wpi::DenseMap<CS_Property, PropertyPublisher> properties;
};
struct Instance {
Instance();
SourcePublisher* GetPublisher(CS_Source source);
std::vector<std::string> GetSinkStreamValues(CS_Sink sink);
std::vector<std::string> GetSourceStreamValues(CS_Source source);
void UpdateStreamValues();
@@ -39,42 +74,41 @@ struct CameraServer::Impl {
wpi::StringMap<cs::VideoSource> m_sources;
wpi::StringMap<cs::VideoSink> m_sinks;
wpi::DenseMap<CS_Sink, CS_Source> m_fixedSources;
wpi::DenseMap<CS_Source, std::shared_ptr<nt::NetworkTable>> m_tables;
std::shared_ptr<nt::NetworkTable> m_publishTable;
wpi::DenseMap<CS_Source, SourcePublisher> m_publishers;
std::shared_ptr<nt::NetworkTable> m_publishTable{
nt::NetworkTableInstance::GetDefault().GetTable(kPublishName)};
cs::VideoListener m_videoListener;
int m_tableListener;
int m_nextPort;
int m_nextPort{CameraServer::kBasePort};
std::vector<std::string> m_addresses;
};
CameraServer* CameraServer::GetInstance() {
struct Creator {
static void* call() { return new CameraServer{}; }
};
struct Deleter {
static void call(void* ptr) { delete static_cast<CameraServer*>(ptr); }
};
static wpi::ManagedStatic<CameraServer, Creator, Deleter> instance;
return &(*instance);
} // namespace
static Instance& GetInstance() {
static Instance instance;
return instance;
}
static wpi::StringRef MakeSourceValue(CS_Source source,
wpi::SmallVectorImpl<char>& buf) {
static std::string_view MakeSourceValue(CS_Source source,
wpi::SmallVectorImpl<char>& buf) {
CS_Status status = 0;
buf.clear();
switch (cs::GetSourceKind(source, &status)) {
case CS_SOURCE_USB: {
wpi::StringRef prefix{"usb:"};
std::string_view prefix{"usb:"};
buf.append(prefix.begin(), prefix.end());
auto path = cs::GetUsbCameraPath(source, &status);
buf.append(path.begin(), path.end());
break;
}
case CS_SOURCE_HTTP: {
wpi::StringRef prefix{"ip:"};
std::string_view prefix{"ip:"};
buf.append(prefix.begin(), prefix.end());
auto urls = cs::GetHttpCameraUrls(source, &status);
if (!urls.empty()) buf.append(urls[0].begin(), urls[0].end());
if (!urls.empty()) {
buf.append(urls[0].begin(), urls[0].end());
}
break;
}
case CS_SOURCE_CV:
@@ -83,27 +117,29 @@ static wpi::StringRef MakeSourceValue(CS_Source source,
return "unknown:";
}
return wpi::StringRef{buf.begin(), buf.size()};
return {buf.begin(), buf.size()};
}
static std::string MakeStreamValue(const wpi::Twine& address, int port) {
return ("mjpg:http://" + address + wpi::Twine(':') + wpi::Twine(port) +
"/?action=stream")
.str();
static std::string MakeStreamValue(std::string_view address, int port) {
return fmt::format("mjpg:http://{}:{}/?action=stream", address, port);
}
std::shared_ptr<nt::NetworkTable> CameraServer::Impl::GetSourceTable(
CS_Source source) {
std::scoped_lock lock(m_mutex);
return m_tables.lookup(source);
SourcePublisher* Instance::GetPublisher(CS_Source source) {
auto it = m_publishers.find(source);
if (it != m_publishers.end()) {
return &it->second;
} else {
return nullptr;
}
}
std::vector<std::string> CameraServer::Impl::GetSinkStreamValues(CS_Sink sink) {
std::vector<std::string> Instance::GetSinkStreamValues(CS_Sink sink) {
CS_Status status = 0;
// Ignore all but MjpegServer
if (cs::GetSinkKind(sink, &status) != CS_SINK_MJPEG)
return std::vector<std::string>{};
if (cs::GetSinkKind(sink, &status) != CS_SINK_MJPEG) {
return {};
}
// Get port
int port = cs::GetMjpegServerPort(sink, &status);
@@ -119,7 +155,9 @@ std::vector<std::string> CameraServer::Impl::GetSinkStreamValues(CS_Sink sink) {
values.emplace_back(MakeStreamValue(cs::GetHostname() + ".local", port));
for (const auto& addr : m_addresses) {
if (addr == "127.0.0.1") continue; // ignore localhost
if (addr == "127.0.0.1") {
continue; // ignore localhost
}
values.emplace_back(MakeStreamValue(addr, port));
}
}
@@ -127,17 +165,19 @@ std::vector<std::string> CameraServer::Impl::GetSinkStreamValues(CS_Sink sink) {
return values;
}
std::vector<std::string> CameraServer::Impl::GetSourceStreamValues(
CS_Source source) {
std::vector<std::string> Instance::GetSourceStreamValues(CS_Source source) {
CS_Status status = 0;
// Ignore all but HttpCamera
if (cs::GetSourceKind(source, &status) != CS_SOURCE_HTTP)
return std::vector<std::string>{};
if (cs::GetSourceKind(source, &status) != CS_SOURCE_HTTP) {
return {};
}
// Generate values
auto values = cs::GetHttpCameraUrls(source, &status);
for (auto& value : values) value = "mjpg:" + value;
for (auto& value : values) {
value = "mjpg:" + value;
}
#ifdef __FRC_ROBORIO__
// Look to see if we have a passthrough server for this source
@@ -159,8 +199,7 @@ std::vector<std::string> CameraServer::Impl::GetSourceStreamValues(
return values;
}
void CameraServer::Impl::UpdateStreamValues() {
std::scoped_lock lock(m_mutex);
void Instance::UpdateStreamValues() {
// Over all the sinks...
for (const auto& i : m_sinks) {
CS_Status status = 0;
@@ -168,16 +207,23 @@ void CameraServer::Impl::UpdateStreamValues() {
// Get the source's subtable (if none exists, we're done)
CS_Source source = m_fixedSources.lookup(sink);
if (source == 0) source = cs::GetSinkSource(sink, &status);
if (source == 0) continue;
auto table = m_tables.lookup(source);
if (table) {
if (source == 0) {
source = cs::GetSinkSource(sink, &status);
}
if (source == 0) {
continue;
}
if (auto publisher = GetPublisher(source)) {
// Don't set stream values if this is a HttpCamera passthrough
if (cs::GetSourceKind(source, &status) == CS_SOURCE_HTTP) continue;
if (cs::GetSourceKind(source, &status) == CS_SOURCE_HTTP) {
continue;
}
// Set table value
auto values = GetSinkStreamValues(sink);
if (!values.empty()) table->GetEntry("streams").SetStringArray(values);
if (!values.empty()) {
publisher->streamsPublisher.Set(values);
}
}
}
@@ -186,11 +232,12 @@ void CameraServer::Impl::UpdateStreamValues() {
CS_Source source = i.second.GetHandle();
// Get the source's subtable (if none exists, we're done)
auto table = m_tables.lookup(source);
if (table) {
if (auto publisher = GetPublisher(source)) {
// Set table value
auto values = GetSourceStreamValues(source);
if (!values.empty()) table->GetEntry("streams").SetStringArray(values);
if (!values.empty()) {
publisher->streamsPublisher.Set(values);
}
}
}
}
@@ -213,79 +260,114 @@ static std::string PixelFormatToString(int pixelFormat) {
}
static std::string VideoModeToString(const cs::VideoMode& mode) {
std::string rv;
wpi::raw_string_ostream oss{rv};
oss << mode.width << "x" << mode.height;
oss << " " << PixelFormatToString(mode.pixelFormat) << " ";
oss << mode.fps << " fps";
return oss.str();
return fmt::format("{}x{} {} {} fps", mode.width, mode.height,
PixelFormatToString(mode.pixelFormat), mode.fps);
}
static std::vector<std::string> GetSourceModeValues(int source) {
std::vector<std::string> rv;
CS_Status status = 0;
for (const auto& mode : cs::EnumerateSourceVideoModes(source, &status))
for (const auto& mode : cs::EnumerateSourceVideoModes(source, &status)) {
rv.emplace_back(VideoModeToString(mode));
}
return rv;
}
static void PutSourcePropertyValue(nt::NetworkTable* table,
const cs::VideoEvent& event, bool isNew) {
wpi::SmallString<64> name;
wpi::SmallString<64> infoName;
if (wpi::StringRef{event.name}.startswith("raw_")) {
name = "RawProperty/";
name += event.name;
infoName = "RawPropertyInfo/";
infoName += event.name;
PropertyPublisher::PropertyPublisher(nt::NetworkTable& table,
const cs::VideoEvent& event) {
std::string name;
std::string infoName;
if (wpi::starts_with(event.name, "raw_")) {
name = fmt::format("RawProperty/{}", event.name);
infoName = fmt::format("RawPropertyInfo/{}", event.name);
} else {
name = "Property/";
name += event.name;
infoName = "PropertyInfo/";
infoName += event.name;
name = fmt::format("Property/{}", event.name);
infoName = fmt::format("PropertyInfo/{}", event.name);
}
wpi::SmallString<64> buf;
CS_Status status = 0;
nt::NetworkTableEntry entry = table->GetEntry(name);
switch (event.propertyKind) {
case CS_PROP_BOOLEAN:
if (isNew)
entry.SetDefaultBoolean(event.value != 0);
else
entry.SetBoolean(event.value != 0);
booleanValueEntry = table.GetBooleanTopic(name).GetEntry(false);
booleanValueEntry.SetDefault(event.value != 0);
break;
case CS_PROP_INTEGER:
case CS_PROP_ENUM:
if (isNew) {
entry.SetDefaultDouble(event.value);
table->GetEntry(infoName + "/min")
.SetDouble(cs::GetPropertyMin(event.propertyHandle, &status));
table->GetEntry(infoName + "/max")
.SetDouble(cs::GetPropertyMax(event.propertyHandle, &status));
table->GetEntry(infoName + "/step")
.SetDouble(cs::GetPropertyStep(event.propertyHandle, &status));
table->GetEntry(infoName + "/default")
.SetDouble(cs::GetPropertyDefault(event.propertyHandle, &status));
} else {
entry.SetDouble(event.value);
}
choicesTopic =
table.GetStringArrayTopic(fmt::format("{}/choices", infoName));
[[fallthrough]];
case CS_PROP_INTEGER:
integerValueEntry = table.GetIntegerTopic(name).GetEntry(0);
minPublisher =
table.GetIntegerTopic(fmt::format("{}/min", infoName)).Publish();
maxPublisher =
table.GetIntegerTopic(fmt::format("{}/max", infoName)).Publish();
stepPublisher =
table.GetIntegerTopic(fmt::format("{}/step", infoName)).Publish();
defaultPublisher =
table.GetIntegerTopic(fmt::format("{}/default", infoName)).Publish();
integerValueEntry.SetDefault(event.value);
minPublisher.Set(cs::GetPropertyMin(event.propertyHandle, &status));
maxPublisher.Set(cs::GetPropertyMax(event.propertyHandle, &status));
stepPublisher.Set(cs::GetPropertyStep(event.propertyHandle, &status));
defaultPublisher.Set(
cs::GetPropertyDefault(event.propertyHandle, &status));
break;
case CS_PROP_STRING:
if (isNew)
entry.SetDefaultString(event.valueStr);
else
entry.SetString(event.valueStr);
stringValueEntry = table.GetStringTopic(name).GetEntry("");
stringValueEntry.SetDefault(event.valueStr);
break;
default:
break;
}
}
CameraServer::Impl::Impl()
: m_publishTable{nt::NetworkTableInstance::GetDefault().GetTable(
kPublishName)},
m_nextPort(kBasePort) {
void PropertyPublisher::Update(const cs::VideoEvent& event) {
switch (event.propertyKind) {
case CS_PROP_BOOLEAN:
if (booleanValueEntry) {
booleanValueEntry.Set(event.value != 0);
}
break;
case CS_PROP_INTEGER:
case CS_PROP_ENUM:
if (integerValueEntry) {
integerValueEntry.Set(event.value);
}
break;
case CS_PROP_STRING:
if (stringValueEntry) {
stringValueEntry.Set(event.valueStr);
}
break;
default:
break;
}
}
SourcePublisher::SourcePublisher(Instance& inst,
std::shared_ptr<nt::NetworkTable> table,
CS_Source source)
: table{table},
sourcePublisher{table->GetStringTopic("source").Publish()},
descriptionPublisher{table->GetStringTopic("description").Publish()},
connectedPublisher{table->GetBooleanTopic("connected").Publish()},
streamsPublisher{table->GetStringArrayTopic("streams").Publish()},
modeEntry{table->GetStringTopic("mode").GetEntry("")},
modesPublisher{table->GetStringArrayTopic("modes").Publish()} {
CS_Status status = 0;
wpi::SmallString<64> buf;
sourcePublisher.Set(MakeSourceValue(source, buf));
wpi::SmallString<64> descBuf;
descriptionPublisher.Set(cs::GetSourceDescription(source, descBuf, &status));
connectedPublisher.Set(cs::IsSourceConnected(source, &status));
streamsPublisher.Set(inst.GetSourceStreamValues(source));
auto mode = cs::GetSourceVideoMode(source, &status);
modeEntry.SetDefault(VideoModeToString(mode));
modesPublisher.Set(GetSourceModeValues(source));
}
Instance::Instance() {
// We publish sources to NetworkTables using the following structure:
// "/CameraPublisher/{Source.Name}/" - root
// - "source" (string): Descriptive, prefixed with type (e.g. "usb:0")
@@ -299,189 +381,110 @@ CameraServer::Impl::Impl()
// Listener for video events
m_videoListener = cs::VideoListener{
[=](const cs::VideoEvent& event) {
[=, this](const cs::VideoEvent& event) {
std::scoped_lock lock(m_mutex);
CS_Status status = 0;
switch (event.kind) {
case cs::VideoEvent::kSourceCreated: {
// Create subtable for the camera
auto table = m_publishTable->GetSubTable(event.name);
{
std::scoped_lock lock(m_mutex);
m_tables.insert(std::make_pair(event.sourceHandle, table));
}
wpi::SmallString<64> buf;
table->GetEntry("source").SetString(
MakeSourceValue(event.sourceHandle, buf));
wpi::SmallString<64> descBuf;
table->GetEntry("description")
.SetString(cs::GetSourceDescription(event.sourceHandle, descBuf,
&status));
table->GetEntry("connected")
.SetBoolean(cs::IsSourceConnected(event.sourceHandle, &status));
table->GetEntry("streams").SetStringArray(
GetSourceStreamValues(event.sourceHandle));
auto mode = cs::GetSourceVideoMode(event.sourceHandle, &status);
table->GetEntry("mode").SetDefaultString(VideoModeToString(mode));
table->GetEntry("modes").SetStringArray(
GetSourceModeValues(event.sourceHandle));
m_publishers.insert(
{event.sourceHandle,
SourcePublisher{*this, table, event.sourceHandle}});
break;
}
case cs::VideoEvent::kSourceDestroyed: {
auto table = GetSourceTable(event.sourceHandle);
if (table) {
table->GetEntry("source").SetString("");
table->GetEntry("streams").SetStringArray(
std::vector<std::string>{});
table->GetEntry("modes").SetStringArray(
std::vector<std::string>{});
}
case cs::VideoEvent::kSourceDestroyed:
m_publishers.erase(event.sourceHandle);
break;
}
case cs::VideoEvent::kSourceConnected: {
auto table = GetSourceTable(event.sourceHandle);
if (table) {
case cs::VideoEvent::kSourceConnected:
if (auto publisher = GetPublisher(event.sourceHandle)) {
// update the description too (as it may have changed)
wpi::SmallString<64> descBuf;
table->GetEntry("description")
.SetString(cs::GetSourceDescription(event.sourceHandle,
descBuf, &status));
table->GetEntry("connected").SetBoolean(true);
publisher->descriptionPublisher.Set(cs::GetSourceDescription(
event.sourceHandle, descBuf, &status));
publisher->connectedPublisher.Set(true);
}
break;
}
case cs::VideoEvent::kSourceDisconnected: {
auto table = GetSourceTable(event.sourceHandle);
if (table) table->GetEntry("connected").SetBoolean(false);
case cs::VideoEvent::kSourceDisconnected:
if (auto publisher = GetPublisher(event.sourceHandle)) {
publisher->connectedPublisher.Set(false);
}
break;
}
case cs::VideoEvent::kSourceVideoModesUpdated: {
auto table = GetSourceTable(event.sourceHandle);
if (table)
table->GetEntry("modes").SetStringArray(
case cs::VideoEvent::kSourceVideoModesUpdated:
if (auto publisher = GetPublisher(event.sourceHandle)) {
publisher->modesPublisher.Set(
GetSourceModeValues(event.sourceHandle));
break;
}
case cs::VideoEvent::kSourceVideoModeChanged: {
auto table = GetSourceTable(event.sourceHandle);
if (table)
table->GetEntry("mode").SetString(VideoModeToString(event.mode));
break;
}
case cs::VideoEvent::kSourcePropertyCreated: {
auto table = GetSourceTable(event.sourceHandle);
if (table) PutSourcePropertyValue(table.get(), event, true);
break;
}
case cs::VideoEvent::kSourcePropertyValueUpdated: {
auto table = GetSourceTable(event.sourceHandle);
if (table) PutSourcePropertyValue(table.get(), event, false);
break;
}
case cs::VideoEvent::kSourcePropertyChoicesUpdated: {
auto table = GetSourceTable(event.sourceHandle);
if (table) {
wpi::SmallString<64> name{"PropertyInfo/"};
name += event.name;
name += "/choices";
auto choices =
cs::GetEnumPropertyChoices(event.propertyHandle, &status);
table->GetEntry(name).SetStringArray(choices);
}
break;
}
case cs::VideoEvent::kSourceVideoModeChanged:
if (auto publisher = GetPublisher(event.sourceHandle)) {
publisher->modeEntry.Set(VideoModeToString(event.mode));
}
break;
case cs::VideoEvent::kSourcePropertyCreated:
if (auto publisher = GetPublisher(event.sourceHandle)) {
publisher->properties.insert(
{event.propertyHandle,
PropertyPublisher{*publisher->table, event}});
}
break;
case cs::VideoEvent::kSourcePropertyValueUpdated:
if (auto publisher = GetPublisher(event.sourceHandle)) {
auto ppIt = publisher->properties.find(event.propertyHandle);
if (ppIt != publisher->properties.end()) {
ppIt->second.Update(event);
}
}
break;
case cs::VideoEvent::kSourcePropertyChoicesUpdated:
if (auto publisher = GetPublisher(event.sourceHandle)) {
auto ppIt = publisher->properties.find(event.propertyHandle);
if (ppIt != publisher->properties.end() &&
ppIt->second.choicesTopic) {
auto choices =
cs::GetEnumPropertyChoices(event.propertyHandle, &status);
if (!ppIt->second.choicesPublisher) {
ppIt->second.choicesPublisher =
ppIt->second.choicesTopic.Publish();
}
ppIt->second.choicesPublisher.Set(choices);
}
}
break;
case cs::VideoEvent::kSinkSourceChanged:
case cs::VideoEvent::kSinkCreated:
case cs::VideoEvent::kSinkDestroyed:
case cs::VideoEvent::kNetworkInterfacesChanged: {
case cs::VideoEvent::kNetworkInterfacesChanged:
m_addresses = cs::GetNetworkInterfaces();
UpdateStreamValues();
break;
}
default:
break;
}
},
0x4fff, true};
// Listener for NetworkTable events
// We don't currently support changing settings via NT due to
// synchronization issues, so just update to current setting if someone
// else tries to change it.
wpi::SmallString<64> buf;
m_tableListener = nt::NetworkTableInstance::GetDefault().AddEntryListener(
kPublishName + wpi::Twine('/'),
[=](const nt::EntryNotification& event) {
wpi::StringRef relativeKey =
event.name.substr(wpi::StringRef(kPublishName).size() + 1);
// get source (sourceName/...)
auto subKeyIndex = relativeKey.find('/');
if (subKeyIndex == wpi::StringRef::npos) return;
wpi::StringRef sourceName = relativeKey.slice(0, subKeyIndex);
auto sourceIt = m_sources.find(sourceName);
if (sourceIt == m_sources.end()) return;
// get subkey
relativeKey = relativeKey.substr(subKeyIndex + 1);
// handle standard names
wpi::StringRef propName;
nt::NetworkTableEntry entry{event.entry};
if (relativeKey == "mode") {
// reset to current mode
entry.SetString(VideoModeToString(sourceIt->second.GetVideoMode()));
return;
} else if (relativeKey.startswith("Property/")) {
propName = relativeKey.substr(9);
} else if (relativeKey.startswith("RawProperty/")) {
propName = relativeKey.substr(12);
} else {
return; // ignore
}
// everything else is a property
auto property = sourceIt->second.GetProperty(propName);
switch (property.GetKind()) {
case cs::VideoProperty::kNone:
return;
case cs::VideoProperty::kBoolean:
entry.SetBoolean(property.Get() != 0);
return;
case cs::VideoProperty::kInteger:
case cs::VideoProperty::kEnum:
entry.SetDouble(property.Get());
return;
case cs::VideoProperty::kString:
entry.SetString(property.GetString());
return;
default:
return;
}
},
NT_NOTIFY_IMMEDIATE | NT_NOTIFY_UPDATE);
}
CameraServer::CameraServer() : m_impl(new Impl) {}
CameraServer::~CameraServer() {}
cs::UsbCamera CameraServer::StartAutomaticCapture() {
cs::UsbCamera camera = StartAutomaticCapture(m_impl->m_defaultUsbDevice++);
cs::UsbCamera camera =
StartAutomaticCapture(::GetInstance().m_defaultUsbDevice++);
auto csShared = GetCameraServerShared();
csShared->ReportUsbCamera(camera.GetHandle());
return camera;
}
cs::UsbCamera CameraServer::StartAutomaticCapture(int dev) {
cs::UsbCamera camera{"USB Camera " + wpi::Twine(dev), dev};
::GetInstance();
cs::UsbCamera camera{fmt::format("USB Camera {}", dev), dev};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
csShared->ReportUsbCamera(camera.GetHandle());
return camera;
}
cs::UsbCamera CameraServer::StartAutomaticCapture(const wpi::Twine& name,
cs::UsbCamera CameraServer::StartAutomaticCapture(std::string_view name,
int dev) {
::GetInstance();
cs::UsbCamera camera{name, dev};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
@@ -489,8 +492,9 @@ cs::UsbCamera CameraServer::StartAutomaticCapture(const wpi::Twine& name,
return camera;
}
cs::UsbCamera CameraServer::StartAutomaticCapture(const wpi::Twine& name,
const wpi::Twine& path) {
cs::UsbCamera CameraServer::StartAutomaticCapture(std::string_view name,
std::string_view path) {
::GetInstance();
cs::UsbCamera camera{name, path};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
@@ -498,7 +502,7 @@ cs::UsbCamera CameraServer::StartAutomaticCapture(const wpi::Twine& name,
return camera;
}
cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& host) {
cs::AxisCamera CameraServer::AddAxisCamera(std::string_view host) {
return AddAxisCamera("Axis Camera", host);
}
@@ -510,12 +514,13 @@ cs::AxisCamera CameraServer::AddAxisCamera(const std::string& host) {
return AddAxisCamera("Axis Camera", host);
}
cs::AxisCamera CameraServer::AddAxisCamera(wpi::ArrayRef<std::string> hosts) {
cs::AxisCamera CameraServer::AddAxisCamera(std::span<const std::string> hosts) {
return AddAxisCamera("Axis Camera", hosts);
}
cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
const wpi::Twine& host) {
cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
std::string_view host) {
::GetInstance();
cs::AxisCamera camera{name, host};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
@@ -523,8 +528,9 @@ cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
return camera;
}
cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
const char* host) {
::GetInstance();
cs::AxisCamera camera{name, host};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
@@ -532,8 +538,9 @@ cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
return camera;
}
cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
const std::string& host) {
::GetInstance();
cs::AxisCamera camera{name, host};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
@@ -541,8 +548,9 @@ cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
return camera;
}
cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
wpi::ArrayRef<std::string> hosts) {
cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
std::span<const std::string> hosts) {
::GetInstance();
cs::AxisCamera camera{name, hosts};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
@@ -550,11 +558,12 @@ cs::AxisCamera CameraServer::AddAxisCamera(const wpi::Twine& name,
return camera;
}
cs::MjpegServer CameraServer::AddSwitchedCamera(const wpi::Twine& name) {
cs::MjpegServer CameraServer::AddSwitchedCamera(std::string_view name) {
auto& inst = ::GetInstance();
// create a dummy CvSource
cs::CvSource source{name, cs::VideoMode::PixelFormat::kMJPEG, 160, 120, 30};
cs::MjpegServer server = StartAutomaticCapture(source);
m_impl->m_fixedSources[server.GetHandle()] = source.GetHandle();
inst.m_fixedSources[server.GetHandle()] = source.GetHandle();
return server;
}
@@ -562,22 +571,23 @@ cs::MjpegServer CameraServer::AddSwitchedCamera(const wpi::Twine& name) {
cs::MjpegServer CameraServer::StartAutomaticCapture(
const cs::VideoSource& camera) {
AddCamera(camera);
auto server = AddServer(wpi::Twine("serve_") + camera.GetName());
auto server = AddServer(fmt::format("serve_{}", camera.GetName()));
server.SetSource(camera);
return server;
}
cs::CvSink CameraServer::GetVideo() {
auto& inst = ::GetInstance();
cs::VideoSource source;
{
auto csShared = GetCameraServerShared();
std::scoped_lock lock(m_impl->m_mutex);
if (m_impl->m_primarySourceName.empty()) {
std::scoped_lock lock(inst.m_mutex);
if (inst.m_primarySourceName.empty()) {
csShared->SetCameraServerError("no camera available");
return cs::CvSink{};
}
auto it = m_impl->m_sources.find(m_impl->m_primarySourceName);
if (it == m_impl->m_sources.end()) {
auto it = inst.m_sources.find(inst.m_primarySourceName);
if (it == inst.m_sources.end()) {
csShared->SetCameraServerError("no camera available");
return cs::CvSink{};
}
@@ -587,40 +597,40 @@ cs::CvSink CameraServer::GetVideo() {
}
cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
auto& inst = ::GetInstance();
wpi::SmallString<64> name{"opencv_"};
name += camera.GetName();
{
std::scoped_lock lock(m_impl->m_mutex);
auto it = m_impl->m_sinks.find(name);
if (it != m_impl->m_sinks.end()) {
std::scoped_lock lock(inst.m_mutex);
auto it = inst.m_sinks.find(name);
if (it != inst.m_sinks.end()) {
auto kind = it->second.GetKind();
if (kind != cs::VideoSink::kCv) {
auto csShared = GetCameraServerShared();
csShared->SetCameraServerError("expected OpenCV sink, but got " +
wpi::Twine(kind));
csShared->SetCameraServerError("expected OpenCV sink, but got {}",
static_cast<int>(kind));
return cs::CvSink{};
}
return *static_cast<cs::CvSink*>(&it->second);
}
}
cs::CvSink newsink{name};
cs::CvSink newsink{name.str()};
newsink.SetSource(camera);
AddServer(newsink);
return newsink;
}
cs::CvSink CameraServer::GetVideo(const wpi::Twine& name) {
wpi::SmallString<64> nameBuf;
wpi::StringRef nameStr = name.toStringRef(nameBuf);
cs::CvSink CameraServer::GetVideo(std::string_view name) {
auto& inst = ::GetInstance();
cs::VideoSource source;
{
std::scoped_lock lock(m_impl->m_mutex);
auto it = m_impl->m_sources.find(nameStr);
if (it == m_impl->m_sources.end()) {
std::scoped_lock lock(inst.m_mutex);
auto it = inst.m_sources.find(name);
if (it == inst.m_sources.end()) {
auto csShared = GetCameraServerShared();
csShared->SetCameraServerError("could not find camera " + nameStr);
csShared->SetCameraServerError("could not find camera {}", name);
return cs::CvSink{};
}
source = it->second;
@@ -628,89 +638,101 @@ cs::CvSink CameraServer::GetVideo(const wpi::Twine& name) {
return GetVideo(source);
}
cs::CvSource CameraServer::PutVideo(const wpi::Twine& name, int width,
cs::CvSource CameraServer::PutVideo(std::string_view name, int width,
int height) {
::GetInstance();
cs::CvSource source{name, cs::VideoMode::kMJPEG, width, height, 30};
StartAutomaticCapture(source);
return source;
}
cs::MjpegServer CameraServer::AddServer(const wpi::Twine& name) {
cs::MjpegServer CameraServer::AddServer(std::string_view name) {
auto& inst = ::GetInstance();
int port;
{
std::scoped_lock lock(m_impl->m_mutex);
port = m_impl->m_nextPort++;
std::scoped_lock lock(inst.m_mutex);
port = inst.m_nextPort++;
}
return AddServer(name, port);
}
cs::MjpegServer CameraServer::AddServer(const wpi::Twine& name, int port) {
cs::MjpegServer CameraServer::AddServer(std::string_view name, int port) {
::GetInstance();
cs::MjpegServer server{name, port};
AddServer(server);
return server;
}
void CameraServer::AddServer(const cs::VideoSink& server) {
std::scoped_lock lock(m_impl->m_mutex);
m_impl->m_sinks.try_emplace(server.GetName(), server);
auto& inst = ::GetInstance();
std::scoped_lock lock(inst.m_mutex);
inst.m_sinks.try_emplace(server.GetName(), server);
}
void CameraServer::RemoveServer(const wpi::Twine& name) {
std::scoped_lock lock(m_impl->m_mutex);
wpi::SmallString<64> nameBuf;
m_impl->m_sinks.erase(name.toStringRef(nameBuf));
void CameraServer::RemoveServer(std::string_view name) {
auto& inst = ::GetInstance();
std::scoped_lock lock(inst.m_mutex);
inst.m_sinks.erase(name);
}
cs::VideoSink CameraServer::GetServer() {
wpi::SmallString<64> name;
auto& inst = ::GetInstance();
std::string name;
{
std::scoped_lock lock(m_impl->m_mutex);
if (m_impl->m_primarySourceName.empty()) {
std::scoped_lock lock(inst.m_mutex);
if (inst.m_primarySourceName.empty()) {
auto csShared = GetCameraServerShared();
csShared->SetCameraServerError("no camera available");
return cs::VideoSink{};
}
name = "serve_";
name += m_impl->m_primarySourceName;
name = fmt::format("serve_{}", inst.m_primarySourceName);
}
return GetServer(name);
}
cs::VideoSink CameraServer::GetServer(const wpi::Twine& name) {
wpi::SmallString<64> nameBuf;
wpi::StringRef nameStr = name.toStringRef(nameBuf);
std::scoped_lock lock(m_impl->m_mutex);
auto it = m_impl->m_sinks.find(nameStr);
if (it == m_impl->m_sinks.end()) {
cs::VideoSink CameraServer::GetServer(std::string_view name) {
auto& inst = ::GetInstance();
std::scoped_lock lock(inst.m_mutex);
auto it = inst.m_sinks.find(name);
if (it == inst.m_sinks.end()) {
auto csShared = GetCameraServerShared();
csShared->SetCameraServerError("could not find server " + nameStr);
csShared->SetCameraServerError("could not find server {}", name);
return cs::VideoSink{};
}
return it->second;
}
void CameraServer::AddCamera(const cs::VideoSource& camera) {
auto& inst = ::GetInstance();
std::string name = camera.GetName();
std::scoped_lock lock(m_impl->m_mutex);
if (m_impl->m_primarySourceName.empty()) m_impl->m_primarySourceName = name;
m_impl->m_sources.try_emplace(name, camera);
std::scoped_lock lock(inst.m_mutex);
if (inst.m_primarySourceName.empty()) {
inst.m_primarySourceName = name;
}
inst.m_sources.try_emplace(name, camera);
}
void CameraServer::RemoveCamera(const wpi::Twine& name) {
std::scoped_lock lock(m_impl->m_mutex);
wpi::SmallString<64> nameBuf;
m_impl->m_sources.erase(name.toStringRef(nameBuf));
void CameraServer::RemoveCamera(std::string_view name) {
auto& inst = ::GetInstance();
std::scoped_lock lock(inst.m_mutex);
inst.m_sources.erase(name);
}
void CameraServer::SetSize(int size) {
std::scoped_lock lock(m_impl->m_mutex);
if (m_impl->m_primarySourceName.empty()) return;
auto it = m_impl->m_sources.find(m_impl->m_primarySourceName);
if (it == m_impl->m_sources.end()) return;
if (size == kSize160x120)
auto& inst = ::GetInstance();
std::scoped_lock lock(inst.m_mutex);
if (inst.m_primarySourceName.empty()) {
return;
}
auto it = inst.m_sources.find(inst.m_primarySourceName);
if (it == inst.m_sources.end()) {
return;
}
if (size == kSize160x120) {
it->second.SetResolution(160, 120);
else if (size == kSize320x240)
} else if (size == kSize320x240) {
it->second.SetResolution(320, 240);
else if (size == kSize640x480)
} else if (size == kSize640x480) {
it->second.SetResolution(640, 480);
}
}

Some files were not shown because too many files have changed in this diff Show More