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/wpilibcExamples/CMakeLists.txt b/wpilibcExamples/CMakeLists.txt
index 27cff6b..3b2413d 100644
--- a/wpilibcExamples/CMakeLists.txt
+++ b/wpilibcExamples/CMakeLists.txt
@@ -10,13 +10,16 @@
file(GLOB_RECURSE sources src/main/cpp/examples/${example}/cpp/*.cpp
src/main/cpp/examples/${example}/c/*.c)
add_executable(${example} ${sources})
+ wpilib_target_warnings(${example})
target_include_directories(${example} PUBLIC src/main/cpp/examples/${example}/include)
- target_link_libraries(${example} wpilibc wpilibNewCommands wpilibOldCommands)
+ target_link_libraries(${example} wpilibc wpilibNewCommands)
if (WITH_TESTS AND EXISTS ${CMAKE_SOURCE_DIR}/wpilibcExamples/src/test/cpp/examples/${example})
wpilib_add_test(${example} src/test/cpp/examples/${example}/cpp)
target_sources(${example}_test PRIVATE ${sources})
- target_include_directories(${example}_test PRIVATE src/test/cpp/examples/${example}/include)
+ target_include_directories(${example}_test PRIVATE
+ src/main/cpp/examples/${example}/include
+ src/test/cpp/examples/${example}/include)
target_compile_definitions(${example}_test PUBLIC RUNNING_FRC_TESTS)
target_link_libraries(${example}_test wpilibc wpilibNewCommands gmock_main)
endif()
@@ -26,6 +29,7 @@
file(GLOB_RECURSE sources src/main/cpp/templates/${template}/cpp/*.cpp
src/main/cpp/templates/${template}/c/*.c)
add_executable(${template} ${sources})
+ wpilib_target_warnings(${template})
target_include_directories(${template} PUBLIC src/main/cpp/templates/${template}/include)
target_link_libraries(${template} wpilibc wpilibNewCommands)
endforeach()
diff --git a/wpilibcExamples/build.gradle b/wpilibcExamples/build.gradle
index 7561ed5..2ca6038 100644
--- a/wpilibcExamples/build.gradle
+++ b/wpilibcExamples/build.gradle
@@ -34,11 +34,6 @@
templatesMap.put(it, [])
}
-nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
- cppCompiler.args.remove('-Wno-error=deprecated-declarations')
- cppCompiler.args.add('-Werror=deprecated-declarations')
-}
-
nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.windowsx64).configure {
linker.args.remove('/DEBUG:FULL')
cppCompiler.debugArgs.remove('/Zi')
@@ -64,14 +59,15 @@
binary.buildable = false
return
}
- lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
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: ':ntcore', library: 'ntcore', linkage: 'shared'
+ project(':ntcore').addNtcoreDependency(binary, 'shared')
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(binary, 'shared')
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
+ lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
}
sources {
@@ -94,11 +90,13 @@
binaries.all { binary ->
lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
+ lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
- lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
+ project(':ntcore').addNtcoreDependency(binary, 'shared')
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(binary, 'shared')
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
+ lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
@@ -141,19 +139,14 @@
binaries.all { binary ->
lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
+ lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
- lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
+ project(':ntcore').addNtcoreDependency(binary, 'shared')
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(binary, 'shared')
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
+ lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
- binary.tasks.withType(CppCompile) {
- if (!(binary.toolChain in VisualCpp)) {
- cppCompiler.args "-Wno-error=deprecated-declarations"
- } else {
- cppCompiler.args "/wd4996"
- }
- }
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
}
@@ -212,11 +205,13 @@
withType(GoogleTestTestSuiteBinarySpec) {
lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
+ lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
- lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
+ project(':ntcore').addNtcoreDependency(it, 'shared')
lib project: ':cscore', library: 'cscore', linkage: 'shared'
project(':hal').addHalDependency(it, 'shared')
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
+ lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
diff --git a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp
deleted file mode 100644
index 24726b0..0000000
--- a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp
+++ /dev/null
@@ -1,28 +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.
-
-#include "ReplaceMeCommand.h"
-
-ReplaceMeCommand::ReplaceMeCommand() {
- // Use Requires() here to declare subsystem dependencies
- // eg. Requires(Robot::chassis.get());
-}
-
-// Called just before this Command runs the first time
-void ReplaceMeCommand::Initialize() {}
-
-// Called repeatedly when this Command is scheduled to run
-void ReplaceMeCommand::Execute() {}
-
-// Make this return true when this Command no longer needs to run execute()
-bool ReplaceMeCommand::IsFinished() {
- return false;
-}
-
-// Called once after isFinished returns true
-void ReplaceMeCommand::End() {}
-
-// Called when another command which requires one or more of the same
-// subsystems is scheduled to run
-void ReplaceMeCommand::Interrupted() {}
diff --git a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h
deleted file mode 100644
index 64fcd26..0000000
--- a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h
+++ /dev/null
@@ -1,17 +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.
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-class ReplaceMeCommand : public frc::Command {
- public:
- ReplaceMeCommand();
- void Initialize() override;
- void Execute() override;
- bool IsFinished() override;
- void End() override;
- void Interrupted() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp
deleted file mode 100644
index ced938d..0000000
--- a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp
+++ /dev/null
@@ -1,24 +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.
-
-#include "ReplaceMeCommandGroup.h"
-
-ReplaceMeCommandGroup::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/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h
deleted file mode 100644
index c51a964..0000000
--- a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h
+++ /dev/null
@@ -1,12 +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.
-
-#pragma once
-
-#include <frc/commands/CommandGroup.h>
-
-class ReplaceMeCommandGroup : public frc::CommandGroup {
- public:
- ReplaceMeCommandGroup();
-};
diff --git a/wpilibcExamples/src/main/cpp/commands/commands.json b/wpilibcExamples/src/main/cpp/commands/commands.json
index 6b5bf1e..7f0c8f9 100644
--- a/wpilibcExamples/src/main/cpp/commands/commands.json
+++ b/wpilibcExamples/src/main/cpp/commands/commands.json
@@ -16,120 +16,7 @@
"commandversion": 0
},
{
- "name": "Command (Old)",
- "description": "Create a base command",
- "tags": [
- "command"
- ],
- "foldername": "command",
- "headers": [
- "ReplaceMeCommand.h"
- ],
- "source": [
- "ReplaceMeCommand.cpp"
- ],
- "replacename": "ReplaceMeCommand",
- "commandversion": 1
- },
- {
- "name": "Command Group (Old)",
- "description": "Create a command group",
- "tags": [
- "commandgroup"
- ],
- "foldername": "commandgroup",
- "headers": [
- "ReplaceMeCommandGroup.h"
- ],
- "source": [
- "ReplaceMeCommandGroup.cpp"
- ],
- "replacename": "ReplaceMeCommandGroup",
- "commandversion": 1
- },
- {
- "name": "Instant Command (Old)",
- "description": "A command that runs immediately",
- "tags": [
- "instantcommand"
- ],
- "foldername": "instant",
- "headers": [
- "ReplaceMeInstantCommand.h"
- ],
- "source": [
- "ReplaceMeInstantCommand.cpp"
- ],
- "replacename": "ReplaceMeInstantCommand",
- "commandversion": 1
- },
- {
- "name": "Subsystem (Old)",
- "description": "A subsystem",
- "tags": [
- "subsystem"
- ],
- "foldername": "subsystem",
- "headers": [
- "ReplaceMeSubsystem.h"
- ],
- "source": [
- "ReplaceMeSubsystem.cpp"
- ],
- "replacename": "ReplaceMeSubsystem",
- "commandversion": 1
- },
- {
- "name": "PID Subsystem (Old)",
- "description": "A subsystem that runs a PID loop",
- "tags": [
- "pidsubsystem",
- "pid"
- ],
- "foldername": "pidsubsystem",
- "headers": [
- "ReplaceMePIDSubsystem.h"
- ],
- "source": [
- "ReplaceMePIDSubsystem.cpp"
- ],
- "replacename": "ReplaceMePIDSubsystem",
- "commandversion": 1
- },
- {
- "name": "Timed Command (Old)",
- "description": "A command that runs for a specified time",
- "tags": [
- "timedcommand"
- ],
- "foldername": "timed",
- "headers": [
- "ReplaceMeTimedCommand.h"
- ],
- "source": [
- "ReplaceMeTimedCommand.cpp"
- ],
- "replacename": "ReplaceMeTimedCommand",
- "commandversion": 1
- },
- {
- "name": "Trigger (Old)",
- "description": "A command that runs off of a trigger",
- "tags": [
- "trigger"
- ],
- "foldername": "trigger",
- "headers": [
- "ReplaceMeTrigger.h"
- ],
- "source": [
- "ReplaceMeTrigger.cpp"
- ],
- "replacename": "ReplaceMeTrigger",
- "commandversion": 1
- },
- {
- "name": "Command (New)",
+ "name": "Command",
"description": "A command.",
"tags": [
"command"
@@ -145,7 +32,7 @@
"commandversion": 2
},
{
- "name": "InstantCommand (New)",
+ "name": "InstantCommand",
"description": "A command that finishes instantly.",
"tags": [
"instantcommand"
@@ -161,7 +48,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"
@@ -177,7 +64,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"
@@ -193,7 +80,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"
@@ -209,7 +96,7 @@
"commandversion": 2
},
{
- "name": "PIDCommand (New)",
+ "name": "PIDCommand",
"description": "A command that runs a PIDController.",
"tags": [
"pidcommand"
@@ -225,7 +112,7 @@
"commandversion": 2
},
{
- "name": "PIDSubsystem (New)",
+ "name": "PIDSubsystem",
"description": "A subsystem that runs a PIDController.",
"tags": [
"pidsubsystem"
@@ -241,7 +128,7 @@
"commandversion": 2
},
{
- "name": "ProfiledPIDCommand (New)",
+ "name": "ProfiledPIDCommand",
"description": "A command that runs a ProfiledPIDController.",
"tags": [
"profiledpidcommand"
@@ -257,7 +144,7 @@
"commandversion": 2
},
{
- "name": "ProfiledPIDSubsystem (New)",
+ "name": "ProfiledPIDSubsystem",
"description": "A subsystem that runs a ProfiledPIDController.",
"tags": [
"profiledpidsubsystem"
@@ -273,7 +160,7 @@
"commandversion": 2
},
{
- "name": "SequentialCommandGroup (New)",
+ "name": "SequentialCommandGroup",
"description": "A command group that runs commands in sequence.",
"tags": [
"sequentialcommandgroup"
@@ -289,7 +176,7 @@
"commandversion": 2
},
{
- "name": "Subsystem (New)",
+ "name": "Subsystem",
"description": "A robot subsystem.",
"tags": [
"subsystem"
@@ -305,7 +192,7 @@
"commandversion": 2
},
{
- "name": "TrapezoidProfileCommand (New)",
+ "name": "TrapezoidProfileCommand",
"description": "A command that executes a trapezoidal motion profile.",
"tags": [
"trapezoidprofilecommand"
@@ -321,7 +208,7 @@
"commandversion": 2
},
{
- "name": "TrapezoidProfileSubsystem (New)",
+ "name": "TrapezoidProfileSubsystem",
"description": "A subsystem that executes a trapezoidal motion profile.",
"tags": [
"trapezoidprofilesubsystem"
diff --git a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp
deleted file mode 100644
index 1a80288..0000000
--- a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp
+++ /dev/null
@@ -1,13 +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.
-
-#include "ReplaceMeInstantCommand.h"
-
-ReplaceMeInstantCommand::ReplaceMeInstantCommand() {
- // Use Requires() here to declare subsystem dependencies
- // eg. Requires(Robot::chassis.get());
-}
-
-// Called once when the command executes
-void ReplaceMeInstantCommand::Initialize() {}
diff --git a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h
deleted file mode 100644
index c73cbcf..0000000
--- a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h
+++ /dev/null
@@ -1,13 +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.
-
-#pragma once
-
-#include <frc/commands/InstantCommand.h>
-
-class ReplaceMeInstantCommand : public frc::InstantCommand {
- public:
- ReplaceMeInstantCommand();
- void Initialize() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp
index e814a09..3a387ff 100644
--- a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp
@@ -9,5 +9,5 @@
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
ReplaceMeParallelCommandGroup::ReplaceMeParallelCommandGroup() {
// Add your commands here, e.g.
- // AddCommands(FooCommand(), BarCommand());
+ // AddCommands(FooCommand{}, BarCommand{});
}
diff --git a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp
index 67c12a3..f664e55 100644
--- a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp
@@ -10,9 +10,8 @@
// For more information, see:
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
ReplaceMeParallelDeadlineGroup::ReplaceMeParallelDeadlineGroup()
- : CommandHelper(
- // The deadline command
- frc2::InstantCommand([] {})) {
+ // The deadline command
+ : CommandHelper{frc2::InstantCommand{[] {}}} {
// Add your commands here, e.g.
- // AddCommands(FooCommand(), BarCommand());
+ // AddCommands(FooCommand{}, BarCommand{});
}
diff --git a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp
index 9cc3784..f51433c 100644
--- a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp
@@ -9,5 +9,5 @@
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
ReplaceMeParallelRaceGroup::ReplaceMeParallelRaceGroup() {
// Add your commands here, e.g.
- // AddCommands(FooCommand(), BarCommand());
+ // AddCommands(FooCommand{}, BarCommand{});
}
diff --git a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp
index 1bcc830..4a7d0e1 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp
@@ -8,16 +8,15 @@
// For more information, see:
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
ReplaceMePIDCommand::ReplaceMePIDCommand()
- : CommandHelper(
- frc2::PIDController(0, 0, 0),
- // This should return the measurement
- [] { return 0; },
- // This should return the setpoint (can also be a constant)
- [] { return 0; },
- // This uses the output
- [](double output) {
- // Use the output here
- }) {}
+ : CommandHelper{frc2::PIDController{0, 0, 0},
+ // This should return the measurement
+ [] { return 0; },
+ // This should return the setpoint (can also be a constant)
+ [] { return 0; },
+ // This uses the output
+ [](double output) {
+ // Use the output here
+ }} {}
// Returns true when the command should end.
bool ReplaceMePIDCommand::IsFinished() {
diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp
deleted file mode 100644
index 7b44893..0000000
--- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp
+++ /dev/null
@@ -1,33 +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.
-
-#include "ReplaceMePIDSubsystem.h"
-
-#include <frc/livewindow/LiveWindow.h>
-#include <frc/smartdashboard/SmartDashboard.h>
-
-ReplaceMePIDSubsystem::ReplaceMePIDSubsystem()
- : PIDSubsystem("ReplaceMePIDSubsystem", 1.0, 0.0, 0.0) {
- // Use these to get going:
- // SetSetpoint() - Sets where the PID controller should move the system
- // to
- // Enable() - Enables the PID controller.
-}
-
-double ReplaceMePIDSubsystem::ReturnPIDInput() {
- // Return your input value for the PID loop
- // e.g. a sensor, like a potentiometer:
- // yourPot->SetAverageVoltage() / kYourMaxVoltage;
- return 0;
-}
-
-void ReplaceMePIDSubsystem::UsePIDOutput(double output) {
- // Use output to drive your system, like a motor
- // e.g. yourMotor->Set(output);
-}
-
-void ReplaceMePIDSubsystem::InitDefaultCommand() {
- // Set the default command for a subsystem here.
- // SetDefaultCommand(new MySpecialCommand());
-}
diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h
deleted file mode 100644
index f9aabc9..0000000
--- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h
+++ /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.
-
-#pragma once
-
-#include <frc/commands/PIDSubsystem.h>
-
-class ReplaceMePIDSubsystem : public frc::PIDSubsystem {
- public:
- ReplaceMePIDSubsystem();
- double ReturnPIDInput() override;
- void UsePIDOutput(double output) override;
- void InitDefaultCommand() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp
index 2cdce1b..749b106 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp
@@ -5,9 +5,8 @@
#include "ReplaceMePIDSubsystem2.h"
ReplaceMePIDSubsystem2::ReplaceMePIDSubsystem2()
- : PIDSubsystem(
- // The PIDController used by the subsystem
- frc2::PIDController(0, 0, 0)) {}
+ // The PIDController used by the subsystem
+ : PIDSubsystem{frc2::PIDController{0, 0, 0}} {}
void ReplaceMePIDSubsystem2::UseOutput(double output, double setpoint) {
// Use the output here
diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp
index 880a222..f3fd26a 100644
--- a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp
@@ -11,13 +11,15 @@
// For more information, see:
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
ReplaceMeProfiledPIDCommand::ReplaceMeProfiledPIDCommand()
- : CommandHelper(
+ : CommandHelper{
// The ProfiledPIDController that the command will use
- frc::ProfiledPIDController<units::meters>(
+ frc::ProfiledPIDController<units::meters>{
// The PID gains
- 0, 0, 0,
+ 0,
+ 0,
+ 0,
// The motion profile constraints
- {0_mps, 0_mps_sq}),
+ {0_mps, 0_mps_sq}},
// This should return the measurement
[] { return 0_m; },
// This should return the goal state (can also be a constant)
@@ -28,7 +30,7 @@
[](double output,
frc::TrapezoidProfile<units::meters>::State setpoint) {
// Use the output and setpoint here
- }) {}
+ }} {}
// Returns true when the command should end.
bool ReplaceMeProfiledPIDCommand::IsFinished() {
diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp
index d65a867..2ee899c 100644
--- a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp
@@ -8,13 +8,14 @@
#include <units/velocity.h>
ReplaceMeProfiledPIDSubsystem::ReplaceMeProfiledPIDSubsystem()
- : ProfiledPIDSubsystem(
- // The ProfiledPIDController used by the subsystem
- frc::ProfiledPIDController<units::meters>(
- // The PID gains
- 0, 0, 0,
- // The constraints for the motion profiles
- {0_mps, 0_mps_sq})) {}
+ // The ProfiledPIDController used by the subsystem
+ : ProfiledPIDSubsystem{frc::ProfiledPIDController<units::meters>{
+ // The PID gains
+ 0,
+ 0,
+ 0,
+ // The constraints for the motion profiles
+ {0_mps, 0_mps_sq}}} {}
void ReplaceMeProfiledPIDSubsystem::UseOutput(
double output, frc::TrapezoidProfile<units::meters>::State setpoint) {
diff --git a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp
index c83a99d..cc2504c 100644
--- a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp
@@ -9,5 +9,5 @@
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
ReplaceMeSequentialCommandGroup::ReplaceMeSequentialCommandGroup() {
// Add your commands here, e.g.
- // AddCommands(FooCommand(), BarCommand());
+ // AddCommands(FooCommand{}, BarCommand{});
}
diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp
deleted file mode 100644
index ca589f1..0000000
--- a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp
+++ /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.
-
-#include "ReplaceMeSubsystem.h"
-
-ReplaceMeSubsystem::ReplaceMeSubsystem() : Subsystem("ExampleSubsystem") {}
-
-void ReplaceMeSubsystem::InitDefaultCommand() {
- // Set the default command for a subsystem here.
- // SetDefaultCommand(new MySpecialCommand());
-}
-
-// Put methods for controlling this subsystem
-// here. Call these from Commands.
diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h
deleted file mode 100644
index 3de6031..0000000
--- a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h
+++ /dev/null
@@ -1,17 +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.
-
-#pragma once
-
-#include <frc/commands/Subsystem.h>
-
-class ReplaceMeSubsystem : public frc::Subsystem {
- private:
- // It's desirable that everything possible under private except
- // for methods that implement subsystem capabilities
-
- public:
- ReplaceMeSubsystem();
- void InitDefaultCommand() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp
deleted file mode 100644
index c6793e0..0000000
--- a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp
+++ /dev/null
@@ -1,24 +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.
-
-#include "ReplaceMeTimedCommand.h"
-
-ReplaceMeTimedCommand::ReplaceMeTimedCommand(units::second_t timeout)
- : TimedCommand(timeout) {
- // Use Requires() here to declare subsystem dependencies
- // eg. Requires(Robot::chassis.get());
-}
-
-// Called just before this Command runs the first time
-void ReplaceMeTimedCommand::Initialize() {}
-
-// Called repeatedly when this Command is scheduled to run
-void ReplaceMeTimedCommand::Execute() {}
-
-// Called once after command times out
-void ReplaceMeTimedCommand::End() {}
-
-// Called when another command which requires one or more of the same
-// subsystems is scheduled to run
-void ReplaceMeTimedCommand::Interrupted() {}
diff --git a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h
deleted file mode 100644
index 48cfa2d..0000000
--- a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h
+++ /dev/null
@@ -1,17 +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.
-
-#pragma once
-
-#include <frc/commands/TimedCommand.h>
-#include <units/time.h>
-
-class ReplaceMeTimedCommand : public frc::TimedCommand {
- public:
- explicit ReplaceMeTimedCommand(units::second_t timeout);
- void Initialize() override;
- void Execute() override;
- void End() override;
- void Interrupted() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp
deleted file mode 100644
index 3c563ff..0000000
--- a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp
+++ /dev/null
@@ -1,11 +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.
-
-#include "ReplaceMeTrigger.h"
-
-ReplaceMeTrigger::ReplaceMeTrigger() = default;
-
-bool ReplaceMeTrigger::Get() {
- return false;
-}
diff --git a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h
deleted file mode 100644
index a76dcd9..0000000
--- a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h
+++ /dev/null
@@ -1,13 +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.
-
-#pragma once
-
-#include <frc/buttons/Trigger.h>
-
-class ReplaceMeTrigger : public frc::Trigger {
- public:
- ReplaceMeTrigger();
- bool Get() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp
index d59b370..d3356c6 100644
--- a/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp
@@ -2,54 +2,37 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
-#include <array>
+#include "Robot.h"
-#include <frc/AddressableLED.h>
-#include <frc/TimedRobot.h>
-#include <frc/smartdashboard/SmartDashboard.h>
+void Robot::RobotInit() {
+ // Default to a length of 60, start empty output
+ // Length is expensive to set, so only set it once, then just update data
+ m_led.SetLength(kLength);
+ m_led.SetData(m_ledBuffer);
+ m_led.Start();
+}
-class Robot : public frc::TimedRobot {
- static constexpr int kLength = 60;
+void Robot::RobotPeriodic() {
+ // Fill the buffer with a rainbow
+ Rainbow();
+ // Set the LEDs
+ m_led.SetData(m_ledBuffer);
+}
- // PWM port 9
- // Must be a PWM header, not MXP or DIO
- frc::AddressableLED m_led{9};
- std::array<frc::AddressableLED::LEDData, kLength>
- m_ledBuffer; // Reuse the buffer
- // Store what the last hue of the first pixel is
- int firstPixelHue = 0;
-
- public:
- void Rainbow() {
- // For every pixel
- for (int i = 0; i < kLength; i++) {
- // Calculate the hue - hue is easier for rainbows because the color
- // shape is a circle so only one value needs to precess
- const auto pixelHue = (firstPixelHue + (i * 180 / kLength)) % 180;
- // Set the value
- m_ledBuffer[i].SetHSV(pixelHue, 255, 128);
- }
- // Increase by to make the rainbow "move"
- firstPixelHue += 3;
- // Check bounds
- firstPixelHue %= 180;
+void Robot::Rainbow() {
+ // For every pixel
+ for (int i = 0; i < kLength; i++) {
+ // Calculate the hue - hue is easier for rainbows because the color
+ // shape is a circle so only one value needs to precess
+ const auto pixelHue = (firstPixelHue + (i * 180 / kLength)) % 180;
+ // Set the value
+ m_ledBuffer[i].SetHSV(pixelHue, 255, 128);
}
-
- void RobotInit() override {
- // Default to a length of 60, start empty output
- // Length is expensive to set, so only set it once, then just update data
- m_led.SetLength(kLength);
- m_led.SetData(m_ledBuffer);
- m_led.Start();
- }
-
- void RobotPeriodic() override {
- // Fill the buffer with a rainbow
- Rainbow();
- // Set the LEDs
- m_led.SetData(m_ledBuffer);
- }
-};
+ // Increase by to make the rainbow "move"
+ firstPixelHue += 3;
+ // Check bounds
+ firstPixelHue %= 180;
+}
#ifndef RUNNING_FRC_TESTS
int main() {
diff --git a/wpilibcExamples/src/main/cpp/examples/AddressableLED/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/AddressableLED/include/Robot.h
new file mode 100644
index 0000000..77090b6
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/AddressableLED/include/Robot.h
@@ -0,0 +1,28 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <array>
+
+#include <frc/AddressableLED.h>
+#include <frc/TimedRobot.h>
+
+class Robot : public frc::TimedRobot {
+ public:
+ void Rainbow();
+ void RobotInit() override;
+ void RobotPeriodic() override;
+
+ private:
+ static constexpr int kLength = 60;
+
+ // PWM port 9
+ // Must be a PWM header, not MXP or DIO
+ frc::AddressableLED m_led{9};
+ std::array<frc::AddressableLED::LEDData, kLength>
+ m_ledBuffer; // Reuse the buffer
+ // Store what the last hue of the first pixel is
+ int firstPixelHue = 0;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp
index e346e41..b636b44 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp
@@ -27,7 +27,7 @@
void TeleopPeriodic() override {
// Drive with arcade style
- m_robotDrive.ArcadeDrive(-m_stick.GetY(), m_stick.GetX());
+ m_robotDrive.ArcadeDrive(-m_stick.GetY(), -m_stick.GetX());
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp
index 7f497b3..23c9a56 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp
@@ -30,7 +30,7 @@
// 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_driverController.GetRightX());
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp
index 158945e..90aa789 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp
@@ -5,9 +5,13 @@
#include "RobotContainer.h"
#include <frc/shuffleboard/Shuffleboard.h>
+#include <frc2/command/Commands.h>
+#include <frc2/command/InstantCommand.h>
#include <frc2/command/button/JoystickButton.h>
#include <units/angle.h>
+namespace ac = AutoConstants;
+
RobotContainer::RobotContainer() {
// Initialize all of your commands and subsystems here
@@ -15,10 +19,10 @@
ConfigureButtonBindings();
// Set up default drive command
- m_drive.SetDefaultCommand(frc2::RunCommand(
+ m_drive.SetDefaultCommand(frc2::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
- m_driverController.GetRightX());
+ -m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -27,32 +31,29 @@
// Configure your button bindings here
// Move the arm to 2 radians above horizontal when the 'A' button is pressed.
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
- .WhenPressed(
- [this] {
- m_arm.SetGoal(2_rad);
- m_arm.Enable();
- },
- {&m_arm});
+ m_driverController.A().OnTrue(frc2::cmd::RunOnce(
+ [this] {
+ m_arm.SetGoal(2_rad);
+ m_arm.Enable();
+ },
+ {&m_arm}));
// Move the arm to neutral position when the 'B' button is pressed.
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
- .WhenPressed(
- [this] {
- m_arm.SetGoal(ArmConstants::kArmOffset);
- m_arm.Enable();
- },
- {&m_arm});
+ m_driverController.B().OnTrue(frc2::cmd::RunOnce(
+ [this] {
+ m_arm.SetGoal(ArmConstants::kArmOffset);
+ m_arm.Enable();
+ },
+ {&m_arm}));
// Disable the arm controller when Y is pressed.
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kY)
- .WhenPressed([this] { m_arm.Disable(); }, {&m_arm});
+ m_driverController.Y().OnTrue(
+ frc2::cmd::RunOnce([this] { m_arm.Disable(); }, {&m_arm}));
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController,
- frc::XboxController::Button::kRightBumper)
- .WhenPressed([this] { m_drive.SetMaxOutput(0.5); })
- .WhenReleased([this] { m_drive.SetMaxOutput(1); });
+ m_driverController.RightBumper()
+ .OnTrue(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }))
+ .OnFalse(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(1.0); }));
}
void RobotContainer::DisablePIDSubsystems() {
@@ -60,6 +61,5 @@
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
- // Runs the chosen command in autonomous
- return new frc2::InstantCommand([] {});
+ return nullptr;
}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp
index c5fb3b2..6d5eab6 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp
@@ -26,9 +26,9 @@
units::volt_t feedforward =
m_feedforward.Calculate(setpoint.position, setpoint.velocity);
// Add the feedforward to the PID output to get the motor output
- m_motor.SetVoltage(units::volt_t(output) + feedforward);
+ m_motor.SetVoltage(units::volt_t{output} + feedforward);
}
units::radian_t ArmSubsystem::GetMeasurement() {
- return units::radian_t(m_encoder.GetDistance()) + kArmOffset;
+ return units::radian_t{m_encoder.GetDistance()} + kArmOffset;
}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h
index bd432ee..cff3932 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h
@@ -4,11 +4,12 @@
#pragma once
+#include <numbers>
+
#include <units/angle.h>
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/voltage.h>
-#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -34,7 +35,7 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::numbers::pi) /
+ (kWheelDiameterInches * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
@@ -56,7 +57,7 @@
constexpr int kEncoderPorts[]{4, 5};
constexpr int kEncoderPPR = 256;
constexpr auto kEncoderDistancePerPulse =
- 2.0_rad * wpi::numbers::pi / kEncoderPPR;
+ 2.0_rad * std::numbers::pi / kEncoderPPR;
// The offset of the arm from the horizontal in its neutral position,
// measured from the horizontal
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h
index 782207b..67d194c 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h
@@ -4,23 +4,13 @@
#pragma once
-#include <frc/XboxController.h>
-#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
-#include <frc2/command/ConditionalCommand.h>
-#include <frc2/command/InstantCommand.h>
-#include <frc2/command/ParallelRaceGroup.h>
-#include <frc2/command/RunCommand.h>
-#include <frc2/command/SequentialCommandGroup.h>
-#include <frc2/command/WaitCommand.h>
-#include <frc2/command/WaitUntilCommand.h>
+#include <frc2/command/button/CommandXboxController.h>
#include "Constants.h"
#include "subsystems/ArmSubsystem.h"
#include "subsystems/DriveSubsystem.h"
-namespace ac = AutoConstants;
-
/**
* This class is where the bulk of the robot should be declared. Since
* Command-based is a "declarative" paradigm, very little robot logic should
@@ -42,7 +32,8 @@
private:
// The driver's controller
- frc::XboxController m_driverController{OIConstants::kDriverControllerPort};
+ frc2::CommandXboxController m_driverController{
+ OIConstants::kDriverControllerPort};
// The robot's subsystems and commands are defined here...
@@ -50,7 +41,5 @@
DriveSubsystem m_drive;
ArmSubsystem m_arm;
- // The chooser for the autonomous routines
-
void ConfigureButtonBindings();
};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp
index 1f6a138..dce4b95 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp
@@ -4,8 +4,6 @@
#include "RobotContainer.h"
-#include <frc/shuffleboard/Shuffleboard.h>
-#include <frc2/command/button/JoystickButton.h>
#include <units/angle.h>
RobotContainer::RobotContainer() {
@@ -15,34 +13,27 @@
ConfigureButtonBindings();
// Set up default drive command
- m_drive.SetDefaultCommand(frc2::RunCommand(
- [this] {
- m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
- m_driverController.GetRightX());
- },
- {&m_drive}));
+ m_drive.SetDefaultCommand(m_drive.ArcadeDriveCommand(
+ [this] { return -m_driverController.GetLeftY(); },
+ [this] { return -m_driverController.GetRightX(); }));
}
void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here
// Move the arm to 2 radians above horizontal when the 'A' button is pressed.
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
- .WhenPressed([this] { m_arm.SetGoal(2_rad); }, {&m_arm});
+ m_driverController.A().OnTrue(m_arm.SetArmGoalCommand(2_rad));
// Move the arm to neutral position when the 'B' button is pressed.
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
- .WhenPressed([this] { m_arm.SetGoal(ArmConstants::kArmOffset); },
- {&m_arm});
+ m_driverController.B().OnTrue(
+ m_arm.SetArmGoalCommand(ArmConstants::kArmOffset));
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController,
- frc::XboxController::Button::kRightBumper)
- .WhenPressed([this] { m_drive.SetMaxOutput(0.5); })
- .WhenReleased([this] { m_drive.SetMaxOutput(1); });
+ m_driverController.RightBumper()
+ .OnTrue(m_drive.SetMaxOutputCommand(0.5))
+ .OnFalse(m_drive.SetMaxOutputCommand(1.0));
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
- // Runs the chosen command in autonomous
- return new frc2::InstantCommand([] {});
+ return nullptr;
}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp
index 7557b5a..5603c68 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp
@@ -25,3 +25,7 @@
m_motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition,
setpoint.position.value(), feedforward / 12_V);
}
+
+frc2::CommandPtr ArmSubsystem::SetArmGoalCommand(units::radian_t goal) {
+ return frc2::cmd::RunOnce([this, goal] { this->SetGoal(goal); }, {this});
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp
index fac0df9..16409ad 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp
@@ -26,10 +26,6 @@
// Implementation of subsystem periodic method goes here.
}
-void DriveSubsystem::ArcadeDrive(double fwd, double rot) {
- m_drive.ArcadeDrive(fwd, rot);
-}
-
void DriveSubsystem::ResetEncoders() {
m_leftEncoder.Reset();
m_rightEncoder.Reset();
@@ -47,6 +43,16 @@
return m_rightEncoder;
}
-void DriveSubsystem::SetMaxOutput(double maxOutput) {
- m_drive.SetMaxOutput(maxOutput);
+frc2::CommandPtr DriveSubsystem::SetMaxOutputCommand(double maxOutput) {
+ return frc2::cmd::RunOnce(
+ [this, maxOutput] { m_drive.SetMaxOutput(maxOutput); });
+}
+
+frc2::CommandPtr DriveSubsystem::ArcadeDriveCommand(
+ std::function<double()> fwd, std::function<double()> rot) {
+ return frc2::cmd::Run(
+ [this, fwd = std::move(fwd), rot = std::move(rot)] {
+ m_drive.ArcadeDrive(fwd(), rot());
+ },
+ {this});
}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h
index bd432ee..cff3932 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h
@@ -4,11 +4,12 @@
#pragma once
+#include <numbers>
+
#include <units/angle.h>
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/voltage.h>
-#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -34,7 +35,7 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::numbers::pi) /
+ (kWheelDiameterInches * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
@@ -56,7 +57,7 @@
constexpr int kEncoderPorts[]{4, 5};
constexpr int kEncoderPPR = 256;
constexpr auto kEncoderDistancePerPulse =
- 2.0_rad * wpi::numbers::pi / kEncoderPPR;
+ 2.0_rad * std::numbers::pi / kEncoderPPR;
// The offset of the arm from the horizontal in its neutral position,
// measured from the horizontal
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h
index 5aba470..08a4dbe 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h
@@ -4,16 +4,8 @@
#pragma once
-#include <frc/XboxController.h>
-#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
-#include <frc2/command/ConditionalCommand.h>
-#include <frc2/command/InstantCommand.h>
-#include <frc2/command/ParallelRaceGroup.h>
-#include <frc2/command/RunCommand.h>
-#include <frc2/command/SequentialCommandGroup.h>
-#include <frc2/command/WaitCommand.h>
-#include <frc2/command/WaitUntilCommand.h>
+#include <frc2/command/button/CommandXboxController.h>
#include "Constants.h"
#include "subsystems/ArmSubsystem.h"
@@ -36,7 +28,8 @@
private:
// The driver's controller
- frc::XboxController m_driverController{OIConstants::kDriverControllerPort};
+ frc2::CommandXboxController m_driverController{
+ OIConstants::kDriverControllerPort};
// The robot's subsystems and commands are defined here...
@@ -44,7 +37,5 @@
DriveSubsystem m_drive;
ArmSubsystem m_arm;
- // The chooser for the autonomous routines
-
void ConfigureButtonBindings();
};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h
index 1fb5b87..ea2dc64 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h
@@ -5,6 +5,7 @@
#pragma once
#include <frc/controller/ArmFeedforward.h>
+#include <frc2/command/Commands.h>
#include <frc2/command/TrapezoidProfileSubsystem.h>
#include <units/angle.h>
@@ -21,6 +22,8 @@
void UseState(State setpoint) override;
+ frc2::CommandPtr SetArmGoalCommand(units::radian_t goal);
+
private:
ExampleSmartMotorController m_motor;
frc::ArmFeedforward m_feedforward;
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h
index 47bf28e..6830b96 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h
@@ -4,10 +4,13 @@
#pragma once
+#include <functional>
+
#include <frc/Encoder.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/motorcontrol/MotorControllerGroup.h>
#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc2/command/Commands.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -24,14 +27,6 @@
// Subsystem methods go here.
/**
- * Drives the robot using arcade controls.
- *
- * @param fwd the commanded forward movement
- * @param rot the commanded rotation
- */
- void ArcadeDrive(double fwd, double rot);
-
- /**
* Resets the drive encoders to currently read a position of 0.
*/
void ResetEncoders();
@@ -63,7 +58,10 @@
*
* @param maxOutput the maximum output to which the drive will be constrained
*/
- void SetMaxOutput(double maxOutput);
+ frc2::CommandPtr SetMaxOutputCommand(double maxOutput);
+
+ frc2::CommandPtr ArcadeDriveCommand(std::function<double()> fwd,
+ std::function<double()> rot);
private:
// Components (e.g. motor controllers and sensors) should generally be
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp
index 330ddc4..2027d25 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/Joystick.h>
#include <frc/Preferences.h>
@@ -22,7 +24,6 @@
#include <frc/util/Color8Bit.h>
#include <units/angle.h>
#include <units/moment_of_inertia.h>
-#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -45,7 +46,7 @@
// distance per pulse = (angle per revolution) / (pulses per revolution)
// = (2 * PI rads) / (4096 pulses)
static constexpr double kArmEncoderDistPerPulse =
- 2.0 * wpi::numbers::pi / 4096.0;
+ 2.0 * std::numbers::pi / 4096.0;
// The arm gearbox represents a gearbox containing two Vex 775pro motors.
frc::DCMotor m_armGearbox = frc::DCMotor::Vex775Pro(2);
@@ -101,8 +102,8 @@
void SimulationPeriodic() override {
// In this method, we update our simulation of what our arm is doing
// First, we set our "inputs" (voltages)
- m_armSim.SetInput(Eigen::Vector<double, 1>{
- m_motor.Get() * frc::RobotController::GetInputVoltage()});
+ m_armSim.SetInput(frc::Vectord<1>{m_motor.Get() *
+ frc::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
m_armSim.Update(20_ms);
@@ -120,8 +121,8 @@
void TeleopInit() override {
// Read Preferences for Arm setpoint and kP on entering Teleop
- armPosition = units::degree_t(
- frc::Preferences::GetDouble(kArmPositionKey, armPosition.value()));
+ armPosition = units::degree_t{
+ frc::Preferences::GetDouble(kArmPositionKey, armPosition.value())};
if (kArmKp != frc::Preferences::GetDouble(kArmPKey, kArmKp)) {
kArmKp = frc::Preferences::GetDouble(kArmPKey, kArmKp);
m_controller.SetP(kArmKp);
@@ -133,8 +134,8 @@
// Here, we run PID control like normal, with a setpoint read from
// preferences in degrees.
double pidOutput = m_controller.Calculate(
- m_encoder.GetDistance(), (units::radian_t(armPosition).value()));
- m_motor.SetVoltage(units::volt_t(pidOutput));
+ m_encoder.GetDistance(), (units::radian_t{armPosition}.value()));
+ m_motor.SetVoltage(units::volt_t{pidOutput});
} else {
// Otherwise, we disable the motor.
m_motor.Set(0.0);
diff --git a/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp
index aed898f..95a9a0d 100644
--- a/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp
@@ -13,20 +13,40 @@
*/
class Robot : public frc::TimedRobot {
public:
- void TeleopPeriodic() override {
- /* 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.
- */
- frc::SmartDashboard::PutNumber("Current Channel 7", m_pdp.GetCurrent(7));
+ void RobotInit() override {
+ // Put the PDP itself to the dashboard
+ frc::SmartDashboard::PutData("PDP", &m_pdp);
+ }
- /* Get the voltage going into the PDP, in Volts. The PDP returns the voltage
- * in increments of 0.05 Volts.
- */
- frc::SmartDashboard::PutNumber("Voltage", m_pdp.GetVoltage());
+ void RobotPeriodic() override {
+ // 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);
+ frc::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.
+ double voltage = m_pdp.GetVoltage();
+ frc::SmartDashboard::PutNumber("Voltage", voltage);
// Retrieves the temperature of the PDP, in degrees Celsius.
- frc::SmartDashboard::PutNumber("Temperature", m_pdp.GetTemperature());
+ double temperatureCelsius = m_pdp.GetTemperature();
+ frc::SmartDashboard::PutNumber("Temperature", temperatureCelsius);
+
+ // Get the total current of all channels.
+ double totalCurrent = m_pdp.GetTotalCurrent();
+ frc::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();
+ frc::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();
+ frc::SmartDashboard::PutNumber("Total Energy", totalEnergy);
}
private:
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
index da638d5..cc7db7b 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
@@ -23,6 +23,6 @@
void Drivetrain::UpdateOdometry() {
m_odometry.Update(m_gyro.GetRotation2d(),
- units::meter_t(m_leftEncoder.GetDistance()),
- units::meter_t(m_rightEncoder.GetDistance()));
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()});
}
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h
index 81d0a71..b4ad1db 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h
@@ -4,6 +4,8 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
@@ -16,7 +18,6 @@
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/velocity.h>
-#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -33,9 +34,9 @@
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ m_leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution);
- m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ m_rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -45,7 +46,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,
@@ -74,7 +75,9 @@
frc::AnalogGyro m_gyro{0};
frc::DifferentialDriveKinematics m_kinematics{kTrackWidth};
- frc::DifferentialDriveOdometry m_odometry{m_gyro.GetRotation2d()};
+ frc::DifferentialDriveOdometry m_odometry{
+ m_gyro.GetRotation2d(), units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}};
// Gains are for example purposes only - must be determined for your own
// robot!
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
index 1ed0e46..866d62d 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
@@ -27,10 +27,8 @@
void Drivetrain::UpdateOdometry() {
m_poseEstimator.Update(m_gyro.GetRotation2d(),
- {units::meters_per_second_t(m_leftEncoder.GetRate()),
- units::meters_per_second_t(m_rightEncoder.GetRate())},
- units::meter_t(m_leftEncoder.GetDistance()),
- units::meter_t(m_rightEncoder.GetDistance()));
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{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
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h
index dfb57a6..3001763 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h
@@ -4,6 +4,8 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
@@ -16,7 +18,6 @@
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/velocity.h>
-#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -34,9 +35,9 @@
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
m_leftEncoder.SetDistancePerPulse(
- 2 * wpi::numbers::pi * kWheelRadius.value() / kEncoderResolution);
+ 2 * std::numbers::pi * kWheelRadius.value() / kEncoderResolution);
m_rightEncoder.SetDistancePerPulse(
- 2 * wpi::numbers::pi * kWheelRadius.value() / kEncoderResolution);
+ 2 * std::numbers::pi * kWheelRadius.value() / kEncoderResolution);
m_leftEncoder.Reset();
m_rightEncoder.Reset();
@@ -45,7 +46,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,
@@ -78,10 +79,12 @@
// Gains are for example purposes only - must be determined for your own
// robot!
frc::DifferentialDrivePoseEstimator m_poseEstimator{
- frc::Rotation2d(),
- frc::Pose2d(),
- {0.01, 0.01, 0.01, 0.01, 0.01},
- {0.1, 0.1, 0.1},
+ m_kinematics,
+ m_gyro.GetRotation2d(),
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()},
+ frc::Pose2d{},
+ {0.01, 0.01, 0.01},
{0.1, 0.1, 0.1}};
// Gains are for example purposes only - must be determined for your own
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
index 4697938..b9e2ba4 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
@@ -16,9 +16,9 @@
static frc::Pose2d GetEstimatedGlobalPose(
const frc::Pose2d& estimatedRobotPose) {
auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1);
- return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)),
- estimatedRobotPose.Y() + units::meter_t(randVec(1)),
+ return frc::Pose2d{estimatedRobotPose.X() + units::meter_t{randVec(0)},
+ estimatedRobotPose.Y() + units::meter_t{randVec(1)},
estimatedRobotPose.Rotation() +
- frc::Rotation2d(units::radian_t(randVec(2))));
+ frc::Rotation2d{units::radian_t{randVec(2)}}};
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp
index bc940cd..8c2423b 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp
@@ -4,9 +4,6 @@
#include "RobotContainer.h"
-#include <frc/shuffleboard/Shuffleboard.h>
-#include <frc2/command/button/JoystickButton.h>
-
#include "commands/DriveDistanceProfiled.h"
RobotContainer::RobotContainer() {
@@ -16,10 +13,10 @@
ConfigureButtonBindings();
// Set up default drive command
- m_drive.SetDefaultCommand(frc2::RunCommand(
+ m_drive.SetDefaultCommand(frc2::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
- m_driverController.GetRightX());
+ -m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -28,37 +25,38 @@
// Configure your button bindings here
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController,
- frc::XboxController::Button::kRightBumper)
- .WhenPressed(&m_driveHalfSpeed)
- .WhenReleased(&m_driveFullSpeed);
+ m_driverController.RightBumper()
+ .OnTrue(m_driveHalfSpeed.get())
+ .OnFalse(m_driveFullSpeed.get());
// Drive forward by 3 meters when the 'A' button is pressed, with a timeout of
// 10 seconds
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
- .WhenPressed(DriveDistanceProfiled(3_m, &m_drive).WithTimeout(10_s));
+ m_driverController.A().OnTrue(
+ DriveDistanceProfiled(3_m, &m_drive).WithTimeout(10_s));
// Do the same thing as above when the 'B' button is pressed, but defined
// inline
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
- .WhenPressed(
- frc2::TrapezoidProfileCommand<units::meters>(
- frc::TrapezoidProfile<units::meters>(
- // Limit the max acceleration and velocity
- {DriveConstants::kMaxSpeed, DriveConstants::kMaxAcceleration},
- // End at desired position in meters; implicitly starts at 0
- {3_m, 0_mps}),
- // Pipe the profile state to the drive
- [this](auto setpointState) {
- m_drive.SetDriveStates(setpointState, setpointState);
- },
- // Require the drive
- {&m_drive})
- .BeforeStarting([this]() { m_drive.ResetEncoders(); })
- .WithTimeout(10_s));
+ m_driverController.B().OnTrue(
+ frc2::TrapezoidProfileCommand<units::meters>(
+ frc::TrapezoidProfile<units::meters>(
+ // Limit the max acceleration and velocity
+ {DriveConstants::kMaxSpeed, DriveConstants::kMaxAcceleration},
+ // End at desired position in meters; implicitly starts at 0
+ {3_m, 0_mps}),
+ // Pipe the profile state to the drive
+ [this](auto setpointState) {
+ m_drive.SetDriveStates(setpointState, setpointState);
+ },
+ // Require the drive
+ {&m_drive})
+ // Convert to CommandPtr
+ .ToPtr()
+ .BeforeStarting(
+ frc2::cmd::RunOnce([this]() { m_drive.ResetEncoders(); }, {}))
+ .WithTimeout(10_s));
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
// Runs the chosen command in autonomous
- return new frc2::InstantCommand([] {});
+ return nullptr;
}
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp
index cecb9d6..6780c33 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp
@@ -10,18 +10,18 @@
DriveDistanceProfiled::DriveDistanceProfiled(units::meter_t distance,
DriveSubsystem* drive)
- : CommandHelper(
- frc::TrapezoidProfile<units::meters>(
+ : CommandHelper{
+ frc::TrapezoidProfile<units::meters>{
// Limit the max acceleration and velocity
{kMaxSpeed, kMaxAcceleration},
// End at desired position in meters; implicitly starts at 0
- {distance, 0_mps}),
+ {distance, 0_mps}},
// Pipe the profile state to the drive
[drive](auto setpointState) {
drive->SetDriveStates(setpointState, setpointState);
},
// Require the drive
- {drive}) {
+ {drive}} {
// Reset drive encoders since we're starting at 0
drive->ResetEncoders();
}
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp
index 270124b..db8ba70 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp
@@ -54,11 +54,11 @@
}
units::meter_t DriveSubsystem::GetLeftEncoderDistance() {
- return units::meter_t(m_leftLeader.GetEncoderDistance());
+ return units::meter_t{m_leftLeader.GetEncoderDistance()};
}
units::meter_t DriveSubsystem::GetRightEncoderDistance() {
- return units::meter_t(m_rightLeader.GetEncoderDistance());
+ return units::meter_t{m_rightLeader.GetEncoderDistance()};
}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h
index 6644c08..7b7de40 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h
@@ -4,12 +4,13 @@
#pragma once
+#include <numbers>
+
#include <units/acceleration.h>
#include <units/length.h>
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h
index aced9e0..4700a70 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h
@@ -4,14 +4,10 @@
#pragma once
-#include <frc/XboxController.h>
-#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
-#include <frc2/command/InstantCommand.h>
-#include <frc2/command/ParallelRaceGroup.h>
-#include <frc2/command/RunCommand.h>
-#include <frc2/command/SequentialCommandGroup.h>
-#include <frc2/command/StartEndCommand.h>
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/Commands.h>
+#include <frc2/command/button/CommandXboxController.h>
#include "Constants.h"
#include "subsystems/DriveSubsystem.h"
@@ -31,17 +27,19 @@
private:
// The driver's controller
- frc::XboxController m_driverController{OIConstants::kDriverControllerPort};
+ frc2::CommandXboxController m_driverController{
+ OIConstants::kDriverControllerPort};
// The robot's subsystems and commands are defined here...
// The robot's subsystems
DriveSubsystem m_drive;
- frc2::InstantCommand m_driveHalfSpeed{[this] { m_drive.SetMaxOutput(0.5); },
- {}};
- frc2::InstantCommand m_driveFullSpeed{[this] { m_drive.SetMaxOutput(1); },
- {}};
+ // RobotContainer-owned commands
+ frc2::CommandPtr m_driveHalfSpeed =
+ frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {});
+ frc2::CommandPtr m_driveFullSpeed =
+ frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {});
void ConfigureButtonBindings();
};
diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp
index ebafa75..518114a 100644
--- a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/Joystick.h>
#include <frc/TimedRobot.h>
@@ -12,14 +14,13 @@
#include <units/length.h>
#include <units/time.h>
#include <units/velocity.h>
-#include <wpi/numbers>
class Robot : public frc::TimedRobot {
public:
static constexpr units::second_t kDt = 20_ms;
Robot() {
- m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::numbers::pi * 1.5);
+ m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * std::numbers::pi * 1.5);
}
void TeleopPeriodic() override {
@@ -31,7 +32,7 @@
// Run controller and update motor output
m_motor.Set(
- m_controller.Calculate(units::meter_t(m_encoder.GetDistance())));
+ m_controller.Calculate(units::meter_t{m_encoder.GetDistance()}));
}
private:
diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp
index 4b2891d..039a499 100644
--- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/Joystick.h>
#include <frc/RobotController.h>
@@ -23,7 +25,6 @@
#include <units/angle.h>
#include <units/length.h>
#include <units/moment_of_inertia.h>
-#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -46,7 +47,7 @@
// distance per pulse = (distance per revolution) / (pulses per revolution)
// = (Pi * D) / ppr
static constexpr double kArmEncoderDistPerPulse =
- 2.0 * wpi::numbers::pi * kElevatorDrumRadius.value() / 4096.0;
+ 2.0 * std::numbers::pi * kElevatorDrumRadius.value() / 4096.0;
// This gearbox represents a gearbox containing 4 Vex 775pro motors.
frc::DCMotor m_elevatorGearbox = frc::DCMotor::Vex775Pro(4);
@@ -64,6 +65,7 @@
kElevatorDrumRadius,
kMinElevatorHeight,
kMaxElevatorHeight,
+ true,
{0.01}};
frc::sim::EncoderSim m_encoderSim{m_encoder};
@@ -73,7 +75,7 @@
m_mech2d.GetRoot("Elevator Root", 10, 0);
frc::MechanismLigament2d* m_elevatorMech2d =
m_elevatorRoot->Append<frc::MechanismLigament2d>(
- "Elevator", units::inch_t(m_elevatorSim.GetPosition()).value(),
+ "Elevator", units::inch_t{m_elevatorSim.GetPosition()}.value(),
90_deg);
public:
@@ -81,13 +83,15 @@
m_encoder.SetDistancePerPulse(kArmEncoderDistPerPulse);
// Put Mechanism 2d to SmartDashboard
+ // To view the Elevator Sim in the simulator, select Network Tables ->
+ // SmartDashboard -> Elevator Sim
frc::SmartDashboard::PutData("Elevator Sim", &m_mech2d);
}
void SimulationPeriodic() override {
// In this method, we update our simulation of what our elevator is doing
// First, we set our "inputs" (voltages)
- m_elevatorSim.SetInput(Eigen::Vector<double, 1>{
+ m_elevatorSim.SetInput(frc::Vectord<1>{
m_motor.Get() * frc::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
@@ -102,15 +106,15 @@
// Update the Elevator length based on the simulated elevator height
m_elevatorMech2d->SetLength(
- units::inch_t(m_elevatorSim.GetPosition()).value());
+ units::inch_t{m_elevatorSim.GetPosition()}.value());
}
void TeleopPeriodic() override {
if (m_joystick.GetTrigger()) {
// Here, we run PID control like normal, with a constant setpoint of 30in.
double pidOutput = m_controller.Calculate(m_encoder.GetDistance(),
- units::meter_t(30_in).value());
- m_motor.SetVoltage(units::volt_t(pidOutput));
+ units::meter_t{30_in}.value());
+ m_motor.SetVoltage(units::volt_t{pidOutput});
} else {
// Otherwise, we disable the motor.
m_motor.Set(0.0);
diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp
index d629185..f708143 100644
--- a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/Joystick.h>
#include <frc/TimedRobot.h>
#include <frc/controller/SimpleMotorFeedforward.h>
@@ -11,7 +13,6 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
#include "ExampleSmartMotorController.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp
index 7db2c83..255cc4f 100644
--- a/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp
@@ -2,10 +2,11 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/smartdashboard/SmartDashboard.h>
-#include <wpi/numbers>
/**
* Sample program displaying the value of a quadrature encoder on the
@@ -40,7 +41,7 @@
* inch diameter (1.5inch radius) wheel, and that we want to measure
* distance in inches.
*/
- m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::numbers::pi * 1.5);
+ m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * std::numbers::pi * 1.5);
/* Defines the lowest rate at which the encoder will not be considered
* stopped, for the purposes of the GetStopped() method. Units are in
diff --git a/wpilibcExamples/src/main/cpp/examples/EventLoop/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/EventLoop/cpp/Robot.cpp
new file mode 100644
index 0000000..c8e84fb
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/EventLoop/cpp/Robot.cpp
@@ -0,0 +1,102 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <frc/Encoder.h>
+#include <frc/Joystick.h>
+#include <frc/TimedRobot.h>
+#include <frc/Ultrasonic.h>
+#include <frc/controller/PIDController.h>
+#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/event/BooleanEvent.h>
+#include <frc/event/EventLoop.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <units/angular_velocity.h>
+#include <units/length.h>
+#include <units/time.h>
+#include <units/voltage.h>
+
+static const auto SHOT_VELOCITY = 200_rpm;
+static const auto TOLERANCE = 8_rpm;
+static const auto KICKER_THRESHOLD = 15_mm;
+
+class Robot : public frc::TimedRobot {
+ public:
+ void RobotInit() override {
+ m_controller.SetTolerance(TOLERANCE.value());
+
+ frc::BooleanEvent isBallAtKicker{&m_loop, [&kickerSensor = m_kickerSensor] {
+ return kickerSensor.GetRange() <
+ KICKER_THRESHOLD;
+ }};
+ frc::BooleanEvent intakeButton{
+ &m_loop, [&joystick = m_joystick] { return joystick.GetRawButton(2); }};
+
+ // if the thumb button is held
+ (intakeButton
+ // and there is not a ball at the kicker
+ && !isBallAtKicker)
+ // activate the intake
+ .IfHigh([&intake = m_intake] { intake.Set(0.5); });
+
+ // if the thumb button is not held
+ (!intakeButton
+ // or there is a ball in the kicker
+ || isBallAtKicker)
+ // stop the intake
+ .IfHigh([&intake = m_intake] { intake.Set(0.0); });
+
+ frc::BooleanEvent shootTrigger{
+ &m_loop, [&joystick = m_joystick] { return joystick.GetTrigger(); }};
+
+ // if the trigger is held
+ shootTrigger
+ // accelerate the shooter wheel
+ .IfHigh([&shooter = m_shooter, &controller = m_controller, &ff = m_ff,
+ &encoder = m_shooterEncoder] {
+ shooter.SetVoltage(units::volt_t{controller.Calculate(
+ encoder.GetRate(), SHOT_VELOCITY.value())} +
+ ff.Calculate(SHOT_VELOCITY));
+ });
+ // if not, stop
+ (!shootTrigger).IfHigh([&shooter = m_shooter] { shooter.Set(0.0); });
+
+ frc::BooleanEvent atTargetVelocity =
+ frc::BooleanEvent(
+ &m_loop,
+ [&controller = m_controller] { return controller.AtSetpoint(); })
+ // debounce for more stability
+ .Debounce(0.2_s);
+
+ // if we're at the target velocity, kick the ball into the shooter wheel
+ atTargetVelocity.IfHigh([&kicker = m_kicker] { 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([&kicker = m_kicker] { kicker.Set(0.0); });
+ }
+
+ void RobotPeriodic() override { m_loop.Poll(); }
+
+ private:
+ frc::PWMSparkMax m_shooter{0};
+ frc::Encoder m_shooterEncoder{0, 1};
+ frc::PIDController m_controller{0.3, 0, 0};
+ frc::SimpleMotorFeedforward<units::radians> m_ff{0.1_V, 0.065_V / 1_rpm};
+
+ frc::PWMSparkMax m_kicker{1};
+ frc::Ultrasonic m_kickerSensor{2, 3};
+
+ frc::PWMSparkMax m_intake{3};
+
+ frc::EventLoop m_loop{};
+ frc::Joystick m_joystick{0};
+};
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp
index c459739..3841118 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp
@@ -4,9 +4,6 @@
#include "RobotContainer.h"
-#include <frc/shuffleboard/Shuffleboard.h>
-#include <frc2/command/button/JoystickButton.h>
-
RobotContainer::RobotContainer() {
// Initialize all of your commands and subsystems here
@@ -14,10 +11,10 @@
ConfigureButtonBindings();
// Set up default drive command
- m_drive.SetDefaultCommand(frc2::RunCommand(
+ m_drive.SetDefaultCommand(frc2::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
- m_driverController.GetRightX());
+ -m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -25,27 +22,45 @@
void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here
+ // We can bind commands while keeping their ownership in RobotContainer
+
// Spin up the shooter when the 'A' button is pressed
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
- .WhenPressed(&m_spinUpShooter);
+ m_driverController.A().OnTrue(m_spinUpShooter.get());
// Turn off the shooter when the 'B' button is pressed
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
- .WhenPressed(&m_stopShooter);
+ m_driverController.B().OnTrue(m_stopShooter.get());
- // Shoot when the 'X' button is held
- frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kX)
- .WhenPressed(&m_shoot)
- .WhenReleased(&m_stopFeeder);
+ // We can also *move* command ownership to the scheduler
+ // Note that we won't be able to access these commands after moving them!
+
+ // Shoots if the shooter wheel has reached the target speed
+ frc2::CommandPtr shoot = frc2::cmd::Either(
+ // Run the feeder
+ frc2::cmd::RunOnce([this] { m_shooter.RunFeeder(); }, {&m_shooter}),
+ // Do nothing
+ frc2::cmd::None(),
+ // Determine which of the above to do based on whether the shooter has
+ // reached the desired speed
+ [this] { return m_shooter.AtSetpoint(); });
+
+ frc2::CommandPtr stopFeeder =
+ frc2::cmd::RunOnce([this] { m_shooter.StopFeeder(); }, {&m_shooter});
+
+ // Shoot when the 'X' button is pressed
+ m_driverController.X()
+ .OnTrue(std::move(shoot))
+ .OnFalse(std::move(stopFeeder));
+
+ // We can also define commands inline at the binding!
+ // (ownership will be passed to the scheduler)
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController,
- frc::XboxController::Button::kRightBumper)
- .WhenPressed(&m_driveHalfSpeed)
- .WhenReleased(&m_driveFullSpeed);
+ m_driverController.RightBumper()
+ .OnTrue(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
+ .OnFalse(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {}));
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
// Runs the chosen command in autonomous
- return &m_autonomousCommand;
+ return m_autonomousCommand.get();
}
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp
index c386ee7..aec84f1 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp
@@ -11,7 +11,7 @@
using namespace ShooterConstants;
ShooterSubsystem::ShooterSubsystem()
- : PIDSubsystem(frc2::PIDController(kP, kI, kD)),
+ : PIDSubsystem{frc2::PIDController{kP, kI, kD}},
m_shooterMotor(kShooterMotorPort),
m_feederMotor(kFeederMotorPort),
m_shooterEncoder(kEncoderPorts[0], kEncoderPorts[1]),
@@ -22,7 +22,7 @@
}
void ShooterSubsystem::UseOutput(double output, double setpoint) {
- m_shooterMotor.SetVoltage(units::volt_t(output) +
+ m_shooterMotor.SetVoltage(units::volt_t{output} +
m_shooterFeedforward.Calculate(kShooterTargetRPS));
}
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h
index 8ac7b0e..855603a 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h
@@ -4,10 +4,11 @@
#pragma once
+#include <numbers>
+
#include <units/angle.h>
#include <units/time.h>
#include <units/voltage.h>
-#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -33,7 +34,7 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::numbers::pi) /
+ (kWheelDiameterInches * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h
index 26714fe..40091f1 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h
@@ -4,16 +4,10 @@
#pragma once
-#include <frc/XboxController.h>
-#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
-#include <frc2/command/ConditionalCommand.h>
-#include <frc2/command/InstantCommand.h>
-#include <frc2/command/ParallelRaceGroup.h>
-#include <frc2/command/RunCommand.h>
-#include <frc2/command/SequentialCommandGroup.h>
-#include <frc2/command/WaitCommand.h>
-#include <frc2/command/WaitUntilCommand.h>
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/Commands.h>
+#include <frc2/command/button/CommandXboxController.h>
#include "Constants.h"
#include "subsystems/DriveSubsystem.h"
@@ -32,65 +26,47 @@
public:
RobotContainer();
+ // The chooser for the autonomous routines
frc2::Command* GetAutonomousCommand();
private:
// The driver's controller
- frc::XboxController m_driverController{OIConstants::kDriverControllerPort};
-
- // The robot's subsystems and commands are defined here...
+ frc2::CommandXboxController m_driverController{
+ OIConstants::kDriverControllerPort};
// The robot's subsystems
DriveSubsystem m_drive;
ShooterSubsystem m_shooter;
- // A simple autonomous routine that shoots the loaded frisbees
- frc2::SequentialCommandGroup m_autonomousCommand =
- frc2::SequentialCommandGroup{
+ // RobotContainer-owned commands
+ // (These variables will still be valid after binding, because we don't move
+ // ownership)
+
+ frc2::CommandPtr m_spinUpShooter =
+ frc2::cmd::RunOnce([this] { m_shooter.Enable(); }, {&m_shooter});
+
+ frc2::CommandPtr m_stopShooter =
+ frc2::cmd::RunOnce([this] { m_shooter.Disable(); }, {&m_shooter});
+
+ // An autonomous routine that shoots the loaded frisbees
+ frc2::CommandPtr m_autonomousCommand =
+ frc2::cmd::Sequence(
// Start the command by spinning up the shooter...
- frc2::InstantCommand([this] { m_shooter.Enable(); }, {&m_shooter}),
+ frc2::cmd::RunOnce([this] { m_shooter.Enable(); }, {&m_shooter}),
// Wait until the shooter is at speed before feeding the frisbees
- frc2::WaitUntilCommand([this] { return m_shooter.AtSetpoint(); }),
+ frc2::cmd::WaitUntil([this] { return m_shooter.AtSetpoint(); }),
// Start running the feeder
- frc2::InstantCommand([this] { m_shooter.RunFeeder(); }, {&m_shooter}),
+ frc2::cmd::RunOnce([this] { m_shooter.RunFeeder(); }, {&m_shooter}),
// Shoot for the specified time
- frc2::WaitCommand(ac::kAutoShootTimeSeconds)}
+ frc2::cmd::Wait(ac::kAutoShootTimeSeconds))
// Add a timeout (will end the command if, for instance, the shooter
// never gets up to speed)
.WithTimeout(ac::kAutoTimeoutSeconds)
// When the command ends, turn off the shooter and the feeder
- .AndThen([this] {
+ .AndThen(frc2::cmd::RunOnce([this] {
m_shooter.Disable();
m_shooter.StopFeeder();
- });
-
- // Assorted commands to be bound to buttons
-
- frc2::InstantCommand m_spinUpShooter{[this] { m_shooter.Enable(); },
- {&m_shooter}};
-
- frc2::InstantCommand m_stopShooter{[this] { m_shooter.Disable(); },
- {&m_shooter}};
-
- // Shoots if the shooter wheel has reached the target speed
- frc2::ConditionalCommand m_shoot{
- // Run the feeder
- frc2::InstantCommand{[this] { m_shooter.RunFeeder(); }, {&m_shooter}},
- // Do nothing
- frc2::InstantCommand(),
- // Determine which of the above to do based on whether the shooter has
- // reached the desired speed
- [this] { return m_shooter.AtSetpoint(); }};
-
- frc2::InstantCommand m_stopFeeder{[this] { m_shooter.StopFeeder(); },
- {&m_shooter}};
-
- frc2::InstantCommand m_driveHalfSpeed{[this] { m_drive.SetMaxOutput(0.5); },
- {}};
- frc2::InstantCommand m_driveFullSpeed{[this] { m_drive.SetMaxOutput(1); },
- {}};
-
- // The chooser for the autonomous routines
+ }));
void ConfigureButtonBindings();
};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp
index 37eb460..c08faee 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp
@@ -22,9 +22,9 @@
frc::SmartDashboard::PutData(&m_wrist);
frc::SmartDashboard::PutData(&m_claw);
- m_drivetrain.SetDefaultCommand(TankDrive([this] { return m_joy.GetLeftY(); },
- [this] { return m_joy.GetRightY(); },
- m_drivetrain));
+ m_drivetrain.SetDefaultCommand(
+ TankDrive([this] { return -m_joy.GetLeftY(); },
+ [this] { return -m_joy.GetRightY(); }, m_drivetrain));
// Configure the button bindings
ConfigureButtonBindings();
@@ -32,20 +32,20 @@
void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here
- frc2::JoystickButton(&m_joy, 5).WhenPressed(
- SetElevatorSetpoint(0.25, m_elevator));
- frc2::JoystickButton(&m_joy, 6).WhenPressed(CloseClaw(m_claw));
- frc2::JoystickButton(&m_joy, 7).WhenPressed(
- SetElevatorSetpoint(0.0, m_elevator));
- frc2::JoystickButton(&m_joy, 8).WhenPressed(OpenClaw(m_claw));
- frc2::JoystickButton(&m_joy, 9).WhenPressed(
- Autonomous(m_claw, m_wrist, m_elevator, m_drivetrain));
+ frc2::JoystickButton(&m_joy, 5).OnTrue(
+ SetElevatorSetpoint(0.25, m_elevator).ToPtr());
+ frc2::JoystickButton(&m_joy, 6).OnTrue(CloseClaw(m_claw).ToPtr());
+ frc2::JoystickButton(&m_joy, 7).OnTrue(
+ SetElevatorSetpoint(0.0, m_elevator).ToPtr());
+ frc2::JoystickButton(&m_joy, 8).OnTrue(OpenClaw(m_claw).ToPtr());
+ frc2::JoystickButton(&m_joy, 9).OnTrue(
+ Autonomous(m_claw, m_wrist, m_elevator, m_drivetrain).ToPtr());
frc2::JoystickButton(&m_joy, 10)
- .WhenPressed(Pickup(m_claw, m_wrist, m_elevator));
+ .OnTrue(Pickup(m_claw, m_wrist, m_elevator).ToPtr());
frc2::JoystickButton(&m_joy, 11)
- .WhenPressed(Place(m_claw, m_wrist, m_elevator));
+ .OnTrue(Place(m_claw, m_wrist, m_elevator).ToPtr());
frc2::JoystickButton(&m_joy, 12)
- .WhenPressed(PrepareToPickup(m_claw, m_wrist, m_elevator));
+ .OnTrue(PrepareToPickup(m_claw, m_wrist, m_elevator).ToPtr());
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp
index d3e85bd..c1f5d88 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp
@@ -9,12 +9,13 @@
#include "Robot.h"
DriveStraight::DriveStraight(double distance, Drivetrain& drivetrain)
- : frc2::CommandHelper<frc2::PIDCommand, DriveStraight>(
- frc2::PIDController(4, 0, 0),
- [&drivetrain] { return drivetrain.GetDistance(); }, distance,
+ : frc2::CommandHelper<frc2::PIDCommand, DriveStraight>{
+ frc2::PIDController{4, 0, 0},
+ [&drivetrain] { return drivetrain.GetDistance(); },
+ distance,
[&drivetrain](double output) { drivetrain.Drive(output, output); },
- {&drivetrain}),
- m_drivetrain(&drivetrain) {
+ {&drivetrain}},
+ m_drivetrain{&drivetrain} {
m_controller.SetTolerance(0.01);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp
index 84bf237..de8f1e7 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp
@@ -9,13 +9,13 @@
#include "Robot.h"
SetDistanceToBox::SetDistanceToBox(double distance, Drivetrain& drivetrain)
- : frc2::CommandHelper<frc2::PIDCommand, SetDistanceToBox>(
- frc2::PIDController(-2, 0, 0),
+ : frc2::CommandHelper<frc2::PIDCommand, SetDistanceToBox>{
+ frc2::PIDController{-2, 0, 0},
[&drivetrain] { return drivetrain.GetDistanceToObstacle(); },
distance,
[&drivetrain](double output) { drivetrain.Drive(output, output); },
- {&drivetrain}),
- m_drivetrain(&drivetrain) {
+ {&drivetrain}},
+ m_drivetrain{&drivetrain} {
m_controller.SetTolerance(0.01);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp
index 16d6e46..2bfd391 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp
@@ -4,10 +4,11 @@
#include "subsystems/Drivetrain.h"
+#include <numbers>
+
#include <frc/Joystick.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <units/length.h>
-#include <wpi/numbers>
Drivetrain::Drivetrain() {
// We need to invert one side of the drivetrain so that positive voltages
@@ -26,9 +27,9 @@
#else
// Circumference = diameter * pi. 360 tick simulated encoders.
m_leftEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() *
- wpi::numbers::pi / 360.0);
+ std::numbers::pi / 360.0);
m_rightEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() *
- wpi::numbers::pi / 360.0);
+ std::numbers::pi / 360.0);
#endif
SetName("Drivetrain");
// Let's show everything on the LiveWindow
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp
index 0c195e3..c75c7bc 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp
@@ -9,7 +9,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
Elevator::Elevator()
- : frc2::PIDSubsystem(frc2::PIDController(kP_real, kI_real, 0)) {
+ : frc2::PIDSubsystem{frc2::PIDController{kP_real, kI_real, 0}} {
#ifdef SIMULATION // Check for simulation and update PID values
GetPIDController()->SetPID(kP_simulation, kI_simulation, 0, 0);
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp
index 339ccd0..8b24a7b 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp
@@ -7,7 +7,7 @@
#include <frc/controller/PIDController.h>
#include <frc/smartdashboard/SmartDashboard.h>
-Wrist::Wrist() : frc2::PIDSubsystem(frc2::PIDController(kP, 0, 0)) {
+Wrist::Wrist() : frc2::PIDSubsystem{frc2::PIDController{kP, 0, 0}} {
m_controller.SetTolerance(2.5);
SetName("Wrist");
diff --git a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp
index 003a08a..a49d4f6 100644
--- a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp
@@ -2,20 +2,20 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
-#include <frc/Joystick.h>
#include <frc/TimedRobot.h>
#include <frc/Timer.h>
+#include <frc/XboxController.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/motorcontrol/PWMSparkMax.h>
class Robot : public frc::TimedRobot {
public:
Robot() {
- m_right.SetInverted(true);
- m_robotDrive.SetExpiration(100_ms);
// 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_right.SetInverted(true);
+ m_robotDrive.SetExpiration(100_ms);
m_timer.Start();
}
@@ -27,19 +27,20 @@
void AutonomousPeriodic() override {
// Drive for 2 seconds
if (m_timer.Get() < 2_s) {
- // Drive forwards half speed
- m_robotDrive.ArcadeDrive(0.5, 0.0);
+ // Drive forwards half speed, make sure to turn input squaring off
+ m_robotDrive.ArcadeDrive(0.5, 0.0, false);
} else {
// Stop robot
- m_robotDrive.ArcadeDrive(0.0, 0.0);
+ m_robotDrive.ArcadeDrive(0.0, 0.0, false);
}
}
void TeleopInit() override {}
void TeleopPeriodic() override {
- // Drive with arcade style (use right stick)
- m_robotDrive.ArcadeDrive(-m_stick.GetY(), m_stick.GetX());
+ // Drive with arcade style (use right stick to steer)
+ m_robotDrive.ArcadeDrive(-m_controller.GetLeftY(),
+ m_controller.GetRightX());
}
void TestInit() override {}
@@ -52,7 +53,7 @@
frc::PWMSparkMax m_right{1};
frc::DifferentialDrive m_robotDrive{m_left, m_right};
- frc::Joystick m_stick{0};
+ frc::XboxController m_controller{0};
frc::Timer m_timer;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
index 0e1410e..5230c7c 100644
--- a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
@@ -32,9 +32,7 @@
*/
void TeleopPeriodic() override {
double turningValue = (kAngleSetpoint - m_gyro.GetAngle()) * kP;
- // Invert the direction of the turn if we are going backwards
- turningValue = std::copysign(turningValue, m_joystick.GetY());
- m_robotDrive.ArcadeDrive(-m_joystick.GetY(), turningValue);
+ m_drive.ArcadeDrive(-m_joystick.GetY(), -turningValue);
}
private:
@@ -52,7 +50,7 @@
frc::PWMSparkMax m_left{kLeftMotorPort};
frc::PWMSparkMax m_right{kRightMotorPort};
- frc::DifferentialDrive m_robotDrive{m_left, m_right};
+ frc::DifferentialDrive m_drive{m_left, m_right};
frc::AnalogGyro m_gyro{kGyroPort};
frc::Joystick m_joystick{kJoystickPort};
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp
index 6f5911e..3404b77 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp
@@ -5,6 +5,7 @@
#include "RobotContainer.h"
#include <frc/shuffleboard/Shuffleboard.h>
+#include <frc2/command/Commands.h>
#include <frc2/command/PIDCommand.h>
#include <frc2/command/ParallelRaceGroup.h>
#include <frc2/command/RunCommand.h>
@@ -20,7 +21,7 @@
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
- m_driverController.GetRightX());
+ -m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -32,33 +33,35 @@
// Stabilize robot to drive straight with gyro when L1 is held
frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kL1)
- .WhenHeld(frc2::PIDCommand{
- frc2::PIDController{dc::kStabilizationP, dc::kStabilizationI,
- dc::kStabilizationD},
- // Close the loop on the turn rate
- [this] { return m_drive.GetTurnRate(); },
- // Setpoint is 0
- 0,
- // Pipe the output to the turning controls
- [this](double output) {
- m_drive.ArcadeDrive(m_driverController.GetLeftY(), output);
- },
- // Require the robot drive
- {&m_drive}});
+ .WhileTrue(
+ frc2::PIDCommand(
+ frc2::PIDController{dc::kStabilizationP, dc::kStabilizationI,
+ dc::kStabilizationD},
+ // Close the loop on the turn rate
+ [this] { return m_drive.GetTurnRate(); },
+ // Setpoint is 0
+ 0,
+ // Pipe the output to the turning controls
+ [this](double output) {
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(), output);
+ },
+ // Require the robot drive
+ {&m_drive})
+ .ToPtr());
// Turn to 90 degrees when the 'Cross' button is pressed
frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kCross)
- .WhenPressed(TurnToAngle{90_deg, &m_drive}.WithTimeout(5_s));
+ .OnTrue(TurnToAngle{90_deg, &m_drive}.WithTimeout(5_s));
// Turn to -90 degrees with a profile when the 'Square' button is pressed,
// with a 5 second timeout
frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kSquare)
- .WhenPressed(TurnToAngle{90_deg, &m_drive}.WithTimeout(5_s));
+ .OnTrue(TurnToAngle{90_deg, &m_drive}.WithTimeout(5_s));
// While holding R1, drive at half speed
frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kR1)
- .WhenPressed(frc2::InstantCommand{[this] { m_drive.SetMaxOutput(0.5); }})
- .WhenReleased(frc2::InstantCommand{[this] { m_drive.SetMaxOutput(1); }});
+ .OnTrue(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
+ .OnFalse(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {}));
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp
index 681bb39..3038f79 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp
@@ -9,16 +9,15 @@
using namespace DriveConstants;
TurnToAngle::TurnToAngle(units::degree_t target, DriveSubsystem* drive)
- : CommandHelper(
- frc2::PIDController(kTurnP, kTurnI, kTurnD),
- // Close loop on heading
- [drive] { return drive->GetHeading().value(); },
- // Set reference to target
- target.value(),
- // Pipe output to turn robot
- [drive](double output) { drive->ArcadeDrive(0, output); },
- // Require the drive
- {drive}) {
+ : CommandHelper{frc2::PIDController{kTurnP, kTurnI, kTurnD},
+ // Close loop on heading
+ [drive] { return drive->GetHeading().value(); },
+ // Set reference to target
+ target.value(),
+ // Pipe output to turn robot
+ [drive](double output) { drive->ArcadeDrive(0, output); },
+ // Require the drive
+ {drive}} {
// Set the controller to be continuous (because it is an angle controller)
m_controller.EnableContinuousInput(-180, 180);
// Set the controller tolerance - the delta tolerance ensures the robot is
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp
index a359625..df4e355 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp
@@ -10,9 +10,9 @@
TurnToAngleProfiled::TurnToAngleProfiled(units::degree_t target,
DriveSubsystem* drive)
- : CommandHelper(
- frc::ProfiledPIDController<units::radians>(
- kTurnP, kTurnI, kTurnD, {kMaxTurnRate, kMaxTurnAcceleration}),
+ : CommandHelper{
+ frc::ProfiledPIDController<units::radians>{
+ kTurnP, kTurnI, kTurnD, {kMaxTurnRate, kMaxTurnAcceleration}},
// Close loop on heading
[drive] { return drive->GetHeading(); },
// Set reference to target
@@ -22,7 +22,7 @@
drive->ArcadeDrive(0, output);
},
// Require the drive
- {drive}) {
+ {drive}} {
// Set the controller to be continuous (because it is an angle controller)
GetController().EnableContinuousInput(-180_deg, 180_deg);
// Set the controller tolerance - the delta tolerance ensures the robot is
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp
index baa78de..0cbd0e5 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp
@@ -53,8 +53,8 @@
}
units::degree_t DriveSubsystem::GetHeading() {
- return units::degree_t(std::remainder(m_gyro.GetAngle(), 360) *
- (kGyroReversed ? -1.0 : 1.0));
+ return units::degree_t{std::remainder(m_gyro.GetAngle(), 360) *
+ (kGyroReversed ? -1.0 : 1.0)};
}
double DriveSubsystem::GetTurnRate() {
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h
index 210f82d..77673c9 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h
@@ -4,9 +4,10 @@
#pragma once
+#include <numbers>
+
#include <units/angle.h>
#include <units/angular_velocity.h>
-#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -32,7 +33,7 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::numbers::pi) /
+ (kWheelDiameterInches * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
constexpr bool kGyroReversed = true;
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp
index a4e0457..2207f79 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp
@@ -28,8 +28,8 @@
* Mecanum drive is used with the gyro angle as an input.
*/
void TeleopPeriodic() override {
- m_robotDrive.DriveCartesian(-m_joystick.GetY(), m_joystick.GetX(),
- m_joystick.GetZ(), m_gyro.GetAngle());
+ m_robotDrive.DriveCartesian(-m_joystick.GetY(), -m_joystick.GetX(),
+ -m_joystick.GetZ(), m_gyro.GetRotation2d());
}
private:
diff --git a/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c b/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c
index 0db402b..b0905f9 100644
--- a/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c
+++ b/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c
@@ -87,13 +87,18 @@
return 1;
}
+ WPI_EventHandle eventHandle = WPI_CreateEvent(1, 0);
+ HAL_ProvideNewDataEventHandle(eventHandle);
+
while (1) {
// Wait for DS data, with a timeout
- HAL_Bool validData = HAL_WaitForDSDataTimeout(1.0);
- if (!validData) {
+ int timed_out = 0;
+ int signaled = WPI_WaitForObjectTimeout(eventHandle, 1.0, &timed_out);
+ if (!signaled) {
// Do something here on no packet
continue;
}
+
enum DriverStationMode dsMode = getDSMode();
switch (dsMode) {
case DisabledMode:
@@ -116,6 +121,9 @@
}
// Clean up resources
+ HAL_RemoveNewDataEventHandle(eventHandle);
+ WPI_DestroyEvent(eventHandle);
+
status = 0;
HAL_FreeDIOPort(dio);
HAL_FreePWMPort(pwmPort, &status);
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp
index 8fae7d2..5a0cdad 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp
@@ -5,14 +5,14 @@
#include "RobotContainer.h"
#include <frc/shuffleboard/Shuffleboard.h>
-#include <frc2/command/button/JoystickButton.h>
RobotContainer::RobotContainer() {
// Initialize all of your commands and subsystems here
// Add commands to the autonomous command chooser
- m_chooser.SetDefaultOption("Simple Auto", &m_simpleAuto);
- m_chooser.AddOption("Complex Auto", &m_complexAuto);
+ // Note that we do *not* move ownership into the chooser
+ m_chooser.SetDefaultOption("Simple Auto", m_simpleAuto.get());
+ m_chooser.AddOption("Complex Auto", m_complexAuto.get());
// Put the chooser on the dashboard
frc::Shuffleboard::GetTab("Autonomous").Add(m_chooser);
@@ -21,10 +21,10 @@
ConfigureButtonBindings();
// Set up default drive command
- m_drive.SetDefaultCommand(frc2::RunCommand(
+ m_drive.SetDefaultCommand(frc2::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
- m_driverController.GetRightX());
+ -m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -33,15 +33,13 @@
// Configure your button bindings here
// Grab the hatch when the 'Circle' button is pressed.
- frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kCircle)
- .WhenPressed(&m_grabHatch);
+ m_driverController.Circle().OnTrue(m_hatch.GrabHatchCommand());
// Release the hatch when the 'Square' button is pressed.
- frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kSquare)
- .WhenPressed(&m_releaseHatch);
+ m_driverController.Square().OnTrue(m_hatch.ReleaseHatchCommand());
// While holding R1, drive at half speed
- frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kR1)
- .WhenPressed(&m_driveHalfSpeed)
- .WhenReleased(&m_driveFullSpeed);
+ m_driverController.R1()
+ .OnTrue(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
+ .OnFalse(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(1.0); }, {}));
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/Autos.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/Autos.cpp
new file mode 100644
index 0000000..73e60ed
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/Autos.cpp
@@ -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.
+
+#include "commands/Autos.h"
+
+#include <frc2/command/Commands.h>
+#include <frc2/command/FunctionalCommand.h>
+
+#include "Constants.h"
+
+using namespace AutoConstants;
+
+frc2::CommandPtr autos::SimpleAuto(DriveSubsystem* drive) {
+ return frc2::FunctionalCommand(
+ // Reset encoders on command start
+ [drive] { drive->ResetEncoders(); },
+ // Drive forward while the command is executing
+ [drive] { drive->ArcadeDrive(AutoConstants::kAutoDriveSpeed, 0); },
+ // Stop driving at the end of the command
+ [drive](bool interrupted) { drive->ArcadeDrive(0, 0); },
+ // End the command when the robot's driven distance exceeds the
+ // desired value
+ [drive] {
+ return drive->GetAverageEncoderDistance() >=
+ AutoConstants::kAutoDriveDistanceInches;
+ },
+ // Requires the drive subsystem
+ {drive})
+ .ToPtr();
+}
+
+frc2::CommandPtr autos::ComplexAuto(DriveSubsystem* drive,
+ HatchSubsystem* hatch) {
+ return frc2::cmd::Sequence(
+ // Drive forward the specified distance
+ frc2::FunctionalCommand(
+ // Reset encoders on command start
+ [drive] { drive->ResetEncoders(); },
+ // Drive forward while the command is executing
+ [drive] { drive->ArcadeDrive(kAutoDriveSpeed, 0); },
+ // Stop driving at the end of the command
+ [drive](bool interrupted) { drive->ArcadeDrive(0, 0); },
+ // End the command when the robot's driven distance exceeds the
+ // desired value
+ [drive] {
+ return drive->GetAverageEncoderDistance() >=
+ kAutoDriveDistanceInches;
+ },
+ // Requires the drive subsystem
+ {drive})
+ .ToPtr(),
+ // Release the hatch
+ hatch->ReleaseHatchCommand(),
+ // Drive backward the specified distance
+ // Drive forward the specified distance
+ frc2::FunctionalCommand(
+ // Reset encoders on command start
+ [drive] { drive->ResetEncoders(); },
+ // Drive backward while the command is executing
+ [drive] { drive->ArcadeDrive(-kAutoDriveSpeed, 0); },
+ // Stop driving at the end of the command
+ [drive](bool interrupted) { drive->ArcadeDrive(0, 0); },
+ // End the command when the robot's driven distance exceeds the
+ // desired value
+ [drive] {
+ return drive->GetAverageEncoderDistance() <=
+ kAutoBackupDistanceInches;
+ },
+ // Requires the drive subsystem
+ {drive})
+ .ToPtr());
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp
deleted file mode 100644
index f88850e..0000000
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp
+++ /dev/null
@@ -1,50 +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.
-
-#include "commands/ComplexAuto.h"
-
-#include <frc2/command/FunctionalCommand.h>
-#include <frc2/command/InstantCommand.h>
-#include <frc2/command/ParallelRaceGroup.h>
-
-using namespace AutoConstants;
-
-ComplexAuto::ComplexAuto(DriveSubsystem* drive, HatchSubsystem* hatch) {
- AddCommands(
- // Drive forward the specified distance
- frc2::FunctionalCommand(
- // Reset encoders on command start
- [&] { drive->ResetEncoders(); },
- // Drive forward while the command is executing
- [&] { drive->ArcadeDrive(kAutoDriveSpeed, 0); },
- // Stop driving at the end of the command
- [&](bool interrupted) { drive->ArcadeDrive(0, 0); },
- // End the command when the robot's driven distance exceeds the
- // desired value
- [&] {
- return drive->GetAverageEncoderDistance() >=
- kAutoDriveDistanceInches;
- },
- // Requires the drive subsystem
- {drive}),
- // Release the hatch
- frc2::InstantCommand([hatch] { hatch->ReleaseHatch(); }, {hatch}),
- // Drive backward the specified distance
- // Drive forward the specified distance
- frc2::FunctionalCommand(
- // Reset encoders on command start
- [&] { drive->ResetEncoders(); },
- // Drive backward while the command is executing
- [&] { drive->ArcadeDrive(-kAutoDriveSpeed, 0); },
- // Stop driving at the end of the command
- [&](bool interrupted) { drive->ArcadeDrive(0, 0); },
- // End the command when the robot's driven distance exceeds the
- // desired value
- [&] {
- return drive->GetAverageEncoderDistance() <=
- kAutoBackupDistanceInches;
- },
- // Requires the drive subsystem
- {drive}));
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp
index ba1c0dd..e766d43 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp
@@ -10,10 +10,14 @@
: m_hatchSolenoid{frc::PneumaticsModuleType::CTREPCM,
kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {}
-void HatchSubsystem::GrabHatch() {
- m_hatchSolenoid.Set(frc::DoubleSolenoid::kForward);
+frc2::CommandPtr HatchSubsystem::GrabHatchCommand() {
+ // implicitly require `this`
+ return this->RunOnce(
+ [this] { m_hatchSolenoid.Set(frc::DoubleSolenoid::kForward); });
}
-void HatchSubsystem::ReleaseHatch() {
- m_hatchSolenoid.Set(frc::DoubleSolenoid::kReverse);
+frc2::CommandPtr HatchSubsystem::ReleaseHatchCommand() {
+ // implicitly require `this`
+ return this->RunOnce(
+ [this] { m_hatchSolenoid.Set(frc::DoubleSolenoid::kReverse); });
}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h
index e9fbfdc..7a2bdae 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h
@@ -4,7 +4,7 @@
#pragma once
-#include <wpi/numbers>
+#include <numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -30,7 +30,7 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::numbers::pi) /
+ (kWheelDiameterInches * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h
index b17c55d..002a8a6 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h
@@ -4,17 +4,13 @@
#pragma once
-#include <frc/PS4Controller.h>
#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
-#include <frc2/command/FunctionalCommand.h>
-#include <frc2/command/InstantCommand.h>
-#include <frc2/command/ParallelRaceGroup.h>
-#include <frc2/command/RunCommand.h>
-#include <frc2/command/SequentialCommandGroup.h>
+#include <frc2/command/Commands.h>
+#include <frc2/command/button/CommandPS4Controller.h>
#include "Constants.h"
-#include "commands/ComplexAuto.h"
+#include "commands/Autos.h"
#include "subsystems/DriveSubsystem.h"
#include "subsystems/HatchSubsystem.h"
@@ -35,7 +31,8 @@
private:
// The driver's controller
- frc::PS4Controller m_driverController{OIConstants::kDriverControllerPort};
+ frc2::CommandPS4Controller m_driverController{
+ OIConstants::kDriverControllerPort};
// The robot's subsystems and commands are defined here...
@@ -43,33 +40,11 @@
DriveSubsystem m_drive;
HatchSubsystem m_hatch;
+ // Commands owned by RobotContainer
+
// The autonomous routines
- frc2::FunctionalCommand m_simpleAuto = frc2::FunctionalCommand(
- // Reset encoders on command start
- [this] { m_drive.ResetEncoders(); },
- // Drive forward while the command is executing
- [this] { m_drive.ArcadeDrive(AutoConstants::kAutoDriveSpeed, 0); },
- // Stop driving at the end of the command
- [this](bool interrupted) { m_drive.ArcadeDrive(0, 0); },
- // End the command when the robot's driven distance exceeds the desired
- // value
- [this] {
- return m_drive.GetAverageEncoderDistance() >=
- AutoConstants::kAutoDriveDistanceInches;
- },
- // Requires the drive subsystem
- {&m_drive});
- ComplexAuto m_complexAuto{&m_drive, &m_hatch};
-
- // Assorted commands to be bound to buttons
-
- frc2::InstantCommand m_grabHatch{[this] { m_hatch.GrabHatch(); }, {&m_hatch}};
- frc2::InstantCommand m_releaseHatch{[this] { m_hatch.ReleaseHatch(); },
- {&m_hatch}};
- frc2::InstantCommand m_driveHalfSpeed{[this] { m_drive.SetMaxOutput(0.5); },
- {}};
- frc2::InstantCommand m_driveFullSpeed{[this] { m_drive.SetMaxOutput(1); },
- {}};
+ frc2::CommandPtr m_simpleAuto = autos::SimpleAuto(&m_drive);
+ frc2::CommandPtr m_complexAuto = autos::ComplexAuto(&m_drive, &m_hatch);
// The chooser for the autonomous routines
frc::SendableChooser<frc2::Command*> m_chooser;
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/Autos.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/Autos.h
new file mode 100644
index 0000000..8adbdf8
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/Autos.h
@@ -0,0 +1,26 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandPtr.h>
+
+#include "subsystems/DriveSubsystem.h"
+#include "subsystems/HatchSubsystem.h"
+
+/** Container for auto command factories. */
+namespace autos {
+
+/**
+ * A simple auto that drives forward, then stops.
+ */
+frc2::CommandPtr SimpleAuto(DriveSubsystem* drive);
+
+/**
+ * A complex auto command that drives forward, releases a hatch, and then drives
+ * backward.
+ */
+frc2::CommandPtr ComplexAuto(DriveSubsystem* drive, HatchSubsystem* hatch);
+
+} // namespace autos
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/ComplexAuto.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/ComplexAuto.h
deleted file mode 100644
index e746d8a..0000000
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/ComplexAuto.h
+++ /dev/null
@@ -1,28 +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.
-
-#pragma once
-
-#include <frc2/command/CommandHelper.h>
-#include <frc2/command/SequentialCommandGroup.h>
-
-#include "Constants.h"
-#include "subsystems/DriveSubsystem.h"
-#include "subsystems/HatchSubsystem.h"
-
-/**
- * A complex auto command that drives forward, releases a hatch, and then drives
- * backward.
- */
-class ComplexAuto
- : public frc2::CommandHelper<frc2::SequentialCommandGroup, ComplexAuto> {
- public:
- /**
- * Creates a new ComplexAuto.
- *
- * @param drive The drive subsystem this command will run on
- * @param hatch The hatch subsystem this command will run on
- */
- ComplexAuto(DriveSubsystem* drive, HatchSubsystem* hatch);
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h
index bb06100..b21bb56 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h
@@ -6,6 +6,7 @@
#include <frc/DoubleSolenoid.h>
#include <frc/PneumaticsControlModule.h>
+#include <frc2/command/CommandPtr.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -19,12 +20,12 @@
/**
* Grabs the hatch.
*/
- void GrabHatch();
+ frc2::CommandPtr GrabHatchCommand();
/**
* Releases the hatch.
*/
- void ReleaseHatch();
+ frc2::CommandPtr ReleaseHatchCommand();
private:
// Components (e.g. motor controllers and sensors) should generally be
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp
index 6f8c5a6..876a984 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp
@@ -28,27 +28,25 @@
// Set up default drive command
m_drive.SetDefaultCommand(DefaultDrive(
&m_drive, [this] { return -m_driverController.GetLeftY(); },
- [this] { return m_driverController.GetRightX(); }));
+ [this] { return -m_driverController.GetRightX(); }));
}
void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here
- // NOTE: Using `new` here will leak these commands if they are ever no longer
- // needed. This is usually a non-issue as button-bindings tend to be permanent
- // - however, if you wish to avoid this, the commands should be
- // stack-allocated and declared as members of RobotContainer.
+ // NOTE: since we're binding a CommandPtr, command ownership here is moved to
+ // the scheduler thus, no memory leaks!
// Grab the hatch when the 'A' button is pressed.
frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
- .WhenPressed(new GrabHatch(&m_hatch));
+ .OnTrue(GrabHatch(&m_hatch).ToPtr());
// Release the hatch when the 'B' button is pressed.
frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
- .WhenPressed(new ReleaseHatch(&m_hatch));
+ .OnTrue(ReleaseHatch(&m_hatch).ToPtr());
// While holding the shoulder button, drive at half speed
frc2::JoystickButton(&m_driverController,
frc::XboxController::Button::kRightBumper)
- .WhenHeld(new HalveDriveSpeed(&m_drive));
+ .WhileTrue(HalveDriveSpeed(&m_drive).ToPtr());
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h
index e9fbfdc..7a2bdae 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h
@@ -4,7 +4,7 @@
#pragma once
-#include <wpi/numbers>
+#include <numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -30,7 +30,7 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::numbers::pi) /
+ (kWheelDiameterInches * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp
index 4d3aac2..a59b758 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp
@@ -5,10 +5,17 @@
#include "Drivetrain.h"
frc::MecanumDriveWheelSpeeds Drivetrain::GetCurrentState() const {
- return {units::meters_per_second_t(m_frontLeftEncoder.GetRate()),
- units::meters_per_second_t(m_frontRightEncoder.GetRate()),
- units::meters_per_second_t(m_backLeftEncoder.GetRate()),
- units::meters_per_second_t(m_backRightEncoder.GetRate())};
+ return {units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
+ units::meters_per_second_t{m_frontRightEncoder.GetRate()},
+ units::meters_per_second_t{m_backLeftEncoder.GetRate()},
+ units::meters_per_second_t{m_backRightEncoder.GetRate()}};
+}
+
+frc::MecanumDriveWheelPositions Drivetrain::GetCurrentWheelDistances() const {
+ return {units::meter_t{m_frontLeftEncoder.GetDistance()},
+ units::meter_t{m_frontRightEncoder.GetDistance()},
+ units::meter_t{m_backLeftEncoder.GetDistance()},
+ units::meter_t{m_backRightEncoder.GetDistance()}};
}
void Drivetrain::SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds) {
@@ -52,5 +59,5 @@
}
void Drivetrain::UpdateOdometry() {
- m_odometry.Update(m_gyro.GetRotation2d(), GetCurrentState());
+ m_odometry.Update(m_gyro.GetRotation2d(), GetCurrentWheelDistances());
}
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h
index 9ec5fc5..fd4ae7a 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h
@@ -4,6 +4,8 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
@@ -13,7 +15,6 @@
#include <frc/kinematics/MecanumDriveOdometry.h>
#include <frc/kinematics/MecanumDriveWheelSpeeds.h>
#include <frc/motorcontrol/PWMSparkMax.h>
-#include <wpi/numbers>
/**
* Represents a mecanum drive style drivetrain.
@@ -30,6 +31,7 @@
}
frc::MecanumDriveWheelSpeeds GetCurrentState() const;
+ frc::MecanumDriveWheelPositions GetCurrentWheelDistances() const;
void SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds);
void Drive(units::meters_per_second_t xSpeed,
units::meters_per_second_t ySpeed, units::radians_per_second_t rot,
@@ -39,7 +41,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
private:
frc::PWMSparkMax m_frontLeftMotor{1};
@@ -68,7 +70,8 @@
m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation,
m_backRightLocation};
- frc::MecanumDriveOdometry m_odometry{m_kinematics, m_gyro.GetRotation2d()};
+ frc::MecanumDriveOdometry m_odometry{m_kinematics, m_gyro.GetRotation2d(),
+ GetCurrentWheelDistances()};
// Gains are for example purposes only - must be determined for your own
// robot!
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
index 36912b5..99aed4e 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
@@ -7,10 +7,10 @@
namespace DriveConstants {
const frc::MecanumDriveKinematics kDriveKinematics{
- frc::Translation2d(kWheelBase / 2, kTrackWidth / 2),
- frc::Translation2d(kWheelBase / 2, -kTrackWidth / 2),
- frc::Translation2d(-kWheelBase / 2, kTrackWidth / 2),
- frc::Translation2d(-kWheelBase / 2, -kTrackWidth / 2)};
+ frc::Translation2d{kWheelBase / 2, kTrackWidth / 2},
+ frc::Translation2d{kWheelBase / 2, -kTrackWidth / 2},
+ frc::Translation2d{-kWheelBase / 2, kTrackWidth / 2},
+ frc::Translation2d{-kWheelBase / 2, -kTrackWidth / 2}};
} // namespace DriveConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
index 3e2c6bf..1e9a9ae 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
@@ -30,9 +30,9 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.Drive(m_driverController.GetLeftY(),
- m_driverController.GetRightX(),
- m_driverController.GetLeftX(), false);
+ m_drive.Drive(-m_driverController.GetLeftY(),
+ -m_driverController.GetRightX(),
+ -m_driverController.GetLeftX(), false);
},
{&m_drive}));
}
@@ -43,8 +43,8 @@
// While holding the shoulder button, drive at half speed
frc2::JoystickButton(&m_driverController,
frc::XboxController::Button::kRightBumper)
- .WhenPressed(&m_driveHalfSpeed)
- .WhenReleased(&m_driveFullSpeed);
+ .OnTrue(&m_driveHalfSpeed)
+ .OnFalse(&m_driveFullSpeed);
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
@@ -57,11 +57,11 @@
// An example trajectory to follow. All units in meters.
auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory(
// Start at the origin facing the +X direction
- frc::Pose2d(0_m, 0_m, frc::Rotation2d(0_deg)),
+ frc::Pose2d{0_m, 0_m, 0_deg},
// Pass through these two interior waypoints, making an 's' curve path
- {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)},
+ {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}},
// End 3 meters straight ahead of where we started, facing forward
- frc::Pose2d(3_m, 0_m, frc::Rotation2d(0_deg)),
+ frc::Pose2d{3_m, 0_m, 0_deg},
// Pass the config
config);
@@ -71,8 +71,8 @@
frc::SimpleMotorFeedforward<units::meters>(ks, kv, ka),
DriveConstants::kDriveKinematics,
- frc2::PIDController(AutoConstants::kPXController, 0, 0),
- frc2::PIDController(AutoConstants::kPYController, 0, 0),
+ frc2::PIDController{AutoConstants::kPXController, 0, 0},
+ frc2::PIDController{AutoConstants::kPYController, 0, 0},
frc::ProfiledPIDController<units::radians>(
AutoConstants::kPThetaController, 0, 0,
AutoConstants::kThetaControllerConstraints),
@@ -81,18 +81,18 @@
[this]() {
return frc::MecanumDriveWheelSpeeds{
- units::meters_per_second_t(m_drive.GetFrontLeftEncoder().GetRate()),
- units::meters_per_second_t(
- m_drive.GetFrontRightEncoder().GetRate()),
- units::meters_per_second_t(m_drive.GetRearLeftEncoder().GetRate()),
- units::meters_per_second_t(
- m_drive.GetRearRightEncoder().GetRate())};
+ units::meters_per_second_t{m_drive.GetFrontLeftEncoder().GetRate()},
+ units::meters_per_second_t{
+ m_drive.GetFrontRightEncoder().GetRate()},
+ units::meters_per_second_t{m_drive.GetRearLeftEncoder().GetRate()},
+ units::meters_per_second_t{
+ m_drive.GetRearRightEncoder().GetRate()}};
},
- frc2::PIDController(DriveConstants::kPFrontLeftVel, 0, 0),
- frc2::PIDController(DriveConstants::kPRearLeftVel, 0, 0),
- frc2::PIDController(DriveConstants::kPFrontRightVel, 0, 0),
- frc2::PIDController(DriveConstants::kPRearRightVel, 0, 0),
+ frc2::PIDController{DriveConstants::kPFrontLeftVel, 0, 0},
+ frc2::PIDController{DriveConstants::kPRearLeftVel, 0, 0},
+ frc2::PIDController{DriveConstants::kPFrontRightVel, 0, 0},
+ frc2::PIDController{DriveConstants::kPRearRightVel, 0, 0},
[this](units::volt_t frontLeft, units::volt_t rearLeft,
units::volt_t frontRight, units::volt_t rearRight) {
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
index 9e06068..9120fa6 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
@@ -28,7 +28,8 @@
m_rearRightEncoder{kRearRightEncoderPorts[0], kRearRightEncoderPorts[1],
kRearRightEncoderReversed},
- m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d()} {
+ m_odometry{kDriveKinematics, m_gyro.GetRotation2d(),
+ getCurrentWheelDistances(), frc::Pose2d{}} {
// Set the distance per pulse for the encoders
m_frontLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rearLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
@@ -43,19 +44,13 @@
void DriveSubsystem::Periodic() {
// Implementation of subsystem periodic method goes here.
- m_odometry.Update(
- m_gyro.GetRotation2d(),
- frc::MecanumDriveWheelSpeeds{
- units::meters_per_second_t(m_frontLeftEncoder.GetRate()),
- units::meters_per_second_t(m_rearLeftEncoder.GetRate()),
- units::meters_per_second_t(m_frontRightEncoder.GetRate()),
- units::meters_per_second_t(m_rearRightEncoder.GetRate())});
+ m_odometry.Update(m_gyro.GetRotation2d(), getCurrentWheelDistances());
}
void DriveSubsystem::Drive(double xSpeed, double ySpeed, double rot,
bool 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);
}
@@ -96,10 +91,18 @@
frc::MecanumDriveWheelSpeeds DriveSubsystem::getCurrentWheelSpeeds() {
return (frc::MecanumDriveWheelSpeeds{
- units::meters_per_second_t(m_frontLeftEncoder.GetRate()),
- units::meters_per_second_t(m_rearLeftEncoder.GetRate()),
- units::meters_per_second_t(m_frontRightEncoder.GetRate()),
- units::meters_per_second_t(m_rearRightEncoder.GetRate())});
+ units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
+ units::meters_per_second_t{m_rearLeftEncoder.GetRate()},
+ units::meters_per_second_t{m_frontRightEncoder.GetRate()},
+ units::meters_per_second_t{m_rearRightEncoder.GetRate()}});
+}
+
+frc::MecanumDriveWheelPositions DriveSubsystem::getCurrentWheelDistances() {
+ return (frc::MecanumDriveWheelPositions{
+ units::meter_t{m_frontLeftEncoder.GetDistance()},
+ units::meter_t{m_rearLeftEncoder.GetDistance()},
+ units::meter_t{m_frontRightEncoder.GetDistance()},
+ units::meter_t{m_rearRightEncoder.GetDistance()}});
}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
@@ -123,5 +126,6 @@
}
void DriveSubsystem::ResetOdometry(frc::Pose2d pose) {
- m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
+ m_odometry.ResetPosition(m_gyro.GetRotation2d(), getCurrentWheelDistances(),
+ pose);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
index 8d59a2c..527504a 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
@@ -2,17 +2,19 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/MecanumDriveKinematics.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/acceleration.h>
#include <units/angle.h>
+#include <units/angular_acceleration.h>
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
#pragma once
@@ -51,7 +53,7 @@
constexpr double kWheelDiameterMeters = 0.15;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterMeters * wpi::numbers::pi) /
+ (kWheelDiameterMeters * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
@@ -70,15 +72,10 @@
} // namespace DriveConstants
namespace AutoConstants {
-using radians_per_second_squared_t =
- units::compound_unit<units::radians,
- units::inverse<units::squared<units::second>>>;
-
-constexpr auto kMaxSpeed = units::meters_per_second_t(3);
-constexpr auto kMaxAcceleration = units::meters_per_second_squared_t(3);
-constexpr auto kMaxAngularSpeed = units::radians_per_second_t(3);
-constexpr auto kMaxAngularAcceleration =
- units::unit_t<radians_per_second_squared_t>(3);
+constexpr auto kMaxSpeed = 3_mps;
+constexpr auto kMaxAcceleration = 3_mps_sq;
+constexpr auto kMaxAngularSpeed = 3_rad_per_s;
+constexpr auto kMaxAngularAcceleration = 3_rad_per_s_sq;
constexpr double kPXController = 0.5;
constexpr double kPYController = 0.5;
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h
index 95b08b6..579a395 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h
@@ -82,6 +82,13 @@
frc::MecanumDriveWheelSpeeds getCurrentWheelSpeeds();
/**
+ * Gets the distances travelled by each wheel.
+ *
+ * @return the distances travelled by each wheel.
+ */
+ frc::MecanumDriveWheelPositions getCurrentWheelDistances();
+
+ /**
* Sets the drive MotorControllers to a desired voltage.
*/
void SetMotorControllersVolts(units::volt_t frontLeftPower,
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp
index f8d95ac..2b57f3c 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp
@@ -21,11 +21,11 @@
}
void TeleopPeriodic() override {
- /* 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());
+ m_robotDrive.DriveCartesian(-m_stick.GetY(), -m_stick.GetX(),
+ -m_stick.GetZ());
}
private:
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp
index daa4b42..c1046dd 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp
@@ -9,10 +9,17 @@
#include "ExampleGlobalMeasurementSensor.h"
frc::MecanumDriveWheelSpeeds Drivetrain::GetCurrentState() const {
- return {units::meters_per_second_t(m_frontLeftEncoder.GetRate()),
- units::meters_per_second_t(m_frontRightEncoder.GetRate()),
- units::meters_per_second_t(m_backLeftEncoder.GetRate()),
- units::meters_per_second_t(m_backRightEncoder.GetRate())};
+ return {units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
+ units::meters_per_second_t{m_frontRightEncoder.GetRate()},
+ units::meters_per_second_t{m_backLeftEncoder.GetRate()},
+ units::meters_per_second_t{m_backRightEncoder.GetRate()}};
+}
+
+frc::MecanumDriveWheelPositions Drivetrain::GetCurrentDistances() const {
+ return {units::meter_t{m_frontLeftEncoder.GetDistance()},
+ units::meter_t{m_frontRightEncoder.GetDistance()},
+ units::meter_t{m_backLeftEncoder.GetDistance()},
+ units::meter_t{m_backRightEncoder.GetDistance()}};
}
void Drivetrain::SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds) {
@@ -49,7 +56,7 @@
}
void Drivetrain::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
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h
index 3eea4a2..eeaf7af 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h
@@ -4,6 +4,8 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
@@ -14,7 +16,6 @@
#include <frc/kinematics/MecanumDriveOdometry.h>
#include <frc/kinematics/MecanumDriveWheelSpeeds.h>
#include <frc/motorcontrol/PWMSparkMax.h>
-#include <wpi/numbers>
/**
* Represents a mecanum drive style drivetrain.
@@ -31,6 +32,7 @@
}
frc::MecanumDriveWheelSpeeds GetCurrentState() const;
+ frc::MecanumDriveWheelPositions GetCurrentDistances() const;
void SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds);
void Drive(units::meters_per_second_t xSpeed,
units::meters_per_second_t ySpeed, units::radians_per_second_t rot,
@@ -39,7 +41,7 @@
static constexpr auto kMaxSpeed = 3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
private:
frc::PWMSparkMax m_frontLeftMotor{1};
@@ -75,6 +77,6 @@
// Gains are for example purposes only - must be determined for your own
// robot!
frc::MecanumDrivePoseEstimator m_poseEstimator{
- frc::Rotation2d(), frc::Pose2d(), m_kinematics,
- {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}};
+ m_kinematics, m_gyro.GetRotation2d(), GetCurrentDistances(),
+ frc::Pose2d{}, {0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}};
};
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
index a4caff4..b9e2ba4 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
@@ -16,9 +16,9 @@
static frc::Pose2d GetEstimatedGlobalPose(
const frc::Pose2d& estimatedRobotPose) {
auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1);
- return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)),
- estimatedRobotPose.Y() + units::meter_t(randVec(1)),
+ return frc::Pose2d{estimatedRobotPose.X() + units::meter_t{randVec(0)},
+ estimatedRobotPose.Y() + units::meter_t{randVec(1)},
estimatedRobotPose.Rotation() +
- frc::Rotation2d(units::radian_t(randVec(3))));
+ frc::Rotation2d{units::radian_t{randVec(2)}}};
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp
index 551dc78..6d1967f 100644
--- a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp
@@ -41,7 +41,7 @@
// update the dashboard mechanism's state
m_elevator->SetLength(kElevatorMinimumLength +
m_elevatorEncoder.GetDistance());
- m_wrist->SetAngle(units::degree_t(m_wristPotentiometer.Get()));
+ m_wrist->SetAngle(units::degree_t{m_wristPotentiometer.Get()});
}
void TeleopPeriodic() override {
diff --git a/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp
index 0092ec3..7a4325f 100644
--- a/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp
@@ -2,25 +2,47 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
+#include <frc/Encoder.h>
#include <frc/Joystick.h>
#include <frc/TimedRobot.h>
#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc/smartdashboard/SmartDashboard.h>
/**
* 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.
*
- * Joystick analog values range from -1 to 1 and speed controller inputs as
+ * Joystick analog values range from -1 to 1 and motor controller inputs as
* range from -1 to 1 making it easy to work together.
+ *
+ * In addition, the encoder value of an encoder connected to ports 0 and 1 is
+ * consistently sent to the Dashboard.
*/
class Robot : public frc::TimedRobot {
public:
void TeleopPeriodic() override { m_motor.Set(m_stick.GetY()); }
+ /*
+ * The RobotPeriodic function is called every control packet no matter the
+ * robot mode.
+ */
+ void RobotPeriodic() override {
+ frc::SmartDashboard::PutNumber("Encoder", m_encoder.GetDistance());
+ }
+
+ void RobotInit() override {
+ // 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((std::numbers::pi * 6) / 360.0);
+ }
+
private:
frc::Joystick m_stick{0};
frc::PWMSparkMax m_motor{0};
+ frc::Encoder m_encoder{0, 1};
};
#ifndef RUNNING_FRC_TESTS
diff --git a/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp
deleted file mode 100644
index 7d0e9ba..0000000
--- a/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp
+++ /dev/null
@@ -1,51 +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.
-
-#include <frc/Encoder.h>
-#include <frc/Joystick.h>
-#include <frc/TimedRobot.h>
-#include <frc/motorcontrol/PWMSparkMax.h>
-#include <frc/smartdashboard/SmartDashboard.h>
-#include <wpi/numbers>
-
-/**
- * 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.
- *
- * Joystick analog values range from -1 to 1 and speed controller inputs as
- * range from -1 to 1 making it easy to work together.
- *
- * In addition, the encoder value of an encoder connected to ports 0 and 1 is
- * consistently sent to the Dashboard.
- */
-class Robot : public frc::TimedRobot {
- public:
- void TeleopPeriodic() override { m_motor.Set(m_stick.GetY()); }
-
- /*
- * The RobotPeriodic function is called every control packet no matter the
- * robot mode.
- */
- void RobotPeriodic() override {
- frc::SmartDashboard::PutNumber("Encoder", m_encoder.GetDistance());
- }
-
- void RobotInit() override {
- // 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((wpi::numbers::pi * 6) / 360.0);
- }
-
- private:
- frc::Joystick m_stick{0};
- frc::PWMSparkMax m_motor{0};
- frc::Encoder m_encoder{0, 1};
-};
-
-#ifndef RUNNING_FRC_TESTS
-int main() {
- return frc::StartRobot<Robot>();
-}
-#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp
index 49ee31b..a72b129 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp
@@ -28,8 +28,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(m_driverController.GetLeftY(),
- m_driverController.GetRightX());
+ m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
+ -m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -38,21 +38,21 @@
// Configure your button bindings here
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
- .WhenPressed(&m_driveHalfSpeed)
- .WhenReleased(&m_driveFullSpeed);
+ frc2::JoystickButton{&m_driverController, 6}
+ .OnTrue(&m_driveHalfSpeed)
+ .OnFalse(&m_driveFullSpeed);
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
// Create a voltage constraint to ensure we don't accelerate too fast
- frc::DifferentialDriveVoltageConstraint autoVoltageConstraint(
- frc::SimpleMotorFeedforward<units::meters>(
- DriveConstants::ks, DriveConstants::kv, DriveConstants::ka),
- DriveConstants::kDriveKinematics, 10_V);
+ frc::DifferentialDriveVoltageConstraint autoVoltageConstraint{
+ frc::SimpleMotorFeedforward<units::meters>{
+ DriveConstants::ks, DriveConstants::kv, DriveConstants::ka},
+ DriveConstants::kDriveKinematics, 10_V};
// Set up config for trajectory
- frc::TrajectoryConfig config(AutoConstants::kMaxSpeed,
- AutoConstants::kMaxAcceleration);
+ frc::TrajectoryConfig config{AutoConstants::kMaxSpeed,
+ AutoConstants::kMaxAcceleration};
// Add kinematics to ensure max speed is actually obeyed
config.SetKinematics(DriveConstants::kDriveKinematics);
// Apply the voltage constraint
@@ -61,26 +61,27 @@
// An example trajectory to follow. All units in meters.
auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory(
// Start at the origin facing the +X direction
- frc::Pose2d(0_m, 0_m, frc::Rotation2d(0_deg)),
+ frc::Pose2d{0_m, 0_m, 0_deg},
// Pass through these two interior waypoints, making an 's' curve path
- {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)},
+ {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}},
// End 3 meters straight ahead of where we started, facing forward
- frc::Pose2d(3_m, 0_m, frc::Rotation2d(0_deg)),
+ frc::Pose2d{3_m, 0_m, 0_deg},
// Pass the config
config);
- frc2::RamseteCommand ramseteCommand(
- exampleTrajectory, [this]() { return m_drive.GetPose(); },
- frc::RamseteController(AutoConstants::kRamseteB,
- AutoConstants::kRamseteZeta),
- frc::SimpleMotorFeedforward<units::meters>(
- DriveConstants::ks, DriveConstants::kv, DriveConstants::ka),
+ frc2::RamseteCommand ramseteCommand{
+ exampleTrajectory,
+ [this]() { return m_drive.GetPose(); },
+ frc::RamseteController{AutoConstants::kRamseteB,
+ AutoConstants::kRamseteZeta},
+ frc::SimpleMotorFeedforward<units::meters>{
+ DriveConstants::ks, DriveConstants::kv, DriveConstants::ka},
DriveConstants::kDriveKinematics,
[this] { return m_drive.GetWheelSpeeds(); },
- frc2::PIDController(DriveConstants::kPDriveVel, 0, 0),
- frc2::PIDController(DriveConstants::kPDriveVel, 0, 0),
+ frc2::PIDController{DriveConstants::kPDriveVel, 0, 0},
+ frc2::PIDController{DriveConstants::kPDriveVel, 0, 0},
[this](auto left, auto right) { m_drive.TankDriveVolts(left, right); },
- {&m_drive});
+ {&m_drive}};
// Reset odometry to the starting pose of the trajectory.
m_drive.ResetOdometry(exampleTrajectory.InitialPose());
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp
index a5b853e..f8ec1db 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp
@@ -16,7 +16,7 @@
m_right2{kRightMotor2Port},
m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]},
m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]},
- m_odometry{m_gyro.GetRotation2d()} {
+ m_odometry{m_gyro.GetRotation2d(), units::meter_t{0}, units::meter_t{0}} {
// 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.
@@ -32,8 +32,8 @@
void DriveSubsystem::Periodic() {
// Implementation of subsystem periodic method goes here.
m_odometry.Update(m_gyro.GetRotation2d(),
- units::meter_t(m_leftEncoder.GetDistance()),
- units::meter_t(m_rightEncoder.GetDistance()));
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()});
}
void DriveSubsystem::ArcadeDrive(double fwd, double rot) {
@@ -80,11 +80,13 @@
}
frc::DifferentialDriveWheelSpeeds DriveSubsystem::GetWheelSpeeds() {
- return {units::meters_per_second_t(m_leftEncoder.GetRate()),
- units::meters_per_second_t(m_rightEncoder.GetRate())};
+ return {units::meters_per_second_t{m_leftEncoder.GetRate()},
+ units::meters_per_second_t{m_rightEncoder.GetRate()}};
}
void DriveSubsystem::ResetOdometry(frc::Pose2d pose) {
ResetEncoders();
- m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
+ m_odometry.ResetPosition(m_gyro.GetRotation2d(),
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}, pose);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h
index 174a028..18747d4 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/trajectory/constraint/DifferentialDriveKinematicsConstraint.h>
#include <units/acceleration.h>
@@ -10,7 +12,6 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
#pragma once
@@ -41,7 +42,7 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::numbers::pi) /
+ (kWheelDiameterInches * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
@@ -59,7 +60,7 @@
namespace AutoConstants {
constexpr auto kMaxSpeed = 3_mps;
-constexpr auto kMaxAcceleration = 3_mps_sq;
+constexpr auto kMaxAcceleration = 1_mps_sq;
// Reasonable baseline values for a RAMSETE follower in units of meters and
// seconds
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp
index 1871688..8c1e632 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp
@@ -23,12 +23,14 @@
void Drivetrain::UpdateOdometry() {
m_odometry.Update(m_gyro.GetRotation2d(),
- units::meter_t(m_leftEncoder.GetDistance()),
- units::meter_t(m_rightEncoder.GetDistance()));
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()});
}
void Drivetrain::ResetOdometry(const frc::Pose2d& pose) {
- m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
+ m_odometry.ResetPosition(m_gyro.GetRotation2d(),
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}, pose);
}
frc::Pose2d Drivetrain::GetPose() const {
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp
index f47da51..d7902f1 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp
@@ -79,9 +79,9 @@
// An example trajectory to follow.
frc::Trajectory m_trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
- frc::Pose2d(0_m, 0_m, 0_rad),
- {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)},
- frc::Pose2d(3_m, 0_m, 0_rad), frc::TrajectoryConfig(3_fps, 3_fps_sq));
+ frc::Pose2d{0_m, 0_m, 0_rad},
+ {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}},
+ frc::Pose2d{3_m, 0_m, 0_rad}, frc::TrajectoryConfig(3_fps, 3_fps_sq));
// The Ramsete Controller to follow the trajectory.
frc::RamseteController m_ramseteController;
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h
index 11fa523..40cc715 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h
@@ -4,6 +4,8 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
@@ -14,7 +16,6 @@
#include <frc/motorcontrol/PWMSparkMax.h>
#include <units/angular_velocity.h>
#include <units/length.h>
-#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -32,9 +33,9 @@
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ m_leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution);
- m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ m_rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -44,7 +45,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,
@@ -75,7 +76,9 @@
frc::AnalogGyro m_gyro{0};
frc::DifferentialDriveKinematics m_kinematics{kTrackWidth};
- frc::DifferentialDriveOdometry m_odometry{m_gyro.GetRotation2d()};
+ frc::DifferentialDriveOdometry m_odometry{
+ m_gyro.GetRotation2d(), units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}};
// Gains are for example purposes only - must be determined for your own
// robot!
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/RapidReactCommandBot.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/RapidReactCommandBot.cpp
new file mode 100644
index 0000000..c25f0e8
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/RapidReactCommandBot.cpp
@@ -0,0 +1,50 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "RapidReactCommandBot.h"
+
+#include <frc2/command/Command.h>
+#include <frc2/command/Commands.h>
+#include <frc2/command/button/Trigger.h>
+
+#include "Constants.h"
+
+void RapidReactCommandBot::ConfigureBindings() {
+ // Automatically run the storage motor whenever the ball storage is not full,
+ // and turn it off whenever it fills.
+ frc2::Trigger([this] {
+ return m_storage.IsFull();
+ }).WhileFalse(m_storage.RunCommand());
+
+ // Automatically disable and retract the intake whenever the ball storage is
+ // full.
+ frc2::Trigger([this] {
+ return m_storage.IsFull();
+ }).OnTrue(m_intake.RetractCommand());
+
+ // Control the drive with split-stick arcade controls
+ m_drive.SetDefaultCommand(m_drive.ArcadeDriveCommand(
+ [this] { return -m_driverController.GetLeftY(); },
+ [this] { return -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(
+ frc2::cmd::Parallel(
+ m_shooter.ShootCommand(ShooterConstants::kShooterTarget),
+ m_storage.RunCommand())
+ // Since we composed this inline we should give it a name
+ .WithName("Shoot"));
+}
+
+frc2::CommandPtr RapidReactCommandBot::GetAutonomousCommand() {
+ return m_drive
+ .DriveDistanceCommand(AutoConstants::kDriveDistance,
+ AutoConstants::kDriveSpeed)
+ .WithTimeout(AutoConstants::kTimeout);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp
new file mode 100644
index 0000000..06bbe40
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp
@@ -0,0 +1,58 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "Robot.h"
+
+void Robot::RobotInit() {
+ // Configure default commands and condition bindings on robot startup
+ m_robot.ConfigureBindings();
+}
+
+void Robot::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.
+ frc2::CommandScheduler::GetInstance().Run();
+}
+
+void Robot::DisabledInit() {}
+
+void Robot::DisabledPeriodic() {}
+
+void Robot::AutonomousInit() {
+ m_autonomousCommand = m_robot.GetAutonomousCommand();
+
+ if (m_autonomousCommand) {
+ m_autonomousCommand->Schedule();
+ }
+}
+
+void Robot::AutonomousPeriodic() {}
+
+void Robot::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) {
+ m_autonomousCommand->Cancel();
+ }
+}
+
+void Robot::TeleopPeriodic() {}
+
+void Robot::TestInit() {
+ // Cancels all running commands at the start of test mode.
+ frc2::CommandScheduler::GetInstance().CancelAll();
+}
+
+void Robot::TestPeriodic() {}
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp
new file mode 100644
index 0000000..98ff0ca
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp
@@ -0,0 +1,46 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/Drive.h"
+
+#include <utility>
+
+#include <frc2/command/Commands.h>
+
+Drive::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);
+}
+
+frc2::CommandPtr Drive::ArcadeDriveCommand(std::function<double()> fwd,
+ std::function<double()> rot) {
+ return Run([this, fwd = std::move(fwd), rot = std::move(rot)] {
+ m_drive.ArcadeDrive(fwd(), rot());
+ })
+ .WithName("ArcadeDrive");
+}
+
+frc2::CommandPtr Drive::DriveDistanceCommand(units::meter_t distance,
+ double speed) {
+ return RunOnce([this] {
+ // Reset encoders at the start of the command
+ m_leftEncoder.Reset();
+ m_rightEncoder.Reset();
+ })
+ // Drive forward at specified speed
+ .AndThen(Run([this, speed] { m_drive.ArcadeDrive(speed, 0.0); }))
+ .Until([this, distance] {
+ return units::math::max(units::meter_t(m_leftEncoder.GetDistance()),
+ units::meter_t(m_rightEncoder.GetDistance())) >=
+ distance;
+ })
+ // Stop the drive when the command ends
+ .FinallyDo([this](bool interrupted) { m_drive.StopMotor(); });
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Intake.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Intake.cpp
new file mode 100644
index 0000000..2069185
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Intake.cpp
@@ -0,0 +1,19 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/Intake.h"
+
+frc2::CommandPtr Intake::IntakeCommand() {
+ return RunOnce([this] { m_piston.Set(frc::DoubleSolenoid::kForward); })
+ .AndThen(Run([this] { m_motor.Set(1.0); }))
+ .WithName("Intake");
+}
+
+frc2::CommandPtr Intake::RetractCommand() {
+ return RunOnce([this] {
+ m_motor.Disable();
+ m_piston.Set(frc::DoubleSolenoid::kReverse);
+ })
+ .WithName("Retract");
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp
new file mode 100644
index 0000000..e8950ee
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp
@@ -0,0 +1,38 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/Shooter.h"
+
+#include <frc2/command/Commands.h>
+
+Shooter::Shooter() {
+ m_shooterFeedback.SetTolerance(ShooterConstants::kShooterTolerance.value());
+ m_shooterEncoder.SetDistancePerPulse(
+ ShooterConstants::kEncoderDistancePerPulse);
+
+ SetDefaultCommand(RunOnce([this] {
+ m_shooterMotor.Disable();
+ m_feederMotor.Disable();
+ })
+ .AndThen(Run([] {}))
+ .WithName("Idle"));
+}
+
+frc2::CommandPtr Shooter::ShootCommand(units::turns_per_second_t setpoint) {
+ return frc2::cmd::Parallel(
+ // Run the shooter flywheel at the desired setpoint using
+ // feedforward and feedback
+ Run([this, setpoint] {
+ m_shooterMotor.SetVoltage(
+ m_shooterFeedforward.Calculate(setpoint) +
+ units::volt_t(m_shooterFeedback.Calculate(
+ m_shooterEncoder.GetRate(), setpoint.value())));
+ }),
+ // Wait until the shooter has reached the setpoint, and then
+ // run the feeder
+ frc2::cmd::WaitUntil([this] {
+ return m_shooterFeedback.AtSetpoint();
+ }).AndThen([this] { m_feederMotor.Set(1.0); }))
+ .WithName("Shoot");
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Storage.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Storage.cpp
new file mode 100644
index 0000000..3e9dc62
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Storage.cpp
@@ -0,0 +1,18 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/Storage.h"
+
+Storage::Storage() {
+ SetDefaultCommand(
+ RunOnce([this] { m_motor.Disable(); }).AndThen([] {}).WithName("Idle"));
+}
+
+frc2::CommandPtr Storage::RunCommand() {
+ return Run([this] { m_motor.Set(1.0); }).WithName("Run");
+}
+
+bool Storage::IsFull() const {
+ return m_ballSensor.Get();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Constants.h
new file mode 100644
index 0000000..330eeba
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Constants.h
@@ -0,0 +1,79 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <numbers>
+
+#include <units/angle.h>
+#include <units/angular_velocity.h>
+#include <units/length.h>
+#include <units/time.h>
+#include <units/voltage.h>
+
+namespace DriveConstants {
+constexpr int kLeftMotor1Port = 0;
+constexpr int kLeftMotor2Port = 1;
+constexpr int kRightMotor1Port = 2;
+constexpr int kRightMotor2Port = 3;
+
+constexpr int kLeftEncoderPorts[]{0, 1};
+constexpr int kRightEncoderPorts[]{2, 3};
+constexpr bool kLeftEncoderReversed = false;
+constexpr bool kRightEncoderReversed = true;
+
+constexpr double kEncoderCPR = 1024;
+constexpr units::meter_t kWheelDiameter = 6.0_in;
+constexpr double kEncoderDistancePerPulse =
+ // Assumes the encoders are directly mounted on the wheel shafts
+ ((kWheelDiameter * std::numbers::pi) / kEncoderCPR).value();
+
+} // namespace DriveConstants
+
+namespace IntakeConstants {
+constexpr int kMotorPort = 6;
+constexpr int kSolenoidPorts[]{0, 1};
+} // namespace IntakeConstants
+
+namespace StorageConstants {
+constexpr int kMotorPort = 7;
+constexpr int kBallSensorPort = 6;
+} // namespace StorageConstants
+
+namespace ShooterConstants {
+constexpr int kEncoderPorts[]{4, 5};
+constexpr bool kEncoderReversed = false;
+constexpr double kEncoderCPR = 1024;
+constexpr double kEncoderDistancePerPulse =
+ // Distance units will be rotations
+ 1.0 / kEncoderCPR;
+
+constexpr int kShooterMotorPort = 4;
+constexpr int kFeederMotorPort = 5;
+
+constexpr auto kShooterFree = 5300_tps;
+constexpr auto kShooterTarget = 4000_tps;
+constexpr auto kShooterTolerance = 50_tps;
+
+// These are not real PID gains, and will have to be tuned for your specific
+// robot.
+constexpr double kP = 1;
+
+constexpr units::volt_t kS = 0.05_V;
+constexpr auto kV =
+ // Should have value 12V at free speed...
+ 12.0_V / kShooterFree;
+
+constexpr double kFeederSpeed = 0.5;
+} // namespace ShooterConstants
+
+namespace OIConstants {
+constexpr int kDriverControllerPort = 0;
+} // namespace OIConstants
+
+namespace AutoConstants {
+constexpr units::second_t kTimeout = 3.0_s;
+constexpr units::meter_t kDriveDistance = 2.0_m;
+constexpr double kDriveSpeed = 0.5;
+} // namespace AutoConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/RapidReactCommandBot.h b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/RapidReactCommandBot.h
new file mode 100644
index 0000000..4f733b7
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/RapidReactCommandBot.h
@@ -0,0 +1,52 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/button/CommandXboxController.h>
+
+#include "Constants.h"
+#include "subsystems/Drive.h"
+#include "subsystems/Intake.h"
+#include "subsystems/Shooter.h"
+#include "subsystems/Storage.h"
+
+/**
+ * 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.
+ */
+class RapidReactCommandBot {
+ public:
+ /**
+ * 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 Robot::RobotInit().
+ *
+ * <p>Event binding methods are available on the frc2::Trigger class.
+ */
+ void ConfigureBindings();
+
+ /**
+ * Use this to define the command that runs during autonomous.
+ *
+ * <p>Scheduled during Robot::AutonomousInit().
+ */
+ frc2::CommandPtr GetAutonomousCommand();
+
+ private:
+ // The robot's subsystems
+ Drive m_drive;
+ Intake m_intake;
+ Shooter m_shooter;
+ Storage m_storage;
+
+ // The driver's controller
+ frc2::CommandXboxController m_driverController{
+ OIConstants::kDriverControllerPort};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Robot.h
new file mode 100644
index 0000000..bab80f7
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Robot.h
@@ -0,0 +1,30 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <optional>
+
+#include <frc/TimedRobot.h>
+#include <frc2/command/CommandPtr.h>
+
+#include "RapidReactCommandBot.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void RobotInit() override;
+ void RobotPeriodic() override;
+ void DisabledInit() override;
+ void DisabledPeriodic() override;
+ void AutonomousInit() override;
+ void AutonomousPeriodic() override;
+ void TeleopInit() override;
+ void TeleopPeriodic() override;
+ void TestInit() override;
+ void TestPeriodic() override;
+
+ private:
+ RapidReactCommandBot m_robot;
+ std::optional<frc2::CommandPtr> m_autonomousCommand;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.h b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.h
new file mode 100644
index 0000000..9a39a14
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.h
@@ -0,0 +1,58 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <functional>
+
+#include <frc/Encoder.h>
+#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/SubsystemBase.h>
+#include <units/length.h>
+
+#include "Constants.h"
+
+class Drive : public frc2::SubsystemBase {
+ public:
+ Drive();
+ /**
+ * Returns a command that drives the robot with arcade controls.
+ *
+ * @param fwd the commanded forward movement
+ * @param rot the commanded rotation
+ */
+ [[nodiscard]] frc2::CommandPtr ArcadeDriveCommand(
+ std::function<double()> fwd, std::function<double()> rot);
+
+ /**
+ * Returns a command that drives the robot forward a specified distance at a
+ * specified speed.
+ *
+ * @param distance The distance to drive forward in meters
+ * @param speed The fraction of max speed at which to drive
+ */
+ [[nodiscard]] frc2::CommandPtr DriveDistanceCommand(units::meter_t distance,
+ double speed);
+
+ private:
+ frc::PWMSparkMax m_leftLeader{DriveConstants::kLeftMotor1Port};
+ frc::PWMSparkMax m_leftFollower{DriveConstants::kLeftMotor2Port};
+ frc::PWMSparkMax m_rightLeader{DriveConstants::kRightMotor1Port};
+ frc::PWMSparkMax m_rightFollower{DriveConstants::kRightMotor2Port};
+
+ frc::MotorControllerGroup m_leftMotors{m_leftLeader, m_leftFollower};
+ frc::MotorControllerGroup m_rightMotors{m_rightLeader, m_rightFollower};
+
+ frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
+
+ frc::Encoder m_leftEncoder{DriveConstants::kLeftEncoderPorts[0],
+ DriveConstants::kLeftEncoderPorts[1],
+ DriveConstants::kLeftEncoderReversed};
+ frc::Encoder m_rightEncoder{DriveConstants::kRightEncoderPorts[0],
+ DriveConstants::kRightEncoderPorts[1],
+ DriveConstants::kRightEncoderReversed};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Intake.h b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Intake.h
new file mode 100644
index 0000000..af8d39a
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Intake.h
@@ -0,0 +1,32 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <functional>
+
+#include <frc/DoubleSolenoid.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/SubsystemBase.h>
+
+#include "Constants.h"
+
+class Intake : public frc2::SubsystemBase {
+ public:
+ Intake() = default;
+
+ /** Returns a command that deploys the intake, and then runs the intake motor
+ * indefinitely. */
+ [[nodiscard]] frc2::CommandPtr IntakeCommand();
+
+ /** Returns a command that turns off and retracts the intake. */
+ [[nodiscard]] frc2::CommandPtr RetractCommand();
+
+ private:
+ frc::PWMSparkMax m_motor{IntakeConstants::kMotorPort};
+ frc::DoubleSolenoid m_piston{frc::PneumaticsModuleType::REVPH,
+ IntakeConstants::kSolenoidPorts[0],
+ IntakeConstants::kSolenoidPorts[1]};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.h b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.h
new file mode 100644
index 0000000..5ab2a63
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.h
@@ -0,0 +1,44 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <functional>
+
+#include <frc/Encoder.h>
+#include <frc/controller/PIDController.h>
+#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/SubsystemBase.h>
+#include <units/angle.h>
+#include <units/angular_velocity.h>
+
+#include "Constants.h"
+
+class Shooter : public frc2::SubsystemBase {
+ public:
+ Shooter();
+
+ /**
+ * 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
+ */
+ [[nodiscard]] frc2::CommandPtr ShootCommand(
+ units::turns_per_second_t setpoint);
+
+ private:
+ frc::PWMSparkMax m_shooterMotor{ShooterConstants::kShooterMotorPort};
+ frc::PWMSparkMax m_feederMotor{ShooterConstants::kFeederMotorPort};
+
+ frc::Encoder m_shooterEncoder{ShooterConstants::kEncoderPorts[0],
+ ShooterConstants::kEncoderPorts[1],
+ ShooterConstants::kEncoderReversed};
+ frc::SimpleMotorFeedforward<units::turns> m_shooterFeedforward{
+ ShooterConstants::kS, ShooterConstants::kV};
+ frc::PIDController m_shooterFeedback{ShooterConstants::kP, 0.0, 0.0};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Storage.h b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Storage.h
new file mode 100644
index 0000000..eab6da4
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Storage.h
@@ -0,0 +1,26 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/DigitalInput.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/SubsystemBase.h>
+
+#include "Constants.h"
+
+class Storage : frc2::SubsystemBase {
+ public:
+ Storage();
+ /** Returns a command that runs the storage motor indefinitely. */
+ [[nodiscard]] frc2::CommandPtr RunCommand();
+
+ /** Whether the ball storage is full. */
+ bool IsFull() const;
+
+ private:
+ frc::PWMSparkMax m_motor{StorageConstants::kMotorPort};
+ frc::DigitalInput m_ballSensor{StorageConstants::kBallSensorPort};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp
index 3cbad01..f6e1fa4 100644
--- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp
@@ -5,7 +5,7 @@
#include "RobotContainer.h"
#include <frc/smartdashboard/SmartDashboard.h>
-#include <frc2/command/PrintCommand.h>
+#include <frc2/command/Commands.h>
#include <frc2/command/button/Button.h>
#include "commands/TeleopArcadeDrive.h"
@@ -19,11 +19,11 @@
// Also set default commands here
m_drive.SetDefaultCommand(TeleopArcadeDrive(
&m_drive, [this] { return -m_controller.GetRawAxis(1); },
- [this] { return m_controller.GetRawAxis(2); }));
+ [this] { return -m_controller.GetRawAxis(2); }));
// Example of how to use the onboard IO
- m_onboardButtonA.WhenPressed(frc2::PrintCommand("Button A Pressed"))
- .WhenReleased(frc2::PrintCommand("Button A Released"));
+ m_onboardButtonA.OnTrue(frc2::cmd::Print("Button A Pressed"))
+ .OnFalse(frc2::cmd::Print("Button A Released"));
// Setup SmartDashboard options.
m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance);
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp
index 2d6c148..8c1f29e 100644
--- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp
@@ -4,8 +4,9 @@
#include "commands/TurnDegrees.h"
+#include <numbers>
+
#include <units/math.h>
-#include <wpi/numbers>
void TurnDegrees::Initialize() {
// Set motors to stop, read encoder values for starting point
@@ -26,7 +27,7 @@
// found here https://www.pololu.com/category/203/romi-chassis-kits, has a
// wheel placement diameter (149 mm) - width of the wheel (8 mm) = 141 mm
// or 5.551 inches. We then take into consideration the width of the tires.
- static auto inchPerDegree = (5.551_in * wpi::numbers::pi) / 360_deg;
+ static auto inchPerDegree = (5.551_in * std::numbers::pi) / 360_deg;
// Compare distance traveled from start to distance based on degree turn.
return GetAverageTurningDistance() >= inchPerDegree * m_angle;
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp
index 13ec2d8..979f8a0 100644
--- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp
@@ -4,7 +4,7 @@
#include "subsystems/Drivetrain.h"
-#include <wpi/numbers>
+#include <numbers>
#include "Constants.h"
@@ -20,9 +20,9 @@
// gearbox is constructed, you might have to invert the left side instead.
m_rightMotor.SetInverted(true);
- m_leftEncoder.SetDistancePerPulse(wpi::numbers::pi * kWheelDiameter.value() /
+ m_leftEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() /
kCountsPerRevolution);
- m_rightEncoder.SetDistancePerPulse(wpi::numbers::pi * kWheelDiameter.value() /
+ m_rightEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() /
kCountsPerRevolution);
ResetEncoders();
}
@@ -49,11 +49,11 @@
}
units::meter_t Drivetrain::GetLeftDistance() {
- return units::meter_t(m_leftEncoder.GetDistance());
+ return units::meter_t{m_leftEncoder.GetDistance()};
}
units::meter_t Drivetrain::GetRightDistance() {
- return units::meter_t(m_rightEncoder.GetDistance());
+ return units::meter_t{m_rightEncoder.GetDistance()};
}
units::meter_t Drivetrain::GetAverageDistance() {
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h
index 821542c..ab88b15 100644
--- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h
@@ -7,6 +7,7 @@
#include <frc/Joystick.h>
#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
+#include <frc2/command/CommandPtr.h>
#include <frc2/command/button/Button.h>
#include "Constants.h"
@@ -50,7 +51,7 @@
OnBoardIO::ChannelMode::INPUT};
// Example button
- frc2::Button m_onboardButtonA{
+ frc2::Trigger m_onboardButtonA{
[this] { return m_onboardIO.GetButtonAPressed(); }};
// Autonomous commands.
diff --git a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp
index 0c2e79c..e54c42f 100644
--- a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp
@@ -46,14 +46,14 @@
// Run instant command 1 when the 'A' button is pressed
frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
- .WhenPressed(&m_instantCommand1);
+ .OnTrue(&m_instantCommand1);
// Run instant command 2 when the 'X' button is pressed
frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kX)
- .WhenPressed(&m_instantCommand2);
+ .OnTrue(&m_instantCommand2);
// Run instant command 3 when the 'Y' button is held; release early to
// interrupt
frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kY)
- .WhenHeld(&m_waitCommand);
+ .OnTrue(&m_waitCommand);
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
diff --git a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp
index a114b92..1417801 100644
--- a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp
@@ -11,7 +11,7 @@
#include <frc/shuffleboard/Shuffleboard.h>
#include <frc/shuffleboard/ShuffleboardLayout.h>
#include <frc/shuffleboard/ShuffleboardTab.h>
-#include <networktables/NetworkTableEntry.h>
+#include <networktables/GenericEntry.h>
#include <networktables/NetworkTableInstance.h>
/**
@@ -57,7 +57,7 @@
void AutonomousInit() override {
// Update the Max Output for the drivetrain.
- m_robotDrive.SetMaxOutput(m_maxSpeed.GetDouble(1.0));
+ m_robotDrive.SetMaxOutput(m_maxSpeed->GetDouble(1.0));
}
private:
@@ -73,7 +73,7 @@
frc::Encoder m_rightEncoder{2, 3};
frc::AnalogPotentiometer m_ElevatorPot{0};
- nt::NetworkTableEntry m_maxSpeed;
+ nt::GenericEntry* m_maxSpeed;
};
#ifndef RUNNING_FRC_TESTS
diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp
index 098b997..93d0889 100644
--- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp
@@ -25,15 +25,17 @@
void Drivetrain::UpdateOdometry() {
m_odometry.Update(m_gyro.GetRotation2d(),
- units::meter_t(m_leftEncoder.GetDistance()),
- units::meter_t(m_rightEncoder.GetDistance()));
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()});
}
void Drivetrain::ResetOdometry(const frc::Pose2d& pose) {
m_leftEncoder.Reset();
m_rightEncoder.Reset();
m_drivetrainSimulator.SetPose(pose);
- m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
+ m_odometry.ResetPosition(m_gyro.GetRotation2d(),
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}, pose);
}
void Drivetrain::SimulationPeriodic() {
diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp
index a6eeef4..7ea7b09 100644
--- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp
@@ -14,12 +14,8 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
- // Flush NetworkTables every loop. This ensures that robot pose and other
- // values are sent during every iteration.
- SetNetworkTablesFlushEnabled(true);
-
m_trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
- frc::Pose2d(2_m, 2_m, 0_rad), {}, frc::Pose2d(6_m, 4_m, 0_rad),
+ frc::Pose2d{2_m, 2_m, 0_rad}, {}, frc::Pose2d{6_m, 4_m, 0_rad},
frc::TrajectoryConfig(2_mps, 2_mps_sq));
}
diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h
index d8c58c2..80363b5 100644
--- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h
@@ -4,6 +4,8 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
@@ -22,7 +24,6 @@
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/velocity.h>
-#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -40,9 +41,9 @@
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ m_leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution);
- m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ m_rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -56,7 +57,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,
@@ -91,7 +92,9 @@
frc::AnalogGyro m_gyro{0};
frc::DifferentialDriveKinematics m_kinematics{kTrackWidth};
- frc::DifferentialDriveOdometry m_odometry{m_gyro.GetRotation2d()};
+ frc::DifferentialDriveOdometry m_odometry{
+ m_gyro.GetRotation2d(), units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}};
// Gains are for example purposes only - must be determined for your own
// robot!
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp
index 0f03d37..aec9738 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp
@@ -2,10 +2,11 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
-#include <frc/controller/LinearPlantInversionFeedforward.h>
#include <frc/controller/LinearQuadraticRegulator.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/estimator/KalmanFilter.h>
@@ -16,7 +17,6 @@
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/angle.h>
#include <units/moment_of_inertia.h>
-#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -64,8 +64,8 @@
// qelms. Velocity error tolerance, in radians and radians per second.
// Decrease this to more heavily penalize state excursion, or make the
// controller behave more aggressively.
- {1.0 * 2.0 * wpi::numbers::pi / 360.0,
- 10.0 * 2.0 * wpi::numbers::pi / 360.0},
+ {1.0 * 2.0 * std::numbers::pi / 360.0,
+ 10.0 * 2.0 * std::numbers::pi / 360.0},
// relms. Control effort (voltage) tolerance. Decrease this to more
// heavily penalize control effort, or make the controller less
// aggressive. 12 is a good starting point because that is the
@@ -94,16 +94,15 @@
public:
void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
- m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
+ m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0);
}
void TeleopInit() override {
- m_loop.Reset(
- Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
+ m_loop.Reset(frc::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()});
m_lastProfiledReference = {
- units::radian_t(m_encoder.GetDistance()),
- units::radians_per_second_t(m_encoder.GetRate())};
+ units::radian_t{m_encoder.GetDistance()},
+ units::radians_per_second_t{m_encoder.GetRate()}};
}
void TeleopPeriodic() override {
@@ -122,12 +121,11 @@
m_lastProfiledReference))
.Calculate(20_ms);
- m_loop.SetNextR(
- Eigen::Vector<double, 2>{m_lastProfiledReference.position.value(),
- m_lastProfiledReference.velocity.value()});
+ m_loop.SetNextR(frc::Vectord<2>{m_lastProfiledReference.position.value(),
+ m_lastProfiledReference.velocity.value()});
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
+ m_loop.Correct(frc::Vectord<1>{m_encoder.GetDistance()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -136,7 +134,7 @@
// Send the new calculated voltage to the motors.
// voltage = duty cycle * battery voltage, so
// duty cycle = voltage / battery voltage
- m_motor.SetVoltage(units::volt_t(m_loop.U(0)));
+ m_motor.SetVoltage(units::volt_t{m_loop.U(0)});
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp
index 318dc61..fce5aec 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp
@@ -9,11 +9,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>
-void Robot::RobotInit() {
- // Flush NetworkTables every loop. This ensures that robot pose and other
- // values are sent during every iteration.
- SetNetworkTablesFlushEnabled(true);
-}
+void Robot::RobotInit() {}
/**
* This function is called every 20 ms, no matter the mode. Use
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp
index a4245d6..fec6de3 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp
@@ -26,10 +26,15 @@
ConfigureButtonBindings();
// Set up default drive command
+ // 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
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
- m_driverController.GetRightX());
+ -m_driverController.GetLeftX());
},
{&m_drive}));
}
@@ -48,8 +53,8 @@
// While holding the shoulder button, drive at half speed
frc2::JoystickButton(&m_driverController,
frc::XboxController::Button::kRightBumper)
- .WhenPressed(&m_driveHalfSpeed)
- .WhenReleased(&m_driveFullSpeed);
+ .OnTrue(&m_driveHalfSpeed)
+ .OnFalse(&m_driveFullSpeed);
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
@@ -70,24 +75,24 @@
// An example trajectory to follow. All units in meters.
auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory(
// Start at (1, 2) facing the +X direction
- frc::Pose2d(1_m, 2_m, 0_deg),
+ frc::Pose2d{1_m, 2_m, 0_deg},
// Pass through these two interior waypoints, making an 's' curve path
- {frc::Translation2d(2_m, 3_m), frc::Translation2d(3_m, 1_m)},
+ {frc::Translation2d{2_m, 3_m}, frc::Translation2d{3_m, 1_m}},
// End 3 meters straight ahead of where we started, facing forward
- frc::Pose2d(4_m, 2_m, 0_deg),
+ frc::Pose2d{4_m, 2_m, 0_deg},
// Pass the config
config);
frc2::RamseteCommand ramseteCommand(
exampleTrajectory, [this] { return m_drive.GetPose(); },
- frc::RamseteController(AutoConstants::kRamseteB,
- AutoConstants::kRamseteZeta),
+ frc::RamseteController{AutoConstants::kRamseteB,
+ AutoConstants::kRamseteZeta},
frc::SimpleMotorFeedforward<units::meters>(
DriveConstants::ks, DriveConstants::kv, DriveConstants::ka),
DriveConstants::kDriveKinematics,
[this] { return m_drive.GetWheelSpeeds(); },
- frc2::PIDController(DriveConstants::kPDriveVel, 0, 0),
- frc2::PIDController(DriveConstants::kPDriveVel, 0, 0),
+ frc2::PIDController{DriveConstants::kPDriveVel, 0, 0},
+ frc2::PIDController{DriveConstants::kPDriveVel, 0, 0},
[this](auto left, auto right) { m_drive.TankDriveVolts(left, right); },
{&m_drive});
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp
index 0971549..15d8596 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp
@@ -30,8 +30,8 @@
void DriveSubsystem::Periodic() {
// Implementation of subsystem periodic method goes here.
m_odometry.Update(m_gyro.GetRotation2d(),
- units::meter_t(m_leftEncoder.GetDistance()),
- units::meter_t(m_rightEncoder.GetDistance()));
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()});
m_fieldSim.SetRobotPose(m_odometry.GetPose());
}
@@ -102,12 +102,14 @@
}
frc::DifferentialDriveWheelSpeeds DriveSubsystem::GetWheelSpeeds() {
- return {units::meters_per_second_t(m_leftEncoder.GetRate()),
- units::meters_per_second_t(m_rightEncoder.GetRate())};
+ return {units::meters_per_second_t{m_leftEncoder.GetRate()},
+ units::meters_per_second_t{m_rightEncoder.GetRate()}};
}
void DriveSubsystem::ResetOdometry(frc::Pose2d pose) {
ResetEncoders();
m_drivetrainSimulator.SetPose(pose);
- m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
+ m_odometry.ResetPosition(m_gyro.GetRotation2d(),
+ units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}, pose);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h
index b12eef1..d8080ca 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
@@ -12,7 +14,6 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
#pragma once
@@ -43,7 +44,7 @@
constexpr auto kWheelDiameter = 6_in;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameter.value() * wpi::numbers::pi) /
+ (kWheelDiameter.value() * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h
index 395133c..57392c7 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h
@@ -144,17 +144,21 @@
// The left-side drive encoder
frc::Encoder m_leftEncoder{DriveConstants::kLeftEncoderPorts[0],
- DriveConstants::kLeftEncoderPorts[1]};
+ DriveConstants::kLeftEncoderPorts[1],
+ DriveConstants::kLeftEncoderReversed};
// The right-side drive encoder
frc::Encoder m_rightEncoder{DriveConstants::kRightEncoderPorts[0],
- DriveConstants::kRightEncoderPorts[1]};
+ DriveConstants::kRightEncoderPorts[1],
+ DriveConstants::kRightEncoderReversed};
// The gyro sensor
frc::ADXRS450_Gyro m_gyro;
// Odometry class for tracking robot pose
- frc::DifferentialDriveOdometry m_odometry{m_gyro.GetRotation2d()};
+ frc::DifferentialDriveOdometry m_odometry{
+ m_gyro.GetRotation2d(), units::meter_t{m_leftEncoder.GetDistance()},
+ units::meter_t{m_rightEncoder.GetDistance()}};
// These classes help simulate our drivetrain.
frc::sim::DifferentialDrivetrainSim m_drivetrainSimulator{
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp
index 4c9d65e..7decddd 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
@@ -17,7 +19,6 @@
#include <units/length.h>
#include <units/mass.h>
#include <units/velocity.h>
-#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -90,17 +91,16 @@
public:
void RobotInit() override {
// Circumference = pi * d, so distance per click = pi * d / counts
- m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi * kDrumRadius.value() /
+ m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi * kDrumRadius.value() /
4096.0);
}
void TeleopInit() override {
// Reset our loop to make sure it's in a known state.
- m_loop.Reset(
- Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
+ m_loop.Reset(frc::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()});
- m_lastProfiledReference = {units::meter_t(m_encoder.GetDistance()),
- units::meters_per_second_t(m_encoder.GetRate())};
+ m_lastProfiledReference = {units::meter_t{m_encoder.GetDistance()},
+ units::meters_per_second_t{m_encoder.GetRate()}};
}
void TeleopPeriodic() override {
@@ -119,12 +119,11 @@
m_lastProfiledReference))
.Calculate(20_ms);
- m_loop.SetNextR(
- Eigen::Vector<double, 2>{m_lastProfiledReference.position.value(),
- m_lastProfiledReference.velocity.value()});
+ m_loop.SetNextR(frc::Vectord<2>{m_lastProfiledReference.position.value(),
+ m_lastProfiledReference.velocity.value()});
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
+ m_loop.Correct(frc::Vectord<1>{m_encoder.GetDistance()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -133,7 +132,7 @@
// Send the new calculated voltage to the motors.
// voltage = duty cycle * battery voltage, so
// duty cycle = voltage / battery voltage
- m_motor.SetVoltage(units::volt_t(m_loop.U(0)));
+ m_motor.SetVoltage(units::volt_t{m_loop.U(0)});
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
index 636916f..5d413ab 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/DriverStation.h>
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
@@ -14,7 +16,6 @@
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
#include <units/angular_velocity.h>
-#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -81,11 +82,11 @@
public:
void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
- m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
+ m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0);
}
void TeleopInit() override {
- m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
+ m_loop.Reset(frc::Vectord<1>{m_encoder.GetRate()});
}
void TeleopPeriodic() override {
@@ -93,14 +94,14 @@
// setpoint of a PID controller.
if (m_joystick.GetRightBumper()) {
// We pressed the bumper, so let's set our next reference
- m_loop.SetNextR(Eigen::Vector<double, 1>{kSpinup.value()});
+ m_loop.SetNextR(frc::Vectord<1>{kSpinup.value()});
} else {
// We released the bumper, so let's spin down
- m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
+ m_loop.SetNextR(frc::Vectord<1>{0.0});
}
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
+ m_loop.Correct(frc::Vectord<1>{m_encoder.GetRate()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -109,7 +110,7 @@
// Send the new calculated voltage to the motors.
// voltage = duty cycle * battery voltage, so
// duty cycle = voltage / battery voltage
- m_motor.SetVoltage(units::volt_t(m_loop.U(0)));
+ m_motor.SetVoltage(units::volt_t{m_loop.U(0)});
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
index 69d1953..d3bab6e 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
@@ -2,11 +2,12 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/DriverStation.h>
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
-#include <frc/controller/LinearPlantInversionFeedforward.h>
#include <frc/controller/LinearQuadraticRegulator.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/estimator/KalmanFilter.h>
@@ -14,7 +15,6 @@
#include <frc/system/LinearSystemLoop.h>
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
-#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -82,11 +82,11 @@
public:
void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
- m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
+ m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0);
}
void TeleopInit() override {
- m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
+ m_loop.Reset(frc::Vectord<1>{m_encoder.GetRate()});
}
void TeleopPeriodic() override {
@@ -94,14 +94,14 @@
// setpoint of a PID controller.
if (m_joystick.GetRightBumper()) {
// We pressed the bumper, so let's set our next reference
- m_loop.SetNextR(Eigen::Vector<double, 1>{kSpinup.value()});
+ m_loop.SetNextR(frc::Vectord<1>{kSpinup.value()});
} else {
// We released the bumper, so let's spin down
- m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
+ m_loop.SetNextR(frc::Vectord<1>{0.0});
}
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
+ m_loop.Correct(frc::Vectord<1>{m_encoder.GetRate()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -110,7 +110,7 @@
// Send the new calculated voltage to the motors.
// voltage = duty cycle * battery voltage, so
// duty cycle = voltage / battery voltage
- m_motor.SetVoltage(units::volt_t(m_loop.U(0)));
+ m_motor.SetVoltage(units::volt_t{m_loop.U(0)});
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp
index 709f403..537da53 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp
@@ -23,7 +23,7 @@
}
void Drivetrain::UpdateOdometry() {
- m_odometry.Update(m_gyro.GetRotation2d(), m_frontLeft.GetState(),
- m_frontRight.GetState(), m_backLeft.GetState(),
- m_backRight.GetState());
+ m_odometry.Update(m_gyro.GetRotation2d(),
+ {m_frontLeft.GetPosition(), m_frontRight.GetPosition(),
+ m_backLeft.GetPosition(), m_backRight.GetPosition()});
}
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
index 24a6527..0f9e27e 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
@@ -4,8 +4,9 @@
#include "SwerveModule.h"
+#include <numbers>
+
#include <frc/geometry/Rotation2d.h>
-#include <wpi/numbers>
SwerveModule::SwerveModule(const int driveMotorChannel,
const int turningMotorChannel,
@@ -20,31 +21,36 @@
// Set the distance per pulse for the drive encoder. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_driveEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ m_driveEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution);
// Set the distance (in this case, angle) per pulse for the turning encoder.
- // This is the the angle through an entire rotation (2 * wpi::numbers::pi)
+ // This is the the angle through an entire rotation (2 * std::numbers::pi)
// divided by the encoder resolution.
- m_turningEncoder.SetDistancePerPulse(2 * wpi::numbers::pi /
+ m_turningEncoder.SetDistancePerPulse(2 * std::numbers::pi /
kEncoderResolution);
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
m_turningPIDController.EnableContinuousInput(
- -units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
+ -units::radian_t{std::numbers::pi}, units::radian_t{std::numbers::pi});
}
frc::SwerveModuleState SwerveModule::GetState() const {
return {units::meters_per_second_t{m_driveEncoder.GetRate()},
- frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))};
+ units::radian_t{m_turningEncoder.GetDistance()}};
+}
+
+frc::SwerveModulePosition SwerveModule::GetPosition() const {
+ return {units::meter_t{m_driveEncoder.GetDistance()},
+ units::radian_t{m_turningEncoder.GetDistance()}};
}
void SwerveModule::SetDesiredState(
const frc::SwerveModuleState& referenceState) {
// Optimize the reference state to avoid spinning further than 90 degrees
const auto state = frc::SwerveModuleState::Optimize(
- referenceState, units::radian_t(m_turningEncoder.Get()));
+ referenceState, units::radian_t{m_turningEncoder.GetDistance()});
// Calculate the drive output from the drive PID controller.
const auto driveOutput = m_drivePIDController.Calculate(
@@ -54,7 +60,7 @@
// Calculate the turning motor output from the turning PID controller.
const auto turnOutput = m_turningPIDController.Calculate(
- units::radian_t(m_turningEncoder.Get()), state.angle.Radians());
+ units::radian_t{m_turningEncoder.GetDistance()}, state.angle.Radians());
const auto turnFeedforward = m_turnFeedforward.Calculate(
m_turningPIDController.GetSetpoint().velocity);
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h
index 2b3cc0e..87233d2 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h
@@ -4,11 +4,12 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
#include <frc/kinematics/SwerveDriveOdometry.h>
-#include <wpi/numbers>
#include "SwerveModule.h"
@@ -27,7 +28,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
private:
frc::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m};
@@ -46,5 +47,9 @@
m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation,
m_backRightLocation};
- frc::SwerveDriveOdometry<4> m_odometry{m_kinematics, m_gyro.GetRotation2d()};
+ frc::SwerveDriveOdometry<4> m_odometry{
+ m_kinematics,
+ m_gyro.GetRotation2d(),
+ {m_frontLeft.GetPosition(), m_frontRight.GetPosition(),
+ m_backLeft.GetPosition(), m_backRight.GetPosition()}};
};
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h
index 00a938b..1861498 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h
@@ -4,17 +4,19 @@
#pragma once
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/kinematics/SwerveModulePosition.h>
#include <frc/kinematics/SwerveModuleState.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
class SwerveModule {
public:
@@ -22,6 +24,7 @@
int driveEncoderChannelA, int driveEncoderChannelB,
int turningEncoderChannelA, int turningEncoderChannelB);
frc::SwerveModuleState GetState() const;
+ frc::SwerveModulePosition GetPosition() const;
void SetDesiredState(const frc::SwerveModuleState& state);
private:
@@ -29,9 +32,9 @@
static constexpr int kEncoderResolution = 4096;
static constexpr auto kModuleMaxAngularVelocity =
- wpi::numbers::pi * 1_rad_per_s; // radians per second
+ std::numbers::pi * 1_rad_per_s; // radians per second
static constexpr auto kModuleMaxAngularAcceleration =
- wpi::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
+ std::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
frc::PWMSparkMax m_driveMotor;
frc::PWMSparkMax m_turningMotor;
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
index a35314e..52b25b9 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
@@ -35,9 +35,9 @@
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
m_drive.Drive(
- units::meters_per_second_t(m_driverController.GetLeftY()),
- units::meters_per_second_t(m_driverController.GetLeftX()),
- units::radians_per_second_t(m_driverController.GetRightX()), false);
+ units::meters_per_second_t{m_driverController.GetLeftY()},
+ units::meters_per_second_t{m_driverController.GetLeftX()},
+ units::radians_per_second_t{m_driverController.GetRightX()}, false);
},
{&m_drive}));
}
@@ -54,11 +54,11 @@
// An example trajectory to follow. All units in meters.
auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory(
// Start at the origin facing the +X direction
- frc::Pose2d(0_m, 0_m, frc::Rotation2d(0_deg)),
+ frc::Pose2d{0_m, 0_m, 0_deg},
// Pass through these two interior waypoints, making an 's' curve path
- {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)},
+ {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}},
// End 3 meters straight ahead of where we started, facing forward
- frc::Pose2d(3_m, 0_m, frc::Rotation2d(0_deg)),
+ frc::Pose2d{3_m, 0_m, 0_deg},
// Pass the config
config);
@@ -66,16 +66,16 @@
AutoConstants::kPThetaController, 0, 0,
AutoConstants::kThetaControllerConstraints};
- thetaController.EnableContinuousInput(units::radian_t(-wpi::numbers::pi),
- units::radian_t(wpi::numbers::pi));
+ thetaController.EnableContinuousInput(units::radian_t{-std::numbers::pi},
+ units::radian_t{std::numbers::pi});
frc2::SwerveControllerCommand<4> swerveControllerCommand(
exampleTrajectory, [this]() { return m_drive.GetPose(); },
m_drive.kDriveKinematics,
- frc2::PIDController(AutoConstants::kPXController, 0, 0),
- frc2::PIDController(AutoConstants::kPYController, 0, 0), thetaController,
+ frc2::PIDController{AutoConstants::kPXController, 0, 0},
+ frc2::PIDController{AutoConstants::kPYController, 0, 0}, thetaController,
[this](auto moduleStates) { m_drive.SetModuleStates(moduleStates); },
@@ -88,10 +88,5 @@
return new frc2::SequentialCommandGroup(
std::move(swerveControllerCommand),
frc2::InstantCommand(
- [this]() {
- m_drive.Drive(units::meters_per_second_t(0),
- units::meters_per_second_t(0),
- units::radians_per_second_t(0), false);
- },
- {}));
+ [this]() { m_drive.Drive(0_mps, 0_mps, 0_rad_per_s, false); }, {}));
}
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp
index fd15100..4b60372 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp
@@ -36,13 +36,17 @@
kRearRightDriveEncoderPorts, kRearRightTurningEncoderPorts,
kRearRightDriveEncoderReversed, kRearRightTurningEncoderReversed},
- m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d()} {}
+ m_odometry{kDriveKinematics,
+ m_gyro.GetRotation2d(),
+ {m_frontLeft.GetPosition(), m_frontRight.GetPosition(),
+ m_rearLeft.GetPosition(), m_rearRight.GetPosition()},
+ frc::Pose2d{}} {}
void DriveSubsystem::Periodic() {
// Implementation of subsystem periodic method goes here.
- m_odometry.Update(m_gyro.GetRotation2d(), m_frontLeft.GetState(),
- m_rearLeft.GetState(), m_frontRight.GetState(),
- m_rearRight.GetState());
+ m_odometry.Update(m_gyro.GetRotation2d(),
+ {m_frontLeft.GetPosition(), m_rearLeft.GetPosition(),
+ m_frontRight.GetPosition(), m_rearRight.GetPosition()});
}
void DriveSubsystem::Drive(units::meters_per_second_t xSpeed,
@@ -98,6 +102,9 @@
}
void DriveSubsystem::ResetOdometry(frc::Pose2d pose) {
- m_odometry.ResetPosition(pose,
- frc::Rotation2d(units::degree_t(GetHeading())));
+ m_odometry.ResetPosition(
+ GetHeading(),
+ {m_frontLeft.GetPosition(), m_frontRight.GetPosition(),
+ m_rearLeft.GetPosition(), m_rearRight.GetPosition()},
+ pose);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp
index 4d20ec8..bb0362e 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp
@@ -4,8 +4,9 @@
#include "subsystems/SwerveModule.h"
+#include <numbers>
+
#include <frc/geometry/Rotation2d.h>
-#include <wpi/numbers>
#include "Constants.h"
@@ -27,7 +28,7 @@
ModuleConstants::kDriveEncoderDistancePerPulse);
// Set the distance (in this case, angle) per pulse for the turning encoder.
- // This is the the angle through an entire rotation (2 * wpi::numbers::pi)
+ // This is the the angle through an entire rotation (2 * std::numbers::pi)
// divided by the encoder resolution.
m_turningEncoder.SetDistancePerPulse(
ModuleConstants::kTurningEncoderDistancePerPulse);
@@ -35,19 +36,24 @@
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
m_turningPIDController.EnableContinuousInput(
- units::radian_t(-wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
+ units::radian_t{-std::numbers::pi}, units::radian_t{std::numbers::pi});
}
frc::SwerveModuleState SwerveModule::GetState() {
return {units::meters_per_second_t{m_driveEncoder.GetRate()},
- frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))};
+ units::radian_t{m_turningEncoder.GetDistance()}};
+}
+
+frc::SwerveModulePosition SwerveModule::GetPosition() {
+ return {units::meter_t{m_driveEncoder.GetDistance()},
+ units::radian_t{m_turningEncoder.GetDistance()}};
}
void SwerveModule::SetDesiredState(
const frc::SwerveModuleState& referenceState) {
// Optimize the reference state to avoid spinning further than 90 degrees
const auto state = frc::SwerveModuleState::Optimize(
- referenceState, units::radian_t(m_turningEncoder.Get()));
+ referenceState, units::radian_t{m_turningEncoder.GetDistance()});
// Calculate the drive output from the drive PID controller.
const auto driveOutput = m_drivePIDController.Calculate(
@@ -55,7 +61,7 @@
// Calculate the turning motor output from the turning PID controller.
auto turnOutput = m_turningPIDController.Calculate(
- units::radian_t(m_turningEncoder.Get()), state.angle.Radians());
+ units::radian_t{m_turningEncoder.GetDistance()}, state.angle.Radians());
// Set the motor outputs.
m_driveMotor.Set(driveOutput);
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h
index e6fa136..cacab87 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h
@@ -2,17 +2,19 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
+#include <numbers>
+
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/acceleration.h>
#include <units/angle.h>
+#include <units/angular_acceleration.h>
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
#pragma once
@@ -76,27 +78,22 @@
constexpr double kWheelDiameterMeters = 0.15;
constexpr double kDriveEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterMeters * wpi::numbers::pi) /
+ (kWheelDiameterMeters * std::numbers::pi) /
static_cast<double>(kEncoderCPR);
constexpr double kTurningEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (wpi::numbers::pi * 2) / static_cast<double>(kEncoderCPR);
+ (std::numbers::pi * 2) / static_cast<double>(kEncoderCPR);
constexpr double kPModuleTurningController = 1;
constexpr double kPModuleDriveController = 1;
} // namespace ModuleConstants
namespace AutoConstants {
-using radians_per_second_squared_t =
- units::compound_unit<units::radians,
- units::inverse<units::squared<units::second>>>;
-
-constexpr auto kMaxSpeed = units::meters_per_second_t(3);
-constexpr auto kMaxAcceleration = units::meters_per_second_squared_t(3);
-constexpr auto kMaxAngularSpeed = units::radians_per_second_t(3.142);
-constexpr auto kMaxAngularAcceleration =
- units::unit_t<radians_per_second_squared_t>(3.142);
+constexpr auto kMaxSpeed = 3_mps;
+constexpr auto kMaxAcceleration = 3_mps_sq;
+constexpr auto kMaxAngularSpeed = 3.142_rad_per_s;
+constexpr auto kMaxAngularAcceleration = 3.142_rad_per_s_sq;
constexpr double kPXController = 0.5;
constexpr double kPYController = 0.5;
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h
index 5233f3f..e9ed17b 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h
@@ -94,10 +94,10 @@
0.7_m; // Distance between centers of front and back wheels on robot
frc::SwerveDriveKinematics<4> kDriveKinematics{
- frc::Translation2d(kWheelBase / 2, kTrackWidth / 2),
- frc::Translation2d(kWheelBase / 2, -kTrackWidth / 2),
- frc::Translation2d(-kWheelBase / 2, kTrackWidth / 2),
- frc::Translation2d(-kWheelBase / 2, -kTrackWidth / 2)};
+ frc::Translation2d{kWheelBase / 2, kTrackWidth / 2},
+ frc::Translation2d{kWheelBase / 2, -kTrackWidth / 2},
+ frc::Translation2d{-kWheelBase / 2, kTrackWidth / 2},
+ frc::Translation2d{-kWheelBase / 2, -kTrackWidth / 2}};
private:
// Components (e.g. motor controllers and sensors) should generally be
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h
index 4208b35..f0d5ede 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h
@@ -4,22 +4,20 @@
#pragma once
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
#include <frc/geometry/Rotation2d.h>
+#include <frc/kinematics/SwerveModulePosition.h>
#include <frc/kinematics/SwerveModuleState.h>
#include <frc/motorcontrol/Spark.h>
#include <frc/trajectory/TrapezoidProfile.h>
-#include <wpi/numbers>
#include "Constants.h"
class SwerveModule {
- using radians_per_second_squared_t =
- units::compound_unit<units::radians,
- units::inverse<units::squared<units::second>>>;
-
public:
SwerveModule(int driveMotorChannel, int turningMotorChannel,
const int driveEncoderPorts[2], const int turningEncoderPorts[2],
@@ -27,6 +25,8 @@
frc::SwerveModuleState GetState();
+ frc::SwerveModulePosition GetPosition();
+
void SetDesiredState(const frc::SwerveModuleState& state);
void ResetEncoders();
@@ -36,12 +36,10 @@
// ProfiledPIDController's constraints only take in meters per second and
// meters per second squared.
- static constexpr units::radians_per_second_t kModuleMaxAngularVelocity =
- units::radians_per_second_t(wpi::numbers::pi); // radians per second
- static constexpr units::unit_t<radians_per_second_squared_t>
- kModuleMaxAngularAcceleration =
- units::unit_t<radians_per_second_squared_t>(
- wpi::numbers::pi * 2.0); // radians per second squared
+ static constexpr auto kModuleMaxAngularVelocity =
+ units::radians_per_second_t{std::numbers::pi};
+ static constexpr auto kModuleMaxAngularAcceleration =
+ units::radians_per_second_squared_t{std::numbers::pi * 2.0};
frc::Spark m_driveMotor;
frc::Spark m_turningMotor;
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp
index 33a3233..5402e87 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp
@@ -27,9 +27,9 @@
}
void Drivetrain::UpdateOdometry() {
- m_poseEstimator.Update(m_gyro.GetRotation2d(), m_frontLeft.GetState(),
- m_frontRight.GetState(), m_backLeft.GetState(),
- m_backRight.GetState());
+ m_poseEstimator.Update(m_gyro.GetRotation2d(),
+ {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
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp
index 968ccad..c5a0839 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp
@@ -4,8 +4,9 @@
#include "SwerveModule.h"
+#include <numbers>
+
#include <frc/geometry/Rotation2d.h>
-#include <wpi/numbers>
SwerveModule::SwerveModule(const int driveMotorChannel,
const int turningMotorChannel,
@@ -20,31 +21,36 @@
// Set the distance per pulse for the drive encoder. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_driveEncoder.SetDistancePerPulse(2 * wpi::numbers::pi *
+ m_driveEncoder.SetDistancePerPulse(2 * std::numbers::pi *
kWheelRadius.value() / kEncoderResolution);
// Set the distance (in this case, angle) per pulse for the turning encoder.
- // This is the the angle through an entire rotation (2 * wpi::numbers::pi)
+ // This is the the angle through an entire rotation (2 * std::numbers::pi)
// divided by the encoder resolution.
- m_turningEncoder.SetDistancePerPulse(2 * wpi::numbers::pi /
+ m_turningEncoder.SetDistancePerPulse(2 * std::numbers::pi /
kEncoderResolution);
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
m_turningPIDController.EnableContinuousInput(
- -units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
+ -units::radian_t{std::numbers::pi}, units::radian_t{std::numbers::pi});
}
frc::SwerveModuleState SwerveModule::GetState() const {
return {units::meters_per_second_t{m_driveEncoder.GetRate()},
- frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))};
+ units::radian_t{m_turningEncoder.GetDistance()}};
+}
+
+frc::SwerveModulePosition SwerveModule::GetPosition() const {
+ return {units::meter_t{m_driveEncoder.GetDistance()},
+ units::radian_t{m_turningEncoder.GetDistance()}};
}
void SwerveModule::SetDesiredState(
const frc::SwerveModuleState& referenceState) {
// Optimize the reference state to avoid spinning further than 90 degrees
const auto state = frc::SwerveModuleState::Optimize(
- referenceState, units::radian_t(m_turningEncoder.Get()));
+ referenceState, units::radian_t{m_turningEncoder.GetDistance()});
// Calculate the drive output from the drive PID controller.
const auto driveOutput = m_drivePIDController.Calculate(
@@ -54,7 +60,7 @@
// Calculate the turning motor output from the turning PID controller.
const auto turnOutput = m_turningPIDController.Calculate(
- units::radian_t(m_turningEncoder.Get()), state.angle.Radians());
+ units::radian_t{m_turningEncoder.GetDistance()}, state.angle.Radians());
const auto turnFeedforward = m_turnFeedforward.Calculate(
m_turningPIDController.GetSetpoint().velocity);
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h
index f525729..e042291 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h
@@ -4,12 +4,13 @@
#pragma once
+#include <numbers>
+
#include <frc/AnalogGyro.h>
#include <frc/estimator/SwerveDrivePoseEstimator.h>
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
#include <frc/kinematics/SwerveDriveOdometry.h>
-#include <wpi/numbers>
#include "SwerveModule.h"
@@ -27,7 +28,7 @@
static constexpr auto kMaxSpeed = 3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::numbers::pi}; // 1/2 rotation per second
+ std::numbers::pi}; // 1/2 rotation per second
private:
frc::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m};
@@ -49,6 +50,11 @@
// Gains are for example purposes only - must be determined for your own
// robot!
frc::SwerveDrivePoseEstimator<4> m_poseEstimator{
- frc::Rotation2d(), frc::Pose2d(), m_kinematics,
- {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}};
+ m_kinematics,
+ frc::Rotation2d{},
+ {m_frontLeft.GetPosition(), m_frontRight.GetPosition(),
+ m_backLeft.GetPosition(), m_backRight.GetPosition()},
+ frc::Pose2d{},
+ {0.1, 0.1, 0.1},
+ {0.1, 0.1, 0.1}};
};
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
index a4caff4..b9e2ba4 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
@@ -16,9 +16,9 @@
static frc::Pose2d GetEstimatedGlobalPose(
const frc::Pose2d& estimatedRobotPose) {
auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1);
- return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)),
- estimatedRobotPose.Y() + units::meter_t(randVec(1)),
+ return frc::Pose2d{estimatedRobotPose.X() + units::meter_t{randVec(0)},
+ estimatedRobotPose.Y() + units::meter_t{randVec(1)},
estimatedRobotPose.Rotation() +
- frc::Rotation2d(units::radian_t(randVec(3))));
+ frc::Rotation2d{units::radian_t{randVec(2)}}};
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h
index 7456584..049d507 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h
@@ -4,17 +4,19 @@
#pragma once
+#include <numbers>
+
#include <frc/Encoder.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/kinematics/SwerveModulePosition.h>
#include <frc/kinematics/SwerveModuleState.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/numbers>
class SwerveModule {
public:
@@ -22,6 +24,7 @@
int driveEncoderChannelA, int driveEncoderChannelB,
int turningEncoderChannelA, int turningEncoderChannelB);
frc::SwerveModuleState GetState() const;
+ frc::SwerveModulePosition GetPosition() const;
void SetDesiredState(const frc::SwerveModuleState& state);
private:
@@ -29,9 +32,9 @@
static constexpr int kEncoderResolution = 4096;
static constexpr auto kModuleMaxAngularVelocity =
- wpi::numbers::pi * 1_rad_per_s; // radians per second
+ std::numbers::pi * 1_rad_per_s; // radians per second
static constexpr auto kModuleMaxAngularAcceleration =
- wpi::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
+ std::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
frc::PWMSparkMax m_driveMotor;
frc::PWMSparkMax m_turningMotor;
diff --git a/wpilibcExamples/src/main/cpp/examples/TankDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/TankDrive/cpp/Robot.cpp
index c003762..4e48d47 100644
--- a/wpilibcExamples/src/main/cpp/examples/TankDrive/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/TankDrive/cpp/Robot.cpp
@@ -28,7 +28,7 @@
void TeleopPeriodic() override {
// Drive with tank style
- m_robotDrive.TankDrive(m_leftStick.GetY(), m_rightStick.GetY());
+ m_robotDrive.TankDrive(-m_leftStick.GetY(), -m_rightStick.GetY());
}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/Robot.cpp
new file mode 100644
index 0000000..9434b46
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/Robot.cpp
@@ -0,0 +1,32 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "Robot.h"
+
+/**
+ * This function is called periodically during operator control.
+ */
+void Robot::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();
+ }
+ }
+}
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp
new file mode 100644
index 0000000..5a878e7
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp
@@ -0,0 +1,26 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/Intake.h"
+
+void Intake::Deploy() {
+ m_piston.Set(frc::DoubleSolenoid::Value::kForward);
+}
+
+void Intake::Retract() {
+ m_piston.Set(frc::DoubleSolenoid::Value::kReverse);
+ m_motor.Set(0); // turn off the motor
+}
+
+void Intake::Activate(double speed) {
+ if (IsDeployed()) {
+ m_motor.Set(speed);
+ } else { // if piston isn't open, do nothing
+ m_motor.Set(0);
+ }
+}
+
+bool Intake::IsDeployed() const {
+ return m_piston.Get() == frc::DoubleSolenoid::Value::kForward;
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Constants.h
new file mode 100644
index 0000000..2ad9b07
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Constants.h
@@ -0,0 +1,26 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+/**
+ * The Constants header provides a convenient place for teams to hold robot-wide
+ * numerical or bool constants. This should not be used for any other purpose.
+ *
+ * It is generally a good idea to place constants into subsystem- or
+ * command-specific namespaces within this header, which can then be used where
+ * they are needed.
+ */
+
+namespace IntakeConstants {
+constexpr int kMotorPort = 1;
+
+constexpr int kPistonFwdChannel = 0;
+constexpr int kPistonRevChannel = 1;
+constexpr double kIntakeSpeed = 0.5;
+} // namespace IntakeConstants
+
+namespace OperatorConstants {
+constexpr int kJoystickIndex = 0;
+} // namespace OperatorConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Robot.h
new file mode 100644
index 0000000..492dded
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Robot.h
@@ -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.
+
+#pragma once
+
+#include <frc/Joystick.h>
+#include <frc/TimedRobot.h>
+
+#include "Constants.h"
+#include "subsystems/Intake.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void TeleopPeriodic() override;
+
+ private:
+ Intake m_intake;
+ frc::Joystick m_joystick{OperatorConstants::kJoystickIndex};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/include/subsystems/Intake.h b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/subsystems/Intake.h
new file mode 100644
index 0000000..20cf1b6
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/subsystems/Intake.h
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/DoubleSolenoid.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+
+#include "Constants.h"
+
+class Intake {
+ public:
+ void Deploy();
+ void Retract();
+ void Activate(double speed);
+ bool IsDeployed() const;
+
+ private:
+ frc::PWMSparkMax m_motor{IntakeConstants::kMotorPort};
+ frc::DoubleSolenoid m_piston{frc::PneumaticsModuleType::CTREPCM,
+ IntakeConstants::kPistonFwdChannel,
+ IntakeConstants::kPistonRevChannel};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/examples.json b/wpilibcExamples/src/main/cpp/examples/examples.json
index 9eb5b6b..aaec45d 100644
--- a/wpilibcExamples/src/main/cpp/examples/examples.json
+++ b/wpilibcExamples/src/main/cpp/examples/examples.json
@@ -1,19 +1,6 @@
[
{
- "name": "Motor Controller",
- "description": "Demonstrate controlling a single motor with a Joystick.",
- "tags": [
- "Robot and Motor",
- "Actuators",
- "Joystick",
- "Complete List"
- ],
- "foldername": "MotorControl",
- "gradlebase": "cpp",
- "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",
@@ -23,7 +10,7 @@
"Joystick",
"Complete List"
],
- "foldername": "MotorControlEncoder",
+ "foldername": "MotorControl",
"gradlebase": "cpp",
"commandversion": 2
},
@@ -85,6 +72,16 @@
"commandversion": 2
},
{
+ "name": "EventLoop",
+ "description": "Demonstrate managing a ball system using EventLoop and BooleanEvent.",
+ "tags": [
+ "EventLoop"
+ ],
+ "foldername": "EventLoop",
+ "gradlebase": "cpp",
+ "commandversion": 2
+ },
+ {
"name": "Arcade Drive",
"description": "An example program which demonstrates the use of Arcade Drive with the DifferentialDrive class",
"tags": [
@@ -347,6 +344,18 @@
"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": "cpp",
+ "commandversion": 2
+ },
+ {
"name": "Select Command Example",
"description": "An example showing how to use the SelectCommand class from the new command framework.",
"tags": [
@@ -600,7 +609,6 @@
],
"foldername": "StateSpaceFlywheel",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -619,7 +627,6 @@
],
"foldername": "StateSpaceFlywheelSysId",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -635,7 +642,6 @@
],
"foldername": "StateSpaceElevator",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -651,7 +657,6 @@
],
"foldername": "StateSpaceArm",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -668,7 +673,6 @@
],
"foldername": "ElevatorSimulation",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -684,7 +688,6 @@
],
"foldername": "DifferentialDrivePoseEstimator",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -700,7 +703,6 @@
],
"foldername": "MecanumDrivePoseEstimator",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -718,7 +720,16 @@
],
"foldername": "ArmSimulation",
"gradlebase": "cpp",
- "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
+ "name": "UnitTesting",
+ "description": "Demonstrates basic unit testing for a robot project.",
+ "tags": [
+ "Testing"
+ ],
+ "foldername": "UnitTest",
+ "gradlebase": "cpp",
"commandversion": 2
},
{
@@ -736,7 +747,6 @@
],
"foldername": "SimpleDifferentialDriveSimulation",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -754,7 +764,6 @@
],
"foldername": "StateSpaceDifferentialDriveSimulation",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
},
{
@@ -771,7 +780,6 @@
],
"foldername": "SwerveDrivePoseEstimator",
"gradlebase": "cpp",
- "mainclass": "Main",
"commandversion": 2
}
]
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp
index 426b989..c1c1ae6 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp
@@ -4,7 +4,6 @@
#include "Robot.h"
-#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>
void Robot::RobotInit() {}
@@ -37,7 +36,7 @@
void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();
- if (m_autonomousCommand != nullptr) {
+ if (m_autonomousCommand) {
m_autonomousCommand->Schedule();
}
}
@@ -49,9 +48,8 @@
// 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 != nullptr) {
+ if (m_autonomousCommand) {
m_autonomousCommand->Cancel();
- m_autonomousCommand = nullptr;
}
}
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp
index 8ba2094..4300501 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp
@@ -4,18 +4,32 @@
#include "RobotContainer.h"
-RobotContainer::RobotContainer() : m_autonomousCommand(&m_subsystem) {
+#include <frc2/command/button/Trigger.h>
+
+#include "commands/Autos.h"
+#include "commands/ExampleCommand.h"
+
+RobotContainer::RobotContainer() {
// Initialize all of your commands and subsystems here
// Configure the button bindings
- ConfigureButtonBindings();
+ ConfigureBindings();
}
-void RobotContainer::ConfigureButtonBindings() {
- // Configure your button bindings here
+void RobotContainer::ConfigureBindings() {
+ // Configure your trigger bindings here
+
+ // Schedule `ExampleCommand` when `exampleCondition` changes to `true`
+ frc2::Trigger([this] {
+ return m_subsystem.ExampleCondition();
+ }).OnTrue(ExampleCommand(&m_subsystem).ToPtr());
+
+ // Schedule `ExampleMethodCommand` when the Xbox controller's B button is
+ // pressed, cancelling on release.
+ m_driverController.B().WhileTrue(m_subsystem.ExampleMethodCommand());
}
-frc2::Command* RobotContainer::GetAutonomousCommand() {
+frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
// An example command will be run in autonomous
- return &m_autonomousCommand;
+ return autos::ExampleAuto(&m_subsystem);
}
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/Autos.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/Autos.cpp
new file mode 100644
index 0000000..3eb0958
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/Autos.cpp
@@ -0,0 +1,14 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "commands/Autos.h"
+
+#include <frc2/command/Commands.h>
+
+#include "commands/ExampleCommand.h"
+
+frc2::CommandPtr autos::ExampleAuto(ExampleSubsystem* subsystem) {
+ return frc2::cmd::Sequence(subsystem->ExampleMethodCommand(),
+ ExampleCommand(subsystem).ToPtr());
+}
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp
index e551aa1..f7ab3e2 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp
@@ -5,4 +5,7 @@
#include "commands/ExampleCommand.h"
ExampleCommand::ExampleCommand(ExampleSubsystem* subsystem)
- : m_subsystem{subsystem} {}
+ : m_subsystem{subsystem} {
+ // Register that this command requires the subsystem.
+ AddRequirements(m_subsystem);
+}
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp
index 4a31aee..1660de7 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp
@@ -8,6 +8,17 @@
// Implementation of subsystem constructor goes here.
}
+frc2::CommandPtr ExampleSubsystem::ExampleMethodCommand() {
+ // Inline construction of command goes here.
+ // Subsystem::RunOnce implicitly requires `this` subsystem.
+ return RunOnce([/* this */] { /* one-time action goes here */ });
+}
+
+bool ExampleSubsystem::ExampleCondition() {
+ // Query some boolean state, such as a digital sensor.
+ return false;
+}
+
void ExampleSubsystem::Periodic() {
// Implementation of subsystem periodic method goes here.
}
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h
index 20cc88a..963b31c 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h
@@ -13,3 +13,9 @@
* command-specific namespaces within this header, which can then be used where
* they are needed.
*/
+
+namespace OperatorConstants {
+
+constexpr int kDriverControllerPort = 0;
+
+} // namespace OperatorConstants
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h
index 25e3229..e9d45e7 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h
@@ -4,8 +4,10 @@
#pragma once
+#include <optional>
+
#include <frc/TimedRobot.h>
-#include <frc2/command/Command.h>
+#include <frc2/command/CommandPtr.h>
#include "RobotContainer.h"
@@ -24,9 +26,9 @@
void SimulationPeriodic() override;
private:
- // Have it null by default so that if testing teleop it
+ // Have it empty by default so that if testing teleop it
// doesn't have undefined behavior and potentially crash.
- frc2::Command* m_autonomousCommand = nullptr;
+ std::optional<frc2::CommandPtr> m_autonomousCommand;
RobotContainer m_container;
};
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h
index 2988968..697b9a2 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h
@@ -4,9 +4,10 @@
#pragma once
-#include <frc2/command/Command.h>
+#include <frc2/command/CommandPtr.h>
+#include <frc2/command/button/CommandXboxController.h>
-#include "commands/ExampleCommand.h"
+#include "Constants.h"
#include "subsystems/ExampleSubsystem.h"
/**
@@ -14,18 +15,21 @@
* 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.
+ * commands, and trigger mappings) should be declared here.
*/
class RobotContainer {
public:
RobotContainer();
- frc2::Command* GetAutonomousCommand();
+ frc2::CommandPtr GetAutonomousCommand();
private:
- // The robot's subsystems and commands are defined here...
- ExampleSubsystem m_subsystem;
- ExampleCommand m_autonomousCommand;
+ // Replace with CommandPS4Controller or CommandJoystick if needed
+ frc2::CommandXboxController m_driverController{
+ OperatorConstants::kDriverControllerPort};
- void ConfigureButtonBindings();
+ // The robot's subsystems are defined here...
+ ExampleSubsystem m_subsystem;
+
+ void ConfigureBindings();
};
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/commands/Autos.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/commands/Autos.h
new file mode 100644
index 0000000..62e2b56
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/commands/Autos.h
@@ -0,0 +1,16 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandPtr.h>
+
+#include "subsystems/ExampleSubsystem.h"
+
+namespace autos {
+/**
+ * Example static factory for an autonomous command.
+ */
+frc2::CommandPtr ExampleAuto(ExampleSubsystem* subsystem);
+} // namespace autos
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h
index a805151..669f2ed 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h
@@ -4,6 +4,7 @@
#pragma once
+#include <frc2/command/CommandPtr.h>
#include <frc2/command/SubsystemBase.h>
class ExampleSubsystem : public frc2::SubsystemBase {
@@ -11,6 +12,19 @@
ExampleSubsystem();
/**
+ * Example command factory method.
+ */
+ frc2::CommandPtr ExampleMethodCommand();
+
+ /**
+ * 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.
+ */
+ bool ExampleCondition();
+
+ /**
* Will be called periodically whenever the CommandScheduler runs.
*/
void Periodic() override;
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/Robot.cpp
new file mode 100644
index 0000000..32782b2
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/Robot.cpp
@@ -0,0 +1,55 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "Robot.h"
+
+#include <frc2/command/CommandScheduler.h>
+
+void Robot::RobotInit() {}
+
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
+
+void Robot::DisabledInit() {}
+
+void Robot::DisabledPeriodic() {}
+
+void Robot::DisabledExit() {}
+
+void Robot::AutonomousInit() {
+ m_autonomousCommand = m_container.GetAutonomousCommand();
+
+ if (m_autonomousCommand) {
+ m_autonomousCommand->Schedule();
+ }
+}
+
+void Robot::AutonomousPeriodic() {}
+
+void Robot::AutonomousExit() {}
+
+void Robot::TeleopInit() {
+ if (m_autonomousCommand) {
+ m_autonomousCommand->Cancel();
+ }
+}
+
+void Robot::TeleopPeriodic() {}
+
+void Robot::TeleopExit() {}
+
+void Robot::TestInit() {
+ frc2::CommandScheduler::GetInstance().CancelAll();
+}
+
+void Robot::TestPeriodic() {}
+
+void Robot::TestExit() {}
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/RobotContainer.cpp
new file mode 100644
index 0000000..e63532a
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/RobotContainer.cpp
@@ -0,0 +1,17 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "RobotContainer.h"
+
+#include <frc2/command/Commands.h>
+
+RobotContainer::RobotContainer() {
+ ConfigureBindings();
+}
+
+void RobotContainer::ConfigureBindings() {}
+
+frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
+ return frc2::cmd::Print("No autonomous command configured");
+}
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/Robot.h
new file mode 100644
index 0000000..6bdb217
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/Robot.h
@@ -0,0 +1,35 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <optional>
+
+#include <frc/TimedRobot.h>
+#include <frc2/command/CommandPtr.h>
+
+#include "RobotContainer.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void RobotInit() override;
+ void RobotPeriodic() override;
+ void DisabledInit() override;
+ void DisabledPeriodic() override;
+ void DisabledExit() override;
+ void AutonomousInit() override;
+ void AutonomousPeriodic() override;
+ void AutonomousExit() override;
+ void TeleopInit() override;
+ void TeleopPeriodic() override;
+ void TeleopExit() override;
+ void TestInit() override;
+ void TestPeriodic() override;
+ void TestExit() override;
+
+ private:
+ std::optional<frc2::CommandPtr> m_autonomousCommand;
+
+ RobotContainer m_container;
+};
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/RobotContainer.h
new file mode 100644
index 0000000..a66653c
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/RobotContainer.h
@@ -0,0 +1,17 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandPtr.h>
+
+class RobotContainer {
+ public:
+ RobotContainer();
+
+ frc2::CommandPtr GetAutonomousCommand();
+
+ private:
+ void ConfigureBindings();
+};
diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp
index 29bae0b..0c67d6d 100644
--- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp
@@ -5,6 +5,7 @@
#include "Robot.h"
#include <frc/DriverStation.h>
+#include <frc/internal/DriverStationModeThread.h>
#include <frc/livewindow/LiveWindow.h>
#include <frc/shuffleboard/Shuffleboard.h>
#include <hal/DriverStation.h>
@@ -23,41 +24,46 @@
void Robot::StartCompetition() {
RobotInit();
+ frc::internal::DriverStationModeThread modeThread;
+
+ wpi::Event event{false, false};
+ frc::DriverStation::ProvideRefreshedDataEventHandle(event.GetHandle());
+
// Tell the DS that the robot is ready to be enabled
HAL_ObserveUserProgramStarting();
while (!m_exit) {
if (IsDisabled()) {
- frc::DriverStation::InDisabled(true);
+ modeThread.InDisabled(true);
Disabled();
- frc::DriverStation::InDisabled(false);
+ modeThread.InDisabled(false);
while (IsDisabled()) {
- frc::DriverStation::WaitForData();
+ wpi::WaitForObject(event.GetHandle());
}
} else if (IsAutonomous()) {
- frc::DriverStation::InAutonomous(true);
+ modeThread.InAutonomous(true);
Autonomous();
- frc::DriverStation::InAutonomous(false);
+ modeThread.InAutonomous(false);
while (IsAutonomousEnabled()) {
- frc::DriverStation::WaitForData();
+ wpi::WaitForObject(event.GetHandle());
}
} else if (IsTest()) {
frc::LiveWindow::SetEnabled(true);
frc::Shuffleboard::EnableActuatorWidgets();
- frc::DriverStation::InTest(true);
+ modeThread.InTest(true);
Test();
- frc::DriverStation::InTest(false);
+ modeThread.InTest(false);
while (IsTest() && IsEnabled()) {
- frc::DriverStation::WaitForData();
+ wpi::WaitForObject(event.GetHandle());
}
frc::LiveWindow::SetEnabled(false);
frc::Shuffleboard::DisableActuatorWidgets();
} else {
- frc::DriverStation::InTeleop(true);
+ modeThread.InTeleop(true);
Teleop();
- frc::DriverStation::InTeleop(false);
+ modeThread.InTeleop(false);
while (IsTeleopEnabled()) {
- frc::DriverStation::WaitForData();
+ wpi::WaitForObject(event.GetHandle());
}
}
}
diff --git a/wpilibcExamples/src/main/cpp/templates/templates.json b/wpilibcExamples/src/main/cpp/templates/templates.json
index 83260a0..67e4438 100644
--- a/wpilibcExamples/src/main/cpp/templates/templates.json
+++ b/wpilibcExamples/src/main/cpp/templates/templates.json
@@ -10,6 +10,16 @@
"commandversion": 2
},
{
+ "name": "Command Robot Skeleton (Advanced)",
+ "description": "Skeleton (stub) code for Command Robot",
+ "tags": [
+ "Command", "Skeleton"
+ ],
+ "foldername": "commandbasedskeleton",
+ "gradlebase": "cpp",
+ "commandversion": 2
+ },
+ {
"name": "Timed Robot",
"description": "Timed style",
"tags": [
diff --git a/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/RainbowTest.cpp b/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/RainbowTest.cpp
new file mode 100644
index 0000000..553a2bb
--- /dev/null
+++ b/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/RainbowTest.cpp
@@ -0,0 +1,53 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <fmt/format.h>
+#include <gtest/gtest.h>
+
+#include <array>
+
+#include <frc/AddressableLED.h>
+#include <frc/simulation/AddressableLEDSim.h>
+#include <frc/util/Color.h>
+#include <frc/util/Color8Bit.h>
+#include <hal/AddressableLEDTypes.h>
+
+#include "Robot.h"
+
+void AssertIndexColor(std::array<frc::AddressableLED::LEDData, 60> data,
+ int index, int hue, int saturation, int value);
+
+TEST(RainbowTest, RainbowPattern) {
+ Robot robot;
+ robot.RobotInit();
+ frc::sim::AddressableLEDSim ledSim =
+ frc::sim::AddressableLEDSim::CreateForChannel(9);
+ EXPECT_TRUE(ledSim.GetRunning());
+ EXPECT_EQ(60, ledSim.GetLength());
+
+ auto rainbowFirstPixelHue = 0;
+ std::array<frc::AddressableLED::LEDData, 60> data;
+ for (int iteration = 0; iteration < 100; iteration++) {
+ SCOPED_TRACE(fmt::format("Iteration {} of 100", iteration));
+ robot.RobotPeriodic();
+ ledSim.GetData(data.data());
+ for (int i = 0; i < 60; i++) {
+ SCOPED_TRACE(fmt::format("LED {} of 60", i));
+ auto hue = (rainbowFirstPixelHue + (i * 180 / 60)) % 180;
+ AssertIndexColor(data, i, hue, 255, 128);
+ }
+ rainbowFirstPixelHue += 3;
+ rainbowFirstPixelHue %= 180;
+ }
+}
+
+void AssertIndexColor(std::array<frc::AddressableLED::LEDData, 60> data,
+ int index, int hue, int saturation, int value) {
+ frc::Color8Bit color{frc::Color::FromHSV(hue, saturation, value)};
+
+ EXPECT_EQ(0, data[index].padding);
+ EXPECT_EQ(color.red, data[index].r & 0xFF);
+ EXPECT_EQ(color.green, data[index].g & 0xFF);
+ EXPECT_EQ(color.blue, data[index].b & 0xFF);
+}
diff --git a/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/main.cpp b/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/main.cpp
new file mode 100644
index 0000000..285c1d5
--- /dev/null
+++ b/wpilibcExamples/src/test/cpp/examples/AddressableLED/cpp/main.cpp
@@ -0,0 +1,17 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <hal/HALBase.h>
+
+#include "gtest/gtest.h"
+
+/**
+ * Runs all unit tests.
+ */
+int main(int argc, char** argv) {
+ HAL_Initialize(500, 0);
+ ::testing::InitGoogleTest(&argc, argv);
+ int ret = RUN_ALL_TESTS();
+ return ret;
+}
diff --git a/wpilibcExamples/src/test/cpp/examples/UnitTest/cpp/main.cpp b/wpilibcExamples/src/test/cpp/examples/UnitTest/cpp/main.cpp
new file mode 100644
index 0000000..285c1d5
--- /dev/null
+++ b/wpilibcExamples/src/test/cpp/examples/UnitTest/cpp/main.cpp
@@ -0,0 +1,17 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <hal/HALBase.h>
+
+#include "gtest/gtest.h"
+
+/**
+ * Runs all unit tests.
+ */
+int main(int argc, char** argv) {
+ HAL_Initialize(500, 0);
+ ::testing::InitGoogleTest(&argc, argv);
+ int ret = RUN_ALL_TESTS();
+ return ret;
+}
diff --git a/wpilibcExamples/src/test/cpp/examples/UnitTest/cpp/subsystems/IntakeTest.cpp b/wpilibcExamples/src/test/cpp/examples/UnitTest/cpp/subsystems/IntakeTest.cpp
new file mode 100644
index 0000000..ae1d786
--- /dev/null
+++ b/wpilibcExamples/src/test/cpp/examples/UnitTest/cpp/subsystems/IntakeTest.cpp
@@ -0,0 +1,46 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <gtest/gtest.h>
+
+#include <frc/DoubleSolenoid.h>
+#include <frc/simulation/DoubleSolenoidSim.h>
+#include <frc/simulation/PWMSim.h>
+
+#include "Constants.h"
+#include "subsystems/Intake.h"
+
+class IntakeTest : public testing::Test {
+ protected:
+ Intake intake; // create our intake
+ frc::sim::PWMSim simMotor{
+ IntakeConstants::kMotorPort}; // create our simulation PWM
+ frc::sim::DoubleSolenoidSim simPiston{
+ frc::PneumaticsModuleType::CTREPCM, IntakeConstants::kPistonFwdChannel,
+ IntakeConstants::kPistonRevChannel}; // create our simulation solenoid
+};
+
+TEST_F(IntakeTest, DoesntWorkWhenClosed) {
+ intake.Retract(); // close the intake
+ intake.Activate(0.5); // try to activate the motor
+ EXPECT_DOUBLE_EQ(
+ 0.0,
+ simMotor.GetSpeed()); // make sure that the value set to the motor is 0
+}
+
+TEST_F(IntakeTest, WorksWhenOpen) {
+ intake.Deploy();
+ intake.Activate(0.5);
+ EXPECT_DOUBLE_EQ(0.5, simMotor.GetSpeed());
+}
+
+TEST_F(IntakeTest, Retract) {
+ intake.Retract();
+ EXPECT_EQ(frc::DoubleSolenoid::Value::kReverse, simPiston.Get());
+}
+
+TEST_F(IntakeTest, Deploy) {
+ intake.Deploy();
+ EXPECT_EQ(frc::DoubleSolenoid::Value::kForward, simPiston.Get());
+}