Squashed 'third_party/allwpilib/' changes from e4b91005cf..83f1860047
83f1860047 [wpilib] Add/update documentation to PneumaticBase and subclasses (NFC) (#4881)
9872e676d8 [commands] Make Subsystem destructor virtual (#4892)
25db20e49d [hal] Fix segfault in various HAL functions (#4891)
b0c6724eed [glass] Add hamburger menu icon to titlebars (#4874)
f0fa8205ac Add missing compiler flags and fix warnings (#4889)
42fc4cb6bc [wpiutil] SafeThread: Provide start/stop hooks (#4880)
cc166c98d2 [templates] Add Command-based skeleton template (#4861)
3f51f10ad3 [build] Update to 2023v3 image (#4886)
1562eae74a [ntcore] Refactor meta-topic decoding from glass (#4809)
b632b288a3 Fix usages of std::min and std::max to be windows safe (#4887)
c11bd2720f [wpilibc] Add internal function to reset Shuffleboard instance (#4884)
f1151d375f [ntcore] Add method to get server time offset (#4847)
fe1b62647f [hal,wpilib] Update documentation for getComments (NFC) (#4879)
c49a45abbd [build] Fix examples linking in incorrect jni library (#4873)
bc3d01a721 [build] Add platform check to doxygen plugin (#4862)
bc473240ae Add Jetbrains Fleet folder to .gitignore (#4872)
2121bd5fb8 [wpimath] Remove RKF45 (#4870)
835f8470d6 [build] Fix roborio cross-compiler on arm hosts (#4864)
6cfe5de00d [ntcore] Don't deadlock server on early destroy (#4863)
2ac41f3edc [hal, wpilib] Add RobotController.getComments() (#4463)
26bdbf3d41 Java optimization and formatting fixes (#4857)
92149efa11 Spelling and grammar cleanups (#4849)
176fddeb4c [commands] Add functions to HID classes to allow use of axes as BooleanEvents/Triggers (#4762)
87a34af367 [templates] Add bindings to command-based template (#4838)
4534e75787 [examples] Remove redundant MotorControl example (#4837)
1cbebaa2f7 [commands] Remove final semicolon from test macro definition (#4859)
6efb9ee405 [commands] Add constructor for SwerveControllerCommand that takes a HolonomicDriveController (#4785)
1e7fcd5637 [cscore] Change run loop functions to not be mac specific (#4854)
1f940e2b60 [apriltag] Add C++ wrappers, rewrite Java/JNI to match (#4842)
a6d127aedf [build] Add missing task dependency in wpilibjExamples (#4852)
b893b3d6d3 [cscore] Add support for USB cameras on macOS (#4846)
1696a490fa [glass] Add support for alternate NT ports (#4848)
40a22d69bc [glass] Add support for alternate NT ports (#4848)
e84dbfede0 [wpilib] GenericHID: Add rumble both option (#4843)
8aa9dbfa90 [examples] Link apriltag package in examples build.gradle (#4845)
eda2fa8a17 [build] Update Spotless (#4840)
d20594db0d Fix typos (#4839)
dd8ecfdd54 [commands] Fix typo in waitUntil docs (NFC) (#4841)
17ceebfff4 [apriltag] Clean up apriltag JNI (#4823)
8b74ab389d [examples] RapidReactCommandBot: Fix array indices (#4833)
1aad3489c2 [sim] Implement PD total current and power (#4830)
2744991771 [wpimath] Fix docs in SwerveModulePosition (#4825)
ffbf6a1fa2 [commands] Disable regularly failing unit test (#4824)
fbabd0ef15 [commands] Enhance Command Sendable implementations (#4822)
7713f68772 [hal] Use atomic rather then mutex for DS Data updates (#4787)
701995d6cc [examples] Update Command-based starter project (#4778)
bf7068ac27 [wpilibc] Add missing PPS implementation for C++ (#4821)
aae0f52ca6 [ntcore] NetworkTable: fix visibility of get/set value (#4820)
ee02fb7ba7 [hal] Add support for Pulse-Per-Second signal (#4819)
518916ba02 [wpilib] Fix DS mode thread event being manual reset accidentally (#4818)
3997c6635b [hal] Update to new image, use new TCP notify callback and new duty cycle API (#4774)
cc8675a4e5 [examples] Add comment on how to view elevator sim (NFC) (#4482)
fb2c170b6e [ntcore] Simplify local startup (#4803)
7ba8a9ee1f [wpimath] ProfiledPIDController: Add to SendableRegistry (#4656)
c569d8e523 [wpilib] Joystick.getMagnitude(): use hypot() function (#4816)
2a5e89fa97 [apriltag] Improve description of pose coordinates (NFC) (#4810)
cc003c6c38 [apriltag] Fix AprilTagFieldLayout JSON name (#4814)
5522916123 [commands] CommandXBoxController bumper documentation fix (NFC) (#4815)
967b30de3a [glass] Fix NT view UpdateClients() bug (#4808)
3270d4fc86 [wpimath] Rewrite pose estimator docs (#4807)
be39678447 [apriltag] Add test to ensure apriltagjni loads (#4805)
61c75deb2a [commands] Test no-op behavior of scheduling a scheduled command (#4806)
a865f48e96 [ntcore] Pass pub/sub options as a unified PubSubOptions struct (#4794)
f66a667321 [commands] Fix incorrect Trigger docs (NFC) (#4792)
f8d4e9866e [ntcore] Clean up ntcore_test.h (#4804)
7e84ea891f [wpimath] Fix ComputerVisionUtil transform example in parameter docs (NFC) (#4800)
da3ec1be10 [wpimath] Change terminology for ArmFeedforward gravity gain (NFC) (#4791)
944dd7265d [wpilibc] Add C++ Notifier error handling, update java notifier error message (#4795)
6948cea67a [wpiutil] Fix MemoryBuffer initialization (#4797)
a31459bce6 [wpiutil] Fix UnescapeCString overflow when inputSize < 2 (#4796)
4a0ad6b48c [wpimath] Rotation2d: Add reference to angleModulus in docs (NFC) (#4786)
e6552d272e [ntcore] Remove table multi-subscriber (#4789)
bde383f763 [hal] Replace const char* with std::string_view in Driver Station sim functions (#4532)
5a52b51443 [hal] Add RobotController.getSerialNumber() (#4783)
69a66ec5ec [wpilib] Fix multiple motor safety issues (#4784)
989c9fb29a [wpimath] Revert Rotation2D change that limits angles (#4781)
0f5b08ec69 [wpigui] Update imgui to 1.89.1+ (#4780)
fba191099c [examples] AddressableLED: Add unit test (#4779)
b390cad095 [wpilibj] Consistently use ErrorMessages.requireNonNullParam (#4776)
b9772214d9 [wpilib] Sendable: Don't call setter for getter changes
342c375a71 [ntcore] Add subscriber option to exclude single publisher
b0e4053087 [ntcore] Use int for options instead of double
f3e666b7bb [cscore] Convert YUYV and UYVY directly to grayscale (#4777)
b300518bd1 [hal] Add CAN Stream API to Java through JNI bindings (#4193)
be27171236 [wpilibj] Shuffleboard: Check for null sendable (#4772)
4bbdbdfb48 [commands] Move GroupedCommands to CommandScheduler (#4728)
f18fd41ac3 [wpimath] Remove broken and obsoleted ComputerVisionUtil functions (#4775)
2d0faecf4f [glass] DataSource: Add spinlock to protect value (#4771)
348bd107fc [hal] Add CANManufacturer for The Thrifty Bot (#4773)
3149dc64b8 [examples] HatchbotInlined: Use Subsystem factories (#4765)
8618dd4160 [glass, wpilib] Replace remaining references to Speed Controller with Motor Controller (#4769)
72e21a1ed1 [apriltag] Use wpilibsuite fork of apriltag (#4764)
eab0d929e6 [commands] CommandGenericHID POV methods: Fix docs (NFC) (#4760)
6789869663 [wpilib] Call set(0) rather than disable for stopMotor (#4763)
c9dea2968d [cscore] Emit warning that USB Camera isn't supported on OSX (#4766)
8f402645f5 [commands] Fix PIDSubsystem setSetpoint behavior (#4759)
f24ad1d715 [build] Upgrade to googletest 1.12.1 (#4752)
ff88756864 [wpimath] Add new DCMotor functions for alternative calculations and reduction calculation (#4749)
f58873db8e [wpimath] Remove extra terms in matrix for pose estimator docs (#4756)
37e969b41a [wpimath] Add constructors to pose estimators with default standard deviations (#4754)
13cdc29382 [ci] Rename comment command from "/wpiformat" to "/format" (#4755)
6e23985ae6 [examples] Add main include directory to test builds (#4751)
66bb0ffb2c [examples] Add unit testing infrastructure (#4646)
74cc86c4c5 [wpimath] Make transform tests use pose/transform equality operators (#4675)
e22d8cc343 [wpimath] Use Odometry for internal state in Pose Estimation (#4668)
68dba92630 [ci] Update mac and windows builds to Java 17 (#4750)
23bfc2d9ab [sim] Remove unmaintained Gazebo support (#4736)
1f1461e254 [wpilib] Add method to enable/disable LiveWindow in test mode (#4678)
eae68fc165 [wpimath] Add tolerance for Rotation3d rotation matrix special orthogonality (#4744)
4c4545fb4b [apriltag] Suppress warning (#4743)
16ffaa754d [docs] Generate docs for apriltag subproject (#4745)
5e74ff26d8 [apriltag, build] Update native utils, add apriltag impl and JNI (#4733)
53875419a1 [hal] Allow overriding stderr printing by HAL_SendError (#4742)
aa6499e920 [ntcore] Fix special topic multi-subscriber handling (#4740)
df70351107 [build] Fix cmake install of thirdparty includes (#4741)
e9bd50ff9b [glass] NT view: clear meta-topic info on disconnect (#4732)
9b319fd56b [ntcore] Add sub option for local vs remote changes (#4731)
18d28ec5e3 [ntcore] Remove duplicate value checking from ClientImpl
bdfb625211 [ntcore] Send duplicate values to network if necessary
21003e34eb [commands] Update Subsystem factories and example to return CommandBase (#4729)
70080457d5 [commands] Refactor ProxyScheduleCommand, SelectCommand into ProxyCommand (#4534)
e82cd5147b [wpilib] Tweak Color HSV formula and use in AddressableLED (#4724)
ec124bb662 [commands] Allow unsetting a subsystem's default command (#4621)
2b2aa8eef7 [examples] Update all examples to use NWU coordinate conventions (#4725)
cb38bacfe8 [commands] Revert to original Trigger implementation (#4673)
15561338d5 [commands] Remove one more default command isFinished check (#4727)
ca35a2e097 Add simgui files to .gitignore (#4726)
20dbae0cee [examples] Renovate command-based examples (#4409)
1a59737f40 [commands] Add convenience factories (#4460)
42b6d4e3f7 Use defaulted comparison operators in C++ (#4723)
135c13958f [wpigui] Add FontAwesome (#4713)
ffbfc61532 [ntcore] Add NetworkTable table-specific listeners (#4640)
8958b2a4da [commands] Add property tests for command compositions (#4715)
e4ac09077c [wpilib] Add link to MotorSafety article (#4720)
f40de0c120 [commands] Add C++ factory templates (#4686)
51fa3e851f [build] cmake: Use FetchContent instead of ExternalProject (#4714)
1da84b2255 [wpigui] Reload fonts to scale rather than preloading (#4712)
e43e2fbc84 [wpiutil] StringExtras: Add UnescapeCString (#4707)
5804d8fa84 [ntcore] Server: Properly handle multiple subscribers (#4717)
169ef5fabf [glass] Update NT view for topicsOnly and sendAll changes (#4718)
148759ef54 [examples] CANPDP: Expand properties shown (#4687)
58ed112b51 [commands] RepeatCommand: restart on following iteration (#4706)
dd1da77d20 [readme] Fix broken CI badge (#4710)
7cda85df20 [build] Check Gradle plugin repo last to fix CI (#4711)
7ed9b13277 [build] Bump version plugin to fix null tag (#4705)
6b4f26225d [apriltag] Fix pluralization of apriltag artifacts (#4671)
b2d2924b72 [cscore] Add Y16 image support (#4702)
34ec89c041 [wpilibc] Shuffleboard SimpleWidget: Return pointer instead of reference (#4703)
e15200068d [ci] Disable HW testbench runs (#4704)
d5200db6cd [wpimath] Rename HolonomicDriveController.calculate params (#4683)
2ee3d86de4 [wpimath] Clarify Rotation3d roll-pitch-yaw direction (#4699)
9f0a8b930f [cscore] Use MFVideoFormat_L8 for Gray on Windows (#4701)
2bca43779e [cscore] Add UYVY image support (#4700)
4307d0ee8b [glass] Plot: allow for more than 11 plots (#4685)
3fe8d355a1 [examples] StateSpaceDifferentialDriveSimulation: Use encoder reversed constants (#4682)
b44034dadc [ntcore] Allow duplicate client IDs on server (#4676)
52d2c53888 [commands] Rename Java factory wait() to waitSeconds() (#4684)
76e918f71e [build] Fix JNI artifacts linking to incorrect libraries (#4680)
0bee875aff [commands] Change C++ CommandPtr to use CommandBase (#4677)
98e922313b [glass] Don't check IsConnected for NT widgets (#4674)
9a36373b8f [apriltag] Switch 2022 apriltag layout length and width values (#4670)
cf8faa9e67 [wpilib] Update values on controllable sendables (#4667)
5ec067c1f8 [ntcore] Implement keep duplicates pub/sub flag (#4666)
e962fd2916 [ntcore] Allow numeric-compatible value sets (#4620)
88bd67e7de [ci] Update clang repositories to jammy (#4665)
902e8686d3 [wpimath] Rework odometry APIs to improve feature parity (#4645)
e2d49181da Update to native utils 2023.8.0 (#4664)
149bac55b1 [cscore] Add Arducam OV9281 exposure quirk (#4663)
88f7a3ccb9 [wpimath] Fix Pose relativeTo documentation (#4661)
8acce443f0 [examples] Fix swerve examples to use getDistance for turning encoder (#4652)
295a1f8f3b [ntcore] Fix WaitForListenerQueue (#4662)
388e7a4265 [ntcore] Provide mechanism to reset internals of NT instance (#4653)
13aceea8dc [apriltag] Fix FieldDimensions argument order (#4659)
c203f3f0a9 [apriltag] Fix documentation for AprilTagFieldLayout (#4657)
f54d495c90 Fix non initialized hal functionality during motor safety init (#4658)
e6392a1570 [cmd] Change factories return type to CommandBase (#4655)
53904e7cf4 [apriltag] Split AprilTag functionality to a separate library (#4578)
2e88a496c2 [wpimath] Add support for swerve joystick normalization (#4516)
ce4c45df13 [wpimath] Rework function signatures for Pose Estimation / Odometry (#4642)
0401597d3b [readme] Add wpinet to MavenArtifacts.md (#4651)
2e5f9e45bb [wpimath] Remove encoder reset comments on Swerve, Mecanum Odometry and Pose Estimation (#4643)
e4b5795fc7 [docs] Disable Doxygen for memory to fix search (#4636)
03d0ea188c [build] cmake: Add missing wpinet to installed config file (#4637)
3082bd236b [build] Move version file to its own source set (#4638)
b7ca860417 [build] Use build cache for sign step (#4635)
64838e6367 [commands] Remove unsafe default command isFinished check (#4411)
1269d2b901 [myRobot] Disable spotbugs (#4565)
14d8506b72 [wpimath] Fix units docs for LinearSystemId::IdentifyDrivetrainSystem() (#4600)
d1d458db2b [wpimath] Constrain Rotation2d range to -pi to pi (#4611)
f656e99245 [readme] Add links to development build documentation (#4481)
6dd937cef7 [commands] Fix Trigger API docs (NFC) (#4599)
49047c85b9 [commands] Report error on C++ CommandPtr use-after-move (#4575)
d07267fed1 [ci] Upgrade containers to Ubuntu 22.04 and remove libclang installation (#4633)
b53ce1d3f0 [build, wpiutil] Switch macos to universal binaries (#4628)
5a320c326b [upstream_util, wpiutil] Refactor python scripts (#4614)
c4e526d315 [glass] Fix NT Mechanism2D (#4626)
d122e4254f [ci] Run spotlessApply after wpiformat in comment command (#4623)
5a1e7ea036 [wpilibj] FieldObject2d: Add null check to close() (#4619)
179f569113 [ntcore] Notify locally on SetDefault (#4617)
b0f6dc199d [wpilibc] ShuffleboardComponent.WithProperties: Update type (#4615)
7836f661cd [wpimath] Add missing open curly brace to units/base.h (#4613)
dbcc1de37f [wpimath] Add DifferentialDriveFeedforward classes which wrap LinearPlantInversionFeedforward (#4598)
93890c528b [wpimath] Add additional angular acceleration units (#4610)
3d8d5936f9 [wpimath] Add macro for disabling units fmt support (#4609)
2b04159dec [wpimath] Update units/base.h license header (#4608)
2764004fad [wpinet] Fix incorrect jni definitions (#4605)
85f1bb8f2b [wpiutil] Reenable jni check task (#4606)
231ae2c353 [glass] Plot: Fix Y-axis not being saved (#4594)
e92b6dd5f9 [wpilib] Fix AprilTagFieldLayout JSON property name typos (#4597)
2a8e0e1cc8 Update all dependencies that use grgit (#4596)
7d06e517e9 [commands] Move SelectCommand factory impl to header (#4581)
323524fed6 [wpimath] Remove deprecated units/units.h header (#4572)
d426873ed1 [commands] Add missing PS4 triangle methods (#4576)
5be5869b2f [apriltags] Use map as internal data model (#4577)
b1b4c1e9e7 [wpimath] Fix Pose3d transformBy rotation type (#4545)
a4054d702f [commands] Allow composing two triggers directly (#4580)
0190301e09 [wpilibc] Explicitly mark EventLoop as non-copyable/non-movable (#4579)
9d1ce6a6d9 [ntcore] Catch file open error when saving preferences (#4571)
5005e2ca04 [ntcore] Change Java event mask to EnumSet (#4564)
fa44a07938 [upstream-utils][mpack] Add upstream util for mpack (#4500)
4ba16db645 [ntcore] Various fixes and cleanups (#4544)
837415abfd [hal] Fix joysticks either crashing or returning 0 (#4570)
2c20fd0d09 [wpilib] SingleJointedArmSim: Check angle equals limit on wouldHit (#4567)
64a7136e08 [wpimath] SwerveDrivePoseEstimator: Restore comment about encoder reset (#4569)
b2b473b24a [wpilib] Add AprilTag and AprilTagFieldLayout (#4421)
7aab8fa93a [build] Update to Native Utils 2023.6.0 (#4563)
12c2851856 [commands] WrapperCommand: inherit from CommandBase (#4561)
0da169dd84 [wpimath] Remove template argument from ElevatorFeedforward (#4554)
2416827c25 [wpimath] Fix docs for pose estimator local measurement models (#4558)
1177a3522e [wpilib] Fix Xbox/PS4 POV sim for port number constructors (#4548)
102344e27a [commands] HID classes: Add missing methods, tweak return types (#4557)
1831ef3e19 [wpilib] Fix Shuffleboard SuppliedValueWidget (#4559)
a9606ce870 [wpilib] Fix Xbox/PS4 POV sim (#4546)
6c80d5eab3 [wpimath] Remove unused SymbolExports.h include from units/base.h (#4541)
b114006543 [ntcore] Unify listeners (#4536)
32fbfb7da6 [build] cmake: Install ntcore generated include files (#4540)
02465920fb [build] Update native utils to 2023.4.0 (#4539)
3a5a376465 [wpimath] Increase constexpr support in geometry data types (#4231)
1c3c86e9f1 [ntcore] Cache GetEntry(name) values (#4531)
dcda09f90a [command] Rename trigger methods (#4210)
66157397c1 [wpilib] Make drive classes follow NWU axes convention (#4079)
9e22ffbebf [ntcore] Fix null deref in NT3 client (#4530)
648ab6115c [wpigui,dlt,glass,ov] Support arm in GUI tools (#4527)
8bc3b04f5b [wpimath] Make ComputerVisionUtil use 3D geometry classes (#4528)
cfb84a6083 [wpilibc] Don't hang waiting for NT server to start (#4524)
02c47726e1 [wpimath] Remove unused odometry instance from DifferentialDrivePoseEstimator test (#4522)
b2a0093294 [ci] Revert upgrade of github-pages-deploy-action (#4521)
2a98d6b5d7 [wpimath] PIDController: Add getters for position & velocity tolerances (#4458)
9f36301dc8 [ci] Write wpiformat patch to job summary (#4519)
901fc555f4 [wpimath] Position Delta Odometry for Mecanum (#4514)
4170ec6107 [wpimath] Position Delta Odometry for Swerve (#4493)
fe400f68c5 [docs] Add wpinet to docs build (#4517)
794669b346 [ntcore] Revamp listeners (#4511)
dcfa85a5d5 [ci] Build sanitizers with clang-14 (#4518)
15ad855f1d [ntcore] Add UnitTopic<T> (C++ only) (#4497)
11244a49d9 [wpilib] Add IsConnected function to all gyros (#4465)
1d2e8eb153 [build] Update myRobot deployment (#4515)
ad53fb19b4 [hal] Use new HMB api for addressable LED (#4479)
ba850bac3b [hal] Add more shutdown checks and motor safety shutdown (#4510)
023a5989f8 [ntcore] Fix typo in NetworkServer client connect message (#4512)
c970011ccc [docs] Add Doxygen aliases used by Foonathan memory (#4509)
07a43c3d9a [readme] Document clang-format version and /wpiformat (#4503)
a05b212b04 [ci] Revert changes to wpiformat task from #4501 (#4508)
09faf31b67 [commands] Replace Command HID inheritance with delegation (#4470)
9e1f9c1133 [commands] Add command factories (#4476)
f19d2b9b84 [ci] Add NUMBER environment variable to comment command commit script (#4507)
a28f93863c [ci] Push comment command commit directly to PR (#4506)
c9f61669b8 [ci] Fix comment command commit push (#4505)
dcce5ad3b3 [ci] Update github-script API usage (#4504)
6836e5923d [wpilibc] Restore get duty cycle scale factor (#4502)
335188c652 [dlt] Add deselect/select all buttons to download view (#4499)
60a29dcb99 [glass] Field2D: Add "hidden" option for objects (#4498)
b55d5b3034 [ci] Update deprecated github actions (#4501)
10ed4b3969 [ntcore] Various NT4 fixes (#4474)
4a401b89d7 [hal, wpilib] New DS thread model and implementation (#3787)
c195b4fc46 [wpimath] Clean up PoseEstimator nominal dt docs (#4496)
8f2e34c6a3 [build] Remove wpilib prefix from CMake flat install (#4492)
150d692df7 [wpimath] Remove unused private PoseEstimator function (#4495)
3e5bfff1b5 [wpimath] FromFieldRelativeSpeeds: Add ChassisSpeeds overload (#4494)
9c7e66a27d [commands] C++: Add CommandPtr overload for SetDefaultCommand (#4488)
0ca274866b [build] Fix CMake system library opt-ins (#4487)
dc037f8d41 [commands] Remove EndlessCommand (#4483)
16cdc741cf [wpimath] Add Pose3d(Pose2d) constructor (#4485)
9d5055176d [build] cmake: Allow disabling ntcore build (#4486)
d1e66e1296 [build] Compile all java code with inline string concatenation (#4490)
1fc098e696 Enable log macros to work with no args (#4475)
878cc8defb [wpilib] LiveWindow: Add enableAllTelemetry() (#4480)
8153911160 [build] Fix MSVC runtime archiver to grab default runtime (#4478)
fbdc810887 Upgrade to C++20 (#4239)
396143004c [ntcore] Add ntcoreffi binary (#4471)
1f45732700 [build] Update to 2023.2.4 native-utils and new dependencies (#4473)
574cb41c18 [ntcore] Various fixes (#4469)
d9d6c425e7 [build] Force Java 11 source compatibility (#4472)
58b6484dbe Switch away from NI interrupt manager to custom implementation (#3705)
ca43fe2798 [wpimath] Use Units conversions in ComputerVisionUtil docs (NFC) (#4464)
87a64ccedc [hal] Convert DutyCycle Raw output to be a high time measurement (#4466)
89a3d00297 [commands] Add FinallyDo and HandleInterrupt decorators (#4412)
1497665f96 [commands] Add C++ versions of Java-only decorators (#4457)
27b173374e [wpimath] Add minLinearAccel parameter to DifferentialDriveAccelerationLimiter (#4422)
2a13dba8ac [wpilib] TrajectoryUtil: Fix ambiguous documentation (NFC) (#4461)
77301b126c [ntcore] NetworkTables 4 (#3217)
90cfa00115 [build] cmake: Fix libssh include directory order (#4459)
5cf961edb9 [commands] Refactor lambda-based commands to inherit FunctionalCommand (#4451)
b2276e47de [wpimath] Enable continuous angle input for HolonomicDriveController (#4453)
893b46139a [fieldImages] Add utilities to simplify loading of fields (#4456)
60e29627c0 [commands] C++ unique_ptr migration (#4319)
3b81cf6c35 [wpilib] Improve Color.toString (#4450)
5c067d30a0 [wpinet] WebSocket: Add SendFrames() (#4445)
ceaf493811 [wpiutil] MakeJByteArray: Use span<uint8> instead of string_view (#4446)
10e04e2b13 [examples] FrisbeeBot: Fix reference capture (#4449)
726f67c64b [build] Add exeSplitSetup (#4444)
c7b7624c1c [wpiutil] Add MessagePack utility functions (#4448)
d600529ec0 [wpinet] uv::Async: Add UnsafeSend() (#4447)
b53b3526a2 [wpimath] Add CoordinateSystem conversion for Transform3d (#4443)
38bb23eb18 [wpimath] Add scalar multiply and divide operators to all geometry classes (#4438)
3937ff8221 [wpilib] Remove deprecated Controller class (#4440)
abbfe244b5 [wpilib] Improve Color FromHSV (#4439)
4ddb8aa0dd [sim] Provide function that resets all simulation data (#4016)
a791470de7 Clean up Java warning suppressions (#4433)
17f504f548 [hal,wpilib] Fix SPI Mode Setting (#4434)
773198537c [wpiutil] Add wpi::scope_exit (#4432)
5ac658c8f0 [wpiutil] Logger: Conditionalize around WPI_LOG (#4431)
8767e4a941 [wpiutil] DataLog: Fix SetMetadata output (#4430)
8c4af073f4 [wpiutil] Synchronization: shutdown race protection (#4429)
c79f38584a [build] Fix Java integration tests (#4428)
36c08dd97c [build] Fix cmake install of fmtlib (#4426)
69b7b3dd7d [ci] Remove the Windows cmake job (#4425)
738c75fed8 [readme] Fix formatting/linting link (#4423)
4eb1d03fb3 [wpimath] Document C++ LinearFilter exception (#4417)
ba4ec6c967 [build] Fix clang-tidy false positive on Linux (#4406)
97836f0e55 [commands] Fix ProfiledPIDSubsystem setGoal behavior (#4414)
fdfb85f695 [wpimath] Remove Java LQR constructor that takes a controller gain matrix (#4419)
ab1baf4832 [wpimath] Add rotation matrix constructor to Rotation3d (#4413)
9730032866 [wpimath] Document LQR and KalmanFilter exceptions (#4418)
5b656eecf6 [wpimath] Fix HTML5 entity (#4420)
9ae38eaa7c [commands] Add owning overload to ProxyScheduleCommand (#4405)
cb33bd71df [commands] deprecate withInterrupt decorator (#4407)
d9b4e7b8bf [commands] Revert "Change grouping decorator impl to flatten nested group structures (#3335)" (#4402)
0389bf5214 [hal] REVPH: Improve handling of disconnected CAN Bus (#4169)
4267fa08d1 [wpilibc] ADIS IMUs: Fix memory leak (#4170)
65c8fbd452 [wpilib] MotorControllerGroup: Override setVoltage (#4403)
f36162fddc [wpimath] Improve Discretization internal docs (#4400)
5149f7d894 [wpimath] Add two-vector Rotation3d constructor (#4398)
20b5bed1cb [wpimath] Clean up Java Quaternion class (#4399)
f18dd1905d [build] Include all thirdparty sources in distribution (#4397)
aa9d7f1cdc [wpiutil] Import foonathan memory (#4306)
2742662254 [ci] Remove a couple of obsolete clang-tidy checks (#4396)
a5df391166 [hal, wpilib] Fix up DIO pulse API (#4387)
59e6706b75 [glass] Turn on docking by default
8461bb1e03 [glass] Add support for saving docking info
b873e208b4 [wpigui] Add support for imgui config flags
873e72df8c [build] Update imgui to 1.88 docking branch
c8bd6fc5b4 [ci] Fix comment-command (take 2) (#4395)
fed68b83b4 [ci] Fix comment-command action not running runners (#4393)
0ef8a4e1df [wpimath] Support formatting more Eigen types (#4391)
c393b3b367 [build] Update to native utils 2023.1.0 and Gradle 7.5.1 (#4392)
b5a17f762c [wpimath] Add direction to slew rate limiter (#4377)
fafc81ed1a [wpiutil] Upgrade to fmt 9.1.0 (#4389)
cc56bdc787 [wpiutil] SafeThread: Add Synchronization object variant (#4382)
4254438d8d [commands] Mark command group lifecycle methods as final (#4385)
97c15af238 [wpimath] LinearSystemId: Fix docs, move C++ impls out of header (#4388)
d22ff8a158 [wpiutil] Add JNI access to C++ stderr (#4381)
fdb5a2791f [wpiutil] jni_util: Add Mac-friendly MakeJLongArray/JArrayRef (#4383)
c3a93fb995 [commands] Revamp Interruptible (#4192)
f2a8d38d2a [commands] Rename Command.repeat to repeatedly (#4379)
9e24c6eac0 [wpiutil] Logger: paren-protect instance usage in macro (#4384)
fe4d12ce22 [wpimath] Add LTV controller derivations and make enums private (#4380)
eb08486039 [build] Fix MacOS binary rpath generation (#4376)
ccf83c634a [build] Use native-utils platform names instead of raw strings (#4375)
3fd69749e7 [docs] Upgrade to doxygen 1.9.4 (#4370)
594df5fc08 [wpinet] uv/util.h: Pull in ws2_32.lib on Windows for ntohs (#4371)
539070820d [ci] Enable asan for wpinet and wpiutil (#4369)
564a56d99b [wpinet] Fix memory leak in WorkerThreadTest (#4368)
5adf50d93c [upstream_utils] Refactor upstream_utils scripts (#4367)
d80e8039d7 [wpiutil] Suppress fmtlib clang-tidy warning in C++20 consteval contexts (#4364)
0e6d67b23b [upstream_utils] Remove yapf format disable comment (#4366)
be5270697a [build] Suppress enum-enum deprecation warning in OpenCV (#4365)
8d28851263 Add Rosetta install command to build requirements (#4363)
3d2115c93e [wpinet] include-what-you-use in MulticastTest (#4360)
91002ae3cc [wpimath] Upgrade to Drake 1.6.0 (#4361)
148c18e658 [wpinet] Upgrade to libuv 1.44.2 (#4362)
a2a5c926b6 Fix clang-tidy warnings (#4359)
ea6b1d8449 [wpiutil] Remove unused ManagedStatic class (#4358)
ac9be78e27 Use stricter C++ type conversions (#4357)
151dabb2af [wpiutil] Upgrade to fmt 9.0.0 (#4337)
340465c929 [ci] Upgrade to clang-format and clang-tidy 14 (NFC) (#4347)
d45bcddd15 [examples] Add comments to StateSpaceDifferentialDrive (#4341)
0e0786331a Update LLVM libraries to 14.0.6 (#4350)
c5db23f296 [wpimath] Add Eigen sparse matrix and iterative solver support (#4349)
44abc8dfa6 [upstream_utils] Remove git version from upstream patches (#4351)
3fdb2f767d [wpimath] Add comments with Ramsete equations (#4348)
0485f05da9 [wpilibjExamples] Upgrade jacoco to match allwpilib (#4346)
0a5eb65231 [wpinet] Handle empty txt block for mdns announcer (#4072)
19ffebaf3e [wpilib] Add reference to I2C Lockup to API Docs (NFC) (#4340)
ce1a90d639 [hal] Replace SerialHelper "goto done" with continue (#4342)
d25af48797 [ci] Make upstream_utils CI fail on untracked files (#4339)
ebb836dacb [examples] Fix negations in event loop examples (#4334)
d83e202f00 [upstream_utils] Update paths in update_fmt.py (#4338)
3ccf806064 [wpimath] Remove redundant LinearFilter.finiteDifference() argument (#4335)
6f1e01f8bd [wpimath] Document example of online filtering for LinearFilter.finiteDifference() (#4336)
1023c34b1c [readme] Update location of ni-libraries (#4333)
faa29d596c [wpilib] Improve Notifier docs (NFC) (#4326)
add00a96ed [wpimath] Improve DifferentialDriveAccelerationLimiter docs (NFC) (#4323)
82fac41244 [wpimath] Better document trackwidth parameters (NFC) (#4324)
5eb44e22a9 Format Python scripts with black (NFC) (#4325)
2e09fa7325 [build] Fix mpack cmake (#4322)
fe3c24b1ee [command] Add ignoringDisable decorator (#4305)
aa221597bc [build] Add M1 builds, change arm name, update to 2023 deps (#4315)
579a8ee229 [ci] Use one worker for Windows release Gradle build (#4318)
5105c5eab6 [wpilibj] Change "final" to "exit" in the IterativeRobotBase JavaDoc (NFC) (#4317)
787fe6e7a5 [wpiutil] Separate third party libraries (#4190)
6671f8d099 [wpigui] Update portable file dialogs (#4316)
9ac9b69aa2 [command] Reorder Scheduler operations (#4261)
e61028cb18 [build] halsim_gui: Add wpinet dependency (#4313)
661d23eaf5 [glass] Add precision setting for NetworkTable view (#4311)
666040e3e5 [hal] Throw exceptions for invalid sizes in I2C and SPI JNI (#4312)
aebc272449 [build] Upgrade to spotbugs Gradle plugin 5.0.8 (#4310)
fd884581e4 [wpilib] Add BooleanEvent/Trigger factories on HID classes (#4247)
9b1bf5c7f1 [wpimath] Move Drake and Eigen to thirdparty folders (#4307)
c9e620a920 [wpilibc] Change EventLoop data structure to vector (#4304)
41d40dd62f [wpinet] Fix libuv unused variable warning on Mac (#4299)
30f5b68264 [wpinet] Fix JNI loading error (#4295)
f7b3f4b90e [examples] Getting Started: Change Joystick to XboxController (#4194)
a99c11c14c [wpimath] Replace UKF implementation with square root form (#4168)
45b7fc445b [wpilib] Add EventLoop (#4104)
16a4888c52 [wpilib] Default off LiveWindow telemetry (#4301)
17752f1337 [ci] Split debug and release Windows builds (#4277)
abb45a68db [commands] Remove custom test wrappers (#4296)
1280a54ef3 [upstream_utils]: Make work with Python 3.8 (#4298)
f2d243fa68 [build] Change defaults for Java lints (#4300)
a4787130f4 Update using development build to work with 2023 gradlerio (#4294)
af7985e46c [wpiutil] Use invoke_result_t instead of result_of in future.h (#4293)
e9d1b5c2d0 [hal] Remove deprecated SimDevice functions (#4209)
45b598d236 [wpilibj] Add toString() methods to Color and Color8Bit (#4286)
fc37265da5 [wpimath] Add angle measurement convention to ArmFeedforward docs (NFC) (#4285)
a4ec13eb0e [wpilibjexamples] Remove unnecessary voltage desaturation
2fa52007af [wpilibc] Use GetBatteryVoltage() in MotorController::SetVoltage
d9f9cd1140 [wpimath] Reset prev_time on pose estimator reset (#4283)
8b6df88783 [wpilibj] Tachometer.getFrequency(): Fix bug (#4281)
345cff08c0 [wpiutil] Make wpi::array constexpr (#4278)
57428112ac [wpimath] Upgrade to Drake v1.3.0 (#4279)
a18d4ff154 [build] Fix tools not being copied when built with -Ponly* (#4276)
d1cd07b9f3 [wpigui] Add OpenURL (#4273)
e67f8e917a [glass] Use glfwSetKeyCallback for Enter key remap (#4275)
be2fedfe50 [wpimath] Add stdexcept include for std::invalid_argument (IWYU) (#4274)
7ad2be172e [build] Update native-utils to 2023.0.1 (#4272)
abc605c9c9 [ci] Update workflows to 20.04 base image (#4271)
3e94805220 [wpiutil] Reduce llvm collections patches (#4268)
db2e1d170e [upstream_utils] Document how to update thirdparty libraries (#4253)
96ebdcaf16 [wpimath] Remove unused Eigen AutoDiff module (#4267)
553b2a3b12 [upstream_utils] Fix stackwalker (#4265)
3e13ef42eb [wpilibc] Add missing std::array #include (include-what-you-use) (#4266)
d651a1fcec Fix internal deprecation warnings (#4257)
b193b318c1 [commands] Add unless() decorator (#4244)
ef3714223b [commands] Remove docs reference to obsolete interrupted() method (NFC) (#4262)
3d8dbbbac3 [readme] Add quickstart (#4225)
013efdde25 [wpinet] Wrap a number of newer libuv features (#4260)
816aa4e465 [wpilib] Add Pneumatics sim classes (#4033)
046c2c8972 [wpilibc] Rename SpeedControllerGroupTest.cpp (#4258)
d80e9cdf64 [upstream_utils] Use shallow clones for thirdparty repos (#4255)
7576136b4a [upstream_utils] Make update_llvm.py executable (#4254)
c3b223ce60 [wpiutil] Vendor llvm and update to 13.0.0 (#4224)
5aa67f56e6 [wpimath] Clean up math comments (#4252)
fff4d1f44e [wpimath] Extend Eigen warning suppression to GCC 12 (#4251)
0d9956273c [wpimath] Add CoordinateSystem.convert() translation and rotation overloads (#4227)
3fada4e0b4 [wpinet] Update to libuv 1.44.1 (#4232)
65b23ac45e [wpilibc] Fix return value of DriverStation::GetJoystickAxisType() (#4230)
4ac34c0141 [upstream_utils] Cleanup update_libuv.py (#4249)
8bd614bb1e [upstream_utils] Use "git am" instead of "git apply" for patches (#4248)
4253d6d5f0 [upstream_utils] Apply "git am" patches individually (#4250)
6a4752dcdc Fix GCC 12.1 warning false positives (#4246)
5876b40f08 [wpimath] Memoize CoordinateSystem and CoordinateAxis statics (#4241)
5983434a70 [cameraserver] Replace IterativeRobot in comment sample code with TimedRobot (#4238)
a3d44a1e69 [wpimath] Add Translation2d.getAngle() (#4217)
d364bbd5a7 [upstream_utils] Give vendor update scripts execute permissions (#4226)
f341e1b2be [wpimath] Document standard coordinate systems better (NFC) (#4228)
9af389b200 [wpinet] AddrToName: Initialize name (#4229)
2ae4adf2d7 [ci] Add wpiformat command to PRs (#4223)
178b2a1e88 Contributing.md: Correct version of clang-format used (#4222)
18db343cdc [wpiutil, wpinet] Vendor libuv, stack walker (#4219)
f0c821282a [build] Use artifactory mirror (#4220)
d673ead481 [wpinet] Move network portions of wpiutil into new wpinet library (#4077)
b33715db15 [wpimath] Add CoordinateSystem class (#4214)
99424ad562 [sim] Allow creating a PWMSim object from a PWMMotorController (#4039)
dc6f641fd2 [wpimath] PIDController: Reset position and velocity error when reset() is called. (#4064)
f20a20f3f1 [wpimath] Add 3D geometry classes (#4175)
708a4bc3bc [wpimath] Conserve previously calculated swerve module angles when updating states for stationary ChassisSpeeds (#4208)
ef7ed21a9d [wpimath] Improve accuracy of ComputerVisionUtil.calculateDistanceToTarget() (#4215)
b1abf455c1 [wpimath] LTVUnicycleController: Use LUT, provide default hyperparameters (#4213)
d5456cf278 [wpimath] LTVDifferentialDriveController: Remove unused variable (#4212)
99343d40ba [command] Remove old command-based framework (#4211)
ee03a7ad3b Remove most 2022 deprecations (#4205)
ce1a7d698a [wpimath] Refactor WheelVoltages inner class to a separate file (#4203)
87bf70fa8e [wpimath] Add LTV controllers (#4094)
ebd2a303bf [wpimath] Remove deprecated MakeMatrix() function (#4202)
e28776d361 [wpimath] LinearSystemLoop: Add extern templates for common cases
dac1429aa9 [wpimath] LQR: Use extern template instead of Impl class
e767605e94 [wpimath] Add typedefs for common types
97c493241f [wpimath] UnscentedKalmanFilter: Move implementation out-of-line
8ea90d8bc9 [wpimath] ExtendedKalmanFilter: Move implementation out-of-line
ae7b1851ec [wpimath] KalmanFilter: Use extern template instead of Impl class
e3d62c22d3 [wpimath] Add extern templates for common cases
7200c4951d [wpiutil] SymbolExports: Add WPILIB_IMPORTS for dllimport
84056c9347 [wpiutil] SymbolExports: Add EXPORT_TEMPLATE_DECLARE/DEFINE
09cf6eeecb [wpimath] ApplyDeadband: add a scale param (#3865)
03230fc842 [build,ci] Enable artifactory build cache (#4200)
63cf3aaa3f [examples] Don't square ArcadeDrive inputs in auto (#4201)
18ff694f02 [wpimath] Add Rotation2d.fromRadians factory (#4178)
4f79ceedd9 [wpilibc] Add missing #include (#4198)
f7ca72fb41 [command] Rename PerpetualCommand to EndlessCommand (#4177)
a06b3f0307 [hal] Correct documentation on updateNotifierAlarm (#4156)
d926dd1610 [wpimath] Fix pose estimator performance (#4111)
51bc893bc5 [wpiutil] CircularBuffer: Change Java package-private methods to public (#4181)
fbe761f7f6 [build] Increase Gradle JVM heap size (#4172)
5ebe911933 [wpimath] Add DifferentialDriveAccelerationLimiter (#4091)
3919250da2 [wpilibj] Remove finalizers (#4158)
b3aee28388 [commands] Allow BooleanSupplier for Trigger operations (#4103)
9d20ab3024 [wpilib] Allow disabling ElevatorSim gravity (#4145)
aaa69f6717 [ci] Remove 32-bit Windows builds (#4078)
355a11a414 Update Java linters and fix new PMD errors (#4157)
ffc69d406c [examples] Reduce suggested acceleration in Ramsete example (#4171)
922d50079a [wpimath] Units: fix comment in degreesToRotations (NFC) (#4159)
dd163b62ae [wpimath] Rotation2d: Add factory method that uses rotations (#4166)
bd80e220b9 [ci] Upgrade CMake actions (#4161)
aef4b16d4c [wpimath] Remove unnecessary NOLINT in LinearPlantInversionFeedforward (NFC) (#4155)
975171609e [wpilib] Compressor: Rename enabled to isEnabled (#4147)
5bf46a9093 [wpimath] Add ComputerVisionUtil (#4124)
f27a1f9bfb [commands] Fix JoystickButton.getAsBoolean (#4131)
1b26e2d5da [commands] Add RepeatCommand (#4009)
88222daa3d [hal] Fix misspelling in AnalogInput/Output docs (NFC) (#4153)
81c5b41ce1 [wpilibj] Document MechanismLigament2d angle unit (NFC) (#4142)
9650e6733e [wpiutil] DataLog: Document finish and thread safety (NFC) (#4140)
c8905ec29a [wpimath] Remove ImplicitModelFollower dt argument (#4119)
b4620f01f9 [wpimath] Fix Rotation2d interpolation in Java (#4125)
2e462a19d3 [wpimath] Constexprify units unary operators (#4138)
069f932e59 [build] Fix gl3w cmake build (#4139)
126e3de91a [wpilibc] Remove unused SetPriority() call from Ultrasonic (#4123)
ba0dccaae4 [wpimath] Fix reference to Rotation2d.fromRadians() (#4118)
e1b6e5f212 [wpilib] Improve MotorSafety documentation (NFC) (#4120)
8d79dc8738 [wpimath] Add ImplicitModelFollower (#4056)
78108c2aba [wpimath] Fix PIDController having incorrect error after calling SetSetpoint() (#4070)
cdafc723fb [examples] Remove unused LinearPlantInversionFeedforward includes (#4069)
0d70884dce [wpimath] Add InterpolatedTreeMap (#4073)
765efa325e [wpimath] Remove redundant column index from vectors (#4116)
89ffcbbe41 [wpimath] Update TrapezoidProfile class name in comment (NFC) (#4107)
95ae23b0e7 [wpimath] Improve EKF numerical stability (#4093)
d5cb6fed67 [wpimath] Support zero cost entries in MakeCostMatrix() (#4100)
d0fef18378 [wpimath] Remove redundant `this.` from ExtendedKalmanFilter.java (#4115)
d640c0f41f [wpimath] Fix pose estimator local measurement standard deviation docs (NFC) (#4113)
a2fa5e3ff7 [wpilibc] BatterySim: Provide non-initializer list versions of Calculate (#4076)
a3eea9958e [hal] Add link to FRC CAN Spec (NFC) (#4086)
db27331d7b [wpilib] Update DifferentialDrive docs (NFC) (#4085)
fdfb31f164 [dlt] Export boolean[] values (#4082)
f93c3331b3 [wpigui] disable changing directory when initializing on MacOS (#4092)
ab7ac4fbb9 [build] Fix various warnings in cmake builds (#4081)
bc39a1a293 [wpilibc] Fix moved pneumatics objects not destructing properly (#4068)
2668130e70 [wpimath] Remove SwerveDrivePoseEstimator encoder reset warning (#4066)
d27ed3722b [ci] Set actions workflow concurrency (#4060)
dae18308c9 [wpimath] Minor fixes to Rotation2d docs (NFC) (#4055)
d66555e42f [datalogtool] Add datalogtool
9f52d8a3b1 [wpilib] DriverStation: Add DataLog support for modes and joystick data
757ea91932 [wpilib] Add DataLogManager
02a804f1c5 [ntcore] Add DataLog support
9b500df0d9 [wpiutil] Add high speed data logging
5a89575b3a [wpiutil] Import customized LLVM MemoryBuffer
b8c4d7527b [wpiutil] Add MappedFileRegion
ac5d46cfa7 [wpilibc] Fix ProfiledPID SetTolerance default velocity value (#4054)
bc9e96e86f [wpilib] Absolute Encoder API and behavior fixes (#4052)
f88c435dd0 [hal] Add mechanism to cancel all periodic callbacks (#4049)
Change-Id: I49aa5b08abbefc7a045e99e19d48ce2cd8fc4d1b
git-subtree-dir: third_party/allwpilib
git-subtree-split: 83f1860047c86aa3330fcb41caf3b2047e074804
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/wpilibjExamples/build.gradle b/wpilibjExamples/build.gradle
index 7d74e80..deb8af1 100644
--- a/wpilibjExamples/build.gradle
+++ b/wpilibjExamples/build.gradle
@@ -21,20 +21,20 @@
finalizedBy jacocoTestReport
}
-if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxraspbian') || project.hasProperty('onlylinuxaarch64bionic')) {
+if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxarm32') || project.hasProperty('onlylinuxarm64')) {
test.enabled = false
}
dependencies {
implementation project(':wpilibj')
-
+ implementation project(':apriltag')
implementation project(':wpimath')
implementation project(':hal')
implementation project(':wpiutil')
+ implementation project(':wpinet')
implementation project(':ntcore')
implementation project(':cscore')
implementation project(':cameraserver')
- implementation project(':wpilibOldCommands')
implementation project(':wpilibNewCommands')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
@@ -43,7 +43,7 @@
}
jacoco {
- toolVersion = "0.8.7"
+ toolVersion = "0.8.8"
}
jacocoTestReport {
@@ -108,17 +108,20 @@
}
binaries.all { binary ->
lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
+ lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
- lib project: ':wpimath', library: 'wpimathJNI', linkage: 'shared'
- lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
+ lib project: ':wpimath', library: 'wpimathJNIShared', linkage: 'shared'
+ project(':ntcore').addNtcoreDependency(binary, 'shared')
+ project(':ntcore').addNtcoreJniDependency(binary)
lib project: ':cscore', library: 'cscore', linkage: 'shared'
- lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared'
lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared'
project(':hal').addHalDependency(binary, 'shared')
project(':hal').addHalJniDependency(binary)
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
- lib project: ':wpiutil', library: 'wpiutilJNI', linkage: 'shared'
+ lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
+ lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
+ lib project: ':wpinet', library: 'wpinetJNIShared', linkage: 'shared'
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
@@ -172,8 +175,9 @@
new groovy.json.JsonSlurper().parseText(exampleFile.text).each { entry ->
project.tasks.create("run${entry.foldername}", JavaExec) { run ->
- mainClass = "edu.wpi.first.wpilibj.examples." + entry.foldername + ".Main"
- classpath = sourceSets.main.runtimeClasspath
+ run.group "run examples"
+ run.mainClass = "edu.wpi.first.wpilibj.examples." + entry.foldername + "." + entry.mainclass
+ run.classpath = sourceSets.main.runtimeClasspath
run.dependsOn it.tasks.install
run.systemProperty 'java.library.path', filePath
run.environment 'LD_LIBRARY_PATH', filePath
@@ -184,6 +188,25 @@
run.jvmArgs = ['-XstartOnFirstThread']
}
}
+ project.tasks.create("test${entry.foldername}", Test) { testTask ->
+ testTask.group "verification"
+ testTask.useJUnitPlatform()
+ testTask.filter {
+ includeTestsMatching("edu.wpi.first.wpilibj.examples.${entry.foldername}.*")
+ setFailOnNoMatchingTests(false)
+ }
+ testTask.classpath = sourceSets.test.runtimeClasspath
+ testTask.dependsOn it.tasks.install
+
+ testTask.systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
+ testTask.testLogging {
+ events "failed"
+ exceptionFormat "full"
+ }
+ testTask.systemProperty 'java.library.path', filePath
+ testTask.environment 'LD_LIBRARY_PATH', filePath
+ testTask.workingDir filePath
+ }
}
found = true
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java
deleted file mode 100644
index 5ca1ca1..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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.wpilibj.commands.command;
-
-import edu.wpi.first.wpilibj.command.Command;
-
-public class ReplaceMeCommand extends Command {
- public ReplaceMeCommand() {
- // Use requires() here to declare subsystem dependencies
- // eg. requires(chassis);
- }
-
- // Called just before this Command runs the first time
- @Override
- protected void initialize() {}
-
- // Called repeatedly when this Command is scheduled to run
- @Override
- protected void execute() {}
-
- // Make this return true when this Command no longer needs to run execute()
- @Override
- protected boolean isFinished() {
- return false;
- }
-
- // Called once after isFinished returns true
- @Override
- protected void end() {}
-
- // Called when another command which requires one or more of the same
- // subsystems is scheduled to run
- @Override
- protected void interrupted() {}
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commandgroup/ReplaceMeCommandGroup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commandgroup/ReplaceMeCommandGroup.java
deleted file mode 100644
index ba8e273..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commandgroup/ReplaceMeCommandGroup.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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.wpilibj.commands.commandgroup;
-
-import edu.wpi.first.wpilibj.command.CommandGroup;
-
-public class ReplaceMeCommandGroup extends CommandGroup {
- /** Add your docs here. */
- public ReplaceMeCommandGroup() {
- // Add Commands here:
- // e.g. addSequential(new Command1());
- // addSequential(new Command2());
- // these will run in order.
-
- // To run multiple commands at the same time,
- // use addParallel()
- // e.g. addParallel(new Command1());
- // addSequential(new Command2());
- // Command1 and Command2 will run in parallel.
-
- // A command group will require all of the subsystems that each member
- // would require.
- // e.g. if Command1 requires chassis, and Command2 requires arm,
- // a CommandGroup containing them would require both the chassis and the
- // arm.
- }
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json
index 8165a3c..f6f2c37 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json
@@ -10,78 +10,7 @@
"commandversion": 0
},
{
- "name": "Command (Old)",
- "description": "Create a base command",
- "tags": [
- "command"
- ],
- "foldername": "command",
- "replacename": "ReplaceMeCommand",
- "commandversion": 1
- },
- {
- "name": "Command Group (Old)",
- "description": "Create a command group",
- "tags": [
- "commandgroup"
- ],
- "foldername": "commandgroup",
- "replacename": "ReplaceMeCommandGroup",
- "commandversion": 1
- },
- {
- "name": "Instant Command (Old)",
- "description": "A command that runs immediately",
- "tags": [
- "instantcommand"
- ],
- "foldername": "instant",
- "replacename": "ReplaceMeInstantCommand",
- "commandversion": 1
- },
- {
- "name": "Subsystem (Old)",
- "description": "A subsystem",
- "tags": [
- "subsystem"
- ],
- "foldername": "subsystem",
- "replacename": "ReplaceMeSubsystem",
- "commandversion": 1
- },
- {
- "name": "PID Subsystem (Old)",
- "description": "A subsystem that runs a PID loop",
- "tags": [
- "pidsubsystem",
- "pid"
- ],
- "foldername": "pidsubsystem",
- "replacename": "ReplaceMePIDSubsystem",
- "commandversion": 1
- },
- {
- "name": "Timed Command (Old)",
- "description": "A command that runs for a specified time",
- "tags": [
- "timedcommand"
- ],
- "foldername": "timed",
- "replacename": "ReplaceMeTimedCommand",
- "commandversion": 1
- },
- {
- "name": "Trigger (Old)",
- "description": "A command that runs off of a trigger",
- "tags": [
- "trigger"
- ],
- "foldername": "trigger",
- "replacename": "ReplaceMeTrigger",
- "commandversion": 1
- },
- {
- "name": "Command (New)",
+ "name": "Command",
"description": "A command.",
"tags": [
"command"
@@ -91,7 +20,7 @@
"commandversion": 2
},
{
- "name": "InstantCommand (New)",
+ "name": "InstantCommand",
"description": "A command that finishes instantly.",
"tags": [
"instantcommand"
@@ -101,7 +30,7 @@
"commandversion": 2
},
{
- "name": "ParallelCommandGroup (New)",
+ "name": "ParallelCommandGroup",
"description": "A command group that runs commands in parallel, ending when all commands have finished.",
"tags": [
"parallelcommandgroup"
@@ -111,7 +40,7 @@
"commandversion": 2
},
{
- "name": "ParallelDeadlineGroup (New)",
+ "name": "ParallelDeadlineGroup",
"description": "A command group that runs commands in parallel, ending when a specific command has finished.",
"tags": [
"paralleldeadlinegroup"
@@ -121,7 +50,7 @@
"commandversion": 2
},
{
- "name": "ParallelRaceGroup (New)",
+ "name": "ParallelRaceGroup",
"description": "A command that runs commands in parallel, ending as soon as any command has finished.",
"tags": [
"parallelracegroup"
@@ -131,7 +60,7 @@
"commandversion": 2
},
{
- "name": "PIDCommand (New)",
+ "name": "PIDCommand",
"description": "A command that runs a PIDController.",
"tags": [
"pidcommand"
@@ -141,7 +70,7 @@
"commandversion": 2
},
{
- "name": "PIDSubsystem (New)",
+ "name": "PIDSubsystem",
"description": "A subsystem that runs a PIDController.",
"tags": [
"pidsubsystem"
@@ -151,7 +80,7 @@
"commandversion": 2
},
{
- "name": "ProfiledPIDCommand (New)",
+ "name": "ProfiledPIDCommand",
"description": "A command that runs a ProfiledPIDController.",
"tags": [
"profiledpidcommand"
@@ -161,7 +90,7 @@
"commandversion": 2
},
{
- "name": "ProfiledPIDSubsystem (New)",
+ "name": "ProfiledPIDSubsystem",
"description": "A subsystem that runs a ProfiledPIDController.",
"tags": [
"profiledpidsubsystem"
@@ -171,7 +100,7 @@
"commandversion": 2
},
{
- "name": "SequentialCommandGroup (New)",
+ "name": "SequentialCommandGroup",
"description": "A command group that runs commands in sequence.",
"tags": [
"sequentialcommandgroup"
@@ -181,7 +110,7 @@
"commandversion": 2
},
{
- "name": "Subsystem (New)",
+ "name": "Subsystem",
"description": "A robot subsystem.",
"tags": [
"subsystem"
@@ -191,7 +120,7 @@
"commandversion": 2
},
{
- "name": "TrapezoidProfileCommand (New)",
+ "name": "TrapezoidProfileCommand",
"description": "A command that executes a trapezoidal motion profile.",
"tags": [
"trapezoidprofilecommand"
@@ -201,7 +130,7 @@
"commandversion": 2
},
{
- "name": "TrapezoidProfileSubsystem (New)",
+ "name": "TrapezoidProfileSubsystem",
"description": "A subystem that executes a trapezoidal motion profile.",
"tags": [
"trapezoidprofilesubsystem"
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instant/ReplaceMeInstantCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instant/ReplaceMeInstantCommand.java
deleted file mode 100644
index 769b595..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instant/ReplaceMeInstantCommand.java
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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.wpilibj.commands.instant;
-
-import edu.wpi.first.wpilibj.command.InstantCommand;
-
-/** Add your docs here. */
-public class ReplaceMeInstantCommand extends InstantCommand {
- /** Add your docs here. */
- public ReplaceMeInstantCommand() {
- super();
- // Use requires() here to declare subsystem dependencies
- // eg. requires(chassis);
- }
-
- // Called once when the command executes
- @Override
- protected void initialize() {}
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem/ReplaceMePIDSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem/ReplaceMePIDSubsystem.java
deleted file mode 100644
index 01e7987..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem/ReplaceMePIDSubsystem.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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.wpilibj.commands.pidsubsystem;
-
-import edu.wpi.first.wpilibj.command.PIDSubsystem;
-
-/** Add your docs here. */
-public class ReplaceMePIDSubsystem extends PIDSubsystem {
- /** Add your docs here. */
- public ReplaceMePIDSubsystem() {
- // Intert a subsystem name and PID values here
- super("SubsystemName", 1, 2, 3);
- // Use these to get going:
- // setSetpoint() - Sets where the PID controller should move the system
- // to
- // enable() - Enables the PID controller.
- }
-
- @Override
- public void initDefaultCommand() {
- // Set the default command for a subsystem here.
- // setDefaultCommand(new MySpecialCommand());
- }
-
- @Override
- protected double returnPIDInput() {
- // Return your input value for the PID loop
- // e.g. a sensor, like a potentiometer:
- // yourPot.getAverageVoltage() / kYourMaxVoltage;
- return 0.0;
- }
-
- @Override
- protected void usePIDOutput(double output) {
- // Use output to drive your system, like a motor
- // e.g. yourMotor.set(output);
- }
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem/ReplaceMeSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem/ReplaceMeSubsystem.java
deleted file mode 100644
index 671daf1..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem/ReplaceMeSubsystem.java
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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.wpilibj.commands.subsystem;
-
-import edu.wpi.first.wpilibj.command.Subsystem;
-
-/** Add your docs here. */
-public class ReplaceMeSubsystem extends Subsystem {
- // Put methods for controlling this subsystem
- // here. Call these from Commands.
-
- @Override
- public void initDefaultCommand() {
- // Set the default command for a subsystem here.
- // setDefaultCommand(new MySpecialCommand());
- }
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/timed/ReplaceMeTimedCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/timed/ReplaceMeTimedCommand.java
deleted file mode 100644
index 6021382..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/timed/ReplaceMeTimedCommand.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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.wpilibj.commands.timed;
-
-import edu.wpi.first.wpilibj.command.TimedCommand;
-
-/** Add your docs here. */
-public class ReplaceMeTimedCommand extends TimedCommand {
- /** Add your docs here. */
- public ReplaceMeTimedCommand(double timeout) {
- super(timeout);
- // Use requires() here to declare subsystem dependencies
- // eg. requires(chassis);
- }
-
- // Called just before this Command runs the first time
- @Override
- protected void initialize() {}
-
- // Called repeatedly when this Command is scheduled to run
- @Override
- protected void execute() {}
-
- // Called once after timeout
- @Override
- protected void end() {}
-
- // Called when another command which requires one or more of the same
- // subsystems is scheduled to run
- @Override
- protected void interrupted() {}
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trigger/ReplaceMeTrigger.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trigger/ReplaceMeTrigger.java
deleted file mode 100644
index c1343d9..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trigger/ReplaceMeTrigger.java
+++ /dev/null
@@ -1,15 +0,0 @@
-// 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.wpilibj.commands.trigger;
-
-import edu.wpi.first.wpilibj.buttons.Trigger;
-
-/** Add your docs here. */
-public class ReplaceMeTrigger extends Trigger {
- @Override
- public boolean get() {
- return false;
- }
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java
index 5eef7e8..45333a5 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java
@@ -32,6 +32,6 @@
// Drive with arcade drive.
// That means that the Y axis drives forward
// and backward, and the X turns left and right.
- m_robotDrive.arcadeDrive(-m_stick.getY(), m_stick.getX());
+ m_robotDrive.arcadeDrive(-m_stick.getY(), -m_stick.getX());
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java
index 656165a..aa0f9a2 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java
@@ -32,6 +32,6 @@
// Drive with split arcade drive.
// That means that the Y axis of the left stick moves forward
// and backward, and the X of the right stick turns left and right.
- m_robotDrive.arcadeDrive(-m_driverController.getLeftY(), m_driverController.getRightX());
+ m_robotDrive.arcadeDrive(-m_driverController.getLeftY(), -m_driverController.getRightX());
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/RobotContainer.java
index 4717d51..1875d64 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/RobotContainer.java
@@ -4,15 +4,13 @@
package edu.wpi.first.wpilibj.examples.armbot;
-import static edu.wpi.first.wpilibj.XboxController.Button;
-
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.examples.armbot.Constants.OIConstants;
import edu.wpi.first.wpilibj.examples.armbot.subsystems.ArmSubsystem;
import edu.wpi.first.wpilibj.examples.armbot.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
-import edu.wpi.first.wpilibj2.command.InstantCommand;
-import edu.wpi.first.wpilibj2.command.RunCommand;
+import edu.wpi.first.wpilibj2.command.Commands;
+import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
/**
@@ -27,7 +25,8 @@
private final ArmSubsystem m_robotArm = new ArmSubsystem();
// The driver's controller
- XboxController m_driverController = new XboxController(OIConstants.kDriverControllerPort);
+ CommandXboxController m_driverController =
+ new CommandXboxController(OIConstants.kDriverControllerPort);
/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
@@ -39,10 +38,10 @@
m_robotDrive.setDefaultCommand(
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
- new RunCommand(
+ Commands.run(
() ->
m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
+ -m_driverController.getLeftY(), -m_driverController.getRightX()),
m_robotDrive));
}
@@ -54,30 +53,35 @@
*/
private void configureButtonBindings() {
// Move the arm to 2 radians above horizontal when the 'A' button is pressed.
- new JoystickButton(m_driverController, Button.kA.value)
- .whenPressed(
- () -> {
- m_robotArm.setGoal(2);
- m_robotArm.enable();
- },
- m_robotArm);
+ m_driverController
+ .a()
+ .onTrue(
+ Commands.runOnce(
+ () -> {
+ m_robotArm.setGoal(2);
+ m_robotArm.enable();
+ },
+ m_robotArm));
// Move the arm to neutral position when the 'B' button is pressed.
- new JoystickButton(m_driverController, Button.kB.value)
- .whenPressed(
- () -> {
- m_robotArm.setGoal(Constants.ArmConstants.kArmOffsetRads);
- m_robotArm.enable();
- },
- m_robotArm);
+ m_driverController
+ .b()
+ .onTrue(
+ Commands.runOnce(
+ () -> {
+ m_robotArm.setGoal(Constants.ArmConstants.kArmOffsetRads);
+ m_robotArm.enable();
+ },
+ m_robotArm));
// Disable the arm controller when Y is pressed.
- new JoystickButton(m_driverController, Button.kY.value).whenPressed(m_robotArm::disable);
+ m_driverController.y().onTrue(Commands.runOnce(m_robotArm::disable));
// Drive at half speed when the bumper is held
- new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ m_driverController
+ .rightBumper()
+ .onTrue(Commands.runOnce(() -> m_robotDrive.setMaxOutput(0.5)))
+ .onFalse(Commands.runOnce(() -> m_robotDrive.setMaxOutput(1.0)));
}
/**
@@ -94,6 +98,6 @@
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
- return new InstantCommand();
+ return Commands.none();
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/RobotContainer.java
index 7ea7999..03f775c 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/RobotContainer.java
@@ -4,15 +4,13 @@
package edu.wpi.first.wpilibj.examples.armbotoffboard;
-import static edu.wpi.first.wpilibj.XboxController.Button;
-
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.examples.armbotoffboard.Constants.OIConstants;
import edu.wpi.first.wpilibj.examples.armbotoffboard.subsystems.ArmSubsystem;
import edu.wpi.first.wpilibj.examples.armbotoffboard.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
-import edu.wpi.first.wpilibj2.command.InstantCommand;
-import edu.wpi.first.wpilibj2.command.RunCommand;
+import edu.wpi.first.wpilibj2.command.Commands;
+import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
/**
@@ -27,7 +25,8 @@
private final ArmSubsystem m_robotArm = new ArmSubsystem();
// The driver's controller
- XboxController m_driverController = new XboxController(OIConstants.kDriverControllerPort);
+ CommandXboxController m_driverController =
+ new CommandXboxController(OIConstants.kDriverControllerPort);
/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
@@ -39,11 +38,8 @@
m_robotDrive.setDefaultCommand(
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
- new RunCommand(
- () ->
- m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
- m_robotDrive));
+ m_robotDrive.arcadeDriveCommand(
+ () -> -m_driverController.getLeftY(), () -> -m_driverController.getRightX()));
}
/**
@@ -54,17 +50,18 @@
*/
private void configureButtonBindings() {
// Move the arm to 2 radians above horizontal when the 'A' button is pressed.
- new JoystickButton(m_driverController, Button.kA.value)
- .whenPressed(() -> m_robotArm.setGoal(2), m_robotArm);
+ m_driverController.a().onTrue(m_robotArm.setArmGoalCommand(2));
// Move the arm to neutral position when the 'B' button is pressed.
- new JoystickButton(m_driverController, Button.kB.value)
- .whenPressed(() -> m_robotArm.setGoal(Constants.ArmConstants.kArmOffsetRads), m_robotArm);
+ m_driverController
+ .b()
+ .onTrue(m_robotArm.setArmGoalCommand(Constants.ArmConstants.kArmOffsetRads));
// Drive at half speed when the bumper is held
- new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ m_driverController
+ .rightBumper()
+ .onTrue(m_robotDrive.limitOutputCommand(0.5))
+ .onFalse(m_robotDrive.limitOutputCommand(1));
}
/**
@@ -73,6 +70,6 @@
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
- return new InstantCommand();
+ return Commands.none();
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java
index 9e70402..e083484 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java
@@ -8,6 +8,8 @@
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.examples.armbotoffboard.Constants.ArmConstants;
import edu.wpi.first.wpilibj.examples.armbotoffboard.ExampleSmartMotorController;
+import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.TrapezoidProfileSubsystem;
/** A robot arm subsystem that moves with a motion profile. */
@@ -36,4 +38,8 @@
m_motor.setSetpoint(
ExampleSmartMotorController.PIDMode.kPosition, setpoint.position, feedforward / 12.0);
}
+
+ public Command setArmGoalCommand(double kArmOffsetRads) {
+ return Commands.runOnce(() -> setGoal(kArmOffsetRads), this);
+ }
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java
index 939bcc3..e3c9159 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java
@@ -9,7 +9,10 @@
import edu.wpi.first.wpilibj.examples.armbotoffboard.Constants.DriveConstants;
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
+import java.util.function.DoubleSupplier;
public class DriveSubsystem extends SubsystemBase {
// The motors on the left side of the drive.
@@ -54,13 +57,14 @@
}
/**
- * Drives the robot using arcade controls.
+ * A split-stick arcade command, with forward/backward controlled by the left hand, and turning
+ * controlled by the right.
*
- * @param fwd the commanded forward movement
- * @param rot the commanded rotation
+ * @param fwd supplier for the commanded forward movement
+ * @param rot supplier for the commanded rotation
*/
- public void arcadeDrive(double fwd, double rot) {
- m_drive.arcadeDrive(fwd, rot);
+ public Command arcadeDriveCommand(DoubleSupplier fwd, DoubleSupplier rot) {
+ return Commands.run(() -> m_drive.arcadeDrive(fwd.getAsDouble(), rot.getAsDouble()), this);
}
/** Resets the drive encoders to currently read a position of 0. */
@@ -101,7 +105,7 @@
*
* @param maxOutput the maximum output to which the drive will be constrained
*/
- public void setMaxOutput(double maxOutput) {
- m_drive.setMaxOutput(maxOutput);
+ public Command limitOutputCommand(double maxOutput) {
+ return Commands.runOnce(() -> m_drive.setMaxOutput(maxOutput));
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java
index 1d5e24f..e2b699d 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java
@@ -16,23 +16,40 @@
private final PowerDistribution m_pdp = new PowerDistribution();
@Override
+ public void robotInit() {
+ // Put the PDP itself to the dashboard
+ SmartDashboard.putData("PDP", m_pdp);
+ }
+
+ @Override
public void robotPeriodic() {
- /*
- * Get the current going through channel 7, in Amperes. The PDP returns the
- * current in increments of 0.125A. At low currents
- * the current readings tend to be less accurate.
- */
- SmartDashboard.putNumber("Current Channel 7", m_pdp.getCurrent(7));
+ // Get the current going through channel 7, in Amperes.
+ // The PDP returns the current in increments of 0.125A.
+ // At low currents the current readings tend to be less accurate.
+ double current7 = m_pdp.getCurrent(7);
+ SmartDashboard.putNumber("Current Channel 7", current7);
- /*
- * Get the voltage going into the PDP, in Volts.
- * The PDP returns the voltage in increments of 0.05 Volts.
- */
- SmartDashboard.putNumber("Voltage", m_pdp.getVoltage());
+ // Get the voltage going into the PDP, in Volts.
+ // The PDP returns the voltage in increments of 0.05 Volts.
+ double voltage = m_pdp.getVoltage();
+ SmartDashboard.putNumber("Voltage", voltage);
- /*
- * Retrieves the temperature of the PDP, in degrees Celsius.
- */
- SmartDashboard.putNumber("Temperature", m_pdp.getTemperature());
+ // Retrieves the temperature of the PDP, in degrees Celsius.
+ double temperatureCelsius = m_pdp.getTemperature();
+ SmartDashboard.putNumber("Temperature", temperatureCelsius);
+
+ // Get the total current of all channels.
+ double totalCurrent = m_pdp.getTotalCurrent();
+ SmartDashboard.putNumber("Total Current", totalCurrent);
+
+ // Get the total power of all channels.
+ // Power is the bus voltage multiplied by the current with the units Watts.
+ double totalPower = m_pdp.getTotalPower();
+ SmartDashboard.putNumber("Total Power", totalPower);
+
+ // Get the total energy of all channels.
+ // Energy is the power summed over time with units Joules.
+ double totalEnergy = m_pdp.getTotalEnergy();
+ SmartDashboard.putNumber("Total Energy", totalEnergy);
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java
index 07b4881..8b4734a 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java
@@ -72,7 +72,9 @@
m_leftEncoder.reset();
m_rightEncoder.reset();
- m_odometry = new DifferentialDriveOdometry(m_gyro.getRotation2d());
+ m_odometry =
+ new DifferentialDriveOdometry(
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance());
}
/**
@@ -98,7 +100,6 @@
* @param xSpeed Linear velocity in m/s.
* @param rot Angular velocity in rad/s.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double rot) {
var wheelSpeeds = m_kinematics.toWheelSpeeds(new ChassisSpeeds(xSpeed, 0.0, rot));
setSpeeds(wheelSpeeds);
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java
index 3b5d9e2..1b1808e 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java
@@ -54,10 +54,12 @@
numbers used below are robot specific, and should be tuned. */
private final DifferentialDrivePoseEstimator m_poseEstimator =
new DifferentialDrivePoseEstimator(
+ m_kinematics,
m_gyro.getRotation2d(),
+ m_leftEncoder.getDistance(),
+ m_rightEncoder.getDistance(),
new Pose2d(),
- VecBuilder.fill(0.05, 0.05, Units.degreesToRadians(5), 0.01, 0.01),
- VecBuilder.fill(0.02, 0.02, Units.degreesToRadians(1)),
+ VecBuilder.fill(0.05, 0.05, Units.degreesToRadians(5)),
VecBuilder.fill(0.5, 0.5, Units.degreesToRadians(30)));
// Gains are for example purposes only - must be determined for your own robot!
@@ -108,7 +110,6 @@
* @param xSpeed Linear velocity in m/s.
* @param rot Angular velocity in rad/s.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double rot) {
var wheelSpeeds = m_kinematics.toWheelSpeeds(new ChassisSpeeds(xSpeed, 0.0, rot));
setSpeeds(wheelSpeeds);
@@ -117,10 +118,7 @@
/** Updates the field-relative position. */
public void updateOdometry() {
m_poseEstimator.update(
- m_gyro.getRotation2d(),
- new DifferentialDriveWheelSpeeds(m_leftEncoder.getRate(), m_rightEncoder.getRate()),
- m_leftEncoder.getDistance(),
- m_rightEncoder.getDistance());
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance());
// Also apply vision measurements. We use 0.3 seconds in the past as an example -- on
// a real robot, this must be calculated based either on latency or timestamps.
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java
index cc39207..6bc4b13 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java
@@ -4,8 +4,6 @@
package edu.wpi.first.wpilibj.examples.drivedistanceoffboard;
-import static edu.wpi.first.wpilibj.XboxController.Button;
-
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.Constants.DriveConstants;
@@ -13,10 +11,9 @@
import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.commands.DriveDistanceProfiled;
import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
-import edu.wpi.first.wpilibj2.command.InstantCommand;
-import edu.wpi.first.wpilibj2.command.RunCommand;
+import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.TrapezoidProfileCommand;
-import edu.wpi.first.wpilibj2.command.button.JoystickButton;
+import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
@@ -28,8 +25,13 @@
// The robot's subsystems
private final DriveSubsystem m_robotDrive = new DriveSubsystem();
+ // Retained command references
+ private final Command m_driveFullSpeed = Commands.runOnce(() -> m_robotDrive.setMaxOutput(1));
+ private final Command m_driveHalfSpeed = Commands.runOnce(() -> m_robotDrive.setMaxOutput(0.5));
+
// The driver's controller
- XboxController m_driverController = new XboxController(OIConstants.kDriverControllerPort);
+ CommandXboxController m_driverController =
+ new CommandXboxController(OIConstants.kDriverControllerPort);
/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
@@ -41,10 +43,10 @@
m_robotDrive.setDefaultCommand(
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
- new RunCommand(
+ Commands.run(
() ->
m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
+ -m_driverController.getLeftY(), -m_driverController.getRightX()),
m_robotDrive));
}
@@ -52,16 +54,19 @@
* Use this method to define your button->command mappings. Buttons can be created by
* instantiating a {@link edu.wpi.first.wpilibj.GenericHID} or one of its subclasses ({@link
* edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
- * JoystickButton}.
+ * edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {
+ // Drive at half speed when the bumper is held
+ m_driverController.rightBumper().onTrue(m_driveHalfSpeed).onFalse(m_driveFullSpeed);
+
// Drive forward by 3 meters when the 'A' button is pressed, with a timeout of 10 seconds
- new JoystickButton(m_driverController, Button.kA.value)
- .whenPressed(new DriveDistanceProfiled(3, m_robotDrive).withTimeout(10));
+ m_driverController.a().onTrue(new DriveDistanceProfiled(3, m_robotDrive).withTimeout(10));
// Do the same thing as above when the 'B' button is pressed, but defined inline
- new JoystickButton(m_driverController, Button.kB.value)
- .whenPressed(
+ m_driverController
+ .b()
+ .onTrue(
new TrapezoidProfileCommand(
new TrapezoidProfile(
// Limit the max acceleration and velocity
@@ -76,11 +81,6 @@
m_robotDrive)
.beforeStarting(m_robotDrive::resetEncoders)
.withTimeout(10));
-
- // Drive at half speed when the bumper is held
- new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
}
/**
@@ -89,6 +89,6 @@
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
- return new InstantCommand();
+ return Commands.none();
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java
index a12a6fd..bb99244 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleencoder/Robot.java
@@ -8,7 +8,6 @@
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
-@SuppressWarnings("PMD.SingularField")
public class Robot extends TimedRobot {
private DutyCycleEncoder m_dutyCycleEncoder;
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java
index 584fbc6..c7350b0 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/dutycycleinput/Robot.java
@@ -9,15 +9,12 @@
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
-@SuppressWarnings("PMD.SingularField")
public class Robot extends TimedRobot {
- private DigitalInput m_input;
private DutyCycle m_dutyCycle;
@Override
public void robotInit() {
- m_input = new DigitalInput(0);
- m_dutyCycle = new DutyCycle(m_input);
+ m_dutyCycle = new DutyCycle(new DigitalInput(0));
}
@Override
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java
index 3f2bae8..4bb6654 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java
@@ -59,6 +59,7 @@
kElevatorDrumRadius,
kMinElevatorHeight,
kMaxElevatorHeight,
+ true,
VecBuilder.fill(0.01));
private final EncoderSim m_encoderSim = new EncoderSim(m_encoder);
@@ -75,6 +76,8 @@
m_encoder.setDistancePerPulse(kElevatorEncoderDistPerPulse);
// Publish Mechanism2d to SmartDashboard
+ // To view the Elevator Sim in the simulator, select Network Tables -> SmartDashboard ->
+ // Elevator Sim
SmartDashboard.putData("Elevator Sim", m_mech2d);
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/eventloop/Main.java
similarity index 87%
copy from wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java
copy to wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/eventloop/Main.java
index 0ca48f6..d6f3150 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/eventloop/Main.java
@@ -2,9 +2,10 @@
// 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.wpilibj.examples.motorcontrolencoder;
+package edu.wpi.first.wpilibj.examples.eventloop;
import edu.wpi.first.wpilibj.RobotBase;
+import edu.wpi.first.wpilibj.examples.encoder.Robot;
/**
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/eventloop/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/eventloop/Robot.java
new file mode 100644
index 0000000..03c5577
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/eventloop/Robot.java
@@ -0,0 +1,92 @@
+// 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.wpilibj.examples.eventloop;
+
+import edu.wpi.first.math.controller.PIDController;
+import edu.wpi.first.math.controller.SimpleMotorFeedforward;
+import edu.wpi.first.wpilibj.Encoder;
+import edu.wpi.first.wpilibj.Joystick;
+import edu.wpi.first.wpilibj.TimedRobot;
+import edu.wpi.first.wpilibj.Ultrasonic;
+import edu.wpi.first.wpilibj.event.BooleanEvent;
+import edu.wpi.first.wpilibj.event.EventLoop;
+import edu.wpi.first.wpilibj.motorcontrol.MotorController;
+import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+
+public class Robot extends TimedRobot {
+ public static final int SHOT_VELOCITY = 200; // rpm
+ public static final int TOLERANCE = 8; // rpm
+ public static final int KICKER_THRESHOLD = 15; // mm
+
+ private final MotorController m_shooter = new PWMSparkMax(0);
+ private final Encoder m_shooterEncoder = new Encoder(0, 1);
+ private final PIDController m_controller = new PIDController(0.3, 0, 0);
+ private final SimpleMotorFeedforward m_ff = new SimpleMotorFeedforward(0.1, 0.065);
+
+ private final MotorController m_kicker = new PWMSparkMax(1);
+ private final Ultrasonic m_kickerSensor = new Ultrasonic(2, 3);
+
+ private final MotorController m_intake = new PWMSparkMax(2);
+
+ private final EventLoop m_loop = new EventLoop();
+ private final Joystick m_joystick = new Joystick(0);
+
+ @Override
+ public void robotInit() {
+ m_controller.setTolerance(TOLERANCE);
+
+ BooleanEvent isBallAtKicker =
+ new BooleanEvent(m_loop, () -> m_kickerSensor.getRangeMM() < KICKER_THRESHOLD);
+ BooleanEvent intakeButton = new BooleanEvent(m_loop, () -> m_joystick.getRawButton(2));
+
+ // if the thumb button is held
+ intakeButton
+ // and there is not a ball at the kicker
+ .and(isBallAtKicker.negate())
+ // activate the intake
+ .ifHigh(() -> m_intake.set(0.5));
+
+ // if the thumb button is not held
+ intakeButton
+ .negate()
+ // or there is a ball in the kicker
+ .or(isBallAtKicker)
+ // stop the intake
+ .ifHigh(m_intake::stopMotor);
+
+ BooleanEvent shootTrigger = new BooleanEvent(m_loop, m_joystick::getTrigger);
+
+ // if the trigger is held
+ shootTrigger
+ // accelerate the shooter wheel
+ .ifHigh(
+ () ->
+ m_shooter.setVoltage(
+ m_controller.calculate(m_shooterEncoder.getRate(), SHOT_VELOCITY)
+ + m_ff.calculate(SHOT_VELOCITY)));
+ // if not, stop
+ shootTrigger.negate().ifHigh(m_shooter::stopMotor);
+
+ BooleanEvent atTargetVelocity =
+ new BooleanEvent(m_loop, m_controller::atSetpoint)
+ // debounce for more stability
+ .debounce(0.2);
+
+ // if we're at the target velocity, kick the ball into the shooter wheel
+ atTargetVelocity.ifHigh(() -> m_kicker.set(0.7));
+
+ // when we stop being at the target velocity, it means the ball was shot
+ atTargetVelocity
+ .falling()
+ // so stop the kicker
+ .ifHigh(m_kicker::stopMotor);
+ }
+
+ @Override
+ public void robotPeriodic() {
+ // poll all the bindings
+ m_loop.poll();
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json
index ddf5d5e..01f79e7 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json
@@ -90,6 +90,17 @@
"commandversion": 2
},
{
+ "name": "EventLoop",
+ "description": "Demonstrate managing a ball system using EventLoop and BooleanEvent.",
+ "tags": [
+ "EventLoop"
+ ],
+ "foldername": "eventloop",
+ "gradlebase": "java",
+ "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
"name": "Relay",
"description": "Demonstrate controlling a Relay from Joystick buttons.",
"tags": [
@@ -218,20 +229,7 @@
"commandversion": 2
},
{
- "name": "Motor Controller",
- "description": "Demonstrate controlling a single motor with a joystick",
- "tags": [
- "Actuators",
- "Joystick",
- "Robot and Motor"
- ],
- "foldername": "motorcontrol",
- "gradlebase": "java",
- "mainclass": "Main",
- "commandversion": 2
- },
- {
- "name": "Motor Control With Encoder",
+ "name": "Motor Control",
"description": "Demonstrate controlling a single motor with a Joystick and displaying the net movement of the motor using an encoder.",
"tags": [
"Robot and Motor",
@@ -241,7 +239,7 @@
"Joystick",
"Complete List"
],
- "foldername": "motorcontrolencoder",
+ "foldername": "motorcontrol",
"gradlebase": "java",
"mainclass": "Main",
"commandversion": 2
@@ -330,6 +328,19 @@
"commandversion": 2
},
{
+ "name": "Rapid React Command Bot",
+ "description": "A fully-functional command-based fender bot for the 2022 game using the new command framework.",
+ "tags": [
+ "Complete robot",
+ "Command-based",
+ "Lambdas"
+ ],
+ "foldername": "rapidreactcommandbot",
+ "gradlebase": "java",
+ "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
"name": "Select Command Example",
"description": "An example showing how to use the SelectCommand class from the new command framework.",
"tags": [
@@ -710,6 +721,17 @@
"commandversion": 2
},
{
+ "name": "UnitTesting",
+ "description": "Demonstrates basic unit testing for a robot project.",
+ "tags": [
+ "Testing"
+ ],
+ "foldername": "unittest",
+ "gradlebase": "java",
+ "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
"name": "DifferentialDrivePoseEstimator",
"description": "Demonstrates the use of the DifferentialDrivePoseEstimator as a replacement for differential drive odometry.",
"tags": [
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/RobotContainer.java
index 1f00dd9..8e052bb 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/RobotContainer.java
@@ -4,20 +4,13 @@
package edu.wpi.first.wpilibj.examples.frisbeebot;
-import static edu.wpi.first.wpilibj.XboxController.Button;
-
-import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.examples.frisbeebot.Constants.AutoConstants;
import edu.wpi.first.wpilibj.examples.frisbeebot.Constants.OIConstants;
import edu.wpi.first.wpilibj.examples.frisbeebot.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj.examples.frisbeebot.subsystems.ShooterSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
-import edu.wpi.first.wpilibj2.command.ConditionalCommand;
-import edu.wpi.first.wpilibj2.command.InstantCommand;
-import edu.wpi.first.wpilibj2.command.RunCommand;
-import edu.wpi.first.wpilibj2.command.WaitCommand;
-import edu.wpi.first.wpilibj2.command.WaitUntilCommand;
-import edu.wpi.first.wpilibj2.command.button.JoystickButton;
+import edu.wpi.first.wpilibj2.command.Commands;
+import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
@@ -30,29 +23,34 @@
private final DriveSubsystem m_robotDrive = new DriveSubsystem();
private final ShooterSubsystem m_shooter = new ShooterSubsystem();
- // A simple autonomous routine that shoots the loaded frisbees
- private final Command m_autoCommand =
- // Start the command by spinning up the shooter...
- new InstantCommand(m_shooter::enable, m_shooter)
- .andThen(
+ private final Command m_spinUpShooter = Commands.runOnce(m_shooter::enable, m_shooter);
+ private final Command m_stopShooter = Commands.runOnce(m_shooter::disable, m_shooter);
+
+ // An autonomous routine that shoots the loaded frisbees
+ Command m_autonomousCommand =
+ Commands.sequence(
+ // Start the command by spinning up the shooter...
+ Commands.runOnce(m_shooter::enable, m_shooter),
// Wait until the shooter is at speed before feeding the frisbees
- new WaitUntilCommand(m_shooter::atSetpoint),
+ Commands.waitUntil(m_shooter::atSetpoint),
// Start running the feeder
- new InstantCommand(m_shooter::runFeeder, m_shooter),
+ Commands.runOnce(m_shooter::runFeeder, m_shooter),
// Shoot for the specified time
- new WaitCommand(AutoConstants.kAutoShootTimeSeconds))
- // Add a timeout (will end the command if, for instance, the shooter never gets up to
- // speed)
+ Commands.waitSeconds(AutoConstants.kAutoShootTimeSeconds))
+ // Add a timeout (will end the command if, for instance, the shooter
+ // never gets up to speed)
.withTimeout(AutoConstants.kAutoTimeoutSeconds)
// When the command ends, turn off the shooter and the feeder
.andThen(
- () -> {
- m_shooter.disable();
- m_shooter.stopFeeder();
- });
+ Commands.runOnce(
+ () -> {
+ m_shooter.disable();
+ m_shooter.stopFeeder();
+ }));
// The driver's controller
- XboxController m_driverController = new XboxController(OIConstants.kDriverControllerPort);
+ CommandXboxController m_driverController =
+ new CommandXboxController(OIConstants.kDriverControllerPort);
/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
@@ -64,45 +62,55 @@
m_robotDrive.setDefaultCommand(
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
- new RunCommand(
+ Commands.run(
() ->
m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
+ -m_driverController.getLeftY(), -m_driverController.getRightX()),
m_robotDrive));
}
/**
- * Use this method to define your button->command mappings. Buttons can be created by
- * instantiating a {@link edu.wpi.first.wpilibj.GenericHID} or one of its subclasses ({@link
- * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
- * edu.wpi.first.wpilibj2.command.button.JoystickButton}.
+ * Use this method to define your button->command mappings. Buttons can be created via the button
+ * factories on {@link edu.wpi.first.wpilibj2.command.button.CommandGenericHID} or one of its
+ * subclasses ({@link edu.wpi.first.wpilibj2.command.button.CommandJoystick} or {@link
+ * CommandXboxController}).
*/
private void configureButtonBindings() {
+ // Configure your button bindings here
+
+ // We can bind commands while retaining references to them in RobotContainer
+
// Spin up the shooter when the 'A' button is pressed
- new JoystickButton(m_driverController, Button.kA.value)
- .whenPressed(new InstantCommand(m_shooter::enable, m_shooter));
+ m_driverController.a().onTrue(m_spinUpShooter);
// Turn off the shooter when the 'B' button is pressed
- new JoystickButton(m_driverController, Button.kB.value)
- .whenPressed(new InstantCommand(m_shooter::disable, m_shooter));
+ m_driverController.b().onTrue(m_stopShooter);
- // Run the feeder when the 'X' button is held, but only if the shooter is at speed
- new JoystickButton(m_driverController, Button.kX.value)
- .whenPressed(
- new ConditionalCommand(
- // Run the feeder
- new InstantCommand(m_shooter::runFeeder, m_shooter),
- // Do nothing
- new InstantCommand(),
- // Determine which of the above to do based on whether the shooter has reached the
- // desired speed
- m_shooter::atSetpoint))
- .whenReleased(new InstantCommand(m_shooter::stopFeeder, m_shooter));
+ // We can also write them as temporary variables outside the bindings
- // Drive at half speed when the bumper is held
- new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ // Shoots if the shooter wheel has reached the target speed
+ Command shoot =
+ Commands.either(
+ // Run the feeder
+ Commands.runOnce(m_shooter::runFeeder, m_shooter),
+ // Do nothing
+ Commands.none(),
+ // Determine which of the above to do based on whether the shooter has reached the
+ // desired speed
+ m_shooter::atSetpoint);
+
+ Command stopFeeder = Commands.runOnce(m_shooter::stopFeeder, m_shooter);
+
+ // Shoot when the 'X' button is pressed
+ m_driverController.x().onTrue(shoot).onFalse(stopFeeder);
+
+ // We can also define commands inline at the binding!
+
+ // While holding the shoulder button, drive at half speed
+ m_driverController
+ .rightBumper()
+ .onTrue(Commands.runOnce(() -> m_robotDrive.setMaxOutput(0.5)))
+ .onFalse(Commands.runOnce(() -> m_robotDrive.setMaxOutput(1)));
}
/**
@@ -111,6 +119,6 @@
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
- return m_autoCommand;
+ return m_autonomousCommand;
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java
index e4c7412..47710f9 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java
@@ -58,7 +58,7 @@
// Assign default commands
m_drivetrain.setDefaultCommand(
- new TankDrive(m_joystick::getLeftY, m_joystick::getRightY, m_drivetrain));
+ new TankDrive(() -> -m_joystick.getLeftY(), () -> -m_joystick.getRightY(), m_drivetrain));
// Show what command your subsystem is running on the SmartDashboard
SmartDashboard.putData(m_drivetrain);
@@ -88,15 +88,15 @@
final JoystickButton r1 = new JoystickButton(m_joystick, 12);
// Connect the buttons to commands
- dpadUp.whenPressed(new SetElevatorSetpoint(0.25, m_elevator));
- dpadDown.whenPressed(new SetElevatorSetpoint(0.0, m_elevator));
- dpadRight.whenPressed(new CloseClaw(m_claw));
- dpadLeft.whenPressed(new OpenClaw(m_claw));
+ dpadUp.onTrue(new SetElevatorSetpoint(0.25, m_elevator));
+ dpadDown.onTrue(new SetElevatorSetpoint(0.0, m_elevator));
+ dpadRight.onTrue(new CloseClaw(m_claw));
+ dpadLeft.onTrue(new OpenClaw(m_claw));
- r1.whenPressed(new PrepareToPickup(m_claw, m_wrist, m_elevator));
- r2.whenPressed(new Pickup(m_claw, m_wrist, m_elevator));
- l1.whenPressed(new Place(m_claw, m_wrist, m_elevator));
- l2.whenPressed(new Autonomous(m_drivetrain, m_claw, m_wrist, m_elevator));
+ r1.onTrue(new PrepareToPickup(m_claw, m_wrist, m_elevator));
+ r2.onTrue(new Pickup(m_claw, m_wrist, m_elevator));
+ l1.onTrue(new Place(m_claw, m_wrist, m_elevator));
+ l2.onTrue(new Autonomous(m_drivetrain, m_claw, m_wrist, m_elevator));
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Autonomous.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Autonomous.java
index 599ed69..44a7ce7 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Autonomous.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Autonomous.java
@@ -8,6 +8,7 @@
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Drivetrain;
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Elevator;
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Wrist;
+import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
/** The main autonomous command to pickup and deliver the soda to the box. */
@@ -22,6 +23,6 @@
new Place(claw, wrist, elevator),
new SetDistanceToBox(0.60, drive),
// new DriveStraight(-2), // Use Encoders if ultrasonic is broken
- parallel(new SetWristSetpoint(-45, wrist), new CloseClaw(claw)));
+ Commands.parallel(new SetWristSetpoint(-45, wrist), new CloseClaw(claw)));
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Pickup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Pickup.java
index 4c7d267..4e6eafd 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Pickup.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/Pickup.java
@@ -7,6 +7,7 @@
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Claw;
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Elevator;
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Wrist;
+import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
/**
@@ -23,6 +24,7 @@
public Pickup(Claw claw, Wrist wrist, Elevator elevator) {
addCommands(
new CloseClaw(claw),
- parallel(new SetWristSetpoint(-45, wrist), new SetElevatorSetpoint(0.25, elevator)));
+ Commands.parallel(
+ new SetWristSetpoint(-45, wrist), new SetElevatorSetpoint(0.25, elevator)));
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/PrepareToPickup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/PrepareToPickup.java
index 1ae5992..3c0661d 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/PrepareToPickup.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/commands/PrepareToPickup.java
@@ -7,6 +7,7 @@
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Claw;
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Elevator;
import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Wrist;
+import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
/** Make sure the robot is in a state to pickup soda cans. */
@@ -21,6 +22,6 @@
public PrepareToPickup(Claw claw, Wrist wrist, Elevator elevator) {
addCommands(
new OpenClaw(claw),
- parallel(new SetWristSetpoint(0, wrist), new SetElevatorSetpoint(0, elevator)));
+ Commands.parallel(new SetWristSetpoint(0, wrist), new SetElevatorSetpoint(0, elevator)));
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java
index f9499f5..45094fa 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java
@@ -4,9 +4,9 @@
package edu.wpi.first.wpilibj.examples.gettingstarted;
-import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
+import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
@@ -20,7 +20,7 @@
private final PWMSparkMax m_leftDrive = new PWMSparkMax(0);
private final PWMSparkMax m_rightDrive = new PWMSparkMax(1);
private final DifferentialDrive m_robotDrive = new DifferentialDrive(m_leftDrive, m_rightDrive);
- private final Joystick m_stick = new Joystick(0);
+ private final XboxController m_controller = new XboxController(0);
private final Timer m_timer = new Timer();
/**
@@ -47,7 +47,8 @@
public void autonomousPeriodic() {
// Drive for 2 seconds
if (m_timer.get() < 2.0) {
- m_robotDrive.arcadeDrive(0.5, 0.0); // drive forwards half speed
+ // Drive forwards half speed, make sure to turn input squaring off
+ m_robotDrive.arcadeDrive(0.5, 0.0, false);
} else {
m_robotDrive.stopMotor(); // stop robot
}
@@ -60,7 +61,7 @@
/** This function is called periodically during teleoperated mode. */
@Override
public void teleopPeriodic() {
- m_robotDrive.arcadeDrive(m_stick.getY(), m_stick.getX());
+ m_robotDrive.arcadeDrive(-m_controller.getLeftY(), -m_controller.getRightX());
}
/** This function is called once each time the robot enters test mode. */
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java
index b0c6641..1f9e41d 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java
@@ -50,8 +50,6 @@
@Override
public void teleopPeriodic() {
double turningValue = (kAngleSetpoint - m_gyro.getAngle()) * kP;
- // Invert the direction of the turn if we are going backwards
- turningValue = Math.copySign(turningValue, m_joystick.getY());
- m_myRobot.arcadeDrive(-m_joystick.getY(), turningValue);
+ m_myRobot.arcadeDrive(-m_joystick.getY(), -turningValue);
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/RobotContainer.java
index b70f5bf..5caf497 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/RobotContainer.java
@@ -45,7 +45,7 @@
new RunCommand(
() ->
m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
+ -m_driverController.getLeftY(), -m_driverController.getRightX()),
m_robotDrive));
}
@@ -58,12 +58,12 @@
private void configureButtonBindings() {
// Drive at half speed when the right bumper is held
new JoystickButton(m_driverController, Button.kR1.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ .onTrue(new InstantCommand(() -> m_robotDrive.setMaxOutput(0.5)))
+ .onFalse(new InstantCommand(() -> m_robotDrive.setMaxOutput(1)));
// Stabilize robot to drive straight with gyro when left bumper is held
new JoystickButton(m_driverController, Button.kL1.value)
- .whenHeld(
+ .whileTrue(
new PIDCommand(
new PIDController(
DriveConstants.kStabilizationP,
@@ -80,11 +80,11 @@
// Turn to 90 degrees when the 'X' button is pressed, with a 5 second timeout
new JoystickButton(m_driverController, Button.kCross.value)
- .whenPressed(new TurnToAngle(90, m_robotDrive).withTimeout(5));
+ .onTrue(new TurnToAngle(90, m_robotDrive).withTimeout(5));
// Turn to -90 degrees with a profile when the Circle button is pressed, with a 5 second timeout
new JoystickButton(m_driverController, Button.kCircle.value)
- .whenPressed(new TurnToAngleProfiled(-90, m_robotDrive).withTimeout(5));
+ .onTrue(new TurnToAngleProfiled(-90, m_robotDrive).withTimeout(5));
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java
index 8b4391c..b86277b 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java
@@ -51,6 +51,6 @@
@Override
public void teleopPeriodic() {
m_robotDrive.driveCartesian(
- -m_joystick.getY(), m_joystick.getX(), m_joystick.getZ(), m_gyro.getAngle());
+ -m_joystick.getY(), -m_joystick.getX(), -m_joystick.getZ(), m_gyro.getRotation2d());
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java
index cda9e26..902ecbe 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java
@@ -4,21 +4,16 @@
package edu.wpi.first.wpilibj.examples.hatchbotinlined;
-import static edu.wpi.first.wpilibj.PS4Controller.Button;
-
import edu.wpi.first.wpilibj.PS4Controller;
-import edu.wpi.first.wpilibj.examples.hatchbotinlined.Constants.AutoConstants;
import edu.wpi.first.wpilibj.examples.hatchbotinlined.Constants.OIConstants;
-import edu.wpi.first.wpilibj.examples.hatchbotinlined.commands.ComplexAutoCommand;
+import edu.wpi.first.wpilibj.examples.hatchbotinlined.commands.Autos;
import edu.wpi.first.wpilibj.examples.hatchbotinlined.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj.examples.hatchbotinlined.subsystems.HatchSubsystem;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj2.command.Command;
-import edu.wpi.first.wpilibj2.command.FunctionalCommand;
-import edu.wpi.first.wpilibj2.command.InstantCommand;
-import edu.wpi.first.wpilibj2.command.RunCommand;
-import edu.wpi.first.wpilibj2.command.button.JoystickButton;
+import edu.wpi.first.wpilibj2.command.Commands;
+import edu.wpi.first.wpilibj2.command.button.CommandPS4Controller;
/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
@@ -31,30 +26,20 @@
private final DriveSubsystem m_robotDrive = new DriveSubsystem();
private final HatchSubsystem m_hatchSubsystem = new HatchSubsystem();
+ // Retained command handles
+
// The autonomous routines
-
// A simple auto routine that drives forward a specified distance, and then stops.
- private final Command m_simpleAuto =
- new FunctionalCommand(
- // Reset encoders on command start
- m_robotDrive::resetEncoders,
- // Drive forward while the command is executing
- () -> m_robotDrive.arcadeDrive(AutoConstants.kAutoDriveSpeed, 0),
- // Stop driving at the end of the command
- interrupt -> m_robotDrive.arcadeDrive(0, 0),
- // End the command when the robot's driven distance exceeds the desired value
- () -> m_robotDrive.getAverageEncoderDistance() >= AutoConstants.kAutoDriveDistanceInches,
- // Require the drive subsystem
- m_robotDrive);
-
+ private final Command m_simpleAuto = Autos.simpleAuto(m_robotDrive);
// A complex auto routine that drives forward, drops a hatch, and then drives backward.
- private final Command m_complexAuto = new ComplexAutoCommand(m_robotDrive, m_hatchSubsystem);
+ private final Command m_complexAuto = Autos.complexAuto(m_robotDrive, m_hatchSubsystem);
// A chooser for autonomous commands
SendableChooser<Command> m_chooser = new SendableChooser<>();
// The driver's controller
- PS4Controller m_driverController = new PS4Controller(OIConstants.kDriverControllerPort);
+ CommandPS4Controller m_driverController =
+ new CommandPS4Controller(OIConstants.kDriverControllerPort);
/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
@@ -66,10 +51,10 @@
m_robotDrive.setDefaultCommand(
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
- new RunCommand(
+ Commands.run(
() ->
m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
+ -m_driverController.getLeftY(), -m_driverController.getRightX()),
m_robotDrive));
// Add commands to the autonomous command chooser
@@ -88,15 +73,14 @@
*/
private void configureButtonBindings() {
// Grab the hatch when the Circle button is pressed.
- new JoystickButton(m_driverController, Button.kCircle.value)
- .whenPressed(new InstantCommand(m_hatchSubsystem::grabHatch, m_hatchSubsystem));
+ m_driverController.circle().onTrue(m_hatchSubsystem.grabHatchCommand());
// Release the hatch when the Square button is pressed.
- new JoystickButton(m_driverController, Button.kSquare.value)
- .whenPressed(new InstantCommand(m_hatchSubsystem::releaseHatch, m_hatchSubsystem));
+ m_driverController.square().onTrue(m_hatchSubsystem.releaseHatchCommand());
// While holding R1, drive at half speed
- new JoystickButton(m_driverController, Button.kR1.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ m_driverController
+ .R1()
+ .onTrue(Commands.runOnce(() -> m_robotDrive.setMaxOutput(0.5)))
+ .onFalse(Commands.runOnce(() -> m_robotDrive.setMaxOutput(1)));
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/commands/ComplexAutoCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/commands/Autos.java
similarity index 62%
rename from wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/commands/ComplexAutoCommand.java
rename to wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/commands/Autos.java
index 1faf45a..8af2735 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/commands/ComplexAutoCommand.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/commands/Autos.java
@@ -7,20 +7,30 @@
import edu.wpi.first.wpilibj.examples.hatchbotinlined.Constants.AutoConstants;
import edu.wpi.first.wpilibj.examples.hatchbotinlined.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj.examples.hatchbotinlined.subsystems.HatchSubsystem;
+import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
-import edu.wpi.first.wpilibj2.command.InstantCommand;
-import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
-/** A complex auto command that drives forward, releases a hatch, and then drives backward. */
-public class ComplexAutoCommand extends SequentialCommandGroup {
- /**
- * Creates a new ComplexAutoCommand.
- *
- * @param driveSubsystem The drive subsystem this command will run on
- * @param hatchSubsystem The hatch subsystem this command will run on
- */
- public ComplexAutoCommand(DriveSubsystem driveSubsystem, HatchSubsystem hatchSubsystem) {
- addCommands(
+/** Container for auto command factories. */
+public final class Autos {
+ /** A simple auto routine that drives forward a specified distance, and then stops. */
+ public static Command simpleAuto(DriveSubsystem drive) {
+ return new FunctionalCommand(
+ // Reset encoders on command start
+ drive::resetEncoders,
+ // Drive forward while the command is executing
+ () -> drive.arcadeDrive(AutoConstants.kAutoDriveSpeed, 0),
+ // Stop driving at the end of the command
+ interrupt -> drive.arcadeDrive(0, 0),
+ // End the command when the robot's driven distance exceeds the desired value
+ () -> drive.getAverageEncoderDistance() >= AutoConstants.kAutoDriveDistanceInches,
+ // Require the drive subsystem
+ drive);
+ }
+
+ /** A complex auto routine that drives forward, drops a hatch, and then drives backward. */
+ public static Command complexAuto(DriveSubsystem driveSubsystem, HatchSubsystem hatchSubsystem) {
+ return Commands.sequence(
// Drive forward up to the front of the cargo ship
new FunctionalCommand(
// Reset encoders on command start
@@ -37,7 +47,7 @@
driveSubsystem),
// Release the hatch
- new InstantCommand(hatchSubsystem::releaseHatch, hatchSubsystem),
+ hatchSubsystem.releaseHatchCommand(),
// Drive backward the specified distance
new FunctionalCommand(
@@ -54,4 +64,8 @@
// Require the drive subsystem
driveSubsystem));
}
+
+ private Autos() {
+ throw new UnsupportedOperationException("This is a utility class!");
+ }
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/HatchSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/HatchSubsystem.java
index fc508f3..b875f2c 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/HatchSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/HatchSubsystem.java
@@ -10,6 +10,7 @@
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.examples.hatchbotinlined.Constants.HatchConstants;
+import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
/** A hatch mechanism actuated by a single {@link edu.wpi.first.wpilibj.DoubleSolenoid}. */
@@ -21,12 +22,14 @@
HatchConstants.kHatchSolenoidPorts[1]);
/** Grabs the hatch. */
- public void grabHatch() {
- m_hatchSolenoid.set(kForward);
+ public CommandBase grabHatchCommand() {
+ // implicitly require `this`
+ return this.runOnce(() -> m_hatchSolenoid.set(kForward));
}
/** Releases the hatch. */
- public void releaseHatch() {
- m_hatchSolenoid.set(kReverse);
+ public CommandBase releaseHatchCommand() {
+ // implicitly require `this`
+ return this.runOnce(() -> m_hatchSolenoid.set(kReverse));
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java
index 1f1024f..19fc2c7 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java
@@ -60,7 +60,9 @@
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
new DefaultDrive(
- m_robotDrive, m_driverController::getLeftY, m_driverController::getRightX));
+ m_robotDrive,
+ () -> -m_driverController.getLeftY(),
+ () -> -m_driverController.getRightX()));
// Add commands to the autonomous command chooser
m_chooser.setDefaultOption("Simple Auto", m_simpleAuto);
@@ -78,14 +80,13 @@
*/
private void configureButtonBindings() {
// Grab the hatch when the 'A' button is pressed.
- new JoystickButton(m_driverController, Button.kA.value)
- .whenPressed(new GrabHatch(m_hatchSubsystem));
+ new JoystickButton(m_driverController, Button.kA.value).onTrue(new GrabHatch(m_hatchSubsystem));
// Release the hatch when the 'B' button is pressed.
new JoystickButton(m_driverController, Button.kB.value)
- .whenPressed(new ReleaseHatch(m_hatchSubsystem));
+ .onTrue(new ReleaseHatch(m_hatchSubsystem));
// While holding the shoulder button, drive at half speed
new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenHeld(new HalveDriveSpeed(m_robotDrive));
+ .whileTrue(new HalveDriveSpeed(m_robotDrive));
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java
index 9210265..8849598 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java
@@ -10,6 +10,7 @@
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
import edu.wpi.first.math.kinematics.MecanumDriveOdometry;
+import edu.wpi.first.math.kinematics.MecanumDriveWheelPositions;
import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
import edu.wpi.first.wpilibj.AnalogGyro;
import edu.wpi.first.wpilibj.Encoder;
@@ -48,7 +49,7 @@
m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation);
private final MecanumDriveOdometry m_odometry =
- new MecanumDriveOdometry(m_kinematics, m_gyro.getRotation2d());
+ new MecanumDriveOdometry(m_kinematics, m_gyro.getRotation2d(), getCurrentDistances());
// Gains are for example purposes only - must be determined for your own robot!
private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3);
@@ -77,6 +78,19 @@
}
/**
+ * Returns the current distances measured by the drivetrain.
+ *
+ * @return The current distances measured by the drivetrain.
+ */
+ public MecanumDriveWheelPositions getCurrentDistances() {
+ return new MecanumDriveWheelPositions(
+ m_frontLeftEncoder.getDistance(),
+ m_frontRightEncoder.getDistance(),
+ m_backLeftEncoder.getDistance(),
+ m_backRightEncoder.getDistance());
+ }
+
+ /**
* Set the desired speeds for each wheel.
*
* @param speeds The desired wheel speeds.
@@ -114,7 +128,6 @@
* @param rot Angular rate of the robot.
* @param fieldRelative Whether the provided x and y speeds are relative to the field.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double ySpeed, double rot, boolean fieldRelative) {
var mecanumDriveWheelSpeeds =
m_kinematics.toWheelSpeeds(
@@ -127,6 +140,6 @@
/** Updates the field relative position of the robot. */
public void updateOdometry() {
- m_odometry.update(m_gyro.getRotation2d(), getCurrentState());
+ m_odometry.update(m_gyro.getRotation2d(), getCurrentDistances());
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java
index 0d36a94..bab80b6 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java
@@ -19,6 +19,7 @@
import edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.Constants.OIConstants;
import edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.MecanumControllerCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
@@ -50,9 +51,9 @@
new RunCommand(
() ->
m_robotDrive.drive(
- m_driverController.getLeftY(),
- m_driverController.getRightX(),
- m_driverController.getLeftX(),
+ -m_driverController.getLeftY(),
+ -m_driverController.getRightX(),
+ -m_driverController.getLeftX(),
false),
m_robotDrive));
}
@@ -66,8 +67,8 @@
private void configureButtonBindings() {
// Drive at half speed when the right bumper is held
new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ .onTrue(new InstantCommand(() -> m_robotDrive.setMaxOutput(0.5)))
+ .onFalse(new InstantCommand(() -> m_robotDrive.setMaxOutput(1)));
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java
index 7874d82..50a23cd 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java
@@ -7,6 +7,7 @@
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.kinematics.MecanumDriveMotorVoltages;
import edu.wpi.first.math.kinematics.MecanumDriveOdometry;
+import edu.wpi.first.math.kinematics.MecanumDriveWheelPositions;
import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
import edu.wpi.first.wpilibj.ADXRS450_Gyro;
import edu.wpi.first.wpilibj.Encoder;
@@ -58,7 +59,10 @@
// Odometry class for tracking robot pose
MecanumDriveOdometry m_odometry =
- new MecanumDriveOdometry(DriveConstants.kDriveKinematics, m_gyro.getRotation2d());
+ new MecanumDriveOdometry(
+ DriveConstants.kDriveKinematics,
+ m_gyro.getRotation2d(),
+ new MecanumDriveWheelPositions());
/** Creates a new DriveSubsystem. */
public DriveSubsystem() {
@@ -77,13 +81,7 @@
@Override
public void periodic() {
// Update the odometry in the periodic block
- m_odometry.update(
- m_gyro.getRotation2d(),
- new MecanumDriveWheelSpeeds(
- m_frontLeftEncoder.getRate(),
- m_rearLeftEncoder.getRate(),
- m_frontRightEncoder.getRate(),
- m_rearRightEncoder.getRate()));
+ m_odometry.update(m_gyro.getRotation2d(), getCurrentWheelDistances());
}
/**
@@ -101,7 +99,7 @@
* @param pose The pose to which to set the odometry.
*/
public void resetOdometry(Pose2d pose) {
- m_odometry.resetPosition(pose, m_gyro.getRotation2d());
+ m_odometry.resetPosition(m_gyro.getRotation2d(), getCurrentWheelDistances(), pose);
}
/**
@@ -113,10 +111,9 @@
* @param rot Angular rate of the robot.
* @param fieldRelative Whether the provided x and y speeds are relative to the field.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double ySpeed, double rot, boolean fieldRelative) {
if (fieldRelative) {
- m_drive.driveCartesian(ySpeed, xSpeed, rot, -m_gyro.getAngle());
+ m_drive.driveCartesian(ySpeed, xSpeed, rot, m_gyro.getRotation2d());
} else {
m_drive.driveCartesian(ySpeed, xSpeed, rot);
}
@@ -188,6 +185,19 @@
}
/**
+ * Gets the current wheel distance measurements.
+ *
+ * @return the current wheel distance measurements in a MecanumDriveWheelPositions object.
+ */
+ public MecanumDriveWheelPositions getCurrentWheelDistances() {
+ return new MecanumDriveWheelPositions(
+ m_frontLeftEncoder.getDistance(),
+ m_rearLeftEncoder.getDistance(),
+ m_frontRightEncoder.getDistance(),
+ m_rearRightEncoder.getDistance());
+ }
+
+ /**
* Sets the max output of the drive. Useful for scaling the drive to drive more slowly.
*
* @param maxOutput the maximum output to which the drive will be constrained
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java
index 1029f0f..c681a86 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java
@@ -40,8 +40,8 @@
@Override
public void teleopPeriodic() {
- // Use the joystick X axis for lateral movement, Y axis for forward
+ // Use the joystick X axis for forward movement, Y axis for lateral
// movement, and Z axis for rotation.
- m_robotDrive.driveCartesian(-m_stick.getY(), m_stick.getX(), m_stick.getZ(), 0.0);
+ m_robotDrive.driveCartesian(-m_stick.getY(), -m_stick.getX(), -m_stick.getZ());
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java
index 427284f..299fe68 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java
@@ -12,6 +12,7 @@
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
+import edu.wpi.first.math.kinematics.MecanumDriveWheelPositions;
import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.AnalogGyro;
@@ -55,11 +56,11 @@
below are robot specific, and should be tuned. */
private final MecanumDrivePoseEstimator m_poseEstimator =
new MecanumDrivePoseEstimator(
- m_gyro.getRotation2d(),
- new Pose2d(),
m_kinematics,
+ m_gyro.getRotation2d(),
+ getCurrentDistances(),
+ new Pose2d(),
VecBuilder.fill(0.05, 0.05, Units.degreesToRadians(5)),
- VecBuilder.fill(Units.degreesToRadians(0.01)),
VecBuilder.fill(0.5, 0.5, Units.degreesToRadians(30)));
// Gains are for example purposes only - must be determined for your own robot!
@@ -89,6 +90,19 @@
}
/**
+ * Returns the current distances measured by the drivetrain.
+ *
+ * @return The current distances measured by the drivetrain.
+ */
+ public MecanumDriveWheelPositions getCurrentDistances() {
+ return new MecanumDriveWheelPositions(
+ m_frontLeftEncoder.getDistance(),
+ m_frontRightEncoder.getDistance(),
+ m_backLeftEncoder.getDistance(),
+ m_backRightEncoder.getDistance());
+ }
+
+ /**
* Set the desired speeds for each wheel.
*
* @param speeds The desired wheel speeds.
@@ -126,7 +140,6 @@
* @param rot Angular rate of the robot.
* @param fieldRelative Whether the provided x and y speeds are relative to the field.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double ySpeed, double rot, boolean fieldRelative) {
var mecanumDriveWheelSpeeds =
m_kinematics.toWheelSpeeds(
@@ -139,7 +152,7 @@
/** Updates the field relative position of the robot. */
public void updateOdometry() {
- m_poseEstimator.update(m_gyro.getRotation2d(), getCurrentState());
+ m_poseEstimator.update(m_gyro.getRotation2d(), getCurrentDistances());
// Also apply vision measurements. We use 0.3 seconds in the past as an example -- on
// a real robot, this must be calculated based either on latency or timestamps.
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java
index 9976381..82ced20 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java
@@ -4,29 +4,50 @@
package edu.wpi.first.wpilibj.examples.motorcontrol;
+import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* This sample program shows how to control a motor using a joystick. In the operator control part
* of the program, the joystick is read and the value is written to the motor.
*
- * <p>Joystick analog values range from -1 to 1 and speed controller inputs also range from -1 to 1
+ * <p>Joystick analog values range from -1 to 1 and motor controller inputs also range from -1 to 1
* making it easy to work together.
+ *
+ * <p>In addition, the encoder value of an encoder connected to ports 0 and 1 is consistently sent
+ * to the Dashboard.
*/
public class Robot extends TimedRobot {
private static final int kMotorPort = 0;
private static final int kJoystickPort = 0;
+ private static final int kEncoderPortA = 0;
+ private static final int kEncoderPortB = 1;
private MotorController m_motor;
private Joystick m_joystick;
+ private Encoder m_encoder;
@Override
public void robotInit() {
m_motor = new PWMSparkMax(kMotorPort);
m_joystick = new Joystick(kJoystickPort);
+ m_encoder = new Encoder(kEncoderPortA, kEncoderPortB);
+ // Use SetDistancePerPulse to set the multiplier for GetDistance
+ // This is set up assuming a 6 inch wheel with a 360 CPR encoder.
+ m_encoder.setDistancePerPulse((Math.PI * 6) / 360.0);
+ }
+
+ /*
+ * The RobotPeriodic function is called every control packet no matter the
+ * robot mode.
+ */
+ @Override
+ public void robotPeriodic() {
+ SmartDashboard.putNumber("Encoder", m_encoder.getDistance());
}
@Override
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Robot.java
deleted file mode 100644
index 9b68965..0000000
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Robot.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// 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.wpilibj.examples.motorcontrolencoder;
-
-import edu.wpi.first.wpilibj.Encoder;
-import edu.wpi.first.wpilibj.Joystick;
-import edu.wpi.first.wpilibj.TimedRobot;
-import edu.wpi.first.wpilibj.motorcontrol.MotorController;
-import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
-import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
-
-/**
- * This sample program shows how to control a motor using a joystick. In the operator control part
- * of the program, the joystick is read and the value is written to the motor.
- *
- * <p>Joystick analog values range from -1 to 1 and speed controller inputs also range from -1 to 1
- * making it easy to work together.
- *
- * <p>In addition, the encoder value of an encoder connected to ports 0 and 1 is consistently sent
- * to the Dashboard.
- */
-public class Robot extends TimedRobot {
- private static final int kMotorPort = 0;
- private static final int kJoystickPort = 0;
- private static final int kEncoderPortA = 0;
- private static final int kEncoderPortB = 1;
-
- private MotorController m_motor;
- private Joystick m_joystick;
- private Encoder m_encoder;
-
- @Override
- public void robotInit() {
- m_motor = new PWMSparkMax(kMotorPort);
- m_joystick = new Joystick(kJoystickPort);
- m_encoder = new Encoder(kEncoderPortA, kEncoderPortB);
- // Use SetDistancePerPulse to set the multiplier for GetDistance
- // This is set up assuming a 6 inch wheel with a 360 CPR encoder.
- m_encoder.setDistancePerPulse((Math.PI * 6) / 360.0);
- }
-
- /*
- * The RobotPeriodic function is called every control packet no matter the
- * robot mode.
- */
- @Override
- public void robotPeriodic() {
- SmartDashboard.putNumber("Encoder", m_encoder.getDistance());
- }
-
- @Override
- public void teleopPeriodic() {
- m_motor.set(m_joystick.getY());
- }
-}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java
index b63766c..d5140ee 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java
@@ -55,7 +55,7 @@
public static final class AutoConstants {
public static final double kMaxSpeedMetersPerSecond = 3;
- public static final double kMaxAccelerationMetersPerSecondSquared = 3;
+ public static final double kMaxAccelerationMetersPerSecondSquared = 1;
// Reasonable baseline values for a RAMSETE follower in units of meters and seconds
public static final double kRamseteB = 2;
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java
index 5df8d2f..9f0980a 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java
@@ -22,6 +22,7 @@
import edu.wpi.first.wpilibj.examples.ramsetecommand.Constants.OIConstants;
import edu.wpi.first.wpilibj.examples.ramsetecommand.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RamseteCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
@@ -53,7 +54,7 @@
new RunCommand(
() ->
m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
+ -m_driverController.getLeftY(), -m_driverController.getRightX()),
m_robotDrive));
}
@@ -66,8 +67,8 @@
private void configureButtonBindings() {
// Drive at half speed when the right bumper is held
new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ .onTrue(new InstantCommand(() -> m_robotDrive.setMaxOutput(0.5)))
+ .onFalse(new InstantCommand(() -> m_robotDrive.setMaxOutput(1)));
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java
index b2fe2f7..90625ce 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java
@@ -64,7 +64,9 @@
m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse);
resetEncoders();
- m_odometry = new DifferentialDriveOdometry(m_gyro.getRotation2d());
+ m_odometry =
+ new DifferentialDriveOdometry(
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance());
}
@Override
@@ -99,7 +101,8 @@
*/
public void resetOdometry(Pose2d pose) {
resetEncoders();
- m_odometry.resetPosition(pose, m_gyro.getRotation2d());
+ m_odometry.resetPosition(
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance(), pose);
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java
index e119080..69288a1 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java
@@ -73,7 +73,9 @@
m_leftEncoder.reset();
m_rightEncoder.reset();
- m_odometry = new DifferentialDriveOdometry(m_gyro.getRotation2d());
+ m_odometry =
+ new DifferentialDriveOdometry(
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance());
}
/**
@@ -99,7 +101,6 @@
* @param xSpeed Linear velocity in m/s.
* @param rot Angular velocity in rad/s.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double rot) {
var wheelSpeeds = m_kinematics.toWheelSpeeds(new ChassisSpeeds(xSpeed, 0.0, rot));
setSpeeds(wheelSpeeds);
@@ -117,7 +118,8 @@
* @param pose The position to reset to.
*/
public void resetOdometry(Pose2d pose) {
- m_odometry.resetPosition(pose, m_gyro.getRotation2d());
+ m_odometry.resetPosition(
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance(), pose);
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Constants.java
new file mode 100644
index 0000000..6ee700c
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Constants.java
@@ -0,0 +1,83 @@
+// 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.wpilibj.examples.rapidreactcommandbot;
+
+import edu.wpi.first.math.util.Units;
+
+/**
+ * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
+ * constants. This class should not be used for any other purpose. All constants should be declared
+ * globally (i.e. public static). Do not put anything functional in this class.
+ *
+ * <p>It is advised to statically import this class (or one of its inner classes) wherever the
+ * constants are needed, to reduce verbosity.
+ */
+public final class Constants {
+ public static final class DriveConstants {
+ public static final int kLeftMotor1Port = 0;
+ public static final int kLeftMotor2Port = 1;
+ public static final int kRightMotor1Port = 2;
+ public static final int kRightMotor2Port = 3;
+
+ public static final int[] kLeftEncoderPorts = {0, 1};
+ public static final int[] kRightEncoderPorts = {2, 3};
+ public static final boolean kLeftEncoderReversed = false;
+ public static final boolean kRightEncoderReversed = true;
+
+ public static final int kEncoderCPR = 1024;
+ public static final double kWheelDiameterMeters = Units.inchesToMeters(6);
+ public static final double kEncoderDistancePerPulse =
+ // Assumes the encoders are directly mounted on the wheel shafts
+ (kWheelDiameterMeters * Math.PI) / (double) kEncoderCPR;
+ }
+
+ public static final class ShooterConstants {
+ public static final int[] kEncoderPorts = {4, 5};
+ public static final boolean kEncoderReversed = false;
+ public static final int kEncoderCPR = 1024;
+ public static final double kEncoderDistancePerPulse =
+ // Distance units will be rotations
+ 1.0 / (double) kEncoderCPR;
+
+ public static final int kShooterMotorPort = 4;
+ public static final int kFeederMotorPort = 5;
+
+ public static final double kShooterFreeRPS = 5300;
+ public static final double kShooterTargetRPS = 4000;
+ public static final double kShooterToleranceRPS = 50;
+
+ // These are not real PID gains, and will have to be tuned for your specific robot.
+ public static final double kP = 1;
+
+ // On a real robot the feedforward constants should be empirically determined; these are
+ // reasonable guesses.
+ public static final double kSVolts = 0.05;
+ public static final double kVVoltSecondsPerRotation =
+ // Should have value 12V at free speed...
+ 12.0 / kShooterFreeRPS;
+
+ public static final double kFeederSpeed = 0.5;
+ }
+
+ public static final class IntakeConstants {
+ public static final int kMotorPort = 6;
+ public static final int[] kSolenoidPorts = {0, 1};
+ }
+
+ public static final class StorageConstants {
+ public static final int kMotorPort = 7;
+ public static final int kBallSensorPort = 6;
+ }
+
+ public static final class AutoConstants {
+ public static final double kTimeoutSeconds = 3;
+ public static final double kDriveDistanceMeters = 2;
+ public static final double kDriveSpeed = 0.5;
+ }
+
+ public static final class OIConstants {
+ public static final int kDriverControllerPort = 0;
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Main.java
similarity index 92%
copy from wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java
copy to wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Main.java
index 0ca48f6..b72cd91 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Main.java
@@ -2,7 +2,7 @@
// 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.wpilibj.examples.motorcontrolencoder;
+package edu.wpi.first.wpilibj.examples.rapidreactcommandbot;
import edu.wpi.first.wpilibj.RobotBase;
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/RapidReactCommandBot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/RapidReactCommandBot.java
new file mode 100644
index 0000000..879f2c2
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/RapidReactCommandBot.java
@@ -0,0 +1,85 @@
+// 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.wpilibj.examples.rapidreactcommandbot;
+
+import static edu.wpi.first.wpilibj2.command.Commands.parallel;
+
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.Constants.AutoConstants;
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.Constants.OIConstants;
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.Constants.ShooterConstants;
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.subsystems.Drive;
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.subsystems.Intake;
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.subsystems.Shooter;
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.subsystems.Storage;
+import edu.wpi.first.wpilibj2.command.CommandBase;
+import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
+import edu.wpi.first.wpilibj2.command.button.Trigger;
+
+/**
+ * This class is where the bulk of the robot should be declared. Since Command-based is a
+ * "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
+ * periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
+ * subsystems, commands, and button mappings) should be declared here.
+ */
+public class RapidReactCommandBot {
+ // The robot's subsystems
+ private final Drive m_drive = new Drive();
+ private final Intake m_intake = new Intake();
+ private final Storage m_storage = new Storage();
+ private final Shooter m_shooter = new Shooter();
+
+ // The driver's controller
+ CommandXboxController m_driverController =
+ new CommandXboxController(OIConstants.kDriverControllerPort);
+
+ /**
+ * Use this method to define bindings between conditions and commands. These are useful for
+ * automating robot behaviors based on button and sensor input.
+ *
+ * <p>Should be called during {@link Robot#robotInit()}.
+ *
+ * <p>Event binding methods are available on the {@link Trigger} class.
+ */
+ public void configureBindings() {
+ // Automatically run the storage motor whenever the ball storage is not full,
+ // and turn it off whenever it fills.
+ new Trigger(m_storage::isFull).whileFalse(m_storage.runCommand());
+
+ // Automatically disable and retract the intake whenever the ball storage is full.
+ new Trigger(m_storage::isFull).onTrue(m_intake.retractCommand());
+
+ // Control the drive with split-stick arcade controls
+ m_drive.setDefaultCommand(
+ m_drive.arcadeDriveCommand(
+ () -> -m_driverController.getLeftY(), () -> -m_driverController.getRightX()));
+
+ // Deploy the intake with the X button
+ m_driverController.x().onTrue(m_intake.intakeCommand());
+ // Retract the intake with the Y button
+ m_driverController.y().onTrue(m_intake.retractCommand());
+
+ // Fire the shooter with the A button
+ m_driverController
+ .a()
+ .onTrue(
+ parallel(
+ m_shooter.shootCommand(ShooterConstants.kShooterTargetRPS),
+ m_storage.runCommand())
+ // Since we composed this inline we should give it a name
+ .withName("Shoot"));
+ }
+
+ /**
+ * Use this to define the command that runs during autonomous.
+ *
+ * <p>Scheduled during {@link Robot#autonomousInit()}.
+ */
+ public CommandBase getAutonomousCommand() {
+ // Drive forward for 2 meters at half speed with a 3 second timeout
+ return m_drive
+ .driveDistanceCommand(AutoConstants.kDriveDistanceMeters, AutoConstants.kDriveSpeed)
+ .withTimeout(AutoConstants.kTimeoutSeconds);
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Robot.java
new file mode 100644
index 0000000..3588677
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/Robot.java
@@ -0,0 +1,92 @@
+// 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.wpilibj.examples.rapidreactcommandbot;
+
+import edu.wpi.first.wpilibj.TimedRobot;
+import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.CommandScheduler;
+
+/**
+ * The VM is configured to automatically run this class, and to call the functions corresponding to
+ * each mode, as described in the TimedRobot documentation. If you change the name of this class or
+ * the package after creating this project, you must also update the build.gradle file in the
+ * project.
+ */
+public class Robot extends TimedRobot {
+ private Command m_autonomousCommand;
+
+ private final RapidReactCommandBot m_robot = new RapidReactCommandBot();
+
+ /**
+ * This function is run when the robot is first started up and should be used for any
+ * initialization code.
+ */
+ @Override
+ public void robotInit() {
+ // Configure default commands and condition bindings on robot startup
+ m_robot.configureBindings();
+ }
+
+ /**
+ * This function is called every robot packet, no matter the mode. Use this for items like
+ * diagnostics that you want ran during disabled, autonomous, teleoperated and test.
+ *
+ * <p>This runs after the mode specific periodic functions, but before LiveWindow and
+ * SmartDashboard integrated updating.
+ */
+ @Override
+ public void robotPeriodic() {
+ // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
+ // commands, running already-scheduled commands, removing finished or interrupted commands,
+ // and running subsystem periodic() methods. This must be called from the robot's periodic
+ // block in order for anything in the Command-based framework to work.
+ CommandScheduler.getInstance().run();
+ }
+
+ /** This function is called once each time the robot enters Disabled mode. */
+ @Override
+ public void disabledInit() {}
+
+ @Override
+ public void disabledPeriodic() {}
+
+ @Override
+ public void autonomousInit() {
+ m_autonomousCommand = m_robot.getAutonomousCommand();
+
+ if (m_autonomousCommand != null) {
+ m_autonomousCommand.schedule();
+ }
+ }
+
+ /** This function is called periodically during autonomous. */
+ @Override
+ public void autonomousPeriodic() {}
+
+ @Override
+ public void teleopInit() {
+ // This makes sure that the autonomous stops running when
+ // teleop starts running. If you want the autonomous to
+ // continue until interrupted by another command, remove
+ // this line or comment it out.
+ if (m_autonomousCommand != null) {
+ m_autonomousCommand.cancel();
+ }
+ }
+
+ /** This function is called periodically during operator control. */
+ @Override
+ public void teleopPeriodic() {}
+
+ @Override
+ public void testInit() {
+ // Cancels all running commands at the start of test mode.
+ CommandScheduler.getInstance().cancelAll();
+ }
+
+ /** This function is called periodically during test mode. */
+ @Override
+ public void testPeriodic() {}
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Drive.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Drive.java
new file mode 100644
index 0000000..eaaa8ad
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Drive.java
@@ -0,0 +1,94 @@
+// 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.wpilibj.examples.rapidreactcommandbot.subsystems;
+
+import edu.wpi.first.wpilibj.Encoder;
+import edu.wpi.first.wpilibj.drive.DifferentialDrive;
+import edu.wpi.first.wpilibj.examples.rapidreactcommandbot.Constants.DriveConstants;
+import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
+import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+import edu.wpi.first.wpilibj2.command.CommandBase;
+import edu.wpi.first.wpilibj2.command.SubsystemBase;
+import java.util.function.DoubleSupplier;
+
+public class Drive extends SubsystemBase {
+ // The motors on the left side of the drive.
+ private final MotorControllerGroup m_leftMotors =
+ new MotorControllerGroup(
+ new PWMSparkMax(DriveConstants.kLeftMotor1Port),
+ new PWMSparkMax(DriveConstants.kLeftMotor2Port));
+
+ // The motors on the right side of the drive.
+ private final MotorControllerGroup m_rightMotors =
+ new MotorControllerGroup(
+ new PWMSparkMax(DriveConstants.kRightMotor1Port),
+ new PWMSparkMax(DriveConstants.kRightMotor2Port));
+
+ // The robot's drive
+ private final DifferentialDrive m_drive = new DifferentialDrive(m_leftMotors, m_rightMotors);
+
+ // The left-side drive encoder
+ private final Encoder m_leftEncoder =
+ new Encoder(
+ DriveConstants.kLeftEncoderPorts[0],
+ DriveConstants.kLeftEncoderPorts[1],
+ DriveConstants.kLeftEncoderReversed);
+
+ // The right-side drive encoder
+ private final Encoder m_rightEncoder =
+ new Encoder(
+ DriveConstants.kRightEncoderPorts[0],
+ DriveConstants.kRightEncoderPorts[1],
+ DriveConstants.kRightEncoderReversed);
+
+ /** Creates a new Drive subsystem. */
+ public Drive() {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotors.setInverted(true);
+
+ // Sets the distance per pulse for the encoders
+ m_leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse);
+ m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse);
+ }
+
+ /**
+ * Returns a command that drives the robot with arcade controls.
+ *
+ * @param fwd the commanded forward movement
+ * @param rot the commanded rotation
+ */
+ public CommandBase arcadeDriveCommand(DoubleSupplier fwd, DoubleSupplier rot) {
+ // A split-stick arcade command, with forward/backward controlled by the left
+ // hand, and turning controlled by the right.
+ return run(() -> m_drive.arcadeDrive(fwd.getAsDouble(), rot.getAsDouble()))
+ .withName("arcadeDrive");
+ }
+
+ /**
+ * Returns a command that drives the robot forward a specified distance at a specified speed.
+ *
+ * @param distanceMeters The distance to drive forward in meters
+ * @param speed The fraction of max speed at which to drive
+ */
+ public CommandBase driveDistanceCommand(double distanceMeters, double speed) {
+ return runOnce(
+ () -> {
+ // Reset encoders at the start of the command
+ m_leftEncoder.reset();
+ m_rightEncoder.reset();
+ })
+ // Drive forward at specified speed
+ .andThen(run(() -> m_drive.arcadeDrive(speed, 0)))
+ // End command when we've traveled the specified distance
+ .until(
+ () ->
+ Math.max(m_leftEncoder.getDistance(), m_rightEncoder.getDistance())
+ >= distanceMeters)
+ // Stop the drive when the command ends
+ .finallyDo(interrupted -> m_drive.stopMotor());
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Intake.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Intake.java
new file mode 100644
index 0000000..533f596
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Intake.java
@@ -0,0 +1,39 @@
+// 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.wpilibj.examples.rapidreactcommandbot.subsystems;
+
+import static edu.wpi.first.wpilibj.examples.rapidreactcommandbot.Constants.IntakeConstants;
+
+import edu.wpi.first.wpilibj.DoubleSolenoid;
+import edu.wpi.first.wpilibj.PneumaticsModuleType;
+import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+import edu.wpi.first.wpilibj2.command.CommandBase;
+import edu.wpi.first.wpilibj2.command.SubsystemBase;
+
+public class Intake extends SubsystemBase {
+ private final PWMSparkMax m_motor = new PWMSparkMax(IntakeConstants.kMotorPort);
+ private final DoubleSolenoid m_pistons =
+ new DoubleSolenoid(
+ PneumaticsModuleType.REVPH,
+ IntakeConstants.kSolenoidPorts[0],
+ IntakeConstants.kSolenoidPorts[1]);
+
+ /** Returns a command that deploys the intake, and then runs the intake motor indefinitely. */
+ public CommandBase intakeCommand() {
+ return runOnce(() -> m_pistons.set(DoubleSolenoid.Value.kForward))
+ .andThen(run(() -> m_motor.set(1.0)))
+ .withName("Intake");
+ }
+
+ /** Returns a command that turns off and retracts the intake. */
+ public CommandBase retractCommand() {
+ return runOnce(
+ () -> {
+ m_motor.disable();
+ m_pistons.set(DoubleSolenoid.Value.kReverse);
+ })
+ .withName("Retract");
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Shooter.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Shooter.java
new file mode 100644
index 0000000..9191fb6
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Shooter.java
@@ -0,0 +1,66 @@
+// 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.wpilibj.examples.rapidreactcommandbot.subsystems;
+
+import static edu.wpi.first.wpilibj2.command.Commands.parallel;
+import static edu.wpi.first.wpilibj2.command.Commands.waitUntil;
+
+import edu.wpi.first.math.controller.PIDController;
+import edu.wpi.first.math.controller.SimpleMotorFeedforward;
+import edu.wpi.first.wpilibj.Encoder;
+import edu.wpi.first.wpilibj.examples.frisbeebot.Constants.ShooterConstants;
+import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+import edu.wpi.first.wpilibj2.command.CommandBase;
+import edu.wpi.first.wpilibj2.command.SubsystemBase;
+
+public class Shooter extends SubsystemBase {
+ private final PWMSparkMax m_shooterMotor = new PWMSparkMax(ShooterConstants.kShooterMotorPort);
+ private final PWMSparkMax m_feederMotor = new PWMSparkMax(ShooterConstants.kFeederMotorPort);
+ private final Encoder m_shooterEncoder =
+ new Encoder(
+ ShooterConstants.kEncoderPorts[0],
+ ShooterConstants.kEncoderPorts[1],
+ ShooterConstants.kEncoderReversed);
+ private final SimpleMotorFeedforward m_shooterFeedforward =
+ new SimpleMotorFeedforward(
+ ShooterConstants.kSVolts, ShooterConstants.kVVoltSecondsPerRotation);
+ private final PIDController m_shooterFeedback = new PIDController(ShooterConstants.kP, 0.0, 0.0);
+
+ /** The shooter subsystem for the robot. */
+ public Shooter() {
+ m_shooterFeedback.setTolerance(ShooterConstants.kShooterToleranceRPS);
+ m_shooterEncoder.setDistancePerPulse(ShooterConstants.kEncoderDistancePerPulse);
+
+ // Set default command to turn off both the shooter and feeder motors, and then idle
+ setDefaultCommand(
+ runOnce(
+ () -> {
+ m_shooterMotor.disable();
+ m_feederMotor.disable();
+ })
+ .andThen(run(() -> {}))
+ .withName("Idle"));
+ }
+
+ /**
+ * Returns a command to shoot the balls currently stored in the robot. Spins the shooter flywheel
+ * up to the specified setpoint, and then runs the feeder motor.
+ *
+ * @param setpointRotationsPerSecond The desired shooter velocity
+ */
+ public CommandBase shootCommand(double setpointRotationsPerSecond) {
+ return parallel(
+ // Run the shooter flywheel at the desired setpoint using feedforward and feedback
+ run(
+ () ->
+ m_shooterMotor.set(
+ m_shooterFeedforward.calculate(setpointRotationsPerSecond)
+ + m_shooterFeedback.calculate(
+ m_shooterEncoder.getRate(), setpointRotationsPerSecond))),
+ // Wait until the shooter has reached the setpoint, and then run the feeder
+ waitUntil(m_shooterFeedback::atSetpoint).andThen(() -> m_feederMotor.set(1)))
+ .withName("Shoot");
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Storage.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Storage.java
new file mode 100644
index 0000000..9b45d66
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/rapidreactcommandbot/subsystems/Storage.java
@@ -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.wpilibj.examples.rapidreactcommandbot.subsystems;
+
+import static edu.wpi.first.wpilibj.examples.rapidreactcommandbot.Constants.StorageConstants;
+
+import edu.wpi.first.wpilibj.DigitalInput;
+import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+import edu.wpi.first.wpilibj2.command.CommandBase;
+import edu.wpi.first.wpilibj2.command.SubsystemBase;
+
+public class Storage extends SubsystemBase {
+ private final PWMSparkMax m_motor = new PWMSparkMax(StorageConstants.kMotorPort);
+ private final DigitalInput m_ballSensor = new DigitalInput(StorageConstants.kBallSensorPort);
+
+ /** Create a new Storage subsystem. */
+ public Storage() {
+ // Set default command to turn off the storage motor and then idle
+ setDefaultCommand(runOnce(m_motor::disable).andThen(run(() -> {})).withName("Idle"));
+ }
+
+ /** Whether the ball storage is full. */
+ public boolean isFull() {
+ return m_ballSensor.get();
+ }
+
+ /** Returns a command that runs the storage motor indefinitely. */
+ public CommandBase runCommand() {
+ return run(() -> m_motor.set(1)).withName("run");
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java
index 8ad7bc3..a9dcacd 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/RobotContainer.java
@@ -17,7 +17,7 @@
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.PrintCommand;
-import edu.wpi.first.wpilibj2.command.button.Button;
+import edu.wpi.first.wpilibj2.command.button.Trigger;
/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
@@ -65,10 +65,10 @@
m_drivetrain.setDefaultCommand(getArcadeDriveCommand());
// Example of how to use the onboard IO
- Button onboardButtonA = new Button(m_onboardIO::getButtonAPressed);
+ Trigger onboardButtonA = new Trigger(m_onboardIO::getButtonAPressed);
onboardButtonA
- .whenActive(new PrintCommand("Button A Pressed"))
- .whenInactive(new PrintCommand("Button A Released"));
+ .onTrue(new PrintCommand("Button A Pressed"))
+ .onFalse(new PrintCommand("Button A Released"));
// Setup SmartDashboard options
m_chooser.setDefaultOption("Auto Routine Distance", new AutonomousDistance(m_drivetrain));
@@ -92,6 +92,6 @@
*/
public Command getArcadeDriveCommand() {
return new ArcadeDrive(
- m_drivetrain, () -> -m_controller.getRawAxis(1), () -> m_controller.getRawAxis(2));
+ m_drivetrain, () -> -m_controller.getRawAxis(1), () -> -m_controller.getRawAxis(2));
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java
index c21f623..a0ee53d 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/sensors/RomiGyro.java
@@ -9,12 +9,12 @@
import edu.wpi.first.hal.SimDouble;
public class RomiGyro {
- private SimDouble m_simRateX;
- private SimDouble m_simRateY;
- private SimDouble m_simRateZ;
- private SimDouble m_simAngleX;
- private SimDouble m_simAngleY;
- private SimDouble m_simAngleZ;
+ private final SimDouble m_simRateX;
+ private final SimDouble m_simRateY;
+ private final SimDouble m_simRateZ;
+ private final SimDouble m_simAngleX;
+ private final SimDouble m_simAngleY;
+ private final SimDouble m_simAngleZ;
private double m_angleXOffset;
private double m_angleYOffset;
@@ -32,6 +32,14 @@
m_simAngleX = gyroSimDevice.createDouble("angle_x", Direction.kInput, 0.0);
m_simAngleY = gyroSimDevice.createDouble("angle_y", Direction.kInput, 0.0);
m_simAngleZ = gyroSimDevice.createDouble("angle_z", Direction.kInput, 0.0);
+ } else {
+ m_simRateX = null;
+ m_simRateY = null;
+ m_simRateZ = null;
+
+ m_simAngleX = null;
+ m_simAngleY = null;
+ m_simAngleZ = null;
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/OnBoardIO.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/OnBoardIO.java
index 848aff5..0199f6a 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/OnBoardIO.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/OnBoardIO.java
@@ -22,12 +22,12 @@
private final DigitalOutput m_yellowLed = new DigitalOutput(3);
// DIO 1
- private DigitalInput m_buttonB;
- private DigitalOutput m_greenLed;
+ private final DigitalInput m_buttonB;
+ private final DigitalOutput m_greenLed;
// DIO 2
- private DigitalInput m_buttonC;
- private DigitalOutput m_redLed;
+ private final DigitalInput m_buttonC;
+ private final DigitalOutput m_redLed;
private static final double MESSAGE_INTERVAL = 1.0;
private double m_nextMessageTime;
@@ -46,13 +46,17 @@
public OnBoardIO(ChannelMode dio1, ChannelMode dio2) {
if (dio1 == ChannelMode.INPUT) {
m_buttonB = new DigitalInput(1);
+ m_greenLed = null;
} else {
+ m_buttonB = null;
m_greenLed = new DigitalOutput(1);
}
if (dio2 == ChannelMode.INPUT) {
m_buttonC = new DigitalInput(2);
+ m_redLed = null;
} else {
+ m_buttonC = null;
m_redLed = new DigitalOutput(2);
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/schedulereventlogging/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/schedulereventlogging/RobotContainer.java
index c798600..fcb467c 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/schedulereventlogging/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/schedulereventlogging/RobotContainer.java
@@ -70,11 +70,11 @@
*/
private void configureButtonBindings() {
// Run instant command 1 when the 'A' button is pressed
- new JoystickButton(m_driverController, Button.kA.value).whenPressed(m_instantCommand1);
+ new JoystickButton(m_driverController, Button.kA.value).onTrue(m_instantCommand1);
// Run instant command 2 when the 'X' button is pressed
- new JoystickButton(m_driverController, Button.kX.value).whenPressed(m_instantCommand2);
+ new JoystickButton(m_driverController, Button.kX.value).onTrue(m_instantCommand2);
// Run instant command 3 when the 'Y' button is held; release early to interrupt
- new JoystickButton(m_driverController, Button.kY.value).whenHeld(m_waitCommand);
+ new JoystickButton(m_driverController, Button.kY.value).whileTrue(m_waitCommand);
}
/**
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java
index eb6a6d9..f9991f6 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java
@@ -4,7 +4,7 @@
package edu.wpi.first.wpilibj.examples.shuffleboard;
-import edu.wpi.first.networktables.NetworkTableEntry;
+import edu.wpi.first.networktables.GenericEntry;
import edu.wpi.first.wpilibj.AnalogPotentiometer;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.TimedRobot;
@@ -22,7 +22,7 @@
private final PWMSparkMax m_elevatorMotor = new PWMSparkMax(2);
private final AnalogPotentiometer m_elevatorPot = new AnalogPotentiometer(0);
- private NetworkTableEntry m_maxSpeed;
+ private GenericEntry m_maxSpeed;
@Override
public void robotInit() {
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java
index 986875a..a9f53a9 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java
@@ -57,7 +57,8 @@
private final DifferentialDriveKinematics m_kinematics =
new DifferentialDriveKinematics(kTrackWidth);
private final DifferentialDriveOdometry m_odometry =
- new DifferentialDriveOdometry(m_gyro.getRotation2d());
+ new DifferentialDriveOdometry(
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance());
// Gains are for example purposes only - must be determined for your own
// robot!
@@ -113,7 +114,6 @@
* @param xSpeed the speed for the x axis
* @param rot the rotation
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double rot) {
setSpeeds(m_kinematics.toWheelSpeeds(new ChassisSpeeds(xSpeed, 0, rot)));
}
@@ -129,7 +129,8 @@
m_leftEncoder.reset();
m_rightEncoder.reset();
m_drivetrainSimulator.setPose(pose);
- m_odometry.resetPosition(pose, m_gyro.getRotation2d());
+ m_odometry.resetPosition(
+ m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance(), pose);
}
/** Check the current robot pose. */
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java
index 99178d4..1beccce 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java
@@ -32,10 +32,6 @@
@Override
public void robotInit() {
- // Flush NetworkTables every loop. This ensures that robot pose and other values
- // are sent during every iteration.
- setNetworkTablesFlushEnabled(true);
-
m_trajectory =
TrajectoryGenerator.generateTrajectory(
new Pose2d(2, 2, new Rotation2d()),
@@ -65,7 +61,6 @@
}
@Override
- @SuppressWarnings("LocalVariableName")
public void teleopPeriodic() {
// Get the x speed. We are inverting this because Xbox controllers return
// negative values when we push forward.
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Robot.java
index 75700c4..8eca311 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Robot.java
@@ -26,10 +26,6 @@
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
-
- // Flush NetworkTables every loop. This ensures that robot pose and other values
- // are sent during every loop iteration.
- setNetworkTablesFlushEnabled(true);
}
@Override
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java
index 4636c37..6cb6e02 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java
@@ -18,6 +18,7 @@
import edu.wpi.first.wpilibj.XboxController.Button;
import edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RamseteCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
@@ -47,10 +48,13 @@
m_robotDrive.setDefaultCommand(
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
+ // If you are using the keyboard as a joystick, it is recommended that you go
+ // to the following link to read about editing the keyboard settings.
+ // https://docs.wpilib.org/en/stable/docs/software/wpilib-tools/robot-simulation/simulation-gui.html#using-the-keyboard-as-a-joystick
new RunCommand(
() ->
m_robotDrive.arcadeDrive(
- -m_driverController.getLeftY(), m_driverController.getRightX()),
+ -m_driverController.getLeftY(), -m_driverController.getRightX()),
m_robotDrive));
}
@@ -63,8 +67,8 @@
private void configureButtonBindings() {
// Drive at half speed when the right bumper is held
new JoystickButton(m_driverController, Button.kRightBumper.value)
- .whenPressed(() -> m_robotDrive.setMaxOutput(0.5))
- .whenReleased(() -> m_robotDrive.setMaxOutput(1));
+ .onTrue(new InstantCommand(() -> m_robotDrive.setMaxOutput(0.5)))
+ .onFalse(new InstantCommand(() -> m_robotDrive.setMaxOutput(1)));
}
public DriveSubsystem getRobotDrive() {
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java
index e974269..406178a 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java
@@ -62,11 +62,11 @@
// These classes help us simulate our drivetrain
public DifferentialDrivetrainSim m_drivetrainSimulator;
- private EncoderSim m_leftEncoderSim;
- private EncoderSim m_rightEncoderSim;
+ private final EncoderSim m_leftEncoderSim;
+ private final EncoderSim m_rightEncoderSim;
// The Field2d class shows the field in the sim GUI
- private Field2d m_fieldSim;
- private ADXRS450_GyroSim m_gyroSim;
+ private final Field2d m_fieldSim;
+ private final ADXRS450_GyroSim m_gyroSim;
/** Creates a new DriveSubsystem. */
public DriveSubsystem() {
@@ -80,7 +80,11 @@
m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse);
resetEncoders();
- m_odometry = new DifferentialDriveOdometry(Rotation2d.fromDegrees(getHeading()));
+ m_odometry =
+ new DifferentialDriveOdometry(
+ Rotation2d.fromDegrees(getHeading()),
+ m_leftEncoder.getDistance(),
+ m_rightEncoder.getDistance());
if (RobotBase.isSimulation()) { // If our robot is simulated
// This class simulates our drivetrain's motion around the field.
@@ -101,6 +105,12 @@
// the Field2d class lets us visualize our robot in the simulation GUI.
m_fieldSim = new Field2d();
SmartDashboard.putData("Field", m_fieldSim);
+ } else {
+ m_leftEncoderSim = null;
+ m_rightEncoderSim = null;
+ m_gyroSim = null;
+
+ m_fieldSim = null;
}
}
@@ -168,7 +178,11 @@
public void resetOdometry(Pose2d pose) {
resetEncoders();
m_drivetrainSimulator.setPose(pose);
- m_odometry.resetPosition(pose, Rotation2d.fromDegrees(getHeading()));
+ m_odometry.resetPosition(
+ Rotation2d.fromDegrees(getHeading()),
+ m_leftEncoder.getDistance(),
+ m_rightEncoder.getDistance(),
+ pose);
}
/**
@@ -188,11 +202,6 @@
* @param rightVolts the commanded right output
*/
public void tankDriveVolts(double leftVolts, double rightVolts) {
- var batteryVoltage = RobotController.getBatteryVoltage();
- if (Math.max(Math.abs(leftVolts), Math.abs(rightVolts)) > batteryVoltage) {
- leftVolts *= batteryVoltage / 12.0;
- rightVolts *= batteryVoltage / 12.0;
- }
m_leftMotors.setVoltage(leftVolts);
m_rightMotors.setVoltage(rightVolts);
m_drive.feed();
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java
index 3b71a0c..6a45f6a 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java
@@ -8,6 +8,7 @@
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
import edu.wpi.first.math.kinematics.SwerveDriveOdometry;
+import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.wpilibj.AnalogGyro;
/** Represents a swerve drive style drivetrain. */
@@ -32,7 +33,15 @@
m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation);
private final SwerveDriveOdometry m_odometry =
- new SwerveDriveOdometry(m_kinematics, m_gyro.getRotation2d());
+ new SwerveDriveOdometry(
+ m_kinematics,
+ m_gyro.getRotation2d(),
+ new SwerveModulePosition[] {
+ m_frontLeft.getPosition(),
+ m_frontRight.getPosition(),
+ m_backLeft.getPosition(),
+ m_backRight.getPosition()
+ });
public Drivetrain() {
m_gyro.reset();
@@ -46,7 +55,6 @@
* @param rot Angular rate of the robot.
* @param fieldRelative Whether the provided x and y speeds are relative to the field.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double ySpeed, double rot, boolean fieldRelative) {
var swerveModuleStates =
m_kinematics.toSwerveModuleStates(
@@ -64,9 +72,11 @@
public void updateOdometry() {
m_odometry.update(
m_gyro.getRotation2d(),
- m_frontLeft.getState(),
- m_frontRight.getState(),
- m_backLeft.getState(),
- m_backRight.getState());
+ new SwerveModulePosition[] {
+ m_frontLeft.getPosition(),
+ m_frontRight.getPosition(),
+ m_backLeft.getPosition(),
+ m_backRight.getPosition()
+ });
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java
index 9749c2d..27ea37f 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java
@@ -8,6 +8,7 @@
import edu.wpi.first.math.controller.ProfiledPIDController;
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
import edu.wpi.first.math.geometry.Rotation2d;
+import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.Encoder;
@@ -72,7 +73,7 @@
// resolution.
m_driveEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution);
- // Set the distance (in this case, angle) per pulse for the turning encoder.
+ // Set the distance (in this case, angle) in radians per pulse for the turning encoder.
// This is the the angle through an entire rotation (2 * pi) divided by the
// encoder resolution.
m_turningEncoder.setDistancePerPulse(2 * Math.PI / kEncoderResolution);
@@ -88,7 +89,18 @@
* @return The current state of the module.
*/
public SwerveModuleState getState() {
- return new SwerveModuleState(m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.get()));
+ return new SwerveModuleState(
+ m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.getDistance()));
+ }
+
+ /**
+ * Returns the current position of the module.
+ *
+ * @return The current position of the module.
+ */
+ public SwerveModulePosition getPosition() {
+ return new SwerveModulePosition(
+ m_driveEncoder.getDistance(), new Rotation2d(m_turningEncoder.getDistance()));
}
/**
@@ -99,7 +111,7 @@
public void setDesiredState(SwerveModuleState desiredState) {
// Optimize the reference state to avoid spinning further than 90 degrees
SwerveModuleState state =
- SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.get()));
+ SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.getDistance()));
// Calculate the drive output from the drive PID controller.
final double driveOutput =
@@ -109,7 +121,7 @@
// Calculate the turning motor output from the turning PID controller.
final double turnOutput =
- m_turningPIDController.calculate(m_turningEncoder.get(), state.angle.getRadians());
+ m_turningPIDController.calculate(m_turningEncoder.getDistance(), state.angle.getRadians());
final double turnFeedforward =
m_turnFeedforward.calculate(m_turningPIDController.getSetpoint().velocity);
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java
index c0e364b..326efee 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java
@@ -8,6 +8,7 @@
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
import edu.wpi.first.math.kinematics.SwerveDriveOdometry;
+import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.wpilibj.ADXRS450_Gyro;
import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.DriveConstants;
@@ -57,7 +58,15 @@
// Odometry class for tracking robot pose
SwerveDriveOdometry m_odometry =
- new SwerveDriveOdometry(DriveConstants.kDriveKinematics, m_gyro.getRotation2d());
+ new SwerveDriveOdometry(
+ DriveConstants.kDriveKinematics,
+ m_gyro.getRotation2d(),
+ new SwerveModulePosition[] {
+ m_frontLeft.getPosition(),
+ m_frontRight.getPosition(),
+ m_rearLeft.getPosition(),
+ m_rearRight.getPosition()
+ });
/** Creates a new DriveSubsystem. */
public DriveSubsystem() {}
@@ -67,10 +76,12 @@
// Update the odometry in the periodic block
m_odometry.update(
m_gyro.getRotation2d(),
- m_frontLeft.getState(),
- m_frontRight.getState(),
- m_rearLeft.getState(),
- m_rearRight.getState());
+ new SwerveModulePosition[] {
+ m_frontLeft.getPosition(),
+ m_frontRight.getPosition(),
+ m_rearLeft.getPosition(),
+ m_rearRight.getPosition()
+ });
}
/**
@@ -88,7 +99,15 @@
* @param pose The pose to which to set the odometry.
*/
public void resetOdometry(Pose2d pose) {
- m_odometry.resetPosition(pose, m_gyro.getRotation2d());
+ m_odometry.resetPosition(
+ m_gyro.getRotation2d(),
+ new SwerveModulePosition[] {
+ m_frontLeft.getPosition(),
+ m_frontRight.getPosition(),
+ m_rearLeft.getPosition(),
+ m_rearRight.getPosition()
+ },
+ pose);
}
/**
@@ -99,7 +118,6 @@
* @param rot Angular rate of the robot.
* @param fieldRelative Whether the provided x and y speeds are relative to the field.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double ySpeed, double rot, boolean fieldRelative) {
var swerveModuleStates =
DriveConstants.kDriveKinematics.toSwerveModuleStates(
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java
index 494d0ab..46825b2 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java
@@ -7,6 +7,7 @@
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.controller.ProfiledPIDController;
import edu.wpi.first.math.geometry.Rotation2d;
+import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.Encoder;
@@ -65,7 +66,7 @@
// Set whether drive encoder should be reversed or not
m_driveEncoder.setReverseDirection(driveEncoderReversed);
- // Set the distance (in this case, angle) per pulse for the turning encoder.
+ // Set the distance (in this case, angle) in radians per pulse for the turning encoder.
// This is the the angle through an entire rotation (2 * pi) divided by the
// encoder resolution.
m_turningEncoder.setDistancePerPulse(ModuleConstants.kTurningEncoderDistancePerPulse);
@@ -84,7 +85,18 @@
* @return The current state of the module.
*/
public SwerveModuleState getState() {
- return new SwerveModuleState(m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.get()));
+ return new SwerveModuleState(
+ m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.getDistance()));
+ }
+
+ /**
+ * Returns the current position of the module.
+ *
+ * @return The current position of the module.
+ */
+ public SwerveModulePosition getPosition() {
+ return new SwerveModulePosition(
+ m_driveEncoder.getDistance(), new Rotation2d(m_turningEncoder.getDistance()));
}
/**
@@ -95,7 +107,7 @@
public void setDesiredState(SwerveModuleState desiredState) {
// Optimize the reference state to avoid spinning further than 90 degrees
SwerveModuleState state =
- SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.get()));
+ SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.getDistance()));
// Calculate the drive output from the drive PID controller.
final double driveOutput =
@@ -103,7 +115,7 @@
// Calculate the turning motor output from the turning PID controller.
final double turnOutput =
- m_turningPIDController.calculate(m_turningEncoder.get(), state.angle.getRadians());
+ m_turningPIDController.calculate(m_turningEncoder.getDistance(), state.angle.getRadians());
// Calculate the turning motor output from the turning PID controller.
m_driveMotor.set(driveOutput);
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/Drivetrain.java
index e1d16a0..8f4c5ce 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/Drivetrain.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/Drivetrain.java
@@ -10,6 +10,7 @@
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
+import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.AnalogGyro;
import edu.wpi.first.wpilibj.Timer;
@@ -39,11 +40,16 @@
below are robot specific, and should be tuned. */
private final SwerveDrivePoseEstimator m_poseEstimator =
new SwerveDrivePoseEstimator(
- m_gyro.getRotation2d(),
- new Pose2d(),
m_kinematics,
+ m_gyro.getRotation2d(),
+ new SwerveModulePosition[] {
+ m_frontLeft.getPosition(),
+ m_frontRight.getPosition(),
+ m_backLeft.getPosition(),
+ m_backRight.getPosition()
+ },
+ new Pose2d(),
VecBuilder.fill(0.05, 0.05, Units.degreesToRadians(5)),
- VecBuilder.fill(Units.degreesToRadians(0.01)),
VecBuilder.fill(0.5, 0.5, Units.degreesToRadians(30)));
public Drivetrain() {
@@ -58,7 +64,6 @@
* @param rot Angular rate of the robot.
* @param fieldRelative Whether the provided x and y speeds are relative to the field.
*/
- @SuppressWarnings("ParameterName")
public void drive(double xSpeed, double ySpeed, double rot, boolean fieldRelative) {
var swerveModuleStates =
m_kinematics.toSwerveModuleStates(
@@ -76,10 +81,12 @@
public void updateOdometry() {
m_poseEstimator.update(
m_gyro.getRotation2d(),
- m_frontLeft.getState(),
- m_frontRight.getState(),
- m_backLeft.getState(),
- m_backRight.getState());
+ new SwerveModulePosition[] {
+ m_frontLeft.getPosition(),
+ m_frontRight.getPosition(),
+ m_backLeft.getPosition(),
+ m_backRight.getPosition()
+ });
// Also apply vision measurements. We use 0.3 seconds in the past as an example -- on
// a real robot, this must be calculated based either on latency or timestamps.
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/SwerveModule.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/SwerveModule.java
index d7c43dd..afd7489 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/SwerveModule.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervedriveposeestimator/SwerveModule.java
@@ -8,6 +8,7 @@
import edu.wpi.first.math.controller.ProfiledPIDController;
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
import edu.wpi.first.math.geometry.Rotation2d;
+import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.Encoder;
@@ -72,7 +73,7 @@
// resolution.
m_driveEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution);
- // Set the distance (in this case, angle) per pulse for the turning encoder.
+ // Set the distance (in this case, angle) in radians per pulse for the turning encoder.
// This is the the angle through an entire rotation (2 * pi) divided by the
// encoder resolution.
m_turningEncoder.setDistancePerPulse(2 * Math.PI / kEncoderResolution);
@@ -88,7 +89,18 @@
* @return The current state of the module.
*/
public SwerveModuleState getState() {
- return new SwerveModuleState(m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.get()));
+ return new SwerveModuleState(
+ m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.getDistance()));
+ }
+
+ /**
+ * Returns the current position of the module.
+ *
+ * @return The current position of the module.
+ */
+ public SwerveModulePosition getPosition() {
+ return new SwerveModulePosition(
+ m_driveEncoder.getDistance(), new Rotation2d(m_turningEncoder.getDistance()));
}
/**
@@ -99,7 +111,7 @@
public void setDesiredState(SwerveModuleState desiredState) {
// Optimize the reference state to avoid spinning further than 90 degrees
SwerveModuleState state =
- SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.get()));
+ SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.getDistance()));
// Calculate the drive output from the drive PID controller.
final double driveOutput =
@@ -109,7 +121,7 @@
// Calculate the turning motor output from the turning PID controller.
final double turnOutput =
- m_turningPIDController.calculate(m_turningEncoder.get(), state.angle.getRadians());
+ m_turningPIDController.calculate(m_turningEncoder.getDistance(), state.angle.getRadians());
final double turnFeedforward =
m_turnFeedforward.calculate(m_turningPIDController.getSetpoint().velocity);
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java
index c91767a..3883d14 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java
@@ -36,6 +36,6 @@
@Override
public void teleopPeriodic() {
- m_myRobot.tankDrive(m_leftStick.getY(), m_rightStick.getY());
+ m_myRobot.tankDrive(-m_leftStick.getY(), -m_rightStick.getY());
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Constants.java
new file mode 100644
index 0000000..cdcfb9d
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Constants.java
@@ -0,0 +1,25 @@
+// 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.wpilibj.examples.unittest;
+
+/**
+ * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
+ * constants. This class should not be used for any other purpose. All constants should be declared
+ * globally (i.e. public static). Do not put anything functional in this class.
+ *
+ * <p>It is advised to statically import this class (or one of its inner classes) wherever the
+ * constants are needed, to reduce verbosity.
+ */
+public final class Constants {
+ public static final int kJoystickIndex = 0;
+
+ public static final class IntakeConstants {
+ public static final int kMotorPort = 1;
+
+ public static final int kPistonFwdChannel = 0;
+ public static final int kPistonRevChannel = 1;
+ public static final double kIntakeSpeed = 0.5;
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Main.java
similarity index 92%
rename from wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java
rename to wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Main.java
index 0ca48f6..4434f47 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Main.java
@@ -2,7 +2,7 @@
// 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.wpilibj.examples.motorcontrolencoder;
+package edu.wpi.first.wpilibj.examples.unittest;
import edu.wpi.first.wpilibj.RobotBase;
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Robot.java
new file mode 100644
index 0000000..9f66c27
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/Robot.java
@@ -0,0 +1,41 @@
+// 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.wpilibj.examples.unittest;
+
+import edu.wpi.first.wpilibj.Joystick;
+import edu.wpi.first.wpilibj.TimedRobot;
+import edu.wpi.first.wpilibj.examples.unittest.Constants.IntakeConstants;
+import edu.wpi.first.wpilibj.examples.unittest.subsystems.Intake;
+
+/**
+ * The VM is configured to automatically run this class, and to call the functions corresponding to
+ * each mode, as described in the TimedRobot documentation. If you change the name of this class or
+ * the package after creating this project, you must also update the build.gradle file in the
+ * project.
+ */
+public class Robot extends TimedRobot {
+ private Intake m_intake = new Intake();
+ private Joystick m_joystick = new Joystick(Constants.kJoystickIndex);
+
+ /** This function is called periodically during operator control. */
+ @Override
+ public void teleopPeriodic() {
+ // Activate the intake while the trigger is held
+ if (m_joystick.getTrigger()) {
+ m_intake.activate(IntakeConstants.kIntakeSpeed);
+ } else {
+ m_intake.activate(0);
+ }
+
+ // Toggle deploying the intake when the top button is pressed
+ if (m_joystick.getTop()) {
+ if (m_intake.isDeployed()) {
+ m_intake.retract();
+ } else {
+ m_intake.deploy();
+ }
+ }
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/Intake.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/Intake.java
new file mode 100644
index 0000000..a51d505
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/Intake.java
@@ -0,0 +1,51 @@
+// 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.wpilibj.examples.unittest.subsystems;
+
+import edu.wpi.first.wpilibj.DoubleSolenoid;
+import edu.wpi.first.wpilibj.PneumaticsModuleType;
+import edu.wpi.first.wpilibj.examples.unittest.Constants.IntakeConstants;
+import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
+
+public class Intake implements AutoCloseable {
+ private final PWMSparkMax m_motor;
+ private final DoubleSolenoid m_piston;
+
+ public Intake() {
+ m_motor = new PWMSparkMax(IntakeConstants.kMotorPort);
+ m_piston =
+ new DoubleSolenoid(
+ PneumaticsModuleType.CTREPCM,
+ IntakeConstants.kPistonFwdChannel,
+ IntakeConstants.kPistonRevChannel);
+ }
+
+ public void deploy() {
+ m_piston.set(DoubleSolenoid.Value.kForward);
+ }
+
+ public void retract() {
+ m_piston.set(DoubleSolenoid.Value.kReverse);
+ m_motor.set(0); // turn off the motor
+ }
+
+ public void activate(double speed) {
+ if (isDeployed()) {
+ m_motor.set(speed);
+ } else { // if piston isn't open, do nothing
+ m_motor.set(0);
+ }
+ }
+
+ public boolean isDeployed() {
+ return m_piston.get() == DoubleSolenoid.Value.kForward;
+ }
+
+ @Override
+ public void close() throws Exception {
+ m_piston.close();
+ m_motor.close();
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Constants.java
index ecfe201..0c958be 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Constants.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Constants.java
@@ -12,4 +12,8 @@
* <p>It is advised to statically import this class (or one of its inner classes) wherever the
* constants are needed, to reduce verbosity.
*/
-public final class Constants {}
+public final class Constants {
+ public static class OperatorConstants {
+ public static final int kDriverControllerPort = 0;
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/RobotContainer.java
index 75f79ae..c29ad38 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/RobotContainer.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/RobotContainer.java
@@ -4,37 +4,52 @@
package edu.wpi.first.wpilibj.templates.commandbased;
-import edu.wpi.first.wpilibj.GenericHID;
-import edu.wpi.first.wpilibj.XboxController;
+import edu.wpi.first.wpilibj.templates.commandbased.Constants.OperatorConstants;
+import edu.wpi.first.wpilibj.templates.commandbased.commands.Autos;
import edu.wpi.first.wpilibj.templates.commandbased.commands.ExampleCommand;
import edu.wpi.first.wpilibj.templates.commandbased.subsystems.ExampleSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
+import edu.wpi.first.wpilibj2.command.button.Trigger;
/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
* periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
- * subsystems, commands, and button mappings) should be declared here.
+ * subsystems, commands, and trigger mappings) should be declared here.
*/
public class RobotContainer {
// The robot's subsystems and commands are defined here...
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();
- private final ExampleCommand m_autoCommand = new ExampleCommand(m_exampleSubsystem);
+ // Replace with CommandPS4Controller or CommandJoystick if needed
+ private final CommandXboxController m_driverController =
+ new CommandXboxController(OperatorConstants.kDriverControllerPort);
/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
- // Configure the button bindings
- configureButtonBindings();
+ // Configure the trigger bindings
+ configureBindings();
}
/**
- * Use this method to define your button->command mappings. Buttons can be created by
- * instantiating a {@link GenericHID} or one of its subclasses ({@link
- * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
- * edu.wpi.first.wpilibj2.command.button.JoystickButton}.
+ * Use this method to define your trigger->command mappings. Triggers can be created via the
+ * {@link Trigger#Trigger(java.util.function.BooleanSupplier)} constructor with an arbitrary
+ * predicate, or via the named factories in {@link
+ * edu.wpi.first.wpilibj2.command.button.CommandGenericHID}'s subclasses for {@link
+ * CommandXboxController Xbox}/{@link edu.wpi.first.wpilibj2.command.button.CommandPS4Controller
+ * PS4} controllers or {@link edu.wpi.first.wpilibj2.command.button.CommandJoystick Flight
+ * joysticks}.
*/
- private void configureButtonBindings() {}
+ private void configureBindings() {
+ // Schedule `ExampleCommand` when `exampleCondition` changes to `true`
+ new Trigger(m_exampleSubsystem::exampleCondition)
+ .onTrue(new ExampleCommand(m_exampleSubsystem));
+
+ // Schedule `exampleMethodCommand` when the Xbox controller's B button is pressed,
+ // cancelling on release.
+ m_driverController.b().whileTrue(m_exampleSubsystem.exampleMethodCommand());
+ }
/**
* Use this to pass the autonomous command to the main {@link Robot} class.
@@ -42,7 +57,7 @@
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
- // An ExampleCommand will run in autonomous
- return m_autoCommand;
+ // An example command will be run in autonomous
+ return Autos.exampleAuto(m_exampleSubsystem);
}
}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/commands/Autos.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/commands/Autos.java
new file mode 100644
index 0000000..330a4ae
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/commands/Autos.java
@@ -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.wpilibj.templates.commandbased.commands;
+
+import edu.wpi.first.wpilibj.templates.commandbased.subsystems.ExampleSubsystem;
+import edu.wpi.first.wpilibj2.command.CommandBase;
+import edu.wpi.first.wpilibj2.command.Commands;
+
+public final class Autos {
+ /** Example static factory for an autonomous command. */
+ public static CommandBase exampleAuto(ExampleSubsystem subsystem) {
+ return Commands.sequence(subsystem.exampleMethodCommand(), new ExampleCommand(subsystem));
+ }
+
+ private Autos() {
+ throw new UnsupportedOperationException("This is a utility class!");
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java
index 8a3594b..57d86cc 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java
@@ -4,12 +4,37 @@
package edu.wpi.first.wpilibj.templates.commandbased.subsystems;
+import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class ExampleSubsystem extends SubsystemBase {
/** Creates a new ExampleSubsystem. */
public ExampleSubsystem() {}
+ /**
+ * Example command factory method.
+ *
+ * @return a command
+ */
+ public CommandBase exampleMethodCommand() {
+ // Inline construction of command goes here.
+ // Subsystem::RunOnce implicitly requires `this` subsystem.
+ return runOnce(
+ () -> {
+ /* one-time action goes here */
+ });
+ }
+
+ /**
+ * An example method querying a boolean state of the subsystem (for example, a digital sensor).
+ *
+ * @return value of some boolean subsystem state, such as a digital sensor.
+ */
+ public boolean exampleCondition() {
+ // Query some boolean state, such as a digital sensor.
+ return false;
+ }
+
@Override
public void periodic() {
// This method will be called once per scheduler run
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Main.java
new file mode 100644
index 0000000..efa0c2e
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Main.java
@@ -0,0 +1,15 @@
+// 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.wpilibj.templates.commandbasedskeleton;
+
+import edu.wpi.first.wpilibj.RobotBase;
+
+public final class Main {
+ private Main() {}
+
+ public static void main(String... args) {
+ RobotBase.startRobot(Robot::new);
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Robot.java
new file mode 100644
index 0000000..f682ec8
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Robot.java
@@ -0,0 +1,73 @@
+// 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.wpilibj.templates.commandbasedskeleton;
+
+import edu.wpi.first.wpilibj.TimedRobot;
+import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.CommandScheduler;
+
+public class Robot extends TimedRobot {
+ private Command m_autonomousCommand;
+
+ private RobotContainer m_robotContainer;
+
+ @Override
+ public void robotInit() {
+ m_robotContainer = new RobotContainer();
+ }
+
+ @Override
+ public void robotPeriodic() {
+ CommandScheduler.getInstance().run();
+ }
+
+ @Override
+ public void disabledInit() {}
+
+ @Override
+ public void disabledPeriodic() {}
+
+ @Override
+ public void disabledExit() {}
+
+ @Override
+ public void autonomousInit() {
+ m_autonomousCommand = m_robotContainer.getAutonomousCommand();
+
+ if (m_autonomousCommand != null) {
+ m_autonomousCommand.schedule();
+ }
+ }
+
+ @Override
+ public void autonomousPeriodic() {}
+
+ @Override
+ public void autonomousExit() {}
+
+ @Override
+ public void teleopInit() {
+ if (m_autonomousCommand != null) {
+ m_autonomousCommand.cancel();
+ }
+ }
+
+ @Override
+ public void teleopPeriodic() {}
+
+ @Override
+ public void teleopExit() {}
+
+ @Override
+ public void testInit() {
+ CommandScheduler.getInstance().cancelAll();
+ }
+
+ @Override
+ public void testPeriodic() {}
+
+ @Override
+ public void testExit() {}
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/RobotContainer.java
new file mode 100644
index 0000000..d6e4d25
--- /dev/null
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/RobotContainer.java
@@ -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.wpilibj.templates.commandbasedskeleton;
+
+import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.Commands;
+
+public class RobotContainer {
+ public RobotContainer() {
+ configureBindings();
+ }
+
+ private void configureBindings() {}
+
+ public Command getAutonomousCommand() {
+ return Commands.print("No autonomous command configured");
+ }
+}
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java
index 76d13a4..bb40caa 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java
@@ -4,9 +4,11 @@
package edu.wpi.first.wpilibj.templates.educational;
-import edu.wpi.first.hal.HAL;
+import edu.wpi.first.hal.DriverStationJNI;
+import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.RobotBase;
+import edu.wpi.first.wpilibj.internal.DriverStationModeThread;
/** Educational robot base class. */
public class EducationalRobot extends RobotBase {
@@ -34,40 +36,65 @@
public void startCompetition() {
robotInit();
+ DriverStationModeThread modeThread = new DriverStationModeThread();
+
+ int event = WPIUtilJNI.createEvent(false, false);
+
+ DriverStation.provideRefreshedDataEventHandle(event);
+
// Tell the DS that the robot is ready to be enabled
- HAL.observeUserProgramStarting();
+ DriverStationJNI.observeUserProgramStarting();
while (!Thread.currentThread().isInterrupted() && !m_exit) {
if (isDisabled()) {
- DriverStation.inDisabled(true);
+ modeThread.inDisabled(true);
disabled();
- DriverStation.inDisabled(false);
+ modeThread.inDisabled(false);
while (isDisabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else if (isAutonomous()) {
- DriverStation.inAutonomous(true);
+ modeThread.inAutonomous(true);
autonomous();
- DriverStation.inAutonomous(false);
+ modeThread.inAutonomous(false);
while (isAutonomousEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else if (isTest()) {
- DriverStation.inTest(true);
+ modeThread.inTest(true);
test();
- DriverStation.inTest(false);
+ modeThread.inTest(false);
while (isTest() && isEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else {
- DriverStation.inTeleop(true);
+ modeThread.inTeleop(true);
teleop();
- DriverStation.inTeleop(false);
+ modeThread.inTeleop(false);
while (isTeleopEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
}
}
+
+ DriverStation.removeRefreshedDataEventHandle(event);
+ modeThread.close();
}
@Override
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java
index 787395c..f089864 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java
@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj.templates.robotbaseskeleton;
-import edu.wpi.first.hal.HAL;
+import edu.wpi.first.hal.DriverStationJNI;
+import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.RobotBase;
-import edu.wpi.first.wpilibj.livewindow.LiveWindow;
-import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
+import edu.wpi.first.wpilibj.internal.DriverStationModeThread;
/**
* The VM is configured to automatically run this class. If you change the name of this class or the
@@ -31,44 +31,65 @@
public void startCompetition() {
robotInit();
+ DriverStationModeThread modeThread = new DriverStationModeThread();
+
+ int event = WPIUtilJNI.createEvent(false, false);
+
+ DriverStation.provideRefreshedDataEventHandle(event);
+
// Tell the DS that the robot is ready to be enabled
- HAL.observeUserProgramStarting();
+ DriverStationJNI.observeUserProgramStarting();
while (!Thread.currentThread().isInterrupted() && !m_exit) {
if (isDisabled()) {
- DriverStation.inDisabled(true);
+ modeThread.inDisabled(true);
disabled();
- DriverStation.inDisabled(false);
+ modeThread.inDisabled(false);
while (isDisabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else if (isAutonomous()) {
- DriverStation.inAutonomous(true);
+ modeThread.inAutonomous(true);
autonomous();
- DriverStation.inAutonomous(false);
+ modeThread.inAutonomous(false);
while (isAutonomousEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else if (isTest()) {
- LiveWindow.setEnabled(true);
- Shuffleboard.enableActuatorWidgets();
- DriverStation.inTest(true);
+ modeThread.inTest(true);
test();
- DriverStation.inTest(false);
+ modeThread.inTest(false);
while (isTest() && isEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
- LiveWindow.setEnabled(false);
- Shuffleboard.disableActuatorWidgets();
} else {
- DriverStation.inTeleop(true);
+ modeThread.inTeleop(true);
teleop();
- DriverStation.inTeleop(false);
+ modeThread.inTeleop(false);
while (isTeleopEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
}
}
+
+ DriverStation.removeRefreshedDataEventHandle(event);
+ modeThread.close();
}
@Override
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/EducationalRobot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/EducationalRobot.java
index 8fed60d..5a84915 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/EducationalRobot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romieducational/EducationalRobot.java
@@ -4,9 +4,11 @@
package edu.wpi.first.wpilibj.templates.romieducational;
-import edu.wpi.first.hal.HAL;
+import edu.wpi.first.hal.DriverStationJNI;
+import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.RobotBase;
+import edu.wpi.first.wpilibj.internal.DriverStationModeThread;
/** Educational robot base class. */
public class EducationalRobot extends RobotBase {
@@ -34,40 +36,65 @@
public void startCompetition() {
robotInit();
+ DriverStationModeThread modeThread = new DriverStationModeThread();
+
+ int event = WPIUtilJNI.createEvent(false, false);
+
+ DriverStation.provideRefreshedDataEventHandle(event);
+
// Tell the DS that the robot is ready to be enabled
- HAL.observeUserProgramStarting();
+ DriverStationJNI.observeUserProgramStarting();
while (!Thread.currentThread().isInterrupted() && !m_exit) {
if (isDisabled()) {
- DriverStation.inDisabled(true);
+ modeThread.inDisabled(true);
disabled();
- DriverStation.inDisabled(false);
+ modeThread.inDisabled(false);
while (isDisabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else if (isAutonomous()) {
- DriverStation.inAutonomous(true);
+ modeThread.inAutonomous(true);
autonomous();
- DriverStation.inAutonomous(false);
+ modeThread.inAutonomous(false);
while (isAutonomousEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else if (isTest()) {
- DriverStation.inTest(true);
+ modeThread.inTest(true);
test();
- DriverStation.inTest(false);
+ modeThread.inTest(false);
while (isTest() && isEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
} else {
- DriverStation.inTeleop(true);
+ modeThread.inTeleop(true);
teleop();
- DriverStation.inTeleop(false);
+ modeThread.inTeleop(false);
while (isTeleopEnabled()) {
- DriverStation.waitForData();
+ try {
+ WPIUtilJNI.waitForObject(event);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
}
}
}
+
+ DriverStation.removeRefreshedDataEventHandle(event);
+ modeThread.close();
}
@Override
diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json
index b2484cc..68e3bfb 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json
@@ -11,6 +11,17 @@
"commandversion": 2
},
{
+ "name": "Command Robot Skeleton (Advanced)",
+ "description": "Skeleton (stub) code for Command Robot",
+ "tags": [
+ "Command", "Skeleton"
+ ],
+ "foldername": "commandbasedskeleton",
+ "gradlebase": "java",
+ "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
"name": "Timed Robot",
"description": "Timed style",
"tags": [
diff --git a/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/addressableled/RainbowTest.java b/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/addressableled/RainbowTest.java
new file mode 100644
index 0000000..90acfb0
--- /dev/null
+++ b/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/addressableled/RainbowTest.java
@@ -0,0 +1,54 @@
+// 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.wpilibj.examples.addressableled;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.wpilibj.simulation.AddressableLEDSim;
+import edu.wpi.first.wpilibj.util.Color;
+import edu.wpi.first.wpilibj.util.Color8Bit;
+import org.junit.jupiter.api.Test;
+
+class RainbowTest {
+ @Test
+ void rainbowPatternTest() {
+ HAL.initialize(500, 0);
+ try (var robot = new Robot()) {
+ robot.robotInit();
+ AddressableLEDSim ledSim = AddressableLEDSim.createForChannel(9);
+ assertTrue(ledSim.getRunning());
+ assertEquals(60, ledSim.getLength());
+
+ var rainbowFirstPixelHue = 0;
+ for (int iteration = 0; iteration < 100; iteration++) {
+ robot.robotPeriodic();
+ var data = ledSim.getData();
+ for (int i = 0; i < 60; i++) {
+ final var hue = (rainbowFirstPixelHue + (i * 180 / 60)) % 180;
+ assertIndexColor(data, i, hue, 255, 128);
+ }
+ rainbowFirstPixelHue += 3;
+ rainbowFirstPixelHue %= 180;
+ }
+ }
+ }
+
+ private void assertIndexColor(byte[] data, int index, int hue, int saturation, int value) {
+ var color = new Color8Bit(Color.fromHSV(hue, saturation, value));
+ int b = data[index * 4];
+ int g = data[(index * 4) + 1];
+ int r = data[(index * 4) + 2];
+ int z = data[(index * 4) + 3];
+
+ assertAll(
+ () -> assertEquals(0, z),
+ () -> assertEquals(color.red, r & 0xFF),
+ () -> assertEquals(color.green, g & 0xFF),
+ () -> assertEquals(color.blue, b & 0xFF));
+ }
+}
diff --git a/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/IntakeTest.java b/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/IntakeTest.java
new file mode 100644
index 0000000..33be835
--- /dev/null
+++ b/wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/IntakeTest.java
@@ -0,0 +1,70 @@
+// 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.wpilibj.examples.unittest.subsystems;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.wpilibj.DoubleSolenoid;
+import edu.wpi.first.wpilibj.PneumaticsModuleType;
+import edu.wpi.first.wpilibj.examples.unittest.Constants.IntakeConstants;
+import edu.wpi.first.wpilibj.simulation.DoubleSolenoidSim;
+import edu.wpi.first.wpilibj.simulation.PWMSim;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class IntakeTest {
+ static final double DELTA = 1e-2; // acceptable deviation range
+ Intake m_intake;
+ PWMSim m_simMotor;
+ DoubleSolenoidSim m_simPiston;
+
+ @BeforeEach // this method will run before each test
+ void setup() {
+ assert HAL.initialize(500, 0); // initialize the HAL, crash if failed
+ m_intake = new Intake(); // create our intake
+ m_simMotor =
+ new PWMSim(IntakeConstants.kMotorPort); // create our simulation PWM motor controller
+ m_simPiston =
+ new DoubleSolenoidSim(
+ PneumaticsModuleType.CTREPCM,
+ IntakeConstants.kPistonFwdChannel,
+ IntakeConstants.kPistonRevChannel); // create our simulation solenoid
+ }
+
+ @SuppressWarnings("PMD.SignatureDeclareThrowsException")
+ @AfterEach // this method will run after each test
+ void shutdown() throws Exception {
+ m_intake.close(); // destroy our intake object
+ }
+
+ @Test // marks this method as a test
+ void doesntWorkWhenClosed() {
+ m_intake.retract(); // close the intake
+ m_intake.activate(0.5); // try to activate the motor
+ assertEquals(
+ 0.0, m_simMotor.getSpeed(), DELTA); // make sure that the value set to the motor is 0
+ }
+
+ @Test
+ void worksWhenOpen() {
+ m_intake.deploy();
+ m_intake.activate(0.5);
+ assertEquals(0.5, m_simMotor.getSpeed(), DELTA);
+ }
+
+ @Test
+ void retractTest() {
+ m_intake.retract();
+ assertEquals(DoubleSolenoid.Value.kReverse, m_simPiston.get());
+ }
+
+ @Test
+ void deployTest() {
+ m_intake.deploy();
+ assertEquals(DoubleSolenoid.Value.kForward, m_simPiston.get());
+ }
+}