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/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDBase.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDBase.java
new file mode 100644
index 0000000..505801a
--- /dev/null
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDBase.java
@@ -0,0 +1,815 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+package edu.wpi.first.wpilibj;
+
+import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
+
+import edu.wpi.first.hal.FRCNetComm.tResourceType;
+import edu.wpi.first.hal.HAL;
+import edu.wpi.first.hal.util.BoundaryException;
+import edu.wpi.first.math.filter.LinearFilter;
+import edu.wpi.first.util.sendable.Sendable;
+import edu.wpi.first.util.sendable.SendableBuilder;
+import edu.wpi.first.util.sendable.SendableRegistry;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Class implements a PID Control Loop.
+ *
+ * <p>Creates a separate thread which reads the given PIDSource and takes care of the integral
+ * calculations, as well as writing the given PIDOutput.
+ *
+ * <p>This feedback controller runs in discrete time, so time deltas are not used in the integral
+ * and derivative calculations. Therefore, the sample rate affects the controller's behavior for a
+ * given set of PID constants.
+ *
+ * @deprecated All APIs which use this have been deprecated.
+ */
+@Deprecated(since = "2020", forRemoval = true)
+public class PIDBase implements PIDInterface, PIDOutput, Sendable, AutoCloseable {
+ public static final double kDefaultPeriod = 0.05;
+ private static int instances;
+
+ // Factor for "proportional" control
+ @SuppressWarnings("MemberName")
+ private double m_P;
+
+ // Factor for "integral" control
+ @SuppressWarnings("MemberName")
+ private double m_I;
+
+ // Factor for "derivative" control
+ @SuppressWarnings("MemberName")
+ private double m_D;
+
+ // Factor for "feed forward" control
+ @SuppressWarnings("MemberName")
+ private double m_F;
+
+ // |maximum output|
+ private double m_maximumOutput = 1.0;
+
+ // |minimum output|
+ private double m_minimumOutput = -1.0;
+
+ // Maximum input - limit setpoint to this
+ private double m_maximumInput;
+
+ // Minimum input - limit setpoint to this
+ private double m_minimumInput;
+
+ // Input range - difference between maximum and minimum
+ private double m_inputRange;
+
+ // Do the endpoints wrap around? (e.g., absolute encoder)
+ private boolean m_continuous;
+
+ // Is the PID controller enabled
+ protected boolean m_enabled;
+
+ // The prior error (used to compute velocity)
+ private double m_prevError;
+
+ // The sum of the errors for use in the integral calc
+ private double m_totalError;
+
+ // The tolerance object used to check if on target
+ private Tolerance m_tolerance;
+
+ private double m_setpoint;
+ private double m_prevSetpoint;
+
+ private double m_result;
+
+ private LinearFilter m_filter;
+
+ protected ReentrantLock m_thisMutex = new ReentrantLock();
+
+ // Ensures when disable() is called, pidWrite() won't run if calculate()
+ // is already running at that time.
+ protected ReentrantLock m_pidWriteMutex = new ReentrantLock();
+
+ protected PIDSource m_pidInput;
+ protected PIDOutput m_pidOutput;
+ protected Timer m_setpointTimer;
+
+ /**
+ * Tolerance is the type of tolerance used to specify if the PID controller is on target.
+ *
+ * <p>The various implementations of this class such as PercentageTolerance and AbsoluteTolerance
+ * specify types of tolerance specifications to use.
+ */
+ public interface Tolerance {
+ boolean onTarget();
+ }
+
+ /** Used internally for when Tolerance hasn't been set. */
+ public static class NullTolerance implements Tolerance {
+ @Override
+ public boolean onTarget() {
+ throw new IllegalStateException("No tolerance value set when calling onTarget().");
+ }
+ }
+
+ public class PercentageTolerance implements Tolerance {
+ private final double m_percentage;
+
+ PercentageTolerance(double value) {
+ m_percentage = value;
+ }
+
+ @Override
+ public boolean onTarget() {
+ return Math.abs(getError()) < m_percentage / 100 * m_inputRange;
+ }
+ }
+
+ public class AbsoluteTolerance implements Tolerance {
+ private final double m_value;
+
+ AbsoluteTolerance(double value) {
+ m_value = value;
+ }
+
+ @Override
+ public boolean onTarget() {
+ return Math.abs(getError()) < m_value;
+ }
+ }
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D, and F.
+ *
+ * @param Kp the proportional coefficient
+ * @param Ki the integral coefficient
+ * @param Kd the derivative coefficient
+ * @param Kf the feed forward term
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output percentage
+ */
+ @SuppressWarnings("ParameterName")
+ public PIDBase(double Kp, double Ki, double Kd, double Kf, PIDSource source, PIDOutput output) {
+ requireNonNullParam(source, "PIDSource", "PIDBase");
+ requireNonNullParam(output, "output", "PIDBase");
+
+ m_setpointTimer = new Timer();
+ m_setpointTimer.start();
+
+ m_P = Kp;
+ m_I = Ki;
+ m_D = Kd;
+ m_F = Kf;
+
+ m_pidInput = source;
+ m_filter = LinearFilter.movingAverage(1);
+
+ m_pidOutput = output;
+
+ instances++;
+ HAL.report(tResourceType.kResourceType_PIDController, instances);
+ m_tolerance = new NullTolerance();
+ SendableRegistry.add(this, "PIDController", instances);
+ }
+
+ /**
+ * Allocate a PID object with the given constants for P, I, and D.
+ *
+ * @param Kp the proportional coefficient
+ * @param Ki the integral coefficient
+ * @param Kd the derivative coefficient
+ * @param source the PIDSource object that is used to get values
+ * @param output the PIDOutput object that is set to the output percentage
+ */
+ @SuppressWarnings("ParameterName")
+ public PIDBase(double Kp, double Ki, double Kd, PIDSource source, PIDOutput output) {
+ this(Kp, Ki, Kd, 0.0, source, output);
+ }
+
+ @Override
+ public void close() {
+ SendableRegistry.remove(this);
+ }
+
+ /**
+ * Read the input, calculate the output accordingly, and write to the output. This should only be
+ * called by the PIDTask and is created during initialization.
+ */
+ @SuppressWarnings("LocalVariableName")
+ protected void calculate() {
+ if (m_pidInput == null || m_pidOutput == null) {
+ return;
+ }
+
+ boolean enabled;
+
+ m_thisMutex.lock();
+ try {
+ enabled = m_enabled;
+ } finally {
+ m_thisMutex.unlock();
+ }
+
+ if (enabled) {
+ double input;
+
+ // Storage for function inputs
+ PIDSourceType pidSourceType;
+ double P;
+ double I;
+ double D;
+ double feedForward = calculateFeedForward();
+ double minimumOutput;
+ double maximumOutput;
+
+ // Storage for function input-outputs
+ double prevError;
+ double error;
+ double totalError;
+
+ m_thisMutex.lock();
+ try {
+ input = m_filter.calculate(m_pidInput.pidGet());
+
+ pidSourceType = m_pidInput.getPIDSourceType();
+ P = m_P;
+ I = m_I;
+ D = m_D;
+ minimumOutput = m_minimumOutput;
+ maximumOutput = m_maximumOutput;
+
+ prevError = m_prevError;
+ error = getContinuousError(m_setpoint - input);
+ totalError = m_totalError;
+ } finally {
+ m_thisMutex.unlock();
+ }
+
+ // Storage for function outputs
+ double result;
+
+ if (pidSourceType.equals(PIDSourceType.kRate)) {
+ if (P != 0) {
+ totalError = clamp(totalError + error, minimumOutput / P, maximumOutput / P);
+ }
+
+ result = P * totalError + D * error + feedForward;
+ } else {
+ if (I != 0) {
+ totalError = clamp(totalError + error, minimumOutput / I, maximumOutput / I);
+ }
+
+ result = P * error + I * totalError + D * (error - prevError) + feedForward;
+ }
+
+ result = clamp(result, minimumOutput, maximumOutput);
+
+ // Ensures m_enabled check and pidWrite() call occur atomically
+ m_pidWriteMutex.lock();
+ m_thisMutex.lock();
+ try {
+ if (m_enabled) {
+ // Don't block other PIDController operations on pidWrite()
+ m_thisMutex.unlock();
+
+ m_pidOutput.pidWrite(result);
+ }
+ } finally {
+ if (!m_enabled) {
+ m_thisMutex.unlock();
+ }
+ m_pidWriteMutex.unlock();
+ }
+
+ m_thisMutex.lock();
+ try {
+ m_prevError = error;
+ m_totalError = totalError;
+ m_result = result;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+ }
+
+ /**
+ * Calculate the feed forward term.
+ *
+ * <p>Both of the provided feed forward calculations are velocity feed forwards. If a different
+ * feed forward calculation is desired, the user can override this function and provide his or her
+ * own. This function does no synchronization because the PIDController class only calls it in
+ * synchronized code, so be careful if calling it oneself.
+ *
+ * <p>If a velocity PID controller is being used, the F term should be set to 1 over the maximum
+ * setpoint for the output. If a position PID controller is being used, the F term should be set
+ * to 1 over the maximum speed for the output measured in setpoint units per this controller's
+ * update period (see the default period in this class's constructor).
+ *
+ * @return The feedforward value.
+ */
+ protected double calculateFeedForward() {
+ if (m_pidInput.getPIDSourceType().equals(PIDSourceType.kRate)) {
+ return m_F * getSetpoint();
+ } else {
+ double temp = m_F * getDeltaSetpoint();
+ m_prevSetpoint = m_setpoint;
+ m_setpointTimer.reset();
+ return temp;
+ }
+ }
+
+ /**
+ * Set the PID Controller gain parameters. Set the proportional, integral, and differential
+ * coefficients.
+ *
+ * @param p Proportional coefficient
+ * @param i Integral coefficient
+ * @param d Differential coefficient
+ */
+ @Override
+ @SuppressWarnings("ParameterName")
+ public void setPID(double p, double i, double d) {
+ m_thisMutex.lock();
+ try {
+ m_P = p;
+ m_I = i;
+ m_D = d;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the PID Controller gain parameters. Set the proportional, integral, and differential
+ * coefficients.
+ *
+ * @param p Proportional coefficient
+ * @param i Integral coefficient
+ * @param d Differential coefficient
+ * @param f Feed forward coefficient
+ */
+ @SuppressWarnings("ParameterName")
+ public void setPID(double p, double i, double d, double f) {
+ m_thisMutex.lock();
+ try {
+ m_P = p;
+ m_I = i;
+ m_D = d;
+ m_F = f;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the Proportional coefficient of the PID controller gain.
+ *
+ * @param p Proportional coefficient
+ */
+ @SuppressWarnings("ParameterName")
+ public void setP(double p) {
+ m_thisMutex.lock();
+ try {
+ m_P = p;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the Integral coefficient of the PID controller gain.
+ *
+ * @param i Integral coefficient
+ */
+ @SuppressWarnings("ParameterName")
+ public void setI(double i) {
+ m_thisMutex.lock();
+ try {
+ m_I = i;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the Differential coefficient of the PID controller gain.
+ *
+ * @param d differential coefficient
+ */
+ @SuppressWarnings("ParameterName")
+ public void setD(double d) {
+ m_thisMutex.lock();
+ try {
+ m_D = d;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the Feed forward coefficient of the PID controller gain.
+ *
+ * @param f feed forward coefficient
+ */
+ @SuppressWarnings("ParameterName")
+ public void setF(double f) {
+ m_thisMutex.lock();
+ try {
+ m_F = f;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Get the Proportional coefficient.
+ *
+ * @return proportional coefficient
+ */
+ @Override
+ public double getP() {
+ m_thisMutex.lock();
+ try {
+ return m_P;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Get the Integral coefficient.
+ *
+ * @return integral coefficient
+ */
+ @Override
+ public double getI() {
+ m_thisMutex.lock();
+ try {
+ return m_I;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Get the Differential coefficient.
+ *
+ * @return differential coefficient
+ */
+ @Override
+ public double getD() {
+ m_thisMutex.lock();
+ try {
+ return m_D;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Get the Feed forward coefficient.
+ *
+ * @return feed forward coefficient
+ */
+ public double getF() {
+ m_thisMutex.lock();
+ try {
+ return m_F;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Return the current PID result This is always centered on zero and constrained the the max and
+ * min outs.
+ *
+ * @return the latest calculated output
+ */
+ public double get() {
+ m_thisMutex.lock();
+ try {
+ return m_result;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the PID controller to consider the input to be continuous, Rather then using the max and
+ * min input range as constraints, it considers them to be the same point and automatically
+ * calculates the shortest route to the setpoint.
+ *
+ * @param continuous Set to true turns on continuous, false turns off continuous
+ */
+ public void setContinuous(boolean continuous) {
+ if (continuous && m_inputRange <= 0) {
+ throw new IllegalStateException("No input range set when calling setContinuous().");
+ }
+ m_thisMutex.lock();
+ try {
+ m_continuous = continuous;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the PID controller to consider the input to be continuous, Rather then using the max and
+ * min input range as constraints, it considers them to be the same point and automatically
+ * calculates the shortest route to the setpoint.
+ */
+ public void setContinuous() {
+ setContinuous(true);
+ }
+
+ /**
+ * Sets the maximum and minimum values expected from the input and setpoint.
+ *
+ * @param minimumInput the minimum value expected from the input
+ * @param maximumInput the maximum value expected from the input
+ */
+ public void setInputRange(double minimumInput, double maximumInput) {
+ m_thisMutex.lock();
+ try {
+ if (minimumInput > maximumInput) {
+ throw new BoundaryException("Lower bound is greater than upper bound");
+ }
+ m_minimumInput = minimumInput;
+ m_maximumInput = maximumInput;
+ m_inputRange = maximumInput - minimumInput;
+ } finally {
+ m_thisMutex.unlock();
+ }
+
+ setSetpoint(m_setpoint);
+ }
+
+ /**
+ * Sets the minimum and maximum values to write.
+ *
+ * @param minimumOutput the minimum percentage to write to the output
+ * @param maximumOutput the maximum percentage to write to the output
+ */
+ public void setOutputRange(double minimumOutput, double maximumOutput) {
+ m_thisMutex.lock();
+ try {
+ if (minimumOutput > maximumOutput) {
+ throw new BoundaryException("Lower bound is greater than upper bound");
+ }
+ m_minimumOutput = minimumOutput;
+ m_maximumOutput = maximumOutput;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the setpoint for the PIDController.
+ *
+ * @param setpoint the desired setpoint
+ */
+ @Override
+ public void setSetpoint(double setpoint) {
+ m_thisMutex.lock();
+ try {
+ if (m_maximumInput > m_minimumInput) {
+ if (setpoint > m_maximumInput) {
+ m_setpoint = m_maximumInput;
+ } else if (setpoint < m_minimumInput) {
+ m_setpoint = m_minimumInput;
+ } else {
+ m_setpoint = setpoint;
+ }
+ } else {
+ m_setpoint = setpoint;
+ }
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Returns the current setpoint of the PIDController.
+ *
+ * @return the current setpoint
+ */
+ @Override
+ public double getSetpoint() {
+ m_thisMutex.lock();
+ try {
+ return m_setpoint;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Returns the change in setpoint over time of the PIDController.
+ *
+ * @return the change in setpoint over time
+ */
+ public double getDeltaSetpoint() {
+ m_thisMutex.lock();
+ try {
+ return (m_setpoint - m_prevSetpoint) / m_setpointTimer.get();
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Returns the current difference of the input from the setpoint.
+ *
+ * @return the current error
+ */
+ @Override
+ public double getError() {
+ m_thisMutex.lock();
+ try {
+ return getContinuousError(getSetpoint() - m_filter.calculate(m_pidInput.pidGet()));
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Returns the current difference of the error over the past few iterations. You can specify the
+ * number of iterations to average with setToleranceBuffer() (defaults to 1). getAvgError() is
+ * used for the onTarget() function.
+ *
+ * @deprecated Use getError(), which is now already filtered.
+ * @return the current average of the error
+ */
+ @Deprecated
+ public double getAvgError() {
+ m_thisMutex.lock();
+ try {
+ return getError();
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Sets what type of input the PID controller will use.
+ *
+ * @param pidSource the type of input
+ */
+ public void setPIDSourceType(PIDSourceType pidSource) {
+ m_pidInput.setPIDSourceType(pidSource);
+ }
+
+ /**
+ * Returns the type of input the PID controller is using.
+ *
+ * @return the PID controller input type
+ */
+ public PIDSourceType getPIDSourceType() {
+ return m_pidInput.getPIDSourceType();
+ }
+
+ /**
+ * Set the PID tolerance using a Tolerance object. Tolerance can be specified as a percentage of
+ * the range or as an absolute value. The Tolerance object encapsulates those options in an
+ * object. Use it by creating the type of tolerance that you want to use: setTolerance(new
+ * PIDController.AbsoluteTolerance(0.1))
+ *
+ * @deprecated Use setPercentTolerance() instead.
+ * @param tolerance A tolerance object of the right type, e.g. PercentTolerance or
+ * AbsoluteTolerance
+ */
+ @Deprecated
+ public void setTolerance(Tolerance tolerance) {
+ m_tolerance = tolerance;
+ }
+
+ /**
+ * Set the absolute error which is considered tolerable for use with OnTarget.
+ *
+ * @param absvalue absolute error which is tolerable in the units of the input object
+ */
+ public void setAbsoluteTolerance(double absvalue) {
+ m_thisMutex.lock();
+ try {
+ m_tolerance = new AbsoluteTolerance(absvalue);
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the percentage error which is considered tolerable for use with OnTarget. (Input of 15.0 =
+ * 15 percent)
+ *
+ * @param percentage percent error which is tolerable
+ */
+ public void setPercentTolerance(double percentage) {
+ m_thisMutex.lock();
+ try {
+ m_tolerance = new PercentageTolerance(percentage);
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the number of previous error samples to average for tolerancing. When determining whether a
+ * mechanism is on target, the user may want to use a rolling average of previous measurements
+ * instead of a precise position or velocity. This is useful for noisy sensors which return a few
+ * erroneous measurements when the mechanism is on target. However, the mechanism will not
+ * register as on target for at least the specified bufLength cycles.
+ *
+ * @deprecated Use a LinearFilter as the input.
+ * @param bufLength Number of previous cycles to average.
+ */
+ @Deprecated
+ public void setToleranceBuffer(int bufLength) {
+ m_thisMutex.lock();
+ try {
+ m_filter = LinearFilter.movingAverage(bufLength);
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Return true if the error is within the percentage of the total input range, determined by
+ * setTolerance. This assumes that the maximum and minimum input were set using setInput.
+ *
+ * @return true if the error is less than the tolerance
+ */
+ public boolean onTarget() {
+ m_thisMutex.lock();
+ try {
+ return m_tolerance.onTarget();
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /** Reset the previous error, the integral term, and disable the controller. */
+ @Override
+ public void reset() {
+ m_thisMutex.lock();
+ try {
+ m_prevError = 0;
+ m_totalError = 0;
+ m_result = 0;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /**
+ * Passes the output directly to setSetpoint().
+ *
+ * <p>PIDControllers can be nested by passing a PIDController as another PIDController's output.
+ * In that case, the output of the parent controller becomes the input (i.e., the reference) of
+ * the child.
+ *
+ * <p>It is the caller's responsibility to put the data into a valid form for setSetpoint().
+ */
+ @Override
+ public void pidWrite(double output) {
+ setSetpoint(output);
+ }
+
+ @Override
+ public void initSendable(SendableBuilder builder) {
+ builder.setSmartDashboardType("PIDController");
+ builder.setSafeState(this::reset);
+ builder.addDoubleProperty("p", this::getP, this::setP);
+ builder.addDoubleProperty("i", this::getI, this::setI);
+ builder.addDoubleProperty("d", this::getD, this::setD);
+ builder.addDoubleProperty("f", this::getF, this::setF);
+ builder.addDoubleProperty("setpoint", this::getSetpoint, this::setSetpoint);
+ }
+
+ /**
+ * Wraps error around for continuous inputs. The original error is returned if continuous mode is
+ * disabled. This is an unsynchronized function.
+ *
+ * @param error The current error of the PID controller.
+ * @return Error for continuous inputs.
+ */
+ protected double getContinuousError(double error) {
+ if (m_continuous && m_inputRange > 0) {
+ error %= m_inputRange;
+ if (Math.abs(error) > m_inputRange / 2) {
+ if (error > 0) {
+ return error - m_inputRange;
+ } else {
+ return error + m_inputRange;
+ }
+ }
+ }
+
+ return error;
+ }
+
+ private static double clamp(double value, double low, double high) {
+ return Math.max(low, Math.min(value, high));
+ }
+}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDController.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDController.java
new file mode 100644
index 0000000..ea7e98d
--- /dev/null
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDController.java
@@ -0,0 +1,180 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+package edu.wpi.first.wpilibj;
+
+import edu.wpi.first.util.sendable.SendableBuilder;
+
+/**
+ * Class implements a PID Control Loop.
+ *
+ * <p>Creates a separate thread which reads the given PIDSource and takes care of the integral
+ * calculations, as well as writing the given PIDOutput.
+ *
+ * <p>This feedback controller runs in discrete time, so time deltas are not used in the integral
+ * and derivative calculations. Therefore, the sample rate affects the controller's behavior for a
+ * given set of PID constants.
+ *
+ * @deprecated Use {@link edu.wpi.first.math.controller.PIDController} instead.
+ */
+@Deprecated(since = "2020", forRemoval = true)
+public class PIDController extends PIDBase implements Controller {
+ Notifier m_controlLoop = new Notifier(this::calculate);
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D, and F.
+ *
+ * @param Kp the proportional coefficient
+ * @param Ki the integral coefficient
+ * @param Kd the derivative coefficient
+ * @param Kf the feed forward term
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output percentage
+ * @param period the loop time for doing calculations in seconds. This particularly affects
+ * calculations of the integral and differential terms. The default is 0.05 (50ms).
+ */
+ @SuppressWarnings("ParameterName")
+ public PIDController(
+ double Kp,
+ double Ki,
+ double Kd,
+ double Kf,
+ PIDSource source,
+ PIDOutput output,
+ double period) {
+ super(Kp, Ki, Kd, Kf, source, output);
+ m_controlLoop.startPeriodic(period);
+ }
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D and period.
+ *
+ * @param Kp the proportional coefficient
+ * @param Ki the integral coefficient
+ * @param Kd the derivative coefficient
+ * @param source the PIDSource object that is used to get values
+ * @param output the PIDOutput object that is set to the output percentage
+ * @param period the loop time for doing calculations in seconds. This particularly affects
+ * calculations of the integral and differential terms. The default is 0.05 (50ms).
+ */
+ @SuppressWarnings("ParameterName")
+ public PIDController(
+ double Kp, double Ki, double Kd, PIDSource source, PIDOutput output, double period) {
+ this(Kp, Ki, Kd, 0.0, source, output, period);
+ }
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D, using a 50ms period.
+ *
+ * @param Kp the proportional coefficient
+ * @param Ki the integral coefficient
+ * @param Kd the derivative coefficient
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output percentage
+ */
+ @SuppressWarnings("ParameterName")
+ public PIDController(double Kp, double Ki, double Kd, PIDSource source, PIDOutput output) {
+ this(Kp, Ki, Kd, source, output, kDefaultPeriod);
+ }
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D, using a 50ms period.
+ *
+ * @param Kp the proportional coefficient
+ * @param Ki the integral coefficient
+ * @param Kd the derivative coefficient
+ * @param Kf the feed forward term
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output percentage
+ */
+ @SuppressWarnings("ParameterName")
+ public PIDController(
+ double Kp, double Ki, double Kd, double Kf, PIDSource source, PIDOutput output) {
+ this(Kp, Ki, Kd, Kf, source, output, kDefaultPeriod);
+ }
+
+ @Override
+ public void close() {
+ m_controlLoop.close();
+ m_thisMutex.lock();
+ try {
+ m_pidOutput = null;
+ m_pidInput = null;
+ m_controlLoop = null;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /** Begin running the PIDController. */
+ @Override
+ public void enable() {
+ m_thisMutex.lock();
+ try {
+ m_enabled = true;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /** Stop running the PIDController, this sets the output to zero before stopping. */
+ @Override
+ public void disable() {
+ // Ensures m_enabled check and pidWrite() call occur atomically
+ m_pidWriteMutex.lock();
+ try {
+ m_thisMutex.lock();
+ try {
+ m_enabled = false;
+ } finally {
+ m_thisMutex.unlock();
+ }
+
+ m_pidOutput.pidWrite(0);
+ } finally {
+ m_pidWriteMutex.unlock();
+ }
+ }
+
+ /**
+ * Set the enabled state of the PIDController.
+ *
+ * @param enable True to enable the PIDController.
+ */
+ public void setEnabled(boolean enable) {
+ if (enable) {
+ enable();
+ } else {
+ disable();
+ }
+ }
+
+ /**
+ * Return true if PIDController is enabled.
+ *
+ * @return True if PIDController is enabled.
+ */
+ public boolean isEnabled() {
+ m_thisMutex.lock();
+ try {
+ return m_enabled;
+ } finally {
+ m_thisMutex.unlock();
+ }
+ }
+
+ /** Reset the previous error, the integral term, and disable the controller. */
+ @Override
+ public void reset() {
+ disable();
+
+ super.reset();
+ }
+
+ @Override
+ public void initSendable(SendableBuilder builder) {
+ super.initSendable(builder);
+ builder.addBooleanProperty("enabled", this::isEnabled, this::setEnabled);
+ }
+}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDInterface.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDInterface.java
new file mode 100644
index 0000000..0e8b2f1
--- /dev/null
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDInterface.java
@@ -0,0 +1,25 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+package edu.wpi.first.wpilibj;
+
+@Deprecated(since = "2020", forRemoval = true)
+@SuppressWarnings("SummaryJavadoc")
+public interface PIDInterface {
+ void setPID(double p, double i, double d);
+
+ double getP();
+
+ double getI();
+
+ double getD();
+
+ void setSetpoint(double setpoint);
+
+ double getSetpoint();
+
+ double getError();
+
+ void reset();
+}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java
new file mode 100644
index 0000000..52f5a99
--- /dev/null
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java
@@ -0,0 +1,21 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+package edu.wpi.first.wpilibj;
+
+/**
+ * This interface allows PIDController to write it's results to its output.
+ *
+ * @deprecated Use DoubleConsumer and new PIDController class.
+ */
+@FunctionalInterface
+@Deprecated(since = "2020", forRemoval = true)
+public interface PIDOutput {
+ /**
+ * Set the output to the value calculated by PIDController.
+ *
+ * @param output the value calculated by PIDController
+ */
+ void pidWrite(double output);
+}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSource.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSource.java
new file mode 100644
index 0000000..c50a988
--- /dev/null
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSource.java
@@ -0,0 +1,34 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+package edu.wpi.first.wpilibj;
+
+/**
+ * This interface allows for PIDController to automatically read from this object.
+ *
+ * @deprecated Use DoubleSupplier and new PIDController class.
+ */
+@Deprecated(since = "2020", forRemoval = true)
+public interface PIDSource {
+ /**
+ * Set which parameter of the device you are using as a process control variable.
+ *
+ * @param pidSource An enum to select the parameter.
+ */
+ void setPIDSourceType(PIDSourceType pidSource);
+
+ /**
+ * Get which parameter of the device you are using as a process control variable.
+ *
+ * @return the currently selected PID source parameter
+ */
+ PIDSourceType getPIDSourceType();
+
+ /**
+ * Get the result to use in PIDController.
+ *
+ * @return the result to use in PIDController
+ */
+ double pidGet();
+}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSourceType.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSourceType.java
new file mode 100644
index 0000000..4018ba6
--- /dev/null
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSourceType.java
@@ -0,0 +1,12 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+package edu.wpi.first.wpilibj;
+
+/** A description for the type of output value to provide to a PIDController. */
+@Deprecated(since = "2020", forRemoval = true)
+public enum PIDSourceType {
+ kDisplacement,
+ kRate
+}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Button.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Button.java
index dcd4401..f674be3 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Button.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Button.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.wpilibj.buttons;
@@ -32,7 +29,7 @@
/**
* Constantly starts the given command while the button is held.
*
- * {@link Command#start()} will be called repeatedly while the button is held, and will be
+ * <p>{@link Command#start()} will be called repeatedly while the button is held, and will be
* canceled when the button is released.
*
* @param command the command to start
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java
index c2a6eb1..c77e9aa 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/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.wpilibj.buttons;
@@ -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/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java
index 8d2b20e..f7f09e7 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java
@@ -1,17 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.buttons;
import edu.wpi.first.wpilibj.GenericHID;
-/**
- * A {@link Button} that gets its state from a {@link 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;
@@ -19,8 +14,7 @@
/**
* Create 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/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java
index 3176977..1351d16 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.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.wpilibj.buttons;
@@ -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/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/POVButton.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/POVButton.java
index 39c891d..73db913 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/POVButton.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/POVButton.java
@@ -1,17 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.buttons;
import edu.wpi.first.wpilibj.GenericHID;
-/**
- * A {@link Button} that gets its state from a POV on a {@link 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;
@@ -31,8 +26,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/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java
index f051776..22db6f6 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java
@@ -1,22 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.buttons;
-import edu.wpi.first.wpilibj.Sendable;
+import edu.wpi.first.util.sendable.Sendable;
+import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
/**
* 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
@@ -40,7 +37,6 @@
*
* @return whether get() return true or the internal table for SmartDashboard use is pressed.
*/
- @SuppressWarnings("PMD.UselessParentheses")
private boolean grab() {
return get() || m_sendablePressed;
}
@@ -70,7 +66,7 @@
/**
* Constantly starts the given command while the button is held.
*
- * {@link Command#start()} will be called repeatedly while the trigger is active, and will be
+ * <p>{@link Command#start()} will be called repeatedly while the trigger is active, and will be
* canceled when the trigger becomes inactive.
*
* @param command the command to start
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java
index 6233a43..234fed4 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java
@@ -1,19 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.command;
-import java.util.Enumeration;
-
+import edu.wpi.first.util.sendable.Sendable;
+import edu.wpi.first.util.sendable.SendableBuilder;
+import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.RobotState;
-import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
-import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
+import java.util.Enumeration;
/**
* The Command class is at the very core of the entire command framework. Every command can be
@@ -22,16 +18,16 @@
* execute()} until the {@link Command#isFinished() isFinished()} returns true. Once it does, {@link
* Command#end() end()} will be called.
*
- * <p>However, if at any point while it is running {@link Command#cancel() cancel()} is called,
- * then the command will be stopped and {@link Command#interrupted() interrupted()} will be called.
+ * <p>However, if at any point while it is running {@link Command#cancel() cancel()} is called, then
+ * the command will be stopped and {@link Command#interrupted() interrupted()} will be called.
*
* <p>If a command uses a {@link Subsystem}, then it should specify that it does so by calling the
* {@link Command#requires(Subsystem) requires(...)} method in its constructor. Note that a Command
* may have multiple requirements, and {@link Command#requires(Subsystem) requires(...)} should be
* called for each one.
*
- * <p>If a command is running and a new command with shared requirements is started, then one of
- * two things will happen. If the active command is interruptible, then {@link Command#cancel()
+ * <p>If a command is running and a new command with shared requirements is started, then one of two
+ * things will happen. If the active command is interruptible, then {@link Command#cancel()
* cancel()} will be called and the command will be removed to make way for the new one. If the
* active command is not interruptible, the other one will not even be started, and the active one
* will continue functioning.
@@ -41,64 +37,40 @@
* @see IllegalUseOfCommandException
*/
public abstract class Command implements Sendable, AutoCloseable {
- /**
- * The time since this command was initialized.
- */
+ /** The time since this command was initialized. */
private double m_startTime = -1;
- /**
- * The time (in seconds) before this command "times out" (or -1 if no timeout).
- */
+ /** The time (in seconds) before this command "times out" (or -1 if no timeout). */
private double m_timeout = -1;
- /**
- * Whether or not this command has been initialized.
- */
+ /** Whether or not this command has been initialized. */
private boolean m_initialized;
- /**
- * The required subsystems.
- */
+ /** The required subsystems. */
private final Set m_requirements = new Set();
- /**
- * Whether or not it is running.
- */
+ /** Whether or not it is running. */
private boolean m_running;
- /**
- * Whether or not it is interruptible.
- */
+ /** Whether or not it is interruptible. */
private boolean m_interruptible = true;
- /**
- * Whether or not it has been canceled.
- */
+ /** Whether or not it has been canceled. */
private boolean m_canceled;
- /**
- * Whether or not it has been locked.
- */
+ /** Whether or not it has been locked. */
private boolean m_locked;
- /**
- * Whether this command should run when the robot is disabled.
- */
+ /** Whether this command should run when the robot is disabled. */
private boolean m_runWhenDisabled;
- /**
- * Whether or not this command has completed running.
- */
+ /** Whether or not this command has completed running. */
private boolean m_completed;
- /**
- * The {@link CommandGroup} this is in.
- */
+ /** The {@link CommandGroup} this is in. */
private CommandGroup m_parent;
- /**
- * Creates a new command. The name of this command will be set to its class name.
- */
+ /** Creates a new command. The name of this command will be set to its class name. */
public Command() {
String name = getClass().getName();
SendableRegistry.add(this, name.substring(name.lastIndexOf('.') + 1));
@@ -149,7 +121,7 @@
/**
* Creates a new command with the given name.
*
- * @param name the name for this command
+ * @param name the name for this command
* @param subsystem the subsystem that this command requires
* @throws IllegalArgumentException if name is null
*/
@@ -162,7 +134,7 @@
* Creates a new command with the given timeout and a default name. The default name is the name
* of the class.
*
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time (in seconds) before this command "times out"
* @param subsystem the subsystem that this command requires
* @throws IllegalArgumentException if given a negative timeout
* @see Command#isTimedOut() isTimedOut()
@@ -175,7 +147,7 @@
/**
* Creates a new command with the given name and timeout.
*
- * @param name the name of the command
+ * @param name the name of the command
* @param timeout the time (in seconds) before this command "times out"
* @throws IllegalArgumentException if given a negative timeout or name was null.
* @see Command#isTimedOut() isTimedOut()
@@ -191,8 +163,8 @@
/**
* Creates a new command with the given name and timeout.
*
- * @param name the name of the command
- * @param timeout the time (in seconds) before this command "times out"
+ * @param name the name of the command
+ * @param timeout the time (in seconds) before this command "times out"
* @param subsystem the subsystem that this command requires
* @throws IllegalArgumentException if given a negative timeout
* @throws IllegalArgumentException if given a negative timeout or name was null.
@@ -239,9 +211,9 @@
* <p>Note that the recommended way to call this method is in the constructor.
*
* @param subsystem the {@link Subsystem} required
- * @throws IllegalArgumentException if subsystem is null
+ * @throws IllegalArgumentException if subsystem is null
* @throws IllegalUseOfCommandException if this command has started before or if it has been given
- * to a {@link CommandGroup}
+ * to a {@link CommandGroup}
* @see Subsystem
*/
protected synchronized void requires(Subsystem subsystem) {
@@ -296,30 +268,20 @@
return !isFinished();
}
- /**
- * The initialize method is called the first time this Command is run after being started.
- */
+ /** The initialize method is called the first time this Command is run after being started. */
protected void initialize() {}
- /**
- * A shadow method called before {@link Command#initialize() initialize()}.
- */
+ /** A shadow method called before {@link Command#initialize() initialize()}. */
@SuppressWarnings("MethodName")
- void _initialize() {
- }
+ void _initialize() {}
- /**
- * The execute method is called repeatedly until this Command either finishes or is canceled.
- */
+ /** The execute method is called repeatedly until this Command either finishes or is canceled. */
@SuppressWarnings("MethodName")
protected void execute() {}
- /**
- * A shadow method called before {@link Command#execute() execute()}.
- */
+ /** A shadow method called before {@link Command#execute() execute()}. */
@SuppressWarnings("MethodName")
- void _execute() {
- }
+ void _execute() {}
/**
* Returns whether this command is finished. If it is, then the command will be removed and {@link
@@ -329,9 +291,8 @@
* method for time-sensitive commands.
*
* <p>Returning false will result in the command never ending automatically. It may still be
- * canceled manually or interrupted by another command. Returning true will result in the
- * command executing once and finishing immediately. We recommend using {@link InstantCommand}
- * for this.
+ * canceled manually or interrupted by another command. Returning true will result in the command
+ * executing once and finishing immediately. We recommend using {@link InstantCommand} for this.
*
* @return whether this command is finished.
* @see Command#isTimedOut() isTimedOut()
@@ -344,12 +305,9 @@
*/
protected void end() {}
- /**
- * A shadow method called after {@link Command#end() end()}.
- */
+ /** A shadow method called after {@link Command#end() end()}. */
@SuppressWarnings("MethodName")
- void _end() {
- }
+ void _end() {}
/**
* Called when the command ends because somebody called {@link Command#cancel() cancel()} or
@@ -365,9 +323,7 @@
end();
}
- /**
- * A shadow method called after {@link Command#interrupted() interrupted()}.
- */
+ /** A shadow method called after {@link Command#interrupted() interrupted()}. */
@SuppressWarnings("MethodName")
void _interrupted() {}
@@ -395,15 +351,13 @@
* Subsystems}) of this command.
*
* @return the requirements (as an {@link Enumeration Enumeration} of {@link Subsystem
- * Subsystems}) of this command
+ * Subsystems}) of this command
*/
- synchronized Enumeration getRequirements() {
+ synchronized Enumeration<?> getRequirements() {
return m_requirements.getElements();
}
- /**
- * Prevents further changes from being made.
- */
+ /** Prevents further changes from being made. */
synchronized void lockChanges() {
m_locked = true;
}
@@ -415,8 +369,8 @@
*/
synchronized void validate(String message) {
if (m_locked) {
- throw new IllegalUseOfCommandException(message
- + " after being started or being added to a command group");
+ throw new IllegalUseOfCommandException(
+ message + " after being started or being added to a command group");
}
}
@@ -445,18 +399,18 @@
}
/**
- * Clears list of subsystem requirements. This is only used by
- * {@link ConditionalCommand} so canceling the chosen command works properly
- * in {@link CommandGroup}.
+ * Clears list of subsystem requirements. This is only used by {@link ConditionalCommand} so
+ * canceling the chosen command works properly in {@link CommandGroup}.
*/
protected void clearRequirements() {
m_requirements.clear();
}
/**
- * Starts up the command. Gets the command ready to start. <p> Note that the command will
- * eventually start, however it will not necessarily do so immediately, and may in fact be
- * canceled before initialize is even called. </p>
+ * Starts up the command. Gets the command ready to start.
+ *
+ * <p>Note that the command will eventually start, however it will not necessarily do so
+ * immediately, and may in fact be canceled before initialize is even called.
*
* @throws IllegalUseOfCommandException if the command is a part of a CommandGroup
*/
@@ -495,18 +449,21 @@
}
/**
- * This will cancel the current command. <p> This will cancel the current command eventually. It
- * can be called multiple times. And it can be called when the command is not running. If the
- * command is running though, then the command will be marked as canceled and eventually removed.
- * </p> <p> A command can not be canceled if it is a part of a command group, you must cancel the
- * command group instead. </p>
+ * This will cancel the current command.
+ *
+ * <p>This will cancel the current command eventually. It can be called multiple times. And it can
+ * be called when the command is not running. If the command is running though, then the command
+ * will be marked as canceled and eventually removed.
+ *
+ * <p>A command can not be canceled if it is a part of a command group, you must cancel the
+ * command group instead.
*
* @throws IllegalUseOfCommandException if this command is a part of a command group
*/
public synchronized void cancel() {
if (m_parent != null) {
- throw new IllegalUseOfCommandException("Can not manually cancel a command in a command "
- + "group");
+ throw new IllegalUseOfCommandException(
+ "Can not manually cancel a command in a command " + "group");
}
_cancel();
}
@@ -604,7 +561,6 @@
*
* @return Name
*/
- @Override
public String getName() {
return SendableRegistry.getName(this);
}
@@ -614,7 +570,6 @@
*
* @param name name
*/
- @Override
public void setName(String name) {
SendableRegistry.setName(this, name);
}
@@ -624,7 +579,6 @@
*
* @return Subsystem name
*/
- @Override
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
@@ -634,7 +588,6 @@
*
* @param subsystem subsystem name
*/
- @Override
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
@@ -653,17 +606,20 @@
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Command");
builder.addStringProperty(".name", this::getName, null);
- builder.addBooleanProperty("running", this::isRunning, value -> {
- if (value) {
- if (!isRunning()) {
- start();
- }
- } else {
- if (isRunning()) {
- cancel();
- }
- }
- });
+ builder.addBooleanProperty(
+ "running",
+ this::isRunning,
+ value -> {
+ if (value) {
+ if (!isRunning()) {
+ start();
+ }
+ } else {
+ if (isRunning()) {
+ cancel();
+ }
+ }
+ });
builder.addBooleanProperty(".isParented", this::isParented, null);
}
}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java
index ef4f353..18e0ca6 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java
@@ -1,61 +1,51 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.command;
+import static java.util.Objects.requireNonNull;
+
import java.util.Enumeration;
import java.util.Vector;
-import static java.util.Objects.requireNonNull;
-
/**
* A {@link CommandGroup} is a list of commands which are executed in sequence.
*
- * <p> Commands in a {@link CommandGroup} are added using the {@link
+ * <p>Commands in a {@link CommandGroup} are added using the {@link
* CommandGroup#addSequential(Command) addSequential(...)} method and are called sequentially.
* {@link CommandGroup CommandGroups} are themselves {@link Command commands} and can be given to
- * other {@link CommandGroup CommandGroups}. </p>
+ * other {@link CommandGroup CommandGroups}.
*
- * <p> {@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command
+ * <p>{@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command
* subcommands}. Additional requirements can be specified by calling {@link
- * CommandGroup#requires(Subsystem) requires(...)} normally in the constructor. </P>
+ * CommandGroup#requires(Subsystem) requires(...)} normally in the constructor.
*
- * <p> CommandGroups can also execute commands in parallel, simply by adding them using {@link
- * CommandGroup#addParallel(Command) addParallel(...)}. </p>
+ * <p>CommandGroups can also execute commands in parallel, simply by adding them using {@link
+ * CommandGroup#addParallel(Command) addParallel(...)}.
*
* @see Command
* @see Subsystem
* @see IllegalUseOfCommandException
*/
public class CommandGroup extends Command {
- /**
- * The commands in this group (stored in entries).
- */
- @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
+ /** The commands in this group (stored in entries). */
+ @SuppressWarnings("PMD.UseArrayListInsteadOfVector")
private final Vector<Entry> m_commands = new Vector<>();
/*
* Intentionally package private
*/
- /**
- * The active children in this group (stored in entries).
- */
- @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
+ /** The active children in this group (stored in entries). */
+ @SuppressWarnings("PMD.UseArrayListInsteadOfVector")
final Vector<Entry> m_children = new Vector<>();
- /**
- * The current command, -1 signifies that none have been run.
- */
+ /** The current command, -1 signifies that none have been run. */
private int m_currentCommandIndex = -1;
/**
* Creates a new {@link CommandGroup CommandGroup}. The name of this command will be set to its
* class name.
*/
- public CommandGroup() {
- }
+ public CommandGroup() {}
/**
* Creates a new {@link CommandGroup CommandGroup} with the given name.
@@ -71,16 +61,16 @@
* Adds a new {@link Command Command} to the group. The {@link Command Command} will be started
* after all the previously added {@link Command Commands}.
*
- * <p> Note that any requirements the given {@link Command Command} has will be added to the
- * group. For this reason, a {@link Command Command's} requirements can not be changed after being
- * added to a group. </p>
+ * <p>Note that any requirements the given {@link Command Command} has will be added to the group.
+ * For this reason, a {@link Command Command's} requirements can not be changed after being added
+ * to a group.
*
- * <p> It is recommended that this method be called in the constructor. </p>
+ * <p>It is recommended that this method be called in the constructor.
*
* @param command The {@link Command Command} to be added
* @throws IllegalUseOfCommandException if the group has been started before or been given to
- * another group
- * @throws IllegalArgumentException if command is null
+ * another group
+ * @throws IllegalArgumentException if command is null
*/
public final synchronized void addSequential(Command command) {
validate("Can not add new command to command group");
@@ -91,7 +81,7 @@
command.setParent(this);
m_commands.addElement(new Entry(command, Entry.IN_SEQUENCE));
- for (Enumeration e = command.getRequirements(); e.hasMoreElements(); ) {
+ for (Enumeration<?> e = command.getRequirements(); e.hasMoreElements(); ) {
requires((Subsystem) e.nextElement());
}
}
@@ -100,22 +90,22 @@
* Adds a new {@link Command Command} to the group with a given timeout. The {@link Command
* Command} will be started after all the previously added commands.
*
- * <p> Once the {@link Command Command} is started, it will be run until it finishes or the time
+ * <p>Once the {@link Command Command} is started, it will be run until it finishes or the time
* expires, whichever is sooner. Note that the given {@link Command Command} will have no
- * knowledge that it is on a timer. </p>
+ * knowledge that it is on a timer.
*
- * <p> Note that any requirements the given {@link Command Command} has will be added to the
- * group. For this reason, a {@link Command Command's} requirements can not be changed after being
- * added to a group. </p>
+ * <p>Note that any requirements the given {@link Command Command} has will be added to the group.
+ * For this reason, a {@link Command Command's} requirements can not be changed after being added
+ * to a group.
*
- * <p> It is recommended that this method be called in the constructor. </p>
+ * <p>It is recommended that this method be called in the constructor.
*
* @param command The {@link Command Command} to be added
* @param timeout The timeout (in seconds)
* @throws IllegalUseOfCommandException if the group has been started before or been given to
- * another group or if the {@link Command Command} has been
- * started before or been given to another group
- * @throws IllegalArgumentException if command is null or timeout is negative
+ * another group or if the {@link Command Command} has been started before or been given to
+ * another group
+ * @throws IllegalArgumentException if command is null or timeout is negative
*/
public final synchronized void addSequential(Command command, double timeout) {
validate("Can not add new command to command group");
@@ -129,7 +119,7 @@
command.setParent(this);
m_commands.addElement(new Entry(command, Entry.IN_SEQUENCE, timeout));
- for (Enumeration e = command.getRequirements(); e.hasMoreElements(); ) {
+ for (Enumeration<?> e = command.getRequirements(); e.hasMoreElements(); ) {
requires((Subsystem) e.nextElement());
}
}
@@ -138,22 +128,22 @@
* Adds a new child {@link Command} to the group. The {@link Command} will be started after all
* the previously added {@link Command Commands}.
*
- * <p> Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
+ * <p>Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
* same time as the subsequent {@link Command Commands}. The child will run until either it
* finishes, a new child with conflicting requirements is started, or the main sequence runs a
* {@link Command} with conflicting requirements. In the latter two cases, the child will be
- * canceled even if it says it can't be interrupted. </p>
+ * canceled even if it says it can't be interrupted.
*
- * <p> Note that any requirements the given {@link Command Command} has will be added to the
- * group. For this reason, a {@link Command Command's} requirements can not be changed after being
- * added to a group. </p>
+ * <p>Note that any requirements the given {@link Command Command} has will be added to the group.
+ * For this reason, a {@link Command Command's} requirements can not be changed after being added
+ * to a group.
*
- * <p> It is recommended that this method be called in the constructor. </p>
+ * <p>It is recommended that this method be called in the constructor.
*
* @param command The command to be added
* @throws IllegalUseOfCommandException if the group has been started before or been given to
- * another command group
- * @throws IllegalArgumentException if command is null
+ * another command group
+ * @throws IllegalArgumentException if command is null
*/
public final synchronized void addParallel(Command command) {
requireNonNull(command, "Provided command was null");
@@ -162,7 +152,7 @@
command.setParent(this);
m_commands.addElement(new Entry(command, Entry.BRANCH_CHILD));
- for (Enumeration e = command.getRequirements(); e.hasMoreElements(); ) {
+ for (Enumeration<?> e = command.getRequirements(); e.hasMoreElements(); ) {
requires((Subsystem) e.nextElement());
}
}
@@ -171,27 +161,27 @@
* Adds a new child {@link Command} to the group with the given timeout. The {@link Command} will
* be started after all the previously added {@link Command Commands}.
*
- * <p> Once the {@link Command Command} is started, it will run until it finishes, is interrupted,
+ * <p>Once the {@link Command Command} is started, it will run until it finishes, is interrupted,
* or the time expires, whichever is sooner. Note that the given {@link Command Command} will have
- * no knowledge that it is on a timer. </p>
+ * no knowledge that it is on a timer.
*
- * <p> Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
+ * <p>Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
* same time as the subsequent {@link Command Commands}. The child will run until either it
* finishes, the timeout expires, a new child with conflicting requirements is started, or the
* main sequence runs a {@link Command} with conflicting requirements. In the latter two cases,
- * the child will be canceled even if it says it can't be interrupted. </p>
+ * the child will be canceled even if it says it can't be interrupted.
*
- * <p> Note that any requirements the given {@link Command Command} has will be added to the
- * group. For this reason, a {@link Command Command's} requirements can not be changed after being
- * added to a group. </p>
+ * <p>Note that any requirements the given {@link Command Command} has will be added to the group.
+ * For this reason, a {@link Command Command's} requirements can not be changed after being added
+ * to a group.
*
- * <p> It is recommended that this method be called in the constructor. </p>
+ * <p>It is recommended that this method be called in the constructor.
*
* @param command The command to be added
* @param timeout The timeout (in seconds)
* @throws IllegalUseOfCommandException if the group has been started before or been given to
- * another command group
- * @throws IllegalArgumentException if command is null
+ * another command group
+ * @throws IllegalArgumentException if command is null
*/
public final synchronized void addParallel(Command command, double timeout) {
requireNonNull(command, "Provided command was null");
@@ -203,7 +193,7 @@
command.setParent(this);
m_commands.addElement(new Entry(command, Entry.BRANCH_CHILD, timeout));
- for (Enumeration e = command.getRequirements(); e.hasMoreElements(); ) {
+ for (Enumeration<?> e = command.getRequirements(); e.hasMoreElements(); ) {
requires((Subsystem) e.nextElement());
}
}
@@ -215,7 +205,7 @@
}
@Override
- @SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
+ @SuppressWarnings("MethodName")
void _execute() {
Entry entry = null;
Command cmd = null;
@@ -293,7 +283,7 @@
cmd.removed();
}
- Enumeration children = m_children.elements();
+ Enumeration<?> children = m_children.elements();
while (children.hasMoreElements()) {
Command cmd = ((Entry) children.nextElement()).m_command;
cmd._cancel();
@@ -312,8 +302,8 @@
* Returns true if all the {@link Command Commands} in this group have been started and have
* finished.
*
- * <p> Teams may override this method, although they should probably reference super.isFinished()
- * if they do. </p>
+ * <p>Teams may override this method, although they should probably reference super.isFinished()
+ * if they do.
*
* @return whether this {@link CommandGroup} is finished
*/
@@ -324,27 +314,23 @@
// Can be overwritten by teams
@Override
- protected void initialize() {
- }
+ protected void initialize() {}
// Can be overwritten by teams
@Override
- protected void execute() {
- }
+ protected void execute() {}
// Can be overwritten by teams
@Override
- protected void end() {
- }
+ protected void end() {}
// Can be overwritten by teams
@Override
- protected void interrupted() {
- }
+ protected void interrupted() {}
/**
* Returns whether or not this group is interruptible. A command group will be uninterruptible if
- * {@link CommandGroup#setInterruptible(boolean) setInterruptable(false)} was called or if it is
+ * {@link CommandGroup#setInterruptible(boolean) setInterruptible(false)} was called or if it is
* currently running an uninterruptible command or child.
*
* @return whether or not this {@link CommandGroup} is interruptible.
@@ -375,7 +361,7 @@
for (int i = 0; i < m_children.size(); i++) {
Command child = m_children.elementAt(i).m_command;
- Enumeration requirements = command.getRequirements();
+ Enumeration<?> requirements = command.getRequirements();
while (requirements.hasMoreElements()) {
Object requirement = requirements.nextElement();
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java
index 01d316e..80c2903 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/ConditionalCommand.java
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-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.wpilibj.command;
@@ -12,55 +9,41 @@
/**
* A {@link ConditionalCommand} is a {@link Command} that starts one of two commands.
*
- * <p>
- * A {@link ConditionalCommand} uses m_condition to determine whether it should run m_onTrue or
+ * <p>A {@link ConditionalCommand} uses m_condition to determine whether it should run m_onTrue or
* m_onFalse.
- * </p>
*
- * <p>
- * A {@link ConditionalCommand} adds the proper {@link Command} to the {@link Scheduler} during
+ * <p>A {@link ConditionalCommand} adds the proper {@link Command} to the {@link Scheduler} during
* {@link ConditionalCommand#initialize()} and then {@link ConditionalCommand#isFinished()} will
* return true once that {@link Command} has finished executing.
- * </p>
*
- * <p>
- * If no {@link Command} is specified for m_onFalse, the occurrence of that condition will be a
+ * <p>If no {@link Command} is specified for m_onFalse, the occurrence of that condition will be a
* no-op.
- * </p>
*
- * <p>
- * A ConditionalCommand will require the superset of subsystems of the onTrue
- * and onFalse commands.
- * </p>
+ * <p>A ConditionalCommand will require the superset of subsystems of the onTrue and onFalse
+ * commands.
*
* @see Command
* @see Scheduler
*/
public abstract class ConditionalCommand extends Command {
- /**
- * The Command to execute if {@link ConditionalCommand#condition()} returns true.
- */
+ /** The Command to execute if {@link ConditionalCommand#condition()} returns true. */
private Command m_onTrue;
- /**
- * The Command to execute if {@link ConditionalCommand#condition()} returns false.
- */
+ /** The Command to execute if {@link ConditionalCommand#condition()} returns false. */
private Command m_onFalse;
- /**
- * Stores command chosen by condition.
- */
+ /** Stores command chosen by condition. */
private Command m_chosenCommand;
private void requireAll() {
if (m_onTrue != null) {
- for (Enumeration e = m_onTrue.getRequirements(); e.hasMoreElements(); ) {
+ for (Enumeration<?> e = m_onTrue.getRequirements(); e.hasMoreElements(); ) {
requires((Subsystem) e.nextElement());
}
}
if (m_onFalse != null) {
- for (Enumeration e = m_onFalse.getRequirements(); e.hasMoreElements(); ) {
+ for (Enumeration<?> e = m_onFalse.getRequirements(); e.hasMoreElements(); ) {
requires((Subsystem) e.nextElement());
}
}
@@ -128,9 +111,7 @@
*/
protected abstract boolean condition();
- /**
- * Calls {@link ConditionalCommand#condition()} and runs the proper command.
- */
+ /** Calls {@link ConditionalCommand#condition()} and runs the proper command. */
@Override
protected void _initialize() {
if (condition()) {
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.java
index 4ed7459..0579fc7 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.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.wpilibj.command;
@@ -11,20 +8,16 @@
* This exception will be thrown if a command is used illegally. There are several ways for this to
* happen.
*
- * <p> Basically, a command becomes "locked" after it is first started or added to a command group.
- * </p>
+ * <p>Basically, a command becomes "locked" after it is first started or added to a command group.
*
- * <p> This exception should be thrown if (after a command has been locked) its requirements change,
+ * <p>This exception should be thrown if (after a command has been locked) its requirements change,
* it is put into multiple command groups, it is started from outside its command group, or it adds
- * a new child. </p>
+ * a new child.
*/
@SuppressWarnings("serial")
public class IllegalUseOfCommandException extends RuntimeException {
- /**
- * Instantiates an {@link IllegalUseOfCommandException}.
- */
- public IllegalUseOfCommandException() {
- }
+ /** Instantiates an {@link IllegalUseOfCommandException}. */
+ public IllegalUseOfCommandException() {}
/**
* Instantiates an {@link IllegalUseOfCommandException} with the given message.
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java
index f255e48..d40f626 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java
@@ -1,23 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.command;
/**
* This command will execute once, then finish immediately afterward.
*
- * <p>Subclassing {@link InstantCommand} is shorthand for returning true from
- * {@link Command isFinished}.
+ * <p>Subclassing {@link InstantCommand} is shorthand for returning true from {@link Command
+ * isFinished}.
*/
public class InstantCommand extends Command {
private Runnable m_func;
- public InstantCommand() {
- }
+ public InstantCommand() {}
/**
* Creates a new {@link InstantCommand InstantCommand} with the given name.
@@ -40,7 +36,7 @@
/**
* Creates a new {@link InstantCommand InstantCommand} with the given name and requirement.
*
- * @param name the name for this command
+ * @param name the name for this command
* @param subsystem the subsystem this command requires
*/
public InstantCommand(String name, Subsystem subsystem) {
@@ -71,7 +67,7 @@
* Creates a new {@link InstantCommand InstantCommand}.
*
* @param requirement the subsystem this command requires
- * @param func the function to run when {@link Command#initialize() initialize()} is run
+ * @param func the function to run when {@link Command#initialize() initialize()} is run
*/
public InstantCommand(Subsystem requirement, Runnable func) {
super(requirement);
@@ -81,9 +77,9 @@
/**
* Creates a new {@link InstantCommand InstantCommand}.
*
- * @param name the name for this command
+ * @param name the name for this command
* @param requirement the subsystem this command requires
- * @param func the function to run when {@link Command#initialize() initialize()} is run
+ * @param func the function to run when {@link Command#initialize() initialize()} is run
*/
public InstantCommand(String name, Subsystem requirement, Runnable func) {
super(name, requirement);
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java
index 78da002..365667a 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java
@@ -1,15 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.command;
-/**
- * An element that is in a LinkedList.
- */
+/** An element that is in a LinkedList. */
class LinkedListElement {
private LinkedListElement m_next;
private LinkedListElement m_previous;
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java
index 8b60254..0334316 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java
@@ -1,62 +1,52 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.command;
+import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.wpilibj.PIDController;
import edu.wpi.first.wpilibj.PIDOutput;
import edu.wpi.first.wpilibj.PIDSource;
import edu.wpi.first.wpilibj.PIDSourceType;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
/**
* This class defines a {@link Command} which interacts heavily with a PID loop.
*
- * <p> It provides some convenience methods to run an internal {@link PIDController} . It will also
+ * <p>It provides some convenience methods to run an internal {@link PIDController} . It will also
* start and stop said {@link PIDController} when the {@link PIDCommand} is first initialized and
- * ended/interrupted. </p>
+ * ended/interrupted.
*/
public abstract class PIDCommand extends Command {
- /**
- * The internal {@link PIDController}.
- */
+ /** The internal {@link PIDController}. */
private final PIDController m_controller;
- /**
- * An output which calls {@link PIDCommand#usePIDOutput(double)}.
- */
+ /** An output which calls {@link PIDCommand#usePIDOutput(double)}. */
private final PIDOutput m_output = this::usePIDOutput;
- /**
- * A source which calls {@link PIDCommand#returnPIDInput()}.
- */
- private final PIDSource m_source = new PIDSource() {
- @Override
- public void setPIDSourceType(PIDSourceType pidSource) {
- }
+ /** A source which calls {@link PIDCommand#returnPIDInput()}. */
+ private final PIDSource m_source =
+ new PIDSource() {
+ @Override
+ public void setPIDSourceType(PIDSourceType pidSource) {}
- @Override
- public PIDSourceType getPIDSourceType() {
- return PIDSourceType.kDisplacement;
- }
+ @Override
+ public PIDSourceType getPIDSourceType() {
+ return PIDSourceType.kDisplacement;
+ }
- @Override
- public double pidGet() {
- return returnPIDInput();
- }
- };
+ @Override
+ public double pidGet() {
+ return returnPIDInput();
+ }
+ };
/**
* Instantiates a {@link PIDCommand} that will use the given p, i and d values.
*
* @param name the name of the command
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
*/
- @SuppressWarnings("ParameterName")
public PIDCommand(String name, double p, double i, double d) {
super(name);
m_controller = new PIDController(p, i, d, m_source, m_output);
@@ -66,13 +56,12 @@
* Instantiates a {@link PIDCommand} that will use the given p, i and d values. It will also space
* the time between PID loop calculations to be equal to the given period.
*
- * @param name the name
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
+ * @param name the name
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
* @param period the time (in seconds) between calculations
*/
- @SuppressWarnings("ParameterName")
public PIDCommand(String name, double p, double i, double d, double period) {
super(name);
m_controller = new PIDController(p, i, d, m_source, m_output, period);
@@ -86,7 +75,6 @@
* @param i the integral value
* @param d the derivative value
*/
- @SuppressWarnings("ParameterName")
public PIDCommand(double p, double i, double d) {
m_controller = new PIDController(p, i, d, m_source, m_output);
}
@@ -96,12 +84,11 @@
* class name as its name. It will also space the time between PID loop calculations to be equal
* to the given period.
*
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
* @param period the time (in seconds) between calculations
*/
- @SuppressWarnings("ParameterName")
public PIDCommand(double p, double i, double d, double period) {
m_controller = new PIDController(p, i, d, m_source, m_output, period);
}
@@ -109,13 +96,12 @@
/**
* Instantiates a {@link PIDCommand} that will use the given p, i and d values.
*
- * @param name the name of the command
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
+ * @param name the name of the command
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
* @param subsystem the subsystem that this command requires
*/
- @SuppressWarnings("ParameterName")
public PIDCommand(String name, double p, double i, double d, Subsystem subsystem) {
super(name, subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output);
@@ -125,16 +111,14 @@
* Instantiates a {@link PIDCommand} that will use the given p, i and d values. It will also space
* the time between PID loop calculations to be equal to the given period.
*
- * @param name the name
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
- * @param period the time (in seconds) between calculations
+ * @param name the name
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
+ * @param period the time (in seconds) between calculations
* @param subsystem the subsystem that this command requires
*/
- @SuppressWarnings("ParameterName")
- public PIDCommand(String name, double p, double i, double d, double period,
- Subsystem subsystem) {
+ public PIDCommand(String name, double p, double i, double d, double period, Subsystem subsystem) {
super(name, subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output, period);
}
@@ -143,12 +127,11 @@
* Instantiates a {@link PIDCommand} that will use the given p, i and d values. It will use the
* class name as its name.
*
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
* @param subsystem the subsystem that this command requires
*/
- @SuppressWarnings("ParameterName")
public PIDCommand(double p, double i, double d, Subsystem subsystem) {
super(subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output);
@@ -159,13 +142,12 @@
* class name as its name. It will also space the time between PID loop calculations to be equal
* to the given period.
*
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
- * @param period the time (in seconds) between calculations
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
+ * @param period the time (in seconds) between calculations
* @param subsystem the subsystem that this command requires
*/
- @SuppressWarnings("ParameterName")
public PIDCommand(double p, double i, double d, double period, Subsystem subsystem) {
super(subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output, period);
@@ -264,8 +246,8 @@
/**
* Uses the value that the pid loop calculated. The calculated value is the "output" parameter.
- * This method is a good time to set motor values, maybe something along the lines of
- * <code>driveline.tankDrive(output, -output)</code>
+ * This method is a good time to set motor values, maybe something along the lines of <code>
+ * driveline.tankDrive(output, -output)</code>
*
* <p>All subclasses of {@link PIDCommand} must override this method.
*
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java
index 7bb6331..bf70f91 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.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.wpilibj.command;
@@ -17,48 +14,40 @@
* {@link PIDController} almost constantly (for instance, an elevator which attempts to stay at a
* constant height).
*
- * <p>It provides some convenience methods to run an internal {@link PIDController} . It also
- * allows access to the internal {@link PIDController} in order to give total control to the
- * programmer.
+ * <p>It provides some convenience methods to run an internal {@link PIDController} . It also allows
+ * access to the internal {@link PIDController} in order to give total control to the programmer.
*/
public abstract class PIDSubsystem extends Subsystem {
- /**
- * The internal {@link PIDController}.
- */
+ /** The internal {@link PIDController}. */
private final PIDController m_controller;
- /**
- * An output which calls {@link PIDCommand#usePIDOutput(double)}.
- */
+ /** An output which calls {@link PIDCommand#usePIDOutput(double)}. */
private final PIDOutput m_output = this::usePIDOutput;
- /**
- * A source which calls {@link PIDCommand#returnPIDInput()}.
- */
- private final PIDSource m_source = new PIDSource() {
- @Override
- public void setPIDSourceType(PIDSourceType pidSource) {
- }
+ /** A source which calls {@link PIDCommand#returnPIDInput()}. */
+ private final PIDSource m_source =
+ new PIDSource() {
+ @Override
+ public void setPIDSourceType(PIDSourceType pidSource) {}
- @Override
- public PIDSourceType getPIDSourceType() {
- return PIDSourceType.kDisplacement;
- }
+ @Override
+ public PIDSourceType getPIDSourceType() {
+ return PIDSourceType.kDisplacement;
+ }
- @Override
- public double pidGet() {
- return returnPIDInput();
- }
- };
+ @Override
+ public double pidGet() {
+ return returnPIDInput();
+ }
+ };
/**
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d values.
*
* @param name the name
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
*/
- @SuppressWarnings("ParameterName")
public PIDSubsystem(String name, double p, double i, double d) {
super(name);
m_controller = new PIDController(p, i, d, m_source, m_output);
@@ -69,12 +58,11 @@
* Instantiates a {@link PIDSubsystem} that will use the given p, i, d, and f values.
*
* @param name the name
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
- * @param f the feed forward value
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
+ * @param f the feed forward value
*/
- @SuppressWarnings("ParameterName")
public PIDSubsystem(String name, double p, double i, double d, double f) {
super(name);
m_controller = new PIDController(p, i, d, f, m_source, m_output);
@@ -85,14 +73,13 @@
* Instantiates a {@link PIDSubsystem} that will use the given p, i, d, and f values. It will also
* space the time between PID loop calculations to be equal to the given period.
*
- * @param name the name
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
- * @param f the feed forward value
+ * @param name the name
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
+ * @param f the feed forward value
* @param period the time (in seconds) between calculations
*/
- @SuppressWarnings("ParameterName")
public PIDSubsystem(String name, double p, double i, double d, double f, double period) {
super(name);
m_controller = new PIDController(p, i, d, f, m_source, m_output, period);
@@ -107,7 +94,6 @@
* @param i the integral value
* @param d the derivative value
*/
- @SuppressWarnings("ParameterName")
public PIDSubsystem(double p, double i, double d) {
m_controller = new PIDController(p, i, d, m_source, m_output);
addChild("PIDController", m_controller);
@@ -118,13 +104,12 @@
* the class name as its name. It will also space the time between PID loop calculations to be
* equal to the given period.
*
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
- * @param f the feed forward coefficient
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
+ * @param f the feed forward coefficient
* @param period the time (in seconds) between calculations
*/
- @SuppressWarnings("ParameterName")
public PIDSubsystem(double p, double i, double d, double f, double period) {
m_controller = new PIDController(p, i, d, f, m_source, m_output, period);
addChild("PIDController", m_controller);
@@ -135,12 +120,11 @@
* class name as its name. It will also space the time between PID loop calculations to be equal
* to the given period.
*
- * @param p the proportional value
- * @param i the integral value
- * @param d the derivative value
+ * @param p the proportional value
+ * @param i the integral value
+ * @param d the derivative value
* @param period the time (in seconds) between calculations
*/
- @SuppressWarnings("ParameterName")
public PIDSubsystem(double p, double i, double d, double period) {
m_controller = new PIDController(p, i, d, m_source, m_output, period);
addChild("PIDController", m_controller);
@@ -156,7 +140,6 @@
return m_controller;
}
-
/**
* Adds the given value to the setpoint. If {@link PIDSubsystem#setInputRange(double, double)
* setInputRange(...)} was used, then the bounds will still be honored by this method.
@@ -222,7 +205,6 @@
*
* @param t the absolute tolerance
*/
- @SuppressWarnings("ParameterName")
public void setAbsoluteTolerance(double t) {
m_controller.setAbsoluteTolerance(t);
}
@@ -233,7 +215,6 @@
*
* @param p the percent tolerance
*/
- @SuppressWarnings("ParameterName")
public void setPercentTolerance(double p) {
m_controller.setPercentTolerance(p);
}
@@ -251,8 +232,8 @@
/**
* Returns the input for the pid loop.
*
- * <p>It returns the input for the pid loop, so if this Subsystem was based off of a gyro, then
- * it should return the angle of the gyro.
+ * <p>It returns the input for the pid loop, so if this Subsystem was based off of a gyro, then it
+ * should return the angle of the gyro.
*
* <p>All subclasses of {@link PIDSubsystem} must override this method.
*
@@ -262,8 +243,8 @@
/**
* Uses the value that the pid loop calculated. The calculated value is the "output" parameter.
- * This method is a good time to set motor values, maybe something along the lines of
- * <code>driveline.tankDrive(output, -output)</code>.
+ * This method is a good time to set motor values, maybe something along the lines of <code>
+ * driveline.tankDrive(output, -output)</code>.
*
* <p>All subclasses of {@link PIDSubsystem} must override this method.
*
@@ -271,16 +252,12 @@
*/
protected abstract void usePIDOutput(double output);
- /**
- * Enables the internal {@link PIDController}.
- */
+ /** Enables the internal {@link PIDController}. */
public void enable() {
m_controller.enable();
}
- /**
- * Disables the internal {@link PIDController}.
- */
+ /** Disables the internal {@link PIDController}. */
public void disable() {
m_controller.disable();
}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java
index b8d7fed..5013b1b 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.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.wpilibj.command;
@@ -13,9 +10,7 @@
* it reaches a certain point.
*/
public class PrintCommand extends InstantCommand {
- /**
- * The message to print out.
- */
+ /** The message to print out. */
private final String m_message;
/**
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java
index c48f604..ca1ed33 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java
@@ -1,42 +1,37 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.command;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
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.wpilibj.Sendable;
+import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
-import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
/**
* The {@link Scheduler} is a singleton which holds the top-level running commands. It is in charge
* of both calling the command's {@link Command#run() run()} method and to make sure that there are
* no two commands with conflicting requirements running.
*
- * <p> It is fine if teams wish to take control of the {@link Scheduler} themselves, all that needs
+ * <p>It is fine if teams wish to take control of the {@link Scheduler} themselves, all that needs
* to be done is to call {@link Scheduler#getInstance() Scheduler.getInstance()}.{@link
* Scheduler#run() run()} often to have {@link Command Commands} function correctly. However, this
- * is already done for you if you use the CommandBased Robot template. </p>
+ * is already done for you if you use the CommandBased Robot template.
*
* @see Command
*/
-public final class Scheduler implements Sendable, AutoCloseable {
- /**
- * The Singleton Instance.
- */
+public final class Scheduler implements NTSendable, AutoCloseable {
+ /** The Singleton Instance. */
private static Scheduler instance;
/**
@@ -51,57 +46,42 @@
return instance;
}
- /**
- * A hashtable of active {@link Command Commands} to their {@link LinkedListElement}.
- */
- @SuppressWarnings("PMD.LooseCoupling")
- private final Hashtable<Command, LinkedListElement> m_commandTable = new Hashtable<>();
- /**
- * The {@link Set} of all {@link Subsystem Subsystems}.
- */
+ /** A hashtable of active {@link Command Commands} to their {@link LinkedListElement}. */
+ private final Map<Command, LinkedListElement> m_commandTable = new Hashtable<>();
+ /** The {@link Set} of all {@link Subsystem Subsystems}. */
private final Set m_subsystems = new Set();
- /**
- * The first {@link Command} in the list.
- */
+ /** The first {@link Command} in the list. */
private LinkedListElement m_firstCommand;
- /**
- * The last {@link Command} in the list.
- */
+ /** The last {@link Command} in the list. */
private LinkedListElement m_lastCommand;
- /**
- * Whether or not we are currently adding a command.
- */
+ /** Whether or not we are currently adding a command. */
private boolean m_adding;
- /**
- * Whether or not we are currently disabled.
- */
+ /** Whether or not we are currently disabled. */
private boolean m_disabled;
- /**
- * A list of all {@link Command Commands} which need to be added.
- */
- @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
+ /** A list of all {@link Command Commands} which need to be added. */
+ @SuppressWarnings("PMD.UseArrayListInsteadOfVector")
private final Vector<Command> m_additions = new Vector<>();
/**
* A list of all {@link edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler Buttons}. It is
* created lazily.
*/
- @SuppressWarnings("PMD.LooseCoupling")
private Vector<ButtonScheduler> m_buttons;
+
private boolean m_runningCommandsChanged;
- /**
- * Instantiates a {@link Scheduler}.
- */
+ /** Instantiates a {@link Scheduler}. */
private Scheduler() {
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler);
SendableRegistry.addLW(this, "Scheduler");
- LiveWindow.setEnabledListener(() -> {
- disable();
- removeAll();
- });
- LiveWindow.setDisabledListener(() -> {
- enable();
- });
+ LiveWindow.setEnabledListener(
+ () -> {
+ disable();
+ removeAll();
+ });
+ LiveWindow.setDisabledListener(
+ () -> {
+ enable();
+ });
}
@Override
@@ -116,8 +96,8 @@
* but will instead wait for the proper time in the {@link Scheduler#run()} loop before doing so.
* The command returns immediately and does nothing if given null.
*
- * <p> Adding a {@link Command} to the {@link Scheduler} involves the {@link Scheduler} removing
- * any {@link Command} which has shared requirements. </p>
+ * <p>Adding a {@link Command} to the {@link Scheduler} involves the {@link Scheduler} removing
+ * any {@link Command} which has shared requirements.
*
* @param command the command to add
*/
@@ -144,11 +124,11 @@
/**
* Adds a command immediately to the {@link Scheduler}. This should only be called in the {@link
* Scheduler#run()} loop. Any command with conflicting requirements will be removed, unless it is
- * uninterruptable. Giving <code>null</code> does nothing.
+ * uninterruptible. Giving <code>null</code> does nothing.
*
* @param command the {@link Command} to add
*/
- @SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity"})
+ @SuppressWarnings("MethodName")
private void _add(Command command) {
if (command == null) {
return;
@@ -163,7 +143,7 @@
// Only add if not already in
if (!m_commandTable.containsKey(command)) {
// Check that the requirements can be had
- Enumeration requirements = command.getRequirements();
+ Enumeration<?> requirements = command.getRequirements();
while (requirements.hasMoreElements()) {
Subsystem lock = (Subsystem) requirements.nextElement();
if (lock.getCurrentCommand() != null && !lock.getCurrentCommand().isInterruptible()) {
@@ -205,10 +185,14 @@
* Runs a single iteration of the loop. This method should be called often in order to have a
* functioning {@link Command} system. The loop has five stages:
*
- * <ol> <li>Poll the Buttons</li> <li>Execute/Remove the Commands</li> <li>Send values to
- * SmartDashboard</li> <li>Add Commands</li> <li>Add Defaults</li> </ol>
+ * <ol>
+ * <li>Poll the Buttons
+ * <li>Execute/Remove the Commands
+ * <li>Send values to SmartDashboard
+ * <li>Add Commands
+ * <li>Add Defaults
+ * </ol>
*/
- @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public void run() {
m_runningCommandsChanged = false;
@@ -224,7 +208,7 @@
}
// Call every subsystem's periodic method
- Enumeration subsystems = m_subsystems.getElements();
+ Enumeration<?> subsystems = m_subsystems.getElements();
while (subsystems.hasMoreElements()) {
((Subsystem) subsystems.nextElement()).periodic();
}
@@ -247,7 +231,7 @@
m_additions.removeAllElements();
// Add in the defaults
- Enumeration locks = m_subsystems.getElements();
+ Enumeration<?> locks = m_subsystems.getElements();
while (locks.hasMoreElements()) {
Subsystem lock = (Subsystem) locks.nextElement();
if (lock.getCurrentCommand() == null) {
@@ -290,7 +274,7 @@
}
element.remove();
- Enumeration requirements = command.getRequirements();
+ Enumeration<?> requirements = command.getRequirements();
while (requirements.hasMoreElements()) {
((Subsystem) requirements.nextElement()).setCurrentCommand(null);
}
@@ -298,9 +282,7 @@
command.removed();
}
- /**
- * Removes all commands.
- */
+ /** Removes all commands. */
public void removeAll() {
// TODO: Confirm that this works with "uninteruptible" commands
while (m_firstCommand != null) {
@@ -308,59 +290,56 @@
}
}
- /**
- * Disable the command scheduler.
- */
+ /** Disable the command scheduler. */
public void disable() {
m_disabled = true;
}
- /**
- * Enable the command scheduler.
- */
+ /** Enable the command scheduler. */
public void enable() {
m_disabled = false;
}
@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(() -> {
- if (namesEntry != null && idsEntry != null && cancelEntry != null) {
- // Get the commands to cancel
- double[] toCancel = cancelEntry.getDoubleArray(new double[0]);
- if (toCancel.length > 0) {
- for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
- for (double d : toCancel) {
- if (e.getData().hashCode() == d) {
- e.getData().cancel();
+ builder.setUpdateTable(
+ () -> {
+ if (namesEntry != null && idsEntry != null && cancelEntry != null) {
+ // Get the commands to cancel
+ double[] toCancel = cancelEntry.getDoubleArray(new double[0]);
+ if (toCancel.length > 0) {
+ for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
+ for (double d : toCancel) {
+ if (e.getData().hashCode() == d) {
+ e.getData().cancel();
+ }
+ }
}
+ cancelEntry.setDoubleArray(new double[0]);
+ }
+
+ if (m_runningCommandsChanged) {
+ // Set the the running commands
+ int number = 0;
+ for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
+ number++;
+ }
+ String[] commands = new String[number];
+ double[] ids = new double[number];
+ number = 0;
+ for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
+ commands[number] = e.getData().getName();
+ ids[number] = e.getData().hashCode();
+ number++;
+ }
+ namesEntry.setStringArray(commands);
+ idsEntry.setDoubleArray(ids);
}
}
- cancelEntry.setDoubleArray(new double[0]);
- }
-
- if (m_runningCommandsChanged) {
- // Set the the running commands
- int number = 0;
- for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
- number++;
- }
- String[] commands = new String[number];
- double[] ids = new double[number];
- number = 0;
- for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
- commands[number] = e.getData().getName();
- ids[number] = e.getData().hashCode();
- number++;
- }
- namesEntry.setStringArray(commands);
- idsEntry.setDoubleArray(ids);
- }
- }
- });
+ });
}
}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Set.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Set.java
index 6aac6d7..d47f16f 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Set.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Set.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.wpilibj.command;
@@ -11,14 +8,11 @@
import java.util.Vector;
@SuppressWarnings("all")
-/**
- * A set.
- */
+/** A set. */
class Set {
private Vector m_set = new Vector();
- public Set() {
- }
+ public Set() {}
public void add(Object o) {
if (m_set.contains(o)) {
@@ -35,7 +29,7 @@
}
public void clear() {
- m_set.clear();
+ m_set.clear();
}
public boolean contains(Object o) {
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java
index bd8c658..56b4150 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.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.wpilibj.command;
@@ -12,9 +9,7 @@
* when it is initialized and will finish immediately.
*/
public class StartCommand extends InstantCommand {
- /**
- * The command to fork.
- */
+ /** The command to fork. */
private final Command m_commandToFork;
/**
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java
index ac1107b..2ba01af 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java
@@ -1,46 +1,37 @@
-/*----------------------------------------------------------------------------*/
-/* 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.wpilibj.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.Collections;
-import edu.wpi.first.wpilibj.Sendable;
-import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
-import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
-
/**
* This class defines a major component of the robot.
*
- * <p> A good example of a subsystem is the driveline, or a claw if the robot has one. </p>
+ * <p>A good example of a subsystem is the driveline, or a claw if the robot has one.
*
- * <p> All motors should be a part of a subsystem. For instance, all the wheel motors should be a
- * part of some kind of "Driveline" subsystem. </p>
+ * <p>All motors should be a part of a subsystem. For instance, all the wheel motors should be a
+ * part of some kind of "Driveline" subsystem.
*
- * <p> Subsystems are used within the command system as requirements for {@link Command}. Only one
+ * <p>Subsystems are used within the command system as requirements for {@link Command}. Only one
* command which requires a subsystem can run at a time. Also, subsystems can have default commands
- * which are started if there is no command running which requires this subsystem. </p>
+ * which are started if there is no command running which requires this subsystem.
*
* @see Command
*/
public abstract class Subsystem implements Sendable, AutoCloseable {
- /**
- * Whether or not getDefaultCommand() was called.
- */
+ /** Whether or not getDefaultCommand() was called. */
private boolean m_initializedDefaultCommand;
- /**
- * The current command.
- */
+ /** The current command. */
private Command m_currentCommand;
+
private boolean m_currentCommandChanged;
- /**
- * The default command.
- */
+ /** The default command. */
private Command m_defaultCommand;
/**
@@ -53,9 +44,7 @@
Scheduler.getInstance().registerSubsystem(this);
}
- /**
- * Creates a subsystem. This will set the name to the name of the class.
- */
+ /** Creates a subsystem. This will set the name to the name of the class. */
public Subsystem() {
String name = getClass().getName();
name = name.substring(name.lastIndexOf('.') + 1);
@@ -76,9 +65,7 @@
*/
protected abstract void initDefaultCommand();
- /**
- * When the run method of the scheduler is called this method will be called.
- */
+ /** When the run method of the scheduler is called this method will be called. */
public void periodic() {
// Override me!
}
@@ -87,8 +74,8 @@
* Sets the default command. If this is not called or is called with null, then there will be no
* default command for the subsystem.
*
- * <p> <b>WARNING:</b> This should <b>NOT</b> be called in a constructor if the subsystem is a
- * singleton. </p>
+ * <p><b>WARNING:</b> This should <b>NOT</b> be called in a constructor if the subsystem is a
+ * singleton.
*
* @param command the default command (or null if there should be none)
* @throws IllegalUseOfCommandException if the command does not require the subsystem
@@ -176,8 +163,7 @@
}
/**
- * Associate a {@link Sendable} with this Subsystem.
- * Also update the child's name.
+ * Associate a {@link Sendable} with this Subsystem. Also update the child's name.
*
* @param name name to give child
* @param child sendable
@@ -201,7 +187,6 @@
*
* @return Name
*/
- @Override
public String getName() {
return SendableRegistry.getName(this);
}
@@ -211,7 +196,6 @@
*
* @param name name
*/
- @Override
public void setName(String name) {
SendableRegistry.setName(this, name);
}
@@ -221,7 +205,6 @@
*
* @return Subsystem name
*/
- @Override
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
@@ -231,7 +214,6 @@
*
* @param subsystem subsystem name
*/
- @Override
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java
index 386bb0e..36e651b 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java
@@ -1,21 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.command;
/**
- * A {@link TimedCommand} will wait for a timeout before finishing.
- * {@link TimedCommand} is used to execute a command for a given amount of time.
+ * A {@link TimedCommand} will wait for a timeout before finishing. {@link TimedCommand} is used to
+ * execute a command for a given amount of time.
*/
public class TimedCommand extends Command {
/**
* Instantiates a TimedCommand with the given name and timeout.
*
- * @param name the name of the command
+ * @param name the name of the command
* @param timeout the time the command takes to run (seconds)
*/
public TimedCommand(String name, double timeout) {
@@ -34,8 +31,8 @@
/**
* Instantiates a TimedCommand with the given name and timeout.
*
- * @param name the name of the command
- * @param timeout the time the command takes to run (seconds)
+ * @param name the name of the command
+ * @param timeout the time the command takes to run (seconds)
* @param subsystem the subsystem that this command requires
*/
public TimedCommand(String name, double timeout, Subsystem subsystem) {
@@ -45,16 +42,14 @@
/**
* Instantiates a TimedCommand with the given timeout.
*
- * @param timeout the time the command takes to run (seconds)
+ * @param timeout the time the command takes to run (seconds)
* @param subsystem the subsystem that this command requires
*/
public TimedCommand(double timeout, Subsystem subsystem) {
super(timeout, subsystem);
}
- /**
- * Ends command when timed out.
- */
+ /** Ends command when timed out. */
@Override
protected boolean isFinished() {
return isTimedOut();
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.java
index 0e1762a..a541944 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.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.wpilibj.command;
@@ -26,7 +23,7 @@
/**
* Instantiates a {@link WaitCommand} with the given timeout.
*
- * @param name the name of the command
+ * @param name the name of the command
* @param timeout the time the command takes to run (seconds)
*/
public WaitCommand(String name, double timeout) {
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java
index 118da6a..23e21d3 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.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.wpilibj.command;
@@ -12,8 +9,8 @@
* If it is not a part of a {@link CommandGroup}, then it will finish immediately. If it is itself
* an active child, then the {@link CommandGroup} will never end.
*
- * <p>This class is useful for the situation where you want to allow anything running in parallel
- * to finish, before continuing in the main {@link CommandGroup} sequence.
+ * <p>This class is useful for the situation where you want to allow anything running in parallel to
+ * finish, before continuing in the main {@link CommandGroup} sequence.
*/
public class WaitForChildren extends Command {
@Override
diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java
index dadcab5..b7226bd 100644
--- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java
+++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.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.wpilibj.command;
@@ -21,9 +18,7 @@
m_time = time;
}
- /**
- * Check if we've reached the actual finish time.
- */
+ /** Check if we've reached the actual finish time. */
@Override
public boolean isFinished() {
return Timer.getMatchTime() >= m_time;
diff --git a/wpilibOldCommands/src/main/native/cpp/PIDBase.cpp b/wpilibOldCommands/src/main/native/cpp/PIDBase.cpp
new file mode 100644
index 0000000..825d4eb
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/cpp/PIDBase.cpp
@@ -0,0 +1,358 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/PIDBase.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include <hal/FRCUsageReporting.h>
+#include <wpi/sendable/SendableBuilder.h>
+#include <wpi/sendable/SendableRegistry.h>
+
+#include "frc/PIDOutput.h"
+
+using namespace frc;
+
+template <class T>
+constexpr const T& clamp(const T& value, const T& low, const T& high) {
+ return std::max(low, std::min(value, high));
+}
+
+PIDBase::PIDBase(double Kp, double Ki, double Kd, PIDSource& source,
+ PIDOutput& output)
+ : PIDBase(Kp, Ki, Kd, 0.0, source, output) {}
+
+PIDBase::PIDBase(double Kp, double Ki, double Kd, double Kf, PIDSource& source,
+ PIDOutput& output) {
+ m_P = Kp;
+ m_I = Ki;
+ m_D = Kd;
+ m_F = Kf;
+
+ m_pidInput = &source;
+ m_filter = LinearFilter<double>::MovingAverage(1);
+
+ m_pidOutput = &output;
+
+ m_setpointTimer.Start();
+
+ static int instances = 0;
+ instances++;
+ HAL_Report(HALUsageReporting::kResourceType_PIDController, instances);
+ wpi::SendableRegistry::Add(this, "PIDController", instances);
+}
+
+double PIDBase::Get() const {
+ std::scoped_lock lock(m_thisMutex);
+ return m_result;
+}
+
+void PIDBase::SetContinuous(bool continuous) {
+ std::scoped_lock lock(m_thisMutex);
+ m_continuous = continuous;
+}
+
+void PIDBase::SetInputRange(double minimumInput, double maximumInput) {
+ {
+ std::scoped_lock lock(m_thisMutex);
+ m_minimumInput = minimumInput;
+ m_maximumInput = maximumInput;
+ m_inputRange = maximumInput - minimumInput;
+ }
+
+ SetSetpoint(m_setpoint);
+}
+
+void PIDBase::SetOutputRange(double minimumOutput, double maximumOutput) {
+ std::scoped_lock lock(m_thisMutex);
+ m_minimumOutput = minimumOutput;
+ m_maximumOutput = maximumOutput;
+}
+
+void PIDBase::SetPID(double p, double i, double d) {
+ {
+ std::scoped_lock lock(m_thisMutex);
+ m_P = p;
+ m_I = i;
+ m_D = d;
+ }
+}
+
+void PIDBase::SetPID(double p, double i, double d, double f) {
+ std::scoped_lock lock(m_thisMutex);
+ m_P = p;
+ m_I = i;
+ m_D = d;
+ m_F = f;
+}
+
+void PIDBase::SetP(double p) {
+ std::scoped_lock lock(m_thisMutex);
+ m_P = p;
+}
+
+void PIDBase::SetI(double i) {
+ std::scoped_lock lock(m_thisMutex);
+ m_I = i;
+}
+
+void PIDBase::SetD(double d) {
+ std::scoped_lock lock(m_thisMutex);
+ m_D = d;
+}
+
+void PIDBase::SetF(double f) {
+ std::scoped_lock lock(m_thisMutex);
+ m_F = f;
+}
+
+double PIDBase::GetP() const {
+ std::scoped_lock lock(m_thisMutex);
+ return m_P;
+}
+
+double PIDBase::GetI() const {
+ std::scoped_lock lock(m_thisMutex);
+ return m_I;
+}
+
+double PIDBase::GetD() const {
+ std::scoped_lock lock(m_thisMutex);
+ return m_D;
+}
+
+double PIDBase::GetF() const {
+ std::scoped_lock lock(m_thisMutex);
+ return m_F;
+}
+
+void PIDBase::SetSetpoint(double setpoint) {
+ {
+ std::scoped_lock lock(m_thisMutex);
+
+ if (m_maximumInput > m_minimumInput) {
+ if (setpoint > m_maximumInput) {
+ m_setpoint = m_maximumInput;
+ } else if (setpoint < m_minimumInput) {
+ m_setpoint = m_minimumInput;
+ } else {
+ m_setpoint = setpoint;
+ }
+ } else {
+ m_setpoint = setpoint;
+ }
+ }
+}
+
+double PIDBase::GetSetpoint() const {
+ std::scoped_lock lock(m_thisMutex);
+ return m_setpoint;
+}
+
+double PIDBase::GetDeltaSetpoint() const {
+ std::scoped_lock lock(m_thisMutex);
+ return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get().value();
+}
+
+double PIDBase::GetError() const {
+ double setpoint = GetSetpoint();
+ {
+ std::scoped_lock lock(m_thisMutex);
+ return GetContinuousError(setpoint - m_pidInput->PIDGet());
+ }
+}
+
+double PIDBase::GetAvgError() const {
+ return GetError();
+}
+
+void PIDBase::SetPIDSourceType(PIDSourceType pidSource) {
+ m_pidInput->SetPIDSourceType(pidSource);
+}
+
+PIDSourceType PIDBase::GetPIDSourceType() const {
+ return m_pidInput->GetPIDSourceType();
+}
+
+void PIDBase::SetTolerance(double percent) {
+ std::scoped_lock lock(m_thisMutex);
+ m_toleranceType = kPercentTolerance;
+ m_tolerance = percent;
+}
+
+void PIDBase::SetAbsoluteTolerance(double absTolerance) {
+ std::scoped_lock lock(m_thisMutex);
+ m_toleranceType = kAbsoluteTolerance;
+ m_tolerance = absTolerance;
+}
+
+void PIDBase::SetPercentTolerance(double percent) {
+ std::scoped_lock lock(m_thisMutex);
+ m_toleranceType = kPercentTolerance;
+ m_tolerance = percent;
+}
+
+void PIDBase::SetToleranceBuffer(int bufLength) {
+ std::scoped_lock lock(m_thisMutex);
+ m_filter = LinearFilter<double>::MovingAverage(bufLength);
+}
+
+bool PIDBase::OnTarget() const {
+ double error = GetError();
+
+ std::scoped_lock lock(m_thisMutex);
+ switch (m_toleranceType) {
+ case kPercentTolerance:
+ return std::fabs(error) < m_tolerance / 100 * m_inputRange;
+ break;
+ case kAbsoluteTolerance:
+ return std::fabs(error) < m_tolerance;
+ break;
+ case kNoTolerance:
+ // TODO: this case needs an error
+ return false;
+ }
+ return false;
+}
+
+void PIDBase::Reset() {
+ std::scoped_lock lock(m_thisMutex);
+ m_prevError = 0;
+ m_totalError = 0;
+ m_result = 0;
+}
+
+void PIDBase::PIDWrite(double output) {
+ SetSetpoint(output);
+}
+
+void PIDBase::InitSendable(wpi::SendableBuilder& builder) {
+ builder.SetSmartDashboardType("PIDController");
+ builder.SetSafeState([=] { Reset(); });
+ builder.AddDoubleProperty(
+ "p", [=] { return GetP(); }, [=](double value) { SetP(value); });
+ builder.AddDoubleProperty(
+ "i", [=] { return GetI(); }, [=](double value) { SetI(value); });
+ builder.AddDoubleProperty(
+ "d", [=] { return GetD(); }, [=](double value) { SetD(value); });
+ builder.AddDoubleProperty(
+ "f", [=] { return GetF(); }, [=](double value) { SetF(value); });
+ builder.AddDoubleProperty(
+ "setpoint", [=] { return GetSetpoint(); },
+ [=](double value) { SetSetpoint(value); });
+}
+
+void PIDBase::Calculate() {
+ if (m_pidInput == nullptr || m_pidOutput == nullptr) {
+ return;
+ }
+
+ bool enabled;
+ {
+ std::scoped_lock lock(m_thisMutex);
+ enabled = m_enabled;
+ }
+
+ if (enabled) {
+ double input;
+
+ // Storage for function inputs
+ PIDSourceType pidSourceType;
+ double P;
+ double I;
+ double D;
+ double feedForward = CalculateFeedForward();
+ double minimumOutput;
+ double maximumOutput;
+
+ // Storage for function input-outputs
+ double prevError;
+ double error;
+ double totalError;
+
+ {
+ std::scoped_lock lock(m_thisMutex);
+
+ input = m_filter.Calculate(m_pidInput->PIDGet());
+
+ pidSourceType = m_pidInput->GetPIDSourceType();
+ P = m_P;
+ I = m_I;
+ D = m_D;
+ minimumOutput = m_minimumOutput;
+ maximumOutput = m_maximumOutput;
+
+ prevError = m_prevError;
+ error = GetContinuousError(m_setpoint - input);
+ totalError = m_totalError;
+ }
+
+ // Storage for function outputs
+ double result;
+
+ if (pidSourceType == PIDSourceType::kRate) {
+ if (P != 0) {
+ totalError =
+ clamp(totalError + error, minimumOutput / P, maximumOutput / P);
+ }
+
+ result = D * error + P * totalError + feedForward;
+ } else {
+ if (I != 0) {
+ totalError =
+ clamp(totalError + error, minimumOutput / I, maximumOutput / I);
+ }
+
+ result =
+ P * error + I * totalError + D * (error - prevError) + feedForward;
+ }
+
+ result = clamp(result, minimumOutput, maximumOutput);
+
+ {
+ // Ensures m_enabled check and PIDWrite() call occur atomically
+ std::scoped_lock pidWriteLock(m_pidWriteMutex);
+ std::unique_lock mainLock(m_thisMutex);
+ if (m_enabled) {
+ // Don't block other PIDBase operations on PIDWrite()
+ mainLock.unlock();
+
+ m_pidOutput->PIDWrite(result);
+ }
+ }
+
+ std::scoped_lock lock(m_thisMutex);
+ m_prevError = m_error;
+ m_error = error;
+ m_totalError = totalError;
+ m_result = result;
+ }
+}
+
+double PIDBase::CalculateFeedForward() {
+ if (m_pidInput->GetPIDSourceType() == PIDSourceType::kRate) {
+ return m_F * GetSetpoint();
+ } else {
+ double temp = m_F * GetDeltaSetpoint();
+ m_prevSetpoint = m_setpoint;
+ m_setpointTimer.Reset();
+ return temp;
+ }
+}
+
+double PIDBase::GetContinuousError(double error) const {
+ if (m_continuous && m_inputRange != 0) {
+ error = std::fmod(error, m_inputRange);
+ if (std::fabs(error) > m_inputRange / 2) {
+ if (error > 0) {
+ return error - m_inputRange;
+ } else {
+ return error + m_inputRange;
+ }
+ }
+ }
+
+ return error;
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/PIDController.cpp b/wpilibOldCommands/src/main/native/cpp/PIDController.cpp
new file mode 100644
index 0000000..ee8382c
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/cpp/PIDController.cpp
@@ -0,0 +1,84 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/PIDController.h"
+
+#include <wpi/sendable/SendableBuilder.h>
+
+#include "frc/Notifier.h"
+#include "frc/PIDOutput.h"
+
+using namespace frc;
+
+PIDController::PIDController(double Kp, double Ki, double Kd, PIDSource* source,
+ PIDOutput* output, double period)
+ : PIDController(Kp, Ki, Kd, 0.0, *source, *output, period) {}
+
+PIDController::PIDController(double Kp, double Ki, double Kd, double Kf,
+ PIDSource* source, PIDOutput* output,
+ double period)
+ : PIDController(Kp, Ki, Kd, Kf, *source, *output, period) {}
+
+PIDController::PIDController(double Kp, double Ki, double Kd, PIDSource& source,
+ PIDOutput& output, double period)
+ : PIDController(Kp, Ki, Kd, 0.0, source, output, period) {}
+
+PIDController::PIDController(double Kp, double Ki, double Kd, double Kf,
+ PIDSource& source, PIDOutput& output,
+ double period)
+ : PIDBase(Kp, Ki, Kd, Kf, source, output) {
+ m_controlLoop = std::make_unique<Notifier>(&PIDController::Calculate, this);
+ m_controlLoop->StartPeriodic(units::second_t(period));
+}
+
+PIDController::~PIDController() {
+ // Forcefully stopping the notifier so the callback can successfully run.
+ m_controlLoop->Stop();
+}
+
+void PIDController::Enable() {
+ {
+ std::scoped_lock lock(m_thisMutex);
+ m_enabled = true;
+ }
+}
+
+void PIDController::Disable() {
+ {
+ // Ensures m_enabled modification and PIDWrite() call occur atomically
+ std::scoped_lock pidWriteLock(m_pidWriteMutex);
+ {
+ std::scoped_lock mainLock(m_thisMutex);
+ m_enabled = false;
+ }
+
+ m_pidOutput->PIDWrite(0);
+ }
+}
+
+void PIDController::SetEnabled(bool enable) {
+ if (enable) {
+ Enable();
+ } else {
+ Disable();
+ }
+}
+
+bool PIDController::IsEnabled() const {
+ std::scoped_lock lock(m_thisMutex);
+ return m_enabled;
+}
+
+void PIDController::Reset() {
+ Disable();
+
+ PIDBase::Reset();
+}
+
+void PIDController::InitSendable(wpi::SendableBuilder& builder) {
+ PIDBase::InitSendable(builder);
+ builder.AddBooleanProperty(
+ "enabled", [=] { return IsEnabled(); },
+ [=](bool value) { SetEnabled(value); });
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/PIDSource.cpp b/wpilibOldCommands/src/main/native/cpp/PIDSource.cpp
new file mode 100644
index 0000000..3a9e3ea
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/cpp/PIDSource.cpp
@@ -0,0 +1,15 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "frc/PIDSource.h"
+
+using namespace frc;
+
+void PIDSource::SetPIDSourceType(PIDSourceType pidSource) {
+ m_pidSource = pidSource;
+}
+
+PIDSourceType PIDSource::GetPIDSourceType() const {
+ return m_pidSource;
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/Button.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/Button.cpp
index 57c86bd..ef2c03d 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/Button.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/Button.cpp
@@ -1,20 +1,27 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/Button.h"
using namespace frc;
-void Button::WhenPressed(Command* command) { WhenActive(command); }
+void Button::WhenPressed(Command* command) {
+ WhenActive(command);
+}
-void Button::WhileHeld(Command* command) { WhileActive(command); }
+void Button::WhileHeld(Command* command) {
+ WhileActive(command);
+}
-void Button::WhenReleased(Command* command) { WhenInactive(command); }
+void Button::WhenReleased(Command* command) {
+ WhenInactive(command);
+}
-void Button::CancelWhenPressed(Command* command) { CancelWhenActive(command); }
+void Button::CancelWhenPressed(Command* command) {
+ CancelWhenActive(command);
+}
-void Button::ToggleWhenPressed(Command* command) { ToggleWhenActive(command); }
+void Button::ToggleWhenPressed(Command* command) {
+ ToggleWhenActive(command);
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/ButtonScheduler.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/ButtonScheduler.cpp
index f79c487..b210c8d 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/ButtonScheduler.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/ButtonScheduler.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/ButtonScheduler.h"
@@ -14,4 +11,6 @@
ButtonScheduler::ButtonScheduler(bool last, Trigger* button, Command* orders)
: m_pressedLast(last), m_button(button), m_command(orders) {}
-void ButtonScheduler::Start() { Scheduler::GetInstance()->AddButton(this); }
+void ButtonScheduler::Start() {
+ Scheduler::GetInstance()->AddButton(this);
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/CancelButtonScheduler.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/CancelButtonScheduler.cpp
index b0f4433..faff376 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/CancelButtonScheduler.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/CancelButtonScheduler.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/CancelButtonScheduler.h"
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/HeldButtonScheduler.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/HeldButtonScheduler.cpp
index 9abf8bc..8fb1064 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/HeldButtonScheduler.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/HeldButtonScheduler.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/HeldButtonScheduler.h"
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/InternalButton.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/InternalButton.cpp
index 6ff7971..5adf83c 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/InternalButton.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/InternalButton.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/InternalButton.h"
@@ -12,8 +9,14 @@
InternalButton::InternalButton(bool inverted)
: m_pressed(inverted), m_inverted(inverted) {}
-void InternalButton::SetInverted(bool inverted) { m_inverted = inverted; }
+void InternalButton::SetInverted(bool inverted) {
+ m_inverted = inverted;
+}
-void InternalButton::SetPressed(bool pressed) { m_pressed = pressed; }
+void InternalButton::SetPressed(bool pressed) {
+ m_pressed = pressed;
+}
-bool InternalButton::Get() { return m_pressed ^ m_inverted; }
+bool InternalButton::Get() {
+ return m_pressed ^ m_inverted;
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/JoystickButton.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/JoystickButton.cpp
index c1d5a29..459c076 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/JoystickButton.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/JoystickButton.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/JoystickButton.h"
@@ -12,4 +9,6 @@
JoystickButton::JoystickButton(GenericHID* joystick, int buttonNumber)
: m_joystick(joystick), m_buttonNumber(buttonNumber) {}
-bool JoystickButton::Get() { return m_joystick->GetRawButton(m_buttonNumber); }
+bool JoystickButton::Get() {
+ return m_joystick->GetRawButton(m_buttonNumber);
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/NetworkButton.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/NetworkButton.cpp
index 8bca356..f5694a1 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/NetworkButton.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/NetworkButton.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/NetworkButton.h"
@@ -12,13 +9,12 @@
using namespace frc;
-NetworkButton::NetworkButton(const wpi::Twine& tableName,
- const wpi::Twine& field)
+NetworkButton::NetworkButton(std::string_view tableName, std::string_view field)
: NetworkButton(nt::NetworkTableInstance::GetDefault().GetTable(tableName),
field) {}
NetworkButton::NetworkButton(std::shared_ptr<nt::NetworkTable> table,
- const wpi::Twine& field)
+ std::string_view field)
: m_entry(table->GetEntry(field)) {}
bool NetworkButton::Get() {
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/POVButton.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/POVButton.cpp
index 73e847a..67b8cae 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/POVButton.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/POVButton.cpp
@@ -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.
#include "frc/buttons/POVButton.h"
@@ -12,4 +9,6 @@
POVButton::POVButton(GenericHID& joystick, int angle, int povNumber)
: m_joystick(&joystick), m_angle(angle), m_povNumber(povNumber) {}
-bool POVButton::Get() { return m_joystick->GetPOV(m_povNumber) == m_angle; }
+bool POVButton::Get() {
+ return m_joystick->GetPOV(m_povNumber) == m_angle;
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/PressedButtonScheduler.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/PressedButtonScheduler.cpp
index 4a470f5..73705bc 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/PressedButtonScheduler.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/PressedButtonScheduler.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/PressedButtonScheduler.h"
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/ReleasedButtonScheduler.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/ReleasedButtonScheduler.cpp
index 671c13e..647169b 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/ReleasedButtonScheduler.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/ReleasedButtonScheduler.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/ReleasedButtonScheduler.h"
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/ToggleButtonScheduler.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/ToggleButtonScheduler.cpp
index cefccb5..d17b2e8 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/ToggleButtonScheduler.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/ToggleButtonScheduler.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/buttons/ToggleButtonScheduler.h"
diff --git a/wpilibOldCommands/src/main/native/cpp/buttons/Trigger.cpp b/wpilibOldCommands/src/main/native/cpp/buttons/Trigger.cpp
index 0cce9d0..9040df6 100644
--- a/wpilibOldCommands/src/main/native/cpp/buttons/Trigger.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/buttons/Trigger.cpp
@@ -1,9 +1,8 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <wpi/sendable/SendableBuilder.h>
#include "frc/buttons/Button.h"
#include "frc/buttons/CancelButtonScheduler.h"
@@ -11,7 +10,6 @@
#include "frc/buttons/PressedButtonScheduler.h"
#include "frc/buttons/ReleasedButtonScheduler.h"
#include "frc/buttons/ToggleButtonScheduler.h"
-#include "frc/smartdashboard/SendableBuilder.h"
using namespace frc;
@@ -36,7 +34,9 @@
return *this;
}
-bool Trigger::Grab() { return Get() || m_sendablePressed; }
+bool Trigger::Grab() {
+ return Get() || m_sendablePressed;
+}
void Trigger::WhenActive(Command* command) {
auto pbs = new PressedButtonScheduler(Grab(), this, command);
@@ -63,10 +63,10 @@
tbs->Start();
}
-void Trigger::InitSendable(SendableBuilder& builder) {
+void Trigger::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Button");
- builder.SetSafeState([=]() { m_sendablePressed = false; });
+ builder.SetSafeState([=] { m_sendablePressed = false; });
builder.AddBooleanProperty(
- "pressed", [=]() { return Grab(); },
+ "pressed", [=] { return Grab(); },
[=](bool value) { m_sendablePressed = value; });
}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp b/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp
index 8c2abcf..778f956 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp
@@ -1,100 +1,109 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "frc/commands/Command.h"
#include <typeinfo>
+#include <wpi/sendable/SendableBuilder.h>
+#include <wpi/sendable/SendableRegistry.h>
+
+#include "frc/Errors.h"
#include "frc/RobotState.h"
#include "frc/Timer.h"
-#include "frc/WPIErrors.h"
#include "frc/commands/CommandGroup.h"
#include "frc/commands/Scheduler.h"
#include "frc/livewindow/LiveWindow.h"
-#include "frc/smartdashboard/SendableBuilder.h"
-#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
int Command::m_commandCounter = 0;
-Command::Command() : Command("", -1.0) {}
+Command::Command() : Command("", -1_s) {}
-Command::Command(const wpi::Twine& name) : Command(name, -1.0) {}
+Command::Command(std::string_view name) : Command(name, -1_s) {}
-Command::Command(double timeout) : Command("", timeout) {}
+Command::Command(units::second_t timeout) : Command("", timeout) {}
-Command::Command(Subsystem& subsystem) : Command("", -1.0) {
+Command::Command(Subsystem& subsystem) : Command("", -1_s) {
Requires(&subsystem);
}
-Command::Command(const wpi::Twine& name, double timeout) {
+Command::Command(std::string_view name, units::second_t timeout) {
// We use -1.0 to indicate no timeout.
- if (timeout < 0.0 && timeout != -1.0)
- wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
+ if (timeout < 0_s && timeout != -1_s) {
+ throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0 s",
+ timeout.value());
+ }
m_timeout = timeout;
// If name contains an empty string
- if (name.isTriviallyEmpty() ||
- (name.isSingleStringRef() && name.getSingleStringRef().empty())) {
- SendableRegistry::GetInstance().Add(
- this, "Command_" + wpi::Twine(typeid(*this).name()));
+ if (name.empty()) {
+ wpi::SendableRegistry::Add(this,
+ fmt::format("Command_{}", typeid(*this).name()));
} else {
- SendableRegistry::GetInstance().Add(this, name);
+ wpi::SendableRegistry::Add(this, name);
}
}
-Command::Command(const wpi::Twine& name, Subsystem& subsystem)
- : Command(name, -1.0) {
+Command::Command(std::string_view name, Subsystem& subsystem)
+ : Command(name, -1_s) {
Requires(&subsystem);
}
-Command::Command(double timeout, Subsystem& subsystem) : Command("", timeout) {
+Command::Command(units::second_t timeout, Subsystem& subsystem)
+ : Command("", timeout) {
Requires(&subsystem);
}
-Command::Command(const wpi::Twine& name, double timeout, Subsystem& subsystem)
+Command::Command(std::string_view name, units::second_t timeout,
+ Subsystem& subsystem)
: Command(name, timeout) {
Requires(&subsystem);
}
-double Command::TimeSinceInitialized() const {
- if (m_startTime < 0.0)
- return 0.0;
- else
+units::second_t Command::TimeSinceInitialized() const {
+ if (m_startTime < 0_s) {
+ return 0_s;
+ } else {
return Timer::GetFPGATimestamp() - m_startTime;
+ }
}
void Command::Requires(Subsystem* subsystem) {
- if (!AssertUnlocked("Can not add new requirement to command")) return;
+ if (!AssertUnlocked("Can not add new requirement to command")) {
+ return;
+ }
- if (subsystem != nullptr)
+ if (subsystem != nullptr) {
m_requirements.insert(subsystem);
- else
- wpi_setWPIErrorWithContext(NullParameter, "subsystem");
+ } else {
+ throw FRC_MakeError(err::NullParameter, "{}", "subsystem");
+ }
}
void Command::Start() {
LockChanges();
- if (m_parent != nullptr)
- wpi_setWPIErrorWithContext(
- CommandIllegalUse,
+ if (m_parent != nullptr) {
+ throw FRC_MakeError(
+ err::CommandIllegalUse, "{}",
"Can not start a command that is part of a command group");
+ }
m_completed = false;
Scheduler::GetInstance()->AddCommand(this);
}
bool Command::Run() {
- if (!m_runWhenDisabled && m_parent == nullptr && RobotState::IsDisabled())
+ if (!m_runWhenDisabled && m_parent == nullptr && RobotState::IsDisabled()) {
Cancel();
+ }
- if (IsCanceled()) return false;
+ if (IsCanceled()) {
+ return false;
+ }
if (!m_initialized) {
m_initialized = true;
@@ -108,23 +117,34 @@
}
void Command::Cancel() {
- if (m_parent != nullptr)
- wpi_setWPIErrorWithContext(
- CommandIllegalUse,
+ if (m_parent != nullptr) {
+ throw FRC_MakeError(
+ err::CommandIllegalUse, "{}",
"Can not cancel a command that is part of a command group");
+ }
_Cancel();
}
-bool Command::IsRunning() const { return m_running; }
+bool Command::IsRunning() const {
+ return m_running;
+}
-bool Command::IsInitialized() const { return m_initialized; }
+bool Command::IsInitialized() const {
+ return m_initialized;
+}
-bool Command::IsCompleted() const { return m_completed; }
+bool Command::IsCompleted() const {
+ return m_completed;
+}
-bool Command::IsCanceled() const { return m_canceled; }
+bool Command::IsCanceled() const {
+ return m_canceled;
+}
-bool Command::IsInterruptible() const { return m_interruptible; }
+bool Command::IsInterruptible() const {
+ return m_interruptible;
+}
void Command::SetInterruptible(bool interruptible) {
m_interruptible = interruptible;
@@ -138,51 +158,64 @@
return m_requirements;
}
-CommandGroup* Command::GetGroup() const { return m_parent; }
+CommandGroup* Command::GetGroup() const {
+ return m_parent;
+}
-void Command::SetRunWhenDisabled(bool run) { m_runWhenDisabled = run; }
+void Command::SetRunWhenDisabled(bool run) {
+ m_runWhenDisabled = run;
+}
-bool Command::WillRunWhenDisabled() const { return m_runWhenDisabled; }
+bool Command::WillRunWhenDisabled() const {
+ return m_runWhenDisabled;
+}
-int Command::GetID() const { return m_commandID; }
+int Command::GetID() const {
+ return m_commandID;
+}
-void Command::SetTimeout(double timeout) {
- if (timeout < 0.0)
- wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
- else
+void Command::SetTimeout(units::second_t timeout) {
+ if (timeout < 0_s) {
+ throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0 s",
+ timeout.value());
+ } else {
m_timeout = timeout;
+ }
}
bool Command::IsTimedOut() const {
- return m_timeout != -1 && TimeSinceInitialized() >= m_timeout;
+ return m_timeout != -1_s && TimeSinceInitialized() >= m_timeout;
}
-bool Command::AssertUnlocked(const std::string& message) {
+bool Command::AssertUnlocked(std::string_view message) {
if (m_locked) {
- std::string buf =
- message + " after being started or being added to a command group";
- wpi_setWPIErrorWithContext(CommandIllegalUse, buf);
- return false;
+ throw FRC_MakeError(
+ err::CommandIllegalUse,
+ "{} after being started or being added to a command group", message);
}
return true;
}
void Command::SetParent(CommandGroup* parent) {
if (parent == nullptr) {
- wpi_setWPIErrorWithContext(NullParameter, "parent");
+ throw FRC_MakeError(err::NullParameter, "{}", "parent");
} else if (m_parent != nullptr) {
- wpi_setWPIErrorWithContext(CommandIllegalUse,
- "Can not give command to a command group after "
- "already being put in a command group");
+ throw FRC_MakeError(err::CommandIllegalUse, "{}",
+ "Can not give command to a command group after "
+ "already being put in a command group");
} else {
LockChanges();
m_parent = parent;
}
}
-bool Command::IsParented() const { return m_parent != nullptr; }
+bool Command::IsParented() const {
+ return m_parent != nullptr;
+}
-void Command::ClearRequirements() { m_requirements.clear(); }
+void Command::ClearRequirements() {
+ m_requirements.clear();
+}
void Command::Initialize() {}
@@ -190,21 +223,33 @@
void Command::End() {}
-void Command::Interrupted() { End(); }
+void Command::Interrupted() {
+ End();
+}
-void Command::_Initialize() { m_completed = false; }
+void Command::_Initialize() {
+ m_completed = false;
+}
-void Command::_Interrupted() { m_completed = true; }
+void Command::_Interrupted() {
+ m_completed = true;
+}
void Command::_Execute() {}
-void Command::_End() { m_completed = true; }
-
-void Command::_Cancel() {
- if (IsRunning()) m_canceled = true;
+void Command::_End() {
+ m_completed = true;
}
-void Command::LockChanges() { m_locked = true; }
+void Command::_Cancel() {
+ if (IsRunning()) {
+ m_canceled = true;
+ }
+}
+
+void Command::LockChanges() {
+ m_locked = true;
+}
void Command::Removed() {
if (m_initialized) {
@@ -224,42 +269,47 @@
void Command::StartRunning() {
m_running = true;
- m_startTime = -1;
+ m_startTime = -1_s;
m_completed = false;
}
-void Command::StartTiming() { m_startTime = Timer::GetFPGATimestamp(); }
-
-std::string Command::GetName() const {
- return SendableRegistry::GetInstance().GetName(this);
+void Command::StartTiming() {
+ m_startTime = Timer::GetFPGATimestamp();
}
-void Command::SetName(const wpi::Twine& name) {
- SendableRegistry::GetInstance().SetName(this, name);
+std::string Command::GetName() const {
+ return wpi::SendableRegistry::GetName(this);
+}
+
+void Command::SetName(std::string_view name) {
+ wpi::SendableRegistry::SetName(this, name);
}
std::string Command::GetSubsystem() const {
- return SendableRegistry::GetInstance().GetSubsystem(this);
+ return wpi::SendableRegistry::GetSubsystem(this);
}
-void Command::SetSubsystem(const wpi::Twine& name) {
- SendableRegistry::GetInstance().SetSubsystem(this, name);
+void Command::SetSubsystem(std::string_view name) {
+ wpi::SendableRegistry::SetSubsystem(this, name);
}
-void Command::InitSendable(SendableBuilder& builder) {
+void Command::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Command");
builder.AddStringProperty(
- ".name", [=]() { return SendableRegistry::GetInstance().GetName(this); },
- nullptr);
+ ".name", [=] { return wpi::SendableRegistry::GetName(this); }, nullptr);
builder.AddBooleanProperty(
- "running", [=]() { return IsRunning(); },
+ "running", [=] { return IsRunning(); },
[=](bool value) {
if (value) {
- if (!IsRunning()) Start();
+ if (!IsRunning()) {
+ Start();
+ }
} else {
- if (IsRunning()) Cancel();
+ if (IsRunning()) {
+ Cancel();
+ }
}
});
builder.AddBooleanProperty(
- ".isParented", [=]() { return IsParented(); }, nullptr);
+ ".isParented", [=] { return IsParented(); }, nullptr);
}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp b/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp
index 31354e3..977795d 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp
@@ -1,24 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "frc/commands/CommandGroup.h"
-#include "frc/WPIErrors.h"
+#include "frc/Errors.h"
using namespace frc;
-CommandGroup::CommandGroup(const wpi::Twine& name) : Command(name) {}
+CommandGroup::CommandGroup(std::string_view name) : Command(name) {}
void CommandGroup::AddSequential(Command* command) {
- if (command == nullptr) {
- wpi_setWPIErrorWithContext(NullParameter, "command");
+ if (!command) {
+ throw FRC_MakeError(err::NullParameter, "{}", "command");
+ }
+ if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
- if (!AssertUnlocked("Cannot add new command to command group")) return;
m_commands.emplace_back(command, CommandGroupEntry::kSequence_InSequence);
@@ -26,18 +24,21 @@
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
- for (auto&& requirement : command->GetRequirements()) Requires(requirement);
+ for (auto&& requirement : command->GetRequirements()) {
+ Requires(requirement);
+ }
}
-void CommandGroup::AddSequential(Command* command, double timeout) {
- if (command == nullptr) {
- wpi_setWPIErrorWithContext(NullParameter, "command");
+void CommandGroup::AddSequential(Command* command, units::second_t timeout) {
+ if (!command) {
+ throw FRC_MakeError(err::NullParameter, "{}", "command");
+ }
+ if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
- if (!AssertUnlocked("Cannot add new command to command group")) return;
- if (timeout < 0.0) {
- wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
- return;
+ if (timeout < 0_s) {
+ throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0 s",
+ timeout.value());
}
m_commands.emplace_back(command, CommandGroupEntry::kSequence_InSequence,
@@ -47,15 +48,19 @@
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
- for (auto&& requirement : command->GetRequirements()) Requires(requirement);
+ for (auto&& requirement : command->GetRequirements()) {
+ Requires(requirement);
+ }
}
void CommandGroup::AddParallel(Command* command) {
- if (command == nullptr) {
- wpi_setWPIErrorWithContext(NullParameter, "command");
+ if (!command) {
+ throw FRC_MakeError(err::NullParameter, "{}", "command");
return;
}
- if (!AssertUnlocked("Cannot add new command to command group")) return;
+ if (!AssertUnlocked("Cannot add new command to command group")) {
+ return;
+ }
m_commands.emplace_back(command, CommandGroupEntry::kSequence_BranchChild);
@@ -63,18 +68,21 @@
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
- for (auto&& requirement : command->GetRequirements()) Requires(requirement);
+ for (auto&& requirement : command->GetRequirements()) {
+ Requires(requirement);
+ }
}
-void CommandGroup::AddParallel(Command* command, double timeout) {
- if (command == nullptr) {
- wpi_setWPIErrorWithContext(NullParameter, "command");
+void CommandGroup::AddParallel(Command* command, units::second_t timeout) {
+ if (!command) {
+ throw FRC_MakeError(err::NullParameter, "{}", "command");
+ }
+ if (!AssertUnlocked("Cannot add new command to command group")) {
return;
}
- if (!AssertUnlocked("Cannot add new command to command group")) return;
- if (timeout < 0.0) {
- wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
- return;
+ if (timeout < 0_s) {
+ throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0 s",
+ timeout.value());
}
m_commands.emplace_back(command, CommandGroupEntry::kSequence_BranchChild,
@@ -84,26 +92,36 @@
// Iterate through command->GetRequirements() and call Requires() on each
// required subsystem
- for (auto&& requirement : command->GetRequirements()) Requires(requirement);
+ for (auto&& requirement : command->GetRequirements()) {
+ Requires(requirement);
+ }
}
bool CommandGroup::IsInterruptible() const {
- if (!Command::IsInterruptible()) return false;
+ if (!Command::IsInterruptible()) {
+ return false;
+ }
if (m_currentCommandIndex != -1 &&
static_cast<size_t>(m_currentCommandIndex) < m_commands.size()) {
Command* cmd = m_commands[m_currentCommandIndex].m_command;
- if (!cmd->IsInterruptible()) return false;
+ if (!cmd->IsInterruptible()) {
+ return false;
+ }
}
for (const auto& child : m_children) {
- if (!child->m_command->IsInterruptible()) return false;
+ if (!child->m_command->IsInterruptible()) {
+ return false;
+ }
}
return true;
}
-int CommandGroup::GetSize() const { return m_children.size(); }
+int CommandGroup::GetSize() const {
+ return m_children.size();
+}
void CommandGroup::Initialize() {}
@@ -118,7 +136,9 @@
void CommandGroup::Interrupted() {}
-void CommandGroup::_Initialize() { m_currentCommandIndex = -1; }
+void CommandGroup::_Initialize() {
+ m_currentCommandIndex = -1;
+}
void CommandGroup::_Execute() {
CommandGroupEntry* entry;
@@ -135,7 +155,9 @@
// If a command is prepared to run
if (cmd != nullptr) {
// If command timed out, cancel it so it's removed from the Scheduler
- if (entry->IsTimedOut()) cmd->_Cancel();
+ if (entry->IsTimedOut()) {
+ cmd->_Cancel();
+ }
// If command finished or was canceled, remove it from Scheduler
if (cmd->Run()) {
@@ -222,7 +244,9 @@
m_children.clear();
}
-void CommandGroup::_Interrupted() { _End(); }
+void CommandGroup::_Interrupted() {
+ _End();
+}
void CommandGroup::CancelConflicts(Command* command) {
for (auto childIter = m_children.begin(); childIter != m_children.end();) {
@@ -238,6 +262,8 @@
break;
}
}
- if (!erased) childIter++;
+ if (!erased) {
+ childIter++;
+ }
}
}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/CommandGroupEntry.cpp b/wpilibOldCommands/src/main/native/cpp/commands/CommandGroupEntry.cpp
index 3441743..1e6f8c7 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/CommandGroupEntry.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/CommandGroupEntry.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/CommandGroupEntry.h"
@@ -12,12 +9,16 @@
using namespace frc;
CommandGroupEntry::CommandGroupEntry(Command* command, Sequence state,
- double timeout)
+ units::second_t timeout)
: m_timeout(timeout), m_command(command), m_state(state) {}
bool CommandGroupEntry::IsTimedOut() const {
- if (m_timeout < 0.0) return false;
- double time = m_command->TimeSinceInitialized();
- if (time == 0.0) return false;
+ if (m_timeout < 0_s) {
+ return false;
+ }
+ auto time = m_command->TimeSinceInitialized();
+ if (time == 0_s) {
+ return false;
+ }
return time >= m_timeout;
}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/ConditionalCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/ConditionalCommand.cpp
index 3d89d92..e2867b5 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/ConditionalCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/ConditionalCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-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/commands/ConditionalCommand.h"
@@ -13,12 +10,14 @@
static void RequireAll(Command& command, Command* onTrue, Command* onFalse) {
if (onTrue != nullptr) {
- for (auto requirement : onTrue->GetRequirements())
+ for (auto requirement : onTrue->GetRequirements()) {
command.Requires(requirement);
+ }
}
if (onFalse != nullptr) {
- for (auto requirement : onFalse->GetRequirements())
+ for (auto requirement : onFalse->GetRequirements()) {
command.Requires(requirement);
+ }
}
}
@@ -29,7 +28,7 @@
RequireAll(*this, onTrue, onFalse);
}
-ConditionalCommand::ConditionalCommand(const wpi::Twine& name, Command* onTrue,
+ConditionalCommand::ConditionalCommand(std::string_view name, Command* onTrue,
Command* onFalse)
: Command(name) {
m_onTrue = onTrue;
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/InstantCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/InstantCommand.cpp
index 445c5e0..d8f3309 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/InstantCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/InstantCommand.cpp
@@ -1,35 +1,35 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/commands/InstantCommand.h"
+#include <utility>
+
using namespace frc;
-InstantCommand::InstantCommand(const wpi::Twine& name) : Command(name) {}
+InstantCommand::InstantCommand(std::string_view name) : Command(name) {}
InstantCommand::InstantCommand(Subsystem& subsystem) : Command(subsystem) {}
-InstantCommand::InstantCommand(const wpi::Twine& name, Subsystem& subsystem)
+InstantCommand::InstantCommand(std::string_view name, Subsystem& subsystem)
: Command(name, subsystem) {}
-InstantCommand::InstantCommand(std::function<void()> func) : m_func(func) {}
+InstantCommand::InstantCommand(std::function<void()> func)
+ : m_func(std::move(func)) {}
InstantCommand::InstantCommand(Subsystem& subsystem, std::function<void()> func)
: InstantCommand(subsystem) {
m_func = func;
}
-InstantCommand::InstantCommand(const wpi::Twine& name,
+InstantCommand::InstantCommand(std::string_view name,
std::function<void()> func)
: InstantCommand(name) {
m_func = func;
}
-InstantCommand::InstantCommand(const wpi::Twine& name, Subsystem& subsystem,
+InstantCommand::InstantCommand(std::string_view name, Subsystem& subsystem,
std::function<void()> func)
: InstantCommand(name, subsystem) {
m_func = func;
@@ -42,4 +42,6 @@
}
}
-bool InstantCommand::IsFinished() { return true; }
+bool InstantCommand::IsFinished() {
+ return true;
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/PIDCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/PIDCommand.cpp
index 90a05f4..e71556a 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/PIDCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/PIDCommand.cpp
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/PIDCommand.h"
-#include "frc/smartdashboard/SendableBuilder.h"
+#include <wpi/sendable/SendableBuilder.h>
using namespace frc;
-PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
+PIDCommand::PIDCommand(std::string_view name, double p, double i, double d,
double f, double period)
: Command(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
@@ -22,12 +19,12 @@
std::make_shared<PIDController>(p, i, d, f, this, this, period);
}
-PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d)
+PIDCommand::PIDCommand(std::string_view name, double p, double i, double d)
: Command(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
}
-PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
+PIDCommand::PIDCommand(std::string_view name, double p, double i, double d,
double period)
: Command(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
@@ -41,7 +38,7 @@
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
}
-PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
+PIDCommand::PIDCommand(std::string_view name, double p, double i, double d,
double f, double period, Subsystem& subsystem)
: Command(name, subsystem) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
@@ -54,13 +51,13 @@
std::make_shared<PIDController>(p, i, d, f, this, this, period);
}
-PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
+PIDCommand::PIDCommand(std::string_view name, double p, double i, double d,
Subsystem& subsystem)
: Command(name, subsystem) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
}
-PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
+PIDCommand::PIDCommand(std::string_view name, double p, double i, double d,
double period, Subsystem& subsystem)
: Command(name, subsystem) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
@@ -75,19 +72,29 @@
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
}
-void PIDCommand::_Initialize() { m_controller->Enable(); }
+void PIDCommand::_Initialize() {
+ m_controller->Enable();
+}
-void PIDCommand::_End() { m_controller->Disable(); }
+void PIDCommand::_End() {
+ m_controller->Disable();
+}
-void PIDCommand::_Interrupted() { _End(); }
+void PIDCommand::_Interrupted() {
+ _End();
+}
void PIDCommand::SetSetpointRelative(double deltaSetpoint) {
SetSetpoint(GetSetpoint() + deltaSetpoint);
}
-void PIDCommand::PIDWrite(double output) { UsePIDOutput(output); }
+void PIDCommand::PIDWrite(double output) {
+ UsePIDOutput(output);
+}
-double PIDCommand::PIDGet() { return ReturnPIDInput(); }
+double PIDCommand::PIDGet() {
+ return ReturnPIDInput();
+}
std::shared_ptr<PIDController> PIDCommand::GetPIDController() const {
return m_controller;
@@ -97,11 +104,15 @@
m_controller->SetSetpoint(setpoint);
}
-double PIDCommand::GetSetpoint() const { return m_controller->GetSetpoint(); }
+double PIDCommand::GetSetpoint() const {
+ return m_controller->GetSetpoint();
+}
-double PIDCommand::GetPosition() { return ReturnPIDInput(); }
+double PIDCommand::GetPosition() {
+ return ReturnPIDInput();
+}
-void PIDCommand::InitSendable(SendableBuilder& builder) {
+void PIDCommand::InitSendable(wpi::SendableBuilder& builder) {
m_controller->InitSendable(builder);
Command::InitSendable(builder);
builder.SetSmartDashboardType("PIDCommand");
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/PIDSubsystem.cpp b/wpilibOldCommands/src/main/native/cpp/commands/PIDSubsystem.cpp
index 4d35943..f76288b 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/PIDSubsystem.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/PIDSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/PIDSubsystem.h"
@@ -11,20 +8,20 @@
using namespace frc;
-PIDSubsystem::PIDSubsystem(const wpi::Twine& name, double p, double i, double d)
+PIDSubsystem::PIDSubsystem(std::string_view name, double p, double i, double d)
: Subsystem(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
AddChild("PIDController", m_controller);
}
-PIDSubsystem::PIDSubsystem(const wpi::Twine& name, double p, double i, double d,
+PIDSubsystem::PIDSubsystem(std::string_view name, double p, double i, double d,
double f)
: Subsystem(name) {
m_controller = std::make_shared<PIDController>(p, i, d, f, this, this);
AddChild("PIDController", m_controller);
}
-PIDSubsystem::PIDSubsystem(const wpi::Twine& name, double p, double i, double d,
+PIDSubsystem::PIDSubsystem(std::string_view name, double p, double i, double d,
double f, double period)
: Subsystem(name) {
m_controller =
@@ -52,13 +49,21 @@
AddChild("PIDController", m_controller);
}
-void PIDSubsystem::Enable() { m_controller->Enable(); }
+void PIDSubsystem::Enable() {
+ m_controller->Enable();
+}
-void PIDSubsystem::Disable() { m_controller->Disable(); }
+void PIDSubsystem::Disable() {
+ m_controller->Disable();
+}
-void PIDSubsystem::PIDWrite(double output) { UsePIDOutput(output); }
+void PIDSubsystem::PIDWrite(double output) {
+ UsePIDOutput(output);
+}
-double PIDSubsystem::PIDGet() { return ReturnPIDInput(); }
+double PIDSubsystem::PIDGet() {
+ return ReturnPIDInput();
+}
void PIDSubsystem::SetSetpoint(double setpoint) {
m_controller->SetSetpoint(setpoint);
@@ -76,11 +81,17 @@
m_controller->SetOutputRange(minimumOutput, maximumOutput);
}
-double PIDSubsystem::GetSetpoint() { return m_controller->GetSetpoint(); }
+double PIDSubsystem::GetSetpoint() {
+ return m_controller->GetSetpoint();
+}
-double PIDSubsystem::GetPosition() { return ReturnPIDInput(); }
+double PIDSubsystem::GetPosition() {
+ return ReturnPIDInput();
+}
-double PIDSubsystem::GetRate() { return ReturnPIDInput(); }
+double PIDSubsystem::GetRate() {
+ return ReturnPIDInput();
+}
void PIDSubsystem::SetAbsoluteTolerance(double absValue) {
m_controller->SetAbsoluteTolerance(absValue);
@@ -90,7 +101,9 @@
m_controller->SetPercentTolerance(percent);
}
-bool PIDSubsystem::OnTarget() const { return m_controller->OnTarget(); }
+bool PIDSubsystem::OnTarget() const {
+ return m_controller->OnTarget();
+}
std::shared_ptr<PIDController> PIDSubsystem::GetPIDController() {
return m_controller;
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/PrintCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/PrintCommand.cpp
index 888e8a1..ca8f49a 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/PrintCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/PrintCommand.cpp
@@ -1,19 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/PrintCommand.h"
-#include <wpi/raw_ostream.h>
+#include <fmt/format.h>
using namespace frc;
-PrintCommand::PrintCommand(const wpi::Twine& message)
- : InstantCommand("Print \"" + message + wpi::Twine('"')) {
- m_message = message.str();
+PrintCommand::PrintCommand(std::string_view message)
+ : InstantCommand(fmt::format("Print \"{}\"", message)) {
+ m_message = message;
}
-void PrintCommand::Initialize() { wpi::outs() << m_message << '\n'; }
+void PrintCommand::Initialize() {
+ fmt::print("{}\n", m_message);
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp b/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp
index 47212e5..701162c 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.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 "frc/commands/Scheduler.h"
@@ -13,16 +10,16 @@
#include <vector>
#include <hal/FRCUsageReporting.h>
+#include <networktables/NTSendableBuilder.h>
#include <networktables/NetworkTableEntry.h>
#include <wpi/mutex.h>
+#include <wpi/sendable/SendableRegistry.h>
-#include "frc/WPIErrors.h"
+#include "frc/Errors.h"
#include "frc/buttons/ButtonScheduler.h"
#include "frc/commands/Command.h"
#include "frc/commands/Subsystem.h"
#include "frc/livewindow/LiveWindow.h"
-#include "frc/smartdashboard/SendableBuilder.h"
-#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
@@ -55,8 +52,9 @@
void Scheduler::AddCommand(Command* command) {
std::scoped_lock lock(m_impl->additionsMutex);
if (std::find(m_impl->additions.begin(), m_impl->additions.end(), command) !=
- m_impl->additions.end())
+ m_impl->additions.end()) {
return;
+ }
m_impl->additions.push_back(command);
}
@@ -66,9 +64,8 @@
}
void Scheduler::RegisterSubsystem(Subsystem* subsystem) {
- if (subsystem == nullptr) {
- wpi_setWPIErrorWithContext(NullParameter, "subsystem");
- return;
+ if (!subsystem) {
+ throw FRC_MakeError(err::NullParameter, "{}", "subsystem");
}
m_impl->subsystems.insert(subsystem);
}
@@ -76,7 +73,9 @@
void Scheduler::Run() {
// Get button input (going backwards preserves button priority)
{
- if (!m_impl->enabled) return;
+ if (!m_impl->enabled) {
+ return;
+ }
std::scoped_lock lock(m_impl->buttonsMutex);
for (auto& button : m_impl->buttons) {
@@ -109,8 +108,8 @@
for (auto& addition : m_impl->additions) {
// Check to make sure no adding during adding
if (m_impl->adding) {
- wpi_setWPIErrorWithContext(IncompatibleState,
- "Can not start command from cancel method");
+ FRC_ReportError(warn::IncompatibleState, "{}",
+ "Can not start command from cancel method");
} else {
m_impl->ProcessCommandAddition(addition);
}
@@ -122,8 +121,8 @@
for (auto& subsystem : m_impl->subsystems) {
if (subsystem->GetCurrentCommand() == nullptr) {
if (m_impl->adding) {
- wpi_setWPIErrorWithContext(IncompatibleState,
- "Can not start command from cancel method");
+ FRC_ReportError(warn::IncompatibleState, "{}",
+ "Can not start command from cancel method");
} else {
m_impl->ProcessCommandAddition(subsystem->GetDefaultCommand());
}
@@ -133,9 +132,8 @@
}
void Scheduler::Remove(Command* command) {
- if (command == nullptr) {
- wpi_setWPIErrorWithContext(NullParameter, "command");
- return;
+ if (!command) {
+ throw FRC_MakeError(err::NullParameter, "{}", "command");
}
m_impl->Remove(command);
@@ -155,18 +153,22 @@
m_impl->commands.clear();
}
-void Scheduler::SetEnabled(bool enabled) { m_impl->enabled = enabled; }
+void Scheduler::SetEnabled(bool enabled) {
+ m_impl->enabled = enabled;
+}
-void Scheduler::InitSendable(SendableBuilder& builder) {
+void Scheduler::InitSendable(nt::NTSendableBuilder& builder) {
builder.SetSmartDashboardType("Scheduler");
auto namesEntry = builder.GetEntry("Names");
auto idsEntry = builder.GetEntry("Ids");
auto cancelEntry = builder.GetEntry("Cancel");
- builder.SetUpdateTable([=]() {
+ builder.SetUpdateTable([=] {
// Get the list of possible commands to cancel
auto new_toCancel = cancelEntry.GetValue();
- wpi::ArrayRef<double> toCancel;
- if (new_toCancel) toCancel = new_toCancel->GetDoubleArray();
+ wpi::span<const double> toCancel;
+ if (new_toCancel) {
+ toCancel = new_toCancel->GetDoubleArray();
+ }
// Cancel commands whose cancel buttons were pressed on the SmartDashboard
if (!toCancel.empty()) {
@@ -184,9 +186,9 @@
if (m_impl->runningCommandsChanged) {
m_impl->commandsBuf.resize(0);
m_impl->idsBuf.resize(0);
- auto& registry = SendableRegistry::GetInstance();
for (const auto& command : m_impl->commands) {
- m_impl->commandsBuf.emplace_back(registry.GetName(command));
+ m_impl->commandsBuf.emplace_back(
+ wpi::SendableRegistry::GetName(command));
m_impl->idsBuf.emplace_back(command->GetID());
}
nt::NetworkTableEntry(namesEntry).SetStringArray(m_impl->commandsBuf);
@@ -198,24 +200,24 @@
Scheduler::Scheduler() : m_impl(new Impl) {
HAL_Report(HALUsageReporting::kResourceType_Command,
HALUsageReporting::kCommand_Scheduler);
- SendableRegistry::GetInstance().AddLW(this, "Scheduler");
- auto scheduler = frc::LiveWindow::GetInstance();
- scheduler->enabled = [this] {
+ wpi::SendableRegistry::AddLW(this, "Scheduler");
+ frc::LiveWindow::SetEnabledCallback([this] {
this->SetEnabled(false);
this->RemoveAll();
- };
- scheduler->disabled = [this] { this->SetEnabled(true); };
+ });
+ frc::LiveWindow::SetDisabledCallback([this] { this->SetEnabled(true); });
}
Scheduler::~Scheduler() {
- 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);
}
void Scheduler::Impl::Remove(Command* command) {
- if (!commands.erase(command)) return;
+ if (!commands.erase(command)) {
+ return;
+ }
for (auto&& requirement : command->GetRequirements()) {
requirement->SetCurrentCommand(nullptr);
@@ -225,7 +227,9 @@
}
void Scheduler::Impl::ProcessCommandAddition(Command* command) {
- if (command == nullptr) return;
+ if (command == nullptr) {
+ return;
+ }
// Only add if not already in
auto found = commands.find(command);
@@ -234,8 +238,9 @@
const auto& requirements = command->GetRequirements();
for (const auto requirement : requirements) {
if (requirement->GetCurrentCommand() != nullptr &&
- !requirement->GetCurrentCommand()->IsInterruptible())
+ !requirement->GetCurrentCommand()->IsInterruptible()) {
return;
+ }
}
// Give it the requirements
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/StartCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/StartCommand.cpp
index 97ddfb9..05dc079 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/StartCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/StartCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/StartCommand.h"
@@ -14,4 +11,6 @@
m_commandToFork = commandToStart;
}
-void StartCommand::Initialize() { m_commandToFork->Start(); }
+void StartCommand::Initialize() {
+ m_commandToFork->Start();
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp b/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp
index 85e800e..824872f 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp
@@ -1,23 +1,21 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "frc/commands/Subsystem.h"
-#include "frc/WPIErrors.h"
+#include <wpi/sendable/SendableBuilder.h>
+#include <wpi/sendable/SendableRegistry.h>
+
+#include "frc/Errors.h"
#include "frc/commands/Command.h"
#include "frc/commands/Scheduler.h"
#include "frc/livewindow/LiveWindow.h"
-#include "frc/smartdashboard/SendableBuilder.h"
-#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
-Subsystem::Subsystem(const wpi::Twine& name) {
- SendableRegistry::GetInstance().AddLW(this, name, name);
+Subsystem::Subsystem(std::string_view name) {
+ wpi::SendableRegistry::AddLW(this, name, name);
Scheduler::GetInstance()->RegisterSubsystem(this);
}
@@ -27,9 +25,8 @@
} else {
const auto& reqs = command->GetRequirements();
if (std::find(reqs.begin(), reqs.end(), this) == reqs.end()) {
- wpi_setWPIErrorWithContext(
- CommandIllegalUse, "A default command must require the subsystem");
- return;
+ throw FRC_MakeError(err::CommandIllegalUse, "{}",
+ "A default command must require the subsystem");
}
m_defaultCommand = command;
@@ -44,12 +41,12 @@
return m_defaultCommand;
}
-wpi::StringRef Subsystem::GetDefaultCommandName() {
+std::string Subsystem::GetDefaultCommandName() {
Command* defaultCommand = GetDefaultCommand();
if (defaultCommand) {
- return SendableRegistry::GetInstance().GetName(defaultCommand);
+ return wpi::SendableRegistry::GetName(defaultCommand);
} else {
- return wpi::StringRef();
+ return {};
}
}
@@ -58,14 +55,16 @@
m_currentCommandChanged = true;
}
-Command* Subsystem::GetCurrentCommand() const { return m_currentCommand; }
+Command* Subsystem::GetCurrentCommand() const {
+ return m_currentCommand;
+}
-wpi::StringRef Subsystem::GetCurrentCommandName() const {
+std::string Subsystem::GetCurrentCommandName() const {
Command* currentCommand = GetCurrentCommand();
if (currentCommand) {
- return SendableRegistry::GetInstance().GetName(currentCommand);
+ return wpi::SendableRegistry::GetName(currentCommand);
} else {
- return wpi::StringRef();
+ return {};
}
}
@@ -74,59 +73,65 @@
void Subsystem::InitDefaultCommand() {}
std::string Subsystem::GetName() const {
- return SendableRegistry::GetInstance().GetName(this);
+ return wpi::SendableRegistry::GetName(this);
}
-void Subsystem::SetName(const wpi::Twine& name) {
- SendableRegistry::GetInstance().SetName(this, name);
+void Subsystem::SetName(std::string_view name) {
+ wpi::SendableRegistry::SetName(this, name);
}
std::string Subsystem::GetSubsystem() const {
- return SendableRegistry::GetInstance().GetSubsystem(this);
+ return wpi::SendableRegistry::GetSubsystem(this);
}
-void Subsystem::SetSubsystem(const wpi::Twine& name) {
- SendableRegistry::GetInstance().SetSubsystem(this, name);
+void Subsystem::SetSubsystem(std::string_view name) {
+ wpi::SendableRegistry::SetSubsystem(this, name);
}
-void Subsystem::AddChild(const wpi::Twine& name,
+void Subsystem::AddChild(std::string_view name,
std::shared_ptr<Sendable> child) {
AddChild(name, *child);
}
-void Subsystem::AddChild(const wpi::Twine& name, Sendable* child) {
+void Subsystem::AddChild(std::string_view name, wpi::Sendable* child) {
AddChild(name, *child);
}
-void Subsystem::AddChild(const wpi::Twine& name, Sendable& child) {
- auto& registry = SendableRegistry::GetInstance();
- registry.AddLW(&child, registry.GetSubsystem(this), name);
+void Subsystem::AddChild(std::string_view name, wpi::Sendable& child) {
+ wpi::SendableRegistry::AddLW(&child,
+ wpi::SendableRegistry::GetSubsystem(this), name);
}
-void Subsystem::AddChild(std::shared_ptr<Sendable> child) { AddChild(*child); }
+void Subsystem::AddChild(std::shared_ptr<wpi::Sendable> child) {
+ AddChild(*child);
+}
-void Subsystem::AddChild(Sendable* child) { AddChild(*child); }
+void Subsystem::AddChild(wpi::Sendable* child) {
+ AddChild(*child);
+}
-void Subsystem::AddChild(Sendable& child) {
- auto& registry = SendableRegistry::GetInstance();
- registry.SetSubsystem(&child, registry.GetSubsystem(this));
- registry.EnableLiveWindow(&child);
+void Subsystem::AddChild(wpi::Sendable& child) {
+ wpi::SendableRegistry::SetSubsystem(
+ &child, wpi::SendableRegistry::GetSubsystem(this));
+ wpi::SendableRegistry::EnableLiveWindow(&child);
}
void Subsystem::ConfirmCommand() {
- if (m_currentCommandChanged) m_currentCommandChanged = false;
+ if (m_currentCommandChanged) {
+ m_currentCommandChanged = false;
+ }
}
-void Subsystem::InitSendable(SendableBuilder& builder) {
+void Subsystem::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Subsystem");
builder.AddBooleanProperty(
- ".hasDefault", [=]() { return m_defaultCommand != nullptr; }, nullptr);
+ ".hasDefault", [=] { return m_defaultCommand != nullptr; }, nullptr);
builder.AddStringProperty(
- ".default", [=]() { return GetDefaultCommandName(); }, nullptr);
+ ".default", [=] { return GetDefaultCommandName(); }, nullptr);
builder.AddBooleanProperty(
- ".hasCommand", [=]() { return m_currentCommand != nullptr; }, nullptr);
+ ".hasCommand", [=] { return m_currentCommand != nullptr; }, nullptr);
builder.AddStringProperty(
- ".command", [=]() { return GetCurrentCommandName(); }, nullptr);
+ ".command", [=] { return GetCurrentCommandName(); }, nullptr);
}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/TimedCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/TimedCommand.cpp
index f5113b2..5c2ccd4 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/TimedCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/TimedCommand.cpp
@@ -1,24 +1,23 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/commands/TimedCommand.h"
using namespace frc;
-TimedCommand::TimedCommand(const wpi::Twine& name, double timeout)
+TimedCommand::TimedCommand(std::string_view name, units::second_t timeout)
: Command(name, timeout) {}
-TimedCommand::TimedCommand(double timeout) : Command(timeout) {}
+TimedCommand::TimedCommand(units::second_t timeout) : Command(timeout) {}
-TimedCommand::TimedCommand(const wpi::Twine& name, double timeout,
+TimedCommand::TimedCommand(std::string_view name, units::second_t timeout,
Subsystem& subsystem)
: Command(name, timeout, subsystem) {}
-TimedCommand::TimedCommand(double timeout, Subsystem& subsystem)
+TimedCommand::TimedCommand(units::second_t timeout, Subsystem& subsystem)
: Command(timeout, subsystem) {}
-bool TimedCommand::IsFinished() { return IsTimedOut(); }
+bool TimedCommand::IsFinished() {
+ return IsTimedOut();
+}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/WaitCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/WaitCommand.cpp
index d326193..b4d44e0 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/WaitCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/WaitCommand.cpp
@@ -1,16 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/WaitCommand.h"
+#include <fmt/format.h>
+
using namespace frc;
-WaitCommand::WaitCommand(double timeout)
- : TimedCommand("Wait(" + std::to_string(timeout) + ")", timeout) {}
+WaitCommand::WaitCommand(units::second_t timeout)
+ : TimedCommand(fmt::format("Wait({})", timeout.value()), timeout) {}
-WaitCommand::WaitCommand(const wpi::Twine& name, double timeout)
+WaitCommand::WaitCommand(std::string_view name, units::second_t timeout)
: TimedCommand(name, timeout) {}
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/WaitForChildren.cpp b/wpilibOldCommands/src/main/native/cpp/commands/WaitForChildren.cpp
index 374c11c..e02a630 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/WaitForChildren.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/WaitForChildren.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/WaitForChildren.h"
@@ -11,10 +8,10 @@
using namespace frc;
-WaitForChildren::WaitForChildren(double timeout)
+WaitForChildren::WaitForChildren(units::second_t timeout)
: Command("WaitForChildren", timeout) {}
-WaitForChildren::WaitForChildren(const wpi::Twine& name, double timeout)
+WaitForChildren::WaitForChildren(std::string_view name, units::second_t timeout)
: Command(name, timeout) {}
bool WaitForChildren::IsFinished() {
diff --git a/wpilibOldCommands/src/main/native/cpp/commands/WaitUntilCommand.cpp b/wpilibOldCommands/src/main/native/cpp/commands/WaitUntilCommand.cpp
index 07ff00b..bb127b1 100644
--- a/wpilibOldCommands/src/main/native/cpp/commands/WaitUntilCommand.cpp
+++ b/wpilibOldCommands/src/main/native/cpp/commands/WaitUntilCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/commands/WaitUntilCommand.h"
@@ -11,14 +8,16 @@
using namespace frc;
-WaitUntilCommand::WaitUntilCommand(double time)
+WaitUntilCommand::WaitUntilCommand(units::second_t time)
: Command("WaitUntilCommand", time) {
m_time = time;
}
-WaitUntilCommand::WaitUntilCommand(const wpi::Twine& name, double time)
+WaitUntilCommand::WaitUntilCommand(std::string_view name, units::second_t time)
: Command(name, time) {
m_time = time;
}
-bool WaitUntilCommand::IsFinished() { return Timer::GetMatchTime() >= m_time; }
+bool WaitUntilCommand::IsFinished() {
+ return Timer::GetMatchTime() >= m_time;
+}
diff --git a/wpilibOldCommands/src/main/native/include/frc/PIDBase.h b/wpilibOldCommands/src/main/native/include/frc/PIDBase.h
new file mode 100644
index 0000000..e834006
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/include/frc/PIDBase.h
@@ -0,0 +1,405 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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>
+
+#include <wpi/deprecated.h>
+#include <wpi/mutex.h>
+#include <wpi/sendable/Sendable.h>
+#include <wpi/sendable/SendableHelper.h>
+
+#include "frc/PIDInterface.h"
+#include "frc/PIDOutput.h"
+#include "frc/PIDSource.h"
+#include "frc/Timer.h"
+#include "frc/filter/LinearFilter.h"
+
+namespace frc {
+
+/**
+ * Class implements a PID Control Loop.
+ *
+ * Creates a separate thread which reads the given PIDSource and takes care of
+ * the integral calculations, as well as writing the given PIDOutput.
+ *
+ * This feedback controller runs in discrete time, so time deltas are not used
+ * in the integral and derivative calculations. Therefore, the sample rate
+ * affects the controller's behavior for a given set of PID constants.
+ *
+ * @deprecated All APIs which use this have been deprecated.
+ */
+class PIDBase : public PIDInterface,
+ public PIDOutput,
+ public wpi::Sendable,
+ public wpi::SendableHelper<PIDBase> {
+ public:
+ /**
+ * Allocate a PID object with the given constants for P, I, D.
+ *
+ * @param p the proportional coefficient
+ * @param i the integral coefficient
+ * @param d the derivative coefficient
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output value
+ */
+ WPI_DEPRECATED("All APIs which use this have been deprecated.")
+ PIDBase(double p, double i, double d, PIDSource& source, PIDOutput& output);
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D.
+ *
+ * @param p the proportional coefficient
+ * @param i the integral coefficient
+ * @param d the derivative coefficient
+ * @param f the feedforward coefficient
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output value
+ */
+ WPI_DEPRECATED("All APIs which use this have been deprecated.")
+ PIDBase(double p, double i, double d, double f, PIDSource& source,
+ PIDOutput& output);
+
+ ~PIDBase() override = default;
+
+ /**
+ * Return the current PID result.
+ *
+ * This is always centered on zero and constrained the the max and min outs.
+ *
+ * @return the latest calculated output
+ */
+ virtual double Get() const;
+
+ /**
+ * Set the PID controller to consider the input to be continuous,
+ *
+ * Rather then using the max and min input range as constraints, it considers
+ * them to be the same point and automatically calculates the shortest route
+ * to the setpoint.
+ *
+ * @param continuous true turns on continuous, false turns off continuous
+ */
+ virtual void SetContinuous(bool continuous = true);
+
+ /**
+ * Sets the maximum and minimum values expected from the input.
+ *
+ * @param minimumInput the minimum value expected from the input
+ * @param maximumInput the maximum value expected from the output
+ */
+ virtual void SetInputRange(double minimumInput, double maximumInput);
+
+ /**
+ * Sets the minimum and maximum values to write.
+ *
+ * @param minimumOutput the minimum value to write to the output
+ * @param maximumOutput the maximum value to write to the output
+ */
+ virtual void SetOutputRange(double minimumOutput, double maximumOutput);
+
+ /**
+ * Set the PID Controller gain parameters.
+ *
+ * Set the proportional, integral, and differential coefficients.
+ *
+ * @param p Proportional coefficient
+ * @param i Integral coefficient
+ * @param d Differential coefficient
+ */
+ void SetPID(double p, double i, double d) override;
+
+ /**
+ * Set the PID Controller gain parameters.
+ *
+ * Set the proportional, integral, and differential coefficients.
+ *
+ * @param p Proportional coefficient
+ * @param i Integral coefficient
+ * @param d Differential coefficient
+ * @param f Feed forward coefficient
+ */
+ virtual void SetPID(double p, double i, double d, double f);
+
+ /**
+ * Set the Proportional coefficient of the PID controller gain.
+ *
+ * @param p proportional coefficient
+ */
+ void SetP(double p);
+
+ /**
+ * Set the Integral coefficient of the PID controller gain.
+ *
+ * @param i integral coefficient
+ */
+ void SetI(double i);
+
+ /**
+ * Set the Differential coefficient of the PID controller gain.
+ *
+ * @param d differential coefficient
+ */
+ void SetD(double d);
+
+ /**
+ * Get the Feed forward coefficient of the PID controller gain.
+ *
+ * @param f Feed forward coefficient
+ */
+ void SetF(double f);
+
+ /**
+ * Get the Proportional coefficient.
+ *
+ * @return proportional coefficient
+ */
+ double GetP() const override;
+
+ /**
+ * Get the Integral coefficient.
+ *
+ * @return integral coefficient
+ */
+ double GetI() const override;
+
+ /**
+ * Get the Differential coefficient.
+ *
+ * @return differential coefficient
+ */
+ double GetD() const override;
+
+ /**
+ * Get the Feed forward coefficient.
+ *
+ * @return Feed forward coefficient
+ */
+ virtual double GetF() const;
+
+ /**
+ * Set the setpoint for the PIDBase.
+ *
+ * @param setpoint the desired setpoint
+ */
+ void SetSetpoint(double setpoint) override;
+
+ /**
+ * Returns the current setpoint of the PIDBase.
+ *
+ * @return the current setpoint
+ */
+ double GetSetpoint() const override;
+
+ /**
+ * Returns the change in setpoint over time of the PIDBase.
+ *
+ * @return the change in setpoint over time
+ */
+ double GetDeltaSetpoint() const;
+
+ /**
+ * Returns the current difference of the input from the setpoint.
+ *
+ * @return the current error
+ */
+ virtual double GetError() const;
+
+ /**
+ * Returns the current average of the error over the past few iterations.
+ *
+ * You can specify the number of iterations to average with
+ * SetToleranceBuffer() (defaults to 1). This is the same value that is used
+ * for OnTarget().
+ *
+ * @return the average error
+ */
+ WPI_DEPRECATED("Use a LinearFilter as the input and GetError().")
+ virtual double GetAvgError() const;
+
+ /**
+ * Sets what type of input the PID controller will use.
+ */
+ virtual void SetPIDSourceType(PIDSourceType pidSource);
+
+ /**
+ * Returns the type of input the PID controller is using.
+ *
+ * @return the PID controller input type
+ */
+ virtual PIDSourceType GetPIDSourceType() const;
+
+ /**
+ * Set the percentage error which is considered tolerable for use with
+ * OnTarget.
+ *
+ * @param percent error which is tolerable
+ */
+ WPI_DEPRECATED("Use SetPercentTolerance() instead.")
+ virtual void SetTolerance(double percent);
+
+ /**
+ * Set the absolute error which is considered tolerable for use with
+ * OnTarget.
+ *
+ * @param absTolerance error which is tolerable
+ */
+ virtual void SetAbsoluteTolerance(double absTolerance);
+
+ /**
+ * Set the percentage error which is considered tolerable for use with
+ * OnTarget.
+ *
+ * @param percent error which is tolerable
+ */
+ virtual void SetPercentTolerance(double percent);
+
+ /**
+ * Set the number of previous error samples to average for tolerancing. When
+ * determining whether a mechanism is on target, the user may want to use a
+ * rolling average of previous measurements instead of a precise position or
+ * velocity. This is useful for noisy sensors which return a few erroneous
+ * measurements when the mechanism is on target. However, the mechanism will
+ * not register as on target for at least the specified bufLength cycles.
+ *
+ * @param bufLength Number of previous cycles to average. Defaults to 1.
+ */
+ WPI_DEPRECATED("Use a LinearDigitalFilter as the input.")
+ virtual void SetToleranceBuffer(int bufLength = 1);
+
+ /**
+ * Return true if the error is within the percentage of the total input range,
+ * determined by SetTolerance. This asssumes that the maximum and minimum
+ * input were set using SetInput.
+ *
+ * Currently this just reports on target as the actual value passes through
+ * the setpoint. Ideally it should be based on being within the tolerance for
+ * some period of time.
+ *
+ * This will return false until at least one input value has been computed.
+ */
+ virtual bool OnTarget() const;
+
+ /**
+ * Reset the previous error, the integral term, and disable the controller.
+ */
+ void Reset() override;
+
+ /**
+ * Passes the output directly to SetSetpoint().
+ *
+ * PIDControllers can be nested by passing a PIDController as another
+ * PIDController's output. In that case, the output of the parent controller
+ * becomes the input (i.e., the reference) of the child.
+ *
+ * It is the caller's responsibility to put the data into a valid form for
+ * SetSetpoint().
+ */
+ void PIDWrite(double output) override;
+
+ void InitSendable(wpi::SendableBuilder& builder) override;
+
+ protected:
+ // Is the pid controller enabled
+ bool m_enabled = false;
+
+ mutable wpi::mutex m_thisMutex;
+
+ // Ensures when Disable() is called, PIDWrite() won't run if Calculate()
+ // is already running at that time.
+ mutable wpi::mutex m_pidWriteMutex;
+
+ PIDSource* m_pidInput;
+ PIDOutput* m_pidOutput;
+ Timer m_setpointTimer;
+
+ /**
+ * Read the input, calculate the output accordingly, and write to the output.
+ * This should only be called by the Notifier.
+ */
+ virtual void Calculate();
+
+ /**
+ * Calculate the feed forward term.
+ *
+ * Both of the provided feed forward calculations are velocity feed forwards.
+ * If a different feed forward calculation is desired, the user can override
+ * this function and provide his or her own. This function does no
+ * synchronization because the PIDBase class only calls it in synchronized
+ * code, so be careful if calling it oneself.
+ *
+ * If a velocity PID controller is being used, the F term should be set to 1
+ * over the maximum setpoint for the output. If a position PID controller is
+ * being used, the F term should be set to 1 over the maximum speed for the
+ * output measured in setpoint units per this controller's update period (see
+ * the default period in this class's constructor).
+ */
+ virtual double CalculateFeedForward();
+
+ /**
+ * Wraps error around for continuous inputs. The original error is returned if
+ * continuous mode is disabled. This is an unsynchronized function.
+ *
+ * @param error The current error of the PID controller.
+ * @return Error for continuous inputs.
+ */
+ double GetContinuousError(double error) const;
+
+ private:
+ // Factor for "proportional" control
+ double m_P;
+
+ // Factor for "integral" control
+ double m_I;
+
+ // Factor for "derivative" control
+ double m_D;
+
+ // Factor for "feed forward" control
+ double m_F;
+
+ // |maximum output|
+ double m_maximumOutput = 1.0;
+
+ // |minimum output|
+ double m_minimumOutput = -1.0;
+
+ // Maximum input - limit setpoint to this
+ double m_maximumInput = 0;
+
+ // Minimum input - limit setpoint to this
+ double m_minimumInput = 0;
+
+ // input range - difference between maximum and minimum
+ double m_inputRange = 0;
+
+ // Do the endpoints wrap around? eg. Absolute encoder
+ bool m_continuous = false;
+
+ // The prior error (used to compute velocity)
+ double m_prevError = 0;
+
+ // The sum of the errors for use in the integral calc
+ double m_totalError = 0;
+
+ enum {
+ kAbsoluteTolerance,
+ kPercentTolerance,
+ kNoTolerance
+ } m_toleranceType = kNoTolerance;
+
+ // The percetage or absolute error that is considered on target.
+ double m_tolerance = 0.05;
+
+ double m_setpoint = 0;
+ double m_prevSetpoint = 0;
+ double m_error = 0;
+ double m_result = 0;
+
+ LinearFilter<double> m_filter{{}, {}};
+};
+
+} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/PIDController.h b/wpilibOldCommands/src/main/native/include/frc/PIDController.h
new file mode 100644
index 0000000..763752d
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/include/frc/PIDController.h
@@ -0,0 +1,137 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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>
+
+#include <wpi/deprecated.h>
+#include <wpi/mutex.h>
+
+#include "frc/Controller.h"
+#include "frc/Notifier.h"
+#include "frc/PIDBase.h"
+#include "frc/PIDSource.h"
+#include "frc/Timer.h"
+
+namespace frc {
+
+class PIDOutput;
+
+/**
+ * Class implements a PID Control Loop.
+ *
+ * Creates a separate thread which reads the given PIDSource and takes care of
+ * the integral calculations, as well as writing the given PIDOutput.
+ *
+ * This feedback controller runs in discrete time, so time deltas are not used
+ * in the integral and derivative calculations. Therefore, the sample rate
+ * affects the controller's behavior for a given set of PID constants.
+ *
+ * @deprecated Use frc2::PIDController class instead.
+ */
+class PIDController : public PIDBase, public Controller {
+ public:
+ /**
+ * Allocate a PID object with the given constants for P, I, D.
+ *
+ * @param p the proportional coefficient
+ * @param i the integral coefficient
+ * @param d the derivative coefficient
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output value
+ * @param period the loop time for doing calculations in seconds. This
+ * particularly affects calculations of the integral and
+ * differential terms. The default is 0.05 (50ms).
+ */
+ WPI_DEPRECATED("Use frc2::PIDController class instead.")
+ PIDController(double p, double i, double d, PIDSource* source,
+ PIDOutput* output, double period = 0.05);
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D.
+ *
+ * @param p the proportional coefficient
+ * @param i the integral coefficient
+ * @param d the derivative coefficient
+ * @param f the feedforward coefficient
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output value
+ * @param period the loop time for doing calculations in seconds. This
+ * particularly affects calculations of the integral and
+ * differential terms. The default is 0.05 (50ms).
+ */
+ WPI_DEPRECATED("Use frc2::PIDController class instead.")
+ PIDController(double p, double i, double d, double f, PIDSource* source,
+ PIDOutput* output, double period = 0.05);
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D.
+ *
+ * @param p the proportional coefficient
+ * @param i the integral coefficient
+ * @param d the derivative coefficient
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output value
+ * @param period the loop time for doing calculations in seconds. This
+ * particularly affects calculations of the integral and
+ * differential terms. The default is 0.05 (50ms).
+ */
+ WPI_DEPRECATED("Use frc2::PIDController class instead.")
+ PIDController(double p, double i, double d, PIDSource& source,
+ PIDOutput& output, double period = 0.05);
+
+ /**
+ * Allocate a PID object with the given constants for P, I, D.
+ *
+ * @param p the proportional coefficient
+ * @param i the integral coefficient
+ * @param d the derivative coefficient
+ * @param f the feedforward coefficient
+ * @param source The PIDSource object that is used to get values
+ * @param output The PIDOutput object that is set to the output value
+ * @param period the loop time for doing calculations in seconds. This
+ * particularly affects calculations of the integral and
+ * differential terms. The default is 0.05 (50ms).
+ */
+ WPI_DEPRECATED("Use frc2::PIDController class instead.")
+ PIDController(double p, double i, double d, double f, PIDSource& source,
+ PIDOutput& output, double period = 0.05);
+
+ ~PIDController() override;
+
+ /**
+ * Begin running the PIDController.
+ */
+ void Enable() override;
+
+ /**
+ * Stop running the PIDController, this sets the output to zero before
+ * stopping.
+ */
+ void Disable() override;
+
+ /**
+ * Set the enabled state of the PIDController.
+ */
+ void SetEnabled(bool enable);
+
+ /**
+ * Return true if PIDController is enabled.
+ */
+ bool IsEnabled() const;
+
+ /**
+ * Reset the previous error, the integral term, and disable the controller.
+ */
+ void Reset() override;
+
+ void InitSendable(wpi::SendableBuilder& builder) override;
+
+ private:
+ std::unique_ptr<Notifier> m_controlLoop;
+};
+
+} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/PIDInterface.h b/wpilibOldCommands/src/main/native/include/frc/PIDInterface.h
new file mode 100644
index 0000000..20d26ef
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/include/frc/PIDInterface.h
@@ -0,0 +1,34 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <wpi/deprecated.h>
+
+namespace frc {
+
+/**
+ * Interface for PID Control Loop.
+ *
+ * @deprecated All APIs which use this have been deprecated.
+ */
+class PIDInterface {
+ public:
+ WPI_DEPRECATED("All APIs which use this have been deprecated.")
+ PIDInterface() = default;
+ PIDInterface(PIDInterface&&) = default;
+ PIDInterface& operator=(PIDInterface&&) = default;
+
+ virtual void SetPID(double p, double i, double d) = 0;
+ virtual double GetP() const = 0;
+ virtual double GetI() const = 0;
+ virtual double GetD() const = 0;
+
+ virtual void SetSetpoint(double setpoint) = 0;
+ virtual double GetSetpoint() const = 0;
+
+ virtual void Reset() = 0;
+};
+
+} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/PIDOutput.h b/wpilibOldCommands/src/main/native/include/frc/PIDOutput.h
new file mode 100644
index 0000000..98c4af4
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/include/frc/PIDOutput.h
@@ -0,0 +1,20 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+namespace frc {
+
+/**
+ * PIDOutput interface is a generic output for the PID class.
+ *
+ * PWMs use this class. Users implement this interface to allow for a
+ * PIDController to read directly from the inputs.
+ */
+class PIDOutput {
+ public:
+ virtual void PIDWrite(double output) = 0;
+};
+
+} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/PIDSource.h b/wpilibOldCommands/src/main/native/include/frc/PIDSource.h
new file mode 100644
index 0000000..3f6ca23
--- /dev/null
+++ b/wpilibOldCommands/src/main/native/include/frc/PIDSource.h
@@ -0,0 +1,36 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+namespace frc {
+
+enum class PIDSourceType { kDisplacement, kRate };
+
+/**
+ * PIDSource interface is a generic sensor source for the PID class.
+ *
+ * All sensors that can be used with the PID class will implement the PIDSource
+ * that returns a standard value that will be used in the PID code.
+ */
+class PIDSource {
+ public:
+ virtual ~PIDSource() = default;
+
+ /**
+ * Set which parameter you are using as a process control variable.
+ *
+ * @param pidSource An enum to select the parameter.
+ */
+ virtual void SetPIDSourceType(PIDSourceType pidSource);
+
+ virtual PIDSourceType GetPIDSourceType() const;
+
+ virtual double PIDGet() = 0;
+
+ protected:
+ PIDSourceType m_pidSource = PIDSourceType::kDisplacement;
+};
+
+} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/Button.h b/wpilibOldCommands/src/main/native/include/frc/buttons/Button.h
index c0830bf..89e2b41 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/Button.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/Button.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/wpilibOldCommands/src/main/native/include/frc/buttons/ButtonScheduler.h b/wpilibOldCommands/src/main/native/include/frc/buttons/ButtonScheduler.h
index 960fbc8..0c3ad20 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/ButtonScheduler.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/ButtonScheduler.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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/wpilibOldCommands/src/main/native/include/frc/buttons/CancelButtonScheduler.h b/wpilibOldCommands/src/main/native/include/frc/buttons/CancelButtonScheduler.h
index 9131fc0..c3938eb 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/CancelButtonScheduler.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/CancelButtonScheduler.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -17,12 +14,12 @@
class CancelButtonScheduler : public ButtonScheduler {
public:
CancelButtonScheduler(bool last, Trigger* button, Command* orders);
- virtual ~CancelButtonScheduler() = default;
+ ~CancelButtonScheduler() override = default;
CancelButtonScheduler(CancelButtonScheduler&&) = default;
CancelButtonScheduler& operator=(CancelButtonScheduler&&) = default;
- virtual void Execute();
+ void Execute() override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/HeldButtonScheduler.h b/wpilibOldCommands/src/main/native/include/frc/buttons/HeldButtonScheduler.h
index 2b51ce6..721688f 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/HeldButtonScheduler.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/HeldButtonScheduler.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -17,12 +14,12 @@
class HeldButtonScheduler : public ButtonScheduler {
public:
HeldButtonScheduler(bool last, Trigger* button, Command* orders);
- virtual ~HeldButtonScheduler() = default;
+ ~HeldButtonScheduler() override = default;
HeldButtonScheduler(HeldButtonScheduler&&) = default;
HeldButtonScheduler& operator=(HeldButtonScheduler&&) = default;
- virtual void Execute();
+ void Execute() override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/InternalButton.h b/wpilibOldCommands/src/main/native/include/frc/buttons/InternalButton.h
index ed4dc56..e9c1fb1 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/InternalButton.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/InternalButton.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -15,7 +12,7 @@
public:
InternalButton() = default;
explicit InternalButton(bool inverted);
- virtual ~InternalButton() = default;
+ ~InternalButton() override = default;
InternalButton(InternalButton&&) = default;
InternalButton& operator=(InternalButton&&) = default;
@@ -23,7 +20,7 @@
void SetInverted(bool inverted);
void SetPressed(bool pressed);
- virtual bool Get();
+ bool Get() override;
private:
bool m_pressed = false;
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/JoystickButton.h b/wpilibOldCommands/src/main/native/include/frc/buttons/JoystickButton.h
index e0e2d4c..24900b4 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/JoystickButton.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/JoystickButton.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -15,12 +12,12 @@
class JoystickButton : public Button {
public:
JoystickButton(GenericHID* joystick, int buttonNumber);
- virtual ~JoystickButton() = default;
+ ~JoystickButton() override = default;
JoystickButton(JoystickButton&&) = default;
JoystickButton& operator=(JoystickButton&&) = default;
- virtual bool Get();
+ bool Get() override;
private:
GenericHID* m_joystick;
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/NetworkButton.h b/wpilibOldCommands/src/main/native/include/frc/buttons/NetworkButton.h
index f16821b..3c468df 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/NetworkButton.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/NetworkButton.h
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <memory>
+#include <string_view>
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableEntry.h>
-#include <wpi/Twine.h>
#include "frc/buttons/Button.h"
@@ -19,15 +16,15 @@
class NetworkButton : public Button {
public:
- NetworkButton(const wpi::Twine& tableName, const wpi::Twine& field);
+ NetworkButton(std::string_view tableName, std::string_view field);
NetworkButton(std::shared_ptr<nt::NetworkTable> table,
- const wpi::Twine& field);
- virtual ~NetworkButton() = default;
+ std::string_view field);
+ ~NetworkButton() override = default;
NetworkButton(NetworkButton&&) = default;
NetworkButton& operator=(NetworkButton&&) = default;
- virtual bool Get();
+ bool Get() override;
private:
nt::NetworkTableEntry m_entry;
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/POVButton.h b/wpilibOldCommands/src/main/native/include/frc/buttons/POVButton.h
index bd73984..87e1789 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/POVButton.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/POVButton.h
@@ -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.
#pragma once
@@ -21,7 +18,7 @@
* @param povNumber The POV number (@see GenericHID#GetPOV)
*/
POVButton(GenericHID& joystick, int angle, int povNumber = 0);
- virtual ~POVButton() = default;
+ ~POVButton() override = default;
POVButton(POVButton&&) = default;
POVButton& operator=(POVButton&&) = default;
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/PressedButtonScheduler.h b/wpilibOldCommands/src/main/native/include/frc/buttons/PressedButtonScheduler.h
index 29c6a95..378d2c5 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/PressedButtonScheduler.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/PressedButtonScheduler.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -17,12 +14,12 @@
class PressedButtonScheduler : public ButtonScheduler {
public:
PressedButtonScheduler(bool last, Trigger* button, Command* orders);
- virtual ~PressedButtonScheduler() = default;
+ ~PressedButtonScheduler() override = default;
PressedButtonScheduler(PressedButtonScheduler&&) = default;
PressedButtonScheduler& operator=(PressedButtonScheduler&&) = default;
- virtual void Execute();
+ void Execute() override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/ReleasedButtonScheduler.h b/wpilibOldCommands/src/main/native/include/frc/buttons/ReleasedButtonScheduler.h
index a567a7b..6ed53ee 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/ReleasedButtonScheduler.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/ReleasedButtonScheduler.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -17,12 +14,12 @@
class ReleasedButtonScheduler : public ButtonScheduler {
public:
ReleasedButtonScheduler(bool last, Trigger* button, Command* orders);
- virtual ~ReleasedButtonScheduler() = default;
+ ~ReleasedButtonScheduler() override = default;
ReleasedButtonScheduler(ReleasedButtonScheduler&&) = default;
ReleasedButtonScheduler& operator=(ReleasedButtonScheduler&&) = default;
- virtual void Execute();
+ void Execute() override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/ToggleButtonScheduler.h b/wpilibOldCommands/src/main/native/include/frc/buttons/ToggleButtonScheduler.h
index 406d131..8df27a9 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/ToggleButtonScheduler.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/ToggleButtonScheduler.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -17,12 +14,12 @@
class ToggleButtonScheduler : public ButtonScheduler {
public:
ToggleButtonScheduler(bool last, Trigger* button, Command* orders);
- virtual ~ToggleButtonScheduler() = default;
+ ~ToggleButtonScheduler() override = default;
ToggleButtonScheduler(ToggleButtonScheduler&&) = default;
ToggleButtonScheduler& operator=(ToggleButtonScheduler&&) = default;
- virtual void Execute();
+ void Execute() override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/buttons/Trigger.h b/wpilibOldCommands/src/main/native/include/frc/buttons/Trigger.h
index 56700e9..966a29f 100644
--- a/wpilibOldCommands/src/main/native/include/frc/buttons/Trigger.h
+++ b/wpilibOldCommands/src/main/native/include/frc/buttons/Trigger.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <atomic>
-#include "frc/smartdashboard/Sendable.h"
-#include "frc/smartdashboard/SendableHelper.h"
+#include <wpi/sendable/Sendable.h>
+#include <wpi/sendable/SendableHelper.h>
namespace frc {
@@ -26,10 +23,10 @@
* 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.
+ * only have to write the Trigger::Get() method to get the full functionality of
+ * the Trigger class.
*/
-class Trigger : public Sendable, public SendableHelper<Trigger> {
+class Trigger : public wpi::Sendable, public wpi::SendableHelper<Trigger> {
public:
Trigger() = default;
~Trigger() override = default;
@@ -47,7 +44,7 @@
void CancelWhenActive(Command* command);
void ToggleWhenActive(Command* command);
- void InitSendable(SendableBuilder& builder) override;
+ void InitSendable(wpi::SendableBuilder& builder) override;
private:
std::atomic_bool m_sendablePressed{false};
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/Command.h b/wpilibOldCommands/src/main/native/include/frc/commands/Command.h
index cc6b795..aa20134 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/Command.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/Command.h
@@ -1,22 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* 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>
+#include <string_view>
+#include <units/time.h>
#include <wpi/SmallPtrSet.h>
-#include <wpi/Twine.h>
+#include <wpi/sendable/Sendable.h>
+#include <wpi/sendable/SendableHelper.h>
-#include "frc/ErrorBase.h"
#include "frc/commands/Subsystem.h"
-#include "frc/smartdashboard/Sendable.h"
-#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -46,9 +43,7 @@
* @see CommandGroup
* @see Subsystem
*/
-class Command : public ErrorBase,
- public Sendable,
- public SendableHelper<Command> {
+class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
friend class CommandGroup;
friend class Scheduler;
@@ -65,15 +60,15 @@
*
* @param name the name for this command
*/
- explicit Command(const wpi::Twine& name);
+ explicit Command(std::string_view name);
/**
* Creates a new command with the given timeout and a default name.
*
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
* @see IsTimedOut()
*/
- explicit Command(double timeout);
+ explicit Command(units::second_t timeout);
/**
* Creates a new command with the given timeout and a default name.
@@ -86,10 +81,10 @@
* Creates a new command with the given name and timeout.
*
* @param name the name of the command
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
* @see IsTimedOut()
*/
- Command(const wpi::Twine& name, double timeout);
+ Command(std::string_view name, units::second_t timeout);
/**
* Creates a new command with the given name and timeout.
@@ -97,24 +92,24 @@
* @param name the name of the command
* @param subsystem the subsystem that the command requires
*/
- Command(const wpi::Twine& name, Subsystem& subsystem);
+ Command(std::string_view name, Subsystem& subsystem);
/**
* Creates a new command with the given name and timeout.
*
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
* @param subsystem the subsystem that the command requires @see IsTimedOut()
*/
- Command(double timeout, Subsystem& subsystem);
+ Command(units::second_t timeout, Subsystem& subsystem);
/**
* Creates a new command with the given name and timeout.
*
* @param name the name of the command
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
* @param subsystem the subsystem that the command requires @see IsTimedOut()
*/
- Command(const wpi::Twine& name, double timeout, Subsystem& subsystem);
+ Command(std::string_view name, units::second_t timeout, Subsystem& subsystem);
~Command() override = default;
@@ -122,13 +117,13 @@
Command& operator=(Command&&) = default;
/**
- * Returns the time since this command was initialized (in seconds).
+ * Returns the time since this command was initialized.
*
* This function will work even if there is no specified timeout.
*
- * @return the time since this command was initialized (in seconds).
+ * @return the time since this command was initialized.
*/
- double TimeSinceInitialized() const;
+ units::second_t TimeSinceInitialized() const;
/**
* This method specifies that the given Subsystem is used by this command.
@@ -140,7 +135,7 @@
* @param subsystem The Subsystem required
* @see Subsystem
*/
- void Requires(Subsystem* s);
+ void Requires(Subsystem* subsystem);
/**
* Starts up the command. Gets the command ready to start.
@@ -219,7 +214,7 @@
/**
* Checks if the command requires the given Subsystem.
*
- * @param system the system
+ * @param subsystem the subsystem
* @return whether or not the subsystem is required (false if given nullptr)
*/
bool DoesRequire(Subsystem* subsystem) const;
@@ -277,10 +272,10 @@
/**
* Sets the timeout of this command.
*
- * @param timeout the timeout (in seconds)
+ * @param timeout the timeout
* @see IsTimedOut()
*/
- void SetTimeout(double timeout);
+ void SetTimeout(units::second_t timeout);
/**
* Returns whether or not the TimeSinceInitialized() method returns a number
@@ -299,7 +294,7 @@
* message)
* @return True if assert passed, false if assert failed.
*/
- bool AssertUnlocked(const std::string& message);
+ bool AssertUnlocked(std::string_view message);
/**
* Sets the parent of this command. No actual change is made to the group.
@@ -401,7 +396,7 @@
*
* @param name name
*/
- void SetName(const wpi::Twine& name);
+ void SetName(std::string_view name);
/**
* Gets the subsystem name of this Command.
@@ -415,7 +410,7 @@
*
* @param subsystem subsystem name
*/
- void SetSubsystem(const wpi::Twine& subsystem);
+ void SetSubsystem(std::string_view subsystem);
private:
/**
@@ -451,10 +446,10 @@
void StartTiming();
// The time since this command was initialized
- double m_startTime = -1;
+ units::second_t m_startTime = -1_s;
// The time (in seconds) before this command "times out" (-1 if no timeout)
- double m_timeout;
+ units::second_t m_timeout;
// Whether or not this command has been initialized
bool m_initialized = false;
@@ -487,7 +482,7 @@
static int m_commandCounter;
public:
- void InitSendable(SendableBuilder& builder) override;
+ void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroup.h b/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroup.h
index 0275cb5..016f700 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroup.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroup.h
@@ -1,15 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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_view>
#include <vector>
-#include <wpi/Twine.h>
+#include <units/time.h>
#include "frc/commands/Command.h"
#include "frc/commands/CommandGroupEntry.h"
@@ -42,9 +40,9 @@
*
* @param name The name for this command group
*/
- explicit CommandGroup(const wpi::Twine& name);
+ explicit CommandGroup(std::string_view name);
- virtual ~CommandGroup() = default;
+ ~CommandGroup() override = default;
CommandGroup(CommandGroup&&) = default;
CommandGroup& operator=(CommandGroup&&) = default;
@@ -78,9 +76,9 @@
* It is recommended that this method be called in the constructor.
*
* @param command The Command to be added
- * @param timeout The timeout (in seconds)
+ * @param timeout The timeout
*/
- void AddSequential(Command* command, double timeout);
+ void AddSequential(Command* command, units::second_t timeout);
/**
* Adds a new child Command to the group. The Command will be started after
@@ -125,9 +123,9 @@
* It is recommended that this method be called in the constructor.
*
* @param command The command to be added
- * @param timeout The timeout (in seconds)
+ * @param timeout The timeout
*/
- void AddParallel(Command* command, double timeout);
+ void AddParallel(Command* command, units::second_t timeout);
bool IsInterruptible() const;
@@ -137,32 +135,32 @@
/**
* Can be overridden by teams.
*/
- virtual void Initialize();
+ void Initialize() override;
/**
* Can be overridden by teams.
*/
- virtual void Execute();
+ void Execute() override;
/**
* Can be overridden by teams.
*/
- virtual bool IsFinished();
+ bool IsFinished() override;
/**
* Can be overridden by teams.
*/
- virtual void End();
+ void End() override;
/**
* Can be overridden by teams.
*/
- virtual void Interrupted();
+ void Interrupted() override;
- virtual void _Initialize();
- virtual void _Execute();
- virtual void _End();
- virtual void _Interrupted();
+ void _Initialize() override;
+ void _Execute() override;
+ void _End() override;
+ void _Interrupted() override;
private:
void CancelConflicts(Command* command);
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroupEntry.h b/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroupEntry.h
index d1d2264..b6162f3 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroupEntry.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/CommandGroupEntry.h
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 frc {
class Command;
@@ -20,14 +19,15 @@
};
CommandGroupEntry() = default;
- CommandGroupEntry(Command* command, Sequence state, double timeout = -1.0);
+ CommandGroupEntry(Command* command, Sequence state,
+ units::second_t timeout = -1_s);
CommandGroupEntry(CommandGroupEntry&&) = default;
CommandGroupEntry& operator=(CommandGroupEntry&&) = default;
bool IsTimedOut() const;
- double m_timeout = -1.0;
+ units::second_t m_timeout = -1_s;
Command* m_command = nullptr;
Sequence m_state = kSequence_InSequence;
};
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/ConditionalCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/ConditionalCommand.h
index f5cd738..19d6d75 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/ConditionalCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/ConditionalCommand.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* 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.
#pragma once
-#include <wpi/Twine.h>
+#include <string_view>
#include "frc/commands/Command.h"
@@ -49,10 +46,10 @@
* @param onTrue The Command to execute if Condition() returns true
* @param onFalse The Command to execute if Condition() returns false
*/
- ConditionalCommand(const wpi::Twine& name, Command* onTrue,
+ ConditionalCommand(std::string_view name, Command* onTrue,
Command* onFalse = nullptr);
- virtual ~ConditionalCommand() = default;
+ ~ConditionalCommand() override = default;
ConditionalCommand(ConditionalCommand&&) = default;
ConditionalCommand& operator=(ConditionalCommand&&) = default;
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/InstantCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/InstantCommand.h
index 3663b7f..d16b34e 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/InstantCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/InstantCommand.h
@@ -1,15 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
-
-#include <wpi/Twine.h>
+#include <string_view>
#include "frc/commands/Command.h"
#include "frc/commands/Subsystem.h"
@@ -28,7 +24,7 @@
*
* @param name The name for this command
*/
- explicit InstantCommand(const wpi::Twine& name);
+ explicit InstantCommand(std::string_view name);
/**
* Creates a new InstantCommand with the given requirement.
@@ -43,7 +39,7 @@
* @param name The name for this command
* @param subsystem The subsystem that the command requires
*/
- InstantCommand(const wpi::Twine& name, Subsystem& subsystem);
+ InstantCommand(std::string_view name, Subsystem& subsystem);
/**
* Create a command that calls the given function when run.
@@ -66,7 +62,7 @@
* @param name The name of the command.
* @param func The function to run when Initialize() is run.
*/
- InstantCommand(const wpi::Twine& name, std::function<void()> func);
+ InstantCommand(std::string_view name, std::function<void()> func);
/**
* Create a command that calls the given function when run.
@@ -75,11 +71,11 @@
* @param subsystem The subsystems that this command runs on.
* @param func The function to run when Initialize() is run.
*/
- InstantCommand(const wpi::Twine& name, Subsystem& subsystem,
+ InstantCommand(std::string_view name, Subsystem& subsystem,
std::function<void()> func);
InstantCommand() = default;
- virtual ~InstantCommand() = default;
+ ~InstantCommand() override = default;
InstantCommand(InstantCommand&&) = default;
InstantCommand& operator=(InstantCommand&&) = default;
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/PIDCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/PIDCommand.h
index d00ac9b..7eb85ec 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/PIDCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/PIDCommand.h
@@ -1,15 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <memory>
-
-#include <wpi/Twine.h>
+#include <string_view>
#include "frc/PIDController.h"
#include "frc/PIDOutput.h"
@@ -20,25 +16,25 @@
class PIDCommand : public Command, public PIDOutput, public PIDSource {
public:
- PIDCommand(const wpi::Twine& name, double p, double i, double d);
- PIDCommand(const wpi::Twine& name, double p, double i, double d,
+ PIDCommand(std::string_view name, double p, double i, double d);
+ PIDCommand(std::string_view name, double p, double i, double d,
double period);
- PIDCommand(const wpi::Twine& name, double p, double i, double d, double f,
+ PIDCommand(std::string_view name, double p, double i, double d, double f,
double period);
PIDCommand(double p, double i, double d);
PIDCommand(double p, double i, double d, double period);
PIDCommand(double p, double i, double d, double f, double period);
- PIDCommand(const wpi::Twine& name, double p, double i, double d,
+ PIDCommand(std::string_view name, double p, double i, double d,
Subsystem& subsystem);
- PIDCommand(const wpi::Twine& name, double p, double i, double d,
- double period, Subsystem& subsystem);
- PIDCommand(const wpi::Twine& name, double p, double i, double d, double f,
+ PIDCommand(std::string_view name, double p, double i, double d, double period,
+ Subsystem& subsystem);
+ PIDCommand(std::string_view name, double p, double i, double d, double f,
double period, Subsystem& subsystem);
PIDCommand(double p, double i, double d, Subsystem& subsystem);
PIDCommand(double p, double i, double d, double period, Subsystem& subsystem);
PIDCommand(double p, double i, double d, double f, double period,
Subsystem& subsystem);
- virtual ~PIDCommand() = default;
+ ~PIDCommand() override = default;
PIDCommand(PIDCommand&&) = default;
PIDCommand& operator=(PIDCommand&&) = default;
@@ -68,7 +64,7 @@
std::shared_ptr<PIDController> m_controller;
public:
- void InitSendable(SendableBuilder& builder) override;
+ void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/PIDSubsystem.h b/wpilibOldCommands/src/main/native/include/frc/commands/PIDSubsystem.h
index fd9b487..6339c26 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/PIDSubsystem.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/PIDSubsystem.h
@@ -1,15 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <wpi/Twine.h>
+#include <string_view>
#include "frc/PIDController.h"
#include "frc/PIDOutput.h"
@@ -37,7 +33,7 @@
* @param i the integral value
* @param d the derivative value
*/
- PIDSubsystem(const wpi::Twine& name, double p, double i, double d);
+ PIDSubsystem(std::string_view name, double p, double i, double d);
/**
* Instantiates a PIDSubsystem that will use the given P, I, D, and F values.
@@ -48,7 +44,7 @@
* @param d the derivative value
* @param f the feedforward value
*/
- PIDSubsystem(const wpi::Twine& name, double p, double i, double d, double f);
+ PIDSubsystem(std::string_view name, double p, double i, double d, double f);
/**
* Instantiates a PIDSubsystem that will use the given P, I, D, and F values.
@@ -63,7 +59,7 @@
* @param f the feedfoward value
* @param period the time (in seconds) between calculations
*/
- PIDSubsystem(const wpi::Twine& name, double p, double i, double d, double f,
+ PIDSubsystem(std::string_view name, double p, double i, double d, double f,
double period);
/**
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/PrintCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/PrintCommand.h
index 5e987d3..01d0d4b 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/PrintCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/PrintCommand.h
@@ -1,15 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <wpi/Twine.h>
+#include <string_view>
#include "frc/commands/InstantCommand.h"
@@ -17,14 +13,14 @@
class PrintCommand : public InstantCommand {
public:
- explicit PrintCommand(const wpi::Twine& message);
- virtual ~PrintCommand() = default;
+ explicit PrintCommand(std::string_view message);
+ ~PrintCommand() override = default;
PrintCommand(PrintCommand&&) = default;
PrintCommand& operator=(PrintCommand&&) = default;
protected:
- virtual void Initialize();
+ void Initialize() override;
private:
std::string m_message;
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h b/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h
index d15ea39..ad82f63 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h
@@ -1,17 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <memory>
-#include "frc/ErrorBase.h"
-#include "frc/smartdashboard/Sendable.h"
-#include "frc/smartdashboard/SendableHelper.h"
+#include <networktables/NTSendable.h>
+#include <wpi/sendable/SendableHelper.h>
namespace frc {
@@ -19,9 +15,7 @@
class Command;
class Subsystem;
-class Scheduler : public ErrorBase,
- public Sendable,
- public SendableHelper<Scheduler> {
+class Scheduler : public nt::NTSendable, public wpi::SendableHelper<Scheduler> {
public:
/**
* Returns the Scheduler, creating it if one does not exist.
@@ -48,7 +42,7 @@
*
* All Subsystems should call this.
*
- * @param system the system
+ * @param subsystem the system
*/
void RegisterSubsystem(Subsystem* subsystem);
@@ -84,7 +78,7 @@
void SetEnabled(bool enabled);
- void InitSendable(SendableBuilder& builder) override;
+ void InitSendable(nt::NTSendableBuilder& builder) override;
private:
Scheduler();
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/StartCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/StartCommand.h
index 5062f92..a58c058 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/StartCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/StartCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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
@@ -14,13 +11,13 @@
class StartCommand : public InstantCommand {
public:
explicit StartCommand(Command* commandToStart);
- virtual ~StartCommand() = default;
+ ~StartCommand() override = default;
StartCommand(StartCommand&&) = default;
StartCommand& operator=(StartCommand&&) = default;
protected:
- virtual void Initialize();
+ void Initialize() override;
private:
Command* m_commandToFork;
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h b/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h
index 2637dd0..8c18d5c 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h
@@ -1,29 +1,21 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <memory>
#include <string>
+#include <string_view>
-#include <wpi/StringRef.h>
-#include <wpi/Twine.h>
-
-#include "frc/ErrorBase.h"
-#include "frc/smartdashboard/Sendable.h"
-#include "frc/smartdashboard/SendableHelper.h"
+#include <wpi/sendable/Sendable.h>
+#include <wpi/sendable/SendableHelper.h>
namespace frc {
class Command;
-class Subsystem : public ErrorBase,
- public Sendable,
- public SendableHelper<Subsystem> {
+class Subsystem : public wpi::Sendable, public wpi::SendableHelper<Subsystem> {
friend class Scheduler;
public:
@@ -32,7 +24,7 @@
*
* @param name the name of the subsystem
*/
- explicit Subsystem(const wpi::Twine& name);
+ explicit Subsystem(std::string_view name);
Subsystem(Subsystem&&) = default;
Subsystem& operator=(Subsystem&&) = default;
@@ -60,7 +52,7 @@
*
* @return the default command name
*/
- wpi::StringRef GetDefaultCommandName();
+ std::string GetDefaultCommandName();
/**
* Sets the current command.
@@ -81,7 +73,7 @@
*
* @return the current command name
*/
- wpi::StringRef GetCurrentCommandName() const;
+ std::string GetCurrentCommandName() const;
/**
* When the run method of the scheduler is called this method will be called.
@@ -112,7 +104,7 @@
*
* @param name name
*/
- void SetName(const wpi::Twine& name);
+ void SetName(std::string_view name);
/**
* Gets the subsystem name of this Subsystem.
@@ -126,7 +118,7 @@
*
* @param subsystem subsystem name
*/
- void SetSubsystem(const wpi::Twine& subsystem);
+ void SetSubsystem(std::string_view subsystem);
/**
* Associate a Sendable with this Subsystem.
@@ -135,7 +127,7 @@
* @param name name to give child
* @param child sendable
*/
- void AddChild(const wpi::Twine& name, std::shared_ptr<Sendable> child);
+ void AddChild(std::string_view name, std::shared_ptr<wpi::Sendable> child);
/**
* Associate a Sendable with this Subsystem.
@@ -144,7 +136,7 @@
* @param name name to give child
* @param child sendable
*/
- void AddChild(const wpi::Twine& name, Sendable* child);
+ void AddChild(std::string_view name, wpi::Sendable* child);
/**
* Associate a Sendable with this Subsystem.
@@ -153,28 +145,28 @@
* @param name name to give child
* @param child sendable
*/
- void AddChild(const wpi::Twine& name, Sendable& child);
+ void AddChild(std::string_view name, wpi::Sendable& child);
/**
- * Associate a {@link Sendable} with this Subsystem.
+ * Associate a Sendable with this Subsystem.
*
* @param child sendable
*/
- void AddChild(std::shared_ptr<Sendable> child);
+ void AddChild(std::shared_ptr<wpi::Sendable> child);
/**
- * Associate a {@link Sendable} with this Subsystem.
+ * Associate a Sendable with this Subsystem.
*
* @param child sendable
*/
- void AddChild(Sendable* child);
+ void AddChild(wpi::Sendable* child);
/**
- * Associate a {@link Sendable} with this Subsystem.
+ * Associate a Sendable with this Subsystem.
*
* @param child sendable
*/
- void AddChild(Sendable& child);
+ void AddChild(wpi::Sendable& child);
private:
/**
@@ -193,7 +185,7 @@
bool m_initializedDefaultCommand = false;
public:
- void InitSendable(SendableBuilder& builder) override;
+ void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/TimedCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/TimedCommand.h
index 16f3348..17eb4f4 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/TimedCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/TimedCommand.h
@@ -1,13 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <wpi/Twine.h>
+#include <string_view>
+
+#include <units/time.h>
#include "frc/commands/Command.h"
@@ -24,35 +23,36 @@
* Creates a new TimedCommand with the given name and timeout.
*
* @param name the name of the command
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
*/
- TimedCommand(const wpi::Twine& name, double timeout);
+ TimedCommand(std::string_view name, units::second_t timeout);
/**
* Creates a new WaitCommand with the given timeout.
*
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
*/
- explicit TimedCommand(double timeout);
+ explicit TimedCommand(units::second_t timeout);
/**
* Creates a new TimedCommand with the given name and timeout.
*
* @param name the name of the command
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
* @param subsystem the subsystem that the command requires
*/
- TimedCommand(const wpi::Twine& name, double timeout, Subsystem& subsystem);
+ TimedCommand(std::string_view name, units::second_t timeout,
+ Subsystem& subsystem);
/**
* Creates a new WaitCommand with the given timeout.
*
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
* @param subsystem the subsystem that the command requires
*/
- TimedCommand(double timeout, Subsystem& subsystem);
+ TimedCommand(units::second_t timeout, Subsystem& subsystem);
- virtual ~TimedCommand() = default;
+ ~TimedCommand() override = default;
TimedCommand(TimedCommand&&) = default;
TimedCommand& operator=(TimedCommand&&) = default;
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/WaitCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/WaitCommand.h
index 794b0f7..3902fb6 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/WaitCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/WaitCommand.h
@@ -1,13 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <units/time.h>
#include "frc/commands/TimedCommand.h"
@@ -18,19 +17,19 @@
/**
* Creates a new WaitCommand with the given name and timeout.
*
- * @param name the name of the command
- * @param timeout the time (in seconds) before this command "times out"
+ * @param timeout the time before this command "times out"
*/
- explicit WaitCommand(double timeout);
+ explicit WaitCommand(units::second_t timeout);
/**
* Creates a new WaitCommand with the given timeout.
*
- * @param timeout the time (in seconds) before this command "times out"
+ * @param name the name of the command
+ * @param timeout the time before this command "times out"
*/
- WaitCommand(const wpi::Twine& name, double timeout);
+ WaitCommand(std::string_view name, units::second_t timeout);
- virtual ~WaitCommand() = default;
+ ~WaitCommand() override = default;
WaitCommand(WaitCommand&&) = default;
WaitCommand& operator=(WaitCommand&&) = default;
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/WaitForChildren.h b/wpilibOldCommands/src/main/native/include/frc/commands/WaitForChildren.h
index cd1f85a..b92d78d 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/WaitForChildren.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/WaitForChildren.h
@@ -1,13 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <units/time.h>
#include "frc/commands/Command.h"
@@ -15,15 +14,15 @@
class WaitForChildren : public Command {
public:
- explicit WaitForChildren(double timeout);
- WaitForChildren(const wpi::Twine& name, double timeout);
- virtual ~WaitForChildren() = default;
+ explicit WaitForChildren(units::second_t timeout);
+ WaitForChildren(std::string_view name, units::second_t timeout);
+ ~WaitForChildren() override = default;
WaitForChildren(WaitForChildren&&) = default;
WaitForChildren& operator=(WaitForChildren&&) = default;
protected:
- virtual bool IsFinished();
+ bool IsFinished() override;
};
} // namespace frc
diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/WaitUntilCommand.h b/wpilibOldCommands/src/main/native/include/frc/commands/WaitUntilCommand.h
index b2f1ffe..715e7bb 100644
--- a/wpilibOldCommands/src/main/native/include/frc/commands/WaitUntilCommand.h
+++ b/wpilibOldCommands/src/main/native/include/frc/commands/WaitUntilCommand.h
@@ -1,13 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2011-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 <units/time.h>
#include "frc/commands/Command.h"
@@ -23,11 +22,11 @@
*
* @see CommandGroup
*/
- explicit WaitUntilCommand(double time);
+ explicit WaitUntilCommand(units::second_t time);
- WaitUntilCommand(const wpi::Twine& name, double time);
+ WaitUntilCommand(std::string_view name, units::second_t time);
- virtual ~WaitUntilCommand() = default;
+ ~WaitUntilCommand() override = default;
WaitUntilCommand(WaitUntilCommand&&) = default;
WaitUntilCommand& operator=(WaitUntilCommand&&) = default;
@@ -36,10 +35,10 @@
/**
* Check if we've reached the actual finish time.
*/
- virtual bool IsFinished();
+ bool IsFinished() override;
private:
- double m_time;
+ units::second_t m_time;
};
} // namespace frc