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/wpilibcIntegrationTests/src/main/native/cpp/AnalogLoopTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/AnalogLoopTest.cpp
index 40fd87c..3540095 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/AnalogLoopTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/AnalogLoopTest.cpp
@@ -1,53 +1,35 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <units/time.h>
#include "TestBench.h"
#include "frc/AnalogInput.h"
#include "frc/AnalogOutput.h"
#include "frc/AnalogTrigger.h"
+#include "frc/AsynchronousInterrupt.h"
#include "frc/Counter.h"
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
-
-static const double kDelayTime = 0.01;
-
-/**
- * A fixture with an analog input and an analog output wired together
- */
-class AnalogLoopTest : public testing::Test {
- protected:
- AnalogInput* m_input;
- AnalogOutput* m_output;
-
- void SetUp() override {
- m_input = new AnalogInput(TestBench::kFakeAnalogOutputChannel);
- m_output = new AnalogOutput(TestBench::kAnalogOutputChannel);
- }
-
- void TearDown() override {
- delete m_input;
- delete m_output;
- }
-};
+static constexpr auto kDelayTime = 10_ms;
/**
* Test analog inputs and outputs by setting one and making sure the other
* matches.
*/
-TEST_F(AnalogLoopTest, AnalogInputWorks) {
+TEST(AnalogLoopTest, AnalogInputWorks) {
+ frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
+ frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
+
// Set the output voltage and check if the input measures the same voltage
for (int32_t i = 0; i < 50; i++) {
- m_output->SetVoltage(i / 10.0);
+ output.SetVoltage(i / 10.0);
- Wait(kDelayTime);
+ frc::Wait(kDelayTime);
- EXPECT_NEAR(m_output->GetVoltage(), m_input->GetVoltage(), 0.01);
+ EXPECT_NEAR(output.GetVoltage(), input.GetVoltage(), 0.01);
}
}
@@ -55,26 +37,29 @@
* Test if we can use an analog trigger to check if the output is within a
* range correctly.
*/
-TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
- AnalogTrigger trigger(m_input);
+TEST(AnalogLoopTest, AnalogTriggerWorks) {
+ frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
+ frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
+
+ frc::AnalogTrigger trigger{&input};
trigger.SetLimitsVoltage(2.0, 3.0);
- m_output->SetVoltage(1.0);
- Wait(kDelayTime);
+ output.SetVoltage(1.0);
+ frc::Wait(kDelayTime);
EXPECT_FALSE(trigger.GetInWindow())
<< "Analog trigger is in the window (2V, 3V)";
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
- m_output->SetVoltage(2.5);
- Wait(kDelayTime);
+ output.SetVoltage(2.5);
+ frc::Wait(kDelayTime);
EXPECT_TRUE(trigger.GetInWindow())
<< "Analog trigger is not in the window (2V, 3V)";
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
- m_output->SetVoltage(4.0);
- Wait(kDelayTime);
+ output.SetVoltage(4.0);
+ frc::Wait(kDelayTime);
EXPECT_FALSE(trigger.GetInWindow())
<< "Analog trigger is in the window (2V, 3V)";
@@ -85,18 +70,21 @@
* Test if we can count the right number of ticks from an analog trigger with
* a counter.
*/
-TEST_F(AnalogLoopTest, AnalogTriggerCounterWorks) {
- AnalogTrigger trigger(m_input);
+TEST(AnalogLoopTest, AnalogTriggerCounterWorks) {
+ frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
+ frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
+
+ frc::AnalogTrigger trigger{&input};
trigger.SetLimitsVoltage(2.0, 3.0);
- Counter counter(trigger);
+ frc::Counter counter{trigger};
// Turn the analog output low and high 50 times
for (int32_t i = 0; i < 50; i++) {
- m_output->SetVoltage(1.0);
- Wait(kDelayTime);
- m_output->SetVoltage(4.0);
- Wait(kDelayTime);
+ output.SetVoltage(1.0);
+ frc::Wait(kDelayTime);
+ output.SetVoltage(4.0);
+ frc::Wait(kDelayTime);
}
// The counter should be 50
@@ -104,28 +92,30 @@
<< "Analog trigger counter did not count 50 ticks";
}
-static void InterruptHandler(uint32_t interruptAssertedMask, void* param) {
- *reinterpret_cast<int32_t*>(param) = 12345;
-}
+TEST(AnalogLoopTest, AsynchronusInterruptWorks) {
+ frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
+ frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
-TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
int32_t param = 0;
- AnalogTrigger trigger(m_input);
+ frc::AnalogTrigger trigger{&input};
trigger.SetLimitsVoltage(2.0, 3.0);
// Given an interrupt handler that sets an int32_t to 12345
- std::shared_ptr<AnalogTriggerOutput> triggerOutput =
- trigger.CreateOutput(AnalogTriggerType::kState);
- triggerOutput->RequestInterrupts(InterruptHandler, ¶m);
- triggerOutput->EnableInterrupts();
+ std::shared_ptr<frc::AnalogTriggerOutput> triggerOutput =
+ trigger.CreateOutput(frc::AnalogTriggerType::kState);
+
+ frc::AsynchronousInterrupt interrupt{triggerOutput,
+ [&](auto a, auto b) { param = 12345; }};
+
+ interrupt.Enable();
// If the analog output moves from below to above the window
- m_output->SetVoltage(0.0);
- Wait(kDelayTime);
- m_output->SetVoltage(5.0);
- triggerOutput->CancelInterrupts();
-
+ output.SetVoltage(0.0);
+ frc::Wait(kDelayTime);
+ output.SetVoltage(5.0);
// Then the int32_t should be 12345
- Wait(kDelayTime);
+ frc::Wait(kDelayTime);
+ interrupt.Disable();
+
EXPECT_EQ(12345, param) << "The interrupt did not run.";
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/AnalogPotentiometerTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/AnalogPotentiometerTest.cpp
index 4497051..107310f 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/AnalogPotentiometerTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/AnalogPotentiometerTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/AnalogPotentiometer.h" // NOLINT(build/include_order)
@@ -13,38 +10,25 @@
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
+static constexpr double kScale = 270.0;
+static constexpr double kAngle = 180.0;
-static const double kScale = 270.0;
-static const double kAngle = 180.0;
+TEST(AnalogPotentiometerTest, InitialSettings) {
+ frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
+ frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
-class AnalogPotentiometerTest : public testing::Test {
- protected:
- AnalogOutput* m_fakePot;
- AnalogPotentiometer* m_pot;
-
- void SetUp() override {
- m_fakePot = new AnalogOutput(TestBench::kAnalogOutputChannel);
- m_pot =
- new AnalogPotentiometer(TestBench::kFakeAnalogOutputChannel, kScale);
- }
-
- void TearDown() override {
- delete m_fakePot;
- delete m_pot;
- }
-};
-
-TEST_F(AnalogPotentiometerTest, TestInitialSettings) {
- m_fakePot->SetVoltage(0.0);
- Wait(0.1);
- EXPECT_NEAR(0.0, m_pot->Get(), 5.0)
+ m_fakePot.SetVoltage(0.0);
+ frc::Wait(100_ms);
+ EXPECT_NEAR(0.0, m_pot.Get(), 5.0)
<< "The potentiometer did not initialize to 0.";
}
-TEST_F(AnalogPotentiometerTest, TestRangeValues) {
- m_fakePot->SetVoltage(kAngle / kScale * RobotController::GetVoltage5V());
- Wait(0.1);
- EXPECT_NEAR(kAngle, m_pot->Get(), 2.0)
+TEST(AnalogPotentiometerTest, RangeValues) {
+ frc::AnalogOutput m_fakePot{TestBench::kAnalogOutputChannel};
+ frc::AnalogPotentiometer m_pot{TestBench::kFakeAnalogOutputChannel, kScale};
+
+ m_fakePot.SetVoltage(kAngle / kScale * frc::RobotController::GetVoltage5V());
+ frc::Wait(100_ms);
+ EXPECT_NEAR(kAngle, m_pot.Get(), 2.0)
<< "The potentiometer did not measure the correct angle.";
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/BuiltInAccelerometerTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/BuiltInAccelerometerTest.cpp
index bfb5f21..00f5f00 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/BuiltInAccelerometerTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/BuiltInAccelerometerTest.cpp
@@ -1,28 +1,24 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/BuiltInAccelerometer.h" // NOLINT(build/include_order)
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
-
static constexpr double kAccelerationTolerance = 0.1;
+
/**
* There's not much we can automatically test with the on-board accelerometer,
* but checking for gravity is probably good enough to tell that it's working.
*/
TEST(BuiltInAccelerometerTest, Accelerometer) {
- BuiltInAccelerometer accelerometer;
+ frc::BuiltInAccelerometer accelerometer;
- /* The testbench sometimes shakes a little from a previous test. Give it
- some time. */
- Wait(1.0);
+ // The testbench sometimes shakes a little from a previous test. Give it some
+ // time.
+ frc::Wait(1_s);
ASSERT_NEAR(0.0, accelerometer.GetX(), kAccelerationTolerance);
ASSERT_NEAR(1.0, accelerometer.GetY(), kAccelerationTolerance);
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp
index a3ddbd2..553fc96 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp
@@ -1,59 +1,38 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/Counter.h" // NOLINT(build/include_order)
+#include <units/time.h>
+
#include "TestBench.h"
-#include "frc/Jaguar.h"
-#include "frc/Talon.h"
#include "frc/Timer.h"
-#include "frc/Victor.h"
+#include "frc/motorcontrol/Jaguar.h"
+#include "frc/motorcontrol/Talon.h"
+#include "frc/motorcontrol/Victor.h"
#include "gtest/gtest.h"
-using namespace frc;
+static constexpr auto kMotorDelay = 2.5_s;
-static const double kMotorDelay = 2.5;
-
-static const double kMaxPeriod = 2.0;
+static constexpr auto kMaxPeriod = 2_s;
class CounterTest : public testing::Test {
protected:
- Counter* m_talonCounter;
- Counter* m_victorCounter;
- Counter* m_jaguarCounter;
- Talon* m_talon;
- Victor* m_victor;
- Jaguar* m_jaguar;
-
- void SetUp() override {
- m_talonCounter = new Counter(TestBench::kTalonEncoderChannelA);
- m_victorCounter = new Counter(TestBench::kVictorEncoderChannelA);
- m_jaguarCounter = new Counter(TestBench::kJaguarEncoderChannelA);
- m_victor = new Victor(TestBench::kVictorChannel);
- m_talon = new Talon(TestBench::kTalonChannel);
- m_jaguar = new Jaguar(TestBench::kJaguarChannel);
- }
-
- void TearDown() override {
- delete m_talonCounter;
- delete m_victorCounter;
- delete m_jaguarCounter;
- delete m_victor;
- delete m_talon;
- delete m_jaguar;
- }
+ frc::Counter m_talonCounter{TestBench::kTalonEncoderChannelA};
+ frc::Counter m_victorCounter{TestBench::kVictorEncoderChannelA};
+ frc::Counter m_jaguarCounter{TestBench::kJaguarEncoderChannelA};
+ frc::Talon m_talon{TestBench::kVictorChannel};
+ frc::Victor m_victor{TestBench::kTalonChannel};
+ frc::Jaguar m_jaguar{TestBench::kJaguarChannel};
void Reset() {
- m_talonCounter->Reset();
- m_victorCounter->Reset();
- m_jaguarCounter->Reset();
- m_talon->Set(0.0);
- m_victor->Set(0.0);
- m_jaguar->Set(0.0);
+ m_talonCounter.Reset();
+ m_victorCounter.Reset();
+ m_jaguarCounter.Reset();
+ m_talon.Set(0.0);
+ m_victor.Set(0.0);
+ m_jaguar.Set(0.0);
}
};
@@ -65,17 +44,17 @@
Reset();
/* Run the motor forward and determine if the counter is counting. */
- m_talon->Set(1.0);
- Wait(0.5);
+ m_talon.Set(1.0);
+ frc::Wait(0.5_s);
- EXPECT_NE(0.0, m_talonCounter->Get()) << "The counter did not count (talon)";
+ EXPECT_NE(0.0, m_talonCounter.Get()) << "The counter did not count (talon)";
/* Set the motor to 0 and determine if the counter resets to 0. */
- m_talon->Set(0.0);
- Wait(0.5);
- m_talonCounter->Reset();
+ m_talon.Set(0.0);
+ frc::Wait(0.5_s);
+ m_talonCounter.Reset();
- EXPECT_FLOAT_EQ(0.0, m_talonCounter->Get())
+ EXPECT_FLOAT_EQ(0.0, m_talonCounter.Get())
<< "The counter did not restart to 0 (talon)";
}
@@ -83,18 +62,17 @@
Reset();
/* Run the motor forward and determine if the counter is counting. */
- m_victor->Set(1.0);
- Wait(0.5);
+ m_victor.Set(1.0);
+ frc::Wait(0.5_s);
- EXPECT_NE(0.0, m_victorCounter->Get())
- << "The counter did not count (victor)";
+ EXPECT_NE(0.0, m_victorCounter.Get()) << "The counter did not count (victor)";
/* Set the motor to 0 and determine if the counter resets to 0. */
- m_victor->Set(0.0);
- Wait(0.5);
- m_victorCounter->Reset();
+ m_victor.Set(0.0);
+ frc::Wait(0.5_s);
+ m_victorCounter.Reset();
- EXPECT_FLOAT_EQ(0.0, m_victorCounter->Get())
+ EXPECT_FLOAT_EQ(0.0, m_victorCounter.Get())
<< "The counter did not restart to 0 (jaguar)";
}
@@ -102,18 +80,17 @@
Reset();
/* Run the motor forward and determine if the counter is counting. */
- m_jaguar->Set(1.0);
- Wait(0.5);
+ m_jaguar.Set(1.0);
+ frc::Wait(0.5_s);
- EXPECT_NE(0.0, m_jaguarCounter->Get())
- << "The counter did not count (jaguar)";
+ EXPECT_NE(0.0, m_jaguarCounter.Get()) << "The counter did not count (jaguar)";
/* Set the motor to 0 and determine if the counter resets to 0. */
- m_jaguar->Set(0.0);
- Wait(0.5);
- m_jaguarCounter->Reset();
+ m_jaguar.Set(0.0);
+ frc::Wait(0.5_s);
+ m_jaguarCounter.Reset();
- EXPECT_FLOAT_EQ(0.0, m_jaguarCounter->Get())
+ EXPECT_FLOAT_EQ(0.0, m_jaguarCounter.Get())
<< "The counter did not restart to 0 (jaguar)";
}
@@ -125,17 +102,17 @@
Reset();
/* Set the Max Period of the counter and run the motor */
- m_talonCounter->SetMaxPeriod(kMaxPeriod);
- m_talon->Set(1.0);
- Wait(0.5);
+ m_talonCounter.SetMaxPeriod(kMaxPeriod);
+ m_talon.Set(1.0);
+ frc::Wait(0.5_s);
- EXPECT_FALSE(m_talonCounter->GetStopped()) << "The counter did not count.";
+ EXPECT_FALSE(m_talonCounter.GetStopped()) << "The counter did not count.";
/* Stop the motor and wait until the Max Period is exceeded */
- m_talon->Set(0.0);
- Wait(kMotorDelay);
+ m_talon.Set(0.0);
+ frc::Wait(kMotorDelay);
- EXPECT_TRUE(m_talonCounter->GetStopped())
+ EXPECT_TRUE(m_talonCounter.GetStopped())
<< "The counter did not stop counting.";
}
@@ -143,17 +120,17 @@
Reset();
/* Set the Max Period of the counter and run the motor */
- m_victorCounter->SetMaxPeriod(kMaxPeriod);
- m_victor->Set(1.0);
- Wait(0.5);
+ m_victorCounter.SetMaxPeriod(kMaxPeriod);
+ m_victor.Set(1.0);
+ frc::Wait(0.5_s);
- EXPECT_FALSE(m_victorCounter->GetStopped()) << "The counter did not count.";
+ EXPECT_FALSE(m_victorCounter.GetStopped()) << "The counter did not count.";
/* Stop the motor and wait until the Max Period is exceeded */
- m_victor->Set(0.0);
- Wait(kMotorDelay);
+ m_victor.Set(0.0);
+ frc::Wait(kMotorDelay);
- EXPECT_TRUE(m_victorCounter->GetStopped())
+ EXPECT_TRUE(m_victorCounter.GetStopped())
<< "The counter did not stop counting.";
}
@@ -161,16 +138,16 @@
Reset();
/* Set the Max Period of the counter and run the motor */
- m_jaguarCounter->SetMaxPeriod(kMaxPeriod);
- m_jaguar->Set(1.0);
- Wait(0.5);
+ m_jaguarCounter.SetMaxPeriod(kMaxPeriod);
+ m_jaguar.Set(1.0);
+ frc::Wait(0.5_s);
- EXPECT_FALSE(m_jaguarCounter->GetStopped()) << "The counter did not count.";
+ EXPECT_FALSE(m_jaguarCounter.GetStopped()) << "The counter did not count.";
/* Stop the motor and wait until the Max Period is exceeded */
- m_jaguar->Set(0.0);
- Wait(kMotorDelay);
+ m_jaguar.Set(0.0);
+ frc::Wait(kMotorDelay);
- EXPECT_TRUE(m_jaguarCounter->GetStopped())
+ EXPECT_TRUE(m_jaguarCounter.GetStopped())
<< "The counter did not stop counting.";
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/DIOLoopTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/DIOLoopTest.cpp
index 10b64d5..e230310 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/DIOLoopTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/DIOLoopTest.cpp
@@ -1,28 +1,30 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/DigitalInput.h" // NOLINT(build/include_order)
#include "frc/DigitalOutput.h" // NOLINT(build/include_order)
+#include <units/math.h>
+#include <units/time.h>
+
#include "TestBench.h"
+#include "frc/AsynchronousInterrupt.h"
#include "frc/Counter.h"
-#include "frc/InterruptableSensorBase.h"
+#include "frc/SynchronousInterrupt.h"
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
+#define EXPECT_NEAR_UNITS(val1, val2, eps) \
+ EXPECT_LE(units::math::abs(val1 - val2), eps)
-static const double kCounterTime = 0.001;
+static constexpr auto kCounterTime = 1_ms;
-static const double kDelayTime = 0.1;
+static constexpr auto kDelayTime = 100_ms;
-static const double kSynchronousInterruptTime = 2.0;
-static const double kSynchronousInterruptTimeTolerance = 0.01;
+static constexpr auto kSynchronousInterruptTime = 2_s;
+static constexpr auto kSynchronousInterruptTimeTolerance = 10_ms;
/**
* A fixture with a digital input and a digital output physically wired
@@ -30,20 +32,10 @@
*/
class DIOLoopTest : public testing::Test {
protected:
- DigitalInput* m_input;
- DigitalOutput* m_output;
+ frc::DigitalInput m_input{TestBench::kLoop1InputChannel};
+ frc::DigitalOutput m_output{TestBench::kLoop1OutputChannel};
- void SetUp() override {
- m_input = new DigitalInput(TestBench::kLoop1InputChannel);
- m_output = new DigitalOutput(TestBench::kLoop1OutputChannel);
- }
-
- void TearDown() override {
- delete m_input;
- delete m_output;
- }
-
- void Reset() { m_output->Set(false); }
+ void Reset() { m_output.Set(false); }
};
/**
@@ -53,15 +45,15 @@
TEST_F(DIOLoopTest, Loop) {
Reset();
- m_output->Set(false);
- Wait(kDelayTime);
- EXPECT_FALSE(m_input->Get()) << "The digital output was turned off, but "
- << "the digital input is on.";
+ m_output.Set(false);
+ frc::Wait(kDelayTime);
+ EXPECT_FALSE(m_input.Get()) << "The digital output was turned off, but "
+ << "the digital input is on.";
- m_output->Set(true);
- Wait(kDelayTime);
- EXPECT_TRUE(m_input->Get()) << "The digital output was turned on, but "
- << "the digital input is off.";
+ m_output.Set(true);
+ frc::Wait(kDelayTime);
+ EXPECT_TRUE(m_input.Get()) << "The digital output was turned on, but "
+ << "the digital input is off.";
}
/**
* Tests to see if the DIO PWM functionality works.
@@ -69,43 +61,43 @@
TEST_F(DIOLoopTest, DIOPWM) {
Reset();
- m_output->Set(false);
- Wait(kDelayTime);
- EXPECT_FALSE(m_input->Get()) << "The digital output was turned off, but "
- << "the digital input is on.";
+ m_output.Set(false);
+ frc::Wait(kDelayTime);
+ EXPECT_FALSE(m_input.Get()) << "The digital output was turned off, but "
+ << "the digital input is on.";
// Set frequency to 2.0 Hz
- m_output->SetPWMRate(2.0);
+ m_output.SetPWMRate(2.0);
// Enable PWM, but leave it off
- m_output->EnablePWM(0.0);
- Wait(0.5);
- m_output->UpdateDutyCycle(0.5);
- m_input->RequestInterrupts();
- m_input->SetUpSourceEdge(false, true);
- InterruptableSensorBase::WaitResult result =
- m_input->WaitForInterrupt(3.0, true);
+ m_output.EnablePWM(0.0);
+ frc::Wait(0.5_s);
+ m_output.UpdateDutyCycle(0.5);
+ frc::SynchronousInterrupt interrupt{m_output};
+ interrupt.SetInterruptEdges(false, true);
+ frc::SynchronousInterrupt::WaitResult result =
+ interrupt.WaitForInterrupt(3_s, true);
- Wait(0.5);
- bool firstCycle = m_input->Get();
- Wait(0.5);
- bool secondCycle = m_input->Get();
- Wait(0.5);
- bool thirdCycle = m_input->Get();
- Wait(0.5);
- bool forthCycle = m_input->Get();
- Wait(0.5);
- bool fifthCycle = m_input->Get();
- Wait(0.5);
- bool sixthCycle = m_input->Get();
- Wait(0.5);
- bool seventhCycle = m_input->Get();
- m_output->DisablePWM();
- Wait(0.5);
- bool firstAfterStop = m_input->Get();
- Wait(0.5);
- bool secondAfterStop = m_input->Get();
+ frc::Wait(0.5_s);
+ bool firstCycle = m_input.Get();
+ frc::Wait(0.5_s);
+ bool secondCycle = m_input.Get();
+ frc::Wait(0.5_s);
+ bool thirdCycle = m_input.Get();
+ frc::Wait(0.5_s);
+ bool forthCycle = m_input.Get();
+ frc::Wait(0.5_s);
+ bool fifthCycle = m_input.Get();
+ frc::Wait(0.5_s);
+ bool sixthCycle = m_input.Get();
+ frc::Wait(0.5_s);
+ bool seventhCycle = m_input.Get();
+ m_output.DisablePWM();
+ frc::Wait(0.5_s);
+ bool firstAfterStop = m_input.Get();
+ frc::Wait(0.5_s);
+ bool secondAfterStop = m_input.Get();
- EXPECT_EQ(InterruptableSensorBase::WaitResult::kFallingEdge, result)
+ EXPECT_EQ(frc::SynchronousInterrupt::WaitResult::kFallingEdge, result)
<< "WaitForInterrupt was not falling.";
EXPECT_FALSE(firstCycle) << "Input not low after first delay";
@@ -126,63 +118,61 @@
TEST_F(DIOLoopTest, FakeCounter) {
Reset();
- Counter counter(m_input);
+ frc::Counter counter{&m_input};
EXPECT_EQ(0, counter.Get()) << "Counter did not initialize to 0.";
/* Count 100 ticks. The counter value should be 100 after this loop. */
- for (int32_t i = 0; i < 100; i++) {
- m_output->Set(true);
- Wait(kCounterTime);
- m_output->Set(false);
- Wait(kCounterTime);
+ for (int32_t i = 0; i < 100; ++i) {
+ m_output.Set(true);
+ frc::Wait(kCounterTime);
+ m_output.Set(false);
+ frc::Wait(kCounterTime);
}
EXPECT_EQ(100, counter.Get()) << "Counter did not count up to 100.";
}
-static void InterruptHandler(uint32_t interruptAssertedMask, void* param) {
- *reinterpret_cast<int32_t*>(param) = 12345;
-}
-
TEST_F(DIOLoopTest, AsynchronousInterruptWorks) {
+ Reset();
+
int32_t param = 0;
- // Given an interrupt handler that sets an int32_t to 12345
- m_input->RequestInterrupts(InterruptHandler, ¶m);
- m_input->EnableInterrupts();
+ frc::AsynchronousInterrupt interrupt(m_input,
+ [&](auto a, auto b) { param = 12345; });
+ interrupt.Enable();
// If the voltage rises
- m_output->Set(false);
- m_output->Set(true);
- m_input->CancelInterrupts();
+ m_output.Set(false);
+ m_output.Set(true);
// Then the int32_t should be 12345
- Wait(kDelayTime);
+ frc::Wait(kDelayTime);
+
+ interrupt.Disable();
+
EXPECT_EQ(12345, param) << "The interrupt did not run.";
}
-static void* InterruptTriggerer(void* data) {
- DigitalOutput* output = static_cast<DigitalOutput*>(data);
- output->Set(false);
- Wait(kSynchronousInterruptTime);
- output->Set(true);
- return nullptr;
-}
-
TEST_F(DIOLoopTest, SynchronousInterruptWorks) {
- // Given a synchronous interrupt
- m_input->RequestInterrupts();
+ Reset();
- // If we have another thread trigger the interrupt in a few seconds
- pthread_t interruptTriggererLoop;
- pthread_create(&interruptTriggererLoop, nullptr, InterruptTriggerer,
- m_output);
+ // Given a synchronous interrupt
+ frc::SynchronousInterrupt interrupt(m_input);
+
+ std::thread thr([this]() {
+ m_output.Set(false);
+ frc::Wait(kSynchronousInterruptTime);
+ m_output.Set(true);
+ });
// Then this thread should pause and resume after that number of seconds
- Timer timer;
+ frc::Timer timer;
timer.Start();
- m_input->WaitForInterrupt(kSynchronousInterruptTime + 1.0);
- EXPECT_NEAR(kSynchronousInterruptTime, timer.Get(),
- kSynchronousInterruptTimeTolerance);
+ interrupt.WaitForInterrupt(kSynchronousInterruptTime + 1_s);
+ auto time = timer.Get().value();
+ if (thr.joinable())
+ thr.join();
+ EXPECT_NEAR(kSynchronousInterruptTime.value(), time,
+ kSynchronousInterruptTimeTolerance.value());
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/DMATest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/DMATest.cpp
new file mode 100644
index 0000000..39116db
--- /dev/null
+++ b/wpilibcIntegrationTests/src/main/native/cpp/DMATest.cpp
@@ -0,0 +1,155 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/AnalogInput.h>
+#include <frc/AnalogOutput.h>
+#include <frc/DigitalOutput.h>
+#include <frc/Timer.h>
+#include <frc/motorcontrol/Jaguar.h>
+
+#include "TestBench.h"
+#include "frc/DMA.h"
+#include "frc/DMASample.h"
+#include "gtest/gtest.h"
+
+using namespace frc;
+
+static constexpr auto kDelayTime = 100_ms;
+
+class DMATest : public testing::Test {
+ protected:
+ AnalogInput m_analogInput{TestBench::kAnalogOutputChannel};
+ AnalogOutput m_analogOutput{TestBench::kFakeAnalogOutputChannel};
+ DigitalOutput m_manualTrigger{TestBench::kLoop1InputChannel};
+ Jaguar m_pwm{TestBench::kFakePwmOutput};
+ DMA m_dma;
+
+ void SetUp() override {
+ m_dma.AddAnalogInput(&m_analogInput);
+ m_dma.SetExternalTrigger(&m_manualTrigger, false, true);
+ m_manualTrigger.Set(true);
+ }
+};
+
+TEST_F(DMATest, DISABLED_PausingWorks) {
+ m_dma.Start(1024);
+ m_dma.SetPause(true);
+ m_manualTrigger.Set(false);
+
+ frc::DMASample sample;
+ int32_t remaining = 0;
+ int32_t status = 0;
+
+ auto timedOut = sample.Update(&m_dma, 5_ms, &remaining, &status);
+
+ ASSERT_EQ(DMASample::DMAReadStatus::kTimeout, timedOut);
+}
+
+TEST_F(DMATest, DISABLED_RemovingTriggersWorks) {
+ m_dma.ClearExternalTriggers();
+ m_dma.Start(1024);
+ m_manualTrigger.Set(false);
+
+ frc::DMASample sample;
+ int32_t remaining = 0;
+ int32_t status = 0;
+
+ auto timedOut = sample.Update(&m_dma, 5_ms, &remaining, &status);
+
+ ASSERT_EQ(DMASample::DMAReadStatus::kTimeout, timedOut);
+}
+
+TEST_F(DMATest, DISABLED_ManualTriggerOnlyHappensOnce) {
+ m_dma.Start(1024);
+ m_manualTrigger.Set(false);
+
+ frc::DMASample sample;
+ int32_t remaining = 0;
+ int32_t status = 0;
+
+ auto timedOut = sample.Update(&m_dma, 5_ms, &remaining, &status);
+
+ ASSERT_EQ(DMASample::DMAReadStatus::kOk, timedOut);
+ ASSERT_EQ(0, remaining);
+ timedOut = sample.Update(&m_dma, 5_ms, &remaining, &status);
+ ASSERT_EQ(DMASample::DMAReadStatus::kTimeout, timedOut);
+}
+
+TEST_F(DMATest, DISABLED_AnalogIndividualTriggers) {
+ m_dma.Start(1024);
+ for (double i = 0; i < 5; i += 0.5) {
+ frc::DMASample sample;
+ int32_t remaining = 0;
+ int32_t status = 0;
+
+ m_analogOutput.SetVoltage(i);
+ frc::Wait(kDelayTime);
+ m_manualTrigger.Set(false);
+ auto timedOut = sample.Update(&m_dma, 1_ms, &remaining, &status);
+ m_manualTrigger.Set(true);
+ ASSERT_EQ(DMASample::DMAReadStatus::kOk, timedOut);
+ ASSERT_EQ(0, status);
+ ASSERT_EQ(0, remaining);
+ ASSERT_DOUBLE_EQ(m_analogInput.GetVoltage(),
+ sample.GetAnalogInputVoltage(&m_analogInput, &status));
+ }
+}
+
+TEST_F(DMATest, DISABLED_AnalogMultipleTriggers) {
+ m_dma.Start(1024);
+ std::vector<double> values;
+ for (double i = 0; i < 5; i += 0.5) {
+ values.push_back(i);
+ m_analogOutput.SetVoltage(i);
+ frc::Wait(kDelayTime);
+ m_manualTrigger.Set(false);
+ frc::Wait(kDelayTime);
+ m_manualTrigger.Set(true);
+ }
+
+ for (size_t i = 0; i < values.size(); i++) {
+ frc::DMASample sample;
+ int32_t remaining = 0;
+ int32_t status = 0;
+ auto timedOut = sample.Update(&m_dma, 1_ms, &remaining, &status);
+ ASSERT_EQ(DMASample::DMAReadStatus::kOk, timedOut);
+ ASSERT_EQ(0, status);
+ ASSERT_EQ(values.size() - i - 1, (uint32_t)remaining);
+ ASSERT_DOUBLE_EQ(values[i],
+ sample.GetAnalogInputVoltage(&m_analogInput, &status));
+ }
+}
+
+TEST_F(DMATest, DISABLED_TimedTriggers) {
+ m_dma.SetTimedTrigger(10_ms);
+ m_dma.Start(1024);
+ frc::Wait(kDelayTime);
+ m_dma.SetPause(true);
+
+ frc::DMASample sample;
+ int32_t remaining = 0;
+ int32_t status = 0;
+
+ auto timedOut = sample.Update(&m_dma, 1_ms, &remaining, &status);
+ ASSERT_EQ(DMASample::DMAReadStatus::kOk, timedOut);
+ ASSERT_EQ(0, status);
+ ASSERT_GT(remaining, 5);
+}
+
+TEST_F(DMATest, DISABLED_PWMTimedTriggers) {
+ m_dma.ClearExternalTriggers();
+ m_dma.SetPwmEdgeTrigger(&m_pwm, true, false);
+ m_dma.Start(1024);
+ frc::Wait(kDelayTime);
+ m_dma.SetPause(true);
+
+ frc::DMASample sample;
+ int32_t remaining = 0;
+ int32_t status = 0;
+
+ auto timedOut = sample.Update(&m_dma, 1_ms, &remaining, &status);
+ ASSERT_EQ(DMASample::DMAReadStatus::kOk, timedOut);
+ ASSERT_EQ(0, status);
+ ASSERT_GT(remaining, 5);
+}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/DigitalGlitchFilterTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/DigitalGlitchFilterTest.cpp
index fa39e79..d7c1a23 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/DigitalGlitchFilterTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/DigitalGlitchFilterTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/DigitalGlitchFilter.h" // NOLINT(build/include_order)
@@ -12,8 +9,6 @@
#include "frc/Encoder.h"
#include "gtest/gtest.h"
-using namespace frc;
-
/**
* Tests that configuring inputs to be filtered succeeds.
*
@@ -21,28 +16,28 @@
* implementation works as intended. We configure the FPGA and then query it to
* make sure that the acutal configuration matches.
*/
-TEST(DigitalGlitchFilterTest, BasicTest) {
- DigitalInput input1(1);
- DigitalInput input2(2);
- DigitalInput input3(3);
- DigitalInput input4(4);
- Encoder encoder5(5, 6);
- Counter counter7(7);
+TEST(DigitalGlitchFilterTest, Basic) {
+ frc::DigitalInput input1{1};
+ frc::DigitalInput input2{2};
+ frc::DigitalInput input3{3};
+ frc::DigitalInput input4{4};
+ frc::Encoder encoder5{5, 6};
+ frc::Counter counter7{7};
// Check that we can make a single filter and set the period.
- DigitalGlitchFilter filter1;
+ frc::DigitalGlitchFilter filter1;
filter1.Add(&input1);
filter1.SetPeriodNanoSeconds(4200);
// Check that we can make a second filter with 2 inputs.
- DigitalGlitchFilter filter2;
+ frc::DigitalGlitchFilter filter2;
filter2.Add(&input2);
filter2.Add(&input3);
filter2.SetPeriodNanoSeconds(97100);
// Check that we can make a third filter with an input, an encoder, and a
// counter.
- DigitalGlitchFilter filter3;
+ frc::DigitalGlitchFilter filter3;
filter3.Add(&input4);
filter3.Add(&encoder5);
filter3.Add(&counter7);
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/DriverStationTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/DriverStationTest.cpp
index df8eef3..e4a2721 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/DriverStationTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/DriverStationTest.cpp
@@ -1,35 +1,31 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/DriverStation.h" // NOLINT(build/include_order)
+#include <units/math.h>
+#include <units/time.h>
+
#include "TestBench.h"
#include "frc/RobotController.h"
#include "gtest/gtest.h"
-using namespace frc;
-
-constexpr double TIMER_TOLERANCE = 0.2;
-constexpr int64_t TIMER_RUNTIME = 1000000; // 1 second
-
-class DriverStationTest : public testing::Test {};
+#define EXPECT_NEAR_UNITS(val1, val2, eps) \
+ EXPECT_LE(units::math::abs(val1 - val2), eps)
/**
* Test if the WaitForData function works
*/
-TEST_F(DriverStationTest, WaitForData) {
- uint64_t initialTime = RobotController::GetFPGATime();
+TEST(DriverStationTest, WaitForData) {
+ units::microsecond_t initialTime(frc::RobotController::GetFPGATime());
+ // 20ms waiting intervals * 50 = 1s
for (int i = 0; i < 50; i++) {
- DriverStation::GetInstance().WaitForData();
+ frc::DriverStation::WaitForData();
}
- uint64_t finalTime = RobotController::GetFPGATime();
+ units::microsecond_t finalTime(frc::RobotController::GetFPGATime());
- EXPECT_NEAR(TIMER_RUNTIME, finalTime - initialTime,
- TIMER_TOLERANCE * TIMER_RUNTIME);
+ EXPECT_NEAR_UNITS(1_s, finalTime - initialTime, 200_ms);
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/FakeEncoderTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/FakeEncoderTest.cpp
index bf5a8ee..3442b48 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/FakeEncoderTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/FakeEncoderTest.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/Encoder.h" // NOLINT(build/include_order)
+#include <units/time.h>
+
#include "TestBench.h"
#include "frc/AnalogOutput.h"
#include "frc/AnalogTrigger.h"
@@ -14,41 +13,24 @@
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
-
-static const double kDelayTime = 0.001;
+static constexpr auto kDelayTime = 1_ms;
class FakeEncoderTest : public testing::Test {
protected:
- DigitalOutput* m_outputA;
- DigitalOutput* m_outputB;
- AnalogOutput* m_indexOutput;
+ frc::DigitalOutput m_outputA{TestBench::kLoop2OutputChannel};
+ frc::DigitalOutput m_outputB{TestBench::kLoop1OutputChannel};
+ frc::AnalogOutput m_indexOutput{TestBench::kAnalogOutputChannel};
- Encoder* m_encoder;
- AnalogTrigger* m_indexAnalogTrigger;
- std::shared_ptr<AnalogTriggerOutput> m_indexAnalogTriggerOutput;
+ frc::Encoder m_encoder{TestBench::kLoop1InputChannel,
+ TestBench::kLoop2InputChannel};
+ frc::AnalogTrigger m_indexAnalogTrigger{TestBench::kFakeAnalogOutputChannel};
+ std::shared_ptr<frc::AnalogTriggerOutput> m_indexAnalogTriggerOutput =
+ m_indexAnalogTrigger.CreateOutput(frc::AnalogTriggerType::kState);
- void SetUp() override {
- m_outputA = new DigitalOutput(TestBench::kLoop2OutputChannel);
- m_outputB = new DigitalOutput(TestBench::kLoop1OutputChannel);
- m_indexOutput = new AnalogOutput(TestBench::kAnalogOutputChannel);
- m_outputA->Set(false);
- m_outputB->Set(false);
- m_encoder = new Encoder(TestBench::kLoop1InputChannel,
- TestBench::kLoop2InputChannel);
- m_indexAnalogTrigger =
- new AnalogTrigger(TestBench::kFakeAnalogOutputChannel);
- m_indexAnalogTrigger->SetLimitsVoltage(2.0, 3.0);
- m_indexAnalogTriggerOutput =
- m_indexAnalogTrigger->CreateOutput(AnalogTriggerType::kState);
- }
-
- void TearDown() override {
- delete m_outputA;
- delete m_outputB;
- delete m_indexOutput;
- delete m_encoder;
- delete m_indexAnalogTrigger;
+ FakeEncoderTest() {
+ m_outputA.Set(false);
+ m_outputB.Set(false);
+ m_indexAnalogTrigger.SetLimitsVoltage(2.0, 3.0);
}
/**
@@ -57,105 +39,105 @@
*/
void Simulate100QuadratureTicks() {
for (int32_t i = 0; i < 100; i++) {
- m_outputA->Set(true);
- Wait(kDelayTime);
- m_outputB->Set(true);
- Wait(kDelayTime);
- m_outputA->Set(false);
- Wait(kDelayTime);
- m_outputB->Set(false);
- Wait(kDelayTime);
+ m_outputA.Set(true);
+ frc::Wait(kDelayTime);
+ m_outputB.Set(true);
+ frc::Wait(kDelayTime);
+ m_outputA.Set(false);
+ frc::Wait(kDelayTime);
+ m_outputB.Set(false);
+ frc::Wait(kDelayTime);
}
}
void SetIndexHigh() {
- m_indexOutput->SetVoltage(5.0);
- Wait(kDelayTime);
+ m_indexOutput.SetVoltage(5.0);
+ frc::Wait(kDelayTime);
}
void SetIndexLow() {
- m_indexOutput->SetVoltage(0.0);
- Wait(kDelayTime);
+ m_indexOutput.SetVoltage(0.0);
+ frc::Wait(kDelayTime);
}
};
/**
* Test the encoder by reseting it to 0 and reading the value.
*/
-TEST_F(FakeEncoderTest, TestDefaultState) {
- EXPECT_FLOAT_EQ(0.0, m_encoder->Get()) << "The encoder did not start at 0.";
+TEST_F(FakeEncoderTest, DefaultState) {
+ EXPECT_DOUBLE_EQ(0.0, m_encoder.Get()) << "The encoder did not start at 0.";
}
/**
* Test the encoder by setting the digital outputs and reading the value.
*/
-TEST_F(FakeEncoderTest, TestCountUp) {
- m_encoder->Reset();
+TEST_F(FakeEncoderTest, CountUp) {
+ m_encoder.Reset();
Simulate100QuadratureTicks();
- EXPECT_FLOAT_EQ(100.0, m_encoder->Get()) << "Encoder did not count to 100.";
+ EXPECT_DOUBLE_EQ(100.0, m_encoder.Get()) << "Encoder did not count to 100.";
}
/**
* Test that the encoder can stay reset while the index source is high
*/
-TEST_F(FakeEncoderTest, TestResetWhileHigh) {
- m_encoder->SetIndexSource(*m_indexAnalogTriggerOutput,
- Encoder::IndexingType::kResetWhileHigh);
+TEST_F(FakeEncoderTest, ResetWhileHigh) {
+ m_encoder.SetIndexSource(*m_indexAnalogTriggerOutput,
+ frc::Encoder::IndexingType::kResetWhileHigh);
SetIndexLow();
Simulate100QuadratureTicks();
SetIndexHigh();
- EXPECT_EQ(0, m_encoder->Get());
+ EXPECT_EQ(0, m_encoder.Get());
Simulate100QuadratureTicks();
- EXPECT_EQ(0, m_encoder->Get());
+ EXPECT_EQ(0, m_encoder.Get());
}
/**
* Test that the encoder can reset when the index source goes from low to high
*/
-TEST_F(FakeEncoderTest, TestResetOnRisingEdge) {
- m_encoder->SetIndexSource(*m_indexAnalogTriggerOutput,
- Encoder::IndexingType::kResetOnRisingEdge);
+TEST_F(FakeEncoderTest, ResetOnRisingEdge) {
+ m_encoder.SetIndexSource(*m_indexAnalogTriggerOutput,
+ frc::Encoder::IndexingType::kResetOnRisingEdge);
SetIndexLow();
Simulate100QuadratureTicks();
SetIndexHigh();
- EXPECT_EQ(0, m_encoder->Get());
+ EXPECT_EQ(0, m_encoder.Get());
Simulate100QuadratureTicks();
- EXPECT_EQ(100, m_encoder->Get());
+ EXPECT_EQ(100, m_encoder.Get());
}
/**
* Test that the encoder can stay reset while the index source is low
*/
-TEST_F(FakeEncoderTest, TestResetWhileLow) {
- m_encoder->SetIndexSource(*m_indexAnalogTriggerOutput,
- Encoder::IndexingType::kResetWhileLow);
+TEST_F(FakeEncoderTest, ResetWhileLow) {
+ m_encoder.SetIndexSource(*m_indexAnalogTriggerOutput,
+ frc::Encoder::IndexingType::kResetWhileLow);
SetIndexHigh();
Simulate100QuadratureTicks();
SetIndexLow();
- EXPECT_EQ(0, m_encoder->Get());
+ EXPECT_EQ(0, m_encoder.Get());
Simulate100QuadratureTicks();
- EXPECT_EQ(0, m_encoder->Get());
+ EXPECT_EQ(0, m_encoder.Get());
}
/**
* Test that the encoder can reset when the index source goes from high to low
*/
-TEST_F(FakeEncoderTest, TestResetOnFallingEdge) {
- m_encoder->SetIndexSource(*m_indexAnalogTriggerOutput,
- Encoder::IndexingType::kResetOnFallingEdge);
+TEST_F(FakeEncoderTest, ResetOnFallingEdge) {
+ m_encoder.SetIndexSource(*m_indexAnalogTriggerOutput,
+ frc::Encoder::IndexingType::kResetOnFallingEdge);
SetIndexHigh();
Simulate100QuadratureTicks();
SetIndexLow();
- EXPECT_EQ(0, m_encoder->Get());
+ EXPECT_EQ(0, m_encoder.Get());
Simulate100QuadratureTicks();
- EXPECT_EQ(100, m_encoder->Get());
+ EXPECT_EQ(100, m_encoder.Get());
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/Main.cpp b/wpilibcIntegrationTests/src/main/native/cpp/Main.cpp
new file mode 100644
index 0000000..95bc5b5
--- /dev/null
+++ b/wpilibcIntegrationTests/src/main/native/cpp/Main.cpp
@@ -0,0 +1,10 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "gtest/gtest.h"
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp
index e368fc2..46e2120 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp
@@ -1,25 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-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 <algorithm>
+#include <units/time.h>
+
#include "TestBench.h"
#include "frc/Encoder.h"
-#include "frc/Jaguar.h"
-#include "frc/LinearFilter.h"
#include "frc/Notifier.h"
-#include "frc/Talon.h"
#include "frc/Timer.h"
-#include "frc/Victor.h"
#include "frc/controller/PIDController.h"
+#include "frc/filter/LinearFilter.h"
+#include "frc/motorcontrol/Jaguar.h"
+#include "frc/motorcontrol/Talon.h"
+#include "frc/motorcontrol/Victor.h"
#include "gtest/gtest.h"
-using namespace frc;
-
enum MotorEncoderTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
std::ostream& operator<<(std::ostream& os, MotorEncoderTestType const& type) {
@@ -38,50 +35,50 @@
return os;
}
-static constexpr double kMotorTime = 0.5;
+static constexpr auto kMotorTime = 0.5_s;
/**
- * A fixture that includes a PWM speed controller and an encoder connected to
+ * A fixture that includes a PWM motor controller and an encoder connected to
* the same motor.
*/
class MotorEncoderTest : public testing::TestWithParam<MotorEncoderTestType> {
protected:
- SpeedController* m_speedController;
- Encoder* m_encoder;
- LinearFilter<double>* m_filter;
+ frc::MotorController* m_motorController;
+ frc::Encoder* m_encoder;
+ frc::LinearFilter<double>* m_filter;
- void SetUp() override {
+ MotorEncoderTest() {
switch (GetParam()) {
case TEST_VICTOR:
- m_speedController = new Victor(TestBench::kVictorChannel);
- m_encoder = new Encoder(TestBench::kVictorEncoderChannelA,
- TestBench::kVictorEncoderChannelB);
+ m_motorController = new frc::Victor(TestBench::kVictorChannel);
+ m_encoder = new frc::Encoder(TestBench::kVictorEncoderChannelA,
+ TestBench::kVictorEncoderChannelB);
break;
case TEST_JAGUAR:
- m_speedController = new Jaguar(TestBench::kJaguarChannel);
- m_encoder = new Encoder(TestBench::kJaguarEncoderChannelA,
- TestBench::kJaguarEncoderChannelB);
+ m_motorController = new frc::Jaguar(TestBench::kJaguarChannel);
+ m_encoder = new frc::Encoder(TestBench::kJaguarEncoderChannelA,
+ TestBench::kJaguarEncoderChannelB);
break;
case TEST_TALON:
- m_speedController = new Talon(TestBench::kTalonChannel);
- m_encoder = new Encoder(TestBench::kTalonEncoderChannelA,
- TestBench::kTalonEncoderChannelB);
+ m_motorController = new frc::Talon(TestBench::kTalonChannel);
+ m_encoder = new frc::Encoder(TestBench::kTalonEncoderChannelA,
+ TestBench::kTalonEncoderChannelB);
break;
}
- m_filter =
- new LinearFilter<double>(LinearFilter<double>::MovingAverage(50));
+ m_filter = new frc::LinearFilter<double>(
+ frc::LinearFilter<double>::MovingAverage(50));
}
- void TearDown() override {
- delete m_speedController;
- delete m_encoder;
+ ~MotorEncoderTest() {
delete m_filter;
+ delete m_encoder;
+ delete m_motorController;
}
void Reset() {
- m_speedController->Set(0.0);
+ m_motorController->Set(0.0);
m_encoder->Reset();
m_filter->Reset();
}
@@ -93,10 +90,10 @@
TEST_P(MotorEncoderTest, Increment) {
Reset();
- /* Drive the speed controller briefly to move the encoder */
- m_speedController->Set(0.2f);
- Wait(kMotorTime);
- m_speedController->Set(0.0);
+ /* Drive the motor controller briefly to move the encoder */
+ m_motorController->Set(0.2f);
+ frc::Wait(kMotorTime);
+ m_motorController->Set(0.0);
/* The encoder should be positive now */
EXPECT_GT(m_encoder->Get(), 0)
@@ -109,10 +106,10 @@
TEST_P(MotorEncoderTest, Decrement) {
Reset();
- /* Drive the speed controller briefly to move the encoder */
- m_speedController->Set(-0.2);
- Wait(kMotorTime);
- m_speedController->Set(0.0);
+ /* Drive the motor controller briefly to move the encoder */
+ m_motorController->Set(-0.2);
+ frc::Wait(kMotorTime);
+ m_motorController->Set(0.0);
/* The encoder should be positive now */
EXPECT_LT(m_encoder->Get(), 0.0)
@@ -125,15 +122,15 @@
TEST_P(MotorEncoderTest, ClampSpeed) {
Reset();
- m_speedController->Set(2.0);
- Wait(kMotorTime);
+ m_motorController->Set(2.0);
+ frc::Wait(kMotorTime);
- EXPECT_FLOAT_EQ(1.0, m_speedController->Get());
+ EXPECT_FLOAT_EQ(1.0, m_motorController->Get());
- m_speedController->Set(-2.0);
- Wait(kMotorTime);
+ m_motorController->Set(-2.0);
+ frc::Wait(kMotorTime);
- EXPECT_FLOAT_EQ(-1.0, m_speedController->Get());
+ EXPECT_FLOAT_EQ(-1.0, m_motorController->Get());
}
/**
@@ -150,10 +147,10 @@
/* 10 seconds should be plenty time to get to the reference */
frc::Notifier pidRunner{[this, &pidController] {
auto speed = pidController.Calculate(m_encoder->GetDistance());
- m_speedController->Set(std::clamp(speed, -0.2, 0.2));
+ m_motorController->Set(std::clamp(speed, -0.2, 0.2));
}};
pidRunner.StartPeriodic(pidController.GetPeriod());
- Wait(10.0);
+ frc::Wait(10_s);
pidRunner.Stop();
RecordProperty("PIDError", pidController.GetPositionError());
@@ -177,10 +174,10 @@
frc::Notifier pidRunner{[this, &pidController] {
auto speed =
pidController.Calculate(m_filter->Calculate(m_encoder->GetRate()));
- m_speedController->Set(std::clamp(speed, -0.3, 0.3));
+ m_motorController->Set(std::clamp(speed, -0.3, 0.3));
}};
pidRunner.StartPeriodic(pidController.GetPeriod());
- Wait(10.0);
+ frc::Wait(10_s);
pidRunner.Stop();
RecordProperty("PIDError", pidController.GetPositionError());
@@ -198,5 +195,5 @@
EXPECT_EQ(0, m_encoder->Get()) << "Encoder did not reset to 0";
}
-INSTANTIATE_TEST_SUITE_P(Test, MotorEncoderTest,
+INSTANTIATE_TEST_SUITE_P(Tests, MotorEncoderTest,
testing::Values(TEST_VICTOR, TEST_JAGUAR, TEST_TALON));
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp
index ed1821b..10ccd34 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp
@@ -1,23 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-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 <units/time.h>
#include "TestBench.h"
#include "frc/Encoder.h"
-#include "frc/Jaguar.h"
-#include "frc/Talon.h"
#include "frc/Timer.h"
-#include "frc/Victor.h"
+#include "frc/motorcontrol/Jaguar.h"
+#include "frc/motorcontrol/Talon.h"
+#include "frc/motorcontrol/Victor.h"
#include "gtest/gtest.h"
-using namespace frc;
-
enum MotorInvertingTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
-static const double motorSpeed = 0.15;
-static const double delayTime = 0.5;
+
+static constexpr double kMotorSpeed = 0.15;
+static constexpr auto kDelayTime = 0.5_s;
+
std::ostream& operator<<(std::ostream& os, MotorInvertingTestType const& type) {
switch (type) {
case TEST_VICTOR:
@@ -36,39 +35,39 @@
class MotorInvertingTest
: public testing::TestWithParam<MotorInvertingTestType> {
protected:
- SpeedController* m_speedController;
- Encoder* m_encoder;
+ frc::MotorController* m_motorController;
+ frc::Encoder* m_encoder;
- void SetUp() override {
+ MotorInvertingTest() {
switch (GetParam()) {
case TEST_VICTOR:
- m_speedController = new Victor(TestBench::kVictorChannel);
- m_encoder = new Encoder(TestBench::kVictorEncoderChannelA,
- TestBench::kVictorEncoderChannelB);
+ m_motorController = new frc::Victor(TestBench::kVictorChannel);
+ m_encoder = new frc::Encoder(TestBench::kVictorEncoderChannelA,
+ TestBench::kVictorEncoderChannelB);
break;
case TEST_JAGUAR:
- m_speedController = new Jaguar(TestBench::kJaguarChannel);
- m_encoder = new Encoder(TestBench::kJaguarEncoderChannelA,
- TestBench::kJaguarEncoderChannelB);
+ m_motorController = new frc::Jaguar(TestBench::kJaguarChannel);
+ m_encoder = new frc::Encoder(TestBench::kJaguarEncoderChannelA,
+ TestBench::kJaguarEncoderChannelB);
break;
case TEST_TALON:
- m_speedController = new Talon(TestBench::kTalonChannel);
- m_encoder = new Encoder(TestBench::kTalonEncoderChannelA,
- TestBench::kTalonEncoderChannelB);
+ m_motorController = new frc::Talon(TestBench::kTalonChannel);
+ m_encoder = new frc::Encoder(TestBench::kTalonEncoderChannelA,
+ TestBench::kTalonEncoderChannelB);
break;
}
}
- void TearDown() override {
- delete m_speedController;
+ ~MotorInvertingTest() {
delete m_encoder;
+ delete m_motorController;
}
void Reset() {
- m_speedController->SetInverted(false);
- m_speedController->Set(0.0);
+ m_motorController->SetInverted(false);
+ m_motorController->Set(0.0);
m_encoder->Reset();
}
};
@@ -76,15 +75,15 @@
TEST_P(MotorInvertingTest, InvertingPositive) {
Reset();
- m_speedController->Set(motorSpeed);
+ m_motorController->Set(kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
bool initDirection = m_encoder->GetDirection();
- m_speedController->SetInverted(true);
- m_speedController->Set(motorSpeed);
+ m_motorController->SetInverted(true);
+ m_motorController->Set(kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
<< "Inverting with Positive value does not change direction";
@@ -95,16 +94,16 @@
TEST_P(MotorInvertingTest, InvertingNegative) {
Reset();
- m_speedController->SetInverted(false);
- m_speedController->Set(-motorSpeed);
+ m_motorController->SetInverted(false);
+ m_motorController->Set(-kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
bool initDirection = m_encoder->GetDirection();
- m_speedController->SetInverted(true);
- m_speedController->Set(-motorSpeed);
+ m_motorController->SetInverted(true);
+ m_motorController->Set(-kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
<< "Inverting with Negative value does not change direction";
@@ -115,16 +114,16 @@
TEST_P(MotorInvertingTest, InvertingSwitchingPosToNeg) {
Reset();
- m_speedController->SetInverted(false);
- m_speedController->Set(motorSpeed);
+ m_motorController->SetInverted(false);
+ m_motorController->Set(kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
bool initDirection = m_encoder->GetDirection();
- m_speedController->SetInverted(true);
- m_speedController->Set(-motorSpeed);
+ m_motorController->SetInverted(true);
+ m_motorController->Set(-kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
<< "Inverting with Switching value does change direction";
@@ -135,16 +134,16 @@
TEST_P(MotorInvertingTest, InvertingSwitchingNegToPos) {
Reset();
- m_speedController->SetInverted(false);
- m_speedController->Set(-motorSpeed);
+ m_motorController->SetInverted(false);
+ m_motorController->Set(-kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
bool initDirection = m_encoder->GetDirection();
- m_speedController->SetInverted(true);
- m_speedController->Set(motorSpeed);
+ m_motorController->SetInverted(true);
+ m_motorController->Set(kMotorSpeed);
- Wait(delayTime);
+ frc::Wait(kDelayTime);
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
<< "Inverting with Switching value does change direction";
@@ -152,5 +151,5 @@
Reset();
}
-INSTANTIATE_TEST_SUITE_P(Test, MotorInvertingTest,
+INSTANTIATE_TEST_SUITE_P(Tests, MotorInvertingTest,
testing::Values(TEST_VICTOR, TEST_JAGUAR, TEST_TALON));
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/NotifierTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/NotifierTest.cpp
index d7f0d6e..eaaaf7e 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/NotifierTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/NotifierTest.cpp
@@ -1,43 +1,43 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/Notifier.h" // NOLINT(build/include_order)
-#include <wpi/raw_ostream.h>
+#include <fmt/core.h>
-#include "TestBench.h"
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
+TEST(NotifierTest, StartPeriodicAndStop) {
+ uint32_t counter = 0;
-unsigned notifierCounter;
+ frc::Notifier notifier{[&] { ++counter; }};
+ notifier.StartPeriodic(1_s);
-void notifierHandler(void*) { notifierCounter++; }
+ frc::Wait(10.5_s);
-/**
- * Test if the Wait function works
- */
-TEST(NotifierTest, DISABLED_TestTimerNotifications) {
- wpi::outs() << "NotifierTest...\n";
- notifierCounter = 0;
- wpi::outs() << "notifier(notifierHandler, nullptr)...\n";
- Notifier notifier(notifierHandler, nullptr);
- wpi::outs() << "Start Periodic...\n";
- notifier.StartPeriodic(1.0);
+ notifier.Stop();
+ EXPECT_EQ(10u, counter) << "Received " << counter
+ << " notifications in 10.5 seconds\n";
+ fmt::print("Received {} notifications in 10.5 seconds\n", counter);
- wpi::outs() << "Wait...\n";
- Wait(10.5);
- wpi::outs() << "...Wait\n";
+ frc::Wait(3_s);
- EXPECT_EQ(10u, notifierCounter)
- << "Received " << notifierCounter << " notifications in 10.5 seconds";
- wpi::outs() << "Received " << notifierCounter
- << " notifications in 10.5 seconds";
+ EXPECT_EQ(10u, counter) << "Received " << counter - 10
+ << " notifications in 3 seconds\n";
+ fmt::print("Received {} notifications in 3 seconds\n", counter - 10);
+}
- wpi::outs() << "...NotifierTest\n";
+TEST(NotifierTest, StartSingle) {
+ uint32_t counter = 0;
+
+ frc::Notifier notifier{[&] { ++counter; }};
+ notifier.StartSingle(1_s);
+
+ frc::Wait(10.5_s);
+
+ EXPECT_EQ(1u, counter) << "Received " << counter
+ << " notifications in 10.5 seconds\n";
+ fmt::print("Received {} notifications in 10.5 seconds\n", counter);
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/PCMTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/PCMTest.cpp
index 5be4d3f..1cc70b7 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/PCMTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/PCMTest.cpp
@@ -1,28 +1,23 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "TestBench.h"
#include "frc/AnalogInput.h"
-#include "frc/Compressor.h"
#include "frc/DigitalInput.h"
#include "frc/DigitalOutput.h"
#include "frc/DoubleSolenoid.h"
+#include "frc/PneumaticsControlModule.h"
#include "frc/Solenoid.h"
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
-
/* The PCM switches the compressor up to a couple seconds after the pressure
switch changes. */
-static const double kCompressorDelayTime = 3.0;
+static constexpr auto kCompressorDelayTime = 3_s;
/* Solenoids should change much more quickly */
-static const double kSolenoidDelayTime = 0.5;
+static constexpr auto kSolenoidDelayTime = 0.5_s;
/* The voltage divider on the test bench should bring the compressor output
to around these values. */
@@ -31,34 +26,17 @@
class PCMTest : public testing::Test {
protected:
- Compressor* m_compressor;
+ frc::PneumaticsControlModule m_pneumaticsModule;
- DigitalOutput* m_fakePressureSwitch;
- AnalogInput* m_fakeCompressor;
- DoubleSolenoid* m_doubleSolenoid;
- DigitalInput *m_fakeSolenoid1, *m_fakeSolenoid2;
-
- void SetUp() override {
- m_compressor = new Compressor();
-
- m_fakePressureSwitch =
- new DigitalOutput(TestBench::kFakePressureSwitchChannel);
- m_fakeCompressor = new AnalogInput(TestBench::kFakeCompressorChannel);
- m_fakeSolenoid1 = new DigitalInput(TestBench::kFakeSolenoid1Channel);
- m_fakeSolenoid2 = new DigitalInput(TestBench::kFakeSolenoid2Channel);
- }
-
- void TearDown() override {
- delete m_compressor;
- delete m_fakePressureSwitch;
- delete m_fakeCompressor;
- delete m_fakeSolenoid1;
- delete m_fakeSolenoid2;
- }
+ frc::DigitalOutput m_fakePressureSwitch{
+ TestBench::kFakePressureSwitchChannel};
+ frc::AnalogInput m_fakeCompressor{TestBench::kFakeCompressorChannel};
+ frc::DigitalInput m_fakeSolenoid1{TestBench::kFakeSolenoid1Channel};
+ frc::DigitalInput m_fakeSolenoid2{TestBench::kFakeSolenoid2Channel};
void Reset() {
- m_compressor->Stop();
- m_fakePressureSwitch->Set(false);
+ m_pneumaticsModule.SetClosedLoopControl(false);
+ m_fakePressureSwitch.Set(false);
}
};
@@ -68,18 +46,18 @@
TEST_F(PCMTest, PressureSwitch) {
Reset();
- m_compressor->SetClosedLoopControl(true);
+ m_pneumaticsModule.SetClosedLoopControl(true);
// Turn on the compressor
- m_fakePressureSwitch->Set(true);
- Wait(kCompressorDelayTime);
- EXPECT_NEAR(kCompressorOnVoltage, m_fakeCompressor->GetVoltage(), 0.5)
+ m_fakePressureSwitch.Set(true);
+ frc::Wait(kCompressorDelayTime);
+ EXPECT_NEAR(kCompressorOnVoltage, m_fakeCompressor.GetVoltage(), 0.5)
<< "Compressor did not turn on when the pressure switch turned on.";
// Turn off the compressor
- m_fakePressureSwitch->Set(false);
- Wait(kCompressorDelayTime);
- EXPECT_NEAR(kCompressorOffVoltage, m_fakeCompressor->GetVoltage(), 0.5)
+ m_fakePressureSwitch.Set(false);
+ frc::Wait(kCompressorDelayTime);
+ EXPECT_NEAR(kCompressorOffVoltage, m_fakeCompressor.GetVoltage(), 0.5)
<< "Compressor did not turn off when the pressure switch turned off.";
}
@@ -88,42 +66,44 @@
*/
TEST_F(PCMTest, Solenoid) {
Reset();
- Solenoid solenoid1(TestBench::kSolenoidChannel1);
- Solenoid solenoid2(TestBench::kSolenoidChannel2);
+ frc::Solenoid solenoid1{frc::PneumaticsModuleType::CTREPCM,
+ TestBench::kSolenoidChannel1};
+ frc::Solenoid solenoid2{frc::PneumaticsModuleType::CTREPCM,
+ TestBench::kSolenoidChannel2};
// Turn both solenoids off
solenoid1.Set(false);
solenoid2.Set(false);
- Wait(kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
// Turn one solenoid on and one off
solenoid1.Set(true);
solenoid2.Set(false);
- Wait(kSolenoidDelayTime);
- EXPECT_FALSE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn on";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
// Turn one solenoid on and one off
solenoid1.Set(false);
solenoid2.Set(true);
- Wait(kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
// Turn both on
solenoid1.Set(true);
solenoid2.Set(true);
- Wait(kSolenoidDelayTime);
- EXPECT_FALSE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn on";
- EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
+ EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
}
@@ -133,42 +113,45 @@
* with the DoubleSolenoid class.
*/
TEST_F(PCMTest, DoubleSolenoid) {
- DoubleSolenoid solenoid(TestBench::kSolenoidChannel1,
- TestBench::kSolenoidChannel2);
+ frc::DoubleSolenoid solenoid{frc::PneumaticsModuleType::CTREPCM,
+ TestBench::kSolenoidChannel1,
+ TestBench::kSolenoidChannel2};
- solenoid.Set(DoubleSolenoid::kOff);
- Wait(kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
- EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kOff)
+ solenoid.Set(frc::DoubleSolenoid::kOff);
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
+ EXPECT_TRUE(solenoid.Get() == frc::DoubleSolenoid::kOff)
<< "Solenoid does not read off";
- solenoid.Set(DoubleSolenoid::kForward);
- Wait(kSolenoidDelayTime);
- EXPECT_FALSE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn on";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
- EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kForward)
+ solenoid.Set(frc::DoubleSolenoid::kForward);
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
+ EXPECT_TRUE(solenoid.Get() == frc::DoubleSolenoid::kForward)
<< "Solenoid does not read forward";
- solenoid.Set(DoubleSolenoid::kReverse);
- Wait(kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
- EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kReverse)
+ solenoid.Set(frc::DoubleSolenoid::kReverse);
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
+ EXPECT_TRUE(solenoid.Get() == frc::DoubleSolenoid::kReverse)
<< "Solenoid does not read reverse";
}
TEST_F(PCMTest, OneShot) {
Reset();
- Solenoid solenoid1(TestBench::kSolenoidChannel1);
- Solenoid solenoid2(TestBench::kSolenoidChannel2);
+ frc::Solenoid solenoid1{frc::PneumaticsModuleType::CTREPCM,
+ TestBench::kSolenoidChannel1};
+ frc::Solenoid solenoid2{frc::PneumaticsModuleType::CTREPCM,
+ TestBench::kSolenoidChannel2};
// Turn both solenoids off
solenoid1.Set(false);
solenoid2.Set(false);
- Wait(kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
@@ -176,14 +159,14 @@
solenoid1.SetPulseDuration(2 * kSolenoidDelayTime);
solenoid2.Set(false);
solenoid1.StartPulse();
- Wait(kSolenoidDelayTime);
- EXPECT_FALSE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn on";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
- Wait(2 * kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(2 * kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
@@ -191,14 +174,14 @@
solenoid1.Set(false);
solenoid2.SetPulseDuration(2 * kSolenoidDelayTime);
solenoid2.StartPulse();
- Wait(kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
- Wait(2 * kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(2 * kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
@@ -207,14 +190,14 @@
solenoid2.SetPulseDuration(2 * kSolenoidDelayTime);
solenoid1.StartPulse();
solenoid2.StartPulse();
- Wait(kSolenoidDelayTime);
- EXPECT_FALSE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn on";
- EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
+ EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
- Wait(2 * kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(2 * kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
@@ -223,19 +206,19 @@
solenoid2.SetPulseDuration(2.5 * kSolenoidDelayTime);
solenoid1.StartPulse();
solenoid2.StartPulse();
- Wait(kSolenoidDelayTime);
- EXPECT_FALSE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn on";
- EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_FALSE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn on";
+ EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
EXPECT_TRUE(solenoid1.Get()) << "Solenoid #1 did not read on";
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
- Wait(kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
+ frc::Wait(kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_FALSE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn on";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_TRUE(solenoid2.Get()) << "Solenoid #2 did not read on";
- Wait(2 * kSolenoidDelayTime);
- EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
- EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
+ frc::Wait(2 * kSolenoidDelayTime);
+ EXPECT_TRUE(m_fakeSolenoid1.Get()) << "Solenoid #1 did not turn off";
+ EXPECT_TRUE(m_fakeSolenoid2.Get()) << "Solenoid #2 did not turn off";
EXPECT_FALSE(solenoid1.Get()) << "Solenoid #1 did not read off";
EXPECT_FALSE(solenoid2.Get()) << "Solenoid #2 did not read off";
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp
index 5917361..4697553 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp
@@ -1,78 +1,52 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include "frc/PowerDistributionPanel.h" // NOLINT(build/include_order)
-
-#include <thread>
+#include "frc/PowerDistribution.h" // NOLINT(build/include_order)
#include <hal/Ports.h>
+#include <units/time.h>
#include "TestBench.h"
-#include "frc/Jaguar.h"
-#include "frc/Talon.h"
#include "frc/Timer.h"
-#include "frc/Victor.h"
+#include "frc/motorcontrol/Talon.h"
#include "gtest/gtest.h"
-using namespace frc;
+static constexpr auto kMotorTime = 0.25_s;
-static const double kMotorTime = 0.25;
-
-class PowerDistributionPanelTest : public testing::Test {
+class PowerDistributionTest : public testing::Test {
protected:
- PowerDistributionPanel* m_pdp;
- Talon* m_talon;
- Victor* m_victor;
- Jaguar* m_jaguar;
-
- void SetUp() override {
- m_pdp = new PowerDistributionPanel();
- m_talon = new Talon(TestBench::kTalonChannel);
- m_victor = new Victor(TestBench::kVictorChannel);
- m_jaguar = new Jaguar(TestBench::kJaguarChannel);
- }
-
- void TearDown() override {
- delete m_pdp;
- delete m_talon;
- delete m_victor;
- delete m_jaguar;
- }
+ frc::PowerDistribution m_pdp;
+ frc::Talon m_talon{TestBench::kTalonChannel};
};
-TEST_F(PowerDistributionPanelTest, CheckRepeatedCalls) {
- auto numChannels = HAL_GetNumPDPChannels();
+TEST_F(PowerDistributionTest, CheckRepeatedCalls) {
+ auto numChannels = HAL_GetNumCTREPDPChannels();
// 1 second
for (int i = 0; i < 50; i++) {
for (int j = 0; j < numChannels; j++) {
- m_pdp->GetCurrent(j);
- ASSERT_TRUE(m_pdp->GetError().GetCode() == 0);
+ m_pdp.GetCurrent(j);
}
- m_pdp->GetVoltage();
- ASSERT_TRUE(m_pdp->GetError().GetCode() == 0);
+ m_pdp.GetVoltage();
}
- std::this_thread::sleep_for(std::chrono::milliseconds(20));
+ frc::Wait(20_ms);
}
/**
* Test if the current changes when the motor is driven using a talon
*/
-TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) {
- Wait(kMotorTime);
+TEST_F(PowerDistributionTest, CheckCurrentTalon) {
+ frc::Wait(kMotorTime);
/* The Current should be 0 */
- EXPECT_FLOAT_EQ(0, m_pdp->GetCurrent(TestBench::kTalonPDPChannel))
+ EXPECT_FLOAT_EQ(0, m_pdp.GetCurrent(TestBench::kTalonPDPChannel))
<< "The Talon current was non-zero";
/* Set the motor to full forward */
- m_talon->Set(1.0);
- Wait(kMotorTime);
+ m_talon.Set(1.0);
+ frc::Wait(kMotorTime);
/* The current should now be positive */
- ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), 0)
+ ASSERT_GT(m_pdp.GetCurrent(TestBench::kTalonPDPChannel), 0)
<< "The Talon current was not positive";
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp
index ffb4d9f..5e79f27 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/Preferences.h" // NOLINT(build/include_order)
@@ -12,14 +9,13 @@
#include <networktables/NetworkTableInstance.h>
#include <ntcore.h>
+#include <units/time.h>
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
-
static const char* kFileName = "networktables.ini";
-static const double kSaveTime = 1.2;
+static constexpr auto kSaveTime = 1.2_s;
/**
* If we write a new networktables.ini with some sample values, test that
@@ -28,6 +24,7 @@
TEST(PreferencesTest, ReadPreferencesFromFile) {
auto inst = nt::NetworkTableInstance::GetDefault();
inst.StopServer();
+
std::remove(kFileName);
std::ofstream preferencesFile(kFileName);
preferencesFile << "[NetworkTables Storage 3.0]" << std::endl;
@@ -45,16 +42,17 @@
<< "double \"/Preferences/testFileGetLong\"=1000000000000000000"
<< std::endl;
preferencesFile.close();
+
inst.StartServer();
- Preferences* preferences = Preferences::GetInstance();
EXPECT_EQ("Hello, preferences file",
- preferences->GetString("testFileGetString"));
- EXPECT_EQ(1, preferences->GetInt("testFileGetInt"));
- EXPECT_FLOAT_EQ(0.5, preferences->GetDouble("testFileGetDouble"));
- EXPECT_FLOAT_EQ(0.25f, preferences->GetFloat("testFileGetFloat"));
- EXPECT_TRUE(preferences->GetBoolean("testFileGetBoolean"));
- EXPECT_EQ(1000000000000000000ll, preferences->GetLong("testFileGetLong"));
+ frc::Preferences::GetString("testFileGetString"));
+ EXPECT_EQ(1, frc::Preferences::GetInt("testFileGetInt"));
+ EXPECT_FLOAT_EQ(0.5, frc::Preferences::GetDouble("testFileGetDouble"));
+ EXPECT_FLOAT_EQ(0.25f, frc::Preferences::GetFloat("testFileGetFloat"));
+ EXPECT_TRUE(frc::Preferences::GetBoolean("testFileGetBoolean"));
+ EXPECT_EQ(1000000000000000000ll,
+ frc::Preferences::GetLong("testFileGetLong"));
}
/**
@@ -64,34 +62,33 @@
TEST(PreferencesTest, WritePreferencesToFile) {
auto inst = nt::NetworkTableInstance::GetDefault();
inst.StartServer();
- Preferences* preferences = Preferences::GetInstance();
- preferences->Remove("testFileGetString");
- preferences->Remove("testFileGetInt");
- preferences->Remove("testFileGetDouble");
- preferences->Remove("testFileGetFloat");
- preferences->Remove("testFileGetBoolean");
- preferences->Remove("testFileGetLong");
+ frc::Preferences::Remove("testFileGetString");
+ frc::Preferences::Remove("testFileGetInt");
+ frc::Preferences::Remove("testFileGetDouble");
+ frc::Preferences::Remove("testFileGetFloat");
+ frc::Preferences::Remove("testFileGetBoolean");
+ frc::Preferences::Remove("testFileGetLong");
- Wait(kSaveTime);
+ frc::Wait(kSaveTime);
- preferences->PutString("testFilePutString", "Hello, preferences file");
- preferences->PutInt("testFilePutInt", 1);
- preferences->PutDouble("testFilePutDouble", 0.5);
- preferences->PutFloat("testFilePutFloat", 0.25f);
- preferences->PutBoolean("testFilePutBoolean", true);
- preferences->PutLong("testFilePutLong", 1000000000000000000ll);
+ frc::Preferences::SetString("testFileSetString", "Hello, preferences file");
+ frc::Preferences::SetInt("testFileSetInt", 1);
+ frc::Preferences::SetDouble("testFileSetDouble", 0.5);
+ frc::Preferences::SetFloat("testFileSetFloat", 0.25f);
+ frc::Preferences::SetBoolean("testFileSetBoolean", true);
+ frc::Preferences::SetLong("testFileSetLong", 1000000000000000000ll);
- Wait(kSaveTime);
+ frc::Wait(kSaveTime);
static char const* kExpectedFileContents[] = {
"[NetworkTables Storage 3.0]",
"string \"/Preferences/.type\"=\"RobotPreferences\"",
- "boolean \"/Preferences/testFilePutBoolean\"=true",
- "double \"/Preferences/testFilePutDouble\"=0.5",
- "double \"/Preferences/testFilePutFloat\"=0.25",
- "double \"/Preferences/testFilePutInt\"=1",
- "double \"/Preferences/testFilePutLong\"=1e+18",
- "string \"/Preferences/testFilePutString\"=\"Hello, preferences file\""};
+ "boolean \"/Preferences/testFileSetBoolean\"=true",
+ "double \"/Preferences/testFileSetDouble\"=0.5",
+ "double \"/Preferences/testFileSetFloat\"=0.25",
+ "double \"/Preferences/testFileSetInt\"=1",
+ "double \"/Preferences/testFileSetLong\"=1e+18",
+ "string \"/Preferences/testFileSetString\"=\"Hello, preferences file\""};
std::ifstream preferencesFile(kFileName);
for (auto& kExpectedFileContent : kExpectedFileContents) {
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/PriorityTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/PriorityTest.cpp
new file mode 100644
index 0000000..3085bed
--- /dev/null
+++ b/wpilibcIntegrationTests/src/main/native/cpp/PriorityTest.cpp
@@ -0,0 +1,68 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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 <thread>
+
+#include <wpi/condition_variable.h>
+#include <wpi/mutex.h>
+
+#include "frc/Threads.h"
+#include "gtest/gtest.h"
+
+TEST(PriorityTest, SetThreadPriority) {
+ bool exited = false;
+ wpi::condition_variable cond;
+ wpi::mutex mutex;
+ std::thread thr{[&] {
+ std::unique_lock lock{mutex};
+ cond.wait(lock, [&] { return exited; });
+ }};
+
+ // Non-RT thread has priority of zero
+ bool isRealTime = false;
+ EXPECT_EQ(0, frc::GetThreadPriority(thr, &isRealTime));
+ EXPECT_FALSE(isRealTime);
+
+ // Set thread priority to 15
+ EXPECT_TRUE(frc::SetThreadPriority(thr, true, 15));
+
+ // Verify thread was given priority 15
+ EXPECT_EQ(15, frc::GetThreadPriority(thr, &isRealTime));
+ EXPECT_TRUE(isRealTime);
+
+ // Set thread back to non-RT
+ EXPECT_TRUE(frc::SetThreadPriority(thr, false, 0));
+
+ // Verify thread is now non-RT
+ EXPECT_EQ(0, frc::GetThreadPriority(thr, &isRealTime));
+ EXPECT_FALSE(isRealTime);
+
+ {
+ std::scoped_lock lock{mutex};
+ exited = true;
+ }
+ cond.notify_one();
+ thr.join();
+}
+
+TEST(PriorityTest, SetCurrentThreadPriority) {
+ // Non-RT thread has priority of zero
+ bool isRealTime = true;
+ EXPECT_EQ(0, frc::GetCurrentThreadPriority(&isRealTime));
+ EXPECT_FALSE(isRealTime);
+
+ // Set thread priority to 15
+ EXPECT_TRUE(frc::SetCurrentThreadPriority(true, 15));
+
+ // Verify thread was given priority 15
+ EXPECT_EQ(15, frc::GetCurrentThreadPriority(&isRealTime));
+ EXPECT_TRUE(isRealTime);
+
+ // Set thread back to non-RT
+ EXPECT_TRUE(frc::SetCurrentThreadPriority(false, 0));
+
+ // Verify thread is now non-RT
+ EXPECT_EQ(0, frc::GetCurrentThreadPriority(&isRealTime));
+ EXPECT_FALSE(isRealTime);
+}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/RelayTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/RelayTest.cpp
index eb45eeb..cf3cfdf 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/RelayTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/RelayTest.cpp
@@ -1,93 +1,72 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/Relay.h" // NOLINT(build/include_order)
+#include <units/time.h>
+
#include "TestBench.h"
#include "frc/DigitalInput.h"
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
+static constexpr auto kDelayTime = 10_ms;
-static const double kDelayTime = 0.01;
+TEST(RelayTest, BothDirections) {
+ frc::Relay relay{TestBench::kRelayChannel};
+ frc::DigitalInput forward{TestBench::kFakeRelayForward};
+ frc::DigitalInput reverse{TestBench::kFakeRelayReverse};
-class RelayTest : public testing::Test {
- protected:
- Relay* m_relay;
- DigitalInput* m_forward;
- DigitalInput* m_reverse;
+ // Set the relay to forward
+ relay.Set(frc::Relay::kForward);
+ frc::Wait(kDelayTime);
+ EXPECT_TRUE(forward.Get()) << "Relay did not set forward";
+ EXPECT_FALSE(reverse.Get()) << "Relay did not set forward";
+ EXPECT_EQ(relay.Get(), frc::Relay::kForward);
- void SetUp() override {
- m_relay = new Relay(TestBench::kRelayChannel);
- m_forward = new DigitalInput(TestBench::kFakeRelayForward);
- m_reverse = new DigitalInput(TestBench::kFakeRelayReverse);
- }
+ // Set the relay to reverse
+ relay.Set(frc::Relay::kReverse);
+ frc::Wait(kDelayTime);
+ EXPECT_TRUE(reverse.Get()) << "Relay did not set reverse";
+ EXPECT_FALSE(forward.Get()) << "Relay did not set reverse";
+ EXPECT_EQ(relay.Get(), frc::Relay::kReverse);
- void TearDown() override {
- delete m_relay;
- delete m_forward;
- delete m_reverse;
- }
+ // Set the relay to off
+ relay.Set(frc::Relay::kOff);
+ frc::Wait(kDelayTime);
+ EXPECT_FALSE(forward.Get()) << "Relay did not set off";
+ EXPECT_FALSE(reverse.Get()) << "Relay did not set off";
+ EXPECT_EQ(relay.Get(), frc::Relay::kOff);
- void Reset() { m_relay->Set(Relay::kOff); }
-};
+ // Set the relay to on
+ relay.Set(frc::Relay::kOn);
+ frc::Wait(kDelayTime);
+ EXPECT_TRUE(forward.Get()) << "Relay did not set on";
+ EXPECT_TRUE(reverse.Get()) << "Relay did not set on";
+ EXPECT_EQ(relay.Get(), frc::Relay::kOn);
+}
-/**
- * Test the relay by setting it forward, reverse, off, and on.
- */
-TEST_F(RelayTest, Relay) {
- Reset();
+TEST(RelayTest, ForwardOnly) {
+ frc::Relay relay{TestBench::kRelayChannel, frc::Relay::kForwardOnly};
+ frc::DigitalInput forward{TestBench::kFakeRelayForward};
+ frc::DigitalInput reverse{TestBench::kFakeRelayReverse};
- // set the relay to forward
- m_relay->Set(Relay::kForward);
- Wait(kDelayTime);
- EXPECT_TRUE(m_forward->Get()) << "Relay did not set forward";
- EXPECT_FALSE(m_reverse->Get()) << "Relay did not set forward";
- EXPECT_EQ(m_relay->Get(), Relay::kForward);
+ relay.Set(frc::Relay::kOn);
+ frc::Wait(kDelayTime);
+ EXPECT_TRUE(forward.Get()) << "Relay did not set forward";
+ EXPECT_FALSE(reverse.Get()) << "Relay did not set forward";
+ EXPECT_EQ(relay.Get(), frc::Relay::kOn);
+}
- // set the relay to reverse
- m_relay->Set(Relay::kReverse);
- Wait(kDelayTime);
- EXPECT_TRUE(m_reverse->Get()) << "Relay did not set reverse";
- EXPECT_FALSE(m_forward->Get()) << "Relay did not set reverse";
- EXPECT_EQ(m_relay->Get(), Relay::kReverse);
+TEST(RelayTest, ReverseOnly) {
+ frc::Relay relay{TestBench::kRelayChannel, frc::Relay::kReverseOnly};
+ frc::DigitalInput forward{TestBench::kFakeRelayForward};
+ frc::DigitalInput reverse{TestBench::kFakeRelayReverse};
- // set the relay to off
- m_relay->Set(Relay::kOff);
- Wait(kDelayTime);
- EXPECT_FALSE(m_forward->Get()) << "Relay did not set off";
- EXPECT_FALSE(m_reverse->Get()) << "Relay did not set off";
- EXPECT_EQ(m_relay->Get(), Relay::kOff);
-
- // set the relay to on
- m_relay->Set(Relay::kOn);
- Wait(kDelayTime);
- EXPECT_TRUE(m_forward->Get()) << "Relay did not set on";
- EXPECT_TRUE(m_reverse->Get()) << "Relay did not set on";
- EXPECT_EQ(m_relay->Get(), Relay::kOn);
-
- // test forward direction
- delete m_relay;
- m_relay = new Relay(TestBench::kRelayChannel, Relay::kForwardOnly);
-
- m_relay->Set(Relay::kOn);
- Wait(kDelayTime);
- EXPECT_TRUE(m_forward->Get()) << "Relay did not set forward";
- EXPECT_FALSE(m_reverse->Get()) << "Relay did not set forward";
- EXPECT_EQ(m_relay->Get(), Relay::kOn);
-
- // test reverse direction
- delete m_relay;
- m_relay = new Relay(TestBench::kRelayChannel, Relay::kReverseOnly);
-
- m_relay->Set(Relay::kOn);
- Wait(kDelayTime);
- EXPECT_FALSE(m_forward->Get()) << "Relay did not set reverse";
- EXPECT_TRUE(m_reverse->Get()) << "Relay did not set reverse";
- EXPECT_EQ(m_relay->Get(), Relay::kOn);
+ relay.Set(frc::Relay::kOn);
+ frc::Wait(kDelayTime);
+ EXPECT_FALSE(forward.Get()) << "Relay did not set reverse";
+ EXPECT_TRUE(reverse.Get()) << "Relay did not set reverse";
+ EXPECT_EQ(relay.Get(), frc::Relay::kOn);
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp b/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp
index 2bfe1b3..1f5e360 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp
@@ -1,66 +1,65 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <cstdlib>
+#include <thread>
+#include <fmt/core.h>
#include <hal/HAL.h>
-#include <wpi/raw_ostream.h>
#include "frc/DriverStation.h"
-#include "frc/Timer.h"
#include "frc/livewindow/LiveWindow.h"
#include "gtest/gtest.h"
#include "mockds/MockDS.h"
-using namespace frc;
+using namespace std::chrono_literals;
class TestEnvironment : public testing::Environment {
bool m_alreadySetUp = false;
MockDS m_mockDS;
public:
- void SetUp() override {
- /* Only set up once. This allows gtest_repeat to be used to
- automatically repeat tests. */
- if (m_alreadySetUp) return;
+ TestEnvironment() {
+ // Only set up once. This allows gtest_repeat to be used to automatically
+ // repeat tests.
+ if (m_alreadySetUp) {
+ return;
+ }
m_alreadySetUp = true;
if (!HAL_Initialize(500, 0)) {
- wpi::errs() << "FATAL ERROR: HAL could not be initialized\n";
+ fmt::print(stderr, "FATAL ERROR: HAL could not be initialized\n");
std::exit(-1);
}
- m_mockDS.start();
+ m_mockDS.Start();
- /* This sets up the network communications library to enable the driver
- station. After starting network coms, it will loop until the driver
- station returns that the robot is enabled, to ensure that tests
- will be able to run on the hardware. */
+ // This sets up the network communications library to enable the driver
+ // station. After starting network coms, it will loop until the driver
+ // station returns that the robot is enabled, to ensure that tests will be
+ // able to run on the hardware.
HAL_ObserveUserProgramStarting();
- LiveWindow::GetInstance()->SetEnabled(false);
+ frc::LiveWindow::SetEnabled(false);
- wpi::outs() << "Started coms\n";
+ fmt::print("Started coms\n");
int enableCounter = 0;
- while (!DriverStation::GetInstance().IsEnabled()) {
+ while (!frc::DriverStation::IsEnabled()) {
if (enableCounter > 50) {
// Robot did not enable properly after 5 seconds.
// Force exit
- wpi::errs() << " Failed to enable. Aborting\n";
+ fmt::print(stderr, " Failed to enable. Aborting\n");
std::terminate();
}
- Wait(0.1);
+ std::this_thread::sleep_for(100ms);
- wpi::outs() << "Waiting for enable: " << enableCounter++ << "\n";
+ fmt::print("Waiting for enable: {}\n", enableCounter++);
}
}
- void TearDown() override { m_mockDS.stop(); }
+ ~TestEnvironment() override { m_mockDS.Stop(); }
};
testing::Environment* const environment =
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/TiltPanCameraTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/TiltPanCameraTest.cpp
index 852429b..42e52fc 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/TiltPanCameraTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/TiltPanCameraTest.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <cmath>
+#include <units/time.h>
+
#include "TestBench.h"
#include "frc/ADXL345_SPI.h"
#include "frc/AnalogGyro.h"
@@ -14,137 +13,79 @@
#include "frc/Timer.h"
#include "gtest/gtest.h"
-using namespace frc;
-
-static constexpr double kServoResetTime = 2.0;
-
-static constexpr double kTestAngle = 90.0;
-
static constexpr double kTiltSetpoint0 = 0.22;
static constexpr double kTiltSetpoint45 = 0.45;
static constexpr double kTiltSetpoint90 = 0.68;
-static constexpr double kTiltTime = 1.0;
-static constexpr double kAccelerometerTolerance = 0.2;
-static constexpr double kSensitivity = 0.013;
/**
* A fixture for the camera with two servos and a gyro
*/
class TiltPanCameraTest : public testing::Test {
protected:
- static AnalogGyro* m_gyro;
- Servo *m_tilt, *m_pan;
- Accelerometer* m_spiAccel;
+ frc::Servo m_tilt{TestBench::kCameraTiltChannel};
+ frc::Servo m_pan{TestBench::kCameraPanChannel};
+ frc::ADXL345_SPI m_spiAccel{frc::SPI::kOnboardCS1};
- static void SetUpTestCase() {
- // The gyro object blocks for 5 seconds in the constructor, so only
- // construct it once for the whole test case
- m_gyro = new AnalogGyro(TestBench::kCameraGyroChannel);
- m_gyro->SetSensitivity(kSensitivity);
+ TiltPanCameraTest() {
+ m_tilt.Set(kTiltSetpoint45);
+ m_pan.SetAngle(0.0);
+
+ // Wait for servos to reset
+ frc::Wait(2_s);
}
- static void TearDownTestCase() { delete m_gyro; }
+ /**
+ * Test if the servo turns 90 degrees and the gyroscope measures this angle
+ * Note servo on TestBench is not the same type of servo that servo class
+ * was designed for so setAngle is significantly off. This has been calibrated
+ * for the servo on the rig.
+ */
+ void GyroTests(frc::AnalogGyro& gyro) {
+ gyro.SetSensitivity(0.013);
- void SetUp() override {
- m_tilt = new Servo(TestBench::kCameraTiltChannel);
- m_pan = new Servo(TestBench::kCameraPanChannel);
- m_spiAccel = new ADXL345_SPI(SPI::kOnboardCS1);
+ gyro.Reset();
- m_tilt->Set(kTiltSetpoint45);
- m_pan->SetAngle(0.0);
+ // Accumulator needs a small amount of time to reset before being tested
+ frc::Wait(1_ms);
- Wait(kServoResetTime);
+ // Verify the gyro angle defaults to 0 immediately after being reset
+ EXPECT_NEAR(0.0, gyro.GetAngle(), 1.0);
- m_gyro->Reset();
- }
+ // Make sure that the gyro doesn't get jerked when the servo goes to zero.
+ m_pan.SetAngle(0.0);
+ frc::Wait(0.5_s);
+ gyro.Reset();
- void DefaultGyroAngle();
- void GyroAngle();
- void GyroCalibratedParameters();
+ for (int32_t i = 0; i < 600; i++) {
+ m_pan.Set(i / 1000.0);
+ frc::Wait(1_ms);
+ }
- void TearDown() override {
- delete m_tilt;
- delete m_pan;
- delete m_spiAccel;
+ double gyroAngle = gyro.GetAngle();
+
+ EXPECT_NEAR(gyroAngle, 90.0, 10.0)
+ << "Gyro measured " << gyroAngle
+ << " degrees, servo should have turned 90 degrees";
}
};
-AnalogGyro* TiltPanCameraTest::m_gyro = nullptr;
+TEST_F(TiltPanCameraTest, Gyro) {
+ int cCenter;
+ double cOffset;
-/**
- * Test if the gyro angle defaults to 0 immediately after being reset.
- */
-void TiltPanCameraTest::DefaultGyroAngle() {
- EXPECT_NEAR(0.0, m_gyro->GetAngle(), 1.0);
-}
+ {
+ frc::AnalogGyro gyro{TestBench::kCameraGyroChannel};
+ GyroTests(gyro);
-/**
- * Test if the servo turns 90 degrees and the gyroscope measures this angle
- * Note servo on TestBench is not the same type of servo that servo class
- * was designed for so setAngle is significantly off. This has been calibrated
- * for the servo on the rig.
- */
-void TiltPanCameraTest::GyroAngle() {
- // Make sure that the gyro doesn't get jerked when the servo goes to zero.
- m_pan->SetAngle(0.0);
- Wait(0.5);
- m_gyro->Reset();
-
- for (int32_t i = 0; i < 600; i++) {
- m_pan->Set(i / 1000.0);
- Wait(0.001);
+ // Gets calibrated parameters from previously calibrated gyro, allocates a
+ // new gyro with the given parameters for center and offset, and re-runs
+ // tests on the new gyro.
+ cCenter = gyro.GetCenter();
+ cOffset = gyro.GetOffset();
}
- double gyroAngle = m_gyro->GetAngle();
-
- EXPECT_NEAR(gyroAngle, kTestAngle, 10.0)
- << "Gyro measured " << gyroAngle << " degrees, servo should have turned "
- << kTestAngle << " degrees";
-}
-
-/**
- * Gets calibrated parameters from previously calibrated gyro, allocates a new
- * gyro with the given parameters for center and offset, and re-runs tests on
- * the new gyro.
- */
-void TiltPanCameraTest::GyroCalibratedParameters() {
- uint32_t cCenter = m_gyro->GetCenter();
- double cOffset = m_gyro->GetOffset();
- delete m_gyro;
- m_gyro = new AnalogGyro(TestBench::kCameraGyroChannel, cCenter, cOffset);
- m_gyro->SetSensitivity(kSensitivity);
-
- // Default gyro angle test
- // Accumulator needs a small amount of time to reset before being tested
- m_gyro->Reset();
- Wait(0.001);
- EXPECT_NEAR(0.0, m_gyro->GetAngle(), 1.0);
-
- // Gyro angle test
- // Make sure that the gyro doesn't get jerked when the servo goes to zero.
- m_pan->SetAngle(0.0);
- Wait(0.5);
- m_gyro->Reset();
-
- for (int32_t i = 0; i < 600; i++) {
- m_pan->Set(i / 1000.0);
- Wait(0.001);
- }
-
- double gyroAngle = m_gyro->GetAngle();
-
- EXPECT_NEAR(gyroAngle, kTestAngle, 10.0)
- << "Gyro measured " << gyroAngle << " degrees, servo should have turned "
- << kTestAngle << " degrees";
-}
-
-/**
- * Run all gyro tests in one function to make sure they are run in order.
- */
-TEST_F(TiltPanCameraTest, TestAllGyroTests) {
- DefaultGyroAngle();
- GyroAngle();
- GyroCalibratedParameters();
+ frc::AnalogGyro gyro{TestBench::kCameraGyroChannel, cCenter, cOffset};
+ GyroTests(gyro);
}
/**
@@ -152,21 +93,24 @@
* camera rotates
*/
TEST_F(TiltPanCameraTest, SPIAccelerometer) {
- m_tilt->Set(kTiltSetpoint0);
- Wait(kTiltTime);
- EXPECT_NEAR(-1.0, m_spiAccel->GetX(), kAccelerometerTolerance);
- EXPECT_NEAR(0.0, m_spiAccel->GetY(), kAccelerometerTolerance);
- EXPECT_NEAR(0.0, m_spiAccel->GetZ(), kAccelerometerTolerance);
+ static constexpr auto kTiltTime = 1_s;
+ static constexpr double kAccelerometerTolerance = 0.2;
- m_tilt->Set(kTiltSetpoint45);
- Wait(kTiltTime);
- EXPECT_NEAR(-std::sqrt(0.5), m_spiAccel->GetX(), kAccelerometerTolerance);
- EXPECT_NEAR(0.0, m_spiAccel->GetY(), kAccelerometerTolerance);
- EXPECT_NEAR(std::sqrt(0.5), m_spiAccel->GetZ(), kAccelerometerTolerance);
+ m_tilt.Set(kTiltSetpoint0);
+ frc::Wait(kTiltTime);
+ EXPECT_NEAR(-1.0, m_spiAccel.GetX(), kAccelerometerTolerance);
+ EXPECT_NEAR(0.0, m_spiAccel.GetY(), kAccelerometerTolerance);
+ EXPECT_NEAR(0.0, m_spiAccel.GetZ(), kAccelerometerTolerance);
- m_tilt->Set(kTiltSetpoint90);
- Wait(kTiltTime);
- EXPECT_NEAR(0.0, m_spiAccel->GetX(), kAccelerometerTolerance);
- EXPECT_NEAR(0.0, m_spiAccel->GetY(), kAccelerometerTolerance);
- EXPECT_NEAR(1.0, m_spiAccel->GetZ(), kAccelerometerTolerance);
+ m_tilt.Set(kTiltSetpoint45);
+ frc::Wait(kTiltTime);
+ EXPECT_NEAR(-std::sqrt(0.5), m_spiAccel.GetX(), kAccelerometerTolerance);
+ EXPECT_NEAR(0.0, m_spiAccel.GetY(), kAccelerometerTolerance);
+ EXPECT_NEAR(std::sqrt(0.5), m_spiAccel.GetZ(), kAccelerometerTolerance);
+
+ m_tilt.Set(kTiltSetpoint90);
+ frc::Wait(kTiltTime);
+ EXPECT_NEAR(0.0, m_spiAccel.GetX(), kAccelerometerTolerance);
+ EXPECT_NEAR(0.0, m_spiAccel.GetY(), kAccelerometerTolerance);
+ EXPECT_NEAR(1.0, m_spiAccel.GetZ(), kAccelerometerTolerance);
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/TimerTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/TimerTest.cpp
index b8f859c..99ec9f5 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/TimerTest.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/TimerTest.cpp
@@ -1,41 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "frc/Timer.h" // NOLINT(build/include_order)
-#include "TestBench.h"
+#include <units/math.h>
+
#include "gtest/gtest.h"
-using namespace frc;
+#define EXPECT_NEAR_UNITS(val1, val2, eps) \
+ EXPECT_LE(units::math::abs(val1 - val2), eps)
-static const double kWaitTime = 0.5;
+TEST(TimerTest, Wait) {
+ auto initialTime = frc::Timer::GetFPGATimestamp();
-class TimerTest : public testing::Test {
- protected:
- Timer* m_timer;
+ frc::Wait(500_ms);
- void SetUp() override { m_timer = new Timer; }
+ auto finalTime = frc::Timer::GetFPGATimestamp();
- void TearDown() override { delete m_timer; }
-
- void Reset() { m_timer->Reset(); }
-};
-
-/**
- * Test if the Wait function works
- */
-TEST_F(TimerTest, Wait) {
- Reset();
-
- double initialTime = m_timer->GetFPGATimestamp();
-
- Wait(kWaitTime);
-
- double finalTime = m_timer->GetFPGATimestamp();
-
- EXPECT_NEAR(kWaitTime, finalTime - initialTime, 0.001);
+ EXPECT_NEAR_UNITS(500_ms, finalTime - initialTime, 1_ms);
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/command/CommandTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/command/CommandTest.cpp
deleted file mode 100644
index fec442a..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/command/CommandTest.cpp
+++ /dev/null
@@ -1,440 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "command/MockCommand.h"
-#include "frc/DriverStation.h"
-#include "frc/RobotState.h"
-#include "frc/Timer.h"
-#include "frc/commands/CommandGroup.h"
-#include "frc/commands/Scheduler.h"
-#include "frc/commands/Subsystem.h"
-#include "gtest/gtest.h"
-
-using namespace frc;
-
-class CommandTest : public testing::Test {
- protected:
- void SetUp() override { Scheduler::GetInstance()->SetEnabled(true); }
-
- /**
- * Tears Down the Scheduler at the end of each test.
- * Must be called at the end of each test inside each test in order to prevent
- * them being deallocated
- * when they leave the scope of the test (causing a segfault).
- * This can not be done within the virtual void Teardown() method because it
- * is called outside of the
- * scope of the test.
- */
- void TeardownScheduler() { Scheduler::GetInstance()->ResetAll(); }
-
- void AssertCommandState(MockCommand* command, int32_t initialize,
- int32_t execute, int32_t isFinished, int32_t end,
- int32_t interrupted) {
- EXPECT_EQ(initialize, command->GetInitializeCount());
- EXPECT_EQ(execute, command->GetExecuteCount());
- EXPECT_EQ(isFinished, command->GetIsFinishedCount());
- EXPECT_EQ(end, command->GetEndCount());
- EXPECT_EQ(interrupted, command->GetInterruptedCount());
- }
-};
-
-class ASubsystem : public Subsystem {
- private:
- Command* m_command = nullptr;
-
- public:
- explicit ASubsystem(const std::string& name) : Subsystem(name) {}
-
- void InitDefaultCommand() override {
- if (m_command != nullptr) {
- SetDefaultCommand(m_command);
- }
- }
-
- void Init(Command* command) { m_command = command; }
-};
-
-// CommandParallelGroupTest ported from CommandParallelGroupTest.java
-TEST_F(CommandTest, ParallelCommands) {
- auto command1 = new MockCommand;
- auto command2 = new MockCommand;
- CommandGroup commandGroup;
-
- commandGroup.AddParallel(command1);
- commandGroup.AddParallel(command2);
-
- AssertCommandState(command1, 0, 0, 0, 0, 0);
- AssertCommandState(command2, 0, 0, 0, 0, 0);
- commandGroup.Start();
- AssertCommandState(command1, 0, 0, 0, 0, 0);
- AssertCommandState(command2, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 0, 0, 0, 0, 0);
- AssertCommandState(command2, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 0);
- AssertCommandState(command2, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 2, 2, 0, 0);
- AssertCommandState(command2, 1, 2, 2, 0, 0);
- command1->SetHasFinished(true);
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 3, 3, 1, 0);
- AssertCommandState(command2, 1, 3, 3, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 3, 3, 1, 0);
- AssertCommandState(command2, 1, 4, 4, 0, 0);
- command2->SetHasFinished(true);
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 3, 3, 1, 0);
- AssertCommandState(command2, 1, 5, 5, 1, 0);
-
- TeardownScheduler();
-}
-// END CommandParallelGroupTest
-
-// CommandScheduleTest ported from CommandScheduleTest.java
-TEST_F(CommandTest, RunAndTerminate) {
- MockCommand command;
- command.Start();
- AssertCommandState(&command, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 2, 2, 0, 0);
- command.SetHasFinished(true);
- AssertCommandState(&command, 1, 2, 2, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 3, 3, 1, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 3, 3, 1, 0);
-
- TeardownScheduler();
-}
-
-TEST_F(CommandTest, RunAndCancel) {
- MockCommand command;
- command.Start();
- AssertCommandState(&command, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 2, 2, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 3, 3, 0, 0);
- command.Cancel();
- AssertCommandState(&command, 1, 3, 3, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 3, 3, 0, 1);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 3, 3, 0, 1);
-
- TeardownScheduler();
-}
-// END CommandScheduleTest
-
-// CommandSequentialGroupTest ported from CommandSequentialGroupTest.java
-TEST_F(CommandTest, ThreeCommandOnSubSystem) {
- ASubsystem subsystem("Three Command Test Subsystem");
- auto command1 = new MockCommand;
- command1->Requires(&subsystem);
- auto command2 = new MockCommand;
- command2->Requires(&subsystem);
- auto command3 = new MockCommand;
- command3->Requires(&subsystem);
-
- CommandGroup commandGroup;
- commandGroup.AddSequential(command1, 1.0);
- commandGroup.AddSequential(command2, 2.0);
- commandGroup.AddSequential(command3);
-
- AssertCommandState(command1, 0, 0, 0, 0, 0);
- AssertCommandState(command2, 0, 0, 0, 0, 0);
- AssertCommandState(command3, 0, 0, 0, 0, 0);
-
- commandGroup.Start();
- AssertCommandState(command1, 0, 0, 0, 0, 0);
- AssertCommandState(command2, 0, 0, 0, 0, 0);
- AssertCommandState(command3, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 0, 0, 0, 0, 0);
- AssertCommandState(command2, 0, 0, 0, 0, 0);
- AssertCommandState(command3, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 0);
- AssertCommandState(command2, 0, 0, 0, 0, 0);
- AssertCommandState(command3, 0, 0, 0, 0, 0);
- Wait(1); // command 1 timeout
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 1);
- AssertCommandState(command2, 1, 1, 1, 0, 0);
- AssertCommandState(command3, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 1);
- AssertCommandState(command2, 1, 2, 2, 0, 0);
- AssertCommandState(command3, 0, 0, 0, 0, 0);
- Wait(2); // command 2 timeout
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 1);
- AssertCommandState(command2, 1, 2, 2, 0, 1);
- AssertCommandState(command3, 1, 1, 1, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 1);
- AssertCommandState(command2, 1, 2, 2, 0, 1);
- AssertCommandState(command3, 1, 2, 2, 0, 0);
- command3->SetHasFinished(true);
- AssertCommandState(command1, 1, 1, 1, 0, 1);
- AssertCommandState(command2, 1, 2, 2, 0, 1);
- AssertCommandState(command3, 1, 2, 2, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 1);
- AssertCommandState(command2, 1, 2, 2, 0, 1);
- AssertCommandState(command3, 1, 3, 3, 1, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(command1, 1, 1, 1, 0, 1);
- AssertCommandState(command2, 1, 2, 2, 0, 1);
- AssertCommandState(command3, 1, 3, 3, 1, 0);
-
- TeardownScheduler();
-}
-// END CommandSequentialGroupTest
-
-// CommandSequentialGroupTest ported from CommandSequentialGroupTest.java
-TEST_F(CommandTest, OneCommandSupersedingAnotherBecauseOfDependencies) {
- ASubsystem subsystem("Command Superseding Test Subsystem");
- MockCommand command1;
- command1.Requires(&subsystem);
- MockCommand command2;
- command2.Requires(&subsystem);
-
- AssertCommandState(&command1, 0, 0, 0, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- command1.Start();
- AssertCommandState(&command1, 0, 0, 0, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 0, 0, 0, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 1, 1, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 2, 2, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 3, 3, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- command2.Start();
- AssertCommandState(&command1, 1, 3, 3, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 4, 4, 0, 1);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 4, 4, 0, 1);
- AssertCommandState(&command2, 1, 1, 1, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 4, 4, 0, 1);
- AssertCommandState(&command2, 1, 2, 2, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 4, 4, 0, 1);
- AssertCommandState(&command2, 1, 3, 3, 0, 0);
-
- TeardownScheduler();
-}
-
-TEST_F(CommandTest,
- OneCommandFailingSupersedingBecauseFirstCanNotBeInterrupted) {
- ASubsystem subsystem("Command Superseding Test Subsystem");
- MockCommand command1;
-
- command1.Requires(&subsystem);
-
- command1.SetInterruptible(false);
- MockCommand command2;
- command2.Requires(&subsystem);
-
- AssertCommandState(&command1, 0, 0, 0, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- command1.Start();
- AssertCommandState(&command1, 0, 0, 0, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 0, 0, 0, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 1, 1, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 2, 2, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 3, 3, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- command2.Start();
- AssertCommandState(&command1, 1, 3, 3, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command1, 1, 4, 4, 0, 0);
- AssertCommandState(&command2, 0, 0, 0, 0, 0);
-
- TeardownScheduler();
-}
-
-// END CommandSequentialGroupTest
-
-class ModifiedMockCommand : public MockCommand {
- public:
- ModifiedMockCommand() : MockCommand() { SetTimeout(2.0); }
- bool IsFinished() override {
- return MockCommand::IsFinished() || IsTimedOut();
- }
-};
-
-TEST_F(CommandTest, TwoSecondTimeout) {
- ASubsystem subsystem("Two Second Timeout Test Subsystem");
- ModifiedMockCommand command;
- command.Requires(&subsystem);
-
- command.Start();
- AssertCommandState(&command, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 2, 2, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 3, 3, 0, 0);
- Wait(2);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 4, 4, 1, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(&command, 1, 4, 4, 1, 0);
-
- TeardownScheduler();
-}
-
-TEST_F(CommandTest, DefaultCommandWhereTheInteruptingCommandEndsItself) {
- ASubsystem subsystem("Default Command Test Subsystem");
- auto defaultCommand = new MockCommand;
- defaultCommand->Requires(&subsystem);
- MockCommand anotherCommand;
- anotherCommand.Requires(&subsystem);
-
- AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
- subsystem.Init(defaultCommand);
-
- AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);
-
- anotherCommand.Start();
- AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);
- AssertCommandState(&anotherCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 2, 2, 0, 0);
- anotherCommand.SetHasFinished(true);
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 2, 2, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 3, 3, 1, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 2, 4, 4, 0, 1);
- AssertCommandState(&anotherCommand, 1, 3, 3, 1, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 2, 5, 5, 0, 1);
- AssertCommandState(&anotherCommand, 1, 3, 3, 1, 0);
-
- TeardownScheduler();
-}
-
-TEST_F(CommandTest, DefaultCommandsInterruptingCommandCanceled) {
- ASubsystem subsystem("Default Command Test Subsystem");
- auto defaultCommand = new MockCommand;
- defaultCommand->Requires(&subsystem);
- MockCommand anotherCommand;
- anotherCommand.Requires(&subsystem);
-
- AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
- subsystem.Init(defaultCommand);
- AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);
-
- anotherCommand.Start();
- AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);
- AssertCommandState(&anotherCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 0, 0, 0, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 1, 1, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 2, 2, 0, 0);
- anotherCommand.Cancel();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 2, 2, 0, 0);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
- AssertCommandState(&anotherCommand, 1, 2, 2, 0, 1);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 2, 4, 4, 0, 1);
- AssertCommandState(&anotherCommand, 1, 2, 2, 0, 1);
- Scheduler::GetInstance()->Run();
- AssertCommandState(defaultCommand, 2, 5, 5, 0, 1);
- AssertCommandState(&anotherCommand, 1, 2, 2, 0, 1);
-
- TeardownScheduler();
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/command/ConditionalCommandTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/command/ConditionalCommandTest.cpp
deleted file mode 100644
index ca14e55..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/command/ConditionalCommandTest.cpp
+++ /dev/null
@@ -1,435 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "command/MockCommand.h"
-#include "command/MockConditionalCommand.h"
-#include "frc/DriverStation.h"
-#include "frc/RobotState.h"
-#include "frc/commands/ConditionalCommand.h"
-#include "frc/commands/Scheduler.h"
-#include "frc/commands/Subsystem.h"
-#include "gtest/gtest.h"
-
-using namespace frc;
-
-class ConditionalCommandTest : public testing::Test {
- public:
- MockConditionalCommand* m_command;
- MockCommand* m_onTrue;
- MockCommand* m_onFalse;
- MockConditionalCommand* m_commandNull;
- Subsystem* m_subsystem;
-
- protected:
- void SetUp() override {
- Scheduler::GetInstance()->SetEnabled(true);
-
- m_subsystem = new Subsystem("MockSubsystem");
- m_onTrue = new MockCommand(m_subsystem);
- m_onFalse = new MockCommand(m_subsystem);
- m_command = new MockConditionalCommand(m_onTrue, m_onFalse);
- m_commandNull = new MockConditionalCommand(m_onTrue, nullptr);
- }
-
- void TearDown() override { delete m_command; }
-
- /**
- * Tears Down the Scheduler at the end of each test.
- *
- * Must be called at the end of each test inside each test in order to prevent
- * them being deallocated when they leave the scope of the test (causing a
- * segfault). This cannot be done within the virtual void Teardown() method
- * because it is called outside of the scope of the test.
- */
- void TeardownScheduler() { Scheduler::GetInstance()->ResetAll(); }
-
- void AssertCommandState(MockCommand& command, int32_t initialize,
- int32_t execute, int32_t isFinished, int32_t end,
- int32_t interrupted) {
- EXPECT_EQ(initialize, command.GetInitializeCount());
- EXPECT_EQ(execute, command.GetExecuteCount());
- EXPECT_EQ(isFinished, command.GetIsFinishedCount());
- EXPECT_EQ(end, command.GetEndCount());
- EXPECT_EQ(interrupted, command.GetInterruptedCount());
- }
-
- void AssertConditionalCommandState(MockConditionalCommand& command,
- int32_t initialize, int32_t execute,
- int32_t isFinished, int32_t end,
- int32_t interrupted) {
- EXPECT_EQ(initialize, command.GetInitializeCount());
- EXPECT_EQ(execute, command.GetExecuteCount());
- EXPECT_EQ(isFinished, command.GetIsFinishedCount());
- EXPECT_EQ(end, command.GetEndCount());
- EXPECT_EQ(interrupted, command.GetInterruptedCount());
- }
-};
-
-TEST_F(ConditionalCommandTest, OnTrueTest) {
- m_command->SetCondition(true);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 0, 0);
- SCOPED_TRACE("5");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 0);
- SCOPED_TRACE("6");
- m_onTrue->SetHasFinished(true);
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
- SCOPED_TRACE("7");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
-
- EXPECT_TRUE(m_onTrue->GetInitializeCount() > 0)
- << "Did not initialize the true command\n";
- EXPECT_TRUE(m_onFalse->GetInitializeCount() == 0)
- << "Initialized the false command\n";
-
- TeardownScheduler();
-}
-
-TEST_F(ConditionalCommandTest, OnFalseTest) {
- m_command->SetCondition(false);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onFalse, 1, 1, 1, 0, 0);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 0, 0);
- SCOPED_TRACE("5");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onFalse, 1, 2, 2, 0, 0);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 0);
- SCOPED_TRACE("6");
- m_onFalse->SetHasFinished(true);
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onFalse, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
- SCOPED_TRACE("7");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onFalse, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
-
- EXPECT_TRUE(m_onFalse->GetInitializeCount() > 0)
- << "Did not initialize the false command";
- EXPECT_TRUE(m_onTrue->GetInitializeCount() == 0)
- << "Initialized the true command";
-
- TeardownScheduler();
-}
-
-TEST_F(ConditionalCommandTest, CancelSubCommandTest) {
- m_command->SetCondition(true);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 0, 0);
- SCOPED_TRACE("5");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 0);
- SCOPED_TRACE("6");
- m_onTrue->Cancel();
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 1);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
- SCOPED_TRACE("7");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 1);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
-
- TeardownScheduler();
-}
-
-TEST_F(ConditionalCommandTest, CancelCondCommandTest) {
- m_command->SetCondition(true);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 0, 0);
- SCOPED_TRACE("5");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 0);
- SCOPED_TRACE("6");
- m_command->Cancel();
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 1);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 1);
- SCOPED_TRACE("7");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 1);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 1);
-
- TeardownScheduler();
-}
-
-TEST_F(ConditionalCommandTest, OnTrueTwiceTest) {
- m_command->SetCondition(true);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 0, 0);
- SCOPED_TRACE("5");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 0);
- SCOPED_TRACE("6");
- m_onTrue->SetHasFinished(true);
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
- SCOPED_TRACE("7");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
-
- m_onTrue->ResetCounters();
- m_command->ResetCounters();
- Scheduler::GetInstance()->AddCommand(m_command);
-
- SCOPED_TRACE("11");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("12");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("13");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("14");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 0, 0);
- SCOPED_TRACE("15");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 0);
- SCOPED_TRACE("16");
- m_onTrue->SetHasFinished(true);
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
- SCOPED_TRACE("17");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 1, 0);
-
- TeardownScheduler();
-}
-
-TEST_F(ConditionalCommandTest, OnTrueInstantTest) {
- m_command->SetCondition(true);
- m_onTrue->SetHasFinished(true);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 1, 0);
- SCOPED_TRACE("5");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 1, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 1, 0);
-
- TeardownScheduler();
-}
-
-TEST_F(ConditionalCommandTest, CancelRequiresTest) {
- m_command->SetCondition(true);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_command);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 1, 1, 0, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 1, 1, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 2, 2, 0, 0);
- SCOPED_TRACE("5");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 2, 2, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 3, 3, 0, 0);
- SCOPED_TRACE("6");
- m_onFalse->Start();
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 0, 0);
- AssertCommandState(*m_onFalse, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 0, 1);
- SCOPED_TRACE("7");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 1, 3, 3, 0, 1);
- AssertCommandState(*m_onFalse, 1, 1, 1, 0, 0);
- AssertConditionalCommandState(*m_command, 1, 4, 4, 0, 1);
-
- TeardownScheduler();
-}
-
-TEST_F(ConditionalCommandTest, OnFalseNullTest) {
- m_command->SetCondition(false);
-
- SCOPED_TRACE("1");
- Scheduler::GetInstance()->AddCommand(m_commandNull);
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_commandNull, 0, 0, 0, 0, 0);
- SCOPED_TRACE("2");
- Scheduler::GetInstance()->Run(); // init command and select m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_commandNull, 0, 0, 0, 0, 0);
- SCOPED_TRACE("3");
- Scheduler::GetInstance()->Run(); // init m_onTrue
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_commandNull, 1, 1, 1, 1, 0);
- SCOPED_TRACE("4");
- Scheduler::GetInstance()->Run();
- AssertCommandState(*m_onTrue, 0, 0, 0, 0, 0);
- AssertConditionalCommandState(*m_commandNull, 1, 1, 1, 1, 0);
-
- TeardownScheduler();
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/command/MockCommand.cpp b/wpilibcIntegrationTests/src/main/native/cpp/command/MockCommand.cpp
deleted file mode 100644
index bcaed0b..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/command/MockCommand.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "command/MockCommand.h"
-
-using namespace frc;
-
-MockCommand::MockCommand(Subsystem* subsys) : MockCommand() {
- Requires(subsys);
-}
-
-MockCommand::MockCommand() {
- m_initializeCount = 0;
- m_executeCount = 0;
- m_isFinishedCount = 0;
- m_hasFinished = false;
- m_endCount = 0;
- m_interruptedCount = 0;
-}
-
-bool MockCommand::HasInitialized() { return GetInitializeCount() > 0; }
-
-bool MockCommand::HasEnd() { return GetEndCount() > 0; }
-
-bool MockCommand::HasInterrupted() { return GetInterruptedCount() > 0; }
-
-void MockCommand::Initialize() { ++m_initializeCount; }
-
-void MockCommand::Execute() { ++m_executeCount; }
-
-bool MockCommand::IsFinished() {
- ++m_isFinishedCount;
- return IsHasFinished();
-}
-
-void MockCommand::End() { ++m_endCount; }
-
-void MockCommand::Interrupted() { ++m_interruptedCount; }
-
-void MockCommand::ResetCounters() {
- m_initializeCount = 0;
- m_executeCount = 0;
- m_isFinishedCount = 0;
- m_hasFinished = false;
- m_endCount = 0;
- m_interruptedCount = 0;
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/command/MockConditionalCommand.cpp b/wpilibcIntegrationTests/src/main/native/cpp/command/MockConditionalCommand.cpp
deleted file mode 100644
index 9434131..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/command/MockConditionalCommand.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "command/MockConditionalCommand.h"
-
-using namespace frc;
-
-MockConditionalCommand::MockConditionalCommand(MockCommand* onTrue,
- MockCommand* onFalse)
- : ConditionalCommand(onTrue, onFalse) {
- m_initializeCount = 0;
- m_executeCount = 0;
- m_isFinishedCount = 0;
- m_endCount = 0;
- m_interruptedCount = 0;
-}
-
-void MockConditionalCommand::SetCondition(bool condition) {
- m_condition = condition;
-}
-
-bool MockConditionalCommand::Condition() { return m_condition; }
-
-bool MockConditionalCommand::HasInitialized() {
- return GetInitializeCount() > 0;
-}
-
-bool MockConditionalCommand::HasEnd() { return GetEndCount() > 0; }
-
-bool MockConditionalCommand::HasInterrupted() {
- return GetInterruptedCount() > 0;
-}
-
-void MockConditionalCommand::Initialize() { ++m_initializeCount; }
-
-void MockConditionalCommand::Execute() { ++m_executeCount; }
-
-bool MockConditionalCommand::IsFinished() {
- ++m_isFinishedCount;
- return ConditionalCommand::IsFinished();
-}
-
-void MockConditionalCommand::End() { ++m_endCount; }
-
-void MockConditionalCommand::Interrupted() { ++m_interruptedCount; }
-
-void MockConditionalCommand::ResetCounters() {
- m_initializeCount = 0;
- m_executeCount = 0;
- m_isFinishedCount = 0;
- m_endCount = 0;
- m_interruptedCount = 0;
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/main.cpp b/wpilibcIntegrationTests/src/main/native/cpp/main.cpp
deleted file mode 100644
index 1e5ecf0..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/main.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "gtest/gtest.h"
-
-int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
- int ret = RUN_ALL_TESTS();
- return ret;
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.cpp b/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.cpp
index 173a23c..b2e5c2d 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.cpp
+++ b/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.cpp
@@ -1,42 +1,37 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "MockDS.h"
#include <stdint.h>
+#include <string_view>
+
+#include <fmt/core.h>
#include <hal/cpp/fpga_clock.h>
#include <wpi/Logger.h>
-#include <wpi/SmallString.h>
#include <wpi/SmallVector.h>
#include <wpi/UDPClient.h>
-#include <wpi/raw_ostream.h>
static void LoggerFunc(unsigned int level, const char* file, unsigned int line,
const char* msg) {
- wpi::SmallString<128> buf;
- wpi::raw_svector_ostream oss(buf);
if (level == 20) {
- oss << "DS: " << msg << '\n';
- wpi::errs() << oss.str();
+ fmt::print(stderr, "DS: {}\n", msg);
return;
}
- wpi::StringRef levelmsg;
- if (level >= 50)
- levelmsg = "CRITICAL: ";
- else if (level >= 40)
- levelmsg = "ERROR: ";
- else if (level >= 30)
- levelmsg = "WARNING: ";
- else
+ std::string_view levelmsg;
+ if (level >= 50) {
+ levelmsg = "CRITICAL";
+ } else if (level >= 40) {
+ levelmsg = "ERROR";
+ } else if (level >= 30) {
+ levelmsg = "WARNING";
+ } else {
return;
- oss << "DS: " << levelmsg << msg << " (" << file << ':' << line << ")\n";
- wpi::errs() << oss.str();
+ }
+ fmt::print(stderr, "DS: {}: {} ({}:{})\n", levelmsg, msg, file, line);
}
static void generateEnabledDsPacket(wpi::SmallVectorImpl<uint8_t>& data,
@@ -50,10 +45,10 @@
data.push_back(0x00); // red 1 station
}
-using namespace frc;
-
-void MockDS::start() {
- if (m_active) return;
+void MockDS::Start() {
+ if (m_active) {
+ return;
+ }
m_active = true;
m_thread = std::thread([&]() {
wpi::Logger logger(LoggerFunc);
@@ -83,7 +78,9 @@
});
}
-void MockDS::stop() {
+void MockDS::Stop() {
m_active = false;
- if (m_thread.joinable()) m_thread.join();
+ if (m_thread.joinable()) {
+ m_thread.join();
+ }
}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.h b/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.h
index 99b17b1..da5fcd9 100644
--- a/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.h
+++ b/wpilibcIntegrationTests/src/main/native/cpp/mockds/MockDS.h
@@ -1,28 +1,23 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <atomic>
#include <thread>
-namespace frc {
class MockDS {
public:
MockDS() = default;
- ~MockDS() { stop(); }
+ ~MockDS() { Stop(); }
MockDS(const MockDS& other) = delete;
MockDS& operator=(const MockDS& other) = delete;
- void start();
- void stop();
+ void Start();
+ void Stop();
private:
std::thread m_thread;
std::atomic_bool m_active{false};
};
-} // namespace frc
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/MockActuatorSendable.cpp b/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/MockActuatorSendable.cpp
deleted file mode 100644
index 172d7c6..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/MockActuatorSendable.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* 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. */
-/*----------------------------------------------------------------------------*/
-
-#include "shuffleboard/MockActuatorSendable.h"
-
-#include "frc/smartdashboard/SendableRegistry.h"
-
-using namespace frc;
-
-MockActuatorSendable::MockActuatorSendable(wpi::StringRef name) {
- SendableRegistry::GetInstance().Add(this, name);
-}
-
-void MockActuatorSendable::InitSendable(SendableBuilder& builder) {
- builder.SetActuator(true);
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardInstanceTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardInstanceTest.cpp
deleted file mode 100644
index d06f510..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardInstanceTest.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "frc/shuffleboard/ShuffleboardInstance.h" // NOLINT(build/include_order)
-
-#include <memory>
-#include <string>
-
-#include <networktables/NetworkTableEntry.h>
-#include <networktables/NetworkTableInstance.h>
-
-#include "frc/shuffleboard/ShuffleboardInstance.h"
-#include "gtest/gtest.h"
-#include "shuffleboard/MockActuatorSendable.h"
-
-using namespace frc;
-
-class ShuffleboardInstanceTest : public testing::Test {
- void SetUp() override {
- m_ntInstance = nt::NetworkTableInstance::Create();
- m_shuffleboardInstance =
- std::make_unique<detail::ShuffleboardInstance>(m_ntInstance);
- }
-
- protected:
- nt::NetworkTableInstance m_ntInstance;
- std::unique_ptr<detail::ShuffleboardInstance> m_shuffleboardInstance;
-};
-
-TEST_F(ShuffleboardInstanceTest, PathFluent) {
- auto entry = m_shuffleboardInstance->GetTab("Tab Title")
- .GetLayout("List", "List Layout")
- .Add("Data", "string")
- .WithWidget("Text View")
- .GetEntry();
-
- EXPECT_EQ("string", entry.GetString("")) << "Wrong entry value";
- EXPECT_EQ("/Shuffleboard/Tab Title/List/Data", entry.GetName())
- << "Entry path generated incorrectly";
-}
-
-TEST_F(ShuffleboardInstanceTest, NestedLayoutsFluent) {
- auto entry = m_shuffleboardInstance->GetTab("Tab")
- .GetLayout("First", "List")
- .GetLayout("Second", "List")
- .GetLayout("Third", "List")
- .GetLayout("Fourth", "List")
- .Add("Value", "string")
- .GetEntry();
-
- EXPECT_EQ("string", entry.GetString("")) << "Wrong entry value";
- EXPECT_EQ("/Shuffleboard/Tab/First/Second/Third/Fourth/Value",
- entry.GetName())
- << "Entry path generated incorrectly";
-}
-
-TEST_F(ShuffleboardInstanceTest, NestedLayoutsOop) {
- ShuffleboardTab& tab = m_shuffleboardInstance->GetTab("Tab");
- ShuffleboardLayout& first = tab.GetLayout("First", "List");
- ShuffleboardLayout& second = first.GetLayout("Second", "List");
- ShuffleboardLayout& third = second.GetLayout("Third", "List");
- ShuffleboardLayout& fourth = third.GetLayout("Fourth", "List");
- SimpleWidget& widget = fourth.Add("Value", "string");
- auto entry = widget.GetEntry();
-
- EXPECT_EQ("string", entry.GetString("")) << "Wrong entry value";
- EXPECT_EQ("/Shuffleboard/Tab/First/Second/Third/Fourth/Value",
- entry.GetName())
- << "Entry path generated incorrectly";
-}
-
-TEST_F(ShuffleboardInstanceTest, LayoutTypeIsSet) {
- std::string layoutType = "Type";
- m_shuffleboardInstance->GetTab("Tab").GetLayout("Title", layoutType);
- m_shuffleboardInstance->Update();
- nt::NetworkTableEntry entry = m_ntInstance.GetEntry(
- "/Shuffleboard/.metadata/Tab/Title/PreferredComponent");
- EXPECT_EQ(layoutType, entry.GetString("Not Set")) << "Layout type not set";
-}
-
-TEST_F(ShuffleboardInstanceTest, NestedActuatorWidgetsAreDisabled) {
- MockActuatorSendable sendable("Actuator");
- m_shuffleboardInstance->GetTab("Tab")
- .GetLayout("Title", "Layout")
- .Add(sendable);
- auto controllableEntry =
- m_ntInstance.GetEntry("/Shuffleboard/Tab/Title/Actuator/.controllable");
- m_shuffleboardInstance->Update();
-
- // Note: we use the unsafe `GetBoolean()` method because if the value is NOT
- // a boolean, or if it is not present, then something has clearly gone very,
- // very wrong
- bool controllable = controllableEntry.GetValue()->GetBoolean();
- // Sanity check
- EXPECT_TRUE(controllable)
- << "The nested actuator widget should be enabled by default";
- m_shuffleboardInstance->DisableActuatorWidgets();
- controllable = controllableEntry.GetValue()->GetBoolean();
- EXPECT_FALSE(controllable)
- << "The nested actuator widget should have been disabled";
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardTabTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardTabTest.cpp
deleted file mode 100644
index 23f3e3a..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardTabTest.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include <array>
-#include <memory>
-#include <string>
-
-#include <networktables/NetworkTableEntry.h>
-#include <networktables/NetworkTableInstance.h>
-
-#include "frc/commands/InstantCommand.h"
-#include "frc/shuffleboard/ShuffleboardInstance.h"
-#include "frc/shuffleboard/ShuffleboardTab.h"
-#include "frc/smartdashboard/Sendable.h"
-#include "gtest/gtest.h"
-
-using namespace frc;
-
-class ShuffleboardTabTest : public testing::Test {
- void SetUp() override {
- m_ntInstance = nt::NetworkTableInstance::Create();
- m_instance = std::make_unique<detail::ShuffleboardInstance>(m_ntInstance);
- m_tab = &(m_instance->GetTab("Tab"));
- }
-
- protected:
- nt::NetworkTableInstance m_ntInstance;
- ShuffleboardTab* m_tab;
- std::unique_ptr<detail::ShuffleboardInstance> m_instance;
-};
-
-TEST_F(ShuffleboardTabTest, AddDouble) {
- auto entry = m_tab->Add("Double", 1.0).GetEntry();
- EXPECT_EQ("/Shuffleboard/Tab/Double", entry.GetName());
- EXPECT_FLOAT_EQ(1.0, entry.GetValue()->GetDouble());
-}
-
-TEST_F(ShuffleboardTabTest, AddInteger) {
- auto entry = m_tab->Add("Int", 1).GetEntry();
- EXPECT_EQ("/Shuffleboard/Tab/Int", entry.GetName());
- EXPECT_FLOAT_EQ(1.0, entry.GetValue()->GetDouble());
-}
-
-TEST_F(ShuffleboardTabTest, AddBoolean) {
- auto entry = m_tab->Add("Bool", false).GetEntry();
- EXPECT_EQ("/Shuffleboard/Tab/Bool", entry.GetName());
- EXPECT_FALSE(entry.GetValue()->GetBoolean());
-}
-
-TEST_F(ShuffleboardTabTest, AddString) {
- auto entry = m_tab->Add("String", "foobar").GetEntry();
- EXPECT_EQ("/Shuffleboard/Tab/String", entry.GetName());
- EXPECT_EQ("foobar", entry.GetValue()->GetString());
-}
-
-TEST_F(ShuffleboardTabTest, AddNamedSendableWithProperties) {
- InstantCommand sendable("Command");
- std::string widgetType = "Command Widget";
- wpi::StringMap<std::shared_ptr<nt::Value>> map;
- map.try_emplace("foo", nt::Value::MakeDouble(1234));
- map.try_emplace("bar", nt::Value::MakeString("baz"));
- m_tab->Add(sendable).WithWidget(widgetType).WithProperties(map);
-
- m_instance->Update();
- std::string meta = "/Shuffleboard/.metadata/Tab/Command";
-
- EXPECT_EQ(1234, m_ntInstance.GetEntry(meta + "/Properties/foo").GetDouble(-1))
- << "Property 'foo' not set correctly";
- EXPECT_EQ("baz",
- m_ntInstance.GetEntry(meta + "/Properties/bar").GetString(""))
- << "Property 'bar' not set correctly";
- EXPECT_EQ(widgetType,
- m_ntInstance.GetEntry(meta + "/PreferredComponent").GetString(""))
- << "Preferred component not set correctly";
-}
-
-TEST_F(ShuffleboardTabTest, AddNumberArray) {
- std::array<double, 3> expect = {{1.0, 2.0, 3.0}};
- auto entry = m_tab->Add("DoubleArray", expect).GetEntry();
- EXPECT_EQ("/Shuffleboard/Tab/DoubleArray", entry.GetName());
-
- auto actual = entry.GetValue()->GetDoubleArray();
- EXPECT_EQ(expect.size(), actual.size());
- for (size_t i = 0; i < expect.size(); i++) {
- EXPECT_FLOAT_EQ(expect[i], actual[i]);
- }
-}
-
-TEST_F(ShuffleboardTabTest, AddBooleanArray) {
- std::array<bool, 2> expect = {{true, false}};
- auto entry = m_tab->Add("BoolArray", expect).GetEntry();
- EXPECT_EQ("/Shuffleboard/Tab/BoolArray", entry.GetName());
-
- auto actual = entry.GetValue()->GetBooleanArray();
- EXPECT_EQ(expect.size(), actual.size());
- for (size_t i = 0; i < expect.size(); i++) {
- EXPECT_EQ(expect[i], actual[i]);
- }
-}
-
-TEST_F(ShuffleboardTabTest, AddStringArray) {
- std::array<std::string, 2> expect = {{"foo", "bar"}};
- auto entry = m_tab->Add("StringArray", expect).GetEntry();
- EXPECT_EQ("/Shuffleboard/Tab/StringArray", entry.GetName());
-
- auto actual = entry.GetValue()->GetStringArray();
- EXPECT_EQ(expect.size(), actual.size());
- for (size_t i = 0; i < expect.size(); i++) {
- EXPECT_EQ(expect[i], actual[i]);
- }
-}
diff --git a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardTest.cpp
deleted file mode 100644
index d39d59d..0000000
--- a/wpilibcIntegrationTests/src/main/native/cpp/shuffleboard/ShuffleboardTest.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "frc/shuffleboard/Shuffleboard.h"
-#include "frc/shuffleboard/ShuffleboardTab.h"
-#include "gtest/gtest.h"
-
-using namespace frc;
-
-class ShuffleboardTest : public testing::Test {};
-
-TEST_F(ShuffleboardTest, TabObjectsCached) {
- ShuffleboardTab& tab1 = Shuffleboard::GetTab("testTabObjectsCached");
- ShuffleboardTab& tab2 = Shuffleboard::GetTab("testTabObjectsCached");
- EXPECT_EQ(&tab1, &tab2) << "Tab objects were not cached";
-}