Squashed 'third_party/allwpilib/' changes from 66b57f032..e473a00f9
e473a00f9 [wpiutil] Base64: Add unsigned span/vector variants (#3702)
52f2d580e [wpiutil] raw_uv_ostream: Add reset() (#3701)
d7b1e3576 [wpiutil] WebSocket: move std::function (#3700)
93799fbe9 [examples] Fix description of TrapezoidProfileSubsystem (#3699)
b84644740 [wpimath] Document pose estimator states, inputs, and outputs (#3698)
2dc35c139 [wpimath] Fix classpaths for JNI class loads (#3697)
2cb171f6f [docs] Set Doxygen extract_all to true and fix Doxygen failures (#3695)
a939cd9c8 [wpimath] Print uncontrollable/unobservable models in LQR and KF (#3694)
d5270d113 [wpimath] Clean up C++ StateSpaceUtil tests (#3692)
b20903960 [wpimath] Remove redundant discretization tests from StateSpaceUtilTest (#3689)
c0cb545b4 [wpilibc] Add deprecated Doxygen attribute to SpeedController (#3691)
35c9f66a7 [wpilib] Rename PneumaticsHub to PneumaticHub (#3686)
796d03d10 [wpiutil] Remove unused LLVM header (#3688)
8723caf78 [wpilibj] Make Java TrapezoidProfile.Constraints an immutable class (#3687)
187f50a34 [wpimath] Catch incorrect parameters to state-space models earlier (#3680)
8d04606c4 Replace instances of frc-characterization with SysId (NFC) (#3681)
b82d4f6e5 [hal, cscore, ntcore] Use WPI common handle type base
87e34967e [wpiutil] Add synchronization primitives
e32499c54 [wpiutil] Add ParallelTcpConnector (#3655)
aa0b49228 [wpilib] Remove redundant "quick turn" docs for curvature drive (NFC) (#3674)
57301a7f9 [hal] REVPH: Start closed-loop compressor control on init (#3673)
d1842ea8f [wpilib] Improve interrupt docs (NFC) (#3679)
558151061 [wpiutil] Add DsClient (#3654)
181723e57 Replace `.to<double>()` and `.template to<double>()` with `.value()` (#3667)
6bc1db44b [commands] Add pointer overload of AddRequirements (artf6003) (#3669)
737b57ed5 [wpimath] Update to drake v0.35.0 (#3665)
4d287d1ae [build] Upgrade WPIJREArtifact to JRE 2022-11.0.12u5 (#3666)
f26eb5ada [hal] Fix another typo (get -> gets) (NFC) (#3663)
94ed275ba [hal] Fix misspelling (numer -> number) (NFC) (#3662)
ac2f44da3 [wpiutil] uv: use move for std::function (#3653)
75fa1fbfb [wpiutil] json::serializer: Optimize construction (#3647)
5e689faea [wpiutil] Import MessagePack implementation (mpack) (#3650)
649a50b40 [wpiutil] Add LEB128 byte-by-byte reader (#3652)
e94397a97 [wpiutil] Move json_serializer.h to public headers (#3646)
4ec58724d [wpiutil] uv::Tcp: Clarify SetNoDelay documentation (#3649)
8cb294aa4 [wpiutil] WebSocket: Make Shutdown() public (#3651)
2b3a9a52b [wpiutil] json: Fix map iterator key() for std::string_view (#3645)
138cbb94b [wpiutil] uv::Async: Add direct call for no-parameter specialization (#3648)
e56d6dea8 [ci] Update testbench pool image to ubuntu-latest (#3643)
43f30e44e [build] Enable comments in doxygen source files (#3644)
9e6db17ef [build] Enable doxygen preprocessor expansion of WPI_DEPRECATED (#3642)
0e631ad2f Add WPILib version to issue template (#3641)
6229d8d2f [build] Docs: set case_sense_names to false (#3392)
4647d09b5 [docs] Fix Doxygen warnings, add CI docs lint job (#3639)
4ad3a5402 [hal] Fix PWM allocation channel (#3637)
05e5feac4 [docs] Fix brownout docs (NFC) (#3638)
67df469c5 [examples] Remove old command-based templates and examples (#3263)
689e9ccfb [hal, wpilib] Add brownout voltage configuration (#3632)
9cd4bc407 [docs] Add useLocal to avoid using installer artifacts (#3634)
61996c2bb [cscore] Fix Java direct callback notifications (#3631)
6d3dd99eb [build] Update to newest native-utils (#3633)
f0b484892 [wpiutil] Fix StringMap iterator equality check (#3629)
8352cbb7a Update development build instructions for 2022 (#3616)
6da08b71d [examples] Fix Intermediate Vision Java Example description (#3628)
5d99059bf [wpiutil] Remove optional.h (#3627)
fa41b106a [glass, wpiutil] Add missing format args (#3626)
4e3fd7d42 [build] Enable Zc:__cplusplus for Windows (#3625)
791d8354d [build] Suppress deprecation/removal warnings for old commands (#3618)
10f19e6fc [hal, wpilib] Add REV PneumaticsHub (#3600)
4c61a1305 [ntcore] Revert to per-element copy for toNative() (#3621)
7b3f62244 [wpiutil] SendableRegistry: Print exception stacktrace (#3620)
d347928e4 [hal] Use better error for when console out is enabled while attempting to use onboard serial port (#3622)
cc31079a1 [hal] Use setcap instead of setuid for setting thread priorities (#3613)
4676648b7 [wpimath] Upgrade to Drake v0.34.0 (#3607)
c7594c911 [build] Allow building wpilibc in cmake without cscore and opencv (#3605)
173cb7359 [wpilib] Add TimesliceRobot (#3502)
af295879f [hal] Set error status for I2C port out of range (#3603)
95dd20a15 [build] Enable spotbugs (#3601)
b65fce86b [wpilib] Remove Timer lock in wpilibj and update docs (#3602)
3b8d3bbcb Remove unused and add missing deprecated.h includes (#3599)
f9e976467 [examples] Rename DriveTrain classes to Drivetrain (#3594)
118a27be2 [wpilib] Add Timer tests (#3595)
59c89428e [wpilib] Deprecate Timer::HasPeriodPassed() (#3598)
202ca5e78 Force C++17 in .clang-format (#3597)
d6f185d8e Rename tests for consistency (#3592)
54ca474db [ci] Enable asan and tsan in CI for tests that pass (#3591)
1ca383b23 Add Debouncer (#3590)
179fde3a7 [build] Update to 2022 native utils and gradle 7 (#3588)
50198ffcf [examples] Add Mechanism2d visualization to Elevator Sim (#3587)
a446c2559 [examples] Synchronize C++ and Java Mechanism2d examples (#3589)
a7fb83103 [ci] clang-tidy: Generate compilation commands DB with Gradle (#3585)
4f5e0c9f8 [examples] Update ArmSimulation example to use Mechanism2d (#3572)
8164b91dc [CI] Print CMake test output on failure (#3583)
4d5fca27e [wpilib] Impove Mechanism2D documentation (NFC) (#3584)
fe59e4b9f Make C++ test names more consistent (#3586)
5c8868549 [wpilibc] Fix C++ MechanisimRoot2D to use same NT entries as Java/Glass (#3582)
9359431ba [wpimath] Clean up Eigen usage
72716f51c [wpimath] Upgrade to Eigen 3.4
382deef75 [wpimath] Explicitly export wpimath symbols
161e21173 [ntcore] Match standard handle layout, only allow 16 instances (#3577)
263a24811 [wpimath] Use jinja for codegen (#3574)
725251d29 [wpilib] Increase tolerances of DifferentialDriveSimTest (#3581)
4dff87301 [wpimath] Make LinearFilter::Factorial() constexpr (#3579)
60ede67ab [hal, wpilib] Switch PCM to be a single object that is allowed to be duplicated (#3475)
906bfc846 [build] Add CMake build support for sanitizers (#3576)
0d4f08ad9 [hal] Simplify string copy of joystick name (#3575)
a52bf87b7 [wpiutil] Add Java function package (#3570)
40c7645d6 [wpiutil] UidVector: Return old object from erase() (#3571)
5b886a23f [wpiutil] jni_util: Add size, operator[] to JArrayRef (#3569)
65797caa7 [sim] Fix halsim_ds_socket stringop overflow warning from GCC 10 (#3568)
66abb3988 [hal] Update runtime enum to allow selecting roborio 2 (#3565)
95a12e0ee [hal] UidSetter: Don't revert euid if its already current value (#3566)
27951442b [wpimath] Use external Eigen headers only (#3564)
c42e053ae [docs] Update to doxygen 1.9.2 (#3562)
e7048c8c8 [docs] Disable doxygen linking for common words that are also classes (#3563)
d8e0b6c97 [wpilibj] Fix java async interrupts (#3559)
5e6c34c61 Update to 2022 roborio image (#3537)
828f073eb [wpiutil] Fix uv::Buffer memory leaks caught by asan (#3555)
2dd5701ac [cscore] Fix mutex use-after-free in cscore test (#3557)
531439198 [ntcore] Fix NetworkTables memory leaks caught by asan (#3556)
3d9a4d585 [wpilibc] Fix AnalogTriggerOutput memory leak reported by asan (#3554)
54eda5928 [wpiutil] Ignore ubsan vptr upcast warning in SendableHelper moves (#3553)
5a4f75c9f [wpilib] Replace Speed controller comments with motor controller (NFC) (#3551)
7810f665f [wpiutil] Fix bug in uleb128 (#3540)
697e2dd33 [wpilib] Fix errant jaguar reference in comments (NFC) (#3550)
936c64ff5 [docs] Enable -linksource for javadocs (#3549)
1ea654954 [build] Upgrade CMake build to googletest 1.11.0 (#3548)
32d9949e4 [wpimath] Move controller tests to wpimath (#3541)
01ba56a8a [hal] Replace strncpy with memcpy (#3539)
e109c4251 [build] Rename makeSim flag to forceGazebo to better describe what it does (#3535)
e4c709164 [docs] Use a doxygen theme and add logo (#3533)
960b6e589 [wpimath] Fix Javadoc warning (#3532)
82eef8d5e [hal] Remove over current fault HAL functions from REV PDH (#3526)
aa3848b2c [wpimath] Move RobotDriveBase::ApplyDeadband() to MathUtil (#3529)
3b5d0d141 [wpimath] Add LinearFilter::BackwardFiniteDifference() (#3528)
c8fc715fe [wpimath] Upgrade drake files to v0.33.0 (#3531)
e5fe3a8e1 [build] Treat javadoc warnings as errors in CI and fix warnings (#3530)
e0c6cd3dc [wpimath] Add an operator for composing two Transform2ds (#3527)
2edd510ab [sim] Add sim wrappers for sensors that use SimDevice (#3517)
2b3e2ebc1 [hal] Fix HAL Notifier thread priority setting (#3522)
ab4cb5932 [gitignore] Update gitignore to ignore bazel / clion files (#3524)
57c8615af [build] Generate spotless patch on failure (#3523)
b90317321 Replace std::cout and std::cerr with fmt::print() (#3519)
10cc8b89c [hal] [wpilib] Add initial support for the REV PDH (#3503)
5d9ae3cdb [hal] Set HAL Notifier thread as RT by default (#3482)
192d251ee [wpilibcIntegrationTests] Properly disable DMA integration tests (#3514)
031962608 [wpilib] Add PS4Controller, remove Hand from GenericHID/XboxController (#3345)
25f6f478a [wpilib] Rename DriverStation::IsOperatorControl() to IsTeleop() (#3505)
e80f09f84 [wpilibj] Add unit tests (#3501)
c159f91f0 [wpilib] Only read DS control word once in IterativeRobotBase (#3504)
eb790a74d Add rio development docs documenting myRobot deploy tasks (#3508)
e47451f5a [wpimath] Replace auto with Eigen types (#3511)
252b8c83b Remove Java formatting from build task in CI (#3507)
09666ff29 Shorten Gazebo CI build (#3506)
baf2e501d Update myRobot to use 2021 java (#3509)
5ac60f0a2 [wpilib] Remove IterativeRobotBase mode init prints (#3500)
fb2ee8ec3 [wpilib] Add TimedRobot functions for running code on mode exit (#3499)
94e0db796 [wpilibc] Add more unit tests (#3494)
b25324695 [wpilibj] Add units to parameter names (NFC) (#3497)
1ac73a247 [hal] Rename PowerDistributionPanel to PowerDistribution (#3466)
2014115bc [examples] frisbeebot: Fix typo and reflow comments (NFC) (#3498)
4a944dc39 [examples] Consistently use 0 for controller port (#3496)
3838cc4ec Use unicode characters in docs equations (#3487)
85748f2e6 [examples] Add C++ TankDrive example (#3493)
d7b8aa56d [wpilibj] Rename DriverStation In[Mode] functions to follow style guide (#3488)
16e096cf8 [build] Fix CMake Windows CI (#3490)
50af74c38 [wpimath] Clean up NumericalIntegration and add Discretization tests (#3489)
bfc209b12 Automate fmt update (#3486)
e7f9331e4 [build] Update to Doxygen 1.9.1 (#3008)
ab8e8aa2a [wpimath] Update drake with upstream (#3484)
1ef826d1d [wpimath] Fix IOException path in WPIMath JNI (#3485)
52bddaa97 [wpimath] Disable iostream support for units and enable fmtlib (#3481)
e4dc3908b [wpiutil] Upgrade to fmtlib 8.0.1 (#3483)
1daadb812 [wpimath] Implement Dormand-Prince integration method (#3476)
9c2723391 [cscore] Add [[nodiscard]] to GrabFrame functions (#3479)
7a8796414 [wpilib] Add Notifier integration tests (#3480)
f8f13c536 [wpilibcExamples] Prefix decimal numbers with 0 (#3478)
1adb69c0f [ntcore] Use "NetworkTables" instead of "Network Tables" in NT specs (#3477)
5f5830b96 Upload wpiformat diff if one exists (#3474)
9fb4f35bb [wpimath] Add tests for DARE overload with Q, R, and N matrices (#3472)
c002e6f92 Run wpiformat (#3473)
c154e5262 [wpilib] Make solenoids exclusive use, PCM act like old sendable compressor (#3464)
6ddef1cca [hal] JNI setDIO: use a boolean and not a short (#3469)
9d68d9582 Remove extra newlines after open curly braces (NFC) (#3471)
a4233e1a1 [wpimath] Add script for updating Drake (#3470)
39373c6d2 Update README.md for new GCC version requirement (#3467)
d29acc90a [wpigui] Add option to reset UI on exit (#3463)
a371235b0 [ntcore] Fix dangling pointer in logger (#3465)
53b4891a5 [wpilibcintegrationtests] Fix deprecated Preferences usage (#3461)
646ded912 [wpimath] Remove incorrect discretization in pose estimators (#3460)
ea0b8f48e Fix some deprecation warnings due to fmtlib upgrade (#3459)
2067d7e30 [wpilibjexamples] Add wpimathjni, wpiutiljni to library path (#3455)
866571ab4 [wpiutil] Upgrade to fmtlib 8.0.0 (#3457)
4e1fa0308 [build] Skip PDB copy on windows build servers (#3458)
b45572167 [build] Change CI back to 18.04 docker images (#3456)
57a160f1b [wpilibc] Fix LiveWindow deprecation warning in RobotBase skeleton template (#3454)
29ae8640d [HLT] Implement duty cycle cross connect tests (#3453)
ee6377e54 [HLT] Add relay and analog cross connects (#3452)
b0f1ae7ea [build] CMake: Build the HAL even if WITH_CSCORE=OFF (#3449)
7aae2b72d Replace std::to_string() with fmt::format() (#3451)
73fcbbd74 [HLT] Add relay digital cross connect tests (#3450)
e7bedde83 [HLT] Add PWM tests that use DMA as the back end (#3447)
7253edb1e [wpilibc] Timer: Fix deprecated warning (#3446)
efa28125c [wpilibc] Add message to RobotBase on how to read stacktrace (#3444)
9832fcfe1 [hal] Fix DIO direction getter (#3445)
49c71f9f2 [wpilibj] Clarify robot quit message (#3364)
791770cf6 [wpimath] Move controller from wpilibj to wpimath (#3439)
9ce9188ff [wpimath] Add ReportWarning to MathShared (#3441)
362066a9b [wpilib] Deprecate getInstance() in favor of static functions (#3440)
26ff9371d Initial commit of cross connect integration test project (#3434)
4a36f86c8 [hal] Add support for DMA to Java (#3158)
85144e47f [commands] Unbreak build (#3438)
b417d961e Split Sendable into NT and non-NT portions (#3432)
ef4ea84cb [commands] Change grouping decorator impl to flatten nested group structures (#3335)
b422665a3 [examples] Invert right side of drive subsystems (#3437)
186dadf14 [hal] Error if attempting to set DIO output on an input port (#3436)
04e64db94 Remove redundant C++ lambda parentheses (NFC) (#3433)
f60994ad2 [wpiutil] Rename Java package to edu.wpi.first.util (#3431)
cfa1ca96f [wpilibc] Make ShuffleboardValue non-copyable (#3430)
4d9ff7643 Fix documentation warnings generated by JavaDoc (NFC) (#3428)
9e1b7e046 [build] Fix clang-tidy and clang-format (#3429)
a77c6ff3a [build] Upgrade clang-format and clang-tidy (NFC) (#3422)
099fde97d [wpilib] Improve PDP comments (NFC) (#3427)
f8fc2463e [wpilibc, wpiutil] Clean up includes (NFC) (#3426)
e246b7884 [wpimath] Clean up member initialization in feedforward classes (#3425)
c1e128bd5 Disable frivolous PMD warnings and enable PMD in ntcore (#3419)
8284075ee Run "Lint and Format" CI job on push as well as pull request (#3412)
f7db09a12 [wpimath] Move C++ filters into filter folder to match Java (#3417)
f9c3d54bd [wpimath] Reset error covariance in pose estimator ResetPosition() (#3418)
0773f4033 [hal] Ensure HAL status variables are initialized to zero (#3421)
d068fb321 [build] Upgrade CI to use 20.04 docker images (#3420)
8d054c940 [wpiutil] Remove STLExtras.h
80f1d7921 [wpiutil] Split function_ref to a separate header
64f541325 Use wpi::span instead of wpi::ArrayRef across all libraries (#3414)
2abbbd9e7 [build] clang-tidy: Remove bugprone-exception-escape (#3415)
a5c471af7 [wpimath] Add LQR template specialization for 2x2 system
edd2f0232 [wpimath] Add DARE solver for Q, R, and N with LQR ctor overloads
b2c3b2dd8 Use std::string_view and fmtlib across all libraries (#3402)
4f1cecb8e [wpiutil] Remove Path.h (#3413)
b336eac34 [build] Publish halsim_ws_core to Maven
2a09f6fa4 [build] Also build sim modules as static libraries
0e702eb79 [hal] Add a unified PCM object (#3331)
dea841103 [wpimath] Add fmtlib formatter overloads for Eigen::Matrix and units (#3409)
82856cf81 [wpiutil] Improve wpi::circular_buffer iterators (#3410)
8aecda03e [wpilib] Fix a documentation typo (#3408)
5c817082a [wpilib] Remove InterruptableSensorBase and replace with interrupt classes (#2410)
15c521a7f [wpimath] Fix drivetrain system identification (#3406)
989de4a1b [build] Force all linker warnings to be fatal for rio builds (#3407)
d9eeb45b0 [wpilibc] Add units to Ultrasonic class API (#3403)
fe570e000 [wpiutil] Replace llvm filesystem with C++17 filesystem (#3401)
01dc0249d [wpimath] Move SlewRateLimiter from wpilib to wpimath (#3399)
93523d572 [wpilibc] Clean up integration tests (#3400)
4f7a4464d [wpiutil] Rewrite StringExtras for std::string_view (#3394)
e09293a15 [wpilibc] Transition C++ classes to units::second_t (#3396)
827b17a52 [build] Create run tasks for Glass and OutlineViewer (#3397)
a61037996 [wpiutil] Avoid MSVC warning on span include (#3393)
4e2c3051b [wpilibc] Use std::string_view instead of Twine (#3380)
50915cb7e [wpilibc] MotorSafety::GetDescription(): Return std::string (#3390)
f4e2d26d5 [wpilibc] Move NullDeleter from frc/Base.h to wpi/NullDeleter.h (#3387)
cb0051ae6 [wpilibc] SimDeviceSim: use fmtlib (#3389)
a238cec12 [wpiutil] Deprecate wpi::math constants in favor of wpi::numbers (#3383)
393bf23c0 [ntcore, cscore, wpiutil] Standardize template impl files on .inc extension (NFC) (#3124)
e7d9ba135 [sim] Disable flaky web server integration tests (#3388)
0a0003c11 [wpilibjExamples] Fix name of Java swerve drive pose estimator example (#3382)
7e1b27554 [wpilibc] Use default copies and moves when possible (#3381)
fb2a56e2d [wpilibc] Remove START_ROBOT_CLASS macro (#3384)
84218bfb4 [wpilibc] Remove frc namespace shim (#3385)
dd7824340 [wpilibc] Remove C++ compiler version static asserts (#3386)
484cf9c0e [wpimath] Suppress the -Wmaybe-uninitialized warning in Eigen (#3378)
a04d1b4f9 [wpilibc] DriverStation: Remove ReportError and ReportWarning
831c10bdf [wpilibc] Errors: Use fmtlib
87603e400 [wpiutil] Import fmtlib (#3375)
442621672 [wpiutil] Add ArrayRef/std::span/wpi::span implicit conversions
bc15b953b [wpiutil] Add std::span implementation
6d20b1204 [wpiutil] StringRef, Twine, raw_ostream: Add std::string_view support (#3373)
2385c2a43 [wpilibc] Remove Utility.h (#3376)
87384ea68 [wpilib] Fix PIDController continuous range error calculations (#3170)
04dae799a [wpimath] Add SimpleMotorFeedforward::Calculate(velocity, nextVelocity) overload (#3183)
0768c3903 [wpilib] DifferentialDrive: Remove right side inversion (#3340)
8dd8d4d2d [wpimath] Fix redundant nested math package introduced by #3316 (#3368)
49b06beed [examples] Add Field2d to RamseteController example (#3371)
4c562a445 [wpimath] Fix typo in comment of update_eigen.py (#3369)
fdbbf1188 [wpimath] Add script for updating Eigen
f1e64b349 [wpimath] Move Eigen unsupported folder into eigeninclude
224f3a05c [sim] Fix build error when building with GCC 11.1 (#3361)
ff56d6861 [wpilibj] Fix SpeedController deprecated warnings (#3360)
1873fbefb [examples] Fix Swerve and Mecanum examples (#3359)
80b479e50 [examples] Fix SwerveBot example to use unique encoder ports (#3358)
1f7c9adee [wpilibjExamples] Fix pose estimator examples (#3356)
9ebc3b058 [outlineviewer] Change default size to 600x400 (#3353)
e21b443a4 [build] Gradle: Make C++ examples runnable (#3348)
da590120c [wpilibj] Add MotorController.setVoltage default (#3347)
561d53885 [build] Update opencv to 4.5.2, imgui/implot to latest (#3344)
44ad67ca8 [wpilibj] Preferences: Add missing Deprecated annotation (#3343)
3fe8fc75a [wpilibc] Revert "Return reference from GetInstance" (#3342)
3cc2da332 Merge branch '2022'
a3cd90dd7 [wpimath] Fix classpath used by generate_numbers.py (#3339)
d6cfdd3ba [wpilib] Preferences: Deprecate Put* in favor of Set* (#3337)
ba08baabb [wpimath] Update Drake DARE solver to v0.29.0 (#3336)
497b712f6 [wpilib] Make IterativeRobotBase::m_period private with getter
f00dfed7a [wpilib] Remove IterativeRobot base class
3c0846168 [hal] Use last error reporting instead of PARAMETER_OUT_OF_RANGE (#3328)
5ef2b4fdc [wpilibj] Fix @deprecated warning for SerialPort constructor (#3329)
23d2326d1 [hal] Report previous allocation location for indexed resource duplicates (#3322)
e338f9f19 [build] Fix wpilibc runCpp task (#3327)
c8ff626fe [wpimath] Move Java classes to edu.wpi.first.math (#3316)
4e424d51f [wpilibj] DifferentialDrivetrainSim: Rename constants to match the style guide (#3312)
6b50323b0 [cscore] Use Lock2DSize if possible for Windows USB cameras (#3326)
65c148536 [wpilibc] Fix "control reaches end of non-void function" warning (#3324)
f99f62bee [wpiutil] uv Handle: Use malloc/free instead of new/delete (#3325)
365f5449c [wpimath] Fix MecanumDriveKinematics (#3266)
ff52f207c [glass, wpilib] Rewrite Mechanism2d (#3281)
ee0eed143 [wpimath] Add DCMotor factory function for Romi motors (#3319)
512738072 [hal] Add HAL_GetLastError to enable better error messages from HAL calls (#3320)
ced654880 [glass, outlineviewer] Update Mac icons to macOS 11 style (#3313)
936d3b9f8 [templates] Add Java template for educational robot (#3309)
6e31230ad [examples] Fix odometry update in SwerveControllerCommand example (#3310)
05ebe9318 Merge branch 'main' into 2022
aaf24e255 [wpilib] Fix initial heading behavior in HolonomicDriveController (#3290)
8d961dfd2 [wpilibc] Remove ErrorBase (#3306)
659b37ef9 [wpiutil] StackTrace: Include offset on Linux (#3305)
0abf6c904 [wpilib] Move motor controllers to motorcontrol package (#3302)
4630191fa [wpiutil] circular_buffer: Use value initialization instead of passing zero (#3303)
b7b178f49 [wpilib] Remove Potentiometer interface
687066af3 [wpilib] Remove GyroBase
6b168ab0c [wpilib] Remove PIDController, PIDOutput, PIDSource
948625de9 [wpimath] Document conversion from filter cutoff frequency to time constant (#3299)
3848eb8b1 [wpilibc] Fix flywhel -> flywheel typo in FlywheelSim (#3298)
3abe0b9d4 [cscore] Move java package to edu.wpi.first.cscore (#3294)
d7fabe81f [wpilib] Remove RobotDrive (#3295)
1dc81669c [wpilib] Remove GearTooth (#3293)
01d0e1260 [wpilib] Revert move of RomiGyro into main wpilibc/j (#3296)
397e569aa [ntcore] Remove "using wpi" from nt namespace
79267f9e6 [ntcore] Remove NetworkTable -> nt::NetworkTable shim
48ebe5736 [ntcore] Remove deprecated Java interfaces and classes
c2064c78b [ntcore] Remove deprecated ITable interfaces
36608a283 [ntcore] Remove deprecated C++ APIs
a1c87e1e1 [glass] LogView: Add "copy to clipboard" button (#3274)
fa7240a50 [wpimath] Fix typo in quintic spline basis matrix
ffb4d38e2 [wpimath] Add derivation for spline basis matrices
f57c188f2 [wpilib] Add AnalogEncoder(int) ctor (#3273)
8471c4fb2 [wpilib] FieldObject2d: Add setTrajectory() method (#3277)
c97acd18e [glass] Field2d enhancements (#3234)
ffb590bfc [wpilib] Fix Compressor sendable properties (#3269)
6137f98eb [hal] Rename SimValueCallback2 to SimValueCallback (#3212)
a6f653969 [hal] Move registerSimPeriodic functions to HAL package (#3211)
10c038d9b [glass] Plot: Fix window creation after removal (#3264)
2d2eaa3ef [wpigui] Ensure window will be initially visible (#3256)
4d28b1f0c [wpimath] Use JNI for trajectory serialization (#3257)
3de800a60 [wpimath] TrajectoryUtil.h: Comment formatting (NFC) (#3262)
eff592377 [glass] Plot: Don't overwrite series ID (#3260)
a79faace1 [wpilibc] Return reference from GetInstance (#3247)
9550777b9 [wpilib] PWMSpeedController: Use PWM by composition (#3248)
c8521a3c3 [glass] Plot: Set reasonable default window size (#3261)
d71eb2cf3 [glass] Plot: Show full source name as tooltip and in popup (#3255)
160fb740f [hal] Use std::lround() instead of adding 0.5 and truncating (#3012)
48e9f3951 [wpilibj] Remove wpilibj package CameraServer (#3213)
8afa596fd [wpilib] Remove deprecated Sendable functions and SendableBase (#3210)
d3e45c297 [wpimath] Make C++ geometry classes immutable (#3249)
2c98939c1 [glass] StringChooser: Don't call SameLine() at end
a18a7409f [glass] NTStringChooser: Clear value of deleted entries
2f19cf452 [glass] NetworkTablesHelper: listen to delete events
da96707dc Merge branch 'main' into 2022
c3a8bdc24 [build] Fix clang-tidy action (#3246)
21624ef27 Add ImGui OutlineViewer (#3220)
1032c9b91 [wpiutil] Unbreak wpi::Format on Windows (#3242)
2e07902d7 [glass] NTField2D: Fix name lookup (#3233)
6e23e1840 [wpilibc] Remove WPILib.h (#3235)
3e22e4506 [wpilib] Make KoP drivetrain simulation weight 60 lbs (#3228)
79d1bd6c8 [glass] NetworkTablesSetting: Allow disable of server option (#3227)
fe341a16f [examples] Use more logical elevator setpoints in GearsBot (#3198)
62abf46b3 [glass] NetworkTablesSettings: Don't block GUI (#3226)
a95a5e0d9 [glass] Move NetworkTablesSettings to libglassnt (#3224)
d6f6ceaba [build] Run Spotless formatter (NFC) (#3221)
0922f8af5 [commands] CommandScheduler.requiring(): Note return can be null (NFC) (#2934)
6812302ff [examples] Make DriveDistanceOffboard example work in sim (#3199)
f3f86b8e7 [wpimath] Add pose estimator overload for vision + std dev measurement (#3200)
1a2680b9e [wpilibj] Change CommandBase.withName() to return CommandBase (#3209)
435bbb6a8 [command] RamseteCommand: Output 0 if interrupted (#3216)
3cf44e0a5 [hal] Add function for changing HAL Notifier thread priority (#3218)
40b367513 [wpimath] Units.java: Add kg-lb conversions (#3203)
9f563d584 [glass] NT: Fix return value in StringToDoubleArray (#3208)
af4adf537 [glass] Auto-size plots to fit window (#3193)
2560146da [sim] GUI: Add option to show prefix in Other Devices (#3186)
eae3a6397 gitignore: Ignore .cache directory (#3196)
959611420 [wpilib] Require non-zero positive value for PIDController.period (#3175)
9522f2e8c [wpimath] Add methods to concatenate trajectories (#3139)
e42a0b6cf [wpimath] Rotation2d comment formatting (NFC) (#3162)
d1c7032de [wpimath] Fix order of setting gyro offset in pose estimators (#3176)
d241bc81a [sim] Add DoubleSolenoidSim and SolenoidSim classes (#3177)
cb7f39afa [wpilibc] Add RobotController::GetBatteryVoltage() to C++ (#3179)
99b5ad9eb [wpilibj] Fix warnings that are not unused variables or deprecation (#3161)
c14b23775 [build] Fixup doxygen generated include dirs to match what users would need (#3154)
d447c7dc3 [sim] Add SimDeviceSim ctor overloads (#3134)
247420c9c [build] Remove jcenter repo (#3157)
04b112e00 [build] Include debug info in plugin published artifacts (#3149)
be0ce9900 [examples] Use PWMSparkMax instead of PWMVictorSPX (#3156)
69e8d0b65 [wpilib] Move RomiGyro into main wpilibc/j (#3143)
94e685e1b [wpimath] Add custom residual support to EKF (#3148)
5899f3dd2 [sim] GUI: Make keyboard settings loading more robust (#3167)
f82aa1d56 [wpilib] Fix HolonomicDriveController atReference() behavior (#3163)
fe5c2cf4b [wpimath] Remove ControllerUtil.java (#3169)
43d40c6e9 [wpiutil] Suppress unchecked cast in CombinedRuntimeLoader (#3155)
3d44d8f79 [wpimath] Fix argument order in UKF docs (NFC) (#3147)
ba6fe8ff2 [cscore] Add USB camera change event (#3123)
533725888 [build] Tweak OpenCV cmake search paths to work better on Linux (#3144)
29bf9d6ef [cscore] Add polled support to listener
483beb636 [ntcore] Move CallbackManager to wpiutil
fdaec7759 [examples] Instantiate m_ramseteController in example (#3142)
8494a5761 Rename default branch to main (#3140)
45590eea2 [wpigui] Hardcode window scale to 1 on macOS (#3135)
834a64920 [build] Publish libglass and libglassnt to Maven (#3127)
2c2ccb361 [wpimath] Fix Rotation2d equality operator (#3128)
fb5c8c39a [wpigui] clang-tidy: readability-braces-around-statements
f7d39193a [wpigui] Fix copyright in pfd and wpigui_metal.mm
aec796b21 [ntcore] Fix conditional jump on uninitialized value (#3125)
fb13bb239 [sim] GUI: Add right click popup for keyboard joystick settings (#3119)
c517ec677 [build] Update thirdparty-imgui to 1.79-2 (#3118)
e8cbf2a71 [wpimath] Fix typo in SwerveDrivePoseEstimator doc (NFC) (#3112)
e9c86df46 [wpimath] Add tests for swerve module optimization (#3100)
6ba8c289c [examples] Remove negative of ArcadeDrive(fwd, ..) in the C++ Getting Started Example (#3102)
3f1672e89 [hal] Add SimDevice createInt() and createLong() (#3110)
15be5cbf1 [examples] Fix segfault in GearsBot C++ example (#3111)
4cf0e5e6d Add quick links to API documentation in README (#3082)
6b1898f12 Fix RT priority docs (NFC) (#3098)
b3426e9c0 [wpimath] Fix missing whitespace in pose estimator doc (#3097)
38c1a1f3e [examples] Fix feildRelative -> fieldRelative typo in XControllerCommand examples (#3104)
4488e25f1 [glass] Shorten SmartDashboard window names (#3096)
cfdb3058e [wpilibj] Update SimDeviceSimTest (#3095)
64adff5fe [examples] Fix typo in ArcadeDrive constructor parameter name (#3092)
6efc58e3d [build] Fix issues with build on windows, deprecations, and native utils (#3090)
f393989a5 [wpimath, wpiutil] Add wpi::array for compile time size checking (#3087)
d6ed20c1e [build] Set macOS deployment target to 10.14 (#3088)
7c524014c [hal] Add [[nodiscard]] to HAL_WaitForNotifierAlarm() (#3085)
406d055f0 [wpilib] Fixup wouldHitLowerLimit in elevator and arm simulation classes. (#3076)
04a90b5dd [examples] Don't continually set setpoint in PotentiometerPID Examples (#3084)
8c5bfa013 [sim] GUI: Add max value setting for keyboard joysticks (#3083)
bc80c5535 [hal] Add SimValue reset() function (#3064)
9c3b51ca0 [wpilib] Document simulation APIs (#3079)
26584ff14 [wpimath] Add model description to LinearSystemId Javadocs (#3080)
42c3d5286 [examples] Sync Java and C++ trajectories in sim example (#3081)
64e72f710 [wpilibc] Add missing function RoboRioSim::ResetData (#3073)
e95503798 [wpimath] Add optimize() to SwerveModuleState (#3065)
fb99910c2 [hal] Add SimInt and SimLong wrappers for int/long SimValue (#3066)
e620bd4d3 [doc] Add machine-readable websocket specification (#3059)
a44e761d9 [glass] Add support for plot Y axis labels
ea1974d57 [wpigui] Update imgui and implot to latest
85a0bd43c [wpimath] Add RKF45 integration (#3047)
278e0f126 [glass] Use .controllable to set widgets' read-only state (#3035)
d8652cfd4 [wpimath] Make Java DCMotor API consistent with C++ and fix motor calcs (#3046)
377b7065a [build] Add toggleOffOn to Java spotless (#3053)
1e9c79c58 [sim] Use plant output to retrieve simulated position (#3043)
78147aa34 [sim] GUI: Fix Keyboard Joystick (#3052)
cd4a2265b [ntcore] Fix NetworkTableEntry::GetRaw() (#3051)
767ac1de1 [build] Use deploy key for doc publish (#3048)
d762215d1 [build] Add publish documentation script (#3040)
1fd09593c [examples] Add missing TestInit method to GettingStarted Example (#3039)
e45a0f6ce [examples] Add RomiGyro to the Romi Reference example (#3037)
94f852572 Update imaging link and fix typo (#3038)
d73cf64e5 [examples] Update RomiReference to match motor directions (#3036)
f945462ba Bump copyright year to 2021 (#3033)
b05946175 [wpimath] Catch Drake JNI exceptions and rethrow them (#3032)
62f0f8190 [wpimath] Deduplicate angle modulus functions (#2998)
bf8c0da4b [glass] Add "About" popup with version number (#3031)
dfdd6b389 [build] Increase Gradle heap size in Gazebo build (#3028)
f5e0fc3e9 Finish clang-tidy cleanups (#3003)
d741101fe [sim] Revert accidental commit of WSProvider_PDP.h (#3027)
e1620799c [examples] Add C++ RomiReference example (#2969)
749c7adb1 [command] Fix use-after-free in CommandScheduler (#3024)
921a73391 [sim] Add WS providers for AddressableLED, PCM, and Solenoid (#3026)
26d0004fe [build] Split Actions into different yml files (#3025)
948af6d5b [wpilib] PWMSpeedController.get(): Apply Inversion (#3016)
670a187a3 [wpilibc] SuppliedValueWidget.h: Forward declare ShuffleboardContainer (#3021)
be9f72502 [ntcore] NetworkTableValue: Use std::forward instead of std::move (#3022)
daf3f4cb1 [cscore] cscore_raw_cv.h: Fix error in PutFrame() (#3019)
5acda4cc7 [wpimath] ElevatorFeedforward.h: Add time.h include
8452af606 [wpimath] units/radiation.h: Add mass.h include
630d44952 [hal] ErrorsInternal.h: Add stdint.h include
7372cf7d9 [cscore] Windows NetworkUtil.cpp: Add missing include
b7e46c558 Include .h from .inc/.inl files (NFC) (#3017)
bf8f8710e [examples] Update Romi template and example (#2996)
6ffe5b775 [glass] Ensure NetworkTableTree parent context menu has an id (#3015)
be0805b85 [build] Update to WPILibVersioningPlugin 4.1.0 (#3014)
65b2359b2 [build] Add spotless for other files (#3007)
8651aa73e [examples] Enable NT Flush in Field2d examples (#3013)
78b542737 [build] Add Gazebo build to Actions CI (#3004)
fccf86532 [sim] DriverStationGui: Fix two bugs (#3010)
185741760 [sim] WSProvider_Joystick: Fix off-by-1 in incoming buttons (#3011)
ee7114a58 [glass] Add drive class widgets (#2975)
00fa91d0d [glass] Use ImGui style for gyro widget colors (#3009)
b7a25bfc3 ThirdPartyNotices: Add portable file dialogs license (#3005)
a2e46b9a1 [glass] modernize-use-nullptr (NFC) (#3006)
a751fa22d [build] Apply spotless for java formatting (#1768)
e563a0b7d [wpimath] Make LinearSystemLoop move-constructible and move-assignable (#2967)
49085ca94 [glass] Add context menus to remove and add NetworkTables values (#2979)
560a850a2 [glass] Add NetworkTables Log window (#2997)
66782e231 [sim] Create Left/Right drivetrain current accessors (#3001)
b60eb1544 clang-tidy: bugprone-virtual-near-miss
cbe59fa3b clang-tidy: google-explicit-constructor
c97c6dc06 clang-tidy: google-readability-casting (NFC)
32fa97d68 clang-tidy: modernize-use-nullptr (NFC)
aee460326 clang-tidy: modernize-pass-by-value
29c7da5f1 clang-tidy: modernize-make-unique
6131f4e32 clang-tidy: modernize-concat-nested-namespaces (NFC)
67e03e625 clang-tidy: modernize-use-equals-default
b124f9101 clang-tidy: modernize-use-default-member-init
d11a3a638 clang-tidy: modernize-use-override (NFC)
4cc0706b0 clang-tidy: modernize-use-using (NFC)
885f5a978 [wpilibc] Speed up ScopedTracerTest (#2999)
60b596457 [wpilibj] Fix typos (NFC) (#3000)
6e1919414 [build] Bring naming checkstyle rules up to date with Google Style guide (#1781)
8c8ec5e63 [wpilibj] Suppress unchecked cast warnings (#2995)
b8413ddd5 [wpiutil] Add noexcept to timestamp static functions (#2994)
5d976b6e1 [glass] Load NetworkTableView settings on first draw (#2993)
2b4317452 Replace NOLINT(runtime/explicit) comments with NOLINT (NFC) (#2992)
1c3011ba4 [glass] Fix handling of "/" NetworkTables key (#2991)
574a42f3b [hal] Fix UnsafeManipulateDIO status check (#2987)
9005cd59e [wpilib] Clamp input voltage in sim classes (#2955)
dd494d4ab [glass] NetworkTablesModel::Update(): Avoid use-after-move (#2988)
7cca469a1 [wpimath] NormalizeAngle: Make inline, remove unnamed namespace (#2986)
2aed432b4 Add braces to C++ single-line loops and conditionals (NFC) (#2973)
0291a3ff5 [wpiutil] StringRef: Add noexcept to several constructors (#2984)
5d7315280 [wpimath] Update UnitsTest.cpp copyright (#2985)
254931b9a [wpimath] Remove LinearSystem from LinearSystemLoop (#2968)
aa89744c9 Update OtherVersions.md to include wpimath info (#2983)
1cda3f5ad [glass] Fix styleguide (#2976)
8f1f64ffb Remove year from file copyright message (NFC) (#2972)
2bc0a7795 [examples] Fix wpiformat warning about utility include (#2971)
4204da6ad [glass] Add application icon
7ac39b10f [wpigui] Add icon support
6b567e006 [wpimath] Add support for varying vision standard deviations in pose estimators (#2956)
df299d6ed [wpimath] Add UnscentedKalmanFilter::Correct() overload (#2966)
4e34f0523 [examples] Use ADXRS450_GyroSim class in simulation example (#2964)
9962f6fd7 [wpilib] Give Field2d a default Sendable name (#2953)
f9d492f4b [sim] GUI: Show "Other Devices" window by default (#2961)
a8bb2ef1c [sim] Fix ADXRS450_GyroSim and DutyCycleEncoderSim (#2963)
240c629cd [sim] Try to guess "Map Gamepad" setting (#2960)
952567dd3 [wpilibc] Add missing move constructors and assignment operators (#2959)
10b396b4c [sim] Various WebSockets fixes and enhancements (#2952)
699bbe21a [examples] Fix comments in Gearsbot to match implementation (NFC) (#2957)
27b67deca [glass] Add more widgets (#2947)
581b7ec55 [wpilib] Add option to flush NetworkTables every iterative loop
acfbb1a44 [ntcore] DispatcherBase::Flush: Use wpi::Now()
d85a6d8fe [ntcore] Reduce limit on flush and update rate to 5 ms
20fbb5c63 [sim] Fix stringop truncation warning from GCC 10 (#2945)
1051a06a7 [glass] Show NT timestamps in seconds (#2944)
98dfc2620 [glass] Fix plots (#2943)
1ba0a2ced [sim] GUI: Add keyboard virtual joystick support (#2940)
4afb13f98 [examples] Replace M_PI with wpi::math::pi (#2938)
b27d33675 [examples] Enhance Romi templates (#2931)
00b9ae77f [sim] Change default WS port number to 3300 (#2932)
65219f309 [examples] Update Field2d position in periodic() (#2928)
f78d1d434 [sim] Process WS Encoder reset internally (#2927)
941edca59 [hal] Add Java SimDeviceDataJNI.getSimDeviceName (#2924)
a699435ed [wpilibj] Fix FlywheelSim argument order in constructor (#2922)
66d641718 [examples] Add tasks to run Java examples (#2920)
558e37c41 [examples] Add simple differential drive simulation example (#2918)
4f40d991e [glass] Switch name of Glass back to glass (#2919)
549af9900 [build] Update native-utils to 2021.0.6 (#2914)
b33693009 [glass] Change basename of glass to Glass (#2915)
c9a0edfb8 [glass] Package macOS application bundle
2c5668af4 [wpigui] Add platform-specific preferences save
751dea32a [wpilibc] Try to work around ABI break introduced in #2901 (#2917)
cd8f4bfb1 [build] Package up msvc runtime into maven artifact (#2913)
a6cfcc686 [wpilibc] Move SendableChooser Doxygen comments to header (NFC) (#2911)
b8c4f603d [wpimath] Upgrade to Eigen 3.3.9 (#2910)
0075e4b39 [wpilibj] Fix NPE in Field2d (#2909)
125af556c [simulation] Fix halsim_gui ntcore and wpiutil deps (#2908)
963ad5c25 [wpilib] Add noise to Differential Drive simulator (#2903)
387f56cb7 [examples] Add Romi reference Java example and templates (#2905)
b3deda38c [examples] Zero motors on disabledInit() in sim physics examples (#2906)
2a5ca7745 [glass] Add glass: an application for display of robot data
727940d84 [wpilib] Move Field2d to SmartDashboard
8cd42478e [wpilib] SendableBuilder: Make GetTable() visible
c11d34b26 [command] Use addCommands in command group templates (#2900)
339d7445b [sim] Add HAL hooks for simulationPeriodic (#2881)
d16f05f2c [wpilib] Fix SmartDashboard update order (#2896)
5427b32a4 [wpiutil] unique_function: Restrict implicit conversion (#2899)
f73701239 [ntcore] Add missing SetDefault initializer_list functions (#2898)
f5a6fc070 [sim] Add initialized flag for all solenoids on a PCM (#2897)
bdf5ba91a [wpilibj] Fix typo in ElevatorSim (#2895)
bc8f33877 [wpilib] Add pose estimators (#2867)
3413bfc06 [wpilib] PIDController: Recompute the error in AtSetpoint() (#2822)
2056f0ce0 [wpilib] Fix bugs in Hatchbot examples (#2893)
5eb8cfd69 [wpilibc] Fix MatchDataSender (#2892)
e6a425448 [build] Delete test folders after tests execute (#2891)
d478ad00d [imgui] Allow usage of imgui_stdlib (#2889)
53eda861d [build] Add unit-testing infrastructure to examples (#2863)
cc1d86ba6 [sim] Add title to simulator GUI window (#2888)
f0528f00e [build] CMake: Use project-specific binary and source dirs (#2886)
5cd2ad124 [wpilibc] Add Color::operator!= (#2887)
6c00e7a90 [build] CI CMake: build with GUI enabled (#2884)
53170bbb5 Update roboRIO toolchain installation instructions (#2883)
467258e05 [sim] GUI: Add option to not zero disconnected joysticks (#2876)
129be23c9 Clarify JDK installation instructions in readme (#2882)
8e9290e86 [build] Add separate CMake setting for wpimath (#2885)
7cf5bebf8 [wpilibj] Cache NT writes from DriverStation (#2780)
f7f9087fb [command] Fix timing issue in RamseteCommand (#2871)
256e7904f [wpilibj] SimDeviceSim: Fix sim value changed callback (#2880)
c8ea1b6c3 [wpilib] Add function to adjust LQR controller gain for pure time delay (#2878)
2816b06c0 [sim] HAL_GetControlWord: Fully zero output (#2873)
4c695ea08 Add toolchain installation instructions to README (#2875)
a14d51806 [wpimath] DCMotor: fix doc typo (NFC) (#2868)
017097791 [build] CMake: build sim extensions as shared libs (#2866)
f61726b5a [build] Fix cmake-config files (#2865)
fc27fdac5 [wpilibc] Cache NT values from driver station (#2768)
47c59859e [sim] Make SimDevice callbacks synchronous (#2861)
6e76ab9c0 [build] Turn on WITH_GUI for Windows cmake CI
5f78b7670 [build] Set GLFW_INSTALL to OFF
5e0808c84 [wpigui] Fix Windows cmake build
508f05a47 [imgui] Fix typo in Windows CMake target sources
Change-Id: I1737b45965f31803a96676bedc7dc40e337aa321
git-subtree-dir: third_party/allwpilib
git-subtree-split: e473a00f9785f9949e5ced30901baeaf426d2fc9
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/wpilibNewCommands/.styleguide b/wpilibNewCommands/.styleguide
index 11a1339..3f20ec8 100644
--- a/wpilibNewCommands/.styleguide
+++ b/wpilibNewCommands/.styleguide
@@ -15,6 +15,7 @@
includeOtherLibs {
^cameraserver/
^cscore
+ ^fmt/
^frc/
^hal/
^imgui
diff --git a/wpilibNewCommands/CMakeLists.txt b/wpilibNewCommands/CMakeLists.txt
new file mode 100644
index 0000000..d44939f
--- /dev/null
+++ b/wpilibNewCommands/CMakeLists.txt
@@ -0,0 +1,59 @@
+project(wpilibNewCommands)
+
+include(SubDirList)
+include(CompileWarnings)
+include(AddTest)
+
+if (WITH_JAVA)
+ find_package(Java REQUIRED)
+ include(UseJava)
+ set(CMAKE_JAVA_COMPILE_FLAGS "-encoding" "UTF8" "-Xlint:unchecked")
+
+ file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java)
+ add_jar(wpilibNewCommands_jar ${JAVA_SOURCES} INCLUDE_JARS hal_jar ntcore_jar cscore_jar cameraserver_jar wpimath_jar wpiutil_jar wpilibj_jar OUTPUT_NAME wpilibNewCommands)
+
+ get_property(WPILIBNEWCOMMANDS_JAR_FILE TARGET wpilibNewCommands_jar PROPERTY JAR_FILE)
+ install(FILES ${WPILIBNEWCOMMANDS_JAR_FILE} DESTINATION "${java_lib_dest}")
+
+ set_property(TARGET wpilibNewCommands_jar PROPERTY FOLDER "java")
+
+ if (WITH_FLAT_INSTALL)
+ set (wpilibNewCommands_config_dir ${wpilib_dest})
+ else()
+ set (wpilibNewCommands_config_dir share/wpilibNewCommands)
+ endif()
+
+ install(FILES wpilibNewCommands-config.cmake DESTINATION ${wpilibNewCommands_config_dir})
+endif()
+
+file(GLOB_RECURSE wpilibNewCommands_native_src src/main/native/cpp/*.cpp)
+add_library(wpilibNewCommands ${wpilibNewCommands_native_src})
+set_target_properties(wpilibNewCommands PROPERTIES DEBUG_POSTFIX "d")
+set_property(TARGET wpilibNewCommands PROPERTY FOLDER "libraries")
+
+target_compile_features(wpilibNewCommands PUBLIC cxx_std_17)
+wpilib_target_warnings(wpilibNewCommands)
+target_link_libraries(wpilibNewCommands wpilibc)
+
+target_include_directories(wpilibNewCommands PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
+ $<INSTALL_INTERFACE:${include_dest}/wpilibNewCommands>)
+
+install(TARGETS wpilibNewCommands EXPORT wpilibNewCommands DESTINATION "${main_lib_dest}")
+install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/wpilibNewCommands")
+
+if (MSVC OR FLAT_INSTALL_WPILIB)
+ set(wpilibNewCommands_config_dir ${wpilib_dest})
+ else()
+ set(wpilibNewCommands_config_dir share/wpilibNewCommands)
+ endif()
+
+ configure_file(wpilibNewCommands-config.cmake.in ${WPILIB_BINARY_DIR}/wpilibNewCommands-config.cmake)
+ install(FILES ${WPILIB_BINARY_DIR}/wpilibNewCommands-config.cmake DESTINATION ${wpilibNewCommands_config_dir})
+ install(EXPORT wpilibNewCommands DESTINATION ${wpilibNewCommands_config_dir})
+
+ if (WITH_TESTS)
+ wpilib_add_test(wpilibNewCommands src/test/native/cpp)
+ target_include_directories(wpilibNewCommands_test PRIVATE src/test/native/include)
+ target_link_libraries(wpilibNewCommands_test wpilibNewCommands gmock_main)
+ endif()
diff --git a/wpilibNewCommands/build.gradle b/wpilibNewCommands/build.gradle
index 82affa0..ed81160 100644
--- a/wpilibNewCommands/build.gradle
+++ b/wpilibNewCommands/build.gradle
@@ -1,101 +1,117 @@
-ext {
- nativeName = 'wpilibNewCommands'
- devMain = 'edu.wpi.first.wpilibj.commands.DevMain'
-}
-
-evaluationDependsOn(':ntcore')
-evaluationDependsOn(':cscore')
-evaluationDependsOn(':hal')
-evaluationDependsOn(':wpimath')
-evaluationDependsOn(':wpilibc')
-evaluationDependsOn(':cameraserver')
-evaluationDependsOn(':wpilibj')
-
-apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
-
-dependencies {
- implementation project(':wpiutil')
- implementation project(':ntcore')
- implementation project(':cscore')
- implementation project(':hal')
- implementation project(':wpimath')
- implementation project(':wpilibj')
- devImplementation project(':wpiutil')
- devImplementation project(':ntcore')
- devImplementation project(':cscore')
- devImplementation project(':hal')
- devImplementation project(':wpimath')
- devImplementation project(':wpilibj')
- testImplementation 'com.google.guava:guava:19.0'
- testImplementation 'org.mockito:mockito-core:2.27.0'
-}
-
-nativeUtils.exportsConfigs {
- wpilibNewCommands {
- x86ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
- '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
- '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
- '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
- x64ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
- '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
- '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
- '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
- }
-}
-
-apply plugin: DisableBuildingGTest
-
-model {
- components {}
- binaries {
- all {
- if (!it.buildable || !(it instanceof NativeBinarySpec)) {
- return
- }
- lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
- lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
- project(':hal').addHalDependency(it, 'shared')
- lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
- lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
-
- if (it.component.name == "${nativeName}Dev") {
- lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared'
- project(':hal').addHalJniDependency(it)
- }
-
- if (it instanceof GoogleTestTestSuiteBinarySpec) {
- nativeUtils.useRequiredLibrary(it, 'opencv_shared')
- lib project: ':cscore', library: 'cscore', linkage: 'shared'
- }
- if ((it instanceof NativeExecutableBinarySpec || it instanceof GoogleTestTestSuiteBinarySpec) && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
- nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
- }
- }
- }
- tasks {
- def c = $.components
- def found = false
- def systemArch = getCurrentArch()
- c.each {
- if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
- it.binaries.each {
- if (!found) {
- def arch = it.targetPlatform.name
- if (arch == systemArch) {
- def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
-
- found = true
- }
- }
- }
- }
- }
- }
-}
-
-test {
- testLogging {
- outputs.upToDateWhen {false}
- showStandardStreams = true
- }
-}
+ext {
+ nativeName = 'wpilibNewCommands'
+ devMain = 'edu.wpi.first.wpilibj.commands.DevMain'
+}
+
+evaluationDependsOn(':ntcore')
+evaluationDependsOn(':cscore')
+evaluationDependsOn(':hal')
+evaluationDependsOn(':wpimath')
+evaluationDependsOn(':wpilibc')
+evaluationDependsOn(':cameraserver')
+evaluationDependsOn(':wpilibj')
+
+apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
+
+dependencies {
+ implementation project(':wpiutil')
+ implementation project(':ntcore')
+ implementation project(':cscore')
+ implementation project(':hal')
+ implementation project(':wpimath')
+ implementation project(':wpilibj')
+ devImplementation project(':wpiutil')
+ devImplementation project(':ntcore')
+ devImplementation project(':cscore')
+ devImplementation project(':hal')
+ devImplementation project(':wpimath')
+ devImplementation project(':wpilibj')
+ testImplementation 'com.google.guava:guava:19.0'
+ testImplementation 'org.mockito:mockito-core:2.27.0'
+}
+
+nativeUtils.exportsConfigs {
+ wpilibNewCommands {
+ x86ExcludeSymbols = [
+ '_CT??_R0?AV_System_error',
+ '_CT??_R0?AVexception',
+ '_CT??_R0?AVfailure',
+ '_CT??_R0?AVruntime_error',
+ '_CT??_R0?AVsystem_error',
+ '_CTA5?AVfailure',
+ '_TI5?AVfailure',
+ '_CT??_R0?AVout_of_range',
+ '_CTA3?AVout_of_range',
+ '_TI3?AVout_of_range',
+ '_CT??_R0?AVbad_cast'
+ ]
+ x64ExcludeSymbols = [
+ '_CT??_R0?AV_System_error',
+ '_CT??_R0?AVexception',
+ '_CT??_R0?AVfailure',
+ '_CT??_R0?AVruntime_error',
+ '_CT??_R0?AVsystem_error',
+ '_CTA5?AVfailure',
+ '_TI5?AVfailure',
+ '_CT??_R0?AVout_of_range',
+ '_CTA3?AVout_of_range',
+ '_TI3?AVout_of_range',
+ '_CT??_R0?AVbad_cast'
+ ]
+ }
+}
+
+model {
+ components {}
+ binaries {
+ all {
+ if (!it.buildable || !(it instanceof NativeBinarySpec)) {
+ return
+ }
+ lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
+ lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
+ project(':hal').addHalDependency(it, 'shared')
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
+
+ if (it.component.name == "${nativeName}Dev") {
+ lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared'
+ project(':hal').addHalJniDependency(it)
+ }
+
+ if (it instanceof GoogleTestTestSuiteBinarySpec) {
+ nativeUtils.useRequiredLibrary(it, 'opencv_shared')
+ lib project: ':cscore', library: 'cscore', linkage: 'shared'
+ }
+ if ((it instanceof NativeExecutableBinarySpec || it instanceof GoogleTestTestSuiteBinarySpec) && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
+ }
+ }
+ }
+ tasks {
+ def c = $.components
+ def found = false
+ def systemArch = getCurrentArch()
+ c.each {
+ if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
+ it.binaries.each {
+ if (!found) {
+ def arch = it.targetPlatform.name
+ if (arch == systemArch) {
+ def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
+
+ found = true
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+test {
+ testLogging {
+ outputs.upToDateWhen {false}
+ showStandardStreams = true
+ }
+}
diff --git a/wpilibNewCommands/src/dev/java/edu/wpi/first/wpilibj2/commands/DevMain.java b/wpilibNewCommands/src/dev/java/edu/wpi/first/wpilibj2/commands/DevMain.java
index ca6ce63..484d735 100644
--- a/wpilibNewCommands/src/dev/java/edu/wpi/first/wpilibj2/commands/DevMain.java
+++ b/wpilibNewCommands/src/dev/java/edu/wpi/first/wpilibj2/commands/DevMain.java
@@ -1,20 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.commands;
import edu.wpi.first.hal.HALUtil;
import edu.wpi.first.networktables.NetworkTablesJNI;
-import edu.wpi.first.wpiutil.RuntimeDetector;
+import edu.wpi.first.util.RuntimeDetector;
public final class DevMain {
- /**
- * Main entry point.
- */
+ /** Main entry point. */
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
@@ -22,6 +17,5 @@
System.out.println(HALUtil.getHALRuntimeType());
}
- private DevMain() {
- }
+ private DevMain() {}
}
diff --git a/wpilibNewCommands/src/dev/native/cpp/main.cpp b/wpilibNewCommands/src/dev/native/cpp/main.cpp
index 5312a1d..a3e363e 100644
--- a/wpilibNewCommands/src/dev/native/cpp/main.cpp
+++ b/wpilibNewCommands/src/dev/native/cpp/main.cpp
@@ -1,8 +1,5 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
int main() {}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java
index ba950c7..8f9901b 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -11,42 +8,34 @@
import java.util.function.BooleanSupplier;
/**
- * A state machine representing a complete action to be performed by the robot. Commands are
- * run by the {@link CommandScheduler}, and can be composed into CommandGroups to allow users to
- * build complicated multi-step actions without the need to roll the state machine logic themselves.
+ * A state machine representing a complete action to be performed by the robot. Commands are run by
+ * the {@link CommandScheduler}, and can be composed into CommandGroups to allow users to build
+ * complicated multi-step actions without the need to roll the state machine logic themselves.
*
* <p>Commands are run synchronously from the main robot loop; no multithreading is used, unless
* specified explicitly from the command implementation.
*/
public interface Command {
+ /** The initial subroutine of a command. Called once when the command is initially scheduled. */
+ default void initialize() {}
+
+ /** The main body of a command. Called repeatedly while the command is scheduled. */
+ default void execute() {}
/**
- * The initial subroutine of a command. Called once when the command is initially scheduled.
- */
- default void initialize() {
- }
-
- /**
- * The main body of a command. Called repeatedly while the command is scheduled.
- */
- default void execute() {
- }
-
- /**
- * The action to take when the command ends. Called when either the command finishes normally,
- * or when it interrupted/canceled.
+ * The action to take when the command ends. Called when either the command finishes normally, or
+ * when it interrupted/canceled.
*
- * <p>Do not schedule commands here that share requirements with this command.
- * Use {@link #andThen(Command...)} instead.
+ * <p>Do not schedule commands here that share requirements with this command. Use {@link
+ * #andThen(Command...)} instead.
*
* @param interrupted whether the command was interrupted/canceled
*/
- default void end(boolean interrupted) {
- }
+ default void end(boolean interrupted) {}
/**
- * Whether the command has finished. Once a command finishes, the scheduler will call its
- * end() method and un-schedule it.
+ * Whether the command has finished. Once a command finishes, the scheduler will call its end()
+ * method and un-schedule it.
*
* @return whether the command has finished.
*/
@@ -55,99 +44,114 @@
}
/**
- * Specifies the set of subsystems used by this command. Two commands cannot use the same
- * subsystem at the same time. If the command is scheduled as interruptible and another
- * command is scheduled that shares a requirement, the command will be interrupted. Else,
- * the command will not be scheduled. If no subsystems are required, return an empty set.
+ * Specifies the set of subsystems used by this command. Two commands cannot use the same
+ * subsystem at the same time. If the command is scheduled as interruptible and another command is
+ * scheduled that shares a requirement, the command will be interrupted. Else, the command will
+ * not be scheduled. If no subsystems are required, return an empty set.
*
- * <p>Note: it is recommended that user implementations contain the requirements as a field,
- * and return that field here, rather than allocating a new set every time this is called.
+ * <p>Note: it is recommended that user implementations contain the requirements as a field, and
+ * return that field here, rather than allocating a new set every time this is called.
*
* @return the set of subsystems that are required
*/
Set<Subsystem> getRequirements();
/**
- * Decorates this command with a timeout. If the specified timeout is exceeded before the command
- * finishes normally, the command will be interrupted and un-scheduled. Note that the
- * timeout only applies to the command returned by this method; the calling command is
- * not itself changed.
+ * Decorates this command with a timeout. If the specified timeout is exceeded before the command
+ * finishes normally, the command will be interrupted and un-scheduled. Note that the timeout only
+ * applies to the command returned by this method; the calling command is not itself changed.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
* @param seconds the timeout duration
* @return the command with the timeout added
*/
default ParallelRaceGroup withTimeout(double seconds) {
- return new ParallelRaceGroup(this, new WaitCommand(seconds));
+ return raceWith(new WaitCommand(seconds));
}
/**
- * Decorates this command with an interrupt condition. If the specified condition becomes true
- * before the command finishes normally, the command will be interrupted and un-scheduled.
- * Note that this only applies to the command returned by this method; the calling command
- * is not itself changed.
+ * Decorates this command with an interrupt condition. If the specified condition becomes true
+ * before the command finishes normally, the command will be interrupted and un-scheduled. Note
+ * that this only applies to the command returned by this method; the calling command is not
+ * itself changed.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
* @param condition the interrupt condition
* @return the command with the interrupt condition added
*/
default ParallelRaceGroup withInterrupt(BooleanSupplier condition) {
- return new ParallelRaceGroup(this, new WaitUntilCommand(condition));
+ return raceWith(new WaitUntilCommand(condition));
}
/**
* Decorates this command with a runnable to run before this command starts.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
- * @param toRun the Runnable to run
+ * @param toRun the Runnable to run
* @param requirements the required subsystems
* @return the decorated command
*/
default SequentialCommandGroup beforeStarting(Runnable toRun, Subsystem... requirements) {
- return new SequentialCommandGroup(new InstantCommand(toRun, requirements), this);
+ return beforeStarting(new InstantCommand(toRun, requirements));
+ }
+
+ /**
+ * Decorates this command with another command to run before this command starts.
+ *
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * cannot be used independently after being decorated, or be re-decorated with a different
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
+ *
+ * @param before the command to run before this one
+ * @return the decorated command
+ */
+ default SequentialCommandGroup beforeStarting(Command before) {
+ return new SequentialCommandGroup(before, this);
}
/**
* Decorates this command with a runnable to run after the command finishes.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
- * @param toRun the Runnable to run
+ * @param toRun the Runnable to run
* @param requirements the required subsystems
* @return the decorated command
*/
default SequentialCommandGroup andThen(Runnable toRun, Subsystem... requirements) {
- return new SequentialCommandGroup(this, new InstantCommand(toRun, requirements));
+ return andThen(new InstantCommand(toRun, requirements));
}
/**
- * Decorates this command with a set of commands to run after it in sequence. Often more
+ * Decorates this command with a set of commands to run after it in sequence. Often more
* convenient/less-verbose than constructing a new {@link SequentialCommandGroup} explicitly.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
* @param next the commands to run next
* @return the decorated command
@@ -160,14 +164,14 @@
/**
* Decorates this command with a set of commands to run parallel to it, ending when the calling
- * command ends and interrupting all the others. Often more convenient/less-verbose than
+ * command ends and interrupting all the others. Often more convenient/less-verbose than
* constructing a new {@link ParallelDeadlineGroup} explicitly.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
* @param parallel the commands to run in parallel
* @return the decorated command
@@ -178,14 +182,14 @@
/**
* Decorates this command with a set of commands to run parallel to it, ending when the last
- * command ends. Often more convenient/less-verbose than constructing a new
- * {@link ParallelCommandGroup} explicitly.
+ * command ends. Often more convenient/less-verbose than constructing a new {@link
+ * ParallelCommandGroup} explicitly.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
* @param parallel the commands to run in parallel
* @return the decorated command
@@ -198,14 +202,14 @@
/**
* Decorates this command with a set of commands to run parallel to it, ending when the first
- * command ends. Often more convenient/less-verbose than constructing a new
- * {@link ParallelRaceGroup} explicitly.
+ * command ends. Often more convenient/less-verbose than constructing a new {@link
+ * ParallelRaceGroup} explicitly.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
* @param parallel the commands to run in parallel
* @return the decorated command
@@ -217,14 +221,14 @@
}
/**
- * Decorates this command to run perpetually, ignoring its ordinary end conditions. The decorated
+ * Decorates this command to run perpetually, ignoring its ordinary end conditions. The decorated
* command can still be interrupted or canceled.
*
- * <p>Note: This decorator works by composing this command within a CommandGroup. The command
+ * <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
- * decorator, unless it is manually cleared from the list of grouped commands with
- * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
- * further decorated without issue.
+ * decorator, unless it is manually cleared from the list of grouped commands with {@link
+ * CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
+ * decorated without issue.
*
* @return the decorated command
*/
@@ -233,9 +237,9 @@
}
/**
- * Decorates this command to run "by proxy" by wrapping it in a {@link ProxyScheduleCommand}.
- * This is useful for "forking off" from command groups when the user does not wish to extend
- * the command's requirements to the entire command group.
+ * Decorates this command to run "by proxy" by wrapping it in a {@link ProxyScheduleCommand}. This
+ * is useful for "forking off" from command groups when the user does not wish to extend the
+ * command's requirements to the entire command group.
*
* @return the decorated command
*/
@@ -246,32 +250,29 @@
/**
* Schedules this command.
*
- * @param interruptible whether this command can be interrupted by another command that
- * shares one of its requirements
+ * @param interruptible whether this command can be interrupted by another command that shares one
+ * of its requirements
*/
default void schedule(boolean interruptible) {
CommandScheduler.getInstance().schedule(interruptible, this);
}
- /**
- * Schedules this command, defaulting to interruptible.
- */
+ /** Schedules this command, defaulting to interruptible. */
default void schedule() {
schedule(true);
}
/**
- * Cancels this command. Will call the command's interrupted() method.
- * Commands will be canceled even if they are not marked as interruptible.
+ * Cancels this command. Will call the command's interrupted() method. Commands will be canceled
+ * even if they are not marked as interruptible.
*/
default void cancel() {
CommandScheduler.getInstance().cancel(this);
}
/**
- * Whether or not the command is currently scheduled. Note that this does not detect whether
- * the command is being run by a CommandGroup, only whether it is directly being run by
- * the scheduler.
+ * Whether or not the command is currently scheduled. Note that this does not detect whether the
+ * command is being run by a CommandGroup, only whether it is directly being run by the scheduler.
*
* @return Whether the command is scheduled.
*/
@@ -280,10 +281,7 @@
}
/**
- * Whether the command requires a given subsystem. Named "hasRequirement" rather than "requires"
- * to avoid confusion with
- * {@link edu.wpi.first.wpilibj.command.Command#requires(edu.wpi.first.wpilibj.command.Subsystem)}
- * - this may be able to be changed in a few years.
+ * Whether the command requires a given subsystem.
*
* @param requirement the subsystem to inquire about
* @return whether the subsystem is required
@@ -293,8 +291,8 @@
}
/**
- * Whether the given command should run when the robot is disabled. Override to return true
- * if the command should run when disabled.
+ * Whether the given command should run when the robot is disabled. Override to return true if the
+ * command should run when disabled.
*
* @return whether the command should run when the robot is disabled
*/
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java
index 49180a8..bb1df60 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java
@@ -1,25 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import edu.wpi.first.util.sendable.Sendable;
+import edu.wpi.first.util.sendable.SendableBuilder;
+import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.HashSet;
import java.util.Set;
-import edu.wpi.first.wpilibj.Sendable;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
-import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
-
-/**
- * A {@link Sendable} base class for {@link Command}s.
- */
-@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
+/** A {@link Sendable} base class for {@link Command}s. */
public abstract class CommandBase implements Sendable, Command {
-
protected Set<Subsystem> m_requirements = new HashSet<>();
protected CommandBase() {
@@ -51,19 +43,17 @@
*
* @param name name
*/
- @Override
public void setName(String name) {
SendableRegistry.setName(this, name);
}
/**
- * Decorates this Command with a name.
- * Is an inline function for #setName(String);
- *
- * @param name name
- * @return the decorated Command
- */
- public Command withName(String name) {
+ * Decorates this Command with a name. Is an inline function for #setName(String);
+ *
+ * @param name name
+ * @return the decorated Command
+ */
+ public CommandBase withName(String name) {
this.setName(name);
return this;
}
@@ -73,7 +63,6 @@
*
* @return Subsystem name
*/
- @Override
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
@@ -83,13 +72,12 @@
*
* @param subsystem subsystem name
*/
- @Override
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
/**
- * Initializes this sendable. Useful for allowing implementations to easily extend SendableBase.
+ * Initializes this sendable. Useful for allowing implementations to easily extend SendableBase.
*
* @param builder the builder used to construct this sendable
*/
@@ -97,18 +85,21 @@
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Command");
builder.addStringProperty(".name", this::getName, null);
- builder.addBooleanProperty("running", this::isScheduled, value -> {
- if (value) {
- if (!isScheduled()) {
- schedule();
- }
- } else {
- if (isScheduled()) {
- cancel();
- }
- }
- });
- builder.addBooleanProperty(".isParented",
- () -> CommandGroupBase.getGroupedCommands().contains(this), null);
+ builder.addBooleanProperty(
+ "running",
+ this::isScheduled,
+ value -> {
+ if (value) {
+ if (!isScheduled()) {
+ schedule();
+ }
+ } else {
+ if (isScheduled()) {
+ cancel();
+ }
+ }
+ });
+ builder.addBooleanProperty(
+ ".isParented", () -> CommandGroupBase.getGroupedCommands().contains(this), null);
}
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandGroupBase.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandGroupBase.java
index 6ac0667..d3a35d4 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandGroupBase.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandGroupBase.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -13,11 +10,11 @@
import java.util.WeakHashMap;
/**
- * A base for CommandGroups. Statically tracks commands that have been allocated to groups to
- * ensure those commands are not also used independently, which can result in inconsistent command
- * state and unpredictable execution.
+ * A base for CommandGroups. Statically tracks commands that have been allocated to groups to ensure
+ * those commands are not also used independently, which can result in inconsistent command state
+ * and unpredictable execution.
*/
-public abstract class CommandGroupBase extends CommandBase implements Command {
+public abstract class CommandGroupBase extends CommandBase {
private static final Set<Command> m_groupedCommands =
Collections.newSetFromMap(new WeakHashMap<>());
@@ -28,8 +25,8 @@
/**
* Clears the list of grouped commands, allowing all commands to be freely used again.
*
- * <p>WARNING: Using this haphazardly can result in unexpected/undesirable behavior. Do not
- * use this unless you fully understand what you are doing.
+ * <p>WARNING: Using this haphazardly can result in unexpected/undesirable behavior. Do not use
+ * this unless you fully understand what you are doing.
*/
public static void clearGroupedCommands() {
m_groupedCommands.clear();
@@ -39,8 +36,8 @@
* Removes a single command from the list of grouped commands, allowing it to be freely used
* again.
*
- * <p>WARNING: Using this haphazardly can result in unexpected/undesirable behavior. Do not
- * use this unless you fully understand what you are doing.
+ * <p>WARNING: Using this haphazardly can result in unexpected/undesirable behavior. Do not use
+ * this unless you fully understand what you are doing.
*
* @param command the command to remove from the list of grouped commands
*/
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandScheduler.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandScheduler.java
index 60488d2..79be1bf 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandScheduler.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandScheduler.java
@@ -1,12 +1,21 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import edu.wpi.first.hal.FRCNetComm.tInstances;
+import edu.wpi.first.hal.FRCNetComm.tResourceType;
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.networktables.NTSendable;
+import edu.wpi.first.networktables.NTSendableBuilder;
+import edu.wpi.first.networktables.NetworkTableEntry;
+import edu.wpi.first.util.sendable.SendableRegistry;
+import edu.wpi.first.wpilibj.RobotBase;
+import edu.wpi.first.wpilibj.RobotState;
+import edu.wpi.first.wpilibj.TimedRobot;
+import edu.wpi.first.wpilibj.Watchdog;
+import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -18,31 +27,15 @@
import java.util.Set;
import java.util.function.Consumer;
-import edu.wpi.first.hal.FRCNetComm.tInstances;
-import edu.wpi.first.hal.FRCNetComm.tResourceType;
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.networktables.NetworkTableEntry;
-import edu.wpi.first.wpilibj.RobotBase;
-import edu.wpi.first.wpilibj.RobotState;
-import edu.wpi.first.wpilibj.Sendable;
-import edu.wpi.first.wpilibj.TimedRobot;
-import edu.wpi.first.wpilibj.Watchdog;
-import edu.wpi.first.wpilibj.livewindow.LiveWindow;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
-import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
-
/**
- * The scheduler responsible for running {@link Command}s. A Command-based robot should call {@link
+ * The scheduler responsible for running {@link Command}s. A Command-based robot should call {@link
* CommandScheduler#run()} on the singleton instance in its periodic block in order to run commands
- * synchronously from the main loop. Subsystems should be registered with the scheduler using
- * {@link CommandScheduler#registerSubsystem(Subsystem...)} in order for their {@link
- * Subsystem#periodic()} methods to be called and for their default commands to be scheduled.
+ * synchronously from the main loop. Subsystems should be registered with the scheduler using {@link
+ * CommandScheduler#registerSubsystem(Subsystem...)} in order for their {@link Subsystem#periodic()}
+ * methods to be called and for their default commands to be scheduled.
*/
-@SuppressWarnings({"PMD.GodClass", "PMD.TooManyFields"})
-public final class CommandScheduler implements Sendable, AutoCloseable {
- /**
- * The Singleton Instance.
- */
+public final class CommandScheduler implements NTSendable, AutoCloseable {
+ /** The Singleton Instance. */
private static CommandScheduler instance;
/**
@@ -57,24 +50,24 @@
return instance;
}
- //A map from commands to their scheduling state. Also used as a set of the currently-running
- //commands.
+ // A map from commands to their scheduling state. Also used as a set of the currently-running
+ // commands.
private final Map<Command, CommandState> m_scheduledCommands = new LinkedHashMap<>();
- //A map from required subsystems to their requiring commands. Also used as a set of the
- //currently-required subsystems.
+ // A map from required subsystems to their requiring commands. Also used as a set of the
+ // currently-required subsystems.
private final Map<Subsystem, Command> m_requirements = new LinkedHashMap<>();
- //A map from subsystems registered with the scheduler to their default commands. Also used
- //as a list of currently-registered subsystems.
+ // A map from subsystems registered with the scheduler to their default commands. Also used
+ // as a list of currently-registered subsystems.
private final Map<Subsystem, Command> m_subsystems = new LinkedHashMap<>();
- //The set of currently-registered buttons that will be polled every iteration.
+ // The set of currently-registered buttons that will be polled every iteration.
private final Collection<Runnable> m_buttons = new LinkedHashSet<>();
private boolean m_disabled;
- //Lists of user-supplied actions to be executed on scheduling events for every command.
+ // Lists of user-supplied actions to be executed on scheduling events for every command.
private final List<Consumer<Command>> m_initActions = new ArrayList<>();
private final List<Consumer<Command>> m_executeActions = new ArrayList<>();
private final List<Consumer<Command>> m_interruptActions = new ArrayList<>();
@@ -86,22 +79,24 @@
private final Map<Command, Boolean> m_toSchedule = new LinkedHashMap<>();
private final List<Command> m_toCancel = new ArrayList<>();
- private final Watchdog m_watchdog = new Watchdog(TimedRobot.kDefaultPeriod, () -> { });
+ private final Watchdog m_watchdog = new Watchdog(TimedRobot.kDefaultPeriod, () -> {});
CommandScheduler() {
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand2_Scheduler);
SendableRegistry.addLW(this, "Scheduler");
- LiveWindow.setEnabledListener(() -> {
- disable();
- cancelAll();
- });
- LiveWindow.setDisabledListener(() -> {
- enable();
- });
+ LiveWindow.setEnabledListener(
+ () -> {
+ disable();
+ cancelAll();
+ });
+ LiveWindow.setDisabledListener(
+ () -> {
+ enable();
+ });
}
/**
- * Changes the period of the loop overrun watchdog. This should be be kept in sync with the
+ * Changes the period of the loop overrun watchdog. This should be be kept in sync with the
* TimedRobot period.
*
* @param period Period in seconds.
@@ -126,9 +121,7 @@
m_buttons.add(button);
}
- /**
- * Removes all button bindings from the scheduler.
- */
+ /** Removes all button bindings from the scheduler. */
public void clearButtons() {
m_buttons.clear();
}
@@ -136,9 +129,9 @@
/**
* Initializes a given command, adds its requirements to the list, and performs the init actions.
*
- * @param command The command to initialize
+ * @param command The command to initialize
* @param interruptible Whether the command is interruptible
- * @param requirements The command requirements
+ * @param requirements The command requirements
*/
private void initCommand(Command command, boolean interruptible, Set<Subsystem> requirements) {
CommandState scheduledCommand = new CommandState(interruptible);
@@ -155,15 +148,14 @@
}
/**
- * Schedules a command for execution. Does nothing if the command is already scheduled. If a
+ * Schedules a command for execution. Does nothing if the command is already scheduled. If a
* command's requirements are not available, it will only be started if all the commands currently
- * using those requirements have been scheduled as interruptible. If this is the case, they will
+ * using those requirements have been scheduled as interruptible. If this is the case, they will
* be interrupted and the command will be scheduled.
*
* @param interruptible whether this command can be interrupted
- * @param command the command to schedule
+ * @param command the command to schedule
*/
- @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
private void schedule(boolean interruptible, Command command) {
if (m_inRunLoop) {
m_toSchedule.put(command, interruptible);
@@ -175,21 +167,22 @@
"A command that is part of a command group cannot be independently scheduled");
}
- //Do nothing if the scheduler is disabled, the robot is disabled and the command doesn't
- //run when disabled, or the command is already scheduled.
- if (m_disabled || (RobotState.isDisabled() && !command.runsWhenDisabled())
+ // Do nothing if the scheduler is disabled, the robot is disabled and the command doesn't
+ // run when disabled, or the command is already scheduled.
+ if (m_disabled
+ || (RobotState.isDisabled() && !command.runsWhenDisabled())
|| m_scheduledCommands.containsKey(command)) {
return;
}
Set<Subsystem> requirements = command.getRequirements();
- //Schedule the command if the requirements are not currently in-use.
+ // Schedule the command if the requirements are not currently in-use.
if (Collections.disjoint(m_requirements.keySet(), requirements)) {
initCommand(command, interruptible, requirements);
} else {
- //Else check if the requirements that are in use have all have interruptible commands,
- //and if so, interrupt those commands and schedule the new command.
+ // Else check if the requirements that are in use have all have interruptible commands,
+ // and if so, interrupt those commands and schedule the new command.
for (Subsystem requirement : requirements) {
if (m_requirements.containsKey(requirement)
&& !m_scheduledCommands.get(m_requirements.get(requirement)).isInterruptible()) {
@@ -206,13 +199,13 @@
}
/**
- * Schedules multiple commands for execution. Does nothing if the command is already scheduled.
- * If a command's requirements are not available, it will only be started if all the commands
- * currently using those requirements have been scheduled as interruptible. If this is the case,
+ * Schedules multiple commands for execution. Does nothing if the command is already scheduled. If
+ * a command's requirements are not available, it will only be started if all the commands
+ * currently using those requirements have been scheduled as interruptible. If this is the case,
* they will be interrupted and the command will be scheduled.
*
* @param interruptible whether the commands should be interruptible
- * @param commands the commands to schedule
+ * @param commands the commands to schedule
*/
public void schedule(boolean interruptible, Command... commands) {
for (Command command : commands) {
@@ -221,7 +214,7 @@
}
/**
- * Schedules multiple commands for execution, with interruptible defaulted to true. Does nothing
+ * Schedules multiple commands for execution, with interruptible defaulted to true. Does nothing
* if the command is already scheduled.
*
* @param commands the commands to schedule
@@ -231,7 +224,7 @@
}
/**
- * Runs a single iteration of the scheduler. The execution occurs in the following order:
+ * Runs a single iteration of the scheduler. The execution occurs in the following order:
*
* <p>Subsystem periodic methods are called.
*
@@ -244,14 +237,13 @@
*
* <p>Any subsystems not being used as requirements have their default methods started.
*/
- @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public void run() {
if (m_disabled) {
return;
}
m_watchdog.reset();
- //Run the periodic method of all registered subsystems.
+ // Run the periodic method of all registered subsystems.
for (Subsystem subsystem : m_subsystems.keySet()) {
subsystem.periodic();
if (RobotBase.isSimulation()) {
@@ -260,16 +252,16 @@
m_watchdog.addEpoch(subsystem.getClass().getSimpleName() + ".periodic()");
}
- //Poll buttons for new commands to add.
+ // Poll buttons for new commands to add.
for (Runnable button : m_buttons) {
button.run();
}
m_watchdog.addEpoch("buttons.run()");
m_inRunLoop = true;
- //Run scheduled commands, remove finished commands.
+ // Run scheduled commands, remove finished commands.
for (Iterator<Command> iterator = m_scheduledCommands.keySet().iterator();
- iterator.hasNext(); ) {
+ iterator.hasNext(); ) {
Command command = iterator.next();
if (!command.runsWhenDisabled() && RobotState.isDisabled()) {
@@ -301,7 +293,7 @@
}
m_inRunLoop = false;
- //Schedule/cancel commands from queues populated during loop
+ // Schedule/cancel commands from queues populated during loop
for (Map.Entry<Command, Boolean> commandInterruptible : m_toSchedule.entrySet()) {
schedule(commandInterruptible.getValue(), commandInterruptible.getKey());
}
@@ -313,7 +305,7 @@
m_toSchedule.clear();
m_toCancel.clear();
- //Add default commands for un-required registered subsystems.
+ // Add default commands for un-required registered subsystems.
for (Map.Entry<Subsystem, Command> subsystemCommand : m_subsystems.entrySet()) {
if (!m_requirements.containsKey(subsystemCommand.getKey())
&& subsystemCommand.getValue() != null) {
@@ -329,10 +321,9 @@
}
/**
- * Registers subsystems with the scheduler. This must be called for the subsystem's periodic
- * block to run when the scheduler is run, and for the subsystem's default command to be
- * scheduled. It is recommended to call this from the constructor of your subsystem
- * implementations.
+ * Registers subsystems with the scheduler. This must be called for the subsystem's periodic block
+ * to run when the scheduler is run, and for the subsystem's default command to be scheduled. It
+ * is recommended to call this from the constructor of your subsystem implementations.
*
* @param subsystems the subsystem to register
*/
@@ -343,7 +334,7 @@
}
/**
- * Un-registers subsystems with the scheduler. The subsystem will no longer have its periodic
+ * Un-registers subsystems with the scheduler. The subsystem will no longer have its periodic
* block called, and will not have its default command scheduled.
*
* @param subsystems the subsystem to un-register
@@ -353,13 +344,13 @@
}
/**
- * Sets the default command for a subsystem. Registers that subsystem if it is not already
- * registered. Default commands will run whenever there is no other command currently scheduled
- * that requires the subsystem. Default commands should be written to never end (i.e. their
- * {@link Command#isFinished()} method should return false), as they would simply be re-scheduled
- * if they do. Default commands must also require their subsystem.
+ * Sets the default command for a subsystem. Registers that subsystem if it is not already
+ * registered. Default commands will run whenever there is no other command currently scheduled
+ * that requires the subsystem. Default commands should be written to never end (i.e. their {@link
+ * Command#isFinished()} method should return false), as they would simply be re-scheduled if they
+ * do. Default commands must also require their subsystem.
*
- * @param subsystem the subsystem whose default command will be set
+ * @param subsystem the subsystem whose default command will be set
* @param defaultCommand the default command to associate with the subsystem
*/
public void setDefaultCommand(Subsystem subsystem, Command defaultCommand) {
@@ -375,7 +366,7 @@
}
/**
- * Gets the default command associated with this subsystem. Null if this subsystem has no default
+ * Gets the default command associated with this subsystem. Null if this subsystem has no default
* command associated with it.
*
* @param subsystem the subsystem to inquire about
@@ -386,9 +377,9 @@
}
/**
- * Cancels commands. The scheduler will only call {@link Command#end(boolean)} method
- * of the canceled command with {@code true},
- * indicating they were canceled (as opposed to finishing normally).
+ * Cancels commands. The scheduler will only call {@link Command#end(boolean)} method of the
+ * canceled command with {@code true}, indicating they were canceled (as opposed to finishing
+ * normally).
*
* <p>Commands will be canceled even if they are not scheduled as interruptible.
*
@@ -415,9 +406,7 @@
}
}
- /**
- * Cancels all commands that are currently scheduled.
- */
+ /** Cancels all commands that are currently scheduled. */
public void cancelAll() {
for (Command command : m_scheduledCommands.keySet().toArray(new Command[0])) {
cancel(command);
@@ -425,7 +414,7 @@
}
/**
- * Returns the time since a given command was scheduled. Note that this only works on commands
+ * Returns the time since a given command was scheduled. Note that this only works on commands
* that are directly scheduled by the scheduler; it will not work on commands inside of
* commandgroups, as the scheduler does not see them.
*
@@ -442,9 +431,9 @@
}
/**
- * Whether the given commands are running. Note that this only works on commands that are
- * directly scheduled by the scheduler; it will not work on commands inside of CommandGroups, as
- * the scheduler does not see them.
+ * Whether the given commands are running. Note that this only works on commands that are directly
+ * scheduled by the scheduler; it will not work on commands inside of CommandGroups, as the
+ * scheduler does not see them.
*
* @param commands the command to query
* @return whether the command is currently scheduled
@@ -454,26 +443,23 @@
}
/**
- * Returns the command currently requiring a given subsystem. Null if no command is currently
+ * Returns the command currently requiring a given subsystem. Null if no command is currently
* requiring the subsystem
*
* @param subsystem the subsystem to be inquired about
- * @return the command currently requiring the subsystem
+ * @return the command currently requiring the subsystem, or null if no command is currently
+ * scheduled
*/
public Command requiring(Subsystem subsystem) {
return m_requirements.get(subsystem);
}
- /**
- * Disables the command scheduler.
- */
+ /** Disables the command scheduler. */
public void disable() {
m_disabled = true;
}
- /**
- * Enables the command scheduler.
- */
+ /** Enables the command scheduler. */
public void enable() {
m_disabled = false;
}
@@ -515,39 +501,38 @@
}
@Override
- public void initSendable(SendableBuilder builder) {
+ public void initSendable(NTSendableBuilder builder) {
builder.setSmartDashboardType("Scheduler");
final NetworkTableEntry namesEntry = builder.getEntry("Names");
final NetworkTableEntry idsEntry = builder.getEntry("Ids");
final NetworkTableEntry cancelEntry = builder.getEntry("Cancel");
- builder.setUpdateTable(() -> {
+ builder.setUpdateTable(
+ () -> {
+ if (namesEntry == null || idsEntry == null || cancelEntry == null) {
+ return;
+ }
- if (namesEntry == null || idsEntry == null || cancelEntry == null) {
- return;
- }
+ Map<Double, Command> ids = new LinkedHashMap<>();
- Map<Double, Command> ids = new LinkedHashMap<>();
+ for (Command command : m_scheduledCommands.keySet()) {
+ ids.put((double) command.hashCode(), command);
+ }
+ double[] toCancel = cancelEntry.getDoubleArray(new double[0]);
+ if (toCancel.length > 0) {
+ for (double hash : toCancel) {
+ cancel(ids.get(hash));
+ ids.remove(hash);
+ }
+ cancelEntry.setDoubleArray(new double[0]);
+ }
- for (Command command : m_scheduledCommands.keySet()) {
- ids.put((double) command.hashCode(), command);
- }
+ List<String> names = new ArrayList<>();
- double[] toCancel = cancelEntry.getDoubleArray(new double[0]);
- if (toCancel.length > 0) {
- for (double hash : toCancel) {
- cancel(ids.get(hash));
- ids.remove(hash);
- }
- cancelEntry.setDoubleArray(new double[0]);
- }
+ ids.values().forEach(command -> names.add(command.getName()));
- List<String> names = new ArrayList<>();
-
- ids.values().forEach(command -> names.add(command.getName()));
-
- namesEntry.setStringArray(names.toArray(new String[0]));
- idsEntry.setNumberArray(ids.keySet().toArray(new Double[0]));
- });
+ namesEntry.setStringArray(names.toArray(new String[0]));
+ idsEntry.setNumberArray(ids.keySet().toArray(new Double[0]));
+ });
}
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandState.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandState.java
index 2e2dc7e..2d60982 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandState.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandState.java
@@ -1,23 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
import edu.wpi.first.wpilibj.Timer;
/**
- * Class that holds scheduling state for a command. Used internally by the
- * {@link CommandScheduler}.
+ * Class that holds scheduling state for a command. Used internally by the {@link CommandScheduler}.
*/
class CommandState {
- //The time since this command was initialized.
+ // The time since this command was initialized.
private double m_startTime = -1;
- //Whether or not it is interruptible.
+ // Whether or not it is interruptible.
private final boolean m_interruptible;
CommandState(boolean interruptible) {
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ConditionalCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ConditionalCommand.java
index 8e3239c..74bf1ce 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ConditionalCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ConditionalCommand.java
@@ -1,23 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.function.BooleanSupplier;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import static edu.wpi.first.wpilibj2.command.CommandGroupBase.requireUngrouped;
+import java.util.function.BooleanSupplier;
+
/**
* Runs one of two commands, depending on the value of the given condition when this command is
- * initialized. Does not actually schedule the selected command - rather, the command is run
- * through this command; this ensures that the command will behave as expected if used as part of a
- * CommandGroup. Requires the requirements of both commands, again to ensure proper functioning
- * when used in a CommandGroup. If this is undesired, consider using {@link ScheduleCommand}.
+ * initialized. Does not actually schedule the selected command - rather, the command is run through
+ * this command; this ensures that the command will behave as expected if used as part of a
+ * CommandGroup. Requires the requirements of both commands, again to ensure proper functioning when
+ * used in a CommandGroup. If this is undesired, consider using {@link ScheduleCommand}.
*
* <p>As this command contains multiple component commands within it, it is technically a command
* group; the command instances that are passed to it cannot be added to any other groups, or
@@ -34,8 +31,8 @@
/**
* Creates a new ConditionalCommand.
*
- * @param onTrue the command to run if the condition is true
- * @param onFalse the command to run if the condition is false
+ * @param onTrue the command to run if the condition is true
+ * @param onFalse the command to run if the condition is false
* @param condition the condition to determine which command to run
*/
public ConditionalCommand(Command onTrue, Command onFalse, BooleanSupplier condition) {
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/FunctionalCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/FunctionalCommand.java
index b9dd6db..d9469c3 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/FunctionalCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/FunctionalCommand.java
@@ -1,20 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
-import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-
/**
* A command that allows the user to pass in functions for each of the basic command methods through
- * the constructor. Useful for inline definitions of complex commands - note, however, that if a
+ * the constructor. Useful for inline definitions of complex commands - note, however, that if a
* command is beyond a certain complexity it is usually better practice to write a proper class for
* it than to inline it.
*/
@@ -27,14 +24,18 @@
/**
* Creates a new FunctionalCommand.
*
- * @param onInit the function to run on command initialization
- * @param onExecute the function to run on command execution
- * @param onEnd the function to run on command end
- * @param isFinished the function that determines whether the command has finished
+ * @param onInit the function to run on command initialization
+ * @param onExecute the function to run on command execution
+ * @param onEnd the function to run on command end
+ * @param isFinished the function that determines whether the command has finished
* @param requirements the subsystems required by this command
*/
- public FunctionalCommand(Runnable onInit, Runnable onExecute, Consumer<Boolean> onEnd,
- BooleanSupplier isFinished, Subsystem... requirements) {
+ public FunctionalCommand(
+ Runnable onInit,
+ Runnable onExecute,
+ Consumer<Boolean> onEnd,
+ BooleanSupplier isFinished,
+ Subsystem... requirements) {
m_onInit = requireNonNullParam(onInit, "onInit", "FunctionalCommand");
m_onExecute = requireNonNullParam(onExecute, "onExecute", "FunctionalCommand");
m_onEnd = requireNonNullParam(onEnd, "onEnd", "FunctionalCommand");
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/InstantCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/InstantCommand.java
index 8518890..10816df 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/InstantCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/InstantCommand.java
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
/**
- * A Command that runs instantly; it will initialize, execute once, and end on the same
- * iteration of the scheduler. Users can either pass in a Runnable and a set of requirements,
- * or else subclass this command if desired.
+ * A Command that runs instantly; it will initialize, execute once, and end on the same iteration of
+ * the scheduler. Users can either pass in a Runnable and a set of requirements, or else subclass
+ * this command if desired.
*/
public class InstantCommand extends CommandBase {
private final Runnable m_toRun;
@@ -20,7 +17,7 @@
/**
* Creates a new InstantCommand that runs the given Runnable with the given requirements.
*
- * @param toRun the Runnable to run
+ * @param toRun the Runnable to run
* @param requirements the subsystems required by this command
*/
public InstantCommand(Runnable toRun, Subsystem... requirements) {
@@ -30,12 +27,11 @@
}
/**
- * Creates a new InstantCommand with a Runnable that does nothing. Useful only as a no-arg
+ * Creates a new InstantCommand with a Runnable that does nothing. Useful only as a no-arg
* constructor to call implicitly from subclass constructors.
*/
public InstantCommand() {
- m_toRun = () -> {
- };
+ m_toRun = () -> {};
}
@Override
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java
index 9105f7a..28c75a9 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java
@@ -1,50 +1,42 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+
+import edu.wpi.first.math.controller.HolonomicDriveController;
+import edu.wpi.first.math.controller.PIDController;
+import edu.wpi.first.math.controller.ProfiledPIDController;
+import edu.wpi.first.math.controller.SimpleMotorFeedforward;
+import edu.wpi.first.math.geometry.Pose2d;
+import edu.wpi.first.math.geometry.Rotation2d;
+import edu.wpi.first.math.kinematics.ChassisSpeeds;
+import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
+import edu.wpi.first.math.kinematics.MecanumDriveMotorVoltages;
+import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
+import edu.wpi.first.math.trajectory.Trajectory;
+import edu.wpi.first.wpilibj.Timer;
import java.util.function.Consumer;
import java.util.function.Supplier;
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.controller.HolonomicDriveController;
-import edu.wpi.first.wpilibj.controller.PIDController;
-import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
-import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward;
-import edu.wpi.first.wpilibj.geometry.Pose2d;
-import edu.wpi.first.wpilibj.geometry.Rotation2d;
-import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds;
-import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics;
-import edu.wpi.first.wpilibj.kinematics.MecanumDriveMotorVoltages;
-import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds;
-import edu.wpi.first.wpilibj.trajectory.Trajectory;
-
-import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-
/**
- * A command that uses two PID controllers ({@link PIDController}) and a
- * ProfiledPIDController ({@link ProfiledPIDController}) to follow a trajectory
- * {@link Trajectory} with a mecanum drive.
+ * A command that uses two PID controllers ({@link PIDController}) and a ProfiledPIDController
+ * ({@link ProfiledPIDController}) to follow a trajectory {@link Trajectory} with a mecanum drive.
*
- * <p>The command handles trajectory-following,
- * Velocity PID calculations, and feedforwards internally. This
- * is intended to be a more-or-less "complete solution" that can be used by teams without a great
- * deal of controls expertise.
+ * <p>The command handles trajectory-following, Velocity PID calculations, and feedforwards
+ * internally. This is intended to be a more-or-less "complete solution" that can be used by teams
+ * without a great deal of controls expertise.
*
- * <p>Advanced teams seeking more flexibility (for example, those who wish to use the onboard
- * PID functionality of a "smart" motor controller) may use the secondary constructor that omits
- * the PID and feedforward functionality, returning only the raw wheel speeds from the PID
- * controllers.
+ * <p>Advanced teams seeking more flexibility (for example, those who wish to use the onboard PID
+ * functionality of a "smart" motor controller) may use the secondary constructor that omits the PID
+ * and feedforward functionality, returning only the raw wheel speeds from the PID controllers.
*
- * <p>The robot angle controller does not follow the angle given by
- * the trajectory but rather goes to the angle given in the final state of the trajectory.
+ * <p>The robot angle controller does not follow the angle given by the trajectory but rather goes
+ * to the angle given in the final state of the trajectory.
*/
-
-@SuppressWarnings({"PMD.TooManyFields", "MemberName"})
+@SuppressWarnings("MemberName")
public class MecanumControllerCommand extends CommandBase {
private final Timer m_timer = new Timer();
private final boolean m_usePID;
@@ -73,85 +65,79 @@
* <p>Note: The controllers will *not* set the outputVolts to zero upon completion of the path
* this is left to the user, since it is not appropriate for paths with nonstationary endstates.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param desiredRotation The angle that the robot should be facing. This
- * is sampled at each time step.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param feedforward The feedforward to use for the drivetrain.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param xController The Trajectory Tracker PID controller for the robot's x position.
+ * @param yController The Trajectory Tracker PID controller for the robot's y position.
+ * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
+ * @param desiredRotation The angle that the robot should be facing. This is sampled at each time
+ * step.
* @param maxWheelVelocityMetersPerSecond The maximum velocity of a drivetrain wheel.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing
- * the current wheel speeds.
- * @param outputDriveVoltages A MecanumDriveMotorVoltages object containing
- * the output motor voltages.
- * @param requirements The subsystems to require.
+ * @param frontLeftController The front left wheel velocity PID.
+ * @param rearLeftController The rear left wheel velocity PID.
+ * @param frontRightController The front right wheel velocity PID.
+ * @param rearRightController The rear right wheel velocity PID.
+ * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing the current wheel speeds.
+ * @param outputDriveVoltages A MecanumDriveMotorVoltages object containing the output motor
+ * voltages.
+ * @param requirements The subsystems to require.
*/
-
- @SuppressWarnings({"PMD.ExcessiveParameterList", "ParameterName"})
- public MecanumControllerCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- SimpleMotorFeedforward feedforward,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Supplier<Rotation2d> desiredRotation,
- double maxWheelVelocityMetersPerSecond,
- PIDController frontLeftController,
- PIDController rearLeftController,
- PIDController frontRightController,
- PIDController rearRightController,
- Supplier<MecanumDriveWheelSpeeds> currentWheelSpeeds,
- Consumer<MecanumDriveMotorVoltages> outputDriveVoltages,
- Subsystem... requirements) {
- m_trajectory = requireNonNullParam(trajectory, "trajectory",
- "MecanumControllerCommand");
+ @SuppressWarnings("ParameterName")
+ public MecanumControllerCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ SimpleMotorFeedforward feedforward,
+ MecanumDriveKinematics kinematics,
+ PIDController xController,
+ PIDController yController,
+ ProfiledPIDController thetaController,
+ Supplier<Rotation2d> desiredRotation,
+ double maxWheelVelocityMetersPerSecond,
+ PIDController frontLeftController,
+ PIDController rearLeftController,
+ PIDController frontRightController,
+ PIDController rearRightController,
+ Supplier<MecanumDriveWheelSpeeds> currentWheelSpeeds,
+ Consumer<MecanumDriveMotorVoltages> outputDriveVoltages,
+ Subsystem... requirements) {
+ m_trajectory = requireNonNullParam(trajectory, "trajectory", "MecanumControllerCommand");
m_pose = requireNonNullParam(pose, "pose", "MecanumControllerCommand");
- m_feedforward = requireNonNullParam(feedforward, "feedforward",
- "MecanumControllerCommand");
- m_kinematics = requireNonNullParam(kinematics, "kinematics",
- "MecanumControllerCommand");
+ m_feedforward = requireNonNullParam(feedforward, "feedforward", "MecanumControllerCommand");
+ m_kinematics = requireNonNullParam(kinematics, "kinematics", "MecanumControllerCommand");
- m_controller = new HolonomicDriveController(
- requireNonNullParam(xController,
- "xController", "SwerveControllerCommand"),
- requireNonNullParam(yController,
- "xController", "SwerveControllerCommand"),
- requireNonNullParam(thetaController,
- "thetaController", "SwerveControllerCommand")
- );
+ m_controller =
+ new HolonomicDriveController(
+ requireNonNullParam(xController, "xController", "SwerveControllerCommand"),
+ requireNonNullParam(yController, "xController", "SwerveControllerCommand"),
+ requireNonNullParam(thetaController, "thetaController", "SwerveControllerCommand"));
- m_desiredRotation = requireNonNullParam(desiredRotation, "desiredRotation",
- "MecanumControllerCommand");
+ m_desiredRotation =
+ requireNonNullParam(desiredRotation, "desiredRotation", "MecanumControllerCommand");
- m_maxWheelVelocityMetersPerSecond = requireNonNullParam(maxWheelVelocityMetersPerSecond,
- "maxWheelVelocityMetersPerSecond", "MecanumControllerCommand");
+ m_maxWheelVelocityMetersPerSecond =
+ requireNonNullParam(
+ maxWheelVelocityMetersPerSecond,
+ "maxWheelVelocityMetersPerSecond",
+ "MecanumControllerCommand");
- m_frontLeftController = requireNonNullParam(frontLeftController,
- "frontLeftController", "MecanumControllerCommand");
- m_rearLeftController = requireNonNullParam(rearLeftController,
- "rearLeftController", "MecanumControllerCommand");
- m_frontRightController = requireNonNullParam(frontRightController,
- "frontRightController", "MecanumControllerCommand");
- m_rearRightController = requireNonNullParam(rearRightController,
- "rearRightController", "MecanumControllerCommand");
+ m_frontLeftController =
+ requireNonNullParam(frontLeftController, "frontLeftController", "MecanumControllerCommand");
+ m_rearLeftController =
+ requireNonNullParam(rearLeftController, "rearLeftController", "MecanumControllerCommand");
+ m_frontRightController =
+ requireNonNullParam(
+ frontRightController, "frontRightController", "MecanumControllerCommand");
+ m_rearRightController =
+ requireNonNullParam(rearRightController, "rearRightController", "MecanumControllerCommand");
- m_currentWheelSpeeds = requireNonNullParam(currentWheelSpeeds,
- "currentWheelSpeeds", "MecanumControllerCommand");
+ m_currentWheelSpeeds =
+ requireNonNullParam(currentWheelSpeeds, "currentWheelSpeeds", "MecanumControllerCommand");
- m_outputDriveVoltages = requireNonNullParam(outputDriveVoltages,
- "outputDriveVoltages", "MecanumControllerCommand");
+ m_outputDriveVoltages =
+ requireNonNullParam(outputDriveVoltages, "outputDriveVoltages", "MecanumControllerCommand");
m_outputWheelSpeeds = null;
@@ -168,56 +154,63 @@
* <p>Note: The controllers will *not* set the outputVolts to zero upon completion of the path
* this is left to the user, since it is not appropriate for paths with nonstationary endstates.
*
- * <p>Note 2: The final rotation of the robot will be set to the rotation of
- * the final pose in the trajectory. The robot will not follow the rotations
- * from the poses at each timestep. If alternate rotation behavior is desired,
- * the other constructor with a supplier for rotation should be used.
+ * <p>Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
+ * trajectory. The robot will not follow the rotations from the poses at each timestep. If
+ * alternate rotation behavior is desired, the other constructor with a supplier for rotation
+ * should be used.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param feedforward The feedforward to use for the drivetrain.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param xController The Trajectory Tracker PID controller for the robot's x position.
+ * @param yController The Trajectory Tracker PID controller for the robot's y position.
+ * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
* @param maxWheelVelocityMetersPerSecond The maximum velocity of a drivetrain wheel.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing
- * the current wheel speeds.
- * @param outputDriveVoltages A MecanumDriveMotorVoltages object containing
- * the output motor voltages.
- * @param requirements The subsystems to require.
+ * @param frontLeftController The front left wheel velocity PID.
+ * @param rearLeftController The rear left wheel velocity PID.
+ * @param frontRightController The front right wheel velocity PID.
+ * @param rearRightController The rear right wheel velocity PID.
+ * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing the current wheel speeds.
+ * @param outputDriveVoltages A MecanumDriveMotorVoltages object containing the output motor
+ * voltages.
+ * @param requirements The subsystems to require.
*/
-
- @SuppressWarnings({"PMD.ExcessiveParameterList", "ParameterName"})
- public MecanumControllerCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- SimpleMotorFeedforward feedforward,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- double maxWheelVelocityMetersPerSecond,
- PIDController frontLeftController,
- PIDController rearLeftController,
- PIDController frontRightController,
- PIDController rearRightController,
- Supplier<MecanumDriveWheelSpeeds> currentWheelSpeeds,
- Consumer<MecanumDriveMotorVoltages> outputDriveVoltages,
- Subsystem... requirements) {
-
- this(trajectory, pose, feedforward, kinematics, xController, yController, thetaController,
- () -> trajectory.getStates().get(trajectory.getStates().size() - 1)
- .poseMeters.getRotation(),
- maxWheelVelocityMetersPerSecond, frontLeftController, rearLeftController,
- frontRightController, rearRightController, currentWheelSpeeds, outputDriveVoltages,
+ @SuppressWarnings("ParameterName")
+ public MecanumControllerCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ SimpleMotorFeedforward feedforward,
+ MecanumDriveKinematics kinematics,
+ PIDController xController,
+ PIDController yController,
+ ProfiledPIDController thetaController,
+ double maxWheelVelocityMetersPerSecond,
+ PIDController frontLeftController,
+ PIDController rearLeftController,
+ PIDController frontRightController,
+ PIDController rearRightController,
+ Supplier<MecanumDriveWheelSpeeds> currentWheelSpeeds,
+ Consumer<MecanumDriveMotorVoltages> outputDriveVoltages,
+ Subsystem... requirements) {
+ this(
+ trajectory,
+ pose,
+ feedforward,
+ kinematics,
+ xController,
+ yController,
+ thetaController,
+ () ->
+ trajectory.getStates().get(trajectory.getStates().size() - 1).poseMeters.getRotation(),
+ maxWheelVelocityMetersPerSecond,
+ frontLeftController,
+ rearLeftController,
+ frontRightController,
+ rearRightController,
+ currentWheelSpeeds,
+ outputDriveVoltages,
requirements);
}
@@ -228,56 +221,50 @@
* <p>Note: The controllers will *not* set the outputVolts to zero upon completion of the path -
* this is left to the user, since it is not appropriate for paths with non-stationary end-states.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param desiredRotation The angle that the robot should be facing. This
- * is sampled at each time step.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param xController The Trajectory Tracker PID controller for the robot's x position.
+ * @param yController The Trajectory Tracker PID controller for the robot's y position.
+ * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
+ * @param desiredRotation The angle that the robot should be facing. This is sampled at each time
+ * step.
* @param maxWheelVelocityMetersPerSecond The maximum velocity of a drivetrain wheel.
- * @param outputWheelSpeeds A MecanumDriveWheelSpeeds object containing
- * the output wheel speeds.
- * @param requirements The subsystems to require.
+ * @param outputWheelSpeeds A MecanumDriveWheelSpeeds object containing the output wheel speeds.
+ * @param requirements The subsystems to require.
*/
-
- @SuppressWarnings({"PMD.ExcessiveParameterList", "ParameterName"})
- public MecanumControllerCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Supplier<Rotation2d> desiredRotation,
- double maxWheelVelocityMetersPerSecond,
- Consumer<MecanumDriveWheelSpeeds> outputWheelSpeeds,
- Subsystem... requirements) {
- m_trajectory = requireNonNullParam(trajectory, "trajectory",
- "MecanumControllerCommand");
+ @SuppressWarnings("ParameterName")
+ public MecanumControllerCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ MecanumDriveKinematics kinematics,
+ PIDController xController,
+ PIDController yController,
+ ProfiledPIDController thetaController,
+ Supplier<Rotation2d> desiredRotation,
+ double maxWheelVelocityMetersPerSecond,
+ Consumer<MecanumDriveWheelSpeeds> outputWheelSpeeds,
+ Subsystem... requirements) {
+ m_trajectory = requireNonNullParam(trajectory, "trajectory", "MecanumControllerCommand");
m_pose = requireNonNullParam(pose, "pose", "MecanumControllerCommand");
m_feedforward = new SimpleMotorFeedforward(0, 0, 0);
- m_kinematics = requireNonNullParam(kinematics,
- "kinematics", "MecanumControllerCommand");
+ m_kinematics = requireNonNullParam(kinematics, "kinematics", "MecanumControllerCommand");
- m_controller = new HolonomicDriveController(
- requireNonNullParam(xController,
- "xController", "SwerveControllerCommand"),
- requireNonNullParam(yController,
- "xController", "SwerveControllerCommand"),
- requireNonNullParam(thetaController,
- "thetaController", "SwerveControllerCommand")
- );
+ m_controller =
+ new HolonomicDriveController(
+ requireNonNullParam(xController, "xController", "SwerveControllerCommand"),
+ requireNonNullParam(yController, "xController", "SwerveControllerCommand"),
+ requireNonNullParam(thetaController, "thetaController", "SwerveControllerCommand"));
- m_desiredRotation = requireNonNullParam(desiredRotation, "desiredRotation",
- "MecanumControllerCommand");
+ m_desiredRotation =
+ requireNonNullParam(desiredRotation, "desiredRotation", "MecanumControllerCommand");
- m_maxWheelVelocityMetersPerSecond = requireNonNullParam(maxWheelVelocityMetersPerSecond,
- "maxWheelVelocityMetersPerSecond", "MecanumControllerCommand");
+ m_maxWheelVelocityMetersPerSecond =
+ requireNonNullParam(
+ maxWheelVelocityMetersPerSecond,
+ "maxWheelVelocityMetersPerSecond",
+ "MecanumControllerCommand");
m_frontLeftController = null;
m_rearLeftController = null;
@@ -286,8 +273,8 @@
m_currentWheelSpeeds = null;
- m_outputWheelSpeeds = requireNonNullParam(outputWheelSpeeds,
- "outputWheelSpeeds", "MecanumControllerCommand");
+ m_outputWheelSpeeds =
+ requireNonNullParam(outputWheelSpeeds, "outputWheelSpeeds", "MecanumControllerCommand");
m_outputDriveVoltages = null;
@@ -303,54 +290,58 @@
* <p>Note: The controllers will *not* set the outputVolts to zero upon completion of the path -
* this is left to the user, since it is not appropriate for paths with non-stationary end-states.
*
- * <p>Note 2: The final rotation of the robot will be set to the rotation of
- * the final pose in the trajectory. The robot will not follow the rotations
- * from the poses at each timestep. If alternate rotation behavior is desired,
- * the other constructor with a supplier for rotation should be used.
+ * <p>Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
+ * trajectory. The robot will not follow the rotations from the poses at each timestep. If
+ * alternate rotation behavior is desired, the other constructor with a supplier for rotation
+ * should be used.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param xController The Trajectory Tracker PID controller for the robot's x position.
+ * @param yController The Trajectory Tracker PID controller for the robot's y position.
+ * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
* @param maxWheelVelocityMetersPerSecond The maximum velocity of a drivetrain wheel.
- * @param outputWheelSpeeds A MecanumDriveWheelSpeeds object containing
- * the output wheel speeds.
- * @param requirements The subsystems to require.
+ * @param outputWheelSpeeds A MecanumDriveWheelSpeeds object containing the output wheel speeds.
+ * @param requirements The subsystems to require.
*/
-
- @SuppressWarnings({"PMD.ExcessiveParameterList", "ParameterName"})
- public MecanumControllerCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- double maxWheelVelocityMetersPerSecond,
- Consumer<MecanumDriveWheelSpeeds> outputWheelSpeeds,
- Subsystem... requirements) {
- this(trajectory, pose, kinematics, xController, yController, thetaController,
- () -> trajectory.getStates().get(trajectory.getStates().size() - 1)
- .poseMeters.getRotation(),
- maxWheelVelocityMetersPerSecond, outputWheelSpeeds, requirements);
+ @SuppressWarnings("ParameterName")
+ public MecanumControllerCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ MecanumDriveKinematics kinematics,
+ PIDController xController,
+ PIDController yController,
+ ProfiledPIDController thetaController,
+ double maxWheelVelocityMetersPerSecond,
+ Consumer<MecanumDriveWheelSpeeds> outputWheelSpeeds,
+ Subsystem... requirements) {
+ this(
+ trajectory,
+ pose,
+ kinematics,
+ xController,
+ yController,
+ thetaController,
+ () ->
+ trajectory.getStates().get(trajectory.getStates().size() - 1).poseMeters.getRotation(),
+ maxWheelVelocityMetersPerSecond,
+ outputWheelSpeeds,
+ requirements);
}
@Override
public void initialize() {
var initialState = m_trajectory.sample(0);
- var initialXVelocity = initialState.velocityMetersPerSecond
- * initialState.poseMeters.getRotation().getCos();
- var initialYVelocity = initialState.velocityMetersPerSecond
- * initialState.poseMeters.getRotation().getSin();
+ var initialXVelocity =
+ initialState.velocityMetersPerSecond * initialState.poseMeters.getRotation().getCos();
+ var initialYVelocity =
+ initialState.velocityMetersPerSecond * initialState.poseMeters.getRotation().getSin();
- m_prevSpeeds = m_kinematics.toWheelSpeeds(
- new ChassisSpeeds(initialXVelocity, initialYVelocity, 0.0));
+ m_prevSpeeds =
+ m_kinematics.toWheelSpeeds(new ChassisSpeeds(initialXVelocity, initialYVelocity, 0.0));
m_timer.reset();
m_timer.start();
@@ -364,8 +355,8 @@
var desiredState = m_trajectory.sample(curTime);
- var targetChassisSpeeds = m_controller.calculate(m_pose.get(), desiredState,
- m_desiredRotation.get());
+ var targetChassisSpeeds =
+ m_controller.calculate(m_pose.get(), desiredState, m_desiredRotation.get());
var targetWheelSpeeds = m_kinematics.toWheelSpeeds(targetChassisSpeeds);
targetWheelSpeeds.normalize(m_maxWheelVelocityMetersPerSecond);
@@ -381,46 +372,57 @@
double rearRightOutput;
if (m_usePID) {
- final double frontLeftFeedforward = m_feedforward.calculate(frontLeftSpeedSetpoint,
- (frontLeftSpeedSetpoint - m_prevSpeeds.frontLeftMetersPerSecond) / dt);
+ final double frontLeftFeedforward =
+ m_feedforward.calculate(
+ frontLeftSpeedSetpoint,
+ (frontLeftSpeedSetpoint - m_prevSpeeds.frontLeftMetersPerSecond) / dt);
- final double rearLeftFeedforward = m_feedforward.calculate(rearLeftSpeedSetpoint,
- (rearLeftSpeedSetpoint - m_prevSpeeds.rearLeftMetersPerSecond) / dt);
+ final double rearLeftFeedforward =
+ m_feedforward.calculate(
+ rearLeftSpeedSetpoint,
+ (rearLeftSpeedSetpoint - m_prevSpeeds.rearLeftMetersPerSecond) / dt);
- final double frontRightFeedforward = m_feedforward.calculate(frontRightSpeedSetpoint,
- (frontRightSpeedSetpoint - m_prevSpeeds.frontRightMetersPerSecond) / dt);
+ final double frontRightFeedforward =
+ m_feedforward.calculate(
+ frontRightSpeedSetpoint,
+ (frontRightSpeedSetpoint - m_prevSpeeds.frontRightMetersPerSecond) / dt);
- final double rearRightFeedforward = m_feedforward.calculate(rearRightSpeedSetpoint,
- (rearRightSpeedSetpoint - m_prevSpeeds.rearRightMetersPerSecond) / dt);
+ final double rearRightFeedforward =
+ m_feedforward.calculate(
+ rearRightSpeedSetpoint,
+ (rearRightSpeedSetpoint - m_prevSpeeds.rearRightMetersPerSecond) / dt);
- frontLeftOutput = frontLeftFeedforward + m_frontLeftController.calculate(
- m_currentWheelSpeeds.get().frontLeftMetersPerSecond,
- frontLeftSpeedSetpoint);
+ frontLeftOutput =
+ frontLeftFeedforward
+ + m_frontLeftController.calculate(
+ m_currentWheelSpeeds.get().frontLeftMetersPerSecond, frontLeftSpeedSetpoint);
- rearLeftOutput = rearLeftFeedforward + m_rearLeftController.calculate(
- m_currentWheelSpeeds.get().rearLeftMetersPerSecond,
- rearLeftSpeedSetpoint);
+ rearLeftOutput =
+ rearLeftFeedforward
+ + m_rearLeftController.calculate(
+ m_currentWheelSpeeds.get().rearLeftMetersPerSecond, rearLeftSpeedSetpoint);
- frontRightOutput = frontRightFeedforward + m_frontRightController.calculate(
- m_currentWheelSpeeds.get().frontRightMetersPerSecond,
- frontRightSpeedSetpoint);
+ frontRightOutput =
+ frontRightFeedforward
+ + m_frontRightController.calculate(
+ m_currentWheelSpeeds.get().frontRightMetersPerSecond, frontRightSpeedSetpoint);
- rearRightOutput = rearRightFeedforward + m_rearRightController.calculate(
- m_currentWheelSpeeds.get().rearRightMetersPerSecond,
- rearRightSpeedSetpoint);
+ rearRightOutput =
+ rearRightFeedforward
+ + m_rearRightController.calculate(
+ m_currentWheelSpeeds.get().rearRightMetersPerSecond, rearRightSpeedSetpoint);
- m_outputDriveVoltages.accept(new MecanumDriveMotorVoltages(
- frontLeftOutput,
- frontRightOutput,
- rearLeftOutput,
- rearRightOutput));
+ m_outputDriveVoltages.accept(
+ new MecanumDriveMotorVoltages(
+ frontLeftOutput, frontRightOutput, rearLeftOutput, rearRightOutput));
} else {
- m_outputWheelSpeeds.accept(new MecanumDriveWheelSpeeds(
- frontLeftSpeedSetpoint,
- frontRightSpeedSetpoint,
- rearLeftSpeedSetpoint,
- rearRightSpeedSetpoint));
+ m_outputWheelSpeeds.accept(
+ new MecanumDriveWheelSpeeds(
+ frontLeftSpeedSetpoint,
+ frontRightSpeedSetpoint,
+ rearLeftSpeedSetpoint,
+ rearRightSpeedSetpoint));
}
m_prevTime = curTime;
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/NotifierCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/NotifierCommand.java
index e63fcc5..487aa12 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/NotifierCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/NotifierCommand.java
@@ -1,24 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.function.BooleanSupplier;
-
import edu.wpi.first.wpilibj.Notifier;
/**
- * A command that starts a notifier to run the given runnable periodically in a separate thread.
- * Has no end condition as-is; either subclass it or use {@link Command#withTimeout(double)} or
- * {@link Command#withInterrupt(BooleanSupplier)} to give it one.
+ * A command that starts a notifier to run the given runnable periodically in a separate thread. Has
+ * no end condition as-is; either subclass it or use {@link Command#withTimeout(double)} or {@link
+ * Command#withInterrupt(java.util.function.BooleanSupplier)} to give it one.
*
* <p>WARNING: Do not use this class unless you are confident in your ability to make the executed
- * code thread-safe. If you do not know what "thread-safe" means, that is a good sign that
- * you should not use this class.
+ * code thread-safe. If you do not know what "thread-safe" means, that is a good sign that you
+ * should not use this class.
*/
public class NotifierCommand extends CommandBase {
protected final Notifier m_notifier;
@@ -27,8 +22,8 @@
/**
* Creates a new NotifierCommand.
*
- * @param toRun the runnable for the notifier to run
- * @param period the period at which the notifier should run, in seconds
+ * @param toRun the runnable for the notifier to run
+ * @param period the period at which the notifier should run, in seconds
* @param requirements the subsystems required by this command
*/
public NotifierCommand(Runnable toRun, double period, Subsystem... requirements) {
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java
index 5f2b093..dcf8dec 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java
@@ -1,24 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+
+import edu.wpi.first.math.controller.PIDController;
import java.util.Set;
import java.util.function.DoubleConsumer;
import java.util.function.DoubleSupplier;
-import edu.wpi.first.wpilibj.controller.PIDController;
-
-import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-
/**
- * A command that controls an output with a {@link PIDController}. Runs forever by default - to add
- * exit conditions and/or other behavior, subclass this class. The controller calculation and
- * output are performed synchronously in the command's execute() method.
+ * A command that controls an output with a {@link PIDController}. Runs forever by default - to add
+ * exit conditions and/or other behavior, subclass this class. The controller calculation and output
+ * are performed synchronously in the command's execute() method.
*/
public class PIDCommand extends CommandBase {
protected final PIDController m_controller;
@@ -29,15 +25,18 @@
/**
* Creates a new PIDCommand, which controls the given output with a PIDController.
*
- * @param controller the controller that controls the output.
+ * @param controller the controller that controls the output.
* @param measurementSource the measurement of the process variable
- * @param setpointSource the controller's setpoint
- * @param useOutput the controller's output
- * @param requirements the subsystems required by this command
+ * @param setpointSource the controller's setpoint
+ * @param useOutput the controller's output
+ * @param requirements the subsystems required by this command
*/
- public PIDCommand(PIDController controller, DoubleSupplier measurementSource,
- DoubleSupplier setpointSource, DoubleConsumer useOutput,
- Subsystem... requirements) {
+ public PIDCommand(
+ PIDController controller,
+ DoubleSupplier measurementSource,
+ DoubleSupplier setpointSource,
+ DoubleConsumer useOutput,
+ Subsystem... requirements) {
requireNonNullParam(controller, "controller", "SynchronousPIDCommand");
requireNonNullParam(measurementSource, "measurementSource", "SynchronousPIDCommand");
requireNonNullParam(setpointSource, "setpointSource", "SynchronousPIDCommand");
@@ -53,15 +52,18 @@
/**
* Creates a new PIDCommand, which controls the given output with a PIDController.
*
- * @param controller the controller that controls the output.
+ * @param controller the controller that controls the output.
* @param measurementSource the measurement of the process variable
- * @param setpoint the controller's setpoint
- * @param useOutput the controller's output
- * @param requirements the subsystems required by this command
+ * @param setpoint the controller's setpoint
+ * @param useOutput the controller's output
+ * @param requirements the subsystems required by this command
*/
- public PIDCommand(PIDController controller, DoubleSupplier measurementSource,
- double setpoint, DoubleConsumer useOutput,
- Subsystem... requirements) {
+ public PIDCommand(
+ PIDController controller,
+ DoubleSupplier measurementSource,
+ double setpoint,
+ DoubleConsumer useOutput,
+ Subsystem... requirements) {
this(controller, measurementSource, () -> setpoint, useOutput, requirements);
}
@@ -72,8 +74,8 @@
@Override
public void execute() {
- m_useOutput.accept(m_controller.calculate(m_measurement.getAsDouble(),
- m_setpoint.getAsDouble()));
+ m_useOutput.accept(
+ m_controller.calculate(m_measurement.getAsDouble(), m_setpoint.getAsDouble()));
}
@Override
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDSubsystem.java
index 4cc578d..ad9bb77 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDSubsystem.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDSubsystem.java
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import edu.wpi.first.wpilibj.controller.PIDController;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import edu.wpi.first.math.controller.PIDController;
+
/**
- * A subsystem that uses a {@link PIDController} to control an output. The controller is run
+ * A subsystem that uses a {@link PIDController} to control an output. The controller is run
* synchronously from the subsystem's periodic() method.
*/
public abstract class PIDSubsystem extends SubsystemBase {
@@ -34,7 +31,7 @@
}
/**
- * Creates a new PIDSubsystem. Initial setpoint is zero.
+ * Creates a new PIDSubsystem. Initial setpoint is zero.
*
* @param controller the PIDController to use
*/
@@ -86,17 +83,13 @@
*/
protected abstract double getMeasurement();
- /**
- * Enables the PID control. Resets the controller.
- */
+ /** Enables the PID control. Resets the controller. */
public void enable() {
m_enabled = true;
m_controller.reset();
}
- /**
- * Disables the PID control. Sets output to zero.
- */
+ /** Disables the PID control. Sets output to zero. */
public void disable() {
m_enabled = false;
useOutput(0, 0);
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java
index 38cc3c1..7195606 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -17,14 +14,14 @@
* <p>As a rule, CommandGroups require the union of the requirements of their component commands.
*/
public class ParallelCommandGroup extends CommandGroupBase {
- //maps commands in this group to whether they are still running
+ // maps commands in this group to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
private boolean m_runWhenDisabled = true;
/**
- * Creates a new ParallelCommandGroup. The given commands will be executed simultaneously.
- * The command group will finish when the last command finishes. If the CommandGroup is
- * interrupted, only the commands that are still running will be interrupted.
+ * Creates a new ParallelCommandGroup. The given commands will be executed simultaneously. The
+ * command group will finish when the last command finishes. If the CommandGroup is interrupted,
+ * only the commands that are still running will be interrupted.
*
* @param commands the commands to include in this group.
*/
@@ -45,8 +42,8 @@
for (Command command : commands) {
if (!Collections.disjoint(command.getRequirements(), m_requirements)) {
- throw new IllegalArgumentException("Multiple commands in a parallel group cannot"
- + "require the same subsystems");
+ throw new IllegalArgumentException(
+ "Multiple commands in a parallel group cannot" + "require the same subsystems");
}
m_commands.put(command, false);
m_requirements.addAll(command.getRequirements());
@@ -89,11 +86,17 @@
@Override
public boolean isFinished() {
- return !m_commands.values().contains(true);
+ return !m_commands.containsValue(true);
}
@Override
public boolean runsWhenDisabled() {
return m_runWhenDisabled;
}
+
+ @Override
+ public ParallelCommandGroup alongWith(Command... parallel) {
+ addCommands(parallel);
+ return this;
+ }
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java
index 37be702..d444991 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -12,23 +9,23 @@
import java.util.Map;
/**
- * A CommandGroup that runs a set of commands in parallel, ending only when a specific command
- * (the "deadline") ends, interrupting all other commands that are still running at that point.
+ * A CommandGroup that runs a set of commands in parallel, ending only when a specific command (the
+ * "deadline") ends, interrupting all other commands that are still running at that point.
*
* <p>As a rule, CommandGroups require the union of the requirements of their component commands.
*/
public class ParallelDeadlineGroup extends CommandGroupBase {
- //maps commands in this group to whether they are still running
+ // maps commands in this group to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
private boolean m_runWhenDisabled = true;
private boolean m_finished = true;
private Command m_deadline;
/**
- * Creates a new ParallelDeadlineGroup. The given commands (including the deadline) will be
- * executed simultaneously. The CommandGroup will finish when the deadline finishes,
- * interrupting all other still-running commands. If the CommandGroup is interrupted, only
- * the commands still running will be interrupted.
+ * Creates a new ParallelDeadlineGroup. The given commands (including the deadline) will be
+ * executed simultaneously. The CommandGroup will finish when the deadline finishes, interrupting
+ * all other still-running commands. If the CommandGroup is interrupted, only the commands still
+ * running will be interrupted.
*
* @param deadline the command that determines when the group ends
* @param commands the commands to be executed
@@ -42,8 +39,8 @@
}
/**
- * Sets the deadline to the given command. The deadline is added to the group if it is not
- * already contained.
+ * Sets the deadline to the given command. The deadline is added to the group if it is not already
+ * contained.
*
* @param deadline the command that determines when the group ends
*/
@@ -67,8 +64,8 @@
for (Command command : commands) {
if (!Collections.disjoint(command.getRequirements(), m_requirements)) {
- throw new IllegalArgumentException("Multiple commands in a parallel group cannot"
- + "require the same subsystems");
+ throw new IllegalArgumentException(
+ "Multiple commands in a parallel group cannot" + "require the same subsystems");
}
m_commands.put(command, false);
m_requirements.addAll(command.getRequirements());
@@ -120,4 +117,10 @@
public boolean runsWhenDisabled() {
return m_runWhenDisabled;
}
+
+ @Override
+ public ParallelDeadlineGroup deadlineWith(Command... parallel) {
+ addCommands(parallel);
+ return this;
+ }
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java
index dcaf5f5..2d79885 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -23,8 +20,8 @@
private boolean m_finished = true;
/**
- * Creates a new ParallelCommandRace. The given commands will be executed simultaneously, and
- * will "race to the finish" - the first command to finish ends the entire command, with all other
+ * Creates a new ParallelCommandRace. The given commands will be executed simultaneously, and will
+ * "race to the finish" - the first command to finish ends the entire command, with all other
* commands being interrupted.
*
* @param commands the commands to include in this group.
@@ -46,8 +43,8 @@
for (Command command : commands) {
if (!Collections.disjoint(command.getRequirements(), m_requirements)) {
- throw new IllegalArgumentException("Multiple commands in a parallel group cannot"
- + " require the same subsystems");
+ throw new IllegalArgumentException(
+ "Multiple commands in a parallel group cannot" + " require the same subsystems");
}
m_commands.add(command);
m_requirements.addAll(command.getRequirements());
@@ -89,4 +86,10 @@
public boolean runsWhenDisabled() {
return m_runWhenDisabled;
}
+
+ @Override
+ public ParallelRaceGroup raceWith(Command... parallel) {
+ addCommands(parallel);
+ return this;
+ }
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PerpetualCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PerpetualCommand.java
index 6ebb376..af219dc 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PerpetualCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PerpetualCommand.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -11,7 +8,7 @@
import static edu.wpi.first.wpilibj2.command.CommandGroupBase.requireUngrouped;
/**
- * A command that runs another command in perpetuity, ignoring that command's end conditions. While
+ * A command that runs another command in perpetuity, ignoring that command's end conditions. While
* this class does not extend {@link CommandGroupBase}, it is still considered a CommandGroup, as it
* allows one to compose another command within it; the command instances that are passed to it
* cannot be added to any other groups, or scheduled individually.
@@ -22,8 +19,8 @@
protected final Command m_command;
/**
- * Creates a new PerpetualCommand. Will run another command in perpetuity, ignoring that
- * command's end conditions, unless this command itself is interrupted.
+ * Creates a new PerpetualCommand. Will run another command in perpetuity, ignoring that command's
+ * end conditions, unless this command itself is interrupted.
*
* @param command the command to run perpetually
*/
@@ -53,4 +50,9 @@
public boolean runsWhenDisabled() {
return m_command.runsWhenDisabled();
}
+
+ @Override
+ public PerpetualCommand perpetually() {
+ return this;
+ }
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PrintCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PrintCommand.java
index 4fb4126..33415d0 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PrintCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PrintCommand.java
@@ -1,15 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-/**
- * A command that prints a string when initialized.
- */
+/** A command that prints a string when initialized. */
public class PrintCommand extends InstantCommand {
/**
* Creates a new a PrintCommand.
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java
index 96e18a0..df56561 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java
@@ -1,26 +1,21 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import static edu.wpi.first.math.trajectory.TrapezoidProfile.State;
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+
+import edu.wpi.first.math.controller.ProfiledPIDController;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.DoubleSupplier;
import java.util.function.Supplier;
-import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
-
-import static edu.wpi.first.wpilibj.trajectory.TrapezoidProfile.State;
-import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-
/**
- * A command that controls an output with a {@link ProfiledPIDController}. Runs forever by
- * default - to add
- * exit conditions and/or other behavior, subclass this class. The controller calculation and
+ * A command that controls an output with a {@link ProfiledPIDController}. Runs forever by default -
+ * to add exit conditions and/or other behavior, subclass this class. The controller calculation and
* output are performed synchronously in the command's execute() method.
*/
public class ProfiledPIDCommand extends CommandBase {
@@ -30,18 +25,21 @@
protected BiConsumer<Double, State> m_useOutput;
/**
- * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController.
- * Goal velocity is specified.
+ * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal
+ * velocity is specified.
*
- * @param controller the controller that controls the output.
+ * @param controller the controller that controls the output.
* @param measurementSource the measurement of the process variable
- * @param goalSource the controller's goal
- * @param useOutput the controller's output
- * @param requirements the subsystems required by this command
+ * @param goalSource the controller's goal
+ * @param useOutput the controller's output
+ * @param requirements the subsystems required by this command
*/
- public ProfiledPIDCommand(ProfiledPIDController controller, DoubleSupplier measurementSource,
- Supplier<State> goalSource, BiConsumer<Double, State> useOutput,
- Subsystem... requirements) {
+ public ProfiledPIDCommand(
+ ProfiledPIDController controller,
+ DoubleSupplier measurementSource,
+ Supplier<State> goalSource,
+ BiConsumer<Double, State> useOutput,
+ Subsystem... requirements) {
requireNonNullParam(controller, "controller", "SynchronousPIDCommand");
requireNonNullParam(measurementSource, "measurementSource", "SynchronousPIDCommand");
requireNonNullParam(goalSource, "goalSource", "SynchronousPIDCommand");
@@ -55,18 +53,21 @@
}
/**
- * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController.
- * Goal velocity is implicitly zero.
+ * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal
+ * velocity is implicitly zero.
*
- * @param controller the controller that controls the output.
+ * @param controller the controller that controls the output.
* @param measurementSource the measurement of the process variable
- * @param goalSource the controller's goal
- * @param useOutput the controller's output
- * @param requirements the subsystems required by this command
+ * @param goalSource the controller's goal
+ * @param useOutput the controller's output
+ * @param requirements the subsystems required by this command
*/
- public ProfiledPIDCommand(ProfiledPIDController controller, DoubleSupplier measurementSource,
- DoubleSupplier goalSource, BiConsumer<Double, State> useOutput,
- Subsystem... requirements) {
+ public ProfiledPIDCommand(
+ ProfiledPIDController controller,
+ DoubleSupplier measurementSource,
+ DoubleSupplier goalSource,
+ BiConsumer<Double, State> useOutput,
+ Subsystem... requirements) {
requireNonNullParam(controller, "controller", "SynchronousPIDCommand");
requireNonNullParam(measurementSource, "measurementSource", "SynchronousPIDCommand");
requireNonNullParam(goalSource, "goalSource", "SynchronousPIDCommand");
@@ -83,15 +84,18 @@
* Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal
* velocity is specified.
*
- * @param controller the controller that controls the output.
+ * @param controller the controller that controls the output.
* @param measurementSource the measurement of the process variable
- * @param goal the controller's goal
- * @param useOutput the controller's output
- * @param requirements the subsystems required by this command
+ * @param goal the controller's goal
+ * @param useOutput the controller's output
+ * @param requirements the subsystems required by this command
*/
- public ProfiledPIDCommand(ProfiledPIDController controller, DoubleSupplier measurementSource,
- State goal, BiConsumer<Double, State> useOutput,
- Subsystem... requirements) {
+ public ProfiledPIDCommand(
+ ProfiledPIDController controller,
+ DoubleSupplier measurementSource,
+ State goal,
+ BiConsumer<Double, State> useOutput,
+ Subsystem... requirements) {
this(controller, measurementSource, () -> goal, useOutput, requirements);
}
@@ -99,15 +103,18 @@
* Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal
* velocity is implicitly zero.
*
- * @param controller the controller that controls the output.
+ * @param controller the controller that controls the output.
* @param measurementSource the measurement of the process variable
- * @param goal the controller's goal
- * @param useOutput the controller's output
- * @param requirements the subsystems required by this command
+ * @param goal the controller's goal
+ * @param useOutput the controller's output
+ * @param requirements the subsystems required by this command
*/
- public ProfiledPIDCommand(ProfiledPIDController controller, DoubleSupplier measurementSource,
- double goal, BiConsumer<Double, State> useOutput,
- Subsystem... requirements) {
+ public ProfiledPIDCommand(
+ ProfiledPIDController controller,
+ DoubleSupplier measurementSource,
+ double goal,
+ BiConsumer<Double, State> useOutput,
+ Subsystem... requirements) {
this(controller, measurementSource, () -> goal, useOutput, requirements);
}
@@ -118,8 +125,9 @@
@Override
public void execute() {
- m_useOutput.accept(m_controller.calculate(m_measurement.getAsDouble(), m_goal.get()),
- m_controller.getSetpoint());
+ m_useOutput.accept(
+ m_controller.calculate(m_measurement.getAsDouble(), m_goal.get()),
+ m_controller.getSetpoint());
}
@Override
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java
index 2385ada..85ece1f 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java
@@ -1,21 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
-import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
-
-import static edu.wpi.first.wpilibj.trajectory.TrapezoidProfile.State;
+import static edu.wpi.first.math.trajectory.TrapezoidProfile.State;
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import edu.wpi.first.math.controller.ProfiledPIDController;
+import edu.wpi.first.math.trajectory.TrapezoidProfile;
+
/**
- * A subsystem that uses a {@link ProfiledPIDController} to control an output. The controller is
- * run synchronously from the subsystem's periodic() method.
+ * A subsystem that uses a {@link ProfiledPIDController} to control an output. The controller is run
+ * synchronously from the subsystem's periodic() method.
*/
public abstract class ProfiledPIDSubsystem extends SubsystemBase {
protected final ProfiledPIDController m_controller;
@@ -29,14 +26,13 @@
* @param controller the ProfiledPIDController to use
* @param initialPosition the initial goal position of the controller
*/
- public ProfiledPIDSubsystem(ProfiledPIDController controller,
- double initialPosition) {
+ public ProfiledPIDSubsystem(ProfiledPIDController controller, double initialPosition) {
m_controller = requireNonNullParam(controller, "controller", "ProfiledPIDSubsystem");
setGoal(initialPosition);
}
/**
- * Creates a new ProfiledPIDSubsystem. Initial goal position is zero.
+ * Creates a new ProfiledPIDSubsystem. Initial goal position is zero.
*
* @param controller the ProfiledPIDController to use
*/
@@ -65,7 +61,7 @@
}
/**
- * Sets the goal state for the subsystem. Goal velocity assumed to be zero.
+ * Sets the goal state for the subsystem. Goal velocity assumed to be zero.
*
* @param goal The goal position for the subsystem's motion profile.
*/
@@ -76,7 +72,7 @@
/**
* Uses the output from the ProfiledPIDController.
*
- * @param output the output of the ProfiledPIDController
+ * @param output the output of the ProfiledPIDController
* @param setpoint the setpoint state of the ProfiledPIDController, for feedforward
*/
protected abstract void useOutput(double output, State setpoint);
@@ -88,17 +84,13 @@
*/
protected abstract double getMeasurement();
- /**
- * Enables the PID control. Resets the controller.
- */
+ /** Enables the PID control. Resets the controller. */
public void enable() {
m_enabled = true;
m_controller.reset(getMeasurement());
}
- /**
- * Disables the PID control. Sets output to zero.
- */
+ /** Disables the PID control. Sets output to zero. */
public void disable() {
m_enabled = false;
useOutput(0, new State());
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommand.java
index 27d67bc..ae403a4 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommand.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -11,7 +8,7 @@
/**
* Schedules the given commands when this command is initialized, and ends when all the commands are
- * no longer scheduled. Useful for forking off from CommandGroups. If this command is interrupted,
+ * no longer scheduled. Useful for forking off from CommandGroups. If this command is interrupted,
* it will cancel all of the commands.
*/
public class ProxyScheduleCommand extends CommandBase {
@@ -19,8 +16,8 @@
private boolean m_finished;
/**
- * Creates a new ProxyScheduleCommand that schedules the given commands when initialized,
- * and ends when they are all no longer scheduled.
+ * Creates a new ProxyScheduleCommand that schedules the given commands when initialized, and ends
+ * when they are all no longer scheduled.
*
* @param toSchedule the commands to schedule
*/
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java
index c6a2b4c..8d8d4d3 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java
@@ -1,41 +1,35 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+
+import edu.wpi.first.math.controller.PIDController;
+import edu.wpi.first.math.controller.RamseteController;
+import edu.wpi.first.math.controller.SimpleMotorFeedforward;
+import edu.wpi.first.math.geometry.Pose2d;
+import edu.wpi.first.math.kinematics.ChassisSpeeds;
+import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;
+import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds;
+import edu.wpi.first.math.trajectory.Trajectory;
+import edu.wpi.first.wpilibj.Timer;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.controller.PIDController;
-import edu.wpi.first.wpilibj.controller.RamseteController;
-import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward;
-import edu.wpi.first.wpilibj.geometry.Pose2d;
-import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds;
-import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics;
-import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds;
-import edu.wpi.first.wpilibj.trajectory.Trajectory;
-
-import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-
/**
* A command that uses a RAMSETE controller ({@link RamseteController}) to follow a trajectory
* {@link Trajectory} with a differential drive.
*
- * <p>The command handles trajectory-following, PID calculations, and feedforwards internally. This
+ * <p>The command handles trajectory-following, PID calculations, and feedforwards internally. This
* is intended to be a more-or-less "complete solution" that can be used by teams without a great
* deal of controls expertise.
*
- * <p>Advanced teams seeking more flexibility (for example, those who wish to use the onboard
- * PID functionality of a "smart" motor controller) may use the secondary constructor that omits
- * the PID and feedforward functionality, returning only the raw wheel speeds from the RAMSETE
- * controller.
+ * <p>Advanced teams seeking more flexibility (for example, those who wish to use the onboard PID
+ * functionality of a "smart" motor controller) may use the secondary constructor that omits the PID
+ * and feedforward functionality, returning only the raw wheel speeds from the RAMSETE controller.
*/
-@SuppressWarnings("PMD.TooManyFields")
public class RamseteCommand extends CommandBase {
private final Timer m_timer = new Timer();
private final boolean m_usePID;
@@ -52,39 +46,38 @@
private double m_prevTime;
/**
- * Constructs a new RamseteCommand that, when executed, will follow the provided trajectory.
- * PID control and feedforward are handled internally, and outputs are scaled -12 to 12
- * representing units of volts.
+ * Constructs a new RamseteCommand that, when executed, will follow the provided trajectory. PID
+ * control and feedforward are handled internally, and outputs are scaled -12 to 12 representing
+ * units of volts.
*
* <p>Note: The controller will *not* set the outputVolts to zero upon completion of the path -
- * this
- * is left to the user, since it is not appropriate for paths with nonstationary endstates.
+ * this is left to the user, since it is not appropriate for paths with nonstationary endstates.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param controller The RAMSETE controller used to follow the trajectory.
- * @param feedforward The feedforward to use for the drive.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param wheelSpeeds A function that supplies the speeds of the left and
- * right sides of the robot drive.
- * @param leftController The PIDController for the left side of the robot drive.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param controller The RAMSETE controller used to follow the trajectory.
+ * @param feedforward The feedforward to use for the drive.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param wheelSpeeds A function that supplies the speeds of the left and right sides of the robot
+ * drive.
+ * @param leftController The PIDController for the left side of the robot drive.
* @param rightController The PIDController for the right side of the robot drive.
- * @param outputVolts A function that consumes the computed left and right
- * outputs (in volts) for the robot drive.
- * @param requirements The subsystems to require.
+ * @param outputVolts A function that consumes the computed left and right outputs (in volts) for
+ * the robot drive.
+ * @param requirements The subsystems to require.
*/
- @SuppressWarnings("PMD.ExcessiveParameterList")
- public RamseteCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- RamseteController controller,
- SimpleMotorFeedforward feedforward,
- DifferentialDriveKinematics kinematics,
- Supplier<DifferentialDriveWheelSpeeds> wheelSpeeds,
- PIDController leftController,
- PIDController rightController,
- BiConsumer<Double, Double> outputVolts,
- Subsystem... requirements) {
+ public RamseteCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ RamseteController controller,
+ SimpleMotorFeedforward feedforward,
+ DifferentialDriveKinematics kinematics,
+ Supplier<DifferentialDriveWheelSpeeds> wheelSpeeds,
+ PIDController leftController,
+ PIDController rightController,
+ BiConsumer<Double, Double> outputVolts,
+ Subsystem... requirements) {
m_trajectory = requireNonNullParam(trajectory, "trajectory", "RamseteCommand");
m_pose = requireNonNullParam(pose, "pose", "RamseteCommand");
m_follower = requireNonNullParam(controller, "controller", "RamseteCommand");
@@ -102,24 +95,24 @@
/**
* Constructs a new RamseteCommand that, when executed, will follow the provided trajectory.
- * Performs no PID control and calculates no feedforwards; outputs are the raw wheel speeds
- * from the RAMSETE controller, and will need to be converted into a usable form by the user.
+ * Performs no PID control and calculates no feedforwards; outputs are the raw wheel speeds from
+ * the RAMSETE controller, and will need to be converted into a usable form by the user.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param follower The RAMSETE follower used to follow the trajectory.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param outputMetersPerSecond A function that consumes the computed left and right
- * wheel speeds.
- * @param requirements The subsystems to require.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param follower The RAMSETE follower used to follow the trajectory.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param outputMetersPerSecond A function that consumes the computed left and right wheel speeds.
+ * @param requirements The subsystems to require.
*/
- public RamseteCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- RamseteController follower,
- DifferentialDriveKinematics kinematics,
- BiConsumer<Double, Double> outputMetersPerSecond,
- Subsystem... requirements) {
+ public RamseteCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ RamseteController follower,
+ DifferentialDriveKinematics kinematics,
+ BiConsumer<Double, Double> outputMetersPerSecond,
+ Subsystem... requirements) {
m_trajectory = requireNonNullParam(trajectory, "trajectory", "RamseteCommand");
m_pose = requireNonNullParam(pose, "pose", "RamseteCommand");
m_follower = requireNonNullParam(follower, "follower", "RamseteCommand");
@@ -138,13 +131,14 @@
@Override
public void initialize() {
- m_prevTime = 0;
+ m_prevTime = -1;
var initialState = m_trajectory.sample(0);
- m_prevSpeeds = m_kinematics.toWheelSpeeds(
- new ChassisSpeeds(initialState.velocityMetersPerSecond,
- 0,
- initialState.curvatureRadPerMeter
- * initialState.velocityMetersPerSecond));
+ m_prevSpeeds =
+ m_kinematics.toWheelSpeeds(
+ new ChassisSpeeds(
+ initialState.velocityMetersPerSecond,
+ 0,
+ initialState.curvatureRadPerMeter * initialState.velocityMetersPerSecond));
m_timer.reset();
m_timer.start();
if (m_usePID) {
@@ -158,8 +152,15 @@
double curTime = m_timer.get();
double dt = curTime - m_prevTime;
- var targetWheelSpeeds = m_kinematics.toWheelSpeeds(
- m_follower.calculate(m_pose.get(), m_trajectory.sample(curTime)));
+ if (m_prevTime < 0) {
+ m_output.accept(0.0, 0.0);
+ m_prevTime = curTime;
+ return;
+ }
+
+ var targetWheelSpeeds =
+ m_kinematics.toWheelSpeeds(
+ m_follower.calculate(m_pose.get(), m_trajectory.sample(curTime)));
var leftSpeedSetpoint = targetWheelSpeeds.leftMetersPerSecond;
var rightSpeedSetpoint = targetWheelSpeeds.rightMetersPerSecond;
@@ -169,34 +170,38 @@
if (m_usePID) {
double leftFeedforward =
- m_feedforward.calculate(leftSpeedSetpoint,
- (leftSpeedSetpoint - m_prevSpeeds.leftMetersPerSecond) / dt);
+ m_feedforward.calculate(
+ leftSpeedSetpoint, (leftSpeedSetpoint - m_prevSpeeds.leftMetersPerSecond) / dt);
double rightFeedforward =
- m_feedforward.calculate(rightSpeedSetpoint,
- (rightSpeedSetpoint - m_prevSpeeds.rightMetersPerSecond) / dt);
+ m_feedforward.calculate(
+ rightSpeedSetpoint, (rightSpeedSetpoint - m_prevSpeeds.rightMetersPerSecond) / dt);
- leftOutput = leftFeedforward
- + m_leftController.calculate(m_speeds.get().leftMetersPerSecond,
- leftSpeedSetpoint);
+ leftOutput =
+ leftFeedforward
+ + m_leftController.calculate(m_speeds.get().leftMetersPerSecond, leftSpeedSetpoint);
- rightOutput = rightFeedforward
- + m_rightController.calculate(m_speeds.get().rightMetersPerSecond,
- rightSpeedSetpoint);
+ rightOutput =
+ rightFeedforward
+ + m_rightController.calculate(
+ m_speeds.get().rightMetersPerSecond, rightSpeedSetpoint);
} else {
leftOutput = leftSpeedSetpoint;
rightOutput = rightSpeedSetpoint;
}
m_output.accept(leftOutput, rightOutput);
-
- m_prevTime = curTime;
m_prevSpeeds = targetWheelSpeeds;
+ m_prevTime = curTime;
}
@Override
public void end(boolean interrupted) {
m_timer.stop();
+
+ if (interrupted) {
+ m_output.accept(0.0, 0.0);
+ }
}
@Override
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RunCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RunCommand.java
index 9099be0..e1a7296 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RunCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RunCommand.java
@@ -1,30 +1,26 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.function.BooleanSupplier;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import java.util.function.BooleanSupplier;
+
/**
- * A command that runs a Runnable continuously. Has no end condition as-is;
- * either subclass it or use {@link Command#withTimeout(double)} or
- * {@link Command#withInterrupt(BooleanSupplier)} to give it one. If you only wish
- * to execute a Runnable once, use {@link InstantCommand}.
+ * A command that runs a Runnable continuously. Has no end condition as-is; either subclass it or
+ * use {@link Command#withTimeout(double)} or {@link Command#withInterrupt(BooleanSupplier)} to give
+ * it one. If you only wish to execute a Runnable once, use {@link InstantCommand}.
*/
public class RunCommand extends CommandBase {
protected final Runnable m_toRun;
/**
- * Creates a new RunCommand. The Runnable will be run continuously until the command
- * ends. Does not run when disabled.
+ * Creates a new RunCommand. The Runnable will be run continuously until the command ends. Does
+ * not run when disabled.
*
- * @param toRun the Runnable to run
+ * @param toRun the Runnable to run
* @param requirements the subsystems to require
*/
public RunCommand(Runnable toRun, Subsystem... requirements) {
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ScheduleCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ScheduleCommand.java
index 700925b..75b5774 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ScheduleCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ScheduleCommand.java
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
import java.util.Set;
/**
- * Schedules the given commands when this command is initialized. Useful for forking off from
- * CommandGroups. Note that if run from a CommandGroup, the group will not know about the status
- * of the scheduled commands, and will treat this command as finishing instantly.
+ * Schedules the given commands when this command is initialized. Useful for forking off from
+ * CommandGroups. Note that if run from a CommandGroup, the group will not know about the status of
+ * the scheduled commands, and will treat this command as finishing instantly.
*/
public class ScheduleCommand extends CommandBase {
private final Set<Command> m_toSchedule;
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SelectCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SelectCommand.java
index 92fe07f..a5c8859 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SelectCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SelectCommand.java
@@ -1,24 +1,21 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.Map;
-import java.util.function.Supplier;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import static edu.wpi.first.wpilibj2.command.CommandGroupBase.requireUngrouped;
+import java.util.Map;
+import java.util.function.Supplier;
+
/**
* Runs one of a selection of commands, either using a selector and a key to command mapping, or a
- * supplier that returns the command directly at runtime. Does not actually schedule the selected
+ * supplier that returns the command directly at runtime. Does not actually schedule the selected
* command - rather, the command is run through this command; this ensures that the command will
- * behave as expected if used as part of a CommandGroup. Requires the requirements of all included
- * commands, again to ensure proper functioning when used in a CommandGroup. If this is undesired,
+ * behave as expected if used as part of a CommandGroup. Requires the requirements of all included
+ * commands, again to ensure proper functioning when used in a CommandGroup. If this is undesired,
* consider using {@link ScheduleCommand}.
*
* <p>As this command contains multiple component commands within it, it is technically a command
@@ -42,7 +39,7 @@
public SelectCommand(Map<Object, Command> commands, Supplier<Object> selector) {
requireUngrouped(commands.values());
- CommandGroupBase.registerGroupedCommands(commands.values().toArray(new Command[]{}));
+ CommandGroupBase.registerGroupedCommands(commands.values().toArray(new Command[] {}));
m_commands = requireNonNullParam(commands, "commands", "SelectCommand");
m_selector = requireNonNullParam(selector, "selector", "SelectCommand");
@@ -69,8 +66,9 @@
public void initialize() {
if (m_selector != null) {
if (!m_commands.keySet().contains(m_selector.get())) {
- m_selectedCommand = new PrintCommand(
- "SelectCommand selector value does not correspond to" + " any command!");
+ m_selectedCommand =
+ new PrintCommand(
+ "SelectCommand selector value does not correspond to" + " any command!");
return;
}
m_selectedCommand = m_commands.get(m_selector.get());
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java
index 0d01f11..38dff8d 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroup.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
@@ -21,8 +18,8 @@
private boolean m_runWhenDisabled = true;
/**
- * Creates a new SequentialCommandGroup. The given commands will be run sequentially, with
- * the CommandGroup finishing when the last command finishes.
+ * Creates a new SequentialCommandGroup. The given commands will be run sequentially, with the
+ * CommandGroup finishing when the last command finishes.
*
* @param commands the commands to include in this group.
*/
@@ -77,9 +74,10 @@
@Override
public void end(boolean interrupted) {
- if (interrupted && !m_commands.isEmpty() && m_currentCommandIndex > -1
- && m_currentCommandIndex < m_commands.size()
- ) {
+ if (interrupted
+ && !m_commands.isEmpty()
+ && m_currentCommandIndex > -1
+ && m_currentCommandIndex < m_commands.size()) {
m_commands.get(m_currentCommandIndex).end(true);
}
m_currentCommandIndex = -1;
@@ -94,4 +92,28 @@
public boolean runsWhenDisabled() {
return m_runWhenDisabled;
}
+
+ @Override
+ public SequentialCommandGroup beforeStarting(Command before) {
+ // store all the commands
+ var commands = new ArrayList<Command>();
+ commands.add(before);
+ commands.addAll(m_commands);
+
+ // reset current state
+ commands.forEach(CommandGroupBase::clearGroupedCommand);
+ m_commands.clear();
+ m_requirements.clear();
+ m_runWhenDisabled = true;
+
+ // add them back
+ addCommands(commands.toArray(Command[]::new));
+ return this;
+ }
+
+ @Override
+ public SequentialCommandGroup andThen(Command... next) {
+ addCommands(next);
+ return this;
+ }
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/StartEndCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/StartEndCommand.java
index 9029135..05e46cb 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/StartEndCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/StartEndCommand.java
@@ -1,32 +1,27 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.function.BooleanSupplier;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
/**
* A command that runs a given runnable when it is initialized, and another runnable when it ends.
- * Useful for running and then stopping a motor, or extending and then retracting a solenoid.
- * Has no end condition as-is; either subclass it or use {@link Command#withTimeout(double)} or
- * {@link Command#withInterrupt(BooleanSupplier)} to give it one.
+ * Useful for running and then stopping a motor, or extending and then retracting a solenoid. Has no
+ * end condition as-is; either subclass it or use {@link Command#withTimeout(double)} or {@link
+ * Command#withInterrupt(java.util.function.BooleanSupplier)} to give it one.
*/
public class StartEndCommand extends CommandBase {
protected final Runnable m_onInit;
protected final Runnable m_onEnd;
/**
- * Creates a new StartEndCommand. Will run the given runnables when the command starts and when
- * it ends.
+ * Creates a new StartEndCommand. Will run the given runnables when the command starts and when it
+ * ends.
*
- * @param onInit the Runnable to run on command init
- * @param onEnd the Runnable to run on command end
+ * @param onInit the Runnable to run on command init
+ * @param onEnd the Runnable to run on command end
* @param requirements the subsystems required by this command
*/
public StartEndCommand(Runnable onInit, Runnable onEnd, Subsystem... requirements) {
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java
index e693d87..4e28b16 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Subsystem.java
@@ -1,52 +1,46 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
/**
- * A robot subsystem. Subsystems are the basic unit of robot organization in the Command-based
+ * A robot subsystem. Subsystems are the basic unit of robot organization in the Command-based
* framework; they encapsulate low-level hardware objects (motor controllers, sensors, etc) and
- * provide methods through which they can be used by {@link Command}s. Subsystems are used by the
+ * provide methods through which they can be used by {@link Command}s. Subsystems are used by the
* {@link CommandScheduler}'s resource management system to ensure multiple robot actions are not
- * "fighting" over the same hardware; Commands that use a subsystem should include that subsystem
- * in their {@link Command#getRequirements()} method, and resources used within a subsystem should
+ * "fighting" over the same hardware; Commands that use a subsystem should include that subsystem in
+ * their {@link Command#getRequirements()} method, and resources used within a subsystem should
* generally remain encapsulated and not be shared by other parts of the robot.
*
- * <p>Subsystems must be registered with the scheduler with the
- * {@link CommandScheduler#registerSubsystem(Subsystem...)} method in order for the
- * {@link Subsystem#periodic()} method to be called. It is recommended that this method be called
- * from the constructor of users' Subsystem implementations. The {@link SubsystemBase}
- * class offers a simple base for user implementations that handles this.
+ * <p>Subsystems must be registered with the scheduler with the {@link
+ * CommandScheduler#registerSubsystem(Subsystem...)} method in order for the {@link
+ * Subsystem#periodic()} method to be called. It is recommended that this method be called from the
+ * constructor of users' Subsystem implementations. The {@link SubsystemBase} class offers a simple
+ * base for user implementations that handles this.
*/
public interface Subsystem {
-
/**
- * This method is called periodically by the {@link CommandScheduler}. Useful for updating
- * subsystem-specific state that you don't want to offload to a {@link Command}. Teams should
- * try to be consistent within their own codebases about which responsibilities will be handled
- * by Commands, and which will be handled here.
+ * This method is called periodically by the {@link CommandScheduler}. Useful for updating
+ * subsystem-specific state that you don't want to offload to a {@link Command}. Teams should try
+ * to be consistent within their own codebases about which responsibilities will be handled by
+ * Commands, and which will be handled here.
*/
- default void periodic() {
- }
+ default void periodic() {}
/**
- * This method is called periodically by the {@link CommandScheduler}. Useful for updating
+ * This method is called periodically by the {@link CommandScheduler}. Useful for updating
* subsystem-specific state that needs to be maintained for simulations, such as for updating
* {@link edu.wpi.first.wpilibj.simulation} classes and setting simulated sensor readings.
*/
- default void simulationPeriodic() {
- }
+ default void simulationPeriodic() {}
/**
- * Sets the default {@link Command} of the subsystem. The default command will be
- * automatically scheduled when no other commands are scheduled that require the subsystem.
- * Default commands should generally not end on their own, i.e. their {@link Command#isFinished()}
- * method should always return false. Will automatically register this subsystem with the
- * {@link CommandScheduler}.
+ * Sets the default {@link Command} of the subsystem. The default command will be automatically
+ * scheduled when no other commands are scheduled that require the subsystem. Default commands
+ * should generally not end on their own, i.e. their {@link Command#isFinished()} method should
+ * always return false. Will automatically register this subsystem with the {@link
+ * CommandScheduler}.
*
* @param defaultCommand the default command to associate with this subsystem
*/
@@ -55,8 +49,8 @@
}
/**
- * Gets the default command for this subsystem. Returns null if no default command is
- * currently associated with the subsystem.
+ * Gets the default command for this subsystem. Returns null if no default command is currently
+ * associated with the subsystem.
*
* @return the default command associated with this subsystem
*/
@@ -65,7 +59,7 @@
}
/**
- * Returns the command currently running on this subsystem. Returns null if no command is
+ * Returns the command currently running on this subsystem. Returns null if no command is
* currently scheduled that requires this subsystem.
*
* @return the scheduled command currently requiring this subsystem
@@ -75,8 +69,8 @@
}
/**
- * Registers this subsystem with the {@link CommandScheduler}, allowing its
- * {@link Subsystem#periodic()} method to be called when the scheduler runs.
+ * Registers this subsystem with the {@link CommandScheduler}, allowing its {@link
+ * Subsystem#periodic()} method to be called when the scheduler runs.
*/
default void register() {
CommandScheduler.getInstance().registerSubsystem(this);
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java
index e22a5c4..c685803 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java
@@ -1,25 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import edu.wpi.first.wpilibj.Sendable;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
-import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
+import edu.wpi.first.util.sendable.Sendable;
+import edu.wpi.first.util.sendable.SendableBuilder;
+import edu.wpi.first.util.sendable.SendableRegistry;
/**
* A base for subsystems that handles registration in the constructor, and provides a more intuitive
* method for setting the default command.
*/
public abstract class SubsystemBase implements Subsystem, Sendable {
-
- /**
- * Constructor.
- */
+ /** Constructor. */
public SubsystemBase() {
String name = this.getClass().getSimpleName();
name = name.substring(name.lastIndexOf('.') + 1);
@@ -32,7 +26,6 @@
*
* @return Name
*/
- @Override
public String getName() {
return SendableRegistry.getName(this);
}
@@ -42,7 +35,6 @@
*
* @param name name
*/
- @Override
public void setName(String name) {
SendableRegistry.setName(this, name);
}
@@ -52,7 +44,6 @@
*
* @return Subsystem name
*/
- @Override
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
@@ -62,14 +53,12 @@
*
* @param subsystem subsystem name
*/
- @Override
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
/**
- * Associates a {@link Sendable} with this Subsystem.
- * Also update the child's name.
+ * Associates a {@link Sendable} with this Subsystem. Also update the child's name.
*
* @param name name to give child
* @param child sendable
@@ -83,10 +72,14 @@
builder.setSmartDashboardType("Subsystem");
builder.addBooleanProperty(".hasDefault", () -> getDefaultCommand() != null, null);
- builder.addStringProperty(".default",
- () -> getDefaultCommand() != null ? getDefaultCommand().getName() : "none", null);
+ builder.addStringProperty(
+ ".default",
+ () -> getDefaultCommand() != null ? getDefaultCommand().getName() : "none",
+ null);
builder.addBooleanProperty(".hasCommand", () -> getCurrentCommand() != null, null);
- builder.addStringProperty(".command",
- () -> getCurrentCommand() != null ? getCurrentCommand().getName() : "none", null);
+ builder.addStringProperty(
+ ".command",
+ () -> getCurrentCommand() != null ? getCurrentCommand().getName() : "none",
+ null);
}
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java
index c0303b9..95b42ee 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java
@@ -1,40 +1,34 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+
+import edu.wpi.first.math.controller.HolonomicDriveController;
+import edu.wpi.first.math.controller.PIDController;
+import edu.wpi.first.math.controller.ProfiledPIDController;
+import edu.wpi.first.math.geometry.Pose2d;
+import edu.wpi.first.math.geometry.Rotation2d;
+import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
+import edu.wpi.first.math.kinematics.SwerveModuleState;
+import edu.wpi.first.math.trajectory.Trajectory;
+import edu.wpi.first.wpilibj.Timer;
import java.util.function.Consumer;
import java.util.function.Supplier;
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.controller.HolonomicDriveController;
-import edu.wpi.first.wpilibj.controller.PIDController;
-import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
-import edu.wpi.first.wpilibj.geometry.Pose2d;
-import edu.wpi.first.wpilibj.geometry.Rotation2d;
-import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics;
-import edu.wpi.first.wpilibj.kinematics.SwerveModuleState;
-import edu.wpi.first.wpilibj.trajectory.Trajectory;
-
-import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-
/**
- * A command that uses two PID controllers ({@link PIDController}) and a
- * ProfiledPIDController ({@link ProfiledPIDController}) to follow a trajectory
- * {@link Trajectory} with a swerve drive.
+ * A command that uses two PID controllers ({@link PIDController}) and a ProfiledPIDController
+ * ({@link ProfiledPIDController}) to follow a trajectory {@link Trajectory} with a swerve drive.
*
- * <p>This command outputs the raw desired Swerve Module States ({@link SwerveModuleState})
- * in an array. The desired wheel and module rotation velocities should be taken
- * from those and used in velocity PIDs.
+ * <p>This command outputs the raw desired Swerve Module States ({@link SwerveModuleState}) in an
+ * array. The desired wheel and module rotation velocities should be taken from those and used in
+ * velocity PIDs.
*
- * <p>The robot angle controller does not follow the angle given by
- * the trajectory but rather goes to the angle given in the final state of the trajectory.
+ * <p>The robot angle controller does not follow the angle given by the trajectory but rather goes
+ * to the angle given in the final state of the trajectory.
*/
-
@SuppressWarnings("MemberName")
public class SwerveControllerCommand extends CommandBase {
private final Timer m_timer = new Timer();
@@ -53,50 +47,44 @@
* <p>Note: The controllers will *not* set the outputVolts to zero upon completion of the path-
* this is left to the user, since it is not appropriate for paths with nonstationary endstates.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param desiredRotation The angle that the drivetrain should be facing. This
- * is sampled at each time step.
- * @param outputModuleStates The raw output module states from the
- * position controllers.
- * @param requirements The subsystems to require.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param xController The Trajectory Tracker PID controller for the robot's x position.
+ * @param yController The Trajectory Tracker PID controller for the robot's y position.
+ * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
+ * @param desiredRotation The angle that the drivetrain should be facing. This is sampled at each
+ * time step.
+ * @param outputModuleStates The raw output module states from the position controllers.
+ * @param requirements The subsystems to require.
*/
@SuppressWarnings("ParameterName")
- public SwerveControllerCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- SwerveDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Supplier<Rotation2d> desiredRotation,
- Consumer<SwerveModuleState[]> outputModuleStates,
- Subsystem... requirements) {
+ public SwerveControllerCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ SwerveDriveKinematics kinematics,
+ PIDController xController,
+ PIDController yController,
+ ProfiledPIDController thetaController,
+ Supplier<Rotation2d> desiredRotation,
+ Consumer<SwerveModuleState[]> outputModuleStates,
+ Subsystem... requirements) {
m_trajectory = requireNonNullParam(trajectory, "trajectory", "SwerveControllerCommand");
m_pose = requireNonNullParam(pose, "pose", "SwerveControllerCommand");
m_kinematics = requireNonNullParam(kinematics, "kinematics", "SwerveControllerCommand");
- m_controller = new HolonomicDriveController(
- requireNonNullParam(xController,
- "xController", "SwerveControllerCommand"),
- requireNonNullParam(yController,
- "xController", "SwerveControllerCommand"),
- requireNonNullParam(thetaController,
- "thetaController", "SwerveControllerCommand")
- );
+ m_controller =
+ new HolonomicDriveController(
+ requireNonNullParam(xController, "xController", "SwerveControllerCommand"),
+ requireNonNullParam(yController, "xController", "SwerveControllerCommand"),
+ requireNonNullParam(thetaController, "thetaController", "SwerveControllerCommand"));
- m_outputModuleStates = requireNonNullParam(outputModuleStates,
- "frontLeftOutput", "SwerveControllerCommand");
+ m_outputModuleStates =
+ requireNonNullParam(outputModuleStates, "frontLeftOutput", "SwerveControllerCommand");
- m_desiredRotation = requireNonNullParam(desiredRotation, "desiredRotation",
- "SwerveControllerCommand");
+ m_desiredRotation =
+ requireNonNullParam(desiredRotation, "desiredRotation", "SwerveControllerCommand");
addRequirements(requirements);
}
@@ -109,38 +97,42 @@
* <p>Note: The controllers will *not* set the outputVolts to zero upon completion of the path-
* this is left to the user, since it is not appropriate for paths with nonstationary endstates.
*
- * <p>Note 2: The final rotation of the robot will be set to the rotation of
- * the final pose in the trajectory. The robot will not follow the rotations
- * from the poses at each timestep. If alternate rotation behavior is desired,
- * the other constructor with a supplier for rotation should be used.
+ * <p>Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
+ * trajectory. The robot will not follow the rotations from the poses at each timestep. If
+ * alternate rotation behavior is desired, the other constructor with a supplier for rotation
+ * should be used.
*
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of
- * the odometry classes to provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param outputModuleStates The raw output module states from the
- * position controllers.
- * @param requirements The subsystems to require.
+ * @param trajectory The trajectory to follow.
+ * @param pose A function that supplies the robot pose - use one of the odometry classes to
+ * provide this.
+ * @param kinematics The kinematics for the robot drivetrain.
+ * @param xController The Trajectory Tracker PID controller for the robot's x position.
+ * @param yController The Trajectory Tracker PID controller for the robot's y position.
+ * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
+ * @param outputModuleStates The raw output module states from the position controllers.
+ * @param requirements The subsystems to require.
*/
@SuppressWarnings("ParameterName")
- public SwerveControllerCommand(Trajectory trajectory,
- Supplier<Pose2d> pose,
- SwerveDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Consumer<SwerveModuleState[]> outputModuleStates,
- Subsystem... requirements) {
- this(trajectory, pose, kinematics, xController, yController, thetaController,
- () -> trajectory.getStates().get(trajectory.getStates().size() - 1)
- .poseMeters.getRotation(),
- outputModuleStates, requirements);
+ public SwerveControllerCommand(
+ Trajectory trajectory,
+ Supplier<Pose2d> pose,
+ SwerveDriveKinematics kinematics,
+ PIDController xController,
+ PIDController yController,
+ ProfiledPIDController thetaController,
+ Consumer<SwerveModuleState[]> outputModuleStates,
+ Subsystem... requirements) {
+ this(
+ trajectory,
+ pose,
+ kinematics,
+ xController,
+ yController,
+ thetaController,
+ () ->
+ trajectory.getStates().get(trajectory.getStates().size() - 1).poseMeters.getRotation(),
+ outputModuleStates,
+ requirements);
}
@Override
@@ -155,8 +147,8 @@
double curTime = m_timer.get();
var desiredState = m_trajectory.sample(curTime);
- var targetChassisSpeeds = m_controller.calculate(m_pose.get(), desiredState,
- m_desiredRotation.get());
+ var targetChassisSpeeds =
+ m_controller.calculate(m_pose.get(), desiredState, m_desiredRotation.get());
var targetModuleStates = m_kinematics.toSwerveModuleStates(targetChassisSpeeds);
m_outputModuleStates.accept(targetModuleStates);
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java
index 0e645c6..674328e 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java
@@ -1,23 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.function.Consumer;
-
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
-
-import static edu.wpi.first.wpilibj.trajectory.TrapezoidProfile.State;
+import static edu.wpi.first.math.trajectory.TrapezoidProfile.State;
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import edu.wpi.first.math.trajectory.TrapezoidProfile;
+import edu.wpi.first.wpilibj.Timer;
+import java.util.function.Consumer;
+
/**
- * A command that runs a {@link TrapezoidProfile}. Useful for smoothly controlling mechanism
- * motion.
+ * A command that runs a {@link TrapezoidProfile}. Useful for smoothly controlling mechanism motion.
*/
public class TrapezoidProfileCommand extends CommandBase {
private final TrapezoidProfile m_profile;
@@ -29,13 +24,12 @@
* Creates a new TrapezoidProfileCommand that will execute the given {@link TrapezoidProfile}.
* Output will be piped to the provided consumer function.
*
- * @param profile The motion profile to execute.
- * @param output The consumer for the profile output.
+ * @param profile The motion profile to execute.
+ * @param output The consumer for the profile output.
* @param requirements The subsystems required by this command.
*/
- public TrapezoidProfileCommand(TrapezoidProfile profile,
- Consumer<State> output,
- Subsystem... requirements) {
+ public TrapezoidProfileCommand(
+ TrapezoidProfile profile, Consumer<State> output, Subsystem... requirements) {
m_profile = requireNonNullParam(profile, "profile", "TrapezoidProfileCommand");
m_output = requireNonNullParam(output, "output", "TrapezoidProfileCommand");
addRequirements(requirements);
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java
index 05e6386..0a6c658 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java
@@ -1,19 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import edu.wpi.first.math.trajectory.TrapezoidProfile;
+
/**
- * A subsystem that generates and runs trapezoidal motion profiles automatically. The user
- * specifies how to use the current state of the motion profile by overriding the `useState` method.
+ * A subsystem that generates and runs trapezoidal motion profiles automatically. The user specifies
+ * how to use the current state of the motion profile by overriding the `useState` method.
*/
public abstract class TrapezoidProfileSubsystem extends SubsystemBase {
private final double m_period;
@@ -27,14 +24,13 @@
/**
* Creates a new TrapezoidProfileSubsystem.
*
- * @param constraints The constraints (maximum velocity and acceleration) for the profiles.
- * @param initialPosition The initial position of the controlled mechanism when the subsystem
- * is constructed.
- * @param period The period of the main robot loop, in seconds.
+ * @param constraints The constraints (maximum velocity and acceleration) for the profiles.
+ * @param initialPosition The initial position of the controlled mechanism when the subsystem is
+ * constructed.
+ * @param period The period of the main robot loop, in seconds.
*/
- public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints,
- double initialPosition,
- double period) {
+ public TrapezoidProfileSubsystem(
+ TrapezoidProfile.Constraints constraints, double initialPosition, double period) {
m_constraints = requireNonNullParam(constraints, "constraints", "TrapezoidProfileSubsystem");
m_state = new TrapezoidProfile.State(initialPosition, 0);
setGoal(initialPosition);
@@ -44,19 +40,19 @@
/**
* Creates a new TrapezoidProfileSubsystem.
*
- * @param constraints The constraints (maximum velocity and acceleration) for the profiles.
- * @param initialPosition The initial position of the controlled mechanism when the subsystem
- * is constructed.
+ * @param constraints The constraints (maximum velocity and acceleration) for the profiles.
+ * @param initialPosition The initial position of the controlled mechanism when the subsystem is
+ * constructed.
*/
- public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints,
- double initialPosition) {
+ public TrapezoidProfileSubsystem(
+ TrapezoidProfile.Constraints constraints, double initialPosition) {
this(constraints, initialPosition, 0.02);
}
/**
* Creates a new TrapezoidProfileSubsystem.
*
- * @param constraints The constraints (maximum velocity and acceleration) for the profiles.
+ * @param constraints The constraints (maximum velocity and acceleration) for the profiles.
*/
public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints) {
this(constraints, 0, 0.02);
@@ -81,7 +77,7 @@
}
/**
- * Sets the goal state for the subsystem. Goal velocity assumed to be zero.
+ * Sets the goal state for the subsystem. Goal velocity assumed to be zero.
*
* @param goal The goal position for the subsystem's motion profile.
*/
@@ -89,16 +85,12 @@
setGoal(new TrapezoidProfile.State(goal, 0));
}
- /**
- * Enable the TrapezoidProfileSubsystem's output.
- */
+ /** Enable the TrapezoidProfileSubsystem's output. */
public void enable() {
m_enabled = true;
}
- /**
- * Disable the TrapezoidProfileSubsystem's output.
- */
+ /** Disable the TrapezoidProfileSubsystem's output. */
public void disable() {
m_enabled = false;
}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitCommand.java
index c53fb42..b285669 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitCommand.java
@@ -1,25 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
- * A command that does nothing but takes a specified amount of time to finish. Useful for
- * CommandGroups. Can also be subclassed to make a command with an internal timer.
+ * A command that does nothing but takes a specified amount of time to finish. Useful for
+ * CommandGroups. Can also be subclassed to make a command with an internal timer.
*/
public class WaitCommand extends CommandBase {
protected Timer m_timer = new Timer();
private final double m_duration;
/**
- * Creates a new WaitCommand. This command will do nothing, and end after the specified duration.
+ * Creates a new WaitCommand. This command will do nothing, and end after the specified duration.
*
* @param seconds the time to wait, in seconds
*/
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitUntilCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitUntilCommand.java
index 5c55fff..9228362 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitUntilCommand.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/WaitUntilCommand.java
@@ -1,21 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-
-import java.util.function.BooleanSupplier;
-
-import edu.wpi.first.wpilibj.Timer;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import edu.wpi.first.wpilibj.Timer;
+import java.util.function.BooleanSupplier;
+
/**
- * A command that does nothing but ends after a specified match time or condition. Useful for
+ * A command that does nothing but ends after a specified match time or condition. Useful for
* CommandGroups.
*/
public class WaitUntilCommand extends CommandBase {
@@ -33,9 +28,9 @@
/**
* Creates a new WaitUntilCommand that ends after a given match time.
*
- * <p>NOTE: The match timer used for this command is UNOFFICIAL. Using this command does NOT
+ * <p>NOTE: The match timer used for this command is UNOFFICIAL. Using this command does NOT
* guarantee that the time at which the action is performed will be judged to be legal by the
- * referees. When in doubt, add a safety factor or time the action manually.
+ * referees. When in doubt, add a safety factor or time the action manually.
*
* @param time the match time after which to end, in seconds
*/
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Button.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Button.java
index d672a38..0f8594d 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Button.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Button.java
@@ -1,22 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
-import java.util.function.BooleanSupplier;
-
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Subsystem;
+import java.util.function.BooleanSupplier;
/**
* This class provides an easy way to link commands to OI inputs.
*
- * <p>It is very easy to link a button to a command. For instance, you could link the trigger
- * button of a joystick to a "score" command.
+ * <p>It is very easy to link a button to a command. For instance, you could link the trigger button
+ * of a joystick to a "score" command.
*
* <p>This class represents a subclass of Trigger that is specifically aimed at buttons on an
* operator interface as a common use case of the more generalized Trigger objects. This is a simple
@@ -27,8 +23,7 @@
* Default constructor; creates a button that is never pressed (unless {@link Button#get()} is
* overridden).
*/
- public Button() {
- }
+ public Button() {}
/**
* Creates a new button with the given condition determining whether it is pressed.
@@ -42,7 +37,7 @@
/**
* Starts the given command whenever the button is newly pressed.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this button, so calls can be chained
*/
@@ -66,7 +61,7 @@
/**
* Runs the given runnable whenever the button is newly pressed.
*
- * @param toRun the runnable to run
+ * @param toRun the runnable to run
* @param requirements the required subsystems
* @return this button, so calls can be chained
*/
@@ -78,10 +73,10 @@
/**
* Constantly starts the given command while the button is held.
*
- * {@link Command#schedule(boolean)} will be called repeatedly while the button is held, and will
- * be canceled when the button is released.
+ * <p>{@link Command#schedule(boolean)} will be called repeatedly while the button is held, and
+ * will be canceled when the button is released.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this button, so calls can be chained
*/
@@ -93,8 +88,8 @@
/**
* Constantly starts the given command while the button is held.
*
- * {@link Command#schedule(boolean)} will be called repeatedly while the button is held, and will
- * be canceled when the button is released. The command is set to be interruptible.
+ * <p>{@link Command#schedule(boolean)} will be called repeatedly while the button is held, and
+ * will be canceled when the button is released. The command is set to be interruptible.
*
* @param command the command to start
* @return this button, so calls can be chained
@@ -107,7 +102,7 @@
/**
* Constantly runs the given runnable while the button is held.
*
- * @param toRun the runnable to run
+ * @param toRun the runnable to run
* @param requirements the required subsystems
* @return this button, so calls can be chained
*/
@@ -120,7 +115,7 @@
* Starts the given command when the button is first pressed, and cancels it when it is released,
* but does not start it again if it ends or is otherwise interrupted.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this button, so calls can be chained
*/
@@ -131,7 +126,7 @@
/**
* Starts the given command when the button is first pressed, and cancels it when it is released,
- * but does not start it again if it ends or is otherwise interrupted. The command is set to be
+ * but does not start it again if it ends or is otherwise interrupted. The command is set to be
* interruptible.
*
* @param command the command to start
@@ -142,11 +137,10 @@
return this;
}
-
/**
* Starts the command when the button is released.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this button, so calls can be chained
*/
@@ -156,7 +150,7 @@
}
/**
- * Starts the command when the button is released. The command is set to be interruptible.
+ * Starts the command when the button is released. The command is set to be interruptible.
*
* @param command the command to start
* @return this button, so calls can be chained
@@ -169,7 +163,7 @@
/**
* Runs the given runnable when the button is released.
*
- * @param toRun the runnable to run
+ * @param toRun the runnable to run
* @param requirements the required subsystems
* @return this button, so calls can be chained
*/
@@ -181,8 +175,9 @@
/**
* Toggles the command whenever the button is pressed (on then off then on).
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
+ * @return this button, so calls can be chained
*/
public Button toggleWhenPressed(final Command command, boolean interruptible) {
toggleWhenActive(command, interruptible);
@@ -190,8 +185,8 @@
}
/**
- * Toggles the command whenever the button is pressed (on then off then on). The command is set
- * to be interruptible.
+ * Toggles the command whenever the button is pressed (on then off then on). The command is set to
+ * be interruptible.
*
* @param command the command to start
* @return this button, so calls can be chained
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/InternalButton.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/InternalButton.java
index 3f74f48..e02f078 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/InternalButton.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/InternalButton.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
@@ -15,9 +12,7 @@
private boolean m_pressed;
private boolean m_inverted;
- /**
- * Creates an InternalButton that is not inverted.
- */
+ /** Creates an InternalButton that is not inverted. */
public InternalButton() {
this(false);
}
@@ -26,7 +21,7 @@
* Creates an InternalButton which is inverted depending on the input.
*
* @param inverted if false, then this button is pressed when set to true, otherwise it is pressed
- * when set to false.
+ * when set to false.
*/
public InternalButton(boolean inverted) {
m_pressed = m_inverted = inverted;
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/JoystickButton.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/JoystickButton.java
index 918bb6a..c42ab4f 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/JoystickButton.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/JoystickButton.java
@@ -1,19 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
-import edu.wpi.first.wpilibj.GenericHID;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-/**
- * A {@link Button} that gets its state from a {@link GenericHID}.
- */
+import edu.wpi.first.wpilibj.GenericHID;
+
+/** A {@link Button} that gets its state from a {@link GenericHID}. */
public class JoystickButton extends Button {
private final GenericHID m_joystick;
private final int m_buttonNumber;
@@ -21,8 +16,7 @@
/**
* Creates a joystick button for triggering commands.
*
- * @param joystick The GenericHID object that has the button (e.g. Joystick, KinectStick,
- * etc)
+ * @param joystick The GenericHID object that has the button (e.g. Joystick, KinectStick, etc)
* @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) }
*/
public JoystickButton(GenericHID joystick, int buttonNumber) {
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/NetworkButton.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/NetworkButton.java
index 4cb1859..ec4f819 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/NetworkButton.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/NetworkButton.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
@@ -11,9 +8,7 @@
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
-/**
- * A {@link Button} that uses a {@link NetworkTable} boolean field.
- */
+/** A {@link Button} that uses a {@link NetworkTable} boolean field. */
public class NetworkButton extends Button {
private final NetworkTableEntry m_entry;
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/POVButton.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/POVButton.java
index 823b756..bd0c585 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/POVButton.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/POVButton.java
@@ -1,19 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
-import edu.wpi.first.wpilibj.GenericHID;
-
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
-/**
- * A {@link Button} that gets its state from a POV on a {@link GenericHID}.
- */
+import edu.wpi.first.wpilibj.GenericHID;
+
+/** A {@link Button} that gets its state from a POV on a {@link GenericHID}. */
public class POVButton extends Button {
private final GenericHID m_joystick;
private final int m_angle;
@@ -35,8 +30,7 @@
}
/**
- * Creates a POV button for triggering commands.
- * By default, acts on POV 0
+ * Creates a POV button for triggering commands. By default, acts on POV 0
*
* @param joystick The GenericHID object that has the POV
* @param angle The desired angle (e.g. 90, 270)
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java
index e5e1763..029d2fd 100644
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java
+++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java
@@ -1,31 +1,28 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
-import java.util.function.BooleanSupplier;
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import edu.wpi.first.wpilibj.Debouncer;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.Subsystem;
-
-import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+import java.util.function.BooleanSupplier;
/**
* This class provides an easy way to link commands to inputs.
*
- * <p>It is very easy to link a button to a command. For instance, you could link the trigger
- * button of a joystick to a "score" command.
+ * <p>It is very easy to link a button to a command. For instance, you could link the trigger button
+ * of a joystick to a "score" command.
*
- * <p>It is encouraged that teams write a subclass of Trigger if they want to have something
- * unusual (for instance, if they want to react to the user holding a button while the robot is
- * reading a certain sensor input). For this, they only have to write the {@link Trigger#get()}
- * method to get the full functionality of the Trigger class.
+ * <p>It is encouraged that teams write a subclass of Trigger if they want to have something unusual
+ * (for instance, if they want to react to the user holding a button while the robot is reading a
+ * certain sensor input). For this, they only have to write the {@link Trigger#get()} method to get
+ * the full functionality of the Trigger class.
*/
public class Trigger {
private final BooleanSupplier m_isActive;
@@ -40,7 +37,7 @@
}
/**
- * Creates a new trigger that is always inactive. Useful only as a no-arg constructor for
+ * Creates a new trigger that is always inactive. Useful only as a no-arg constructor for
* subclasses that will be overriding {@link Trigger#get()} anyway.
*/
public Trigger() {
@@ -61,33 +58,35 @@
/**
* Starts the given command whenever the trigger just becomes active.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this trigger, so calls can be chained
*/
public Trigger whenActive(final Command command, boolean interruptible) {
requireNonNullParam(command, "command", "whenActive");
- CommandScheduler.getInstance().addButton(new Runnable() {
- private boolean m_pressedLast = get();
+ CommandScheduler.getInstance()
+ .addButton(
+ new Runnable() {
+ private boolean m_pressedLast = get();
- @Override
- public void run() {
- boolean pressed = get();
+ @Override
+ public void run() {
+ boolean pressed = get();
- if (!m_pressedLast && pressed) {
- command.schedule(interruptible);
- }
+ if (!m_pressedLast && pressed) {
+ command.schedule(interruptible);
+ }
- m_pressedLast = pressed;
- }
- });
+ m_pressedLast = pressed;
+ }
+ });
return this;
}
/**
- * Starts the given command whenever the trigger just becomes active. The command is set to be
+ * Starts the given command whenever the trigger just becomes active. The command is set to be
* interruptible.
*
* @param command the command to start
@@ -100,7 +99,7 @@
/**
* Runs the given runnable whenever the trigger just becomes active.
*
- * @param toRun the runnable to run
+ * @param toRun the runnable to run
* @param requirements the required subsystems
* @return this trigger, so calls can be chained
*/
@@ -111,40 +110,42 @@
/**
* Constantly starts the given command while the button is held.
*
- * {@link Command#schedule(boolean)} will be called repeatedly while the trigger is active, and
+ * <p>{@link Command#schedule(boolean)} will be called repeatedly while the trigger is active, and
* will be canceled when the trigger becomes inactive.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this trigger, so calls can be chained
*/
public Trigger whileActiveContinuous(final Command command, boolean interruptible) {
requireNonNullParam(command, "command", "whileActiveContinuous");
- CommandScheduler.getInstance().addButton(new Runnable() {
- private boolean m_pressedLast = get();
+ CommandScheduler.getInstance()
+ .addButton(
+ new Runnable() {
+ private boolean m_pressedLast = get();
- @Override
- public void run() {
- boolean pressed = get();
+ @Override
+ public void run() {
+ boolean pressed = get();
- if (pressed) {
- command.schedule(interruptible);
- } else if (m_pressedLast) {
- command.cancel();
- }
+ if (pressed) {
+ command.schedule(interruptible);
+ } else if (m_pressedLast) {
+ command.cancel();
+ }
- m_pressedLast = pressed;
- }
- });
+ m_pressedLast = pressed;
+ }
+ });
return this;
}
/**
* Constantly starts the given command while the button is held.
*
- * {@link Command#schedule(boolean)} will be called repeatedly while the trigger is active, and
- * will be canceled when the trigger becomes inactive. The command is set to be interruptible.
+ * <p>{@link Command#schedule(boolean)} will be called repeatedly while the trigger is active, and
+ * will be canceled when the trigger becomes inactive. The command is set to be interruptible.
*
* @param command the command to start
* @return this trigger, so calls can be chained
@@ -156,7 +157,7 @@
/**
* Constantly runs the given runnable while the button is held.
*
- * @param toRun the runnable to run
+ * @param toRun the runnable to run
* @param requirements the required subsystems
* @return this trigger, so calls can be chained
*/
@@ -168,35 +169,37 @@
* Starts the given command when the trigger initially becomes active, and ends it when it becomes
* inactive, but does not re-start it in-between.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this trigger, so calls can be chained
*/
public Trigger whileActiveOnce(final Command command, boolean interruptible) {
requireNonNullParam(command, "command", "whileActiveOnce");
- CommandScheduler.getInstance().addButton(new Runnable() {
- private boolean m_pressedLast = get();
+ CommandScheduler.getInstance()
+ .addButton(
+ new Runnable() {
+ private boolean m_pressedLast = get();
- @Override
- public void run() {
- boolean pressed = get();
+ @Override
+ public void run() {
+ boolean pressed = get();
- if (!m_pressedLast && pressed) {
- command.schedule(interruptible);
- } else if (m_pressedLast && !pressed) {
- command.cancel();
- }
+ if (!m_pressedLast && pressed) {
+ command.schedule(interruptible);
+ } else if (m_pressedLast && !pressed) {
+ command.cancel();
+ }
- m_pressedLast = pressed;
- }
- });
+ m_pressedLast = pressed;
+ }
+ });
return this;
}
/**
* Starts the given command when the trigger initially becomes active, and ends it when it becomes
- * inactive, but does not re-start it in-between. The command is set to be interruptible.
+ * inactive, but does not re-start it in-between. The command is set to be interruptible.
*
* @param command the command to start
* @return this trigger, so calls can be chained
@@ -208,32 +211,34 @@
/**
* Starts the command when the trigger becomes inactive.
*
- * @param command the command to start
+ * @param command the command to start
* @param interruptible whether the command is interruptible
* @return this trigger, so calls can be chained
*/
public Trigger whenInactive(final Command command, boolean interruptible) {
requireNonNullParam(command, "command", "whenInactive");
- CommandScheduler.getInstance().addButton(new Runnable() {
- private boolean m_pressedLast = get();
+ CommandScheduler.getInstance()
+ .addButton(
+ new Runnable() {
+ private boolean m_pressedLast = get();
- @Override
- public void run() {
- boolean pressed = get();
+ @Override
+ public void run() {
+ boolean pressed = get();
- if (m_pressedLast && !pressed) {
- command.schedule(interruptible);
- }
+ if (m_pressedLast && !pressed) {
+ command.schedule(interruptible);
+ }
- m_pressedLast = pressed;
- }
- });
+ m_pressedLast = pressed;
+ }
+ });
return this;
}
/**
- * Starts the command when the trigger becomes inactive. The command is set to be interruptible.
+ * Starts the command when the trigger becomes inactive. The command is set to be interruptible.
*
* @param command the command to start
* @return this trigger, so calls can be chained
@@ -245,7 +250,7 @@
/**
* Runs the given runnable when the trigger becomes inactive.
*
- * @param toRun the runnable to run
+ * @param toRun the runnable to run
* @param requirements the required subsystems
* @return this trigger, so calls can be chained
*/
@@ -256,36 +261,38 @@
/**
* Toggles a command when the trigger becomes active.
*
- * @param command the command to toggle
+ * @param command the command to toggle
* @param interruptible whether the command is interruptible
* @return this trigger, so calls can be chained
*/
public Trigger toggleWhenActive(final Command command, boolean interruptible) {
requireNonNullParam(command, "command", "toggleWhenActive");
- CommandScheduler.getInstance().addButton(new Runnable() {
- private boolean m_pressedLast = get();
+ CommandScheduler.getInstance()
+ .addButton(
+ new Runnable() {
+ private boolean m_pressedLast = get();
- @Override
- public void run() {
- boolean pressed = get();
+ @Override
+ public void run() {
+ boolean pressed = get();
- if (!m_pressedLast && pressed) {
- if (command.isScheduled()) {
- command.cancel();
- } else {
- command.schedule(interruptible);
- }
- }
+ if (!m_pressedLast && pressed) {
+ if (command.isScheduled()) {
+ command.cancel();
+ } else {
+ command.schedule(interruptible);
+ }
+ }
- m_pressedLast = pressed;
- }
- });
+ m_pressedLast = pressed;
+ }
+ });
return this;
}
/**
- * Toggles a command when the trigger becomes active. The command is set to be interruptible.
+ * Toggles a command when the trigger becomes active. The command is set to be interruptible.
*
* @param command the command to toggle
* @return this trigger, so calls can be chained
@@ -303,20 +310,22 @@
public Trigger cancelWhenActive(final Command command) {
requireNonNullParam(command, "command", "cancelWhenActive");
- CommandScheduler.getInstance().addButton(new Runnable() {
- private boolean m_pressedLast = get();
+ CommandScheduler.getInstance()
+ .addButton(
+ new Runnable() {
+ private boolean m_pressedLast = get();
- @Override
- public void run() {
- boolean pressed = get();
+ @Override
+ public void run() {
+ boolean pressed = get();
- if (!m_pressedLast && pressed) {
- command.cancel();
- }
+ if (!m_pressedLast && pressed) {
+ command.cancel();
+ }
- m_pressedLast = pressed;
- }
- });
+ m_pressedLast = pressed;
+ }
+ });
return this;
}
@@ -351,4 +360,23 @@
public Trigger negate() {
return new Trigger(() -> !get());
}
+
+ /**
+ * Creates a new debounced trigger from this trigger - it will become active when this trigger has
+ * been active for longer than the specified period.
+ *
+ * @param seconds the debounce period
+ * @return the debounced trigger
+ */
+ public Trigger debounce(double seconds) {
+ return new Trigger(
+ new BooleanSupplier() {
+ Debouncer m_debouncer = new Debouncer(seconds);
+
+ @Override
+ public boolean getAsBoolean() {
+ return m_debouncer.calculate(get());
+ }
+ });
+ }
}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp
index 248368d..b434c1b 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/Command.h"
@@ -20,12 +17,11 @@
using namespace frc2;
-Command::~Command() { CommandScheduler::GetInstance().Cancel(this); }
-
-Command::Command(const Command& rhs) : ErrorBase(rhs) {}
+Command::~Command() {
+ CommandScheduler::GetInstance().Cancel(this);
+}
Command& Command::operator=(const Command& rhs) {
- ErrorBase::operator=(rhs);
m_isGrouped = false;
return *this;
}
@@ -52,12 +48,11 @@
std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) && {
return std::move(*this).BeforeStarting(
- std::move(toRun),
- wpi::makeArrayRef(requirements.begin(), requirements.end()));
+ std::move(toRun), {requirements.begin(), requirements.end()});
}
SequentialCommandGroup Command::BeforeStarting(
- std::function<void()> toRun, wpi::ArrayRef<Subsystem*> requirements) && {
+ std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
std::vector<std::unique_ptr<Command>> temp;
temp.emplace_back(
std::make_unique<InstantCommand>(std::move(toRun), requirements));
@@ -68,13 +63,12 @@
SequentialCommandGroup Command::AndThen(
std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) && {
- return std::move(*this).AndThen(
- std::move(toRun),
- wpi::makeArrayRef(requirements.begin(), requirements.end()));
+ return std::move(*this).AndThen(std::move(toRun),
+ {requirements.begin(), requirements.end()});
}
SequentialCommandGroup Command::AndThen(
- std::function<void()> toRun, wpi::ArrayRef<Subsystem*> requirements) && {
+ std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
std::vector<std::unique_ptr<Command>> temp;
temp.emplace_back(std::move(*this).TransferOwnership());
temp.emplace_back(
@@ -86,13 +80,17 @@
return PerpetualCommand(std::move(*this).TransferOwnership());
}
-ProxyScheduleCommand Command::AsProxy() { return ProxyScheduleCommand(this); }
+ProxyScheduleCommand Command::AsProxy() {
+ return ProxyScheduleCommand(this);
+}
void Command::Schedule(bool interruptible) {
CommandScheduler::GetInstance().Schedule(interruptible, this);
}
-void Command::Cancel() { CommandScheduler::GetInstance().Cancel(this); }
+void Command::Cancel() {
+ CommandScheduler::GetInstance().Cancel(this);
+}
bool Command::IsScheduled() const {
return CommandScheduler::GetInstance().IsScheduled(this);
@@ -106,11 +104,17 @@
return hasRequirement;
}
-std::string Command::GetName() const { return GetTypeName(*this); }
+std::string Command::GetName() const {
+ return GetTypeName(*this);
+}
-bool Command::IsGrouped() const { return m_isGrouped; }
+bool Command::IsGrouped() const {
+ return m_isGrouped;
+}
-void Command::SetGrouped(bool grouped) { m_isGrouped = grouped; }
+void Command::SetGrouped(bool grouped) {
+ m_isGrouped = grouped;
+}
namespace frc2 {
bool RequirementsDisjoint(Command* first, Command* second) {
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp
index 30c3af6..b6f76f3 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandBase.cpp
@@ -1,19 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/CommandBase.h"
-#include <frc/smartdashboard/SendableBuilder.h>
-#include <frc/smartdashboard/SendableRegistry.h>
+#include <wpi/sendable/SendableBuilder.h>
+#include <wpi/sendable/SendableRegistry.h>
using namespace frc2;
CommandBase::CommandBase() {
- frc::SendableRegistry::GetInstance().Add(this, GetTypeName(*this));
+ wpi::SendableRegistry::Add(this, GetTypeName(*this));
}
void CommandBase::AddRequirements(
@@ -21,7 +18,7 @@
m_requirements.insert(requirements.begin(), requirements.end());
}
-void CommandBase::AddRequirements(wpi::ArrayRef<Subsystem*> requirements) {
+void CommandBase::AddRequirements(wpi::span<Subsystem* const> requirements) {
m_requirements.insert(requirements.begin(), requirements.end());
}
@@ -29,27 +26,31 @@
m_requirements.insert(requirements.begin(), requirements.end());
}
+void CommandBase::AddRequirements(Subsystem* requirement) {
+ m_requirements.insert(requirement);
+}
+
wpi::SmallSet<Subsystem*, 4> CommandBase::GetRequirements() const {
return m_requirements;
}
-void CommandBase::SetName(const wpi::Twine& name) {
- frc::SendableRegistry::GetInstance().SetName(this, name);
+void CommandBase::SetName(std::string_view name) {
+ wpi::SendableRegistry::SetName(this, name);
}
std::string CommandBase::GetName() const {
- return frc::SendableRegistry::GetInstance().GetName(this);
+ return wpi::SendableRegistry::GetName(this);
}
std::string CommandBase::GetSubsystem() const {
- return frc::SendableRegistry::GetInstance().GetSubsystem(this);
+ return wpi::SendableRegistry::GetSubsystem(this);
}
-void CommandBase::SetSubsystem(const wpi::Twine& subsystem) {
- frc::SendableRegistry::GetInstance().SetSubsystem(this, subsystem);
+void CommandBase::SetSubsystem(std::string_view subsystem) {
+ wpi::SendableRegistry::SetSubsystem(this, subsystem);
}
-void CommandBase::InitSendable(frc::SendableBuilder& builder) {
+void CommandBase::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Command");
builder.AddStringProperty(
".name", [this] { return GetName(); }, nullptr);
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp
index 8869d4c..a3d275d 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp
@@ -1,50 +1,47 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/CommandGroupBase.h"
-#include <frc/WPIErrors.h>
-
using namespace frc2;
-bool CommandGroupBase::RequireUngrouped(Command& command) {
+bool CommandGroupBase::RequireUngrouped(const Command& command) {
if (command.IsGrouped()) {
- wpi_setGlobalWPIErrorWithContext(
- CommandIllegalUse,
+ throw FRC_MakeError(
+ frc::err::CommandIllegalUse, "{}",
"Commands cannot be added to more than one CommandGroup");
- return false;
- } else {
- return true;
}
+ return true;
+}
+
+bool CommandGroupBase::RequireUngrouped(const Command* command) {
+ return RequireUngrouped(*command);
}
bool CommandGroupBase::RequireUngrouped(
- wpi::ArrayRef<std::unique_ptr<Command>> commands) {
+ wpi::span<const std::unique_ptr<Command>> commands) {
bool allUngrouped = true;
for (auto&& command : commands) {
allUngrouped &= !command.get()->IsGrouped();
}
if (!allUngrouped) {
- wpi_setGlobalWPIErrorWithContext(
- CommandIllegalUse,
+ throw FRC_MakeError(
+ frc::err::CommandIllegalUse, "{}",
"Commands cannot be added to more than one CommandGroup");
}
return allUngrouped;
}
bool CommandGroupBase::RequireUngrouped(
- std::initializer_list<Command*> commands) {
+ std::initializer_list<const Command*> commands) {
bool allUngrouped = true;
for (auto&& command : commands) {
allUngrouped &= !command->IsGrouped();
}
if (!allUngrouped) {
- wpi_setGlobalWPIErrorWithContext(
- CommandIllegalUse,
+ throw FRC_MakeError(
+ frc::err::CommandIllegalUse, "{}",
"Commands cannot be added to more than one CommandGroup");
}
return allUngrouped;
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp
index a59c68b..f79fa59 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp
@@ -1,25 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/CommandScheduler.h"
+#include <cstdio>
+
#include <frc/RobotBase.h>
#include <frc/RobotState.h>
#include <frc/TimedRobot.h>
-#include <frc/WPIErrors.h>
#include <frc/livewindow/LiveWindow.h>
-#include <frc/smartdashboard/SendableBuilder.h>
-#include <frc/smartdashboard/SendableRegistry.h>
#include <hal/FRCUsageReporting.h>
#include <hal/HALBase.h>
+#include <networktables/NTSendableBuilder.h>
#include <networktables/NetworkTableEntry.h>
#include <wpi/DenseMap.h>
#include <wpi/SmallVector.h>
-#include <wpi/raw_ostream.h>
+#include <wpi/sendable/SendableRegistry.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandState.h"
@@ -69,24 +66,24 @@
CommandScheduler::CommandScheduler()
: m_impl(new Impl), m_watchdog(frc::TimedRobot::kDefaultPeriod, [] {
- wpi::outs() << "CommandScheduler loop time overrun.\n";
+ std::puts("CommandScheduler loop time overrun.");
}) {
HAL_Report(HALUsageReporting::kResourceType_Command,
HALUsageReporting::kCommand2_Scheduler);
- frc::SendableRegistry::GetInstance().AddLW(this, "Scheduler");
- auto scheduler = frc::LiveWindow::GetInstance();
- scheduler->enabled = [this] {
+ wpi::SendableRegistry::AddLW(this, "Scheduler");
+ frc::LiveWindow::SetEnabledCallback([this] {
this->Disable();
this->CancelAll();
- };
- scheduler->disabled = [this] { this->Enable(); };
+ });
+ frc::LiveWindow::SetDisabledCallback([this] { this->Enable(); });
}
CommandScheduler::~CommandScheduler() {
- frc::SendableRegistry::GetInstance().Remove(this);
- auto scheduler = frc::LiveWindow::GetInstance();
- scheduler->enabled = nullptr;
- scheduler->disabled = nullptr;
+ wpi::SendableRegistry::Remove(this);
+ frc::LiveWindow::SetEnabledCallback(nullptr);
+ frc::LiveWindow::SetDisabledCallback(nullptr);
+
+ std::unique_ptr<Impl>().swap(m_impl);
}
CommandScheduler& CommandScheduler::GetInstance() {
@@ -102,7 +99,9 @@
m_impl->buttons.emplace_back(std::move(button));
}
-void CommandScheduler::ClearButtons() { m_impl->buttons.clear(); }
+void CommandScheduler::ClearButtons() {
+ m_impl->buttons.clear();
+}
void CommandScheduler::Schedule(bool interruptible, Command* command) {
if (m_impl->inRunLoop) {
@@ -111,9 +110,9 @@
}
if (command->IsGrouped()) {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "A command that is part of a command group "
- "cannot be independently scheduled");
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "A command that is part of a command group "
+ "cannot be independently scheduled");
return;
}
if (m_impl->disabled ||
@@ -155,10 +154,12 @@
}
}
-void CommandScheduler::Schedule(Command* command) { Schedule(true, command); }
+void CommandScheduler::Schedule(Command* command) {
+ Schedule(true, command);
+}
void CommandScheduler::Schedule(bool interruptible,
- wpi::ArrayRef<Command*> commands) {
+ wpi::span<Command* const> commands) {
for (auto command : commands) {
Schedule(interruptible, command);
}
@@ -171,7 +172,7 @@
}
}
-void CommandScheduler::Schedule(wpi::ArrayRef<Command*> commands) {
+void CommandScheduler::Schedule(wpi::span<Command* const> commands) {
for (auto command : commands) {
Schedule(true, command);
}
@@ -281,7 +282,8 @@
}
}
-void CommandScheduler::RegisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems) {
+void CommandScheduler::RegisterSubsystem(
+ wpi::span<Subsystem* const> subsystems) {
for (auto* subsystem : subsystems) {
RegisterSubsystem(subsystem);
}
@@ -295,7 +297,7 @@
}
void CommandScheduler::UnregisterSubsystem(
- wpi::ArrayRef<Subsystem*> subsystems) {
+ wpi::span<Subsystem* const> subsystems) {
for (auto* subsystem : subsystems) {
UnregisterSubsystem(subsystem);
}
@@ -311,13 +313,19 @@
}
void CommandScheduler::Cancel(Command* command) {
+ if (!m_impl) {
+ return;
+ }
+
if (m_impl->inRunLoop) {
m_impl->toCancel.emplace_back(command);
return;
}
auto find = m_impl->scheduledCommands.find(command);
- if (find == m_impl->scheduledCommands.end()) return;
+ if (find == m_impl->scheduledCommands.end()) {
+ return;
+ }
command->End(true);
for (auto&& action : m_impl->interruptActions) {
action(*command);
@@ -331,7 +339,7 @@
}
}
-void CommandScheduler::Cancel(wpi::ArrayRef<Command*> commands) {
+void CommandScheduler::Cancel(wpi::span<Command* const> commands) {
for (auto command : commands) {
Cancel(command);
}
@@ -351,16 +359,17 @@
Cancel(commands);
}
-double CommandScheduler::TimeSinceScheduled(const Command* command) const {
+units::second_t CommandScheduler::TimeSinceScheduled(
+ const Command* command) const {
auto find = m_impl->scheduledCommands.find(command);
if (find != m_impl->scheduledCommands.end()) {
return find->second.TimeSinceInitialized();
} else {
- return -1;
+ return -1_s;
}
}
bool CommandScheduler::IsScheduled(
- wpi::ArrayRef<const Command*> commands) const {
+ wpi::span<const Command* const> commands) const {
for (auto command : commands) {
if (!IsScheduled(command)) {
return false;
@@ -393,9 +402,13 @@
}
}
-void CommandScheduler::Disable() { m_impl->disabled = true; }
+void CommandScheduler::Disable() {
+ m_impl->disabled = true;
+}
-void CommandScheduler::Enable() { m_impl->disabled = false; }
+void CommandScheduler::Enable() {
+ m_impl->disabled = false;
+}
void CommandScheduler::OnCommandInitialize(Action action) {
m_impl->initActions.emplace_back(std::move(action));
@@ -413,7 +426,7 @@
m_impl->finishActions.emplace_back(std::move(action));
}
-void CommandScheduler::InitSendable(frc::SendableBuilder& builder) {
+void CommandScheduler::InitSendable(nt::NTSendableBuilder& builder) {
builder.SetSmartDashboardType("Scheduler");
auto namesEntry = builder.GetEntry("Names");
auto idsEntry = builder.GetEntry("Ids");
@@ -430,8 +443,7 @@
m_impl->scheduledCommands.end()) {
Cancel(command);
}
- nt::NetworkTableEntry(cancelEntry)
- .SetDoubleArray(wpi::ArrayRef<double>{});
+ nt::NetworkTableEntry(cancelEntry).SetDoubleArray({});
}
wpi::SmallVector<std::string, 8> names;
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandState.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandState.cpp
index b41fa70..f53a694 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandState.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandState.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/CommandState.h"
@@ -19,7 +16,12 @@
void CommandState::StartTiming() {
m_startTime = frc::Timer::GetFPGATimestamp();
}
-void CommandState::StartRunning() { m_startTime = -1; }
-double CommandState::TimeSinceInitialized() const {
- return m_startTime != -1 ? frc::Timer::GetFPGATimestamp() - m_startTime : -1;
+
+void CommandState::StartRunning() {
+ m_startTime = -1_s;
+}
+
+units::second_t CommandState::TimeSinceInitialized() const {
+ return m_startTime != -1_s ? frc::Timer::GetFPGATimestamp() - m_startTime
+ : -1_s;
}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ConditionalCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ConditionalCommand.cpp
index 2344513..30ef410 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ConditionalCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ConditionalCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/ConditionalCommand.h"
@@ -39,7 +36,9 @@
m_selectedCommand->Initialize();
}
-void ConditionalCommand::Execute() { m_selectedCommand->Execute(); }
+void ConditionalCommand::Execute() {
+ m_selectedCommand->Execute();
+}
void ConditionalCommand::End(bool interrupted) {
m_selectedCommand->End(interrupted);
@@ -49,4 +48,6 @@
return m_selectedCommand->IsFinished();
}
-bool ConditionalCommand::RunsWhenDisabled() const { return m_runsWhenDisabled; }
+bool ConditionalCommand::RunsWhenDisabled() const {
+ return m_runsWhenDisabled;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp
index ee28ba7..0c45099 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/FunctionalCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/FunctionalCommand.h"
@@ -24,7 +21,7 @@
std::function<void()> onExecute,
std::function<void(bool)> onEnd,
std::function<bool()> isFinished,
- wpi::ArrayRef<Subsystem*> requirements)
+ wpi::span<Subsystem* const> requirements)
: m_onInit{std::move(onInit)},
m_onExecute{std::move(onExecute)},
m_onEnd{std::move(onEnd)},
@@ -32,10 +29,18 @@
AddRequirements(requirements);
}
-void FunctionalCommand::Initialize() { m_onInit(); }
+void FunctionalCommand::Initialize() {
+ m_onInit();
+}
-void FunctionalCommand::Execute() { m_onExecute(); }
+void FunctionalCommand::Execute() {
+ m_onExecute();
+}
-void FunctionalCommand::End(bool interrupted) { m_onEnd(interrupted); }
+void FunctionalCommand::End(bool interrupted) {
+ m_onEnd(interrupted);
+}
-bool FunctionalCommand::IsFinished() { return m_isFinished(); }
+bool FunctionalCommand::IsFinished() {
+ return m_isFinished();
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp
index 6f66c5c..1e9d173 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/InstantCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/InstantCommand.h"
@@ -16,13 +13,17 @@
}
InstantCommand::InstantCommand(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements)
+ wpi::span<Subsystem* const> requirements)
: m_toRun{std::move(toRun)} {
AddRequirements(requirements);
}
InstantCommand::InstantCommand() : m_toRun{[] {}} {}
-void InstantCommand::Initialize() { m_toRun(); }
+void InstantCommand::Initialize() {
+ m_toRun();
+}
-bool InstantCommand::IsFinished() { return true; }
+bool InstantCommand::IsFinished() {
+ return true;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp
index eb32853..c521f8b 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/MecanumControllerCommand.h"
+#include <utility>
+
using namespace frc2;
using namespace units;
@@ -27,12 +26,12 @@
units::volt_t)>
output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_feedforward(feedforward),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
- m_desiredRotation(desiredRotation),
+ m_desiredRotation(std::move(desiredRotation)),
m_maxWheelVelocity(maxWheelVelocity),
m_frontLeftController(
std::make_unique<frc2::PIDController>(frontLeftController)),
@@ -42,8 +41,8 @@
std::make_unique<frc2::PIDController>(frontRightController)),
m_rearRightController(
std::make_unique<frc2::PIDController>(rearRightController)),
- m_currentWheelSpeeds(currentWheelSpeeds),
- m_outputVolts(output),
+ m_currentWheelSpeeds(std::move(currentWheelSpeeds)),
+ m_outputVolts(std::move(output)),
m_usePID(true) {
AddRequirements(requirements);
}
@@ -64,8 +63,8 @@
units::volt_t)>
output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_feedforward(feedforward),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
@@ -78,8 +77,8 @@
std::make_unique<frc2::PIDController>(frontRightController)),
m_rearRightController(
std::make_unique<frc2::PIDController>(rearRightController)),
- m_currentWheelSpeeds(currentWheelSpeeds),
- m_outputVolts(output),
+ m_currentWheelSpeeds(std::move(currentWheelSpeeds)),
+ m_outputVolts(std::move(output)),
m_usePID(true) {
AddRequirements(requirements);
m_desiredRotation = [&] {
@@ -103,13 +102,13 @@
std::function<void(units::volt_t, units::volt_t, units::volt_t,
units::volt_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_feedforward(feedforward),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
- m_desiredRotation(desiredRotation),
+ m_desiredRotation(std::move(desiredRotation)),
m_maxWheelVelocity(maxWheelVelocity),
m_frontLeftController(
std::make_unique<frc2::PIDController>(frontLeftController)),
@@ -119,8 +118,8 @@
std::make_unique<frc2::PIDController>(frontRightController)),
m_rearRightController(
std::make_unique<frc2::PIDController>(rearRightController)),
- m_currentWheelSpeeds(currentWheelSpeeds),
- m_outputVolts(output),
+ m_currentWheelSpeeds(std::move(currentWheelSpeeds)),
+ m_outputVolts(std::move(output)),
m_usePID(true) {
AddRequirements(requirements);
}
@@ -140,9 +139,9 @@
std::function<void(units::volt_t, units::volt_t, units::volt_t,
units::volt_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_feedforward(feedforward),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
@@ -155,8 +154,8 @@
std::make_unique<frc2::PIDController>(frontRightController)),
m_rearRightController(
std::make_unique<frc2::PIDController>(rearRightController)),
- m_currentWheelSpeeds(currentWheelSpeeds),
- m_outputVolts(output),
+ m_currentWheelSpeeds(std::move(currentWheelSpeeds)),
+ m_outputVolts(std::move(output)),
m_usePID(true) {
AddRequirements(requirements);
m_desiredRotation = [&] {
@@ -175,13 +174,13 @@
units::meters_per_second_t, units::meters_per_second_t)>
output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
- m_desiredRotation(desiredRotation),
+ m_desiredRotation(std::move(desiredRotation)),
m_maxWheelVelocity(maxWheelVelocity),
- m_outputVel(output),
+ m_outputVel(std::move(output)),
m_usePID(false) {
AddRequirements(requirements);
}
@@ -196,12 +195,12 @@
units::meters_per_second_t, units::meters_per_second_t)>
output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
m_maxWheelVelocity(maxWheelVelocity),
- m_outputVel(output),
+ m_outputVel(std::move(output)),
m_usePID(false) {
AddRequirements(requirements);
m_desiredRotation = [&] {
@@ -219,14 +218,14 @@
std::function<void(units::meters_per_second_t, units::meters_per_second_t,
units::meters_per_second_t, units::meters_per_second_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
- m_desiredRotation(desiredRotation),
+ m_desiredRotation(std::move(desiredRotation)),
m_maxWheelVelocity(maxWheelVelocity),
- m_outputVel(output),
+ m_outputVel(std::move(output)),
m_usePID(false) {
AddRequirements(requirements);
}
@@ -240,13 +239,13 @@
std::function<void(units::meters_per_second_t, units::meters_per_second_t,
units::meters_per_second_t, units::meters_per_second_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
m_maxWheelVelocity(maxWheelVelocity),
- m_outputVel(output),
+ m_outputVel(std::move(output)),
m_usePID(false) {
AddRequirements(requirements);
m_desiredRotation = [&] {
@@ -311,20 +310,20 @@
(rearRightSpeedSetpoint - m_prevSpeeds.rearRight) / dt);
auto frontLeftOutput = volt_t(m_frontLeftController->Calculate(
- m_currentWheelSpeeds().frontLeft.to<double>(),
- frontLeftSpeedSetpoint.to<double>())) +
+ m_currentWheelSpeeds().frontLeft.value(),
+ frontLeftSpeedSetpoint.value())) +
frontLeftFeedforward;
auto rearLeftOutput = volt_t(m_rearLeftController->Calculate(
- m_currentWheelSpeeds().rearLeft.to<double>(),
- rearLeftSpeedSetpoint.to<double>())) +
+ m_currentWheelSpeeds().rearLeft.value(),
+ rearLeftSpeedSetpoint.value())) +
rearLeftFeedforward;
auto frontRightOutput = volt_t(m_frontRightController->Calculate(
- m_currentWheelSpeeds().frontRight.to<double>(),
- frontRightSpeedSetpoint.to<double>())) +
+ m_currentWheelSpeeds().frontRight.value(),
+ frontRightSpeedSetpoint.value())) +
frontRightFeedforward;
auto rearRightOutput = volt_t(m_rearRightController->Calculate(
- m_currentWheelSpeeds().rearRight.to<double>(),
- rearRightSpeedSetpoint.to<double>())) +
+ m_currentWheelSpeeds().rearRight.value(),
+ rearRightSpeedSetpoint.value())) +
rearRightFeedforward;
m_outputVolts(frontLeftOutput, rearLeftOutput, frontRightOutput,
@@ -338,7 +337,9 @@
}
}
-void MecanumControllerCommand::End(bool interrupted) { m_timer.Stop(); }
+void MecanumControllerCommand::End(bool interrupted) {
+ m_timer.Stop();
+}
bool MecanumControllerCommand::IsFinished() {
return m_timer.HasElapsed(m_trajectory.TotalTime());
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp
index 1b13d75..37e5bc6 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/NotifierCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/NotifierCommand.h"
@@ -18,7 +15,7 @@
NotifierCommand::NotifierCommand(std::function<void()> toRun,
units::second_t period,
- wpi::ArrayRef<Subsystem*> requirements)
+ wpi::span<Subsystem* const> requirements)
: m_toRun(toRun), m_notifier{std::move(toRun)}, m_period{period} {
AddRequirements(requirements);
}
@@ -35,6 +32,10 @@
m_notifier(frc::Notifier(other.m_toRun)),
m_period(other.m_period) {}
-void NotifierCommand::Initialize() { m_notifier.StartPeriodic(m_period); }
+void NotifierCommand::Initialize() {
+ m_notifier.StartPeriodic(m_period);
+}
-void NotifierCommand::End(bool interrupted) { m_notifier.Stop(); }
+void NotifierCommand::End(bool interrupted) {
+ m_notifier.Stop();
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp
index ea6c105..d11735a 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/PIDCommand.h"
+#include <utility>
+
using namespace frc2;
PIDCommand::PIDCommand(PIDController controller,
@@ -14,7 +13,7 @@
std::function<double()> setpointSource,
std::function<void(double)> useOutput,
std::initializer_list<Subsystem*> requirements)
- : m_controller{controller},
+ : m_controller{std::move(controller)},
m_measurement{std::move(measurementSource)},
m_setpoint{std::move(setpointSource)},
m_useOutput{std::move(useOutput)} {
@@ -25,8 +24,8 @@
std::function<double()> measurementSource,
std::function<double()> setpointSource,
std::function<void(double)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_controller{controller},
+ wpi::span<Subsystem* const> requirements)
+ : m_controller{std::move(controller)},
m_measurement{std::move(measurementSource)},
m_setpoint{std::move(setpointSource)},
m_useOutput{std::move(useOutput)} {
@@ -44,17 +43,23 @@
PIDCommand::PIDCommand(PIDController controller,
std::function<double()> measurementSource,
double setpoint, std::function<void(double)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements)
+ wpi::span<Subsystem* const> requirements)
: PIDCommand(
controller, measurementSource, [setpoint] { return setpoint; },
useOutput, requirements) {}
-void PIDCommand::Initialize() { m_controller.Reset(); }
+void PIDCommand::Initialize() {
+ m_controller.Reset();
+}
void PIDCommand::Execute() {
m_useOutput(m_controller.Calculate(m_measurement(), m_setpoint()));
}
-void PIDCommand::End(bool interrupted) { m_useOutput(0); }
+void PIDCommand::End(bool interrupted) {
+ m_useOutput(0);
+}
-PIDController& PIDCommand::GetController() { return m_controller; }
+PIDController& PIDCommand::GetController() {
+ return m_controller;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDSubsystem.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDSubsystem.cpp
index f7d988d..7c820ae 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDSubsystem.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDSubsystem.cpp
@@ -1,16 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/PIDSubsystem.h"
+#include <utility>
+
using namespace frc2;
PIDSubsystem::PIDSubsystem(PIDController controller, double initialPosition)
- : m_controller{controller} {
+ : m_controller{std::move(controller)} {
SetSetpoint(initialPosition);
AddChild("PID Controller", &m_controller);
}
@@ -21,9 +20,13 @@
}
}
-void PIDSubsystem::SetSetpoint(double setpoint) { m_setpoint = setpoint; }
+void PIDSubsystem::SetSetpoint(double setpoint) {
+ m_setpoint = setpoint;
+}
-double PIDSubsystem::GetSetpoint() const { return m_setpoint; }
+double PIDSubsystem::GetSetpoint() const {
+ return m_setpoint;
+}
void PIDSubsystem::Enable() {
m_controller.Reset();
@@ -35,6 +38,10 @@
m_enabled = false;
}
-bool PIDSubsystem::IsEnabled() { return m_enabled; }
+bool PIDSubsystem::IsEnabled() {
+ return m_enabled;
+}
-PIDController& PIDSubsystem::GetController() { return m_controller; }
+PIDController& PIDSubsystem::GetController() {
+ return m_controller;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp
index 557984e..a12d2b4 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/ParallelCommandGroup.h"
@@ -24,7 +21,9 @@
void ParallelCommandGroup::Execute() {
for (auto& commandRunning : m_commands) {
- if (!commandRunning.second) continue;
+ if (!commandRunning.second) {
+ continue;
+ }
commandRunning.first->Execute();
if (commandRunning.first->IsFinished()) {
commandRunning.first->End(false);
@@ -46,7 +45,9 @@
bool ParallelCommandGroup::IsFinished() {
for (auto& command : m_commands) {
- if (command.second) return false;
+ if (command.second) {
+ return false;
+ }
}
return true;
}
@@ -58,13 +59,15 @@
void ParallelCommandGroup::AddCommands(
std::vector<std::unique_ptr<Command>>&& commands) {
for (auto&& command : commands) {
- if (!RequireUngrouped(*command)) return;
+ if (!RequireUngrouped(*command)) {
+ return;
+ }
}
if (isRunning) {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Commands cannot be added to a CommandGroup "
- "while the group is running");
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Commands cannot be added to a CommandGroup "
+ "while the group is running");
}
for (auto&& command : commands) {
@@ -74,10 +77,9 @@
m_runWhenDisabled &= command->RunsWhenDisabled();
m_commands.emplace_back(std::move(command), false);
} else {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Multiple commands in a parallel group cannot "
- "require the same subsystems");
- return;
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Multiple commands in a parallel group cannot "
+ "require the same subsystems");
}
}
}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp
index 935cf8b..93dd2fd 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/ParallelDeadlineGroup.h"
@@ -26,7 +23,9 @@
void ParallelDeadlineGroup::Execute() {
for (auto& commandRunning : m_commands) {
- if (!commandRunning.second) continue;
+ if (!commandRunning.second) {
+ continue;
+ }
commandRunning.first->Execute();
if (commandRunning.first->IsFinished()) {
commandRunning.first->End(false);
@@ -46,7 +45,9 @@
}
}
-bool ParallelDeadlineGroup::IsFinished() { return m_finished; }
+bool ParallelDeadlineGroup::IsFinished() {
+ return m_finished;
+}
bool ParallelDeadlineGroup::RunsWhenDisabled() const {
return m_runWhenDisabled;
@@ -59,9 +60,9 @@
}
if (!m_finished) {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Commands cannot be added to a CommandGroup "
- "while the group is running");
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Commands cannot be added to a CommandGroup "
+ "while the group is running");
}
for (auto&& command : commands) {
@@ -71,10 +72,9 @@
m_runWhenDisabled &= command->RunsWhenDisabled();
m_commands.emplace_back(std::move(command), false);
} else {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Multiple commands in a parallel group cannot "
- "require the same subsystems");
- return;
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Multiple commands in a parallel group cannot "
+ "require the same subsystems");
}
}
}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp
index 5fc5e31..63c7cbc 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/ParallelRaceGroup.h"
@@ -38,9 +35,13 @@
isRunning = false;
}
-bool ParallelRaceGroup::IsFinished() { return m_finished; }
+bool ParallelRaceGroup::IsFinished() {
+ return m_finished;
+}
-bool ParallelRaceGroup::RunsWhenDisabled() const { return m_runWhenDisabled; }
+bool ParallelRaceGroup::RunsWhenDisabled() const {
+ return m_runWhenDisabled;
+}
void ParallelRaceGroup::AddCommands(
std::vector<std::unique_ptr<Command>>&& commands) {
@@ -49,9 +50,9 @@
}
if (isRunning) {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Commands cannot be added to a CommandGroup "
- "while the group is running");
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Commands cannot be added to a CommandGroup "
+ "while the group is running");
}
for (auto&& command : commands) {
@@ -61,10 +62,9 @@
m_runWhenDisabled &= command->RunsWhenDisabled();
m_commands.emplace_back(std::move(command));
} else {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Multiple commands in a parallel group cannot "
- "require the same subsystems");
- return;
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Multiple commands in a parallel group cannot "
+ "require the same subsystems");
}
}
}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp
index f29850b..bd8bb93 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/PerpetualCommand.cpp
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/PerpetualCommand.h"
using namespace frc2;
PerpetualCommand::PerpetualCommand(std::unique_ptr<Command>&& command) {
- if (!CommandGroupBase::RequireUngrouped(command)) {
+ if (!CommandGroupBase::RequireUngrouped(*command)) {
return;
}
m_command = std::move(command);
@@ -18,8 +15,18 @@
AddRequirements(m_command->GetRequirements());
}
-void PerpetualCommand::Initialize() { m_command->Initialize(); }
+void PerpetualCommand::Initialize() {
+ m_command->Initialize();
+}
-void PerpetualCommand::Execute() { m_command->Execute(); }
+void PerpetualCommand::Execute() {
+ m_command->Execute();
+}
-void PerpetualCommand::End(bool interrupted) { m_command->End(interrupted); }
+void PerpetualCommand::End(bool interrupted) {
+ m_command->End(interrupted);
+}
+
+PerpetualCommand PerpetualCommand::Perpetually() && {
+ return std::move(*this);
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PrintCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PrintCommand.cpp
index e077760..8d7c855 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PrintCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/PrintCommand.cpp
@@ -1,18 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/PrintCommand.h"
-#include <wpi/raw_ostream.h>
+#include <fmt/format.h>
using namespace frc2;
-PrintCommand::PrintCommand(const wpi::Twine& message)
- : CommandHelper{[str = message.str()] { wpi::outs() << str << "\n"; }, {}} {
-}
+PrintCommand::PrintCommand(std::string_view message)
+ : CommandHelper{[str = std::string(message)] { fmt::print("{}\n", str); },
+ {}} {}
-bool PrintCommand::RunsWhenDisabled() const { return true; }
+bool PrintCommand::RunsWhenDisabled() const {
+ return true;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp
index 6f96315..116ce3c 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ProxyScheduleCommand.cpp
@@ -1,18 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/ProxyScheduleCommand.h"
using namespace frc2;
-ProxyScheduleCommand::ProxyScheduleCommand(wpi::ArrayRef<Command*> toSchedule) {
+ProxyScheduleCommand::ProxyScheduleCommand(
+ wpi::span<Command* const> toSchedule) {
SetInsert(m_toSchedule, toSchedule);
}
+ProxyScheduleCommand::ProxyScheduleCommand(Command* toSchedule) {
+ SetInsert(m_toSchedule, {&toSchedule, 1});
+}
+
void ProxyScheduleCommand::Initialize() {
for (auto* command : m_toSchedule) {
command->Schedule();
@@ -34,4 +36,6 @@
}
}
-bool ProxyScheduleCommand::IsFinished() { return m_finished; }
+bool ProxyScheduleCommand::IsFinished() {
+ return m_finished;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp
index e2c56ab..4674031 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/RamseteCommand.h"
+#include <utility>
+
using namespace frc2;
using namespace units;
@@ -19,15 +18,15 @@
frc2::PIDController leftController, frc2::PIDController rightController,
std::function<void(volt_t, volt_t)> output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_controller(controller),
m_feedforward(feedforward),
m_kinematics(kinematics),
- m_speeds(wheelSpeeds),
+ m_speeds(std::move(wheelSpeeds)),
m_leftController(std::make_unique<frc2::PIDController>(leftController)),
m_rightController(std::make_unique<frc2::PIDController>(rightController)),
- m_outputVolts(output),
+ m_outputVolts(std::move(output)),
m_usePID(true) {
AddRequirements(requirements);
}
@@ -40,16 +39,16 @@
std::function<frc::DifferentialDriveWheelSpeeds()> wheelSpeeds,
frc2::PIDController leftController, frc2::PIDController rightController,
std::function<void(volt_t, volt_t)> output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_controller(controller),
m_feedforward(feedforward),
m_kinematics(kinematics),
- m_speeds(wheelSpeeds),
+ m_speeds(std::move(wheelSpeeds)),
m_leftController(std::make_unique<frc2::PIDController>(leftController)),
m_rightController(std::make_unique<frc2::PIDController>(rightController)),
- m_outputVolts(output),
+ m_outputVolts(std::move(output)),
m_usePID(true) {
AddRequirements(requirements);
}
@@ -61,11 +60,11 @@
std::function<void(units::meters_per_second_t, units::meters_per_second_t)>
output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_controller(controller),
m_kinematics(kinematics),
- m_outputVel(output),
+ m_outputVel(std::move(output)),
m_usePID(false) {
AddRequirements(requirements);
}
@@ -76,18 +75,18 @@
frc::DifferentialDriveKinematics kinematics,
std::function<void(units::meters_per_second_t, units::meters_per_second_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_controller(controller),
m_kinematics(kinematics),
- m_outputVel(output),
+ m_outputVel(std::move(output)),
m_usePID(false) {
AddRequirements(requirements);
}
void RamseteCommand::Initialize() {
- m_prevTime = 0_s;
+ m_prevTime = -1_s;
auto initialState = m_trajectory.Sample(0_s);
m_prevSpeeds = m_kinematics.ToWheelSpeeds(
frc::ChassisSpeeds{initialState.velocity, 0_mps,
@@ -104,6 +103,17 @@
auto curTime = m_timer.Get();
auto dt = curTime - m_prevTime;
+ if (m_prevTime < 0_s) {
+ if (m_usePID) {
+ m_outputVolts(0_V, 0_V);
+ } else {
+ m_outputVel(0_mps, 0_mps);
+ }
+
+ m_prevTime = curTime;
+ return;
+ }
+
auto targetWheelSpeeds = m_kinematics.ToWheelSpeeds(
m_controller.Calculate(m_pose(), m_trajectory.Sample(curTime)));
@@ -116,26 +126,35 @@
targetWheelSpeeds.right,
(targetWheelSpeeds.right - m_prevSpeeds.right) / dt);
- auto leftOutput = volt_t(m_leftController->Calculate(
- m_speeds().left.to<double>(),
- targetWheelSpeeds.left.to<double>())) +
- leftFeedforward;
+ auto leftOutput =
+ volt_t(m_leftController->Calculate(m_speeds().left.value(),
+ targetWheelSpeeds.left.value())) +
+ leftFeedforward;
- auto rightOutput = volt_t(m_rightController->Calculate(
- m_speeds().right.to<double>(),
- targetWheelSpeeds.right.to<double>())) +
- rightFeedforward;
+ auto rightOutput =
+ volt_t(m_rightController->Calculate(m_speeds().right.value(),
+ targetWheelSpeeds.right.value())) +
+ rightFeedforward;
m_outputVolts(leftOutput, rightOutput);
} else {
m_outputVel(targetWheelSpeeds.left, targetWheelSpeeds.right);
}
-
- m_prevTime = curTime;
m_prevSpeeds = targetWheelSpeeds;
+ m_prevTime = curTime;
}
-void RamseteCommand::End(bool interrupted) { m_timer.Stop(); }
+void RamseteCommand::End(bool interrupted) {
+ m_timer.Stop();
+
+ if (interrupted) {
+ if (m_usePID) {
+ m_outputVolts(0_V, 0_V);
+ } else {
+ m_outputVel(0_mps, 0_mps);
+ }
+ }
+}
bool RamseteCommand::IsFinished() {
return m_timer.HasElapsed(m_trajectory.TotalTime());
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp
index dff0ffe..c63e5d6 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/RunCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/RunCommand.h"
@@ -16,9 +13,11 @@
}
RunCommand::RunCommand(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements)
+ wpi::span<Subsystem* const> requirements)
: m_toRun{std::move(toRun)} {
AddRequirements(requirements);
}
-void RunCommand::Execute() { m_toRun(); }
+void RunCommand::Execute() {
+ m_toRun();
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp
index ea1ea8d..ff50bc5 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ScheduleCommand.cpp
@@ -1,24 +1,29 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/ScheduleCommand.h"
using namespace frc2;
-ScheduleCommand::ScheduleCommand(wpi::ArrayRef<Command*> toSchedule) {
+ScheduleCommand::ScheduleCommand(wpi::span<Command* const> toSchedule) {
SetInsert(m_toSchedule, toSchedule);
}
+ScheduleCommand::ScheduleCommand(Command* toSchedule) {
+ SetInsert(m_toSchedule, {&toSchedule, 1});
+}
+
void ScheduleCommand::Initialize() {
for (auto command : m_toSchedule) {
command->Schedule();
}
}
-bool ScheduleCommand::IsFinished() { return true; }
+bool ScheduleCommand::IsFinished() {
+ return true;
+}
-bool ScheduleCommand::RunsWhenDisabled() const { return true; }
+bool ScheduleCommand::RunsWhenDisabled() const {
+ return true;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp
index 1aa19e4..345a415 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/SequentialCommandGroup.h"
+#include "frc2/command/InstantCommand.h"
+
using namespace frc2;
SequentialCommandGroup::SequentialCommandGroup(
@@ -23,7 +22,9 @@
}
void SequentialCommandGroup::Execute() {
- if (m_commands.empty()) return;
+ if (m_commands.empty()) {
+ return;
+ }
auto& currentCommand = m_commands[m_currentCommandIndex];
@@ -61,9 +62,9 @@
}
if (m_currentCommandIndex != invalid_index) {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Commands cannot be added to a CommandGroup "
- "while the group is running");
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Commands cannot be added to a CommandGroup "
+ "while the group is running");
}
for (auto&& command : commands) {
@@ -73,3 +74,33 @@
m_commands.emplace_back(std::move(command));
}
}
+
+SequentialCommandGroup SequentialCommandGroup::BeforeStarting(
+ std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
+ // store all the commands
+ std::vector<std::unique_ptr<Command>> tmp;
+ tmp.emplace_back(
+ std::make_unique<InstantCommand>(std::move(toRun), requirements));
+ for (auto&& command : m_commands) {
+ command->SetGrouped(false);
+ tmp.emplace_back(std::move(command));
+ }
+
+ // reset current state
+ m_commands.clear();
+ m_requirements.clear();
+ m_runWhenDisabled = true;
+
+ // add the commands back
+ AddCommands(std::move(tmp));
+ return std::move(*this);
+}
+
+SequentialCommandGroup SequentialCommandGroup::AndThen(
+ std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
+ std::vector<std::unique_ptr<Command>> tmp;
+ tmp.emplace_back(
+ std::make_unique<InstantCommand>(std::move(toRun), requirements));
+ AddCommands(std::move(tmp));
+ return std::move(*this);
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp
index ad54ae0..dc40200 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/StartEndCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/StartEndCommand.h"
@@ -18,7 +15,7 @@
StartEndCommand::StartEndCommand(std::function<void()> onInit,
std::function<void()> onEnd,
- wpi::ArrayRef<Subsystem*> requirements)
+ wpi::span<Subsystem* const> requirements)
: m_onInit{std::move(onInit)}, m_onEnd{std::move(onEnd)} {
AddRequirements(requirements);
}
@@ -29,6 +26,10 @@
m_onEnd = other.m_onEnd;
}
-void StartEndCommand::Initialize() { m_onInit(); }
+void StartEndCommand::Initialize() {
+ m_onInit();
+}
-void StartEndCommand::End(bool interrupted) { m_onEnd(); }
+void StartEndCommand::End(bool interrupted) {
+ m_onEnd();
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp
index 010fcb1..51cbddf 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Subsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/Subsystem.h"
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/SubsystemBase.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/SubsystemBase.cpp
index a28de20..8216a07 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/SubsystemBase.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/SubsystemBase.cpp
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/SubsystemBase.h"
-#include <frc/smartdashboard/SendableBuilder.h>
-#include <frc/smartdashboard/SendableRegistry.h>
+#include <wpi/sendable/SendableBuilder.h>
+#include <wpi/sendable/SendableRegistry.h>
#include "frc2/command/Command.h"
#include "frc2/command/CommandScheduler.h"
@@ -16,11 +13,11 @@
using namespace frc2;
SubsystemBase::SubsystemBase() {
- frc::SendableRegistry::GetInstance().AddLW(this, GetTypeName(*this));
+ wpi::SendableRegistry::AddLW(this, GetTypeName(*this));
CommandScheduler::GetInstance().RegisterSubsystem({this});
}
-void SubsystemBase::InitSendable(frc::SendableBuilder& builder) {
+void SubsystemBase::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Subsystem");
builder.AddBooleanProperty(
".hasDefault", [this] { return GetDefaultCommand() != nullptr; },
@@ -29,7 +26,9 @@
".default",
[this]() -> std::string {
auto command = GetDefaultCommand();
- if (command == nullptr) return "none";
+ if (command == nullptr) {
+ return "none";
+ }
return command->GetName();
},
nullptr);
@@ -40,29 +39,30 @@
".command",
[this]() -> std::string {
auto command = GetCurrentCommand();
- if (command == nullptr) return "none";
+ if (command == nullptr) {
+ return "none";
+ }
return command->GetName();
},
nullptr);
}
std::string SubsystemBase::GetName() const {
- return frc::SendableRegistry::GetInstance().GetName(this);
+ return wpi::SendableRegistry::GetName(this);
}
-void SubsystemBase::SetName(const wpi::Twine& name) {
- frc::SendableRegistry::GetInstance().SetName(this, name);
+void SubsystemBase::SetName(std::string_view name) {
+ wpi::SendableRegistry::SetName(this, name);
}
std::string SubsystemBase::GetSubsystem() const {
- return frc::SendableRegistry::GetInstance().GetSubsystem(this);
+ return wpi::SendableRegistry::GetSubsystem(this);
}
-void SubsystemBase::SetSubsystem(const wpi::Twine& name) {
- frc::SendableRegistry::GetInstance().SetSubsystem(this, name);
+void SubsystemBase::SetSubsystem(std::string_view name) {
+ wpi::SendableRegistry::SetSubsystem(this, name);
}
-void SubsystemBase::AddChild(std::string name, frc::Sendable* child) {
- auto& registry = frc::SendableRegistry::GetInstance();
- registry.AddLW(child, GetSubsystem(), name);
+void SubsystemBase::AddChild(std::string name, wpi::Sendable* child) {
+ wpi::SendableRegistry::AddLW(child, GetSubsystem(), name);
}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitCommand.cpp
index 5c49bee..da03540 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitCommand.cpp
@@ -1,17 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/WaitCommand.h"
+#include <fmt/format.h>
+#include <frc/fmt/Units.h>
+
using namespace frc2;
WaitCommand::WaitCommand(units::second_t duration) : m_duration{duration} {
- auto durationStr = std::to_string(duration.to<double>());
- SetName(wpi::Twine(GetName()) + ": " + wpi::Twine(durationStr) + " seconds");
+ SetName(fmt::format("{}: {}", GetName(), duration));
}
void WaitCommand::Initialize() {
@@ -19,8 +18,14 @@
m_timer.Start();
}
-void WaitCommand::End(bool interrupted) { m_timer.Stop(); }
+void WaitCommand::End(bool interrupted) {
+ m_timer.Stop();
+}
-bool WaitCommand::IsFinished() { return m_timer.HasElapsed(m_duration); }
+bool WaitCommand::IsFinished() {
+ return m_timer.HasElapsed(m_duration);
+}
-bool WaitCommand::RunsWhenDisabled() const { return true; }
+bool WaitCommand::RunsWhenDisabled() const {
+ return true;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitUntilCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitUntilCommand.cpp
index 739a049..9ccd94e 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitUntilCommand.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/WaitUntilCommand.cpp
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/WaitUntilCommand.h"
-#include "frc2/Timer.h"
+#include <frc/Timer.h>
using namespace frc2;
@@ -15,8 +12,12 @@
: m_condition{std::move(condition)} {}
WaitUntilCommand::WaitUntilCommand(units::second_t time)
- : m_condition{[=] { return Timer::GetMatchTime() - time > 0_s; }} {}
+ : m_condition{[=] { return frc::Timer::GetMatchTime() - time > 0_s; }} {}
-bool WaitUntilCommand::IsFinished() { return m_condition(); }
+bool WaitUntilCommand::IsFinished() {
+ return m_condition();
+}
-bool WaitUntilCommand::RunsWhenDisabled() const { return true; }
+bool WaitUntilCommand::RunsWhenDisabled() const {
+ return true;
+}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp
index d8a7372..955830a 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Button.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/button/Button.h"
@@ -23,7 +20,7 @@
}
Button Button::WhenPressed(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements) {
+ wpi::span<Subsystem* const> requirements) {
WhenActive(std::move(toRun), requirements);
return *this;
}
@@ -40,7 +37,7 @@
}
Button Button::WhileHeld(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements) {
+ wpi::span<Subsystem* const> requirements) {
WhileActiveContinous(std::move(toRun), requirements);
return *this;
}
@@ -62,7 +59,7 @@
}
Button Button::WhenReleased(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements) {
+ wpi::span<Subsystem* const> requirements) {
WhenInactive(std::move(toRun), requirements);
return *this;
}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/NetworkButton.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/NetworkButton.cpp
index 01214e0..3886c62 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/NetworkButton.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/NetworkButton.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/button/NetworkButton.h"
@@ -15,9 +12,9 @@
}) {}
NetworkButton::NetworkButton(std::shared_ptr<nt::NetworkTable> table,
- const wpi::Twine& field)
+ std::string_view field)
: NetworkButton(table->GetEntry(field)) {}
-NetworkButton::NetworkButton(const wpi::Twine& table, const wpi::Twine& field)
+NetworkButton::NetworkButton(std::string_view table, std::string_view field)
: NetworkButton(nt::NetworkTableInstance::GetDefault().GetTable(table),
field) {}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp
index 875b54e..0801549 100644
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp
+++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/Trigger.cpp
@@ -1,17 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/button/Trigger.h"
+#include <frc/Debouncer.h>
+
#include "frc2/command/InstantCommand.h"
using namespace frc2;
-Trigger::Trigger(const Trigger& other) : m_isActive(other.m_isActive) {}
+Trigger::Trigger(const Trigger& other) = default;
Trigger Trigger::WhenActive(Command* command, bool interruptible) {
CommandScheduler::GetInstance().AddButton(
@@ -30,12 +29,12 @@
Trigger Trigger::WhenActive(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) {
- return WhenActive(std::move(toRun), wpi::makeArrayRef(requirements.begin(),
- requirements.end()));
+ return WhenActive(std::move(toRun),
+ {requirements.begin(), requirements.end()});
}
Trigger Trigger::WhenActive(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements) {
+ wpi::span<Subsystem* const> requirements) {
return WhenActive(InstantCommand(std::move(toRun), requirements));
}
@@ -58,13 +57,12 @@
Trigger Trigger::WhileActiveContinous(
std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) {
- return WhileActiveContinous(
- std::move(toRun),
- wpi::makeArrayRef(requirements.begin(), requirements.end()));
+ return WhileActiveContinous(std::move(toRun),
+ {requirements.begin(), requirements.end()});
}
-Trigger Trigger::WhileActiveContinous(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements) {
+Trigger Trigger::WhileActiveContinous(
+ std::function<void()> toRun, wpi::span<Subsystem* const> requirements) {
return WhileActiveContinous(InstantCommand(std::move(toRun), requirements));
}
@@ -100,12 +98,12 @@
Trigger Trigger::WhenInactive(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) {
- return WhenInactive(std::move(toRun), wpi::makeArrayRef(requirements.begin(),
- requirements.end()));
+ return WhenInactive(std::move(toRun),
+ {requirements.begin(), requirements.end()});
}
Trigger Trigger::WhenInactive(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements) {
+ wpi::span<Subsystem* const> requirements) {
return WhenInactive(InstantCommand(std::move(toRun), requirements));
}
@@ -140,3 +138,9 @@
});
return *this;
}
+
+Trigger Trigger::Debounce(units::second_t debounceTime) {
+ return Trigger([debouncer = frc::Debouncer(debounceTime), *this]() mutable {
+ return debouncer.Calculate(m_isActive());
+ });
+}
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h
index 060832c..66f4f7e 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -12,11 +9,10 @@
#include <memory>
#include <string>
-#include <frc/ErrorBase.h>
#include <units/time.h>
-#include <wpi/ArrayRef.h>
#include <wpi/Demangle.h>
#include <wpi/SmallSet.h>
+#include <wpi/span.h>
#include "frc2/command/Subsystem.h"
@@ -49,13 +45,13 @@
* @see CommandScheduler
* @see CommandHelper
*/
-class Command : public frc::ErrorBase {
+class Command {
public:
Command() = default;
virtual ~Command();
- Command(const Command&);
- Command& operator=(const Command&);
+ Command(const Command&) = default;
+ Command& operator=(const Command& rhs);
Command(Command&&) = default;
Command& operator=(Command&&) = default;
@@ -111,7 +107,7 @@
* @param duration the timeout duration
* @return the command with the timeout added
*/
- ParallelRaceGroup WithTimeout(units::second_t duration) &&;
+ virtual ParallelRaceGroup WithTimeout(units::second_t duration) &&;
/**
* Decorates this command with an interrupt condition. If the specified
@@ -122,7 +118,7 @@
* @param condition the interrupt condition
* @return the command with the interrupt condition added
*/
- ParallelRaceGroup WithInterrupt(std::function<bool()> condition) &&;
+ virtual ParallelRaceGroup WithInterrupt(std::function<bool()> condition) &&;
/**
* Decorates this command with a runnable to run before this command starts.
@@ -131,7 +127,7 @@
* @param requirements the required subsystems
* @return the decorated command
*/
- SequentialCommandGroup BeforeStarting(
+ virtual SequentialCommandGroup BeforeStarting(
std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) &&;
@@ -142,9 +138,9 @@
* @param requirements the required subsystems
* @return the decorated command
*/
- SequentialCommandGroup BeforeStarting(
+ virtual SequentialCommandGroup BeforeStarting(
std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {}) &&;
+ wpi::span<Subsystem* const> requirements = {}) &&;
/**
* Decorates this command with a runnable to run after the command finishes.
@@ -153,7 +149,7 @@
* @param requirements the required subsystems
* @return the decorated command
*/
- SequentialCommandGroup AndThen(
+ virtual SequentialCommandGroup AndThen(
std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) &&;
@@ -164,9 +160,9 @@
* @param requirements the required subsystems
* @return the decorated command
*/
- SequentialCommandGroup AndThen(
+ virtual SequentialCommandGroup AndThen(
std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {}) &&;
+ wpi::span<Subsystem* const> requirements = {}) &&;
/**
* Decorates this command to run perpetually, ignoring its ordinary end
@@ -174,17 +170,17 @@
*
* @return the decorated command
*/
- PerpetualCommand Perpetually() &&;
+ virtual PerpetualCommand Perpetually() &&;
/**
- * Decorates this command to run "by proxy" by wrapping it in a {@link
- * ProxyScheduleCommand}. This is useful for "forking off" from command groups
+ * Decorates this command to run "by proxy" by wrapping it in a
+ * ProxyScheduleCommand. This is useful for "forking off" from command groups
* when the user does not wish to extend the command's requirements to the
* entire command group.
*
* @return the decorated command
*/
- ProxyScheduleCommand AsProxy();
+ virtual ProxyScheduleCommand AsProxy();
/**
* Schedules this command.
@@ -215,11 +211,9 @@
bool IsScheduled() const;
/**
- * Whether the command requires a given subsystem. Named "hasRequirement"
- * rather than "requires" to avoid confusion with
- * {@link
- * edu.wpi.first.wpilibj.command.Command#requires(edu.wpi.first.wpilibj.command.Subsystem)}
- * - this may be able to be changed in a few years.
+ * Whether the command requires a given subsystem. Named "HasRequirement"
+ * rather than "requires" to avoid confusion with Command::Requires(Subsystem)
+ * -- this may be able to be changed in a few years.
*
* @param requirement the subsystem to inquire about
* @return whether the subsystem is required
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h
index 481a51a..9a498bc 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandBase.h
@@ -1,20 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <initializer_list>
#include <string>
+#include <string_view>
-#include <frc/smartdashboard/Sendable.h>
-#include <frc/smartdashboard/SendableHelper.h>
-#include <wpi/ArrayRef.h>
#include <wpi/SmallSet.h>
-#include <wpi/Twine.h>
+#include <wpi/sendable/Sendable.h>
+#include <wpi/sendable/SendableHelper.h>
+#include <wpi/span.h>
#include "frc2/command/Command.h"
@@ -23,25 +20,42 @@
* A Sendable base class for Commands.
*/
class CommandBase : public Command,
- public frc::Sendable,
- public frc::SendableHelper<CommandBase> {
+ public wpi::Sendable,
+ public wpi::SendableHelper<CommandBase> {
public:
/**
- * Adds the specified requirements to the command.
+ * Adds the specified Subsystem requirements to the command.
*
- * @param requirements the requirements to add
+ * @param requirements the Subsystem requirements to add
*/
void AddRequirements(std::initializer_list<Subsystem*> requirements);
/**
- * Adds the specified requirements to the command.
+ * Adds the specified Subsystem requirements to the command.
*
- * @param requirements the requirements to add
+ * @param requirements the Subsystem requirements to add
*/
- void AddRequirements(wpi::ArrayRef<Subsystem*> requirements);
+ void AddRequirements(wpi::span<Subsystem* const> requirements);
+ /**
+ * Adds the specified Subsystem requirements to the command.
+ *
+ * @param requirements the Subsystem requirements to add
+ */
void AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements);
+ /**
+ * Adds the specified Subsystem requirement to the command.
+ *
+ * @param requirement the Subsystem requirement to add
+ */
+ void AddRequirements(Subsystem* requirement);
+
+ /**
+ * Gets the Subsystem requirements of the command.
+ *
+ * @return the Command's Subsystem requirements
+ */
wpi::SmallSet<Subsystem*, 4> GetRequirements() const override;
/**
@@ -49,7 +63,7 @@
*
* @param name name
*/
- void SetName(const wpi::Twine& name);
+ void SetName(std::string_view name);
/**
* Gets the name of this Command.
@@ -70,9 +84,9 @@
*
* @param subsystem subsystem name
*/
- void SetSubsystem(const wpi::Twine& subsystem);
+ void SetSubsystem(std::string_view subsystem);
- void InitSendable(frc::SendableBuilder& builder) override;
+ void InitSendable(wpi::SendableBuilder& builder) override;
protected:
CommandBase();
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h
index 8b04b4c..6a84ee0 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandGroupBase.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,7 +8,7 @@
#include <memory>
#include <vector>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
@@ -28,10 +25,19 @@
* Requires that the specified command not have been already allocated to a
* CommandGroup. Reports an error if the command is already grouped.
*
- * @param commands The command to check
+ * @param command The command to check
* @return True if all the command is ungrouped.
*/
- static bool RequireUngrouped(Command& command);
+ static bool RequireUngrouped(const Command& command);
+
+ /**
+ * Requires that the specified command not have been already allocated to a
+ * CommandGroup. Reports an error if the command is already grouped.
+ *
+ * @param command The command to check
+ * @return True if all the command is ungrouped.
+ */
+ static bool RequireUngrouped(const Command* command);
/**
* Requires that the specified commands not have been already allocated to a
@@ -40,7 +46,8 @@
* @param commands The commands to check
* @return True if all the commands are ungrouped.
*/
- static bool RequireUngrouped(wpi::ArrayRef<std::unique_ptr<Command>>);
+ static bool RequireUngrouped(
+ wpi::span<const std::unique_ptr<Command>> commands);
/**
* Requires that the specified commands not have been already allocated to a
@@ -49,7 +56,7 @@
* @param commands The commands to check
* @return True if all the commands are ungrouped.
*/
- static bool RequireUngrouped(std::initializer_list<Command*>);
+ static bool RequireUngrouped(std::initializer_list<const Command*> commands);
/**
* Adds the given commands to the command group.
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h
index f78a848..5709f0c 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandHelper.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h
index 4711695..8976e85 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,14 +8,13 @@
#include <memory>
#include <utility>
-#include <frc/ErrorBase.h>
-#include <frc/WPIErrors.h>
+#include <frc/Errors.h>
#include <frc/Watchdog.h>
-#include <frc/smartdashboard/Sendable.h>
-#include <frc/smartdashboard/SendableHelper.h>
+#include <networktables/NTSendable.h>
#include <units/time.h>
-#include <wpi/ArrayRef.h>
#include <wpi/FunctionExtras.h>
+#include <wpi/sendable/SendableHelper.h>
+#include <wpi/span.h>
namespace frc2 {
class Command;
@@ -31,9 +27,8 @@
* with the scheduler using RegisterSubsystem() in order for their Periodic()
* methods to be called and for their default commands to be scheduled.
*/
-class CommandScheduler final : public frc::Sendable,
- public frc::ErrorBase,
- public frc::SendableHelper<CommandScheduler> {
+class CommandScheduler final : public nt::NTSendable,
+ public wpi::SendableHelper<CommandScheduler> {
public:
/**
* Returns the Scheduler instance.
@@ -42,7 +37,7 @@
*/
static CommandScheduler& GetInstance();
- ~CommandScheduler();
+ ~CommandScheduler() override;
CommandScheduler(const CommandScheduler&) = delete;
CommandScheduler& operator=(const CommandScheduler&) = delete;
@@ -97,7 +92,7 @@
* @param interruptible whether the commands should be interruptible
* @param commands the commands to schedule
*/
- void Schedule(bool interruptible, wpi::ArrayRef<Command*> commands);
+ void Schedule(bool interruptible, wpi::span<Command* const> commands);
/**
* Schedules multiple commands for execution. Does nothing if the command is
@@ -117,7 +112,7 @@
*
* @param commands the commands to schedule
*/
- void Schedule(wpi::ArrayRef<Command*> commands);
+ void Schedule(wpi::span<Command* const> commands);
/**
* Schedules multiple commands for execution, with interruptible defaulted to
@@ -165,10 +160,10 @@
void UnregisterSubsystem(Subsystem* subsystem);
void RegisterSubsystem(std::initializer_list<Subsystem*> subsystems);
- void RegisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems);
+ void RegisterSubsystem(wpi::span<Subsystem* const> subsystems);
void UnregisterSubsystem(std::initializer_list<Subsystem*> subsystems);
- void UnregisterSubsystem(wpi::ArrayRef<Subsystem*> subsystems);
+ void UnregisterSubsystem(wpi::span<Subsystem* const> subsystems);
/**
* Sets the default command for a subsystem. Registers that subsystem if it
@@ -185,14 +180,12 @@
Command, std::remove_reference_t<T>>>>
void SetDefaultCommand(Subsystem* subsystem, T&& defaultCommand) {
if (!defaultCommand.HasRequirement(subsystem)) {
- wpi_setWPIErrorWithContext(
- CommandIllegalUse, "Default commands must require their subsystem!");
- return;
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Default commands must require their subsystem!");
}
if (defaultCommand.IsFinished()) {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Default commands should not end!");
- return;
+ throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
+ "Default commands should not end!");
}
SetDefaultCommandImpl(subsystem,
std::make_unique<std::remove_reference_t<T>>(
@@ -216,7 +209,7 @@
* <p>Commands will be canceled even if they are not scheduled as
* interruptible.
*
- * @param commands the commands to cancel
+ * @param command the command to cancel
*/
void Cancel(Command* command);
@@ -230,7 +223,7 @@
*
* @param commands the commands to cancel
*/
- void Cancel(wpi::ArrayRef<Command*> commands);
+ void Cancel(wpi::span<Command* const> commands);
/**
* Cancels commands. The scheduler will only call Command::End()
@@ -256,9 +249,9 @@
* them.
*
* @param command the command to query
- * @return the time since the command was scheduled, in seconds
+ * @return the time since the command was scheduled
*/
- double TimeSinceScheduled(const Command* command) const;
+ units::second_t TimeSinceScheduled(const Command* command) const;
/**
* Whether the given commands are running. Note that this only works on
@@ -268,7 +261,7 @@
* @param commands the command to query
* @return whether the command is currently scheduled
*/
- bool IsScheduled(wpi::ArrayRef<const Command*> commands) const;
+ bool IsScheduled(wpi::span<const Command* const> commands) const;
/**
* Whether the given commands are running. Note that this only works on
@@ -285,7 +278,7 @@
* that are directly scheduled by the scheduler; it will not work on commands
* inside of CommandGroups, as the scheduler does not see them.
*
- * @param commands the command to query
+ * @param command the command to query
* @return whether the command is currently scheduled
*/
bool IsScheduled(const Command* command) const;
@@ -339,7 +332,7 @@
*/
void OnCommandFinish(Action action);
- void InitSendable(frc::SendableBuilder& builder) override;
+ void InitSendable(nt::NTSendableBuilder& builder) override;
private:
// Constructor; private as this is a singleton
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandState.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandState.h
index 41fc5d0..4c731b3 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandState.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandState.h
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
+#include <units/time.h>
+
namespace frc2 {
/**
* Class that holds scheduling state for a command. Used internally by the
@@ -21,10 +20,10 @@
bool IsInterruptible() const { return m_interruptible; }
// The time since this command was initialized.
- double TimeSinceInitialized() const;
+ units::second_t TimeSinceInitialized() const;
private:
- double m_startTime = -1;
+ units::second_t m_startTime = -1_s;
bool m_interruptible;
void StartTiming();
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ConditionalCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ConditionalCommand.h
index af9f113..2c37200 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ConditionalCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ConditionalCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h
index eb88b5e..31b2ada 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/FunctionalCommand.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
#include <initializer_list>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -55,7 +52,7 @@
std::function<void()> onExecute,
std::function<void(bool)> onEnd,
std::function<bool()> isFinished,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
FunctionalCommand(FunctionalCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h
index 3f29b17..3aba587 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/InstantCommand.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
#include <initializer_list>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -40,8 +37,8 @@
* @param toRun the Runnable to run
* @param requirements the subsystems required by this command
*/
- InstantCommand(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ explicit InstantCommand(std::function<void()> toRun,
+ wpi::span<Subsystem* const> requirements = {});
InstantCommand(InstantCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h
index 87b16ee..29f0fd4 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h
@@ -1,15 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <cmath>
#include <functional>
#include <initializer_list>
#include <memory>
+#include <frc/Timer.h>
#include <frc/controller/HolonomicDriveController.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
@@ -23,19 +21,18 @@
#include <units/length.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "CommandBase.h"
#include "CommandHelper.h"
-#include "frc2/Timer.h"
#pragma once
namespace frc2 {
/**
- * A command that uses two PID controllers ({@link PIDController}) and a
- * ProfiledPIDController ({@link ProfiledPIDController}) to follow a trajectory
- * {@link Trajectory} with a mecanum drive.
+ * A command that uses two PID controllers (PIDController) and a profiled PID
+ * controller (ProfiledPIDController) to follow a trajectory (Trajectory) with a
+ * mecanum drive.
*
* <p>The command handles trajectory-following,
* Velocity PID calculations, and feedforwards internally. This
@@ -207,7 +204,7 @@
std::function<void(units::volt_t, units::volt_t, units::volt_t,
units::volt_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new MecanumControllerCommand that when executed will follow
@@ -260,7 +257,7 @@
std::function<void(units::volt_t, units::volt_t, units::volt_t,
units::volt_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new MecanumControllerCommand that when executed will follow
@@ -376,7 +373,7 @@
units::meters_per_second_t,
units::meters_per_second_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new MecanumControllerCommand that when executed will follow
@@ -416,7 +413,7 @@
units::meters_per_second_t,
units::meters_per_second_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
void Initialize() override;
@@ -447,7 +444,7 @@
m_outputVolts;
bool m_usePID;
- frc2::Timer m_timer;
+ frc::Timer m_timer;
frc::MecanumDriveWheelSpeeds m_prevSpeeds;
units::second_t m_prevTime;
};
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h
index 1c6d776..ec68fe7 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/NotifierCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -12,7 +9,7 @@
#include <frc/Notifier.h>
#include <units/time.h>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -20,9 +17,9 @@
namespace frc2 {
/**
* A command that starts a notifier to run the given runnable periodically in a
- * separate thread. Has no end condition as-is; either subclass it or use {@link
- * Command#withTimeout(double)} or
- * {@link Command#withInterrupt(BooleanSupplier)} to give it one.
+ * separate thread. Has no end condition as-is; either subclass it or use
+ * Command::WithTimeout(double) or Command::WithInterrupt(BooleanSupplier) to
+ * give it one.
*
* <p>WARNING: Do not use this class unless you are confident in your ability to
* make the executed code thread-safe. If you do not know what "thread-safe"
@@ -48,7 +45,7 @@
* @param requirements the subsystems required by this command
*/
NotifierCommand(std::function<void()> toRun, units::second_t period,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
NotifierCommand(NotifierCommand&& other);
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h
index 8653313..31baf9e 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,6 +8,7 @@
#include <initializer_list>
#include <frc/controller/PIDController.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -56,7 +54,7 @@
std::function<double()> measurementSource,
std::function<double()> setpointSource,
std::function<void(double)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Creates a new PIDCommand, which controls the given output with a
@@ -86,7 +84,7 @@
PIDCommand(PIDController controller,
std::function<double()> measurementSource, double setpoint,
std::function<void(double)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
PIDCommand(PIDCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/PIDSubsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/PIDSubsystem.h
index 608fe56..c8a53db 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/PIDSubsystem.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/PIDSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ParallelCommandGroup.h b/wpilibNewCommands/src/main/native/include/frc2/command/ParallelCommandGroup.h
index 5b0f0da..342265a 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ParallelCommandGroup.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ParallelCommandGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -86,7 +83,7 @@
bool RunsWhenDisabled() const override;
private:
- void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
+ void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
bool m_runWhenDisabled{true};
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ParallelDeadlineGroup.h b/wpilibNewCommands/src/main/native/include/frc2/command/ParallelDeadlineGroup.h
index 4debe75..af78c3b 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ParallelDeadlineGroup.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ParallelDeadlineGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -94,7 +91,7 @@
bool RunsWhenDisabled() const override;
private:
- void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
+ void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
void SetDeadline(std::unique_ptr<Command>&& deadline);
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ParallelRaceGroup.h b/wpilibNewCommands/src/main/native/include/frc2/command/ParallelRaceGroup.h
index 167dee4..3ba3907 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ParallelRaceGroup.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ParallelRaceGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -74,7 +71,7 @@
bool RunsWhenDisabled() const override;
private:
- void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
+ void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
std::vector<std::unique_ptr<Command>> m_commands;
bool m_runWhenDisabled{true};
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/PerpetualCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/PerpetualCommand.h
index 4a93704..a288ae2 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/PerpetualCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/PerpetualCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -68,6 +65,8 @@
void End(bool interrupted) override;
+ PerpetualCommand Perpetually() && override;
+
private:
std::unique_ptr<Command> m_command;
};
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/PrintCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/PrintCommand.h
index 7b706a0..536e77f 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/PrintCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/PrintCommand.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <wpi/Twine.h>
+#include <string_view>
#include "frc2/command/CommandHelper.h"
#include "frc2/command/InstantCommand.h"
@@ -23,7 +20,7 @@
*
* @param message the message to print
*/
- explicit PrintCommand(const wpi::Twine& message);
+ explicit PrintCommand(std::string_view message);
PrintCommand(PrintCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h
index 5bc4978..b02c81d 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -13,7 +10,7 @@
#include <frc/controller/ProfiledPIDController.h>
#include <units/time.h>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -73,7 +70,7 @@
std::function<Distance_t()> measurementSource,
std::function<State()> goalSource,
std::function<void(double, State)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements = {})
+ wpi::span<Subsystem* const> requirements = {})
: m_controller{controller},
m_measurement{std::move(measurementSource)},
m_goal{std::move(goalSource)},
@@ -117,7 +114,7 @@
std::function<Distance_t()> measurementSource,
std::function<Distance_t()> goalSource,
std::function<void(double, State)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements = {})
+ wpi::span<Subsystem* const> requirements = {})
: ProfiledPIDCommand(
controller, measurementSource,
[&goalSource]() {
@@ -156,7 +153,7 @@
ProfiledPIDCommand(frc::ProfiledPIDController<Distance> controller,
std::function<Distance_t()> measurementSource, State goal,
std::function<void(double, State)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements = {})
+ wpi::span<Subsystem* const> requirements = {})
: ProfiledPIDCommand(
controller, measurementSource, [goal] { return goal; }, useOutput,
requirements) {}
@@ -194,7 +191,7 @@
std::function<Distance_t()> measurementSource,
Distance_t goal,
std::function<void(double, State)> useOutput,
- wpi::ArrayRef<Subsystem*> requirements = {})
+ wpi::span<Subsystem* const> requirements = {})
: ProfiledPIDCommand(
controller, measurementSource, [goal] { return goal; }, useOutput,
requirements) {}
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDSubsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDSubsystem.h
index 2bbe149..c8639b6 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDSubsystem.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h
index ef5204f..ad603f9 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ProxyScheduleCommand.h
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -30,7 +27,9 @@
*
* @param toSchedule the commands to schedule
*/
- explicit ProxyScheduleCommand(wpi::ArrayRef<Command*> toSchedule);
+ explicit ProxyScheduleCommand(wpi::span<Command* const> toSchedule);
+
+ explicit ProxyScheduleCommand(Command* toSchedule);
ProxyScheduleCommand(ProxyScheduleCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h
index 21d5cfd..5f84997 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/RamseteCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,6 +8,7 @@
#include <initializer_list>
#include <memory>
+#include <frc/Timer.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/RamseteController.h>
#include <frc/controller/SimpleMotorFeedforward.h>
@@ -19,9 +17,8 @@
#include <frc/trajectory/Trajectory.h>
#include <units/length.h>
#include <units/voltage.h>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
-#include "frc2/Timer.h"
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -117,7 +114,7 @@
frc2::PIDController leftController,
frc2::PIDController rightController,
std::function<void(units::volt_t, units::volt_t)> output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new RamseteCommand that, when executed, will follow the
@@ -165,7 +162,7 @@
std::function<void(units::meters_per_second_t,
units::meters_per_second_t)>
output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
void Initialize() override;
@@ -188,7 +185,7 @@
std::function<void(units::meters_per_second_t, units::meters_per_second_t)>
m_outputVel;
- Timer m_timer;
+ frc::Timer m_timer;
units::second_t m_prevTime;
frc::DifferentialDriveWheelSpeeds m_prevSpeeds;
bool m_usePID;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h
index 2036230..510840e 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/RunCommand.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
#include <initializer_list>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -41,14 +38,14 @@
* @param toRun the Runnable to run
* @param requirements the subsystems to require
*/
- RunCommand(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ explicit RunCommand(std::function<void()> toRun,
+ wpi::span<Subsystem* const> requirements = {});
RunCommand(RunCommand&& other) = default;
RunCommand(const RunCommand& other) = default;
- void Execute();
+ void Execute() override;
protected:
std::function<void()> m_toRun;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h
index c2824ca..ca476d0 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/ScheduleCommand.h
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -29,7 +26,9 @@
*
* @param toSchedule the commands to schedule
*/
- explicit ScheduleCommand(wpi::ArrayRef<Command*> toSchedule);
+ explicit ScheduleCommand(wpi::span<Command* const> toSchedule);
+
+ explicit ScheduleCommand(Command* toSchedule);
ScheduleCommand(ScheduleCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h
index e1074f4..b4e7f89 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/SelectCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -51,8 +48,8 @@
template <class... Types,
typename = std::enable_if_t<std::conjunction_v<
std::is_base_of<Command, std::remove_reference_t<Types>>...>>>
- SelectCommand(std::function<Key()> selector,
- std::pair<Key, Types>... commands)
+ explicit SelectCommand(std::function<Key()> selector,
+ std::pair<Key, Types>... commands)
: m_selector{std::move(selector)} {
std::vector<std::pair<Key, std::unique_ptr<Command>>> foo;
@@ -62,7 +59,7 @@
...);
for (auto&& command : foo) {
- if (!CommandGroupBase::RequireUngrouped(command.second)) {
+ if (!CommandGroupBase::RequireUngrouped(*command.second)) {
return;
}
}
@@ -79,7 +76,7 @@
std::vector<std::pair<Key, std::unique_ptr<Command>>>&& commands)
: m_selector{std::move(selector)} {
for (auto&& command : commands) {
- if (!CommandGroupBase::RequireUngrouped(command.second)) {
+ if (!CommandGroupBase::RequireUngrouped(*command.second)) {
return;
}
}
@@ -102,7 +99,8 @@
*
* @param toRun a supplier providing the command to run
*/
- explicit SelectCommand(std::function<Command*()> toRun) : m_toRun{toRun} {}
+ explicit SelectCommand(std::function<Command*()> toRun)
+ : m_toRun{std::move(toRun)} {}
SelectCommand(SelectCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h b/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h
index c49356e..d80c07b 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -18,9 +15,7 @@
#include <utility>
#include <vector>
-#include <frc/ErrorBase.h>
-#include <frc/WPIErrors.h>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandHelper.h"
@@ -91,6 +86,16 @@
bool RunsWhenDisabled() const override;
+ SequentialCommandGroup BeforeStarting(
+ std::function<void()> toRun,
+ wpi::span<Subsystem* const> requirements = {}) &&
+ override;
+
+ SequentialCommandGroup AndThen(
+ std::function<void()> toRun,
+ wpi::span<Subsystem* const> requirements = {}) &&
+ override;
+
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h b/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h
index d21f572..d40fbec 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/SetUtilities.h
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
+#include <wpi/span.h>
namespace frc2 {
template <typename T>
-void SetInsert(wpi::SmallVectorImpl<T*>& vector, wpi::ArrayRef<T*> toAdd) {
+void SetInsert(wpi::SmallVectorImpl<T*>& vector, wpi::span<T* const> toAdd) {
for (auto addCommand : toAdd) {
bool exists = false;
for (auto existingCommand : vector) {
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h
index 9b1252e..d364696 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/StartEndCommand.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
#include <initializer_list>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -45,7 +42,7 @@
* @param requirements the subsystems required by this command
*/
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
StartEndCommand(StartEndCommand&& other) = default;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h
index 3f8a278..4744463 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SubsystemBase.h b/wpilibNewCommands/src/main/native/include/frc2/command/SubsystemBase.h
index d75ad0d..748271a 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/SubsystemBase.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/SubsystemBase.h
@@ -1,16 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <string>
+#include <string_view>
-#include <frc/smartdashboard/Sendable.h>
-#include <frc/smartdashboard/SendableHelper.h>
+#include <wpi/sendable/Sendable.h>
+#include <wpi/sendable/SendableHelper.h>
#include "frc2/command/Subsystem.h"
@@ -20,10 +18,10 @@
* provides a more intuitive method for setting the default command.
*/
class SubsystemBase : public Subsystem,
- public frc::Sendable,
- public frc::SendableHelper<SubsystemBase> {
+ public wpi::Sendable,
+ public wpi::SendableHelper<SubsystemBase> {
public:
- void InitSendable(frc::SendableBuilder& builder) override;
+ void InitSendable(wpi::SendableBuilder& builder) override;
/**
* Gets the name of this Subsystem.
@@ -37,7 +35,7 @@
*
* @param name name
*/
- void SetName(const wpi::Twine& name);
+ void SetName(std::string_view name);
/**
* Gets the subsystem name of this Subsystem.
@@ -49,9 +47,9 @@
/**
* Sets the subsystem name of this Subsystem.
*
- * @param subsystem subsystem name
+ * @param name subsystem name
*/
- void SetSubsystem(const wpi::Twine& name);
+ void SetSubsystem(std::string_view name);
/**
* Associate a Sendable with this Subsystem.
@@ -60,7 +58,7 @@
* @param name name to give child
* @param child sendable
*/
- void AddChild(std::string name, frc::Sendable* child);
+ void AddChild(std::string name, wpi::Sendable* child);
protected:
SubsystemBase();
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h
index 6036ce8..9620fef 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h
@@ -1,15 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <cmath>
#include <functional>
#include <initializer_list>
#include <memory>
+#include <frc/Timer.h>
#include <frc/controller/HolonomicDriveController.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
@@ -21,20 +19,19 @@
#include <units/length.h>
#include <units/time.h>
#include <units/voltage.h>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "CommandBase.h"
#include "CommandHelper.h"
-#include "frc2/Timer.h"
#pragma once
namespace frc2 {
/**
- * A command that uses two PID controllers ({@link PIDController}) and a
- * ProfiledPIDController ({@link ProfiledPIDController}) to follow a trajectory
- * {@link Trajectory} with a swerve drive.
+ * A command that uses two PID controllers (PIDController) and a profiled PID
+ * controller (ProfiledPIDController) to follow a trajectory (Trajectory) with a
+ * swerve drive.
*
* <p>The command handles trajectory-following, Velocity PID calculations, and
* feedforwards internally. This is intended to be a more-or-less "complete
@@ -170,7 +167,7 @@
std::function<frc::Rotation2d()> desiredRotation,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)>
output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Constructs a new SwerveControllerCommand that when executed will follow the
@@ -208,7 +205,7 @@
frc::ProfiledPIDController<units::radians> thetaController,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)>
output,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
void Initialize() override;
@@ -228,7 +225,7 @@
std::function<frc::Rotation2d()> m_desiredRotation;
- frc2::Timer m_timer;
+ frc::Timer m_timer;
units::second_t m_prevTime;
frc::Rotation2d m_finalRotation;
};
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc
index 616244e..1f65b78 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc
@@ -1,13 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
+#include <utility>
+
+#include "frc2/command/SwerveControllerCommand.h"
namespace frc2 {
@@ -20,11 +20,11 @@
std::function<frc::Rotation2d()> desiredRotation,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
- m_desiredRotation(desiredRotation),
+ m_desiredRotation(std::move(desiredRotation)),
m_outputStates(output) {
this->AddRequirements(requirements);
}
@@ -37,8 +37,8 @@
frc::ProfiledPIDController<units::radians> thetaController,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
std::initializer_list<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
m_outputStates(output) {
@@ -56,12 +56,12 @@
frc::ProfiledPIDController<units::radians> thetaController,
std::function<frc::Rotation2d()> desiredRotation,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
- m_desiredRotation(desiredRotation),
+ m_desiredRotation(std::move(desiredRotation)),
m_outputStates(output) {
this->AddRequirements(requirements);
}
@@ -73,9 +73,9 @@
frc2::PIDController xController, frc2::PIDController yController,
frc::ProfiledPIDController<units::radians> thetaController,
std::function<void(std::array<frc::SwerveModuleState, NumModules>)> output,
- wpi::ArrayRef<Subsystem*> requirements)
- : m_trajectory(trajectory),
- m_pose(pose),
+ wpi::span<Subsystem* const> requirements)
+ : m_trajectory(std::move(trajectory)),
+ m_pose(std::move(pose)),
m_kinematics(kinematics),
m_controller(xController, yController, thetaController),
m_outputStates(output) {
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h
index 70bf7f9..1d8d2c5 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h
@@ -1,19 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
#include <initializer_list>
+#include <frc/Timer.h>
#include <frc/trajectory/TrapezoidProfile.h>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
-#include "frc2/Timer.h"
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -38,8 +35,9 @@
* Creates a new TrapezoidProfileCommand that will execute the given
* TrapezoidalProfile. Output will be piped to the provided consumer function.
*
- * @param profile The motion profile to execute.
- * @param output The consumer for the profile output.
+ * @param profile The motion profile to execute.
+ * @param output The consumer for the profile output.
+ * @param requirements The list of requirements.
*/
TrapezoidProfileCommand(frc::TrapezoidProfile<Distance> profile,
std::function<void(State)> output,
@@ -52,12 +50,13 @@
* Creates a new TrapezoidProfileCommand that will execute the given
* TrapezoidalProfile. Output will be piped to the provided consumer function.
*
- * @param profile The motion profile to execute.
- * @param output The consumer for the profile output.
+ * @param profile The motion profile to execute.
+ * @param output The consumer for the profile output.
+ * @param requirements The list of requirements.
*/
TrapezoidProfileCommand(frc::TrapezoidProfile<Distance> profile,
std::function<void(State)> output,
- wpi::ArrayRef<Subsystem*> requirements = {})
+ wpi::span<Subsystem* const> requirements = {})
: m_profile(profile), m_output(output) {
this->AddRequirements(requirements);
}
@@ -79,7 +78,7 @@
frc::TrapezoidProfile<Distance> m_profile;
std::function<void(State)> m_output;
- Timer m_timer;
+ frc::Timer m_timer;
};
} // namespace frc2
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileSubsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileSubsystem.h
index 08336f1..fbebaf3 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileSubsystem.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/WaitCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/WaitCommand.h
index 568db65..82249c3 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/WaitCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/WaitCommand.h
@@ -1,15 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
+#include <frc/Timer.h>
#include <units/time.h>
-#include "frc2/Timer.h"
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
@@ -42,7 +39,7 @@
bool RunsWhenDisabled() const override;
protected:
- Timer m_timer;
+ frc::Timer m_timer;
private:
units::second_t m_duration;
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/WaitUntilCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/WaitUntilCommand.h
index 741d3eb..ca74218 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/WaitUntilCommand.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/WaitUntilCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h
index 5e01edf..bab7a0f 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/Button.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,7 +8,7 @@
#include <initializer_list>
#include <utility>
-#include <wpi/ArrayRef.h>
+#include <wpi/span.h>
#include "Trigger.h"
@@ -28,7 +25,7 @@
/**
* Create a new button that is pressed when the given condition is true.
*
- * @param isActive Whether the button is pressed.
+ * @param isPressed Whether the button is pressed.
*/
explicit Button(std::function<bool()> isPressed);
@@ -82,7 +79,7 @@
* @param requirements the required subsystems.
*/
Button WhenPressed(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started repeatedly while the button is pressed, and
@@ -128,7 +125,7 @@
* @param requirements the required subsystems.
*/
Button WhileHeld(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started when the button is pressed, and canceled
@@ -202,7 +199,7 @@
* @param requirements the required subsystems.
*/
Button WhenReleased(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to start when the button is pressed, and be canceled when
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/JoystickButton.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/JoystickButton.h
index 421562e..4cd4689 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/button/JoystickButton.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/JoystickButton.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/GenericHID.h>
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/NetworkButton.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/NetworkButton.h
index 9c09dd1..191e55d 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/button/NetworkButton.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/NetworkButton.h
@@ -1,23 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
+#include <string_view>
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableInstance.h>
-#include <wpi/Twine.h>
#include "Button.h"
namespace frc2 {
/**
- * A {@link Button} that uses a {@link NetworkTable} boolean field.
+ * A Button that uses a NetworkTable boolean field.
*/
class NetworkButton : public Button {
public:
@@ -35,7 +32,7 @@
* @param field The field that is the value.
*/
NetworkButton(std::shared_ptr<nt::NetworkTable> table,
- const wpi::Twine& field);
+ std::string_view field);
/**
* Creates a NetworkButton that commands can be bound to.
@@ -43,6 +40,6 @@
* @param table The table where the networktable value is located.
* @param field The field that is the value.
*/
- NetworkButton(const wpi::Twine& table, const wpi::Twine& field);
+ NetworkButton(std::string_view table, std::string_view field);
};
} // namespace frc2
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h
index e4f8f0e..cd8b62c 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/POVButton.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/GenericHID.h>
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h
index ecfc4d1..3213d4b 100644
--- a/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h
+++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -12,7 +9,8 @@
#include <memory>
#include <utility>
-#include <wpi/ArrayRef.h>
+#include <units/time.h>
+#include <wpi/span.h>
#include "frc2/command/Command.h"
#include "frc2/command/CommandScheduler.h"
@@ -92,7 +90,7 @@
* Binds a runnable to execute when the trigger becomes active.
*
* @param toRun the runnable to execute.
- * @paaram requirements the required subsystems.
+ * @param requirements the required subsystems.
*/
Trigger WhenActive(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
@@ -101,10 +99,10 @@
* Binds a runnable to execute when the trigger becomes active.
*
* @param toRun the runnable to execute.
- * @paaram requirements the required subsystems.
+ * @param requirements the required subsystems.
*/
Trigger WhenActive(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started repeatedly while the trigger is active, and
@@ -164,7 +162,7 @@
* @param requirements the required subsystems.
*/
Trigger WhileActiveContinous(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started when the trigger becomes active, and
@@ -264,7 +262,7 @@
* @param requirements the required subsystems.
*/
Trigger WhenInactive(std::function<void()> toRun,
- wpi::ArrayRef<Subsystem*> requirements = {});
+ wpi::span<Subsystem* const> requirements = {});
/**
* Binds a command to start when the trigger becomes active, and be canceled
@@ -348,6 +346,15 @@
return Trigger([*this] { return !m_isActive(); });
}
+ /**
+ * Creates a new debounced trigger from this trigger - it will become active
+ * when this trigger has been active for longer than the specified period.
+ *
+ * @param debounceTime the debounce period
+ * @return the debounced trigger
+ */
+ Trigger Debounce(units::second_t debounceTime);
+
private:
std::function<bool()> m_isActive;
};
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/MockHardwareExtension.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/MockHardwareExtension.java
index 0547b66..b0ffc88 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/MockHardwareExtension.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/MockHardwareExtension.java
@@ -1,19 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2;
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.wpilibj.simulation.DriverStationSim;
-
public final class MockHardwareExtension implements BeforeAllCallback {
private static ExtensionContext getRoot(ExtensionContext context) {
return context.getParent().map(MockHardwareExtension::getRoot).orElse(context);
@@ -21,10 +17,15 @@
@Override
public void beforeAll(ExtensionContext context) {
- getRoot(context).getStore(Namespace.GLOBAL).getOrComputeIfAbsent("HAL Initialized", key -> {
- initializeHardware();
- return true;
- }, Boolean.class);
+ getRoot(context)
+ .getStore(Namespace.GLOBAL)
+ .getOrComputeIfAbsent(
+ "HAL Initialized",
+ key -> {
+ initializeHardware();
+ return true;
+ },
+ Boolean.class);
}
private void initializeHardware() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java
index d661598..b2f482c 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java
@@ -1,20 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.ResourceLock;
class CommandDecoratorTest extends CommandTestBase {
@Test
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandGroupErrorTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandGroupErrorTest.java
index 82e78c5..8da92c7 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandGroupErrorTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandGroupErrorTest.java
@@ -1,30 +1,25 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
+
class CommandGroupErrorTest extends CommandTestBase {
@Test
void commandInMultipleGroupsTest() {
-
MockCommandHolder command1Holder = new MockCommandHolder(true);
Command command1 = command1Holder.getMock();
MockCommandHolder command2Holder = new MockCommandHolder(true);
Command command2 = command2Holder.getMock();
- @SuppressWarnings("PMD.UnusedLocalVariable")
- Command group = new ParallelCommandGroup(command1, command2);
- assertThrows(IllegalArgumentException.class,
- () -> new ParallelCommandGroup(command1, command2));
+ new ParallelCommandGroup(command1, command2);
+ assertThrows(
+ IllegalArgumentException.class, () -> new ParallelCommandGroup(command1, command2));
}
@Test
@@ -35,11 +30,9 @@
MockCommandHolder command2Holder = new MockCommandHolder(true);
Command command2 = command2Holder.getMock();
- @SuppressWarnings("PMD.UnusedLocalVariable")
- Command group = new ParallelCommandGroup(command1, command2);
+ new ParallelCommandGroup(command1, command2);
- assertThrows(IllegalArgumentException.class,
- () -> scheduler.schedule(command1));
+ assertThrows(IllegalArgumentException.class, () -> scheduler.schedule(command1));
}
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java
index d19331b..b5058c7 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java
@@ -1,19 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class CommandRequirementsTest extends CommandTestBase {
@Test
void requirementInterruptTest() {
@@ -66,13 +63,12 @@
Subsystem system = new TestSubsystem();
Command missingRequirement = new WaitUntilCommand(() -> false);
- Command ends = new InstantCommand(() -> {
- }, system);
+ Command ends = new InstantCommand(() -> {}, system);
- assertThrows(IllegalArgumentException.class,
+ assertThrows(
+ IllegalArgumentException.class,
() -> scheduler.setDefaultCommand(system, missingRequirement));
- assertThrows(IllegalArgumentException.class,
- () -> scheduler.setDefaultCommand(system, ends));
+ assertThrows(IllegalArgumentException.class, () -> scheduler.setDefaultCommand(system, ends));
}
}
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandScheduleTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandScheduleTest.java
index 74d2d5d..a30a6ca 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandScheduleTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandScheduleTest.java
@@ -1,14 +1,9 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -16,6 +11,8 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class CommandScheduleTest extends CommandTestBase {
@Test
void instantScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandTestBase.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandTestBase.java
index 6500f69..88190ed 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandTestBase.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandTestBase.java
@@ -1,27 +1,21 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.Set;
-
-import org.junit.jupiter.api.BeforeEach;
-
-import edu.wpi.first.wpilibj.DriverStation;
-import edu.wpi.first.wpilibj.simulation.DriverStationSim;
-
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-/**
- * Basic setup for all {@link Command tests}."
- */
-@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
+import edu.wpi.first.wpilibj.DriverStation;
+import edu.wpi.first.wpilibj.simulation.DriverStationSim;
+import java.util.Set;
+import org.junit.jupiter.api.BeforeEach;
+
+/** Basic setup for all {@link Command tests}." */
public abstract class CommandTestBase {
+ protected CommandTestBase() {}
+
@BeforeEach
void commandSetup() {
CommandScheduler.getInstance().cancelAll();
@@ -37,8 +31,8 @@
DriverStationSim.setEnabled(enabled);
DriverStationSim.notifyNewData();
- DriverStation.getInstance().isNewControlData();
- while (DriverStation.getInstance().isEnabled() != enabled) {
+ DriverStation.isNewControlData();
+ while (DriverStation.isEnabled() != enabled) {
try {
Thread.sleep(1);
} catch (InterruptedException exception) {
@@ -47,10 +41,9 @@
}
}
- public class TestSubsystem extends SubsystemBase {
- }
+ public static class TestSubsystem extends SubsystemBase {}
- public class MockCommandHolder {
+ public static class MockCommandHolder {
private final Command m_mockCommand = mock(Command.class);
public MockCommandHolder(boolean runWhenDisabled, Subsystem... requirements) {
@@ -66,10 +59,9 @@
public void setFinished(boolean finished) {
when(m_mockCommand.isFinished()).thenReturn(finished);
}
-
}
- public class Counter {
+ public static class Counter {
public int m_counter;
public void increment() {
@@ -77,7 +69,7 @@
}
}
- public class ConditionHolder {
+ public static class ConditionHolder {
private boolean m_condition;
public void setCondition(boolean condition) {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java
index 939fa01..ccf4205 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class ConditionalCommandTest extends CommandTestBase {
@Test
void conditionalCommandTest() {
@@ -55,8 +52,7 @@
new ConditionalCommand(command1, command2, () -> true);
scheduler.schedule(conditionalCommand);
- scheduler.schedule(new InstantCommand(() -> {
- }, system3));
+ scheduler.schedule(new InstantCommand(() -> {}, system3));
assertFalse(scheduler.isScheduled(conditionalCommand));
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/DefaultCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/DefaultCommandTest.java
index dccf0ff..dc910fc 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/DefaultCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/DefaultCommandTest.java
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/FunctionalCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/FunctionalCommandTest.java
index 484cdf9..e6a073f 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/FunctionalCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/FunctionalCommandTest.java
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
class FunctionalCommandTest extends CommandTestBase {
@Test
void functionalCommandScheduleTest() {
@@ -22,8 +19,11 @@
ConditionHolder cond4 = new ConditionHolder();
FunctionalCommand command =
- new FunctionalCommand(() -> cond1.setCondition(true), () -> cond2.setCondition(true),
- interrupted -> cond3.setCondition(true), cond4::getCondition);
+ new FunctionalCommand(
+ () -> cond1.setCondition(true),
+ () -> cond2.setCondition(true),
+ interrupted -> cond3.setCondition(true),
+ cond4::getCondition);
scheduler.schedule(command);
scheduler.run();
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/InstantCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/InstantCommandTest.java
index e2b9dbe..88c55a6 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/InstantCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/InstantCommandTest.java
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
class InstantCommandTest extends CommandTestBase {
@Test
void instantCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java
index 9d9ebfd..ac158c2 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java
@@ -1,37 +1,32 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.ArrayList;
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.math.controller.PIDController;
+import edu.wpi.first.math.controller.ProfiledPIDController;
+import edu.wpi.first.math.geometry.Pose2d;
+import edu.wpi.first.math.geometry.Rotation2d;
+import edu.wpi.first.math.geometry.Translation2d;
+import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
+import edu.wpi.first.math.kinematics.MecanumDriveOdometry;
+import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
+import edu.wpi.first.math.trajectory.TrajectoryConfig;
+import edu.wpi.first.math.trajectory.TrajectoryGenerator;
+import edu.wpi.first.math.trajectory.TrapezoidProfile;
+import edu.wpi.first.wpilibj.Timer;
+import edu.wpi.first.wpilibj.simulation.SimHooks;
+import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.controller.PIDController;
-import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
-import edu.wpi.first.wpilibj.geometry.Pose2d;
-import edu.wpi.first.wpilibj.geometry.Rotation2d;
-import edu.wpi.first.wpilibj.geometry.Translation2d;
-import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics;
-import edu.wpi.first.wpilibj.kinematics.MecanumDriveOdometry;
-import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds;
-import edu.wpi.first.wpilibj.simulation.SimHooks;
-import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
-import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
-import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
-
-import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
class MecanumControllerCommandTest {
@BeforeEach
void setupAll() {
@@ -52,8 +47,8 @@
private double m_frontRightSpeed;
private double m_rearRightSpeed;
- private final ProfiledPIDController m_rotController = new ProfiledPIDController(1, 0, 0,
- new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
+ private final ProfiledPIDController m_rotController =
+ new ProfiledPIDController(1, 0, 0, new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
private static final double kxTolerance = 1 / 12.0;
private static final double kyTolerance = 1 / 12.0;
@@ -62,14 +57,16 @@
private static final double kWheelBase = 0.5;
private static final double kTrackWidth = 0.5;
- private final MecanumDriveKinematics m_kinematics = new MecanumDriveKinematics(
- new Translation2d(kWheelBase / 2, kTrackWidth / 2),
- new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
- new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
- new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
+ private final MecanumDriveKinematics m_kinematics =
+ new MecanumDriveKinematics(
+ new Translation2d(kWheelBase / 2, kTrackWidth / 2),
+ new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
+ new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
+ new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
- private final MecanumDriveOdometry m_odometry = new MecanumDriveOdometry(m_kinematics,
- new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
+ private final MecanumDriveOdometry m_odometry =
+ new MecanumDriveOdometry(
+ m_kinematics, new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
public void setWheelSpeeds(MecanumDriveWheelSpeeds wheelSpeeds) {
this.m_frontLeftSpeed = wheelSpeeds.frontLeftMetersPerSecond;
@@ -79,8 +76,8 @@
}
public MecanumDriveWheelSpeeds getCurrentWheelSpeeds() {
- return new MecanumDriveWheelSpeeds(m_frontLeftSpeed,
- m_frontRightSpeed, m_rearLeftSpeed, m_rearRightSpeed);
+ return new MecanumDriveWheelSpeeds(
+ m_frontLeftSpeed, m_frontRightSpeed, m_rearLeftSpeed, m_rearRightSpeed);
}
public Pose2d getRobotPose() {
@@ -90,7 +87,6 @@
@Test
@ResourceLock("timing")
- @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
void testReachesReference() {
final var subsystem = new Subsystem() {};
@@ -102,15 +98,17 @@
final var endState = trajectory.sample(trajectory.getTotalTimeSeconds());
- final var command = new MecanumControllerCommand(trajectory,
- this::getRobotPose,
- m_kinematics,
- new PIDController(0.6, 0, 0),
- new PIDController(0.6, 0, 0),
- m_rotController,
- 8.8,
- this::setWheelSpeeds,
- subsystem);
+ final var command =
+ new MecanumControllerCommand(
+ trajectory,
+ this::getRobotPose,
+ m_kinematics,
+ new PIDController(0.6, 0, 0),
+ new PIDController(0.6, 0, 0),
+ m_rotController,
+ 8.8,
+ this::setWheelSpeeds,
+ subsystem);
m_timer.reset();
m_timer.start();
@@ -125,12 +123,12 @@
command.end(true);
assertAll(
- () -> assertEquals(endState.poseMeters.getX(),
- getRobotPose().getX(), kxTolerance),
- () -> assertEquals(endState.poseMeters.getY(),
- getRobotPose().getY(), kyTolerance),
- () -> assertEquals(endState.poseMeters.getRotation().getRadians(),
- getRobotPose().getRotation().getRadians(), kAngularTolerance)
- );
+ () -> assertEquals(endState.poseMeters.getX(), getRobotPose().getX(), kxTolerance),
+ () -> assertEquals(endState.poseMeters.getY(), getRobotPose().getY(), kyTolerance),
+ () ->
+ assertEquals(
+ endState.poseMeters.getRotation().getRadians(),
+ getRobotPose().getRotation().getRadians(),
+ kAngularTolerance));
}
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/NotifierCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/NotifierCommandTest.java
index 2448821..283a3de 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/NotifierCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/NotifierCommandTest.java
@@ -1,22 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.wpilibj.simulation.SimHooks;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.wpilibj.simulation.SimHooks;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
class NotifierCommandTest extends CommandTestBase {
@BeforeEach
void setup() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroupTest.java
index a32b994..afc32ae 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroupTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroupTest.java
@@ -1,14 +1,9 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -17,6 +12,8 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class ParallelCommandGroupTest extends CommandTestBase {
@Test
void parallelGroupScheduleTest() {
@@ -126,7 +123,7 @@
MockCommandHolder command2Holder = new MockCommandHolder(true, system2, system3);
Command command2 = command2Holder.getMock();
- assertThrows(IllegalArgumentException.class,
- () -> new ParallelCommandGroup(command1, command2));
+ assertThrows(
+ IllegalArgumentException.class, () -> new ParallelCommandGroup(command1, command2));
}
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java
index bc10a0e..1fe3866 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java
@@ -1,14 +1,9 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -16,6 +11,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.internal.verification.VerificationModeFactory.times;
+import org.junit.jupiter.api.Test;
+
class ParallelDeadlineGroupTest extends CommandTestBase {
@Test
void parallelDeadlineScheduleTest() {
@@ -86,7 +83,6 @@
}
}
-
@Test
void parallelDeadlineRequirementTest() {
Subsystem system1 = new TestSubsystem();
@@ -123,7 +119,7 @@
MockCommandHolder command2Holder = new MockCommandHolder(true, system2, system3);
Command command2 = command2Holder.getMock();
- assertThrows(IllegalArgumentException.class,
- () -> new ParallelDeadlineGroup(command1, command2));
+ assertThrows(
+ IllegalArgumentException.class, () -> new ParallelDeadlineGroup(command1, command2));
}
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java
index 360882d..3201a52 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java
@@ -1,14 +1,9 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -19,6 +14,8 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class ParallelRaceGroupTest extends CommandTestBase {
@Test
void parallelRaceScheduleTest() {
@@ -92,7 +89,6 @@
}
}
-
@Test
void parallelRaceRequirementTest() {
Subsystem system1 = new TestSubsystem();
@@ -205,5 +201,4 @@
assertFalse(scheduler.isScheduled(group));
}
}
-
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PerpetualCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PerpetualCommandTest.java
index 58195f3..f9e93a3 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PerpetualCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PerpetualCommandTest.java
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
class PerpetualCommandTest extends CommandTestBase {
@Test
void perpetualCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PrintCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PrintCommandTest.java
index 1895fc0..6abd94b 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PrintCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/PrintCommandTest.java
@@ -1,20 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.junit.jupiter.api.Test;
+
class PrintCommandTest extends CommandTestBase {
@Test
void printCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommandTest.java
index 5364b95..3c34688 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyScheduleCommandTest.java
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class ProxyScheduleCommandTest extends CommandTestBase {
@Test
void proxyScheduleCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RobotDisabledCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RobotDisabledCommandTest.java
index 3b607bf..b807c71 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RobotDisabledCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RobotDisabledCommandTest.java
@@ -1,20 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.Map;
-
-import org.junit.jupiter.api.Test;
-
import static edu.wpi.first.wpilibj2.command.CommandGroupBase.parallel;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
class RobotDisabledCommandTest extends CommandTestBase {
@Test
void robotDisabledCommandCancelTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RunCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RunCommandTest.java
index 07c18dd..92e2d75 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RunCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/RunCommandTest.java
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
class RunCommandTest extends CommandTestBase {
@Test
void runCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java
index c8d5127..c9ae4b2 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class ScheduleCommandTest extends CommandTestBase {
@Test
void scheduleCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java
index c148816..558ef57 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
class SchedulerTest extends CommandTestBase {
@Test
void schedulerLambdaTestNoInterrupt() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java
index 53f6a98..de40ef8 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java
@@ -1,21 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.Map;
-
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
class SelectCommandTest extends CommandTestBase {
@Test
void selectCommandTest() {
@@ -29,10 +25,11 @@
Command command3 = command3Holder.getMock();
SelectCommand selectCommand =
- new SelectCommand(Map.ofEntries(
- Map.entry("one", command1),
- Map.entry("two", command2),
- Map.entry("three", command3)),
+ new SelectCommand(
+ Map.ofEntries(
+ Map.entry("one", command1),
+ Map.entry("two", command2),
+ Map.entry("three", command3)),
() -> "one");
scheduler.schedule(selectCommand);
@@ -64,17 +61,17 @@
Command command3 = command3Holder.getMock();
SelectCommand selectCommand =
- new SelectCommand(Map.ofEntries(
- Map.entry("one", command1),
- Map.entry("two", command2),
- Map.entry("three", command3)),
+ new SelectCommand(
+ Map.ofEntries(
+ Map.entry("one", command1),
+ Map.entry("two", command2),
+ Map.entry("three", command3)),
() -> "four");
assertDoesNotThrow(() -> scheduler.schedule(selectCommand));
}
}
-
@Test
void selectCommandRequirementTest() {
Subsystem system1 = new TestSubsystem();
@@ -90,13 +87,16 @@
MockCommandHolder command3Holder = new MockCommandHolder(true, system3, system4);
Command command3 = command3Holder.getMock();
- SelectCommand selectCommand = new SelectCommand(
- Map.ofEntries(Map.entry("one", command1), Map.entry("two", command2),
- Map.entry("three", command3)), () -> "one");
+ SelectCommand selectCommand =
+ new SelectCommand(
+ Map.ofEntries(
+ Map.entry("one", command1),
+ Map.entry("two", command2),
+ Map.entry("three", command3)),
+ () -> "one");
scheduler.schedule(selectCommand);
- scheduler.schedule(new InstantCommand(() -> {
- }, system3));
+ scheduler.schedule(new InstantCommand(() -> {}, system3));
assertFalse(scheduler.isScheduled(selectCommand));
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroupTest.java
index a47f865..811034c 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroupTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SequentialCommandGroupTest.java
@@ -1,20 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.Test;
+
class SequentialCommandGroupTest extends CommandTestBase {
@Test
void sequentialGroupScheduleTest() {
@@ -100,7 +97,6 @@
}
}
-
@Test
void sequentialGroupRequirementTest() {
Subsystem system1 = new TestSubsystem();
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/StartEndCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/StartEndCommandTest.java
index 90ad41a..60c5c44 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/StartEndCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/StartEndCommandTest.java
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
class StartEndCommandTest extends CommandTestBase {
@Test
void startEndCommandScheduleTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java
index 2febfbf..0cf6d67 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java
@@ -1,37 +1,32 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import java.util.ArrayList;
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.math.controller.PIDController;
+import edu.wpi.first.math.controller.ProfiledPIDController;
+import edu.wpi.first.math.geometry.Pose2d;
+import edu.wpi.first.math.geometry.Rotation2d;
+import edu.wpi.first.math.geometry.Translation2d;
+import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
+import edu.wpi.first.math.kinematics.SwerveDriveOdometry;
+import edu.wpi.first.math.kinematics.SwerveModuleState;
+import edu.wpi.first.math.trajectory.TrajectoryConfig;
+import edu.wpi.first.math.trajectory.TrajectoryGenerator;
+import edu.wpi.first.math.trajectory.TrapezoidProfile;
+import edu.wpi.first.wpilibj.Timer;
+import edu.wpi.first.wpilibj.simulation.SimHooks;
+import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.controller.PIDController;
-import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
-import edu.wpi.first.wpilibj.geometry.Pose2d;
-import edu.wpi.first.wpilibj.geometry.Rotation2d;
-import edu.wpi.first.wpilibj.geometry.Translation2d;
-import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics;
-import edu.wpi.first.wpilibj.kinematics.SwerveDriveOdometry;
-import edu.wpi.first.wpilibj.kinematics.SwerveModuleState;
-import edu.wpi.first.wpilibj.simulation.SimHooks;
-import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
-import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
-import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
-
-import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
class SwerveControllerCommandTest {
@BeforeEach
void setup() {
@@ -47,14 +42,16 @@
private final Timer m_timer = new Timer();
private Rotation2d m_angle = new Rotation2d(0);
- private SwerveModuleState[] m_moduleStates = new SwerveModuleState[]{
- new SwerveModuleState(0, new Rotation2d(0)),
- new SwerveModuleState(0, new Rotation2d(0)),
- new SwerveModuleState(0, new Rotation2d(0)),
- new SwerveModuleState(0, new Rotation2d(0))};
+ private SwerveModuleState[] m_moduleStates =
+ new SwerveModuleState[] {
+ new SwerveModuleState(0, new Rotation2d(0)),
+ new SwerveModuleState(0, new Rotation2d(0)),
+ new SwerveModuleState(0, new Rotation2d(0)),
+ new SwerveModuleState(0, new Rotation2d(0))
+ };
- private final ProfiledPIDController m_rotController = new ProfiledPIDController(1, 0, 0,
- new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
+ private final ProfiledPIDController m_rotController =
+ new ProfiledPIDController(1, 0, 0, new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
private static final double kxTolerance = 1 / 12.0;
private static final double kyTolerance = 1 / 12.0;
@@ -63,14 +60,15 @@
private static final double kWheelBase = 0.5;
private static final double kTrackWidth = 0.5;
- private final SwerveDriveKinematics m_kinematics = new SwerveDriveKinematics(
- new Translation2d(kWheelBase / 2, kTrackWidth / 2),
- new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
- new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
- new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
+ private final SwerveDriveKinematics m_kinematics =
+ new SwerveDriveKinematics(
+ new Translation2d(kWheelBase / 2, kTrackWidth / 2),
+ new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
+ new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
+ new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
- private final SwerveDriveOdometry m_odometry = new SwerveDriveOdometry(m_kinematics,
- new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
+ private final SwerveDriveOdometry m_odometry =
+ new SwerveDriveOdometry(m_kinematics, new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
@SuppressWarnings("PMD.ArrayIsStoredDirectly")
public void setModuleStates(SwerveModuleState[] moduleStates) {
@@ -84,7 +82,6 @@
@Test
@ResourceLock("timing")
- @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
void testReachesReference() {
final var subsystem = new Subsystem() {};
@@ -96,14 +93,16 @@
final var endState = trajectory.sample(trajectory.getTotalTimeSeconds());
- final var command = new SwerveControllerCommand(trajectory,
- this::getRobotPose,
- m_kinematics,
- new PIDController(0.6, 0, 0),
- new PIDController(0.6, 0, 0),
- m_rotController,
- this::setModuleStates,
- subsystem);
+ final var command =
+ new SwerveControllerCommand(
+ trajectory,
+ this::getRobotPose,
+ m_kinematics,
+ new PIDController(0.6, 0, 0),
+ new PIDController(0.6, 0, 0),
+ m_rotController,
+ this::setModuleStates,
+ subsystem);
m_timer.reset();
m_timer.start();
@@ -118,12 +117,12 @@
command.end(true);
assertAll(
- () -> assertEquals(endState.poseMeters.getX(),
- getRobotPose().getX(), kxTolerance),
- () -> assertEquals(endState.poseMeters.getY(),
- getRobotPose().getY(), kyTolerance),
- () -> assertEquals(endState.poseMeters.getRotation().getRadians(),
- getRobotPose().getRotation().getRadians(), kAngularTolerance)
- );
+ () -> assertEquals(endState.poseMeters.getX(), getRobotPose().getX(), kxTolerance),
+ () -> assertEquals(endState.poseMeters.getY(), getRobotPose().getY(), kyTolerance),
+ () ->
+ assertEquals(
+ endState.poseMeters.getRotation().getRadians(),
+ getRobotPose().getRotation().getRadians(),
+ kAngularTolerance));
}
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitCommandTest.java
index f7f9296..7cf1a28 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitCommandTest.java
@@ -1,27 +1,24 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.wpilibj.simulation.SimHooks;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyDouble;
+import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.wpilibj.simulation.SimHooks;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.ResourceLock;
+
class WaitCommandTest extends CommandTestBase {
@BeforeEach
void setup() {
@@ -62,6 +59,7 @@
MockCommandHolder command1Holder = new MockCommandHolder(true);
Command command1 = command1Holder.getMock();
when(command1.withTimeout(anyDouble())).thenCallRealMethod();
+ when(command1.raceWith(notNull())).thenCallRealMethod();
Command timeout = command1.withTimeout(2);
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitUntilCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitUntilCommandTest.java
index c38feee..85539dc 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitUntilCommandTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/WaitUntilCommandTest.java
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
class WaitUntilCommandTest extends CommandTestBase {
@Test
void waitUntilTest() {
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java
index 44083d0..1a4f05d 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java
@@ -1,18 +1,9 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
-import org.junit.jupiter.api.Test;
-
-import edu.wpi.first.wpilibj2.command.Command;
-import edu.wpi.first.wpilibj2.command.CommandScheduler;
-import edu.wpi.first.wpilibj2.command.CommandTestBase;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -21,6 +12,11 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import edu.wpi.first.wpilibj.simulation.SimHooks;
+import edu.wpi.first.wpilibj2.command.Command;
+import edu.wpi.first.wpilibj2.command.CommandScheduler;
+import edu.wpi.first.wpilibj2.command.CommandTestBase;
+import org.junit.jupiter.api.Test;
class ButtonTest extends CommandTestBase {
@Test
@@ -140,7 +136,6 @@
@Test
void runnableBindingTest() {
-
InternalButton buttonWhenPressed = new InternalButton();
InternalButton buttonWhileHeld = new InternalButton();
InternalButton buttonWhenReleased = new InternalButton();
@@ -178,4 +173,26 @@
assertFalse(button1.negate().get());
assertTrue(button1.and(button2.negate()).get());
}
+
+ @Test
+ void debounceTest() {
+ CommandScheduler scheduler = CommandScheduler.getInstance();
+ MockCommandHolder commandHolder = new MockCommandHolder(true);
+ Command command = commandHolder.getMock();
+
+ InternalButton button = new InternalButton();
+ Trigger debounced = button.debounce(0.1);
+
+ debounced.whenActive(command);
+
+ button.setPressed(true);
+ scheduler.run();
+ verify(command, never()).schedule(true);
+
+ SimHooks.stepTiming(0.3);
+
+ button.setPressed(true);
+ scheduler.run();
+ verify(command).schedule(true);
+ }
}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/NetworkButtonTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/NetworkButtonTest.java
index 26a4a1c..9502977 100644
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/NetworkButtonTest.java
+++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/NetworkButtonTest.java
@@ -1,22 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.CommandTestBase;
-
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
class NetworkButtonTest extends CommandTestBase {
@BeforeEach
@@ -35,9 +31,7 @@
var scheduler = CommandScheduler.getInstance();
var commandHolder = new MockCommandHolder(true);
var command = commandHolder.getMock();
- var entry = NetworkTableInstance.getDefault()
- .getTable("TestTable")
- .getEntry("Test");
+ var entry = NetworkTableInstance.getDefault().getTable("TestTable").getEntry("Test");
var button = new NetworkButton("TestTable", "Test");
entry.setBoolean(false);
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp
index 67eb428..5ae17cc 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/simulation/SimHooks.h>
@@ -17,7 +14,7 @@
using namespace frc2;
class CommandDecoratorTest : public CommandTestBase {};
-TEST_F(CommandDecoratorTest, WithTimeoutTest) {
+TEST_F(CommandDecoratorTest, WithTimeout) {
CommandScheduler scheduler = GetScheduler();
frc::sim::PauseTiming();
@@ -37,7 +34,7 @@
frc::sim::ResumeTiming();
}
-TEST_F(CommandDecoratorTest, WithInterruptTest) {
+TEST_F(CommandDecoratorTest, WithInterrupt) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
@@ -56,7 +53,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(CommandDecoratorTest, BeforeStartingTest) {
+TEST_F(CommandDecoratorTest, BeforeStarting) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
@@ -74,7 +71,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(CommandDecoratorTest, AndThenTest) {
+TEST_F(CommandDecoratorTest, AndThen) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
@@ -93,7 +90,7 @@
EXPECT_TRUE(finished);
}
-TEST_F(CommandDecoratorTest, PerpetuallyTest) {
+TEST_F(CommandDecoratorTest, Perpetually) {
CommandScheduler scheduler = GetScheduler();
auto command = InstantCommand([] {}, {}).Perpetually();
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp
index 2600430..c812670 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp
@@ -1,9 +1,8 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <frc/Errors.h>
#include "CommandTestBase.h"
#include "frc2/command/CommandScheduler.h"
@@ -18,7 +17,7 @@
using namespace frc2;
class CommandRequirementsTest : public CommandTestBase {};
-TEST_F(CommandRequirementsTest, RequirementInterruptTest) {
+TEST_F(CommandRequirementsTest, RequirementInterrupt) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement;
@@ -45,7 +44,7 @@
scheduler.Run();
}
-TEST_F(CommandRequirementsTest, RequirementUninterruptibleTest) {
+TEST_F(CommandRequirementsTest, RequirementUninterruptible) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement;
@@ -72,13 +71,11 @@
scheduler.Run();
}
-TEST_F(CommandRequirementsTest, DefaultCommandRequirementErrorTest) {
+TEST_F(CommandRequirementsTest, DefaultCommandRequirementError) {
TestSubsystem requirement1;
- ErrorConfirmer confirmer("require");
MockCommand command1;
- requirement1.SetDefaultCommand(std::move(command1));
-
- EXPECT_TRUE(requirement1.GetDefaultCommand() == NULL);
+ ASSERT_THROW(requirement1.SetDefaultCommand(std::move(command1)),
+ frc::RuntimeError);
}
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandScheduleTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandScheduleTest.cpp
index 6572a98..cb16b48 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandScheduleTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandScheduleTest.cpp
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
using namespace frc2;
class CommandScheduleTest : public CommandTestBase {};
-TEST_F(CommandScheduleTest, InstantScheduleTest) {
+TEST_F(CommandScheduleTest, InstantSchedule) {
CommandScheduler scheduler = GetScheduler();
MockCommand command;
@@ -25,7 +22,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(CommandScheduleTest, SingleIterationScheduleTest) {
+TEST_F(CommandScheduleTest, SingleIterationSchedule) {
CommandScheduler scheduler = GetScheduler();
MockCommand command;
@@ -41,7 +38,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(CommandScheduleTest, MultiScheduleTest) {
+TEST_F(CommandScheduleTest, MultiSchedule) {
CommandScheduler scheduler = GetScheduler();
MockCommand command1;
MockCommand command2;
@@ -78,7 +75,7 @@
EXPECT_FALSE(scheduler.IsScheduled({&command1, &command2, &command3}));
}
-TEST_F(CommandScheduleTest, SchedulerCancelTest) {
+TEST_F(CommandScheduleTest, SchedulerCancel) {
CommandScheduler scheduler = GetScheduler();
MockCommand command;
@@ -95,7 +92,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(CommandScheduleTest, NotScheduledCancelTest) {
+TEST_F(CommandScheduleTest, NotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
MockCommand command;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.cpp
index e5136ba..7ebbb70 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
@@ -16,9 +13,13 @@
scheduler.ClearButtons();
}
-CommandScheduler CommandTestBase::GetScheduler() { return CommandScheduler(); }
+CommandScheduler CommandTestBase::GetScheduler() {
+ return CommandScheduler();
+}
-void CommandTestBase::SetUp() { frc::sim::DriverStationSim::SetEnabled(true); }
+void CommandTestBase::SetUp() {
+ frc::sim::DriverStationSim::SetEnabled(true);
+}
void CommandTestBase::TearDown() {
CommandScheduler::GetInstance().ClearButtons();
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h
index c6400a8..a3890f6 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -12,7 +9,6 @@
#include <frc/simulation/DriverStationSim.h>
-#include "ErrorConfirmer.h"
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandScheduler.h"
#include "frc2/command/SetUtilities.h"
@@ -68,20 +64,20 @@
.WillRepeatedly(::testing::Return(m_requirements));
}
- MockCommand(const MockCommand& other) : Command{} {}
+ MockCommand(const MockCommand& other) : Command{other} {}
void SetFinished(bool finished) {
EXPECT_CALL(*this, IsFinished())
.WillRepeatedly(::testing::Return(finished));
}
- ~MockCommand() {
+ ~MockCommand() { // NOLINT
auto& scheduler = CommandScheduler::GetInstance();
scheduler.Cancel(this);
}
protected:
- std::unique_ptr<Command> TransferOwnership() && {
+ std::unique_ptr<Command> TransferOwnership() && { // NOLINT
return std::make_unique<MockCommand>(std::move(*this));
}
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp
index 927721a..27b89e5 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/ConditionalCommand.h"
@@ -13,7 +10,7 @@
using namespace frc2;
class ConditionalCommandTest : public CommandTestBase {};
-TEST_F(ConditionalCommandTest, ConditionalCommandScheduleTest) {
+TEST_F(ConditionalCommandTest, ConditionalCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> mock = std::make_unique<MockCommand>();
@@ -34,7 +31,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&conditional));
}
-TEST_F(ConditionalCommandTest, ConditionalCommandRequirementTest) {
+TEST_F(ConditionalCommandTest, ConditionalCommandRequirement) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement1;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/DefaultCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/DefaultCommandTest.cpp
index b97cbb6..a9e3fc6 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/DefaultCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/DefaultCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/RunCommand.h"
@@ -11,7 +8,7 @@
using namespace frc2;
class DefaultCommandTest : public CommandTestBase {};
-TEST_F(DefaultCommandTest, DefaultCommandScheduleTest) {
+TEST_F(DefaultCommandTest, DefaultCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem subsystem;
@@ -25,7 +22,7 @@
EXPECT_TRUE(scheduler.IsScheduled(handle));
}
-TEST_F(DefaultCommandTest, DefaultCommandInterruptResumeTest) {
+TEST_F(DefaultCommandTest, DefaultCommandInterruptResume) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem subsystem;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.cpp
deleted file mode 100644
index 2c13f5d..0000000
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "ErrorConfirmer.h"
-
-#include <regex>
-
-ErrorConfirmer* ErrorConfirmer::instance;
-
-int32_t ErrorConfirmer::HandleError(HAL_Bool isError, int32_t errorCode,
- HAL_Bool isLVCode, const char* details,
- const char* location, const char* callStack,
- HAL_Bool printMsg) {
- if (std::regex_search(details, std::regex(instance->m_msg))) {
- instance->ConfirmError();
- }
- return 1;
-}
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.h b/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.h
deleted file mode 100644
index 2df5e26..0000000
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <hal/simulation/MockHooks.h>
-
-#include "gmock/gmock.h"
-
-class ErrorConfirmer {
- public:
- explicit ErrorConfirmer(const char* msg) : m_msg(msg) {
- if (instance != nullptr) return;
- HALSIM_SetSendError(HandleError);
- EXPECT_CALL(*this, ConfirmError());
- instance = this;
- }
-
- ~ErrorConfirmer() {
- HALSIM_SetSendError(nullptr);
- instance = nullptr;
- }
-
- MOCK_METHOD0(ConfirmError, void());
-
- const char* m_msg;
-
- static int32_t HandleError(HAL_Bool isError, int32_t errorCode,
- HAL_Bool isLVCode, const char* details,
- const char* location, const char* callStack,
- HAL_Bool printMsg);
-
- private:
- static ErrorConfirmer* instance;
-};
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/FunctionalCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/FunctionalCommandTest.cpp
index 140d4fb..0f0ebda 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/FunctionalCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/FunctionalCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/FunctionalCommand.h"
@@ -11,7 +8,7 @@
using namespace frc2;
class FunctionalCommandTest : public CommandTestBase {};
-TEST_F(FunctionalCommandTest, FunctionalCommandScheduleTest) {
+TEST_F(FunctionalCommandTest, FunctionalCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/InstantCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/InstantCommandTest.cpp
index e91f677..90eab85 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/InstantCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/InstantCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/InstantCommand.h"
@@ -11,7 +8,7 @@
using namespace frc2;
class InstantCommandTest : public CommandTestBase {};
-TEST_F(InstantCommandTest, InstantCommandScheduleTest) {
+TEST_F(InstantCommandTest, InstantCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp
index 07bc07a..537d892 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc2/Timer.h>
#include <frc2/command/MecanumControllerCommand.h>
#include <frc2/command/Subsystem.h>
+#include <frc/Timer.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
#include <frc/geometry/Rotation2d.h>
@@ -17,7 +14,7 @@
#include <frc/kinematics/MecanumDriveOdometry.h>
#include <frc/simulation/SimHooks.h>
#include <frc/trajectory/TrajectoryGenerator.h>
-#include <wpi/math>
+#include <wpi/numbers>
#include "gtest/gtest.h"
@@ -30,7 +27,7 @@
units::inverse<units::squared<units::second>>>;
protected:
- frc2::Timer m_timer;
+ frc::Timer m_timer;
frc::Rotation2d m_angle{0_rad};
units::meters_per_second_t m_frontLeftSpeed = 0.0_mps;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/NotifierCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/NotifierCommandTest.cpp
index b4df5a7..00c9b89 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/NotifierCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/NotifierCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/simulation/SimHooks.h>
@@ -15,7 +12,7 @@
class NotifierCommandTest : public CommandTestBase {};
-TEST_F(NotifierCommandTest, NotifierCommandScheduleTest) {
+TEST_F(NotifierCommandTest, NotifierCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
frc::sim::PauseTiming();
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/POVButtonTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/POVButtonTest.cpp
index 2a1646d..5f6e733 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/POVButtonTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/POVButtonTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Joystick.h>
#include <frc/simulation/JoystickSim.h>
@@ -18,7 +15,7 @@
using namespace frc2;
class POVButtonTest : public CommandTestBase {};
-TEST_F(POVButtonTest, SetPOVTest) {
+TEST_F(POVButtonTest, SetPOV) {
frc::sim::JoystickSim joysim(1);
joysim.SetPOV(0);
joysim.NotifyNewData();
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelCommandGroupTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelCommandGroupTest.cpp
index 55c7b98..d6c0295 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelCommandGroupTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelCommandGroupTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/InstantCommand.h"
@@ -13,7 +10,7 @@
using namespace frc2;
class ParallelCommandGroupTest : public CommandTestBase {};
-TEST_F(ParallelCommandGroupTest, ParallelGroupScheduleTest) {
+TEST_F(ParallelCommandGroupTest, ParallelGroupSchedule) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
@@ -43,7 +40,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelCommandGroupTest, ParallelGroupInterruptTest) {
+TEST_F(ParallelCommandGroupTest, ParallelGroupInterrupt) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
@@ -74,7 +71,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelCommandGroupTest, ParallelGroupNotScheduledCancelTest) {
+TEST_F(ParallelCommandGroupTest, ParallelGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
ParallelCommandGroup group((InstantCommand(), InstantCommand()));
@@ -82,7 +79,7 @@
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(&group));
}
-TEST_F(ParallelCommandGroupTest, ParallelGroupCopyTest) {
+TEST_F(ParallelCommandGroupTest, ParallelGroupCopy) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
@@ -98,7 +95,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelCommandGroupTest, ParallelGroupRequirementTest) {
+TEST_F(ParallelCommandGroupTest, ParallelGroupRequirement) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement1;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelDeadlineGroupTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelDeadlineGroupTest.cpp
index 6e3246f..67d8720 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelDeadlineGroupTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelDeadlineGroupTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/InstantCommand.h"
@@ -13,7 +10,7 @@
using namespace frc2;
class ParallelDeadlineGroupTest : public CommandTestBase {};
-TEST_F(ParallelDeadlineGroupTest, DeadlineGroupScheduleTest) {
+TEST_F(ParallelDeadlineGroupTest, DeadlineGroupSchedule) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
@@ -51,7 +48,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelDeadlineGroupTest, SequentialGroupInterruptTest) {
+TEST_F(ParallelDeadlineGroupTest, SequentialGroupInterrupt) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem subsystem;
@@ -90,7 +87,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelDeadlineGroupTest, DeadlineGroupNotScheduledCancelTest) {
+TEST_F(ParallelDeadlineGroupTest, DeadlineGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
ParallelDeadlineGroup group{InstantCommand(), InstantCommand()};
@@ -98,7 +95,7 @@
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(&group));
}
-TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineCopyTest) {
+TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineCopy) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
@@ -114,7 +111,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineRequirementTest) {
+TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineRequirement) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement1;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelRaceGroupTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelRaceGroupTest.cpp
index 072bcb0..72f4274 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelRaceGroupTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ParallelRaceGroupTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/InstantCommand.h"
@@ -14,7 +11,7 @@
using namespace frc2;
class ParallelRaceGroupTest : public CommandTestBase {};
-TEST_F(ParallelRaceGroupTest, ParallelRaceScheduleTest) {
+TEST_F(ParallelRaceGroupTest, ParallelRaceSchedule) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
@@ -50,7 +47,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelRaceGroupTest, ParallelRaceInterruptTest) {
+TEST_F(ParallelRaceGroupTest, ParallelRaceInterrupt) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
@@ -86,7 +83,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelRaceGroupTest, ParallelRaceNotScheduledCancelTest) {
+TEST_F(ParallelRaceGroupTest, ParallelRaceNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
ParallelRaceGroup group{InstantCommand(), InstantCommand()};
@@ -94,7 +91,7 @@
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(&group));
}
-TEST_F(ParallelRaceGroupTest, ParallelRaceCopyTest) {
+TEST_F(ParallelRaceGroupTest, ParallelRaceCopy) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
@@ -110,7 +107,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelRaceGroupTest, RaceGroupRequirementTest) {
+TEST_F(ParallelRaceGroupTest, RaceGroupRequirement) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement1;
@@ -131,7 +128,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(ParallelRaceGroupTest, ParallelRaceOnlyCallsEndOnceTest) {
+TEST_F(ParallelRaceGroupTest, ParallelRaceOnlyCallsEndOnce) {
CommandScheduler scheduler = GetScheduler();
bool finished1 = false;
@@ -155,7 +152,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group2));
}
-TEST_F(ParallelRaceGroupTest, ParallelRaceScheduleTwiceTest) {
+TEST_F(ParallelRaceGroupTest, ParallelRaceScheduleTwice) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/PerpetualCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/PerpetualCommandTest.cpp
index b3ef861..6254b85 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/PerpetualCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/PerpetualCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/InstantCommand.h"
@@ -12,7 +9,7 @@
using namespace frc2;
class PerpetualCommandTest : public CommandTestBase {};
-TEST_F(PerpetualCommandTest, PerpetualCommandScheduleTest) {
+TEST_F(PerpetualCommandTest, PerpetualCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
bool check = false;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/PrintCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/PrintCommandTest.cpp
index b940566..02575a3 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/PrintCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/PrintCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <regex>
@@ -13,7 +10,7 @@
using namespace frc2;
class PrintCommandTest : public CommandTestBase {};
-TEST_F(PrintCommandTest, PrintCommandScheduleTest) {
+TEST_F(PrintCommandTest, PrintCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
PrintCommand command("Test!");
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ProxyScheduleCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ProxyScheduleCommandTest.cpp
index 09a569f..def7be9 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ProxyScheduleCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ProxyScheduleCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <regex>
@@ -15,7 +12,7 @@
using namespace frc2;
class ProxyScheduleCommandTest : public CommandTestBase {};
-TEST_F(ProxyScheduleCommandTest, ProxyScheduleCommandScheduleTest) {
+TEST_F(ProxyScheduleCommandTest, ProxyScheduleCommandSchedule) {
CommandScheduler& scheduler = CommandScheduler::GetInstance();
bool scheduled = false;
@@ -30,7 +27,7 @@
EXPECT_TRUE(scheduled);
}
-TEST_F(ProxyScheduleCommandTest, ProxyScheduleCommandEndTest) {
+TEST_F(ProxyScheduleCommandTest, ProxyScheduleCommandEnd) {
CommandScheduler& scheduler = CommandScheduler::GetInstance();
bool finished = false;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/RobotDisabledCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/RobotDisabledCommandTest.cpp
index bac40d5..1595a1e 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/RobotDisabledCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/RobotDisabledCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/ConditionalCommand.h"
@@ -16,7 +13,7 @@
using namespace frc2;
class RobotDisabledCommandTest : public CommandTestBase {};
-TEST_F(RobotDisabledCommandTest, RobotDisabledCommandCancelTest) {
+TEST_F(RobotDisabledCommandTest, RobotDisabledCommandCancel) {
CommandScheduler scheduler = GetScheduler();
MockCommand command({}, false, false);
@@ -37,7 +34,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(RobotDisabledCommandTest, RunWhenDisabledTest) {
+TEST_F(RobotDisabledCommandTest, RunWhenDisabled) {
CommandScheduler scheduler = GetScheduler();
MockCommand command1;
@@ -55,7 +52,7 @@
EXPECT_TRUE(scheduler.IsScheduled(&command2));
}
-TEST_F(RobotDisabledCommandTest, SequentialGroupRunWhenDisabledTest) {
+TEST_F(RobotDisabledCommandTest, SequentialGroupRunWhenDisabled) {
CommandScheduler scheduler = GetScheduler();
SequentialCommandGroup runWhenDisabled{MockCommand(), MockCommand()};
@@ -71,7 +68,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&dontRunWhenDisabled));
}
-TEST_F(RobotDisabledCommandTest, ParallelGroupRunWhenDisabledTest) {
+TEST_F(RobotDisabledCommandTest, ParallelGroupRunWhenDisabled) {
CommandScheduler scheduler = GetScheduler();
ParallelCommandGroup runWhenDisabled{MockCommand(), MockCommand()};
@@ -87,7 +84,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&dontRunWhenDisabled));
}
-TEST_F(RobotDisabledCommandTest, ParallelRaceRunWhenDisabledTest) {
+TEST_F(RobotDisabledCommandTest, ParallelRaceRunWhenDisabled) {
CommandScheduler scheduler = GetScheduler();
ParallelRaceGroup runWhenDisabled{MockCommand(), MockCommand()};
@@ -103,7 +100,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&dontRunWhenDisabled));
}
-TEST_F(RobotDisabledCommandTest, ParallelDeadlineRunWhenDisabledTest) {
+TEST_F(RobotDisabledCommandTest, ParallelDeadlineRunWhenDisabled) {
CommandScheduler scheduler = GetScheduler();
ParallelDeadlineGroup runWhenDisabled{MockCommand(), MockCommand()};
@@ -119,7 +116,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&dontRunWhenDisabled));
}
-TEST_F(RobotDisabledCommandTest, ConditionalCommandRunWhenDisabledTest) {
+TEST_F(RobotDisabledCommandTest, ConditionalCommandRunWhenDisabled) {
CommandScheduler scheduler = GetScheduler();
ConditionalCommand runWhenDisabled{MockCommand(), MockCommand(),
@@ -136,7 +133,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&dontRunWhenDisabled));
}
-TEST_F(RobotDisabledCommandTest, SelectCommandRunWhenDisabledTest) {
+TEST_F(RobotDisabledCommandTest, SelectCommandRunWhenDisabled) {
CommandScheduler scheduler = GetScheduler();
SelectCommand<int> runWhenDisabled{[] { return 1; },
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/RunCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/RunCommandTest.cpp
index 07eecb3..11d4ada 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/RunCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/RunCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/RunCommand.h"
@@ -11,7 +8,7 @@
using namespace frc2;
class RunCommandTest : public CommandTestBase {};
-TEST_F(RunCommandTest, RunCommandScheduleTest) {
+TEST_F(RunCommandTest, RunCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ScheduleCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ScheduleCommandTest.cpp
index 29e8dc5..4003b4a 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ScheduleCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ScheduleCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <regex>
@@ -15,7 +12,7 @@
using namespace frc2;
class ScheduleCommandTest : public CommandTestBase {};
-TEST_F(ScheduleCommandTest, ScheduleCommandScheduleTest) {
+TEST_F(ScheduleCommandTest, ScheduleCommandSchedule) {
CommandScheduler& scheduler = CommandScheduler::GetInstance();
bool scheduled = false;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/SchedulerTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/SchedulerTest.cpp
index 2582ad9..c0f1e5a 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/SchedulerTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/SchedulerTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/InstantCommand.h"
@@ -29,7 +26,7 @@
EXPECT_EQ(counter, 3);
}
-TEST_F(SchedulerTest, SchedulerLambdaInterruptTest) {
+TEST_F(SchedulerTest, SchedulerLambdaInterrupt) {
CommandScheduler scheduler = GetScheduler();
RunCommand command([] {}, {});
@@ -45,7 +42,7 @@
EXPECT_EQ(counter, 1);
}
-TEST_F(SchedulerTest, UnregisterSubsystemTest) {
+TEST_F(SchedulerTest, UnregisterSubsystem) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem system;
@@ -55,7 +52,7 @@
EXPECT_NO_FATAL_FAILURE(scheduler.UnregisterSubsystem(&system));
}
-TEST_F(SchedulerTest, SchedulerCancelAllTest) {
+TEST_F(SchedulerTest, SchedulerCancelAll) {
CommandScheduler scheduler = GetScheduler();
RunCommand command([] {}, {});
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp
index 6be14ef..409e2a6 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/ConditionalCommand.h"
@@ -13,7 +10,7 @@
using namespace frc2;
class SelectCommandTest : public CommandTestBase {};
-TEST_F(SelectCommandTest, SelectCommandTest) {
+TEST_F(SelectCommandTest, SelectCommand) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> mock = std::make_unique<MockCommand>();
@@ -39,7 +36,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&select));
}
-TEST_F(SelectCommandTest, SelectCommandRequirementTest) {
+TEST_F(SelectCommandTest, SelectCommandRequirement) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement1;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/SequentialCommandGroupTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/SequentialCommandGroupTest.cpp
index 3a6f8d8..2d88c0a 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/SequentialCommandGroupTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/SequentialCommandGroupTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/InstantCommand.h"
@@ -13,7 +10,7 @@
using namespace frc2;
class SequentialCommandGroupTest : public CommandTestBase {};
-TEST_F(SequentialCommandGroupTest, SequentialGroupScheduleTest) {
+TEST_F(SequentialCommandGroupTest, SequentialGroupSchedule) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
@@ -52,7 +49,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(SequentialCommandGroupTest, SequentialGroupInterruptTest) {
+TEST_F(SequentialCommandGroupTest, SequentialGroupInterrupt) {
CommandScheduler scheduler = GetScheduler();
std::unique_ptr<MockCommand> command1Holder = std::make_unique<MockCommand>();
@@ -91,7 +88,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(SequentialCommandGroupTest, SequentialGroupNotScheduledCancelTest) {
+TEST_F(SequentialCommandGroupTest, SequentialGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
SequentialCommandGroup group{InstantCommand(), InstantCommand()};
@@ -99,7 +96,7 @@
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(&group));
}
-TEST_F(SequentialCommandGroupTest, SequentialGroupCopyTest) {
+TEST_F(SequentialCommandGroupTest, SequentialGroupCopy) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
@@ -115,7 +112,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&group));
}
-TEST_F(SequentialCommandGroupTest, SequentialGroupRequirementTest) {
+TEST_F(SequentialCommandGroupTest, SequentialGroupRequirement) {
CommandScheduler scheduler = GetScheduler();
TestSubsystem requirement1;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/StartEndCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/StartEndCommandTest.cpp
index 3f25792..53a2df2 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/StartEndCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/StartEndCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/StartEndCommand.h"
@@ -11,7 +8,7 @@
using namespace frc2;
class StartEndCommandTest : public CommandTestBase {};
-TEST_F(StartEndCommandTest, StartEndCommandScheduleTest) {
+TEST_F(StartEndCommandTest, StartEndCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp
index b2c47d0..93117b8 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc2/Timer.h>
#include <frc2/command/Subsystem.h>
#include <frc2/command/SwerveControllerCommand.h>
+#include <frc/Timer.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
#include <frc/geometry/Rotation2d.h>
@@ -18,7 +15,7 @@
#include <frc/kinematics/SwerveModuleState.h>
#include <frc/simulation/SimHooks.h>
#include <frc/trajectory/TrajectoryGenerator.h>
-#include <wpi/math>
+#include <wpi/numbers>
#include "gtest/gtest.h"
@@ -31,10 +28,10 @@
units::inverse<units::squared<units::second>>>;
protected:
- frc2::Timer m_timer;
+ frc::Timer m_timer;
frc::Rotation2d m_angle{0_rad};
- std::array<frc::SwerveModuleState, 4> m_moduleStates{
+ wpi::array<frc::SwerveModuleState, 4> m_moduleStates{
frc::SwerveModuleState{}, frc::SwerveModuleState{},
frc::SwerveModuleState{}, frc::SwerveModuleState{}};
@@ -63,7 +60,7 @@
void TearDown() override { frc::sim::ResumeTiming(); }
- std::array<frc::SwerveModuleState, 4> getCurrentWheelSpeeds() {
+ wpi::array<frc::SwerveModuleState, 4> getCurrentWheelSpeeds() {
return m_moduleStates;
}
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitCommandTest.cpp
index 000a9bb..30eea6b 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/simulation/SimHooks.h>
@@ -14,7 +11,7 @@
using namespace frc2;
class WaitCommandTest : public CommandTestBase {};
-TEST_F(WaitCommandTest, WaitCommandScheduleTest) {
+TEST_F(WaitCommandTest, WaitCommandSchedule) {
frc::sim::PauseTiming();
CommandScheduler scheduler = GetScheduler();
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitUntilCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitUntilCommandTest.cpp
index e9728db..01acc39 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitUntilCommandTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/WaitUntilCommandTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/WaitUntilCommand.h"
@@ -11,7 +8,7 @@
using namespace frc2;
class WaitUntilCommandTest : public CommandTestBase {};
-TEST_F(WaitUntilCommandTest, WaitUntilCommandScheduleTest) {
+TEST_F(WaitUntilCommandTest, WaitUntilCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
bool finished = false;
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ButtonTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/ButtonTest.cpp
similarity index 83%
rename from wpilibNewCommands/src/test/native/cpp/frc2/command/ButtonTest.cpp
rename to wpilibNewCommands/src/test/native/cpp/frc2/command/button/ButtonTest.cpp
index d504ff7..db4276d 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ButtonTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/ButtonTest.cpp
@@ -1,11 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include "CommandTestBase.h"
+#include <frc/simulation/SimHooks.h>
+
+#include "../CommandTestBase.h"
#include "frc2/command/CommandScheduler.h"
#include "frc2/command/RunCommand.h"
#include "frc2/command/WaitUntilCommand.h"
@@ -15,7 +14,7 @@
using namespace frc2;
class ButtonTest : public CommandTestBase {};
-TEST_F(ButtonTest, WhenPressedTest) {
+TEST_F(ButtonTest, WhenPressed) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed = false;
@@ -33,7 +32,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(ButtonTest, WhenReleasedTest) {
+TEST_F(ButtonTest, WhenReleased) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed = false;
@@ -51,7 +50,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(ButtonTest, WhileHeldTest) {
+TEST_F(ButtonTest, WhileHeld) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed = false;
@@ -74,7 +73,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(ButtonTest, WhenHeldTest) {
+TEST_F(ButtonTest, WhenHeld) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed = false;
@@ -102,7 +101,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(ButtonTest, ToggleWhenPressedTest) {
+TEST_F(ButtonTest, ToggleWhenPressed) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed = false;
@@ -122,7 +121,7 @@
EXPECT_FALSE(scheduler.IsScheduled(&command));
}
-TEST_F(ButtonTest, AndTest) {
+TEST_F(ButtonTest, And) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed1 = false;
@@ -140,7 +139,7 @@
EXPECT_TRUE(scheduler.IsScheduled(&command));
}
-TEST_F(ButtonTest, OrTest) {
+TEST_F(ButtonTest, Or) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed1 = false;
@@ -165,7 +164,7 @@
EXPECT_TRUE(scheduler.IsScheduled(&command2));
}
-TEST_F(ButtonTest, NegateTest) {
+TEST_F(ButtonTest, Negate) {
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
bool pressed = true;
@@ -179,7 +178,7 @@
EXPECT_TRUE(scheduler.IsScheduled(&command));
}
-TEST_F(ButtonTest, RValueButtonTest) {
+TEST_F(ButtonTest, RValueButton) {
auto& scheduler = CommandScheduler::GetInstance();
int counter = 0;
bool pressed = false;
@@ -193,3 +192,19 @@
scheduler.Run();
EXPECT_EQ(counter, 1);
}
+
+TEST_F(ButtonTest, Debounce) {
+ auto& scheduler = CommandScheduler::GetInstance();
+ bool pressed = false;
+ RunCommand command([] {});
+
+ Trigger([&pressed] { return pressed; }).Debounce(100_ms).WhenActive(&command);
+ pressed = true;
+ scheduler.Run();
+ EXPECT_FALSE(scheduler.IsScheduled(&command));
+
+ frc::sim::StepTiming(300_ms);
+
+ scheduler.Run();
+ EXPECT_TRUE(scheduler.IsScheduled(&command));
+}
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/button/NetworkButtonTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/NetworkButtonTest.cpp
index 18fef35..7de1084 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/button/NetworkButtonTest.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/NetworkButtonTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <networktables/NetworkTableInstance.h>
@@ -25,7 +22,7 @@
}
};
-TEST_F(NetworkButtonTest, SetNetworkButtonTest) {
+TEST_F(NetworkButtonTest, SetNetworkButton) {
auto& scheduler = CommandScheduler::GetInstance();
auto entry = nt::NetworkTableInstance::GetDefault()
.GetTable("TestTable")
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h b/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h
index 89d55b6..05adf8e 100644
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h
+++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/make_vector.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibNewCommands/src/test/native/cpp/main.cpp b/wpilibNewCommands/src/test/native/cpp/main.cpp
index c6b6c58..6aea19a 100644
--- a/wpilibNewCommands/src/test/native/cpp/main.cpp
+++ b/wpilibNewCommands/src/test/native/cpp/main.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <hal/HALBase.h>
diff --git a/wpilibNewCommands/wpilibNewCommands-config.cmake.in b/wpilibNewCommands/wpilibNewCommands-config.cmake.in
new file mode 100644
index 0000000..75aa6ad
--- /dev/null
+++ b/wpilibNewCommands/wpilibNewCommands-config.cmake.in
@@ -0,0 +1,11 @@
+include(CMakeFindDependencyMacro)
+ @FILENAME_DEP_REPLACE@
+ @WPIUTIL_DEP_REPLACE@
+ @NTCORE_DEP_REPLACE@
+ @CSCORE_DEP_REPLACE@
+ @CAMERASERVER_DEP_REPLACE@
+ @HAL_DEP_REPLACE@
+ @WPILIBC_DEP_REPLACE@
+ @WPIMATH_DEP_REPLACE@
+
+ include(${SELF_DIR}/wpilibNewCommands.cmake)