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/wpilibcExamples/CMakeLists.txt b/wpilibcExamples/CMakeLists.txt
new file mode 100644
index 0000000..27cff6b
--- /dev/null
+++ b/wpilibcExamples/CMakeLists.txt
@@ -0,0 +1,31 @@
+project(wpilibcExamples)
+
+include(AddTest)
+include(SubDirList)
+
+SUBDIR_LIST(TEMPLATES ${CMAKE_SOURCE_DIR}/wpilibcExamples/src/main/cpp/templates)
+SUBDIR_LIST(EXAMPLES ${CMAKE_SOURCE_DIR}/wpilibcExamples/src/main/cpp/examples)
+
+foreach(example ${EXAMPLES})
+ file(GLOB_RECURSE sources src/main/cpp/examples/${example}/cpp/*.cpp
+ src/main/cpp/examples/${example}/c/*.c)
+ add_executable(${example} ${sources})
+ target_include_directories(${example} PUBLIC src/main/cpp/examples/${example}/include)
+ target_link_libraries(${example} wpilibc wpilibNewCommands wpilibOldCommands)
+
+ if (WITH_TESTS AND EXISTS ${CMAKE_SOURCE_DIR}/wpilibcExamples/src/test/cpp/examples/${example})
+ wpilib_add_test(${example} src/test/cpp/examples/${example}/cpp)
+ target_sources(${example}_test PRIVATE ${sources})
+ target_include_directories(${example}_test PRIVATE src/test/cpp/examples/${example}/include)
+ target_compile_definitions(${example}_test PUBLIC RUNNING_FRC_TESTS)
+ target_link_libraries(${example}_test wpilibc wpilibNewCommands gmock_main)
+ endif()
+endforeach()
+
+foreach(template ${TEMPLATES})
+ file(GLOB_RECURSE sources src/main/cpp/templates/${template}/cpp/*.cpp
+ src/main/cpp/templates/${template}/c/*.c)
+ add_executable(${template} ${sources})
+ target_include_directories(${template} PUBLIC src/main/cpp/templates/${template}/include)
+ target_link_libraries(${template} wpilibc wpilibNewCommands)
+endforeach()
diff --git a/wpilibcExamples/build.gradle b/wpilibcExamples/build.gradle
index 35f20d4..975e90a 100644
--- a/wpilibcExamples/build.gradle
+++ b/wpilibcExamples/build.gradle
@@ -2,6 +2,7 @@
apply plugin: 'cpp'
apply plugin: 'c'
+apply plugin: 'google-test-test-suite'
apply plugin: 'visual-studio'
apply plugin: 'edu.wpi.first.NativeUtils'
apply plugin: ExtraTasks
@@ -9,28 +10,29 @@
evaluationDependsOn(':hal')
apply from: '../shared/config.gradle'
+apply from: "${rootDir}/shared/googletest.gradle"
ext.examplesMap = [:]
ext.templatesMap = [:]
File examplesTree = file("$projectDir/src/main/cpp/examples")
examplesTree.list(new FilenameFilter() {
- @Override
- public boolean accept(File current, String name) {
- return new File(current, name).isDirectory();
- }
-}).each {
- examplesMap.put(it, [])
-}
+ @Override
+ public boolean accept(File current, String name) {
+ return new File(current, name).isDirectory();
+ }
+ }).each {
+ examplesMap.put(it, [])
+ }
File templatesTree = file("$projectDir/src/main/cpp/templates")
templatesTree.list(new FilenameFilter() {
- @Override
- public boolean accept(File current, String name) {
- return new File(current, name).isDirectory();
- }
-}).each {
- templatesMap.put(it, [])
-}
+ @Override
+ public boolean accept(File current, String name) {
+ return new File(current, name).isDirectory();
+ }
+ }).each {
+ templatesMap.put(it, [])
+ }
nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
cppCompiler.args.remove('-Wno-error=deprecated-declarations')
@@ -44,6 +46,8 @@
useCpp = true
}
+def simModules = ["halsim_gui"]
+
apply from: "${rootDir}/shared/opencv.gradle"
model {
@@ -82,7 +86,6 @@
"${key}"(NativeExecutableSpec) {
targetBuildTypes 'debug'
binaries.all { binary ->
- lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
@@ -92,7 +95,12 @@
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
- nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
+ nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
+ }
+ if (binary.targetPlatform.name == getCurrentArch()) {
+ simModules.each {
+ lib project: ":simulation:$it", library: it, linkage: 'shared'
+ }
}
}
sources {
@@ -125,7 +133,6 @@
"${key}"(NativeExecutableSpec) {
targetBuildTypes 'debug'
binaries.all { binary ->
- lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
@@ -142,7 +149,7 @@
}
}
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
- nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
+ nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
}
}
sources {
@@ -160,39 +167,62 @@
}
}
}
- tasks {
- def b = $.binaries
- b.each { binary->
- if (binary in NativeExecutableBinarySpec) {
- def installDir = binary.tasks.install.installDirectory.get().toString() + File.separatorChar
- def runFile = binary.tasks.install.runScriptFile.get().asFile.toString()
-
- binary.tasks.install.doLast {
- if (binary.targetPlatform.operatingSystem.isWindows()) {
- // Windows batch scripts
- fileName = binary.component.name + 'RealDS.bat'
- file = new File(installDir + fileName)
- file.withWriter { out ->
- out.println '@ECHO OFF'
- out.print 'SET HALSIM_EXTENSIONS='
- out.println '"' + new File(installDir + 'lib\\halsim_ds_socket.dll').toString() + '"'
- out.println runFile + ' %*'
+ testSuites {
+ examplesMap.each { key, value ->
+ def testFolder = new File("${rootDir}/wpilibcExamples/src/test/cpp/examples/${key}")
+ if (testFolder.exists()) {
+ "${key}Test"(GoogleTestTestSuiteSpec) {
+ for (NativeComponentSpec c : $.components) {
+ if (c.name == key) {
+ testing c
+ break
}
- } else {
- fileName = binary.component.name + 'RealDS.sh'
- file = new File(installDir + fileName)
- file.withWriter { out ->
- out.print 'export HALSIM_EXTENSIONS='
- out.println '"' + new File(installDir + '/lib/libhalsim_ds_socket.so').toString() + '"'
- out.println runFile + ' "$@"'
+ }
+ sources {
+ cpp {
+ source {
+ srcDirs "src/test/cpp/examples/${key}/cpp"
+ include '**/*.cpp'
+ }
+ exportedHeaders {
+ srcDirs "src/test/cpp/examples/${key}/include"
+ }
+ }
+ c {
+ source {
+ srcDirs "src/test/cpp/examples/${key}/c"
+ include '**/*.c'
+ }
+ exportedHeaders {
+ srcDirs "src/test/cpp/examples/${key}/include"
+ }
}
}
}
-
}
}
}
+ binaries {
+ withType(GoogleTestTestSuiteBinarySpec) {
+ lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
+ lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
+ lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
+ lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
+ lib project: ':cscore', library: 'cscore', linkage: 'shared'
+ project(':hal').addHalDependency(it, 'shared')
+ lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
+ }
+ nativeUtils.useRequiredLibrary(it, 'opencv_shared')
+
+ it.cppCompiler.define('RUNNING_FRC_TESTS')
+ it.cCompiler.define('RUNNING_FRC_TESTS')
+ }
+ }
}
+
apply from: 'publish.gradle'
model {
@@ -223,6 +253,54 @@
commandFile = new File("$projectDir/src/main/cpp/commands/commands.json")
}
+model {
+ // Create run tasks for all examples.
+ tasks {
+ // Iterate through the components and check if it is an example.
+ $.components.each { component ->
+ if (examplesMap.containsKey(component.name)) {
+ // Get the appropriate binary and create the run task.
+ component.binaries.each { binary ->
+ if (binary.targetPlatform.name == getCurrentArch() && binary.buildType.name == "debug") {
+ project.tasks.create("run${component.name}", Exec) {
+ // Add simulation modules to HALSIM_EXTENSIONS environment variable.
+ def setupEnv = {
+ String extensions = ""
+ binary.tasks.install.installDirectory.get().getAsFile().eachFileRecurse {
+ def name = it.name
+
+ // If we don't have a shared library, skip.
+ if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib')))
+ return
+
+ def file = it
+ simModules.each {
+ if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
+ extensions += file.absolutePath + File.pathSeparator
+ }
+ }
+ }
+
+ if (extensions != '') {
+ environment 'HALSIM_EXTENSIONS', extensions
+ }
+ }
+
+ // Create the task dependency and run the executable.
+ doFirst { setupEnv() }
+ dependsOn binary.tasks.install
+ commandLine binary.tasks.install.runScriptFile.get().asFile.toString()
+
+ group = "application"
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
ext {
isCppCommands = true
}
diff --git a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp
index 07c233e..24726b0 100644
--- a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "ReplaceMeCommand.h"
@@ -19,7 +16,9 @@
void ReplaceMeCommand::Execute() {}
// Make this return true when this Command no longer needs to run execute()
-bool ReplaceMeCommand::IsFinished() { return false; }
+bool ReplaceMeCommand::IsFinished() {
+ return false;
+}
// Called once after isFinished returns true
void ReplaceMeCommand::End() {}
diff --git a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h
index 49a3139..64fcd26 100644
--- a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h
+++ b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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
diff --git a/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.cpp b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.cpp
index e8085a1..c17d267 100644
--- a/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeCommand2.h"
@@ -21,4 +18,6 @@
void ReplaceMeCommand2::End(bool interrupted) {}
// Returns true when the command should end.
-bool ReplaceMeCommand2::IsFinished() { return false; }
+bool ReplaceMeCommand2::IsFinished() {
+ return false;
+}
diff --git a/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.h b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.h
index fd041fa..8a1e8e0 100644
--- a/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.h
+++ b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp
index 1a431f4..ced938d 100644
--- a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "ReplaceMeCommandGroup.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h
index a58f586..c51a964 100644
--- a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h
+++ b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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
diff --git a/wpilibcExamples/src/main/cpp/commands/commands.json b/wpilibcExamples/src/main/cpp/commands/commands.json
index d039a73..6b5bf1e 100644
--- a/wpilibcExamples/src/main/cpp/commands/commands.json
+++ b/wpilibcExamples/src/main/cpp/commands/commands.json
@@ -322,7 +322,7 @@
},
{
"name": "TrapezoidProfileSubsystem (New)",
- "description": "A command that executes a trapezoidal motion profile.",
+ "description": "A subsystem that executes a trapezoidal motion profile.",
"tags": [
"trapezoidprofilesubsystem"
],
diff --git a/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.cpp b/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.cpp
index 4ff8ad8..19de34f 100644
--- a/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.cpp
@@ -1,10 +1,7 @@
-/*----------------------------------------------------------------------------*/
-/* 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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 "ReplaceMeEmptyClass.h"
-ReplaceMeEmptyClass::ReplaceMeEmptyClass() {}
+ReplaceMeEmptyClass::ReplaceMeEmptyClass() = default;
diff --git a/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.h b/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.h
index 131edab..e6a733c 100644
--- a/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.h
+++ b/wpilibcExamples/src/main/cpp/commands/emptyclass/ReplaceMeEmptyClass.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp
index c130e09..1a80288 100644
--- a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "ReplaceMeInstantCommand.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h
index b50b617..c73cbcf 100644
--- a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h
+++ b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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
diff --git a/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.cpp b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.cpp
index 5e21e56..4de2be6 100644
--- a/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeInstantCommand2.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.h b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.h
index dec11c2..cd8de5f 100644
--- a/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.h
+++ b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp
index 3361a2c..e814a09 100644
--- a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeParallelCommandGroup.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.h b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.h
index a4f9519..1cbabdd 100644
--- a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.h
+++ b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp
index 5c3466c..67c12a3 100644
--- a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeParallelDeadlineGroup.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.h b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.h
index 7ecebb4..91be75f 100644
--- a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.h
+++ b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp
index 6d977f9..9cc3784 100644
--- a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeParallelRaceGroup.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.h b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.h
index 0b13b18..a3f4227 100644
--- a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.h
+++ b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp
index b39be7a..1bcc830 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMePIDCommand.h"
@@ -23,4 +20,6 @@
}) {}
// Returns true when the command should end.
-bool ReplaceMePIDCommand::IsFinished() { return false; }
+bool ReplaceMePIDCommand::IsFinished() {
+ return false;
+}
diff --git a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.h b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.h
index 03c874c..a78d216 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.h
+++ b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp
index f446f8e..7b44893 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "ReplaceMePIDSubsystem.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h
index 2ab3d92..f9aabc9 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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
diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp
index 0fa81a2..2cdce1b 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMePIDSubsystem2.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.h b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.h
index 6c8e344..0b450f4 100644
--- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.h
+++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp
index eada0ac..880a222 100644
--- a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeProfiledPIDCommand.h"
@@ -34,4 +31,6 @@
}) {}
// Returns true when the command should end.
-bool ReplaceMeProfiledPIDCommand::IsFinished() { return false; }
+bool ReplaceMeProfiledPIDCommand::IsFinished() {
+ return false;
+}
diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.h b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.h
index dc2c50e..0bd45ac 100644
--- a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.h
+++ b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp
index 4ba8baf..d65a867 100644
--- a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeProfiledPIDSubsystem.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.h b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.h
index 6969c29..8e86f3f 100644
--- a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp
index c7d0702..c83a99d 100644
--- a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeSequentialCommandGroup.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.h b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.h
index 5e629b8..f9fe09e 100644
--- a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.h
+++ b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp
index 8ca89d3..ca589f1 100644
--- a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "ReplaceMeSubsystem.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h
index de84a48..3de6031 100644
--- a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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
diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.cpp b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.cpp
index 5d6805a..8d0ede0 100644
--- a/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.cpp
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeSubsystem2.h"
-ReplaceMeSubsystem2::ReplaceMeSubsystem2() {}
+ReplaceMeSubsystem2::ReplaceMeSubsystem2() = default;
// This method will be called once per scheduler run
void ReplaceMeSubsystem2::Periodic() {}
diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.h b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.h
index 6f15f46..ca11456 100644
--- a/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.h
+++ b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -16,7 +13,7 @@
/**
* Will be called periodically whenever the CommandScheduler runs.
*/
- void Periodic();
+ void Periodic() override;
private:
// Components (e.g. motor controllers and sensors) should generally be
diff --git a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp
index 2076e5b..c6793e0 100644
--- a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "ReplaceMeTimedCommand.h"
-ReplaceMeTimedCommand::ReplaceMeTimedCommand(double timeout)
+ReplaceMeTimedCommand::ReplaceMeTimedCommand(units::second_t timeout)
: TimedCommand(timeout) {
// Use Requires() here to declare subsystem dependencies
// eg. Requires(Robot::chassis.get());
diff --git a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h
index bf55e45..48cfa2d 100644
--- a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h
+++ b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h
@@ -1,17 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/commands/TimedCommand.h>
+#include <units/time.h>
class ReplaceMeTimedCommand : public frc::TimedCommand {
public:
- explicit ReplaceMeTimedCommand(double timeout);
+ explicit ReplaceMeTimedCommand(units::second_t timeout);
void Initialize() override;
void Execute() override;
void End() override;
diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.cpp b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.cpp
index a337013..3928d3b 100644
--- a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeTrapezoidProfileCommand.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.h b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.h
index 5cf7a20..a3cd8c8 100644
--- a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.h
+++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.cpp
index 8bc1bee..a3f458c 100644
--- a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "ReplaceMeTrapezoidProfileSubsystem.h"
diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.h b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.h
index 42a8cb5..99b9410 100644
--- a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp
index 4759e0e..3c563ff 100644
--- a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp
+++ b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* 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 "ReplaceMeTrigger.h"
-ReplaceMeTrigger::ReplaceMeTrigger() {}
+ReplaceMeTrigger::ReplaceMeTrigger() = default;
-bool ReplaceMeTrigger::Get() { return false; }
+bool ReplaceMeTrigger::Get() {
+ return false;
+}
diff --git a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h
index 9da7ef8..a76dcd9 100644
--- a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h
+++ b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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
diff --git a/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp
index 3658824..d59b370 100644
--- a/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/AddressableLED/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <array>
@@ -55,5 +52,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp
index 3361754..abe79f4 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp
@@ -1,32 +1,31 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a demo program showing the use of the DifferentialDrive class.
* Runs the motors with arcade steering.
*/
class Robot : public frc::TimedRobot {
- frc::PWMVictorSPX m_leftMotor{0};
- frc::PWMVictorSPX m_rightMotor{1};
+ frc::PWMSparkMax m_leftMotor{0};
+ frc::PWMSparkMax m_rightMotor{1};
frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor};
frc::Joystick m_stick{0};
public:
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
// Drive with arcade style
m_robotDrive.ArcadeDrive(m_stick.GetY(), m_stick.GetX());
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp
index 67f1e12..644e35f 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp
@@ -1,37 +1,34 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc/GenericHID.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a demo program showing the use of the DifferentialDrive class.
* Runs the motors with split arcade steering and an Xbox controller.
*/
class Robot : public frc::TimedRobot {
- frc::PWMVictorSPX m_leftMotor{0};
- frc::PWMVictorSPX m_rightMotor{1};
+ frc::PWMSparkMax m_leftMotor{0};
+ frc::PWMSparkMax m_rightMotor{1};
frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor};
frc::XboxController m_driverController{0};
public:
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
// Drive with split arcade style
// That means that the Y axis of the left stick moves forward
// and backward, and the X of the right stick turns left and right.
- m_robotDrive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::JoystickHand::kLeftHand),
- m_driverController.GetX(frc::GenericHID::JoystickHand::kRightHand));
+ m_robotDrive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/Robot.cpp
index be32fbb..2803c5c 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,14 +17,18 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
* can use it to reset any subsystem information you want to clear when the
* robot is disabled.
*/
-void Robot::DisabledInit() { m_container.DisablePIDSubsystems(); }
+void Robot::DisabledInit() {
+ m_container.DisablePIDSubsystems();
+}
void Robot::DisabledPeriodic() {}
@@ -67,5 +68,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp
index d3a0133..48310da 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -20,9 +17,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -31,7 +27,7 @@
// Configure your button bindings here
// Move the arm to 2 radians above horizontal when the 'A' button is pressed.
- frc2::JoystickButton(&m_driverController, 1)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
.WhenPressed(
[this] {
m_arm.SetGoal(2_rad);
@@ -40,7 +36,7 @@
{&m_arm});
// Move the arm to neutral position when the 'B' button is pressed.
- frc2::JoystickButton(&m_driverController, 2)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
.WhenPressed(
[this] {
m_arm.SetGoal(ArmConstants::kArmOffset);
@@ -49,16 +45,19 @@
{&m_arm});
// Disable the arm controller when Y is pressed.
- frc2::JoystickButton(&m_driverController, 4)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kY)
.WhenPressed([this] { m_arm.Disable(); }, {&m_arm});
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
- .WhenPressed([this] { m_drive.SetMaxOutput(.5); })
+ frc2::JoystickButton(&m_driverController,
+ frc::XboxController::Button::kRightBumper)
+ .WhenPressed([this] { m_drive.SetMaxOutput(0.5); })
.WhenReleased([this] { m_drive.SetMaxOutput(1); });
}
-void RobotContainer::DisablePIDSubsystems() { m_arm.Disable(); }
+void RobotContainer::DisablePIDSubsystems() {
+ m_arm.Disable();
+}
frc2::Command* RobotContainer::GetAutonomousCommand() {
// Runs the chosen command in autonomous
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp
index 5531c5b..8618aaa 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/ArmSubsystem.h"
@@ -19,7 +16,7 @@
m_motor(kMotorPort),
m_encoder(kEncoderPorts[0], kEncoderPorts[1]),
m_feedforward(kS, kCos, kV, kA) {
- m_encoder.SetDistancePerPulse(kEncoderDistancePerPulse.to<double>());
+ m_encoder.SetDistancePerPulse(kEncoderDistancePerPulse.value());
// Start arm in neutral position
SetGoal(State{kArmOffset, 0_rad_per_s});
}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/DriveSubsystem.cpp
index 64be1b8..5ba38b8 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -38,9 +35,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h
index ac5ffe0..16a4e00 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,7 +8,7 @@
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -37,7 +34,8 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterInches * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace ArmConstants {
@@ -57,7 +55,8 @@
constexpr int kEncoderPorts[]{4, 5};
constexpr int kEncoderPPR = 256;
-constexpr auto kEncoderDistancePerPulse = 2.0_rad * wpi::math::pi / kEncoderPPR;
+constexpr auto kEncoderDistancePerPulse =
+ 2.0_rad * wpi::numbers::pi / kEncoderPPR;
// The offset of the arm from the horizontal in its neutral position,
// measured from the horizontal
@@ -70,5 +69,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h
index c238cb6..782207b 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h
index 1733efe..45cd582 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h
@@ -1,15 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/controller/ArmFeedforward.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/ProfiledPIDSubsystem.h>
#include <units/angle.h>
@@ -27,7 +24,7 @@
units::radian_t GetMeasurement() override;
private:
- frc::PWMVictorSPX m_motor;
+ frc::PWMSparkMax m_motor;
frc::Encoder m_encoder;
frc::ArmFeedforward m_feedforward;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h
index 3ed1357..47bf28e 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -73,16 +70,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1;
- frc::PWMVictorSPX m_left2;
- frc::PWMVictorSPX m_right1;
- frc::PWMVictorSPX m_right2;
+ frc::PWMSparkMax m_left1;
+ frc::PWMSparkMax m_left2;
+ frc::PWMSparkMax m_right1;
+ frc::PWMSparkMax m_right2;
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp
index ba7bbf5..b5a4420 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -20,9 +17,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -31,17 +27,18 @@
// Configure your button bindings here
// Move the arm to 2 radians above horizontal when the 'A' button is pressed.
- frc2::JoystickButton(&m_driverController, 1)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
.WhenPressed([this] { m_arm.SetGoal(2_rad); }, {&m_arm});
// Move the arm to neutral position when the 'B' button is pressed.
- frc2::JoystickButton(&m_driverController, 1)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
.WhenPressed([this] { m_arm.SetGoal(ArmConstants::kArmOffset); },
{&m_arm});
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
- .WhenPressed([this] { m_drive.SetMaxOutput(.5); })
+ frc2::JoystickButton(&m_driverController,
+ frc::XboxController::Button::kRightBumper)
+ .WhenPressed([this] { m_drive.SetMaxOutput(0.5); })
.WhenReleased([this] { m_drive.SetMaxOutput(1); });
}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp
index 54a59ed..f80970a 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/ArmSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/ArmSubsystem.h"
@@ -26,5 +23,5 @@
m_feedforward.Calculate(setpoint.position, setpoint.velocity);
// Add the feedforward to the PID output to get the motor output
m_motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition,
- setpoint.position.to<double>(), feedforward / 12_V);
+ setpoint.position.value(), feedforward / 12_V);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp
index 47c898e..03d3415 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -38,9 +35,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h
index ac5ffe0..16a4e00 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,7 +8,7 @@
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -37,7 +34,8 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterInches * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace ArmConstants {
@@ -57,7 +55,8 @@
constexpr int kEncoderPorts[]{4, 5};
constexpr int kEncoderPPR = 256;
-constexpr auto kEncoderDistancePerPulse = 2.0_rad * wpi::math::pi / kEncoderPPR;
+constexpr auto kEncoderDistancePerPulse =
+ 2.0_rad * wpi::numbers::pi / kEncoderPPR;
// The offset of the arm from the horizontal in its neutral position,
// measured from the horizontal
@@ -70,5 +69,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h
index f0e888d..5d55839 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <frc/SpeedController.h>
+#include <frc/motorcontrol/MotorController.h>
/**
* A simplified stub class that simulates the API of a common "smart" motor
@@ -15,7 +12,7 @@
*
* <p>Has no actual functionality.
*/
-class ExampleSmartMotorController : public frc::SpeedController {
+class ExampleSmartMotorController : public frc::MotorController {
public:
enum PIDMode { kPosition, kVelocity, kMovementWitchcraft };
@@ -82,6 +79,4 @@
void Disable() override {}
void StopMotor() override {}
-
- void PIDWrite(double output) override {}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h
index fa07359..5aba470 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h
index 8030cb4..1fb5b87 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/ArmSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h
index 3ed1357..47bf28e 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -73,16 +70,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1;
- frc::PWMVictorSPX m_left2;
- frc::PWMVictorSPX m_right1;
- frc::PWMVictorSPX m_right2;
+ frc::PWMSparkMax m_left1;
+ frc::PWMSparkMax m_left2;
+ frc::PWMSparkMax m_right1;
+ frc::PWMSparkMax m_right2;
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp
index 18df257..b8b8368 100644
--- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp
@@ -1,26 +1,27 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
-#include <frc/GenericHID.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/RobotController.h>
-#include <frc/StateSpaceUtil.h>
#include <frc/TimedRobot.h>
#include <frc/controller/PIDController.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/simulation/BatterySim.h>
#include <frc/simulation/EncoderSim.h>
#include <frc/simulation/RoboRioSim.h>
#include <frc/simulation/SingleJointedArmSim.h>
+#include <frc/smartdashboard/Mechanism2d.h>
+#include <frc/smartdashboard/MechanismLigament2d.h>
+#include <frc/smartdashboard/MechanismRoot2d.h>
+#include <frc/smartdashboard/SmartDashboard.h>
#include <frc/system/plant/LinearSystemId.h>
+#include <frc/util/Color.h>
+#include <frc/util/Color8Bit.h>
#include <units/angle.h>
#include <units/moment_of_inertia.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -33,63 +34,81 @@
static constexpr int kJoystickPort = 0;
// The P gain for the PID controller that drives this arm.
- static constexpr double kArmKp = 5.0;
+ static constexpr double kArmKp = 50.0;
// distance per pulse = (angle per revolution) / (pulses per revolution)
// = (2 * PI rads) / (4096 pulses)
static constexpr double kArmEncoderDistPerPulse =
- 2.0 * wpi::math::pi / 4096.0;
+ 2.0 * wpi::numbers::pi / 4096.0;
- // The arm gearbox represents a gerbox containing two Vex 775pro motors.
+ // The arm gearbox represents a gearbox containing two Vex 775pro motors.
frc::DCMotor m_armGearbox = frc::DCMotor::Vex775Pro(2);
// Standard classes for controlling our arm
frc2::PIDController m_controller{kArmKp, 0, 0};
frc::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel};
- frc::PWMVictorSPX m_motor{kMotorPort};
+ frc::PWMSparkMax m_motor{kMotorPort};
frc::Joystick m_joystick{kJoystickPort};
// Simulation classes help us simulate what's going on, including gravity.
- // This sim represents an arm with 2 775s, a 100:1 reduction, a mass of 5kg,
- // 30in overall arm length, range of motion nin [-180, 0] degrees, and noise
- // with a standard deviation of 0.5 degrees.
+ // This sim represents an arm with 2 775s, a 600:1 reduction, a mass of 5kg,
+ // 30in overall arm length, range of motion in [-75, 255] degrees, and noise
+ // with a standard deviation of 1 encoder tick.
frc::sim::SingleJointedArmSim m_armSim{
m_armGearbox,
- 100.0,
+ 600.0,
frc::sim::SingleJointedArmSim::EstimateMOI(30_in, 5_kg),
30_in,
- -180_deg,
- 0_deg,
+ -75_deg,
+ 255_deg,
5_kg,
true,
- {(0.5_deg).to<double>()}};
+ {kArmEncoderDistPerPulse}};
frc::sim::EncoderSim m_encoderSim{m_encoder};
- public:
- void RobotInit() { m_encoder.SetDistancePerPulse(kArmEncoderDistPerPulse); }
+ // Create a Mechanism2d display of an Arm
+ frc::Mechanism2d m_mech2d{60, 60};
+ frc::MechanismRoot2d* m_armBase = m_mech2d.GetRoot("ArmBase", 30, 30);
+ frc::MechanismLigament2d* m_armTower =
+ m_armBase->Append<frc::MechanismLigament2d>(
+ "Arm Tower", 30, -90_deg, 6, frc::Color8Bit{frc::Color::kBlue});
+ frc::MechanismLigament2d* m_arm = m_armBase->Append<frc::MechanismLigament2d>(
+ "Arm", 30, m_armSim.GetAngle(), 6, frc::Color8Bit{frc::Color::kYellow});
- void SimulationPeriodic() {
+ public:
+ void RobotInit() override {
+ m_encoder.SetDistancePerPulse(kArmEncoderDistPerPulse);
+
+ // Put Mechanism 2d to SmartDashboard
+ frc::SmartDashboard::PutData("Arm Sim", &m_mech2d);
+ }
+
+ void SimulationPeriodic() override {
// In this method, we update our simulation of what our arm is doing
// First, we set our "inputs" (voltages)
- m_armSim.SetInput(frc::MakeMatrix<1, 1>(
- m_motor.Get() * frc::RobotController::GetInputVoltage()));
+ m_armSim.SetInput(Eigen::Vector<double, 1>{
+ m_motor.Get() * frc::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
m_armSim.Update(20_ms);
// Finally, we set our simulated encoder's readings and simulated battery
// voltage
- m_encoderSim.SetDistance(m_armSim.GetAngle().to<double>());
+ m_encoderSim.SetDistance(m_armSim.GetAngle().value());
// SimBattery estimates loaded battery voltages
frc::sim::RoboRioSim::SetVInVoltage(
frc::sim::BatterySim::Calculate({m_armSim.GetCurrentDraw()}));
+
+ // Update the Mechanism Arm angle based on the simulated arm angle
+ m_arm->SetAngle(m_armSim.GetAngle());
}
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
if (m_joystick.GetTrigger()) {
- // Here, we run PID control like normal, with a constant setpoint of 30in.
- double pidOutput =
- m_controller.Calculate(m_encoder.GetDistance(), (30_in).to<double>());
+ // Here, we run PID control like normal, with a constant setpoint of 75
+ // degrees.
+ double pidOutput = m_controller.Calculate(
+ m_encoder.GetDistance(), (units::radian_t(75_deg)).value());
m_motor.SetVoltage(units::volt_t(pidOutput));
} else {
// Otherwise, we disable the motor.
@@ -97,12 +116,14 @@
}
}
- void DisabledInit() {
+ void DisabledInit() override {
// This just makes sure that our simulation code knows that the motor's off.
m_motor.Set(0.0);
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp
index 2811cf1..7f4f761 100644
--- a/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <cameraserver/CameraServer.h>
#include <frc/TimedRobot.h>
@@ -22,15 +19,15 @@
static void VisionThread() {
// Get the Axis camera from CameraServer
cs::AxisCamera camera =
- frc::CameraServer::GetInstance()->AddAxisCamera("axis-camera.local");
+ frc::CameraServer::AddAxisCamera("axis-camera.local");
// Set the resolution
camera.SetResolution(640, 480);
// Get a CvSink. This will capture Mats from the Camera
- cs::CvSink cvSink = frc::CameraServer::GetInstance()->GetVideo();
+ cs::CvSink cvSink = frc::CameraServer::GetVideo();
// Setup a CvSource. This will send images back to the Dashboard
cs::CvSource outputStream =
- frc::CameraServer::GetInstance()->PutVideo("Rectangle", 640, 480);
+ frc::CameraServer::PutVideo("Rectangle", 640, 480);
// Mats are very memory expensive. Lets reuse this Mat.
cv::Mat mat;
@@ -61,5 +58,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp
index 76493b5..aed898f 100644
--- a/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp
@@ -1,11 +1,8 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/PowerDistributionPanel.h>
+#include <frc/PowerDistribution.h>
#include <frc/TimedRobot.h>
#include <frc/smartdashboard/SmartDashboard.h>
@@ -34,9 +31,11 @@
private:
// Object for dealing with the Power Distribution Panel (PDP).
- frc::PowerDistributionPanel m_pdp;
+ frc::PowerDistribution m_pdp;
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/DMA/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DMA/cpp/Robot.cpp
index fb3999b..9097d94 100644
--- a/wpilibcExamples/src/main/cpp/examples/DMA/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DMA/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogInput.h>
#include <frc/DMA.h>
@@ -42,7 +39,7 @@
// Start DMA. No triggers or inputs can be added after this call
// unless DMA is stopped.
- m_dma.StartDMA(1024);
+ m_dma.Start(1024);
}
void RobotPeriodic() override {
@@ -56,10 +53,13 @@
// Update our sample. remaining is the number of samples remaining in the
// buffer status is more specific error messages if readStatus is not OK.
// Wait 1ms if buffer is empty
- HAL_DMAReadStatus readStatus =
+ frc::DMASample::DMAReadStatus readStatus =
sample.Update(&m_dma, 1_ms, &remaining, &status);
- if (readStatus == HAL_DMA_OK) {
+ // Unset trigger
+ m_dmaTrigger.Set(true);
+
+ if (readStatus == frc::DMASample::DMAReadStatus::kOk) {
// Status value in all these reads should be checked, a non 0 value means
// value could not be read
@@ -78,5 +78,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
index c639539..da638d5 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Drivetrain.h"
@@ -11,9 +8,9 @@
const auto leftFeedforward = m_feedforward.Calculate(speeds.left);
const auto rightFeedforward = m_feedforward.Calculate(speeds.right);
const double leftOutput = m_leftPIDController.Calculate(
- m_leftEncoder.GetRate(), speeds.left.to<double>());
+ m_leftEncoder.GetRate(), speeds.left.value());
const double rightOutput = m_rightPIDController.Calculate(
- m_rightEncoder.GetRate(), speeds.right.to<double>());
+ m_rightEncoder.GetRate(), speeds.right.value());
m_leftGroup.SetVoltage(units::volt_t{leftOutput} + leftFeedforward);
m_rightGroup.SetVoltage(units::volt_t{rightOutput} + rightFeedforward);
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp
index 22d1cf6..e9119c8 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc/SlewRateLimiter.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
+#include <frc/filter/SlewRateLimiter.h>
#include "Drivetrain.h"
@@ -21,16 +18,14 @@
void TeleopPeriodic() override {
// Get the x speed. We are inverting this because Xbox controllers return
// negative values when we push forward.
- const auto xSpeed = -m_speedLimiter.Calculate(
- m_controller.GetY(frc::GenericHID::kLeftHand)) *
+ const auto xSpeed = -m_speedLimiter.Calculate(m_controller.GetLeftY()) *
Drivetrain::kMaxSpeed;
// Get the rate of angular rotation. We are inverting this because we want a
// positive value when we pull to the left (remember, CCW is positive in
// mathematics). Xbox controllers return positive values when you pull to
// the right by default.
- const auto rot = -m_rotLimiter.Calculate(
- m_controller.GetX(frc::GenericHID::kRightHand)) *
+ const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
Drivetrain::kMaxAngularSpeed;
m_drive.Drive(xSpeed, rot);
@@ -48,5 +43,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h
index d8f3521..81d0a71 100644
--- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h
@@ -1,25 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/SimpleMotorFeedforward.h>
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/kinematics/DifferentialDriveOdometry.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <units/angle.h>
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/velocity.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -27,13 +24,18 @@
class Drivetrain {
public:
Drivetrain() {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightGroup.SetInverted(true);
+
m_gyro.Reset();
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_leftEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
+ m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
- m_rightEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
+ m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -43,7 +45,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::math::pi}; // 1/2 rotation per second
+ wpi::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,
@@ -55,13 +57,13 @@
static constexpr double kWheelRadius = 0.0508; // meters
static constexpr int kEncoderResolution = 4096;
- frc::PWMVictorSPX m_leftLeader{1};
- frc::PWMVictorSPX m_leftFollower{2};
- frc::PWMVictorSPX m_rightLeader{3};
- frc::PWMVictorSPX m_rightFollower{4};
+ frc::PWMSparkMax m_leftLeader{1};
+ frc::PWMSparkMax m_leftFollower{2};
+ frc::PWMSparkMax m_rightLeader{3};
+ frc::PWMSparkMax m_rightFollower{4};
- frc::SpeedControllerGroup m_leftGroup{m_leftLeader, m_leftFollower};
- frc::SpeedControllerGroup m_rightGroup{m_rightLeader, m_rightFollower};
+ frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower};
+ frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower};
frc::Encoder m_leftEncoder{0, 1};
frc::Encoder m_rightEncoder{2, 3};
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
new file mode 100644
index 0000000..1ed0e46
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
@@ -0,0 +1,42 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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 "Drivetrain.h"
+
+#include <frc/Timer.h>
+
+#include "ExampleGlobalMeasurementSensor.h"
+
+void Drivetrain::SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds) {
+ const auto leftFeedforward = m_feedforward.Calculate(speeds.left);
+ const auto rightFeedforward = m_feedforward.Calculate(speeds.right);
+ const double leftOutput = m_leftPIDController.Calculate(
+ m_leftEncoder.GetRate(), speeds.left.value());
+ const double rightOutput = m_rightPIDController.Calculate(
+ m_rightEncoder.GetRate(), speeds.right.value());
+
+ m_leftGroup.SetVoltage(units::volt_t{leftOutput} + leftFeedforward);
+ m_rightGroup.SetVoltage(units::volt_t{rightOutput} + rightFeedforward);
+}
+
+void Drivetrain::Drive(units::meters_per_second_t xSpeed,
+ units::radians_per_second_t rot) {
+ SetSpeeds(m_kinematics.ToWheelSpeeds({xSpeed, 0_mps, rot}));
+}
+
+void Drivetrain::UpdateOdometry() {
+ m_poseEstimator.Update(m_gyro.GetRotation2d(),
+ {units::meters_per_second_t(m_leftEncoder.GetRate()),
+ units::meters_per_second_t(m_rightEncoder.GetRate())},
+ units::meter_t(m_leftEncoder.GetDistance()),
+ units::meter_t(m_rightEncoder.GetDistance()));
+
+ // Also apply vision measurements. We use 0.3 seconds in the past as an
+ // example -- on a real robot, this must be calculated based either on latency
+ // or timestamps.
+ m_poseEstimator.AddVisionMeasurement(
+ ExampleGlobalMeasurementSensor::GetEstimatedGlobalPose(
+ m_poseEstimator.GetEstimatedPosition()),
+ frc::Timer::GetFPGATimestamp() - 0.3_s);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp
new file mode 100644
index 0000000..e9119c8
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp
@@ -0,0 +1,49 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/TimedRobot.h>
+#include <frc/XboxController.h>
+#include <frc/filter/SlewRateLimiter.h>
+
+#include "Drivetrain.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void AutonomousPeriodic() override {
+ TeleopPeriodic();
+ m_drive.UpdateOdometry();
+ }
+
+ void TeleopPeriodic() override {
+ // Get the x speed. We are inverting this because Xbox controllers return
+ // negative values when we push forward.
+ const auto xSpeed = -m_speedLimiter.Calculate(m_controller.GetLeftY()) *
+ Drivetrain::kMaxSpeed;
+
+ // Get the rate of angular rotation. We are inverting this because we want a
+ // positive value when we pull to the left (remember, CCW is positive in
+ // mathematics). Xbox controllers return positive values when you pull to
+ // the right by default.
+ const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
+ Drivetrain::kMaxAngularSpeed;
+
+ m_drive.Drive(xSpeed, rot);
+ }
+
+ private:
+ frc::XboxController m_controller{0};
+
+ // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0
+ // to 1.
+ frc::SlewRateLimiter<units::scalar> m_speedLimiter{3 / 1_s};
+ frc::SlewRateLimiter<units::scalar> m_rotLimiter{3 / 1_s};
+
+ Drivetrain m_drive;
+};
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h
new file mode 100644
index 0000000..dfb57a6
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h
@@ -0,0 +1,90 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/AnalogGyro.h>
+#include <frc/Encoder.h>
+#include <frc/controller/PIDController.h>
+#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/estimator/DifferentialDrivePoseEstimator.h>
+#include <frc/kinematics/DifferentialDriveKinematics.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <units/angle.h>
+#include <units/angular_velocity.h>
+#include <units/length.h>
+#include <units/velocity.h>
+#include <wpi/numbers>
+
+/**
+ * Represents a differential drive style drivetrain.
+ */
+class Drivetrain {
+ public:
+ Drivetrain() {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightGroup.SetInverted(true);
+
+ m_gyro.Reset();
+ // Set the distance per pulse for the drive encoders. We can simply use the
+ // distance traveled for one rotation of the wheel divided by the encoder
+ // resolution.
+ m_leftEncoder.SetDistancePerPulse(
+ 2 * wpi::numbers::pi * kWheelRadius.value() / kEncoderResolution);
+ m_rightEncoder.SetDistancePerPulse(
+ 2 * wpi::numbers::pi * kWheelRadius.value() / kEncoderResolution);
+
+ m_leftEncoder.Reset();
+ m_rightEncoder.Reset();
+ }
+
+ static constexpr units::meters_per_second_t kMaxSpeed =
+ 3.0_mps; // 3 meters per second
+ static constexpr units::radians_per_second_t kMaxAngularSpeed{
+ wpi::numbers::pi}; // 1/2 rotation per second
+
+ void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
+ void Drive(units::meters_per_second_t xSpeed,
+ units::radians_per_second_t rot);
+ void UpdateOdometry();
+
+ private:
+ static constexpr units::meter_t kTrackWidth = 0.381_m * 2;
+ static constexpr units::meter_t kWheelRadius = 0.0508_m;
+ static constexpr int kEncoderResolution = 4096;
+
+ frc::PWMSparkMax m_leftLeader{1};
+ frc::PWMSparkMax m_leftFollower{2};
+ frc::PWMSparkMax m_rightLeader{3};
+ frc::PWMSparkMax m_rightFollower{4};
+
+ frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower};
+ frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower};
+
+ frc::Encoder m_leftEncoder{0, 1};
+ frc::Encoder m_rightEncoder{2, 3};
+
+ frc2::PIDController m_leftPIDController{1.0, 0.0, 0.0};
+ frc2::PIDController m_rightPIDController{1.0, 0.0, 0.0};
+
+ frc::AnalogGyro m_gyro{0};
+
+ frc::DifferentialDriveKinematics m_kinematics{kTrackWidth};
+
+ // Gains are for example purposes only - must be determined for your own
+ // robot!
+ frc::DifferentialDrivePoseEstimator m_poseEstimator{
+ frc::Rotation2d(),
+ frc::Pose2d(),
+ {0.01, 0.01, 0.01, 0.01, 0.01},
+ {0.1, 0.1, 0.1},
+ {0.1, 0.1, 0.1}};
+
+ // Gains are for example purposes only - must be determined for your own
+ // robot!
+ frc::SimpleMotorFeedforward<units::meters> m_feedforward{1_V, 3_V / 1_mps};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
new file mode 100644
index 0000000..a4caff4
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/StateSpaceUtil.h>
+#include <frc/geometry/Pose2d.h>
+
+/**
+ * This dummy class represents a global measurement sensor, such as a computer
+ * vision solution.
+ */
+class ExampleGlobalMeasurementSensor {
+ public:
+ static frc::Pose2d GetEstimatedGlobalPose(
+ const frc::Pose2d& estimatedRobotPose) {
+ auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1);
+ return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)),
+ estimatedRobotPose.Y() + units::meter_t(randVec(1)),
+ estimatedRobotPose.Rotation() +
+ frc::Rotation2d(units::radian_t(randVec(3))));
+ }
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp
index 78bb48a..fb879fe 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -21,9 +18,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -32,18 +28,19 @@
// Configure your button bindings here
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
+ frc2::JoystickButton(&m_driverController,
+ frc::XboxController::Button::kRightBumper)
.WhenPressed(&m_driveHalfSpeed)
.WhenReleased(&m_driveFullSpeed);
// Drive forward by 3 meters when the 'A' button is pressed, with a timeout of
// 10 seconds
- frc2::JoystickButton(&m_driverController, 1)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
.WhenPressed(DriveDistanceProfiled(3_m, &m_drive).WithTimeout(10_s));
// Do the same thing as above when the 'B' button is pressed, but defined
// inline
- frc2::JoystickButton(&m_driverController, 2)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
.WhenPressed(
frc2::TrapezoidProfileCommand<units::meters>(
frc::TrapezoidProfile<units::meters>(
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp
index 7de607c..cecb9d6 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/DriveDistanceProfiled.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp
index d0bdef6..270124b 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -15,6 +12,16 @@
m_rightLeader{kRightMotor1Port},
m_rightFollower{kRightMotor2Port},
m_feedforward{ks, kv, ka} {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightLeader.SetInverted(true);
+
+ // You might need to not do this depending on the specific motor controller
+ // that you are using -- contact the respective vendor's documentation for
+ // more details.
+ m_rightFollower.SetInverted(true);
+
m_leftFollower.Follow(m_leftLeader);
m_rightFollower.Follow(m_rightLeader);
@@ -30,10 +37,10 @@
frc::TrapezoidProfile<units::meters>::State left,
frc::TrapezoidProfile<units::meters>::State right) {
m_leftLeader.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition,
- left.position.to<double>(),
+ left.position.value(),
m_feedforward.Calculate(left.velocity) / 12_V);
m_rightLeader.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition,
- right.position.to<double>(),
+ right.position.value(),
m_feedforward.Calculate(right.velocity) / 12_V);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h
index 8ff887e..92f82ba 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -12,7 +9,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -46,5 +43,5 @@
} // namespace DriveConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h
index f0e888d..71dc4d4 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <frc/SpeedController.h>
+#include <frc/motorcontrol/MotorController.h>
/**
* A simplified stub class that simulates the API of a common "smart" motor
@@ -15,7 +12,7 @@
*
* <p>Has no actual functionality.
*/
-class ExampleSmartMotorController : public frc::SpeedController {
+class ExampleSmartMotorController : public frc::MotorController {
public:
enum PIDMode { kPosition, kVelocity, kMovementWitchcraft };
@@ -71,9 +68,9 @@
*/
void ResetEncoder() {}
- void Set(double speed) override {}
+ void Set(double speed) override { m_value = speed; }
- double Get() const override { return 0; }
+ double Get() const override { return m_value; }
void SetInverted(bool isInverted) override {}
@@ -83,5 +80,6 @@
void StopMotor() override {}
- void PIDWrite(double output) override {}
+ private:
+ double m_value = 0.0;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h
index af35be4..aced9e0 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/commands/DriveDistanceProfiled.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/commands/DriveDistanceProfiled.h
index 2199590..34cf8f3 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/commands/DriveDistanceProfiled.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/commands/DriveDistanceProfiled.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.h
index 45fa982..9086353 100644
--- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp
index b75d99c..a9343d8 100644
--- a/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/DutyCycleEncoder.h>
#include <frc/TimedRobot.h>
@@ -34,11 +31,13 @@
frc::SmartDashboard::PutBoolean("Connected", connected);
frc::SmartDashboard::PutNumber("Frequency", frequency);
- frc::SmartDashboard::PutNumber("Output", output.to<double>());
+ frc::SmartDashboard::PutNumber("Output", output.value());
frc::SmartDashboard::PutNumber("Distance", distance);
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp
index 1a113ae..69d41bc 100644
--- a/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/DutyCycleInput/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/DigitalInput.h>
#include <frc/DutyCycle.h>
@@ -31,5 +28,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp
index b1bb1ec..ebafa75 100644
--- a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp
@@ -1,28 +1,25 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/controller/ProfiledPIDController.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/acceleration.h>
#include <units/length.h>
#include <units/time.h>
#include <units/velocity.h>
-#include <wpi/math>
+#include <wpi/numbers>
class Robot : public frc::TimedRobot {
public:
static constexpr units::second_t kDt = 20_ms;
Robot() {
- m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::math::pi * 1.5);
+ m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::numbers::pi * 1.5);
}
void TeleopPeriodic() override {
@@ -40,7 +37,7 @@
private:
frc::Joystick m_joystick{1};
frc::Encoder m_encoder{1, 2};
- frc::PWMVictorSPX m_motor{1};
+ frc::PWMSparkMax m_motor{1};
// Create a PID controller whose setpoint's change is subject to maximum
// velocity and acceleration constraints.
@@ -51,5 +48,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp
index 1f67449..4b2891d 100644
--- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp
@@ -1,26 +1,29 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
-#include <frc/GenericHID.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/RobotController.h>
#include <frc/StateSpaceUtil.h>
#include <frc/TimedRobot.h>
#include <frc/controller/PIDController.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/simulation/BatterySim.h>
#include <frc/simulation/ElevatorSim.h>
#include <frc/simulation/EncoderSim.h>
#include <frc/simulation/RoboRioSim.h>
+#include <frc/smartdashboard/Mechanism2d.h>
+#include <frc/smartdashboard/MechanismLigament2d.h>
+#include <frc/smartdashboard/MechanismRoot2d.h>
+#include <frc/smartdashboard/SmartDashboard.h>
#include <frc/system/plant/LinearSystemId.h>
+#include <frc/util/Color.h>
+#include <frc/util/Color8Bit.h>
#include <units/angle.h>
+#include <units/length.h>
#include <units/moment_of_inertia.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -37,13 +40,13 @@
static constexpr units::meter_t kElevatorDrumRadius = 2_in;
static constexpr units::kilogram_t kCarriageMass = 4.0_kg;
- static constexpr units::meter_t kMinElevatorHeight = 0_in;
+ static constexpr units::meter_t kMinElevatorHeight = 2_in;
static constexpr units::meter_t kMaxElevatorHeight = 50_in;
// distance per pulse = (distance per revolution) / (pulses per revolution)
// = (Pi * D) / ppr
static constexpr double kArmEncoderDistPerPulse =
- 2.0 * wpi::math::pi * kElevatorDrumRadius.to<double>() / 4096.0;
+ 2.0 * wpi::numbers::pi * kElevatorDrumRadius.value() / 4096.0;
// This gearbox represents a gearbox containing 4 Vex 775pro motors.
frc::DCMotor m_elevatorGearbox = frc::DCMotor::Vex775Pro(4);
@@ -51,7 +54,7 @@
// Standard classes for controlling our elevator
frc2::PIDController m_controller{kElevatorKp, 0, 0};
frc::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel};
- frc::PWMVictorSPX m_motor{kMotorPort};
+ frc::PWMSparkMax m_motor{kMotorPort};
frc::Joystick m_joystick{kJoystickPort};
// Simulation classes help us simulate what's going on, including gravity.
@@ -64,31 +67,49 @@
{0.01}};
frc::sim::EncoderSim m_encoderSim{m_encoder};
- public:
- void RobotInit() { m_encoder.SetDistancePerPulse(kArmEncoderDistPerPulse); }
+ // Create a Mechanism2d display of an elevator
+ frc::Mechanism2d m_mech2d{20, 50};
+ frc::MechanismRoot2d* m_elevatorRoot =
+ m_mech2d.GetRoot("Elevator Root", 10, 0);
+ frc::MechanismLigament2d* m_elevatorMech2d =
+ m_elevatorRoot->Append<frc::MechanismLigament2d>(
+ "Elevator", units::inch_t(m_elevatorSim.GetPosition()).value(),
+ 90_deg);
- void SimulationPeriodic() {
+ public:
+ void RobotInit() override {
+ m_encoder.SetDistancePerPulse(kArmEncoderDistPerPulse);
+
+ // Put Mechanism 2d to SmartDashboard
+ frc::SmartDashboard::PutData("Elevator Sim", &m_mech2d);
+ }
+
+ void SimulationPeriodic() override {
// In this method, we update our simulation of what our elevator is doing
// First, we set our "inputs" (voltages)
- m_elevatorSim.SetInput(frc::MakeMatrix<1, 1>(
- m_motor.Get() * frc::RobotController::GetInputVoltage()));
+ m_elevatorSim.SetInput(Eigen::Vector<double, 1>{
+ m_motor.Get() * frc::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
m_elevatorSim.Update(20_ms);
// Finally, we set our simulated encoder's readings and simulated battery
// voltage
- m_encoderSim.SetDistance(m_elevatorSim.GetPosition().to<double>());
+ m_encoderSim.SetDistance(m_elevatorSim.GetPosition().value());
// SimBattery estimates loaded battery voltages
frc::sim::RoboRioSim::SetVInVoltage(
frc::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()}));
+
+ // Update the Elevator length based on the simulated elevator height
+ m_elevatorMech2d->SetLength(
+ units::inch_t(m_elevatorSim.GetPosition()).value());
}
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
if (m_joystick.GetTrigger()) {
// Here, we run PID control like normal, with a constant setpoint of 30in.
- double pidOutput =
- m_controller.Calculate(m_encoder.GetDistance(), (30_in).to<double>());
+ double pidOutput = m_controller.Calculate(m_encoder.GetDistance(),
+ units::meter_t(30_in).value());
m_motor.SetVoltage(units::volt_t(pidOutput));
} else {
// Otherwise, we disable the motor.
@@ -96,12 +117,14 @@
}
}
- void DisabledInit() {
+ void DisabledInit() override {
// This just makes sure that our simulation code knows that the motor's off.
m_motor.Set(0.0);
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp
index 5addac4..d629185 100644
--- a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Joystick.h>
#include <frc/TimedRobot.h>
@@ -14,7 +11,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
#include "ExampleSmartMotorController.h"
@@ -46,7 +43,7 @@
// Send setpoint to offboard controller PID
m_motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition,
- m_setpoint.position.to<double>(),
+ m_setpoint.position.value(),
m_feedforward.Calculate(m_setpoint.velocity) / 12_V);
}
@@ -64,5 +61,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h
index f0e888d..5d55839 100644
--- a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h
+++ b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <frc/SpeedController.h>
+#include <frc/motorcontrol/MotorController.h>
/**
* A simplified stub class that simulates the API of a common "smart" motor
@@ -15,7 +12,7 @@
*
* <p>Has no actual functionality.
*/
-class ExampleSmartMotorController : public frc::SpeedController {
+class ExampleSmartMotorController : public frc::MotorController {
public:
enum PIDMode { kPosition, kVelocity, kMovementWitchcraft };
@@ -82,6 +79,4 @@
void Disable() override {}
void StopMotor() override {}
-
- void PIDWrite(double output) override {}
};
diff --git a/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp
index 3cfffd7..7db2c83 100644
--- a/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/smartdashboard/SmartDashboard.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* Sample program displaying the value of a quadrature encoder on the
@@ -43,7 +40,7 @@
* inch diameter (1.5inch radius) wheel, and that we want to measure
* distance in inches.
*/
- m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::math::pi * 1.5);
+ m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::numbers::pi * 1.5);
/* Defines the lowest rate at which the encoder will not be considered
* stopped, for the purposes of the GetStopped() method. Units are in
@@ -82,5 +79,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp
index 729a6c6..b781422 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -19,9 +16,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -30,18 +26,21 @@
// Configure your button bindings here
// Spin up the shooter when the 'A' button is pressed
- frc2::JoystickButton(&m_driverController, 1).WhenPressed(&m_spinUpShooter);
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
+ .WhenPressed(&m_spinUpShooter);
// Turn off the shooter when the 'B' button is pressed
- frc2::JoystickButton(&m_driverController, 2).WhenPressed(&m_stopShooter);
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
+ .WhenPressed(&m_stopShooter);
// Shoot when the 'X' button is held
- frc2::JoystickButton(&m_driverController, 3)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kX)
.WhenPressed(&m_shoot)
.WhenReleased(&m_stopFeeder);
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
+ frc2::JoystickButton(&m_driverController,
+ frc::XboxController::Button::kRightBumper)
.WhenPressed(&m_driveHalfSpeed)
.WhenReleased(&m_driveFullSpeed);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/DriveSubsystem.cpp
index 47c898e..f40a649 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -16,6 +13,11 @@
m_right2{kRightMotor2Port},
m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]},
m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_leftMotors.SetInverted(true);
+
// Set the distance per pulse for the encoders
m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
@@ -38,9 +40,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp
index 85be752..c386ee7 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/ShooterSubsystem.h"
@@ -19,9 +16,9 @@
m_feederMotor(kFeederMotorPort),
m_shooterEncoder(kEncoderPorts[0], kEncoderPorts[1]),
m_shooterFeedforward(kS, kV) {
- m_controller.SetTolerance(kShooterToleranceRPS.to<double>());
+ m_controller.SetTolerance(kShooterToleranceRPS.value());
m_shooterEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
- SetSetpoint(kShooterTargetRPS.to<double>());
+ SetSetpoint(kShooterTargetRPS.value());
}
void ShooterSubsystem::UseOutput(double output, double setpoint) {
@@ -29,10 +26,18 @@
m_shooterFeedforward.Calculate(kShooterTargetRPS));
}
-bool ShooterSubsystem::AtSetpoint() { return m_controller.AtSetpoint(); }
+bool ShooterSubsystem::AtSetpoint() {
+ return m_controller.AtSetpoint();
+}
-double ShooterSubsystem::GetMeasurement() { return m_shooterEncoder.GetRate(); }
+double ShooterSubsystem::GetMeasurement() {
+ return m_shooterEncoder.GetRate();
+}
-void ShooterSubsystem::RunFeeder() { m_feederMotor.Set(kFeederSpeed); }
+void ShooterSubsystem::RunFeeder() {
+ m_feederMotor.Set(kFeederSpeed);
+}
-void ShooterSubsystem::StopFeeder() { m_feederMotor.Set(0); }
+void ShooterSubsystem::StopFeeder() {
+ m_feederMotor.Set(0);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h
index 0e2d0e7..8ac7b0e 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <units/angle.h>
#include <units/time.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -36,7 +33,8 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterInches * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace ShooterConstants {
@@ -74,5 +72,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h
index 76dff49..26714fe 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -59,8 +56,7 @@
// Shoot for the specified time
frc2::WaitCommand(ac::kAutoShootTimeSeconds)}
// Add a timeout (will end the command if, for instance, the shooter
- // never gets up to
- // speed)
+ // never gets up to speed)
.WithTimeout(ac::kAutoTimeoutSeconds)
// When the command ends, turn off the shooter and the feeder
.AndThen([this] {
@@ -76,15 +72,14 @@
frc2::InstantCommand m_stopShooter{[this] { m_shooter.Disable(); },
{&m_shooter}};
- // Shoots if the shooter wheen has reached the target speed
+ // Shoots if the shooter wheel has reached the target speed
frc2::ConditionalCommand m_shoot{
// Run the feeder
frc2::InstantCommand{[this] { m_shooter.RunFeeder(); }, {&m_shooter}},
// Do nothing
frc2::InstantCommand(),
// Determine which of the above to do based on whether the shooter has
- // reached the
- // desired speed
+ // reached the desired speed
[this] { return m_shooter.AtSetpoint(); }};
frc2::InstantCommand m_stopFeeder{[this] { m_shooter.StopFeeder(); },
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h
index 3ed1357..47bf28e 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -73,16 +70,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1;
- frc::PWMVictorSPX m_left2;
- frc::PWMVictorSPX m_right1;
- frc::PWMVictorSPX m_right2;
+ frc::PWMSparkMax m_left1;
+ frc::PWMSparkMax m_left2;
+ frc::PWMSparkMax m_right1;
+ frc::PWMSparkMax m_right2;
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h
index 7553544..e53b32d 100644
--- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h
@@ -1,15 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/PIDSubsystem.h>
#include <units/angle.h>
@@ -28,8 +25,8 @@
void StopFeeder();
private:
- frc::PWMVictorSPX m_shooterMotor;
- frc::PWMVictorSPX m_feederMotor;
+ frc::PWMSparkMax m_shooterMotor;
+ frc::PWMSparkMax m_feederMotor;
frc::Encoder m_shooterEncoder;
frc::SimpleMotorFeedforward<units::turns> m_shooterFeedforward;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp
index 11a1d75..3ac0f75 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -25,10 +22,9 @@
frc::SmartDashboard::PutData(&m_wrist);
frc::SmartDashboard::PutData(&m_claw);
- m_drivetrain.SetDefaultCommand(TankDrive(
- [this] { return m_joy.GetY(frc::GenericHID::JoystickHand::kLeftHand); },
- [this] { return m_joy.GetY(frc::GenericHID::JoystickHand::kRightHand); },
- &m_drivetrain));
+ m_drivetrain.SetDefaultCommand(TankDrive([this] { return m_joy.GetLeftY(); },
+ [this] { return m_joy.GetRightY(); },
+ &m_drivetrain));
// Configure the button bindings
ConfigureButtonBindings();
@@ -36,24 +32,20 @@
void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here
- frc2::JoystickButton m_dUp{&m_joy, 5};
- frc2::JoystickButton m_dRight{&m_joy, 6};
- frc2::JoystickButton m_dDown{&m_joy, 7};
- frc2::JoystickButton m_dLeft{&m_joy, 8};
- frc2::JoystickButton m_l2{&m_joy, 9};
- frc2::JoystickButton m_r2{&m_joy, 10};
- frc2::JoystickButton m_l1{&m_joy, 11};
- frc2::JoystickButton m_r1{&m_joy, 12};
-
- m_dUp.WhenPressed(SetElevatorSetpoint(0.2, &m_elevator));
- m_dDown.WhenPressed(SetElevatorSetpoint(-0.2, &m_elevator));
- m_dRight.WhenPressed(CloseClaw(&m_claw));
- m_dLeft.WhenPressed(OpenClaw(&m_claw));
-
- m_r1.WhenPressed(PrepareToPickup(&m_claw, &m_wrist, &m_elevator));
- m_r2.WhenPressed(Pickup(&m_claw, &m_wrist, &m_elevator));
- m_l1.WhenPressed(Place(&m_claw, &m_wrist, &m_elevator));
- m_l2.WhenPressed(Autonomous(&m_claw, &m_wrist, &m_elevator, &m_drivetrain));
+ frc2::JoystickButton(&m_joy, 5).WhenPressed(
+ SetElevatorSetpoint(0.25, &m_elevator));
+ frc2::JoystickButton(&m_joy, 6).WhenPressed(CloseClaw(&m_claw));
+ frc2::JoystickButton(&m_joy, 7).WhenPressed(
+ SetElevatorSetpoint(0.0, &m_elevator));
+ frc2::JoystickButton(&m_joy, 8).WhenPressed(OpenClaw(&m_claw));
+ frc2::JoystickButton(&m_joy, 9).WhenPressed(
+ Autonomous(&m_claw, &m_wrist, &m_elevator, &m_drivetrain));
+ frc2::JoystickButton(&m_joy, 10)
+ .WhenPressed(Pickup(&m_claw, &m_wrist, &m_elevator));
+ frc2::JoystickButton(&m_joy, 11)
+ .WhenPressed(Place(&m_claw, &m_wrist, &m_elevator));
+ frc2::JoystickButton(&m_joy, 12)
+ .WhenPressed(PrepareToPickup(&m_claw, &m_wrist, &m_elevator));
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Autonomous.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Autonomous.cpp
index 5db0cdb..23ccfff 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Autonomous.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Autonomous.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/Autonomous.h"
@@ -18,7 +15,7 @@
#include "commands/SetWristSetpoint.h"
Autonomous::Autonomous(Claw* claw, Wrist* wrist, Elevator* elevator,
- DriveTrain* drivetrain) {
+ Drivetrain* drivetrain) {
SetName("Autonomous");
AddCommands(
// clang-format off
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp
index 97a9ccf..d10c310 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/CloseClaw.h"
@@ -15,10 +12,14 @@
}
// Called just before this Command runs the first time
-void CloseClaw::Initialize() { m_claw->Close(); }
+void CloseClaw::Initialize() {
+ m_claw->Close();
+}
// Make this return true when this Command no longer needs to run execute()
-bool CloseClaw::IsFinished() { return m_claw->IsGripping(); }
+bool CloseClaw::IsFinished() {
+ return m_claw->IsGripping();
+}
// Called once after isFinished returns true
void CloseClaw::End(bool) {
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp
index d84951c..60408db 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/DriveStraight.h"
@@ -11,11 +8,11 @@
#include "Robot.h"
-DriveStraight::DriveStraight(double distance, DriveTrain* drivetrain)
+DriveStraight::DriveStraight(double distance, Drivetrain* drivetrain)
: frc2::CommandHelper<frc2::PIDCommand, DriveStraight>(
frc2::PIDController(4, 0, 0),
- [this]() { return m_drivetrain->GetDistance(); }, distance,
- [this](double output) { m_drivetrain->Drive(output, output); },
+ [drivetrain] { return drivetrain->GetDistance(); }, distance,
+ [drivetrain](double output) { drivetrain->Drive(output, output); },
{drivetrain}),
m_drivetrain(drivetrain) {
m_controller.SetTolerance(0.01);
@@ -28,4 +25,6 @@
frc2::PIDCommand::Initialize();
}
-bool DriveStraight::IsFinished() { return m_controller.AtSetpoint(); }
+bool DriveStraight::IsFinished() {
+ return m_controller.AtSetpoint();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp
index bd1414a..e05b7bd 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/OpenClaw.h"
@@ -22,4 +19,6 @@
}
// Called once after isFinished returns true
-void OpenClaw::End(bool) { m_claw->Stop(); }
+void OpenClaw::End(bool) {
+ m_claw->Stop();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Pickup.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Pickup.cpp
index 996414f..7d32ef4 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Pickup.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Pickup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/Pickup.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Place.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Place.cpp
index 764ab0e..ff52a8f 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Place.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/Place.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/Place.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/PrepareToPickup.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/PrepareToPickup.cpp
index f1399d0..2a05e25 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/PrepareToPickup.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/PrepareToPickup.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/PrepareToPickup.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp
index 5da3045..d594797 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/SetDistanceToBox.h"
@@ -11,11 +8,12 @@
#include "Robot.h"
-SetDistanceToBox::SetDistanceToBox(double distance, DriveTrain* drivetrain)
+SetDistanceToBox::SetDistanceToBox(double distance, Drivetrain* drivetrain)
: frc2::CommandHelper<frc2::PIDCommand, SetDistanceToBox>(
frc2::PIDController(-2, 0, 0),
- [this]() { return m_drivetrain->GetDistanceToObstacle(); }, distance,
- [this](double output) { m_drivetrain->Drive(output, output); },
+ [drivetrain] { return drivetrain->GetDistanceToObstacle(); },
+ distance,
+ [drivetrain](double output) { drivetrain->Drive(output, output); },
{drivetrain}),
m_drivetrain(drivetrain) {
m_controller.SetTolerance(0.01);
@@ -28,4 +26,6 @@
frc2::PIDCommand::Initialize();
}
-bool SetDistanceToBox::IsFinished() { return m_controller.AtSetpoint(); }
+bool SetDistanceToBox::IsFinished() {
+ return m_controller.AtSetpoint();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetElevatorSetpoint.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetElevatorSetpoint.cpp
index 161c1ee..e539903 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetElevatorSetpoint.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetElevatorSetpoint.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/SetElevatorSetpoint.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetWristSetpoint.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetWristSetpoint.cpp
index 50c9d0a..5063a99 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetWristSetpoint.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetWristSetpoint.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/SetWristSetpoint.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/TankDrive.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/TankDrive.cpp
index 58b1cfe..a68edab 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/TankDrive.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/TankDrive.cpp
@@ -1,26 +1,33 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/TankDrive.h"
+#include <utility>
+
#include "Robot.h"
TankDrive::TankDrive(std::function<double()> left,
- std::function<double()> right, DriveTrain* drivetrain)
- : m_left(left), m_right(right), m_drivetrain(drivetrain) {
+ std::function<double()> right, Drivetrain* drivetrain)
+ : m_left(std::move(left)),
+ m_right(std::move(right)),
+ m_drivetrain(drivetrain) {
SetName("TankDrive");
AddRequirements({m_drivetrain});
}
// Called repeatedly when this Command is scheduled to run
-void TankDrive::Execute() { m_drivetrain->Drive(m_left(), m_right()); }
+void TankDrive::Execute() {
+ m_drivetrain->Drive(m_left(), m_right());
+}
// Make this return true when this Command no longer needs to run execute()
-bool TankDrive::IsFinished() { return false; }
+bool TankDrive::IsFinished() {
+ return false;
+}
// Called once after isFinished returns true
-void TankDrive::End(bool) { m_drivetrain->Drive(0, 0); }
+void TankDrive::End(bool) {
+ m_drivetrain->Drive(0, 0);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp
index e4ebc14..b1560da 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/Claw.h"
@@ -15,16 +12,26 @@
AddChild("Motor", &m_motor);
}
-void Claw::Open() { m_motor.Set(-1); }
+void Claw::Open() {
+ m_motor.Set(-1);
+}
-void Claw::Close() { m_motor.Set(1); }
+void Claw::Close() {
+ m_motor.Set(1);
+}
-void Claw::Stop() { m_motor.Set(0); }
+void Claw::Stop() {
+ m_motor.Set(0);
+}
-bool Claw::IsGripping() { return m_contact.Get(); }
+bool Claw::IsGripping() {
+ return m_contact.Get();
+}
void Claw::Log() {
frc::SmartDashboard::PutBoolean("Claw switch", IsGripping());
}
-void Claw::Periodic() { Log(); }
+void Claw::Periodic() {
+ Log();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/DriveTrain.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/DriveTrain.cpp
deleted file mode 100644
index 6bc946c..0000000
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/DriveTrain.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "subsystems/DriveTrain.h"
-
-#include <frc/Joystick.h>
-#include <frc/smartdashboard/SmartDashboard.h>
-
-DriveTrain::DriveTrain() {
-// Encoders may measure differently in the real world and in
-// simulation. In this example the robot moves 0.042 barleycorns
-// per tick in the real world, but the simulated encoders
-// simulate 360 tick encoders. This if statement allows for the
-// real robot to handle this difference in devices.
-#ifndef SIMULATION
- m_leftEncoder.SetDistancePerPulse(0.042);
- m_rightEncoder.SetDistancePerPulse(0.042);
-#else
- // Circumference in ft = 4in/12(in/ft)*PI
- m_leftEncoder.SetDistancePerPulse(static_cast<double>(4.0 / 12.0 * M_PI) /
- 360.0);
- m_rightEncoder.SetDistancePerPulse(static_cast<double>(4.0 / 12.0 * M_PI) /
- 360.0);
-#endif
- SetName("DriveTrain");
- // Let's show everything on the LiveWindow
- AddChild("Front_Left Motor", &m_frontLeft);
- AddChild("Rear Left Motor", &m_rearLeft);
- AddChild("Front Right Motor", &m_frontRight);
- AddChild("Rear Right Motor", &m_rearRight);
- AddChild("Left Encoder", &m_leftEncoder);
- AddChild("Right Encoder", &m_rightEncoder);
- AddChild("Rangefinder", &m_rangefinder);
- AddChild("Gyro", &m_gyro);
-}
-
-void DriveTrain::Log() {
- frc::SmartDashboard::PutNumber("Left Distance", m_leftEncoder.GetDistance());
- frc::SmartDashboard::PutNumber("Right Distance",
- m_rightEncoder.GetDistance());
- frc::SmartDashboard::PutNumber("Left Speed", m_leftEncoder.GetRate());
- frc::SmartDashboard::PutNumber("Right Speed", m_rightEncoder.GetRate());
- frc::SmartDashboard::PutNumber("Gyro", m_gyro.GetAngle());
-}
-
-void DriveTrain::Drive(double left, double right) {
- m_robotDrive.TankDrive(left, right);
-}
-
-double DriveTrain::GetHeading() { return m_gyro.GetAngle(); }
-
-void DriveTrain::Reset() {
- m_gyro.Reset();
- m_leftEncoder.Reset();
- m_rightEncoder.Reset();
-}
-
-double DriveTrain::GetDistance() {
- return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
-}
-
-double DriveTrain::GetDistanceToObstacle() {
- // Really meters in simulation since it's a rangefinder...
- return m_rangefinder.GetAverageVoltage();
-}
-
-void DriveTrain::Periodic() { Log(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp
new file mode 100644
index 0000000..f3d41a2
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp
@@ -0,0 +1,79 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/Drivetrain.h"
+
+#include <frc/Joystick.h>
+#include <frc/smartdashboard/SmartDashboard.h>
+#include <units/length.h>
+#include <wpi/numbers>
+
+Drivetrain::Drivetrain() {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_right.SetInverted(true);
+
+// Encoders may measure differently in the real world and in
+// simulation. In this example the robot moves 0.042 barleycorns
+// per tick in the real world, but the simulated encoders
+// simulate 360 tick encoders. This if statement allows for the
+// real robot to handle this difference in devices.
+#ifndef SIMULATION
+ m_leftEncoder.SetDistancePerPulse(0.042);
+ m_rightEncoder.SetDistancePerPulse(0.042);
+#else
+ // Circumference = diameter * pi. 360 tick simulated encoders.
+ m_leftEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() *
+ wpi::numbers::pi / 360.0);
+ m_rightEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() *
+ wpi::numbers::pi / 360.0);
+#endif
+ SetName("Drivetrain");
+ // Let's show everything on the LiveWindow
+ AddChild("Front_Left Motor", &m_frontLeft);
+ AddChild("Rear Left Motor", &m_rearLeft);
+ AddChild("Front Right Motor", &m_frontRight);
+ AddChild("Rear Right Motor", &m_rearRight);
+ AddChild("Left Encoder", &m_leftEncoder);
+ AddChild("Right Encoder", &m_rightEncoder);
+ AddChild("Rangefinder", &m_rangefinder);
+ AddChild("Gyro", &m_gyro);
+}
+
+void Drivetrain::Log() {
+ frc::SmartDashboard::PutNumber("Left Distance", m_leftEncoder.GetDistance());
+ frc::SmartDashboard::PutNumber("Right Distance",
+ m_rightEncoder.GetDistance());
+ frc::SmartDashboard::PutNumber("Left Speed", m_leftEncoder.GetRate());
+ frc::SmartDashboard::PutNumber("Right Speed", m_rightEncoder.GetRate());
+ frc::SmartDashboard::PutNumber("Gyro", m_gyro.GetAngle());
+}
+
+void Drivetrain::Drive(double left, double right) {
+ m_robotDrive.TankDrive(left, right);
+}
+
+double Drivetrain::GetHeading() {
+ return m_gyro.GetAngle();
+}
+
+void Drivetrain::Reset() {
+ m_gyro.Reset();
+ m_leftEncoder.Reset();
+ m_rightEncoder.Reset();
+}
+
+double Drivetrain::GetDistance() {
+ return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
+}
+
+double Drivetrain::GetDistanceToObstacle() {
+ // Really meters in simulation since it's a rangefinder...
+ return m_rangefinder.GetAverageVoltage();
+}
+
+void Drivetrain::Periodic() {
+ Log();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp
index d5e4ddd..0c195e3 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/Elevator.h"
@@ -24,12 +21,18 @@
AddChild("Pot", &m_pot);
}
-void Elevator::Log() { frc::SmartDashboard::PutData("Wrist Pot", &m_pot); }
+void Elevator::Log() {
+ frc::SmartDashboard::PutData("Wrist Pot", &m_pot);
+}
-double Elevator::GetMeasurement() { return m_pot.Get(); }
+double Elevator::GetMeasurement() {
+ return m_pot.Get();
+}
void Elevator::UseOutput(double output, double setpoint) {
m_motor.Set(output);
}
-void Elevator::Periodic() { Log(); }
+void Elevator::Periodic() {
+ Log();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp
index a335a63..fb3ab35 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/Wrist.h"
@@ -26,8 +23,14 @@
frc::SmartDashboard::PutNumber("Wrist Angle", GetMeasurement());
}
-double Wrist::GetMeasurement() { return m_pot.Get(); }
+double Wrist::GetMeasurement() {
+ return m_pot.Get();
+}
-void Wrist::UseOutput(double output, double setpoint) { m_motor.Set(output); }
+void Wrist::UseOutput(double output, double setpoint) {
+ m_motor.Set(output);
+}
-void Wrist::Periodic() { Log(); }
+void Wrist::Periodic() {
+ Log();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/RobotContainer.h
index 50fc7d6..ae1ec9d 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/RobotContainer.h
@@ -1,18 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <frc/Joystick.h>
+#include <frc/XboxController.h>
#include <frc2/command/Command.h>
#include "commands/Autonomous.h"
#include "subsystems/Claw.h"
-#include "subsystems/DriveTrain.h"
+#include "subsystems/Drivetrain.h"
#include "subsystems/Elevator.h"
#include "subsystems/Wrist.h"
@@ -31,12 +28,12 @@
private:
// The robot's subsystems and commands are defined here...
- frc::Joystick m_joy{0};
+ frc::XboxController m_joy{0};
Claw m_claw;
Wrist m_wrist;
Elevator m_elevator;
- DriveTrain m_drivetrain;
+ Drivetrain m_drivetrain;
Autonomous m_autonomousCommand;
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Autonomous.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Autonomous.h
index c0d429c..5dae1c1 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Autonomous.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Autonomous.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,7 +8,7 @@
#include <frc2/command/SequentialCommandGroup.h>
#include "subsystems/Claw.h"
-#include "subsystems/DriveTrain.h"
+#include "subsystems/Drivetrain.h"
#include "subsystems/Elevator.h"
#include "subsystems/Wrist.h"
@@ -22,5 +19,5 @@
: public frc2::CommandHelper<frc2::SequentialCommandGroup, Autonomous> {
public:
Autonomous(Claw* claw, Wrist* wrist, Elevator* elevator,
- DriveTrain* drivetrain);
+ Drivetrain* drivetrain);
};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/CloseClaw.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/CloseClaw.h
index a5e6c0b..fe8133b 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/CloseClaw.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/CloseClaw.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -13,8 +10,7 @@
#include "subsystems/Claw.h"
/**
- * Opens the claw for one second. Real robots should use sensors, stalling
- * motors is BAD!
+ * Closes the claw until the limit switch is tripped.
*/
class CloseClaw : public frc2::CommandHelper<frc2::CommandBase, CloseClaw> {
public:
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/DriveStraight.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/DriveStraight.h
index 1955169..abc598c 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/DriveStraight.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/DriveStraight.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/PIDCommand.h>
-#include "subsystems/DriveTrain.h"
+#include "subsystems/Drivetrain.h"
/**
* Drive the given distance straight (negative values go backwards).
@@ -21,10 +18,10 @@
class DriveStraight
: public frc2::CommandHelper<frc2::PIDCommand, DriveStraight> {
public:
- explicit DriveStraight(double distance, DriveTrain* drivetrain);
+ explicit DriveStraight(double distance, Drivetrain* drivetrain);
void Initialize() override;
bool IsFinished() override;
private:
- DriveTrain* m_drivetrain;
+ Drivetrain* m_drivetrain;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/OpenClaw.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/OpenClaw.h
index 486f86b..f7b3d0f 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/OpenClaw.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/OpenClaw.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Pickup.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Pickup.h
index 4d74588..33327eb 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Pickup.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Pickup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Place.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Place.h
index 85945c3..353ef1c 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Place.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/Place.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/PrepareToPickup.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/PrepareToPickup.h
index b2aa4d1..0289d4f 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/PrepareToPickup.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/PrepareToPickup.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetDistanceToBox.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetDistanceToBox.h
index b5b7b13..2104a5c 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetDistanceToBox.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetDistanceToBox.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/PIDCommand.h>
-#include "subsystems/DriveTrain.h"
+#include "subsystems/Drivetrain.h"
/**
* Drive until the robot is the given distance away from the box. Uses a local
@@ -21,10 +18,10 @@
class SetDistanceToBox
: public frc2::CommandHelper<frc2::PIDCommand, SetDistanceToBox> {
public:
- explicit SetDistanceToBox(double distance, DriveTrain* drivetrain);
+ explicit SetDistanceToBox(double distance, Drivetrain* drivetrain);
void Initialize() override;
bool IsFinished() override;
private:
- DriveTrain* m_drivetrain;
+ Drivetrain* m_drivetrain;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetElevatorSetpoint.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetElevatorSetpoint.h
index c3bcf6f..8df402d 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetElevatorSetpoint.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetElevatorSetpoint.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetWristSetpoint.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetWristSetpoint.h
index 96c01fa..e362b30 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetWristSetpoint.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/SetWristSetpoint.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/TankDrive.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/TankDrive.h
index bdfd592..c49fdf3 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/TankDrive.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/commands/TankDrive.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/CommandHelper.h>
-#include "subsystems/DriveTrain.h"
+#include "subsystems/Drivetrain.h"
/**
* Have the robot drive tank style using the PS3 Joystick until interrupted.
@@ -18,7 +15,7 @@
class TankDrive : public frc2::CommandHelper<frc2::CommandBase, TankDrive> {
public:
TankDrive(std::function<double()> left, std::function<double()> right,
- DriveTrain* drivetrain);
+ Drivetrain* drivetrain);
void Execute() override;
bool IsFinished() override;
void End(bool interrupted) override;
@@ -26,5 +23,5 @@
private:
std::function<double()> m_left;
std::function<double()> m_right;
- DriveTrain* m_drivetrain;
+ Drivetrain* m_drivetrain;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h
index a660c1c..3b65382 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/DigitalInput.h>
-#include <frc/PWMVictorSPX.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
/**
@@ -53,6 +50,6 @@
void Periodic() override;
private:
- frc::PWMVictorSPX m_motor{7};
+ frc::PWMSparkMax m_motor{7};
frc::DigitalInput m_contact{5};
};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h
deleted file mode 100644
index 0fed552..0000000
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/AnalogGyro.h>
-#include <frc/AnalogInput.h>
-#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
-#include <frc/drive/DifferentialDrive.h>
-#include <frc2/command/SubsystemBase.h>
-
-namespace frc {
-class Joystick;
-} // namespace frc
-
-/**
- * The DriveTrain subsystem incorporates the sensors and actuators attached to
- * the robots chassis. These include four drive motors, a left and right encoder
- * and a gyro.
- */
-class DriveTrain : public frc2::SubsystemBase {
- public:
- DriveTrain();
-
- /**
- * The log method puts interesting information to the SmartDashboard.
- */
- void Log();
-
- /**
- * Tank style driving for the DriveTrain.
- * @param left Speed in range [-1,1]
- * @param right Speed in range [-1,1]
- */
- void Drive(double left, double right);
-
- /**
- * @return The robots heading in degrees.
- */
- double GetHeading();
-
- /**
- * Reset the robots sensors to the zero states.
- */
- void Reset();
-
- /**
- * @return The distance driven (average of left and right encoders).
- */
- double GetDistance();
-
- /**
- * @return The distance to the obstacle detected by the rangefinder.
- */
- double GetDistanceToObstacle();
-
- /**
- * Log the data periodically. This method is automatically called
- * by the subsystem.
- */
- void Periodic() override;
-
- private:
- frc::PWMVictorSPX m_frontLeft{1};
- frc::PWMVictorSPX m_rearLeft{2};
- frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft};
-
- frc::PWMVictorSPX m_frontRight{3};
- frc::PWMVictorSPX m_rearRight{4};
- frc::SpeedControllerGroup m_right{m_frontRight, m_rearRight};
-
- frc::DifferentialDrive m_robotDrive{m_left, m_right};
-
- frc::Encoder m_leftEncoder{1, 2};
- frc::Encoder m_rightEncoder{3, 4};
- frc::AnalogInput m_rangefinder{6};
- frc::AnalogGyro m_gyro{1};
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Drivetrain.h
new file mode 100644
index 0000000..108a9c0
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Drivetrain.h
@@ -0,0 +1,81 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/AnalogGyro.h>
+#include <frc/AnalogInput.h>
+#include <frc/Encoder.h>
+#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc2/command/SubsystemBase.h>
+
+namespace frc {
+class Joystick;
+} // namespace frc
+
+/**
+ * The Drivetrain subsystem incorporates the sensors and actuators attached to
+ * the robots chassis. These include four drive motors, a left and right encoder
+ * and a gyro.
+ */
+class Drivetrain : public frc2::SubsystemBase {
+ public:
+ Drivetrain();
+
+ /**
+ * The log method puts interesting information to the SmartDashboard.
+ */
+ void Log();
+
+ /**
+ * Tank style driving for the Drivetrain.
+ * @param left Speed in range [-1,1]
+ * @param right Speed in range [-1,1]
+ */
+ void Drive(double left, double right);
+
+ /**
+ * @return The robots heading in degrees.
+ */
+ double GetHeading();
+
+ /**
+ * Reset the robots sensors to the zero states.
+ */
+ void Reset();
+
+ /**
+ * @return The distance driven (average of left and right encoders).
+ */
+ double GetDistance();
+
+ /**
+ * @return The distance to the obstacle detected by the rangefinder.
+ */
+ double GetDistanceToObstacle();
+
+ /**
+ * Log the data periodically. This method is automatically called
+ * by the subsystem.
+ */
+ void Periodic() override;
+
+ private:
+ frc::PWMSparkMax m_frontLeft{1};
+ frc::PWMSparkMax m_rearLeft{2};
+ frc::MotorControllerGroup m_left{m_frontLeft, m_rearLeft};
+
+ frc::PWMSparkMax m_frontRight{3};
+ frc::PWMSparkMax m_rearRight{4};
+ frc::MotorControllerGroup m_right{m_frontRight, m_rearRight};
+
+ frc::DifferentialDrive m_robotDrive{m_left, m_right};
+
+ frc::Encoder m_leftEncoder{1, 2};
+ frc::Encoder m_rightEncoder{3, 4};
+ frc::AnalogInput m_rangefinder{6};
+ frc::AnalogGyro m_gyro{1};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h
index 5d2cbd1..80008c5 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/AnalogPotentiometer.h>
-#include <frc/PWMVictorSPX.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/PIDSubsystem.h>
/**
@@ -46,7 +43,7 @@
void Periodic() override;
private:
- frc::PWMVictorSPX m_motor{5};
+ frc::PWMSparkMax m_motor{5};
double m_setpoint = 0;
// Conversion value of potentiometer varies between the real world and
diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h
index 795d2a4..e873c2c 100644
--- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h
+++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/AnalogPotentiometer.h>
-#include <frc/PWMVictorSPX.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/PIDSubsystem.h>
/**
@@ -43,7 +40,7 @@
void Periodic() override;
private:
- frc::PWMVictorSPX m_motor{6};
+ frc::PWMSparkMax m_motor{6};
double m_setpoint = 0;
// Conversion value of potentiometer varies between the real world and
diff --git a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp
index f43cb57..6b7d2b6 100644
--- a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp
@@ -1,21 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/Timer.h>
#include <frc/drive/DifferentialDrive.h>
-#include <frc/livewindow/LiveWindow.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
class Robot : public frc::TimedRobot {
public:
Robot() {
- m_robotDrive.SetExpiration(0.1);
+ m_robotDrive.SetExpiration(100_ms);
m_timer.Start();
}
@@ -26,9 +22,9 @@
void AutonomousPeriodic() override {
// Drive for 2 seconds
- if (m_timer.Get() < 2.0) {
+ if (m_timer.Get() < 2_s) {
// Drive forwards half speed
- m_robotDrive.ArcadeDrive(-0.5, 0.0);
+ m_robotDrive.ArcadeDrive(0.5, 0.0);
} else {
// Stop robot
m_robotDrive.ArcadeDrive(0.0, 0.0);
@@ -42,19 +38,22 @@
m_robotDrive.ArcadeDrive(m_stick.GetY(), m_stick.GetX());
}
+ void TestInit() override {}
+
void TestPeriodic() override {}
private:
// Robot drive system
- frc::PWMVictorSPX m_left{0};
- frc::PWMVictorSPX m_right{1};
+ frc::PWMSparkMax m_left{0};
+ frc::PWMSparkMax m_right{1};
frc::DifferentialDrive m_robotDrive{m_left, m_right};
frc::Joystick m_stick{0};
- frc::LiveWindow& m_lw = *frc::LiveWindow::GetInstance();
frc::Timer m_timer;
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
index b0c70d2..1dda356 100644
--- a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <cmath>
#include <frc/AnalogGyro.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a sample program to demonstrate how to use a gyro sensor to make a
@@ -47,8 +44,8 @@
static constexpr int kGyroPort = 0;
static constexpr int kJoystickPort = 0;
- frc::PWMVictorSPX m_left{kLeftMotorPort};
- frc::PWMVictorSPX m_right{kRightMotorPort};
+ frc::PWMSparkMax m_left{kLeftMotorPort};
+ frc::PWMSparkMax m_right{kRightMotorPort};
frc::DifferentialDrive m_robotDrive{m_left, m_right};
frc::AnalogGyro m_gyro{kGyroPort};
@@ -56,5 +53,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp
index 6213333..eb95395 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -22,9 +19,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -34,8 +30,8 @@
// Assorted commands to be bound to buttons
- // Stabilize robot to drive straight with gyro when left bumper is held
- frc2::JoystickButton(&m_driverController, 5)
+ // Stabilize robot to drive straight with gyro when L1 is held
+ frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kL1)
.WhenHeld(frc2::PIDCommand{
frc2::PIDController{dc::kStabilizationP, dc::kStabilizationI,
dc::kStabilizationD},
@@ -45,24 +41,22 @@
0,
// Pipe the output to the turning controls
[this](double output) {
- m_drive.ArcadeDrive(m_driverController.GetY(
- frc::GenericHID::JoystickHand::kLeftHand),
- output);
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(), output);
},
// Require the robot drive
{&m_drive}});
- // Turn to 90 degrees when the 'X' button is pressed
- frc2::JoystickButton(&m_driverController, 3)
+ // Turn to 90 degrees when the 'Cross' button is pressed
+ frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kCross)
.WhenPressed(TurnToAngle{90_deg, &m_drive}.WithTimeout(5_s));
- // Turn to -90 degrees with a profile when the 'A' button is pressed, with a 5
- // second timeout
- frc2::JoystickButton(&m_driverController, 1)
+ // Turn to -90 degrees with a profile when the 'Square' button is pressed,
+ // with a 5 second timeout
+ frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kSquare)
.WhenPressed(TurnToAngle{90_deg, &m_drive}.WithTimeout(5_s));
- // While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
+ // While holding R1, drive at half speed
+ frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kR1)
.WhenPressed(frc2::InstantCommand{[this] { m_drive.SetMaxOutput(0.5); }})
.WhenReleased(frc2::InstantCommand{[this] { m_drive.SetMaxOutput(1); }});
}
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp
index 0be1f73..681bb39 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/TurnToAngle.h"
@@ -15,9 +12,9 @@
: CommandHelper(
frc2::PIDController(kTurnP, kTurnI, kTurnD),
// Close loop on heading
- [drive] { return drive->GetHeading().to<double>(); },
+ [drive] { return drive->GetHeading().value(); },
// Set reference to target
- target.to<double>(),
+ target.value(),
// Pipe output to turn robot
[drive](double output) { drive->ArcadeDrive(0, output); },
// Require the drive
@@ -27,10 +24,11 @@
// Set the controller tolerance - the delta tolerance ensures the robot is
// stationary at the setpoint before it is considered as having reached the
// reference
- m_controller.SetTolerance(kTurnTolerance.to<double>(),
- kTurnRateTolerance.to<double>());
+ m_controller.SetTolerance(kTurnTolerance.value(), kTurnRateTolerance.value());
AddRequirements({drive});
}
-bool TurnToAngle::IsFinished() { return GetController().AtSetpoint(); }
+bool TurnToAngle::IsFinished() {
+ return GetController().AtSetpoint();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp
index c2baa90..a359625 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/TurnToAngleProfiled.h"
@@ -36,4 +33,6 @@
AddRequirements({drive});
}
-bool TurnToAngleProfiled::IsFinished() { return GetController().AtGoal(); }
+bool TurnToAngleProfiled::IsFinished() {
+ return GetController().AtGoal();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp
index c6d8d8c..baa78de 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -16,6 +13,11 @@
m_right2{kRightMotor2Port},
m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]},
m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotors.SetInverted(true);
+
// Set the distance per pulse for the encoders
m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
@@ -38,9 +40,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h
index cc8b841..210f82d 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Constants.h
@@ -1,15 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <units/angle.h>
#include <units/angular_velocity.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -35,7 +32,8 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterInches * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
constexpr bool kGyroReversed = true;
@@ -61,5 +59,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h
index 37c7e4f..041812e 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <frc/XboxController.h>
+#include <frc/PS4Controller.h>
#include <frc/controller/PIDController.h>
#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
@@ -35,7 +32,7 @@
private:
// The driver's controller
- frc::XboxController m_driverController{OIConstants::kDriverControllerPort};
+ frc::PS4Controller m_driverController{OIConstants::kDriverControllerPort};
// The robot's subsystems and commands are defined here...
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngle.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngle.h
index 4afa20e..6df79bf 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngle.h
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngle.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngleProfiled.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngleProfiled.h
index 0b52044..f3136aa 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngleProfiled.h
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/commands/TurnToAngleProfiled.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h
index cd3d667..96174dd 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/ADXRS450_Gyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include <units/angle.h>
@@ -89,16 +86,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1;
- frc::PWMVictorSPX m_left2;
- frc::PWMVictorSPX m_right1;
- frc::PWMVictorSPX m_right2;
+ frc::PWMSparkMax m_left1;
+ frc::PWMSparkMax m_left2;
+ frc::PWMSparkMax m_right1;
+ frc::PWMSparkMax m_right2;
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
diff --git a/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp
index 86b4f24..5885873 100644
--- a/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp
@@ -1,15 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogGyro.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/drive/MecanumDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a sample program that uses mecanum drive with a gyro sensor to
@@ -47,10 +44,10 @@
static constexpr int kGyroPort = 0;
static constexpr int kJoystickPort = 0;
- frc::PWMVictorSPX m_frontLeft{kFrontLeftMotorPort};
- frc::PWMVictorSPX m_rearLeft{kRearLeftMotorPort};
- frc::PWMVictorSPX m_frontRight{kFrontRightMotorPort};
- frc::PWMVictorSPX m_rearRight{kRearRightMotorPort};
+ frc::PWMSparkMax m_frontLeft{kFrontLeftMotorPort};
+ frc::PWMSparkMax m_rearLeft{kRearLeftMotorPort};
+ frc::PWMSparkMax m_frontRight{kFrontRightMotorPort};
+ frc::PWMSparkMax m_rearRight{kRearRightMotorPort};
frc::MecanumDrive m_robotDrive{m_frontLeft, m_rearLeft, m_frontRight,
m_rearRight};
@@ -59,5 +56,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c b/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c
index ae5833e..0db402b 100644
--- a/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c
+++ b/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
This example shows how to use the HAL directly, and what is needed to run a
@@ -65,10 +62,11 @@
// Create a Motor Controller
status = 0;
- HAL_DigitalHandle pwmPort = HAL_InitializePWMPort(HAL_GetPort(2), &status);
+ HAL_DigitalHandle pwmPort =
+ HAL_InitializePWMPort(HAL_GetPort(2), NULL, &status);
if (status != 0) {
- const char* message = HAL_GetErrorMessage(status);
+ const char* message = HAL_GetLastError(&status);
printf("%s\n", message);
return 1;
}
@@ -78,10 +76,11 @@
// Create an Input
status = 0;
- HAL_DigitalHandle dio = HAL_InitializeDIOPort(HAL_GetPort(2), 1, &status);
+ HAL_DigitalHandle dio =
+ HAL_InitializeDIOPort(HAL_GetPort(2), 1, NULL, &status);
if (status != 0) {
- const char* message = HAL_GetErrorMessage(status);
+ const char* message = HAL_GetLastError(&status);
printf("%s\n", message);
status = 0;
HAL_FreePWMPort(pwmPort, &status);
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp
index 90865ac..31a78b5 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -26,9 +23,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
@@ -36,12 +32,14 @@
void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here
- // Grab the hatch when the 'A' button is pressed.
- frc2::JoystickButton(&m_driverController, 1).WhenPressed(&m_grabHatch);
- // Release the hatch when the 'B' button is pressed.
- frc2::JoystickButton(&m_driverController, 2).WhenPressed(&m_releaseHatch);
- // While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
+ // Grab the hatch when the 'Circle' button is pressed.
+ frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kCircle)
+ .WhenPressed(&m_grabHatch);
+ // Release the hatch when the 'Square' button is pressed.
+ frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kSquare)
+ .WhenPressed(&m_releaseHatch);
+ // While holding R1, drive at half speed
+ frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kR1)
.WhenPressed(&m_driveHalfSpeed)
.WhenReleased(&m_driveFullSpeed);
}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp
index c5f928b..f88850e 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp
@@ -1,37 +1,50 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/ComplexAuto.h"
+#include <frc2/command/FunctionalCommand.h>
#include <frc2/command/InstantCommand.h>
#include <frc2/command/ParallelRaceGroup.h>
-#include <frc2/command/StartEndCommand.h>
using namespace AutoConstants;
ComplexAuto::ComplexAuto(DriveSubsystem* drive, HatchSubsystem* hatch) {
AddCommands(
// Drive forward the specified distance
- frc2::StartEndCommand([drive] { drive->ArcadeDrive(kAutoDriveSpeed, 0); },
- [drive] { drive->ArcadeDrive(0, 0); }, {drive})
- .BeforeStarting([drive] { drive->ResetEncoders(); })
- .WithInterrupt([drive] {
+ frc2::FunctionalCommand(
+ // Reset encoders on command start
+ [&] { drive->ResetEncoders(); },
+ // Drive forward while the command is executing
+ [&] { drive->ArcadeDrive(kAutoDriveSpeed, 0); },
+ // Stop driving at the end of the command
+ [&](bool interrupted) { drive->ArcadeDrive(0, 0); },
+ // End the command when the robot's driven distance exceeds the
+ // desired value
+ [&] {
return drive->GetAverageEncoderDistance() >=
kAutoDriveDistanceInches;
- }),
+ },
+ // Requires the drive subsystem
+ {drive}),
// Release the hatch
frc2::InstantCommand([hatch] { hatch->ReleaseHatch(); }, {hatch}),
// Drive backward the specified distance
- frc2::StartEndCommand(
- [drive] { drive->ArcadeDrive(-kAutoDriveSpeed, 0); },
- [drive] { drive->ArcadeDrive(0, 0); }, {drive})
- .BeforeStarting([drive] { drive->ResetEncoders(); })
- .WithInterrupt([drive] {
+ // Drive forward the specified distance
+ frc2::FunctionalCommand(
+ // Reset encoders on command start
+ [&] { drive->ResetEncoders(); },
+ // Drive backward while the command is executing
+ [&] { drive->ArcadeDrive(-kAutoDriveSpeed, 0); },
+ // Stop driving at the end of the command
+ [&](bool interrupted) { drive->ArcadeDrive(0, 0); },
+ // End the command when the robot's driven distance exceeds the
+ // desired value
+ [&] {
return drive->GetAverageEncoderDistance() <=
kAutoBackupDistanceInches;
- }));
+ },
+ // Requires the drive subsystem
+ {drive}));
}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp
index 47c898e..bd94b68 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -16,6 +13,11 @@
m_right2{kRightMotor2Port},
m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]},
m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotors.SetInverted(true);
+
// Set the distance per pulse for the encoders
m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
@@ -38,9 +40,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp
index ea7b796..ba1c0dd 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp
@@ -1,16 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/HatchSubsystem.h"
using namespace HatchConstants;
HatchSubsystem::HatchSubsystem()
- : m_hatchSolenoid{kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {}
+ : m_hatchSolenoid{frc::PneumaticsModuleType::CTREPCM,
+ kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {}
void HatchSubsystem::GrabHatch() {
m_hatchSolenoid.Set(frc::DoubleSolenoid::kForward);
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h
index d465f6c..e9fbfdc 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Constants.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <wpi/math>
+#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -33,7 +30,8 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterInches * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace HatchConstants {
@@ -48,5 +46,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h
index 106812b..b17c55d 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.h
@@ -1,20 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <frc/XboxController.h>
+#include <frc/PS4Controller.h>
#include <frc/smartdashboard/SendableChooser.h>
#include <frc2/command/Command.h>
+#include <frc2/command/FunctionalCommand.h>
#include <frc2/command/InstantCommand.h>
#include <frc2/command/ParallelRaceGroup.h>
#include <frc2/command/RunCommand.h>
#include <frc2/command/SequentialCommandGroup.h>
-#include <frc2/command/StartEndCommand.h>
#include "Constants.h"
#include "commands/ComplexAuto.h"
@@ -38,7 +35,7 @@
private:
// The driver's controller
- frc::XboxController m_driverController{OIConstants::kDriverControllerPort};
+ frc::PS4Controller m_driverController{OIConstants::kDriverControllerPort};
// The robot's subsystems and commands are defined here...
@@ -47,15 +44,21 @@
HatchSubsystem m_hatch;
// The autonomous routines
- frc2::ParallelRaceGroup m_simpleAuto =
- frc2::StartEndCommand(
- [this] { m_drive.ArcadeDrive(ac::kAutoDriveSpeed, 0); },
- [this] { m_drive.ArcadeDrive(0, 0); }, {&m_drive})
- .BeforeStarting([this] { m_drive.ResetEncoders(); })
- .WithInterrupt([this] {
- return m_drive.GetAverageEncoderDistance() >=
- ac::kAutoDriveDistanceInches;
- });
+ frc2::FunctionalCommand m_simpleAuto = frc2::FunctionalCommand(
+ // Reset encoders on command start
+ [this] { m_drive.ResetEncoders(); },
+ // Drive forward while the command is executing
+ [this] { m_drive.ArcadeDrive(AutoConstants::kAutoDriveSpeed, 0); },
+ // Stop driving at the end of the command
+ [this](bool interrupted) { m_drive.ArcadeDrive(0, 0); },
+ // End the command when the robot's driven distance exceeds the desired
+ // value
+ [this] {
+ return m_drive.GetAverageEncoderDistance() >=
+ AutoConstants::kAutoDriveDistanceInches;
+ },
+ // Requires the drive subsystem
+ {&m_drive});
ComplexAuto m_complexAuto{&m_drive, &m_hatch};
// Assorted commands to be bound to buttons
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/ComplexAuto.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/ComplexAuto.h
index b767f3b..e746d8a 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/ComplexAuto.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/commands/ComplexAuto.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h
index 3ed1357..47bf28e 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -73,16 +70,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1;
- frc::PWMVictorSPX m_left2;
- frc::PWMVictorSPX m_right1;
- frc::PWMVictorSPX m_right2;
+ frc::PWMSparkMax m_left1;
+ frc::PWMSparkMax m_left2;
+ frc::PWMSparkMax m_right1;
+ frc::PWMSparkMax m_right2;
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h
index 681aea8..bb06100 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.h
@@ -1,13 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/DoubleSolenoid.h>
+#include <frc/PneumaticsControlModule.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp
index d4199ef..b46efd4 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -30,9 +27,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(DefaultDrive(
- &m_drive,
- [this] { return m_driverController.GetY(frc::GenericHID::kLeftHand); },
- [this] { return m_driverController.GetX(frc::GenericHID::kRightHand); }));
+ &m_drive, [this] { return m_driverController.GetLeftY(); },
+ [this] { return m_driverController.GetRightX(); }));
}
void RobotContainer::ConfigureButtonBindings() {
@@ -44,13 +40,14 @@
// stack-allocated and declared as members of RobotContainer.
// Grab the hatch when the 'A' button is pressed.
- frc2::JoystickButton(&m_driverController, 1)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
.WhenPressed(new GrabHatch(&m_hatch));
// Release the hatch when the 'B' button is pressed.
- frc2::JoystickButton(&m_driverController, 2)
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB)
.WhenPressed(new ReleaseHatch(&m_hatch));
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
+ frc2::JoystickButton(&m_driverController,
+ frc::XboxController::Button::kRightBumper)
.WhenHeld(new HalveDriveSpeed(&m_drive));
}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ComplexAuto.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ComplexAuto.cpp
index cb41de6..cfc5153 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ComplexAuto.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ComplexAuto.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/ComplexAuto.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp
index 3bdee6e..7ef404e 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp
@@ -1,16 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/DefaultDrive.h"
+#include <utility>
+
DefaultDrive::DefaultDrive(DriveSubsystem* subsystem,
std::function<double()> forward,
std::function<double()> rotation)
- : m_drive{subsystem}, m_forward{forward}, m_rotation{rotation} {
+ : m_drive{subsystem},
+ m_forward{std::move(forward)},
+ m_rotation{std::move(rotation)} {
AddRequirements({subsystem});
}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp
index 6c7ef40..7ee1b2c 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/DriveDistance.h"
@@ -20,7 +17,13 @@
m_drive->ArcadeDrive(m_speed, 0);
}
-void DriveDistance::End(bool interrupted) { m_drive->ArcadeDrive(0, 0); }
+void DriveDistance::Execute() {
+ m_drive->ArcadeDrive(m_speed, 0);
+}
+
+void DriveDistance::End(bool interrupted) {
+ m_drive->ArcadeDrive(0, 0);
+}
bool DriveDistance::IsFinished() {
return std::abs(m_drive->GetAverageEncoderDistance()) >= m_distance;
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp
index f665761..e769cbd 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp
@@ -1,16 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/GrabHatch.h"
GrabHatch::GrabHatch(HatchSubsystem* subsystem) : m_hatch(subsystem) {
- AddRequirements({subsystem});
+ AddRequirements(subsystem);
}
-void GrabHatch::Initialize() { m_hatch->GrabHatch(); }
+void GrabHatch::Initialize() {
+ m_hatch->GrabHatch();
+}
-bool GrabHatch::IsFinished() { return true; }
+bool GrabHatch::IsFinished() {
+ return true;
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveSpeed.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveSpeed.cpp
index b35b2c6..0f561b3 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveSpeed.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveSpeed.cpp
@@ -1,15 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/HalveDriveSpeed.h"
HalveDriveSpeed::HalveDriveSpeed(DriveSubsystem* subsystem)
: m_drive(subsystem) {}
-void HalveDriveSpeed::Initialize() { m_drive->SetMaxOutput(0.5); }
+void HalveDriveSpeed::Initialize() {
+ m_drive->SetMaxOutput(0.5);
+}
-void HalveDriveSpeed::End(bool interrupted) { m_drive->SetMaxOutput(1); }
+void HalveDriveSpeed::End(bool interrupted) {
+ m_drive->SetMaxOutput(1);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp
index e8fbd61..7e6c9e8 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/ReleaseHatch.h"
@@ -11,6 +8,10 @@
AddRequirements({subsystem});
}
-void ReleaseHatch::Initialize() { m_hatch->ReleaseHatch(); }
+void ReleaseHatch::Initialize() {
+ m_hatch->ReleaseHatch();
+}
-bool ReleaseHatch::IsFinished() { return true; }
+bool ReleaseHatch::IsFinished() {
+ return true;
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp
index 47c898e..bd94b68 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -16,6 +13,11 @@
m_right2{kRightMotor2Port},
m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]},
m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotors.SetInverted(true);
+
// Set the distance per pulse for the encoders
m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
@@ -38,9 +40,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp
index ea7b796..ba1c0dd 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp
@@ -1,16 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/HatchSubsystem.h"
using namespace HatchConstants;
HatchSubsystem::HatchSubsystem()
- : m_hatchSolenoid{kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {}
+ : m_hatchSolenoid{frc::PneumaticsModuleType::CTREPCM,
+ kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {}
void HatchSubsystem::GrabHatch() {
m_hatchSolenoid.Set(frc::DoubleSolenoid::kForward);
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h
index d465f6c..e9fbfdc 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Constants.h
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <wpi/math>
+#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -33,7 +30,8 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterInches * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace HatchConstants {
@@ -48,5 +46,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.h
index 881d2f5..980e6e5 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ComplexAuto.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ComplexAuto.h
index 88a2460..d66394c 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ComplexAuto.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ComplexAuto.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.h
index d42d133..2e7cac8 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.h
index 6f350a9..34d2577 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -26,6 +23,8 @@
void Initialize() override;
+ void Execute() override;
+
void End(bool interrupted) override;
bool IsFinished() override;
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.h
index 0ab0c13..0cf5c5a 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveSpeed.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveSpeed.h
index 0b5d7c7..efc572d 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveSpeed.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveSpeed.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.h
index b98866f..e3628cf 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h
index 3ed1357..47bf28e 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -73,16 +70,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1;
- frc::PWMVictorSPX m_left2;
- frc::PWMVictorSPX m_right1;
- frc::PWMVictorSPX m_right2;
+ frc::PWMSparkMax m_left1;
+ frc::PWMSparkMax m_left2;
+ frc::PWMSparkMax m_right1;
+ frc::PWMSparkMax m_right2;
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.h
index 681aea8..bb06100 100644
--- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.h
@@ -1,13 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/DoubleSolenoid.h>
+#include <frc/PneumaticsControlModule.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/HidRumble/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/HidRumble/cpp/Robot.cpp
index 3deafa5..d0fdd6d 100644
--- a/wpilibcExamples/src/main/cpp/examples/HidRumble/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/HidRumble/cpp/Robot.cpp
@@ -1,11 +1,7 @@
-/*----------------------------------------------------------------------------*/
-/* 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. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/GenericHID.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
@@ -27,9 +23,11 @@
}
private:
- frc::XboxController m_hid{0};
+ frc::GenericHID m_hid{0};
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp
index 01a9d04..b61f86d 100644
--- a/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp
@@ -1,10 +1,8 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+#include <cstdio>
#include <thread>
#include <cameraserver/CameraServer.h>
@@ -12,7 +10,6 @@
#include <opencv2/core/core.hpp>
#include <opencv2/core/types.hpp>
#include <opencv2/imgproc/imgproc.hpp>
-#include <wpi/raw_ostream.h>
/**
* This is a demo program showing the use of OpenCV to do vision processing. The
@@ -21,21 +18,20 @@
* processing.
*/
class Robot : public frc::TimedRobot {
-#if defined(__linux__)
+#if defined(__linux__) || defined(_WIN32)
private:
static void VisionThread() {
// Get the USB camera from CameraServer
- cs::UsbCamera camera =
- frc::CameraServer::GetInstance()->StartAutomaticCapture();
+ cs::UsbCamera camera = frc::CameraServer::StartAutomaticCapture();
// Set the resolution
camera.SetResolution(640, 480);
// Get a CvSink. This will capture Mats from the Camera
- cs::CvSink cvSink = frc::CameraServer::GetInstance()->GetVideo();
+ cs::CvSink cvSink = frc::CameraServer::GetVideo();
// Setup a CvSource. This will send images back to the Dashboard
cs::CvSource outputStream =
- frc::CameraServer::GetInstance()->PutVideo("Rectangle", 640, 480);
+ frc::CameraServer::PutVideo("Rectangle", 640, 480);
// Mats are very memory expensive. Lets reuse this Mat.
cv::Mat mat;
@@ -63,16 +59,18 @@
void RobotInit() override {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
-#if defined(__linux__)
+#if defined(__linux__) || defined(_WIN32)
std::thread visionThread(VisionThread);
visionThread.detach();
#else
- wpi::errs() << "Vision only available on Linux.\n";
- wpi::errs().flush();
+ std::fputs("Vision only available on Linux or Windows.\n", stderr);
+ std::fflush(stderr);
#endif
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp
index b65b1d7..c33450d 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Drivetrain.h"
@@ -25,13 +22,13 @@
m_feedforward.Calculate(wheelSpeeds.rearRight);
const double frontLeftOutput = m_frontLeftPIDController.Calculate(
- m_frontLeftEncoder.GetRate(), wheelSpeeds.frontLeft.to<double>());
+ m_frontLeftEncoder.GetRate(), wheelSpeeds.frontLeft.value());
const double frontRightOutput = m_frontRightPIDController.Calculate(
- m_frontRightEncoder.GetRate(), wheelSpeeds.frontRight.to<double>());
+ m_frontRightEncoder.GetRate(), wheelSpeeds.frontRight.value());
const double backLeftOutput = m_backLeftPIDController.Calculate(
- m_backLeftEncoder.GetRate(), wheelSpeeds.rearLeft.to<double>());
+ m_backLeftEncoder.GetRate(), wheelSpeeds.rearLeft.value());
const double backRightOutput = m_backRightPIDController.Calculate(
- m_backRightEncoder.GetRate(), wheelSpeeds.rearRight.to<double>());
+ m_backRightEncoder.GetRate(), wheelSpeeds.rearRight.value());
m_frontLeftMotor.SetVoltage(units::volt_t{frontLeftOutput} +
frontLeftFeedforward);
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp
index a9695c4..4943184 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc/SlewRateLimiter.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
+#include <frc/filter/SlewRateLimiter.h>
#include "Drivetrain.h"
@@ -33,23 +30,20 @@
void DriveWithJoystick(bool fieldRelative) {
// Get the x speed. We are inverting this because Xbox controllers return
// negative values when we push forward.
- const auto xSpeed = -m_xspeedLimiter.Calculate(
- m_controller.GetY(frc::GenericHID::kLeftHand)) *
+ const auto xSpeed = -m_xspeedLimiter.Calculate(m_controller.GetLeftY()) *
Drivetrain::kMaxSpeed;
// Get the y speed or sideways/strafe speed. We are inverting this because
// we want a positive value when we pull to the left. Xbox controllers
// return positive values when you pull to the right by default.
- const auto ySpeed = -m_yspeedLimiter.Calculate(
- m_controller.GetX(frc::GenericHID::kLeftHand)) *
+ const auto ySpeed = -m_yspeedLimiter.Calculate(m_controller.GetLeftX()) *
Drivetrain::kMaxSpeed;
// Get the rate of angular rotation. We are inverting this because we want a
// positive value when we pull to the left (remember, CCW is positive in
// mathematics). Xbox controllers return positive values when you pull to
// the right by default.
- const auto rot = -m_rotLimiter.Calculate(
- m_controller.GetX(frc::GenericHID::kRightHand)) *
+ const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
Drivetrain::kMaxAngularSpeed;
m_mecanum.Drive(xSpeed, ySpeed, rot, fieldRelative);
@@ -57,5 +51,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h
index 9c5d9e4..0aa3086 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h
@@ -1,22 +1,19 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/SimpleMotorFeedforward.h>
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/MecanumDriveKinematics.h>
#include <frc/kinematics/MecanumDriveOdometry.h>
#include <frc/kinematics/MecanumDriveWheelSpeeds.h>
-#include <wpi/math>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <wpi/numbers>
/**
* Represents a mecanum drive style drivetrain.
@@ -35,13 +32,13 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::math::pi}; // 1/2 rotation per second
+ wpi::numbers::pi}; // 1/2 rotation per second
private:
- frc::PWMVictorSPX m_frontLeftMotor{1};
- frc::PWMVictorSPX m_frontRightMotor{2};
- frc::PWMVictorSPX m_backLeftMotor{3};
- frc::PWMVictorSPX m_backRightMotor{4};
+ frc::PWMSparkMax m_frontLeftMotor{1};
+ frc::PWMSparkMax m_frontRightMotor{2};
+ frc::PWMSparkMax m_backLeftMotor{3};
+ frc::PWMSparkMax m_backRightMotor{4};
frc::Encoder m_frontLeftEncoder{0, 1};
frc::Encoder m_frontRightEncoder{2, 3};
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
index 0cf9b96..36912b5 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Constants.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
index 7746099..3e2c6bf 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
+#include <utility>
+
#include <frc/controller/PIDController.h>
#include <frc/geometry/Translation2d.h>
#include <frc/shuffleboard/Shuffleboard.h>
@@ -31,10 +30,9 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.Drive(m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand),
- m_driverController.GetX(frc::GenericHID::kLeftHand),
- false);
+ m_drive.Drive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX(),
+ m_driverController.GetLeftX(), false);
},
{&m_drive}));
}
@@ -43,7 +41,8 @@
// Configure your button bindings here
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
+ frc2::JoystickButton(&m_driverController,
+ frc::XboxController::Button::kRightBumper)
.WhenPressed(&m_driveHalfSpeed)
.WhenReleased(&m_driveFullSpeed);
}
@@ -97,7 +96,7 @@
[this](units::volt_t frontLeft, units::volt_t rearLeft,
units::volt_t frontRight, units::volt_t rearRight) {
- m_drive.SetSpeedControllersVolts(frontLeft, rearLeft, frontRight,
+ m_drive.SetMotorControllersVolts(frontLeft, rearLeft, frontRight,
rearRight);
},
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
index ef6564f..4cc4e47 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -51,15 +48,15 @@
}
void DriveSubsystem::Drive(double xSpeed, double ySpeed, double rot,
- bool feildRelative) {
- if (feildRelative) {
+ bool fieldRelative) {
+ if (fieldRelative) {
m_drive.DriveCartesian(ySpeed, xSpeed, rot, -m_gyro.GetAngle());
} else {
m_drive.DriveCartesian(ySpeed, xSpeed, rot);
}
}
-void DriveSubsystem::SetSpeedControllersVolts(units::volt_t frontLeftPower,
+void DriveSubsystem::SetMotorControllersVolts(units::volt_t frontLeftPower,
units::volt_t rearLeftPower,
units::volt_t frontRightPower,
units::volt_t rearRightPower) {
@@ -80,7 +77,9 @@
return m_frontLeftEncoder;
}
-frc::Encoder& DriveSubsystem::GetRearLeftEncoder() { return m_rearLeftEncoder; }
+frc::Encoder& DriveSubsystem::GetRearLeftEncoder() {
+ return m_rearLeftEncoder;
+}
frc::Encoder& DriveSubsystem::GetFrontRightEncoder() {
return m_frontRightEncoder;
@@ -106,11 +105,17 @@
return m_gyro.GetRotation2d().Degrees();
}
-void DriveSubsystem::ZeroHeading() { m_gyro.Reset(); }
+void DriveSubsystem::ZeroHeading() {
+ m_gyro.Reset();
+}
-double DriveSubsystem::GetTurnRate() { return -m_gyro.GetRate(); }
+double DriveSubsystem::GetTurnRate() {
+ return -m_gyro.GetRate();
+}
-frc::Pose2d DriveSubsystem::GetPose() { return m_odometry.GetPose(); }
+frc::Pose2d DriveSubsystem::GetPose() {
+ return m_odometry.GetPose();
+}
void DriveSubsystem::ResetOdometry(frc::Pose2d pose) {
m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
index c37cb8a..592e948 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/MecanumDriveKinematics.h>
@@ -15,7 +12,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
#pragma once
@@ -37,7 +34,7 @@
constexpr int kFrontLeftEncoderPorts[]{0, 1};
constexpr int kRearLeftEncoderPorts[]{2, 3};
constexpr int kFrontRightEncoderPorts[]{4, 5};
-constexpr int kRearRightEncoderPorts[]{5, 6};
+constexpr int kRearRightEncoderPorts[]{6, 7};
constexpr bool kFrontLeftEncoderReversed = false;
constexpr bool kRearLeftEncoderReversed = true;
@@ -51,10 +48,11 @@
extern const frc::MecanumDriveKinematics kDriveKinematics;
constexpr int kEncoderCPR = 1024;
-constexpr double kWheelDiameterMeters = .15;
+constexpr double kWheelDiameterMeters = 0.15;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterMeters * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterMeters * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
// These characterization values MUST be determined either experimentally or
@@ -93,5 +91,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h
index 3b4f6cc..93485e3 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -42,7 +39,7 @@
// The robot's subsystems
DriveSubsystem m_drive;
- frc2::InstantCommand m_driveHalfSpeed{[this] { m_drive.SetMaxOutput(.5); },
+ frc2::InstantCommand m_driveHalfSpeed{[this] { m_drive.SetMaxOutput(0.5); },
{}};
frc2::InstantCommand m_driveFullSpeed{[this] { m_drive.SetMaxOutput(1); },
{}};
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h
index 1cd72d2..95b08b6 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h
@@ -1,21 +1,18 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/ADXRS450_Gyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/drive/MecanumDrive.h>
#include <frc/geometry/Pose2d.h>
#include <frc/geometry/Rotation2d.h>
#include <frc/interfaces/Gyro.h>
#include <frc/kinematics/MecanumDriveOdometry.h>
#include <frc/kinematics/MecanumDriveWheelSpeeds.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -42,7 +39,7 @@
* @param fieldRelative Whether the provided x and y speeds are relative to
* the field.
*/
- void Drive(double xSpeed, double ySpeed, double rot, bool feildRelative);
+ void Drive(double xSpeed, double ySpeed, double rot, bool fieldRelative);
/**
* Resets the drive encoders to currently read a position of 0.
@@ -85,9 +82,9 @@
frc::MecanumDriveWheelSpeeds getCurrentWheelSpeeds();
/**
- * Sets the drive SpeedControllers to a desired voltage.
+ * Sets the drive MotorControllers to a desired voltage.
*/
- void SetSpeedControllersVolts(units::volt_t frontLeftPower,
+ void SetMotorControllersVolts(units::volt_t frontLeftPower,
units::volt_t rearLeftPower,
units::volt_t frontRightPower,
units::volt_t rearRightPower);
@@ -138,10 +135,10 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_frontLeft;
- frc::PWMVictorSPX m_rearLeft;
- frc::PWMVictorSPX m_frontRight;
- frc::PWMVictorSPX m_rearRight;
+ frc::PWMSparkMax m_frontLeft;
+ frc::PWMSparkMax m_rearLeft;
+ frc::PWMSparkMax m_frontRight;
+ frc::PWMSparkMax m_rearRight;
// The robot's drive
frc::MecanumDrive m_drive{m_frontLeft, m_rearLeft, m_frontRight, m_rearRight};
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp
index 8b4c98c..822e9ee 100644
--- a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/drive/MecanumDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a demo program showing how to use Mecanum control with the
@@ -38,10 +35,10 @@
static constexpr int kJoystickChannel = 0;
- frc::PWMVictorSPX m_frontLeft{kFrontLeftChannel};
- frc::PWMVictorSPX m_rearLeft{kRearLeftChannel};
- frc::PWMVictorSPX m_frontRight{kFrontRightChannel};
- frc::PWMVictorSPX m_rearRight{kRearRightChannel};
+ frc::PWMSparkMax m_frontLeft{kFrontLeftChannel};
+ frc::PWMSparkMax m_rearLeft{kRearLeftChannel};
+ frc::PWMSparkMax m_frontRight{kFrontRightChannel};
+ frc::PWMSparkMax m_rearRight{kRearRightChannel};
frc::MecanumDrive m_robotDrive{m_frontLeft, m_rearLeft, m_frontRight,
m_rearRight};
@@ -49,5 +46,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp
new file mode 100644
index 0000000..149f12e
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp
@@ -0,0 +1,61 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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 "Drivetrain.h"
+
+#include <frc/Timer.h>
+
+#include "ExampleGlobalMeasurementSensor.h"
+
+frc::MecanumDriveWheelSpeeds Drivetrain::GetCurrentState() const {
+ return {units::meters_per_second_t(m_frontLeftEncoder.GetRate()),
+ units::meters_per_second_t(m_frontRightEncoder.GetRate()),
+ units::meters_per_second_t(m_backLeftEncoder.GetRate()),
+ units::meters_per_second_t(m_backRightEncoder.GetRate())};
+}
+
+void Drivetrain::SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds) {
+ std::function<void(units::meters_per_second_t, const frc::Encoder&,
+ frc2::PIDController&, frc::PWMSparkMax&)>
+ calcAndSetSpeeds = [&m_feedforward = m_feedforward](
+ units::meters_per_second_t speed,
+ const auto& encoder, auto& controller,
+ auto& motor) {
+ auto feedforward = m_feedforward.Calculate(speed);
+ double output = controller.Calculate(encoder.GetRate(), speed.value());
+ motor.SetVoltage(units::volt_t{output} + feedforward);
+ };
+
+ calcAndSetSpeeds(wheelSpeeds.frontLeft, m_frontLeftEncoder,
+ m_frontLeftPIDController, m_frontLeftMotor);
+ calcAndSetSpeeds(wheelSpeeds.frontRight, m_frontRightEncoder,
+ m_frontRightPIDController, m_frontRightMotor);
+ calcAndSetSpeeds(wheelSpeeds.rearLeft, m_backLeftEncoder,
+ m_backLeftPIDController, m_backLeftMotor);
+ calcAndSetSpeeds(wheelSpeeds.rearRight, m_backRightEncoder,
+ m_backRightPIDController, m_backRightMotor);
+}
+
+void Drivetrain::Drive(units::meters_per_second_t xSpeed,
+ units::meters_per_second_t ySpeed,
+ units::radians_per_second_t rot, bool fieldRelative) {
+ auto wheelSpeeds = m_kinematics.ToWheelSpeeds(
+ fieldRelative ? frc::ChassisSpeeds::FromFieldRelativeSpeeds(
+ xSpeed, ySpeed, rot, m_gyro.GetRotation2d())
+ : frc::ChassisSpeeds{xSpeed, ySpeed, rot});
+ wheelSpeeds.Normalize(kMaxSpeed);
+ SetSpeeds(wheelSpeeds);
+}
+
+void Drivetrain::UpdateOdometry() {
+ m_poseEstimator.Update(m_gyro.GetRotation2d(), GetCurrentState());
+
+ // Also apply vision measurements. We use 0.3 seconds in the past as an
+ // example -- on a real robot, this must be calculated based either on latency
+ // or timestamps.
+ m_poseEstimator.AddVisionMeasurement(
+ ExampleGlobalMeasurementSensor::GetEstimatedGlobalPose(
+ m_poseEstimator.GetEstimatedPosition()),
+ frc::Timer::GetFPGATimestamp() - 0.3_s);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp
new file mode 100644
index 0000000..4943184
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp
@@ -0,0 +1,57 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/TimedRobot.h>
+#include <frc/XboxController.h>
+#include <frc/filter/SlewRateLimiter.h>
+
+#include "Drivetrain.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void AutonomousPeriodic() override {
+ DriveWithJoystick(false);
+ m_mecanum.UpdateOdometry();
+ }
+
+ void TeleopPeriodic() override { DriveWithJoystick(true); }
+
+ private:
+ frc::XboxController m_controller{0};
+ Drivetrain m_mecanum;
+
+ // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0
+ // to 1.
+ frc::SlewRateLimiter<units::scalar> m_xspeedLimiter{3 / 1_s};
+ frc::SlewRateLimiter<units::scalar> m_yspeedLimiter{3 / 1_s};
+ frc::SlewRateLimiter<units::scalar> m_rotLimiter{3 / 1_s};
+
+ void DriveWithJoystick(bool fieldRelative) {
+ // Get the x speed. We are inverting this because Xbox controllers return
+ // negative values when we push forward.
+ const auto xSpeed = -m_xspeedLimiter.Calculate(m_controller.GetLeftY()) *
+ Drivetrain::kMaxSpeed;
+
+ // Get the y speed or sideways/strafe speed. We are inverting this because
+ // we want a positive value when we pull to the left. Xbox controllers
+ // return positive values when you pull to the right by default.
+ const auto ySpeed = -m_yspeedLimiter.Calculate(m_controller.GetLeftX()) *
+ Drivetrain::kMaxSpeed;
+
+ // Get the rate of angular rotation. We are inverting this because we want a
+ // positive value when we pull to the left (remember, CCW is positive in
+ // mathematics). Xbox controllers return positive values when you pull to
+ // the right by default.
+ const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
+ Drivetrain::kMaxAngularSpeed;
+
+ m_mecanum.Drive(xSpeed, ySpeed, rot, fieldRelative);
+ }
+};
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h
new file mode 100644
index 0000000..d084fa5
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h
@@ -0,0 +1,73 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/AnalogGyro.h>
+#include <frc/Encoder.h>
+#include <frc/controller/PIDController.h>
+#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/estimator/MecanumDrivePoseEstimator.h>
+#include <frc/geometry/Translation2d.h>
+#include <frc/kinematics/MecanumDriveKinematics.h>
+#include <frc/kinematics/MecanumDriveOdometry.h>
+#include <frc/kinematics/MecanumDriveWheelSpeeds.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <wpi/numbers>
+
+/**
+ * Represents a mecanum drive style drivetrain.
+ */
+class Drivetrain {
+ public:
+ Drivetrain() { m_gyro.Reset(); }
+
+ frc::MecanumDriveWheelSpeeds GetCurrentState() const;
+ void SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds);
+ void Drive(units::meters_per_second_t xSpeed,
+ units::meters_per_second_t ySpeed, units::radians_per_second_t rot,
+ bool fieldRelative);
+ void UpdateOdometry();
+
+ static constexpr auto kMaxSpeed = 3.0_mps; // 3 meters per second
+ static constexpr units::radians_per_second_t kMaxAngularSpeed{
+ wpi::numbers::pi}; // 1/2 rotation per second
+
+ private:
+ frc::PWMSparkMax m_frontLeftMotor{1};
+ frc::PWMSparkMax m_frontRightMotor{2};
+ frc::PWMSparkMax m_backLeftMotor{3};
+ frc::PWMSparkMax m_backRightMotor{4};
+
+ frc::Encoder m_frontLeftEncoder{0, 1};
+ frc::Encoder m_frontRightEncoder{2, 3};
+ frc::Encoder m_backLeftEncoder{4, 5};
+ frc::Encoder m_backRightEncoder{6, 7};
+
+ frc::Translation2d m_frontLeftLocation{0.381_m, 0.381_m};
+ frc::Translation2d m_frontRightLocation{0.381_m, -0.381_m};
+ frc::Translation2d m_backLeftLocation{-0.381_m, 0.381_m};
+ frc::Translation2d m_backRightLocation{-0.381_m, -0.381_m};
+
+ frc2::PIDController m_frontLeftPIDController{1.0, 0.0, 0.0};
+ frc2::PIDController m_frontRightPIDController{1.0, 0.0, 0.0};
+ frc2::PIDController m_backLeftPIDController{1.0, 0.0, 0.0};
+ frc2::PIDController m_backRightPIDController{1.0, 0.0, 0.0};
+
+ frc::AnalogGyro m_gyro{0};
+
+ frc::MecanumDriveKinematics m_kinematics{
+ m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation,
+ m_backRightLocation};
+
+ // Gains are for example purposes only - must be determined for your own
+ // robot!
+ frc::SimpleMotorFeedforward<units::meters> m_feedforward{1_V, 3_V / 1_mps};
+
+ // Gains are for example purposes only - must be determined for your own
+ // robot!
+ frc::MecanumDrivePoseEstimator m_poseEstimator{
+ frc::Rotation2d(), frc::Pose2d(), m_kinematics,
+ {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
new file mode 100644
index 0000000..a4caff4
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/StateSpaceUtil.h>
+#include <frc/geometry/Pose2d.h>
+
+/**
+ * This dummy class represents a global measurement sensor, such as a computer
+ * vision solution.
+ */
+class ExampleGlobalMeasurementSensor {
+ public:
+ static frc::Pose2d GetEstimatedGlobalPose(
+ const frc::Pose2d& estimatedRobotPose) {
+ auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1);
+ return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)),
+ estimatedRobotPose.Y() + units::meter_t(randVec(1)),
+ estimatedRobotPose.Rotation() +
+ frc::Rotation2d(units::radian_t(randVec(3))));
+ }
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp
new file mode 100644
index 0000000..551dc78
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp
@@ -0,0 +1,76 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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>
+#include <frc/Encoder.h>
+#include <frc/Joystick.h>
+#include <frc/TimedRobot.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc/simulation/SimHooks.h>
+#include <frc/smartdashboard/Mechanism2d.h>
+#include <frc/smartdashboard/MechanismLigament2d.h>
+#include <frc/smartdashboard/SmartDashboard.h>
+#include <frc/util/Color.h>
+#include <frc/util/Color8Bit.h>
+#include <units/angle.h>
+
+/**
+ * This sample program shows how to use Mechanism2d - a visual representation of
+ * arms, elevators, and other mechanisms on dashboards; driven by a node-based
+ * API.
+ *
+ * <p>Ligaments are based on other ligaments or roots, and roots are contained
+ * in the base Mechanism2d object. Use pointers for nodes, and beware not to let
+ * the container out of scope - the appended nodes will be recursively
+ * destructed!
+ */
+class Robot : public frc::TimedRobot {
+ static constexpr double kMetersPerPulse = 0.01;
+ static constexpr double kElevatorMinimumLength = 0.5;
+
+ public:
+ void RobotInit() override {
+ m_elevatorEncoder.SetDistancePerPulse(kMetersPerPulse);
+
+ // publish to dashboard
+ frc::SmartDashboard::PutData("Mech2d", &m_mech);
+ }
+
+ void RobotPeriodic() override {
+ // update the dashboard mechanism's state
+ m_elevator->SetLength(kElevatorMinimumLength +
+ m_elevatorEncoder.GetDistance());
+ m_wrist->SetAngle(units::degree_t(m_wristPotentiometer.Get()));
+ }
+
+ void TeleopPeriodic() override {
+ m_elevatorMotor.Set(m_joystick.GetRawAxis(0));
+ m_wristMotor.Set(m_joystick.GetRawAxis(1));
+ }
+
+ private:
+ frc::PWMSparkMax m_elevatorMotor{0};
+ frc::PWMSparkMax m_wristMotor{1};
+ frc::Encoder m_elevatorEncoder{0, 1};
+ frc::AnalogPotentiometer m_wristPotentiometer{1, 90};
+ frc::Joystick m_joystick{0};
+
+ // the main mechanism object
+ frc::Mechanism2d m_mech{3, 3};
+ // the mechanism root node
+ frc::MechanismRoot2d* m_root = m_mech.GetRoot("climber", 2, 0);
+ // MechanismLigament2d objects represent each "section"/"stage" of the
+ // mechanism, and are based off the root node or another ligament object
+ frc::MechanismLigament2d* m_elevator =
+ m_root->Append<frc::MechanismLigament2d>("elevator", 1, 90_deg);
+ frc::MechanismLigament2d* m_wrist =
+ m_elevator->Append<frc::MechanismLigament2d>(
+ "wrist", 0.5, 90_deg, 6, frc::Color8Bit{frc::Color::kPurple});
+};
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp
index 2217ec1..0092ec3 100644
--- a/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This sample program shows how to control a motor using a joystick. In the
@@ -23,9 +20,11 @@
private:
frc::Joystick m_stick{0};
- frc::PWMVictorSPX m_motor{0};
+ frc::PWMSparkMax m_motor{0};
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp
index 8e0a14a..7d0e9ba 100644
--- a/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/smartdashboard/SmartDashboard.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* This sample program shows how to control a motor using a joystick. In the
@@ -38,15 +35,17 @@
void RobotInit() override {
// Use SetDistancePerPulse to set the multiplier for GetDistance
// This is set up assuming a 6 inch wheel with a 360 CPR encoder.
- m_encoder.SetDistancePerPulse((wpi::math::pi * 6) / 360.0);
+ m_encoder.SetDistancePerPulse((wpi::numbers::pi * 6) / 360.0);
}
private:
frc::Joystick m_stick{0};
- frc::PWMVictorSPX m_motor{0};
+ frc::PWMSparkMax m_motor{0};
frc::Encoder m_encoder{0, 1};
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/OI.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/OI.cpp
deleted file mode 100644
index c5fcb15..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/OI.cpp
+++ /dev/null
@@ -1,41 +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 "OI.h"
-
-#include <frc/smartdashboard/SmartDashboard.h>
-
-#include "commands/Collect.h"
-#include "commands/DriveForward.h"
-#include "commands/LowGoal.h"
-#include "commands/SetCollectionSpeed.h"
-#include "commands/SetPivotSetpoint.h"
-#include "commands/Shoot.h"
-#include "subsystems/Collector.h"
-#include "subsystems/Pivot.h"
-
-OI::OI() {
- m_r1.WhenPressed(new LowGoal());
- m_r2.WhenPressed(new Collect());
-
- m_l1.WhenPressed(new SetPivotSetpoint(Pivot::kShoot));
- m_l2.WhenPressed(new SetPivotSetpoint(Pivot::kShootNear));
-
- m_sticks.WhenActive(new Shoot());
-
- // SmartDashboard Buttons
- frc::SmartDashboard::PutData("Drive Forward", new DriveForward(2.25));
- frc::SmartDashboard::PutData("Drive Backward", new DriveForward(-2.25));
- frc::SmartDashboard::PutData("Start Rollers",
- new SetCollectionSpeed(Collector::kForward));
- frc::SmartDashboard::PutData("Stop Rollers",
- new SetCollectionSpeed(Collector::kStop));
- frc::SmartDashboard::PutData("Reverse Rollers",
- new SetCollectionSpeed(Collector::kReverse));
-}
-
-frc::Joystick& OI::GetJoystick() { return m_joystick; }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/Robot.cpp
deleted file mode 100644
index 9da27f3..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/Robot.cpp
+++ /dev/null
@@ -1,85 +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 "Robot.h"
-
-#include <iostream>
-
-#include <frc/commands/Scheduler.h>
-#include <frc/livewindow/LiveWindow.h>
-#include <frc/smartdashboard/SmartDashboard.h>
-
-DriveTrain Robot::drivetrain;
-Pivot Robot::pivot;
-Collector Robot::collector;
-Shooter Robot::shooter;
-Pneumatics Robot::pneumatics;
-OI Robot::oi;
-
-void Robot::RobotInit() {
- // Show what command your subsystem is running on the SmartDashboard
- frc::SmartDashboard::PutData(&drivetrain);
- frc::SmartDashboard::PutData(&pivot);
- frc::SmartDashboard::PutData(&collector);
- frc::SmartDashboard::PutData(&shooter);
- frc::SmartDashboard::PutData(&pneumatics);
-
- // instantiate the command used for the autonomous period
- m_autoChooser.SetDefaultOption("Drive and Shoot", &m_driveAndShootAuto);
- m_autoChooser.AddOption("Drive Forward", &m_driveForwardAuto);
- frc::SmartDashboard::PutData("Auto Mode", &m_autoChooser);
-
- pneumatics.Start(); // Pressurize the pneumatics.
-}
-
-void Robot::AutonomousInit() {
- m_autonomousCommand = m_autoChooser.GetSelected();
- m_autonomousCommand->Start();
-}
-
-void Robot::AutonomousPeriodic() {
- frc::Scheduler::GetInstance()->Run();
- Log();
-}
-
-void Robot::TeleopInit() {
- // This makes sure that the autonomous stops running when
- // teleop starts running. If you want the autonomous to
- // continue until interrupted by another command, remove
- // this line or comment it out.
- if (m_autonomousCommand != nullptr) {
- m_autonomousCommand->Cancel();
- }
- std::cout << "Starting Teleop" << std::endl;
-}
-
-void Robot::TeleopPeriodic() {
- frc::Scheduler::GetInstance()->Run();
- Log();
-}
-
-void Robot::TestPeriodic() {}
-
-void Robot::DisabledInit() { shooter.Unlatch(); }
-
-void Robot::DisabledPeriodic() { Log(); }
-
-/**
- * Log interesting values to the SmartDashboard.
- */
-void Robot::Log() {
- Robot::pneumatics.WritePressure();
- frc::SmartDashboard::PutNumber("Pivot Pot Value", pivot.GetAngle());
- frc::SmartDashboard::PutNumber("Left Distance",
- drivetrain.GetLeftEncoder().GetDistance());
- frc::SmartDashboard::PutNumber("Right Distance",
- drivetrain.GetRightEncoder().GetDistance());
-}
-
-#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
-#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/CheckForHotGoal.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/CheckForHotGoal.cpp
deleted file mode 100644
index c5d80c0..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/CheckForHotGoal.cpp
+++ /dev/null
@@ -1,17 +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 "commands/CheckForHotGoal.h"
-
-#include "Robot.h"
-
-CheckForHotGoal::CheckForHotGoal(double time) { SetTimeout(time); }
-
-// Make this return true when this Command no longer needs to run execute()
-bool CheckForHotGoal::IsFinished() {
- return IsTimedOut() || Robot::shooter.GoalIsHot();
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/CloseClaw.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/CloseClaw.cpp
deleted file mode 100644
index 8db41f3..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/CloseClaw.cpp
+++ /dev/null
@@ -1,15 +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 "commands/CloseClaw.h"
-
-#include "Robot.h"
-
-CloseClaw::CloseClaw() { Requires(&Robot::collector); }
-
-// Called just before this Command runs the first time
-void CloseClaw::Initialize() { Robot::collector.Close(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/Collect.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/Collect.cpp
deleted file mode 100644
index b51c2df..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/Collect.cpp
+++ /dev/null
@@ -1,21 +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 "commands/Collect.h"
-
-#include "Robot.h"
-#include "commands/CloseClaw.h"
-#include "commands/SetCollectionSpeed.h"
-#include "commands/SetPivotSetpoint.h"
-#include "commands/WaitForBall.h"
-
-Collect::Collect() {
- AddSequential(new SetCollectionSpeed(Collector::kForward));
- AddParallel(new CloseClaw());
- AddSequential(new SetPivotSetpoint(Pivot::kCollect));
- AddSequential(new WaitForBall());
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveAndShootAutonomous.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveAndShootAutonomous.cpp
deleted file mode 100644
index 3486292..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveAndShootAutonomous.cpp
+++ /dev/null
@@ -1,28 +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 "commands/DriveAndShootAutonomous.h"
-
-#include "Robot.h"
-#include "commands/CheckForHotGoal.h"
-#include "commands/CloseClaw.h"
-#include "commands/DriveForward.h"
-#include "commands/SetPivotSetpoint.h"
-#include "commands/Shoot.h"
-#include "commands/WaitForPressure.h"
-
-DriveAndShootAutonomous::DriveAndShootAutonomous() {
- AddSequential(new CloseClaw());
- AddSequential(new WaitForPressure(), 2);
-#ifndef SIMULATION
- // NOTE: Simulation doesn't currently have the concept of hot.
- AddSequential(new CheckForHotGoal(2));
-#endif
- AddSequential(new SetPivotSetpoint(45));
- AddSequential(new DriveForward(8, 0.3));
- AddSequential(new Shoot());
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveForward.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveForward.cpp
deleted file mode 100644
index 1de5846..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveForward.cpp
+++ /dev/null
@@ -1,51 +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 "commands/DriveForward.h"
-
-#include <cmath>
-
-#include "Robot.h"
-
-void DriveForward::init(double dist, double maxSpeed) {
- Requires(&Robot::drivetrain);
- m_distance = dist;
- m_driveForwardSpeed = maxSpeed;
-}
-
-DriveForward::DriveForward() { init(10, 0.5); }
-
-DriveForward::DriveForward(double dist) { init(dist, 0.5); }
-
-DriveForward::DriveForward(double dist, double maxSpeed) {
- init(dist, maxSpeed);
-}
-
-// Called just before this Command runs the first time
-void DriveForward::Initialize() {
- Robot::drivetrain.GetRightEncoder().Reset();
- SetTimeout(2);
-}
-
-// Called repeatedly when this Command is scheduled to run
-void DriveForward::Execute() {
- m_error = (m_distance - Robot::drivetrain.GetRightEncoder().GetDistance());
- if (m_driveForwardSpeed * kP * m_error >= m_driveForwardSpeed) {
- Robot::drivetrain.TankDrive(m_driveForwardSpeed, m_driveForwardSpeed);
- } else {
- Robot::drivetrain.TankDrive(m_driveForwardSpeed * kP * m_error,
- m_driveForwardSpeed * kP * m_error);
- }
-}
-
-// Make this return true when this Command no longer needs to run execute()
-bool DriveForward::IsFinished() {
- return (std::fabs(m_error) <= kTolerance) || IsTimedOut();
-}
-
-// Called once after isFinished returns true
-void DriveForward::End() { Robot::drivetrain.Stop(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveWithJoystick.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveWithJoystick.cpp
deleted file mode 100644
index 7704d70..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/DriveWithJoystick.cpp
+++ /dev/null
@@ -1,24 +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 "commands/DriveWithJoystick.h"
-
-#include "Robot.h"
-
-DriveWithJoystick::DriveWithJoystick() { Requires(&Robot::drivetrain); }
-
-// Called repeatedly when this Command is scheduled to run
-void DriveWithJoystick::Execute() {
- auto& joystick = Robot::oi.GetJoystick();
- Robot::drivetrain.TankDrive(joystick.GetY(), joystick.GetRawAxis(4));
-}
-
-// Make this return true when this Command no longer needs to run execute()
-bool DriveWithJoystick::IsFinished() { return false; }
-
-// Called once after isFinished returns true
-void DriveWithJoystick::End() { Robot::drivetrain.Stop(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/ExtendShooter.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/ExtendShooter.cpp
deleted file mode 100644
index 53494c9..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/ExtendShooter.cpp
+++ /dev/null
@@ -1,20 +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 "commands/ExtendShooter.h"
-
-#include "Robot.h"
-
-ExtendShooter::ExtendShooter() : frc::TimedCommand(1.0) {
- Requires(&Robot::shooter);
-}
-
-// Called just before this Command runs the first time
-void ExtendShooter::Initialize() { Robot::shooter.ExtendBoth(); }
-
-// Called once after isFinished returns true
-void ExtendShooter::End() { Robot::shooter.RetractBoth(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/LowGoal.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/LowGoal.cpp
deleted file mode 100644
index f4ed788..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/LowGoal.cpp
+++ /dev/null
@@ -1,19 +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 "commands/LowGoal.h"
-
-#include "Robot.h"
-#include "commands/ExtendShooter.h"
-#include "commands/SetCollectionSpeed.h"
-#include "commands/SetPivotSetpoint.h"
-
-LowGoal::LowGoal() {
- AddSequential(new SetPivotSetpoint(Pivot::kLowGoal));
- AddSequential(new SetCollectionSpeed(Collector::kReverse));
- AddSequential(new ExtendShooter());
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/OpenClaw.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/OpenClaw.cpp
deleted file mode 100644
index 4e4a9c8..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/OpenClaw.cpp
+++ /dev/null
@@ -1,18 +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 "commands/OpenClaw.h"
-
-#include "Robot.h"
-
-OpenClaw::OpenClaw() { Requires(&Robot::collector); }
-
-// Called just before this Command runs the first time
-void OpenClaw::Initialize() { Robot::collector.Open(); }
-
-// Make this return true when this Command no longer needs to run execute()
-bool OpenClaw::IsFinished() { return Robot::collector.IsOpen(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/SetCollectionSpeed.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/SetCollectionSpeed.cpp
deleted file mode 100644
index 2011a02..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/SetCollectionSpeed.cpp
+++ /dev/null
@@ -1,18 +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 "commands/SetCollectionSpeed.h"
-
-#include "Robot.h"
-
-SetCollectionSpeed::SetCollectionSpeed(double speed) {
- Requires(&Robot::collector);
- m_speed = speed;
-}
-
-// Called just before this Command runs the first time
-void SetCollectionSpeed::Initialize() { Robot::collector.SetSpeed(m_speed); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/SetPivotSetpoint.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/SetPivotSetpoint.cpp
deleted file mode 100644
index f9929de..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/SetPivotSetpoint.cpp
+++ /dev/null
@@ -1,24 +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 "commands/SetPivotSetpoint.h"
-
-#include "Robot.h"
-
-SetPivotSetpoint::SetPivotSetpoint(double setpoint) {
- m_setpoint = setpoint;
- Requires(&Robot::pivot);
-}
-
-// Called just before this Command runs the first time
-void SetPivotSetpoint::Initialize() {
- Robot::pivot.Enable();
- Robot::pivot.SetSetpoint(m_setpoint);
-}
-
-// Make this return true when this Command no longer needs to run execute()
-bool SetPivotSetpoint::IsFinished() { return Robot::pivot.OnTarget(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/Shoot.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/Shoot.cpp
deleted file mode 100644
index 836ccd2..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/Shoot.cpp
+++ /dev/null
@@ -1,21 +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 "commands/Shoot.h"
-
-#include "Robot.h"
-#include "commands/ExtendShooter.h"
-#include "commands/OpenClaw.h"
-#include "commands/SetCollectionSpeed.h"
-#include "commands/WaitForPressure.h"
-
-Shoot::Shoot() {
- AddSequential(new WaitForPressure());
- AddSequential(new SetCollectionSpeed(Collector::kStop));
- AddSequential(new OpenClaw());
- AddSequential(new ExtendShooter());
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/WaitForBall.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/WaitForBall.cpp
deleted file mode 100644
index daf9665..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/WaitForBall.cpp
+++ /dev/null
@@ -1,15 +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 "commands/WaitForBall.h"
-
-#include "Robot.h"
-
-WaitForBall::WaitForBall() { Requires(&Robot::collector); }
-
-// Make this return true when this Command no longer needs to run execute()
-bool WaitForBall::IsFinished() { return Robot::collector.HasBall(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/WaitForPressure.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/WaitForPressure.cpp
deleted file mode 100644
index 00cc454..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/commands/WaitForPressure.cpp
+++ /dev/null
@@ -1,15 +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 "commands/WaitForPressure.h"
-
-#include "Robot.h"
-
-WaitForPressure::WaitForPressure() { Requires(&Robot::pneumatics); }
-
-// Make this return true when this Command no longer needs to run execute()
-bool WaitForPressure::IsFinished() { return Robot::pneumatics.IsPressurized(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Collector.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Collector.cpp
deleted file mode 100644
index 8f345ce..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Collector.cpp
+++ /dev/null
@@ -1,36 +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 "subsystems/Collector.h"
-
-#include <frc/livewindow/LiveWindow.h>
-
-Collector::Collector() : frc::Subsystem("Collector") {
- // Put everything to the LiveWindow for testing.
- AddChild("Roller Motor", m_rollerMotor);
- AddChild("Ball Detector", m_ballDetector);
- AddChild("Claw Open Detector", m_openDetector);
- AddChild("Piston", m_piston);
-}
-
-bool Collector::HasBall() {
- return m_ballDetector.Get(); // TODO: prepend ! to reflect real robot
-}
-
-void Collector::SetSpeed(double speed) { m_rollerMotor.Set(-speed); }
-
-void Collector::Stop() { m_rollerMotor.Set(0); }
-
-bool Collector::IsOpen() {
- return m_openDetector.Get(); // TODO: prepend ! to reflect real robot
-}
-
-void Collector::Open() { m_piston.Set(true); }
-
-void Collector::Close() { m_piston.Set(false); }
-
-void Collector::InitDefaultCommand() {}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/DriveTrain.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/DriveTrain.cpp
deleted file mode 100644
index 53cb625..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/DriveTrain.cpp
+++ /dev/null
@@ -1,70 +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 "subsystems/DriveTrain.h"
-
-#include <cmath>
-
-#include <frc/Joystick.h>
-
-#include "commands/DriveWithJoystick.h"
-
-DriveTrain::DriveTrain() : frc::Subsystem("DriveTrain") {
- // AddChild("Front Left CIM", m_frontLeftCIM);
- // AddChild("Front Right CIM", m_frontRightCIM);
- // AddChild("Back Left CIM", m_backLeftCIM);
- // AddChild("Back Right CIM", m_backRightCIM);
-
- // Configure the DifferentialDrive to reflect the fact that all our
- // motors are wired backwards and our drivers sensitivity preferences.
- m_robotDrive.SetSafetyEnabled(false);
- m_robotDrive.SetExpiration(0.1);
- m_robotDrive.SetMaxOutput(1.0);
- m_leftCIMs.SetInverted(true);
- m_rightCIMs.SetInverted(true);
-
- // Configure encoders
- m_rightEncoder.SetPIDSourceType(frc::PIDSourceType::kDisplacement);
- m_leftEncoder.SetPIDSourceType(frc::PIDSourceType::kDisplacement);
-
-#ifndef SIMULATION
- // Converts to feet
- m_rightEncoder.SetDistancePerPulse(0.0785398);
- m_leftEncoder.SetDistancePerPulse(0.0785398);
-#else
- // Convert to feet 4in diameter wheels with 360 tick simulated encoders
- m_rightEncoder.SetDistancePerPulse((4.0 /*in*/ * M_PI) /
- (360.0 * 12.0 /*in/ft*/));
- m_leftEncoder.SetDistancePerPulse((4.0 /*in*/ * M_PI) /
- (360.0 * 12.0 /*in/ft*/));
-#endif
-
- AddChild("Right Encoder", m_rightEncoder);
- AddChild("Left Encoder", m_leftEncoder);
-
-// Configure gyro
-#ifndef SIMULATION
- m_gyro.SetSensitivity(0.007); // TODO: Handle more gracefully?
-#endif
- AddChild("Gyro", m_gyro);
-}
-
-void DriveTrain::InitDefaultCommand() {
- SetDefaultCommand(new DriveWithJoystick());
-}
-
-void DriveTrain::TankDrive(double leftAxis, double rightAxis) {
- m_robotDrive.TankDrive(leftAxis, rightAxis);
-}
-
-void DriveTrain::Stop() { m_robotDrive.TankDrive(0.0, 0.0); }
-
-frc::Encoder& DriveTrain::GetLeftEncoder() { return m_leftEncoder; }
-
-frc::Encoder& DriveTrain::GetRightEncoder() { return m_rightEncoder; }
-
-double DriveTrain::GetAngle() { return m_gyro.GetAngle(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pivot.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pivot.cpp
deleted file mode 100644
index 861d583..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pivot.cpp
+++ /dev/null
@@ -1,42 +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 "subsystems/Pivot.h"
-
-Pivot::Pivot() : frc::PIDSubsystem("Pivot", 7.0, 0.0, 8.0) {
- SetAbsoluteTolerance(0.005);
- GetPIDController()->SetContinuous(false);
-#ifdef SIMULATION
- // PID is different in simulation.
- GetPIDController()->SetPID(0.5, 0.001, 2);
- SetAbsoluteTolerance(5);
-#endif
-
- // Put everything to the LiveWindow for testing.
- AddChild("Upper Limit Switch", m_upperLimitSwitch);
- AddChild("Lower Limit Switch", m_lowerLimitSwitch);
- AddChild("Pot", m_pot);
- AddChild("Motor", m_motor);
-}
-
-void InitDefaultCommand() {}
-
-double Pivot::ReturnPIDInput() { return m_pot.Get(); }
-
-void Pivot::UsePIDOutput(double output) { m_motor.PIDWrite(output); }
-
-bool Pivot::IsAtUpperLimit() {
- return m_upperLimitSwitch.Get(); // TODO: inverted from real robot
- // (prefix with !)
-}
-
-bool Pivot::IsAtLowerLimit() {
- return m_lowerLimitSwitch.Get(); // TODO: inverted from real robot
- // (prefix with !)
-}
-
-double Pivot::GetAngle() { return m_pot.Get(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pneumatics.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pneumatics.cpp
deleted file mode 100644
index dd1a824..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pneumatics.cpp
+++ /dev/null
@@ -1,36 +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 "subsystems/Pneumatics.h"
-
-#include <frc/smartdashboard/SmartDashboard.h>
-
-Pneumatics::Pneumatics() : frc::Subsystem("Pneumatics") {
- AddChild("Pressure Sensor", m_pressureSensor);
-}
-
-void Pneumatics::InitDefaultCommand() {
- // No default command
-}
-
-void Pneumatics::Start() {
-#ifndef SIMULATION
- m_compressor.Start();
-#endif
-}
-
-bool Pneumatics::IsPressurized() {
-#ifndef SIMULATION
- return kMaxPressure <= m_pressureSensor.GetVoltage();
-#else
- return true; // NOTE: Simulation always has full pressure
-#endif
-}
-
-void Pneumatics::WritePressure() {
- frc::SmartDashboard::PutNumber("Pressure", m_pressureSensor.GetVoltage());
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Shooter.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Shooter.cpp
deleted file mode 100644
index 80d7ac3..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Shooter.cpp
+++ /dev/null
@@ -1,60 +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 "subsystems/Shooter.h"
-
-Shooter::Shooter() : Subsystem("Shooter") {
- // Put everything to the LiveWindow for testing.
- AddChild("Hot Goal Sensor", m_hotGoalSensor);
- AddChild("Piston1 Reed Switch Front ", m_piston1ReedSwitchFront);
- AddChild("Piston1 Reed Switch Back ", m_piston1ReedSwitchBack);
- AddChild("Latch Piston", m_latchPiston);
-}
-
-void Shooter::InitDefaultCommand() {
- // Set the default command for a subsystem here.
- // SetDefaultCommand(new MySpecialCommand());
-}
-
-void Shooter::ExtendBoth() {
- m_piston1.Set(frc::DoubleSolenoid::kForward);
- m_piston2.Set(frc::DoubleSolenoid::kForward);
-}
-
-void Shooter::RetractBoth() {
- m_piston1.Set(frc::DoubleSolenoid::kReverse);
- m_piston2.Set(frc::DoubleSolenoid::kReverse);
-}
-
-void Shooter::Extend1() { m_piston1.Set(frc::DoubleSolenoid::kForward); }
-
-void Shooter::Retract1() { m_piston1.Set(frc::DoubleSolenoid::kReverse); }
-
-void Shooter::Extend2() { m_piston2.Set(frc::DoubleSolenoid::kReverse); }
-
-void Shooter::Retract2() { m_piston2.Set(frc::DoubleSolenoid::kForward); }
-
-void Shooter::Off1() { m_piston1.Set(frc::DoubleSolenoid::kOff); }
-
-void Shooter::Off2() { m_piston2.Set(frc::DoubleSolenoid::kOff); }
-
-void Shooter::Unlatch() { m_latchPiston.Set(true); }
-
-void Shooter::Latch() { m_latchPiston.Set(false); }
-
-void Shooter::ToggleLatchPosition() { m_latchPiston.Set(!m_latchPiston.Get()); }
-
-bool Shooter::Piston1IsExtended() { return !m_piston1ReedSwitchFront.Get(); }
-
-bool Shooter::Piston1IsRetracted() { return !m_piston1ReedSwitchBack.Get(); }
-
-void Shooter::OffBoth() {
- m_piston1.Set(frc::DoubleSolenoid::kOff);
- m_piston2.Set(frc::DoubleSolenoid::kOff);
-}
-
-bool Shooter::GoalIsHot() { return m_hotGoalSensor.Get(); }
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/triggers/DoubleButton.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/triggers/DoubleButton.cpp
deleted file mode 100644
index f2f7f64..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/triggers/DoubleButton.cpp
+++ /dev/null
@@ -1,20 +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 "triggers/DoubleButton.h"
-
-#include <frc/Joystick.h>
-
-DoubleButton::DoubleButton(frc::Joystick* joy, int button1, int button2)
- : m_joy(*joy) {
- m_button1 = button1;
- m_button2 = button2;
-}
-
-bool DoubleButton::Get() {
- return m_joy.GetRawButton(m_button1) && m_joy.GetRawButton(m_button2);
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/OI.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/OI.h
deleted file mode 100644
index 2df4395..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/OI.h
+++ /dev/null
@@ -1,29 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/Joystick.h>
-#include <frc/buttons/JoystickButton.h>
-
-#include "triggers/DoubleButton.h"
-
-class OI {
- public:
- OI();
- frc::Joystick& GetJoystick();
-
- private:
- frc::Joystick m_joystick{0};
-
- frc::JoystickButton m_l1{&m_joystick, 11};
- frc::JoystickButton m_l2{&m_joystick, 9};
- frc::JoystickButton m_r1{&m_joystick, 12};
- frc::JoystickButton m_r2{&m_joystick, 10};
-
- DoubleButton m_sticks{&m_joystick, 2, 3};
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/Robot.h
deleted file mode 100644
index b24085d..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/Robot.h
+++ /dev/null
@@ -1,48 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/TimedRobot.h>
-#include <frc/commands/Command.h>
-#include <frc/smartdashboard/SendableChooser.h>
-
-#include "OI.h"
-#include "commands/DriveAndShootAutonomous.h"
-#include "commands/DriveForward.h"
-#include "subsystems/Collector.h"
-#include "subsystems/DriveTrain.h"
-#include "subsystems/Pivot.h"
-#include "subsystems/Pneumatics.h"
-#include "subsystems/Shooter.h"
-
-class Robot : public frc::TimedRobot {
- public:
- static DriveTrain drivetrain;
- static Pivot pivot;
- static Collector collector;
- static Shooter shooter;
- static Pneumatics pneumatics;
- static OI oi;
-
- private:
- frc::Command* m_autonomousCommand = nullptr;
- DriveAndShootAutonomous m_driveAndShootAuto;
- DriveForward m_driveForwardAuto;
- frc::SendableChooser<frc::Command*> m_autoChooser;
-
- void RobotInit() override;
- void AutonomousInit() override;
- void AutonomousPeriodic() override;
- void TeleopInit() override;
- void TeleopPeriodic() override;
- void TestPeriodic() override;
- void DisabledInit() override;
- void DisabledPeriodic() override;
-
- void Log();
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/CheckForHotGoal.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/CheckForHotGoal.h
deleted file mode 100644
index 9f42461..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/CheckForHotGoal.h
+++ /dev/null
@@ -1,22 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-/**
- * This command looks for the hot goal and waits until it's detected or timed
- * out. The timeout is because it's better to shoot and get some autonomous
- * points than get none. When called sequentially, this command will block until
- * the hot goal is detected or until it is timed out.
- */
-class CheckForHotGoal : public frc::Command {
- public:
- explicit CheckForHotGoal(double time);
- bool IsFinished() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/CloseClaw.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/CloseClaw.h
deleted file mode 100644
index 60f12a9..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/CloseClaw.h
+++ /dev/null
@@ -1,22 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/InstantCommand.h>
-
-/**
- * Close the claw.
- *
- * NOTE: It doesn't wait for the claw to close since there is no sensor to
- * detect that.
- */
-class CloseClaw : public frc::InstantCommand {
- public:
- CloseClaw();
- void Initialize() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/Collect.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/Collect.h
deleted file mode 100644
index c2965c2..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/Collect.h
+++ /dev/null
@@ -1,18 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/CommandGroup.h>
-
-/**
- * Get the robot set to collect balls.
- */
-class Collect : public frc::CommandGroup {
- public:
- Collect();
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveAndShootAutonomous.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveAndShootAutonomous.h
deleted file mode 100644
index e143738..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveAndShootAutonomous.h
+++ /dev/null
@@ -1,19 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/CommandGroup.h>
-
-/**
- * Drive over the line and then shoot the ball. If the hot goal is not detected,
- * it will wait briefly.
- */
-class DriveAndShootAutonomous : public frc::CommandGroup {
- public:
- DriveAndShootAutonomous();
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveForward.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveForward.h
deleted file mode 100644
index a89134e..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveForward.h
+++ /dev/null
@@ -1,34 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-/**
- * This command drives the robot over a given distance with simple proportional
- * control This command will drive a given distance limiting to a maximum speed.
- */
-class DriveForward : public frc::Command {
- public:
- DriveForward();
- explicit DriveForward(double dist);
- DriveForward(double dist, double maxSpeed);
- void Initialize() override;
- void Execute() override;
- bool IsFinished() override;
- void End() override;
-
- private:
- double m_driveForwardSpeed;
- double m_distance;
- double m_error = 0;
- static constexpr double kTolerance = 0.1;
- static constexpr double kP = -1.0 / 5.0;
-
- void init(double dist, double maxSpeed);
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveWithJoystick.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveWithJoystick.h
deleted file mode 100644
index e6d9b0e..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/DriveWithJoystick.h
+++ /dev/null
@@ -1,22 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-/**
- * This command allows PS3 joystick to drive the robot. It is always running
- * except when interrupted by another command.
- */
-class DriveWithJoystick : public frc::Command {
- public:
- DriveWithJoystick();
- void Execute() override;
- bool IsFinished() override;
- void End() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/ExtendShooter.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/ExtendShooter.h
deleted file mode 100644
index 634860e..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/ExtendShooter.h
+++ /dev/null
@@ -1,20 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/TimedCommand.h>
-
-/**
- * Extend the shooter and then retract it after a second.
- */
-class ExtendShooter : public frc::TimedCommand {
- public:
- ExtendShooter();
- void Initialize() override;
- void End() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/LowGoal.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/LowGoal.h
deleted file mode 100644
index 62237fe..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/LowGoal.h
+++ /dev/null
@@ -1,19 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/CommandGroup.h>
-
-/**
- * Spit the ball out into the low goal assuming that the robot is in front of
- * it.
- */
-class LowGoal : public frc::CommandGroup {
- public:
- LowGoal();
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/OpenClaw.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/OpenClaw.h
deleted file mode 100644
index 0d78877..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/OpenClaw.h
+++ /dev/null
@@ -1,20 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-/**
- * Opens the claw
- */
-class OpenClaw : public frc::Command {
- public:
- OpenClaw();
- void Initialize() override;
- bool IsFinished() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/SetCollectionSpeed.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/SetCollectionSpeed.h
deleted file mode 100644
index 24bb4e3..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/SetCollectionSpeed.h
+++ /dev/null
@@ -1,24 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/InstantCommand.h>
-
-/**
- * This command sets the collector rollers spinning at the given speed. Since
- * there is no sensor for detecting speed, it finishes immediately. As a result,
- * the spinners may still be adjusting their speed.
- */
-class SetCollectionSpeed : public frc::InstantCommand {
- public:
- explicit SetCollectionSpeed(double speed);
- void Initialize() override;
-
- private:
- double m_speed;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/SetPivotSetpoint.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/SetPivotSetpoint.h
deleted file mode 100644
index 8f8f615..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/SetPivotSetpoint.h
+++ /dev/null
@@ -1,25 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-/**
- * Moves the pivot to a given angle. This command finishes when it is within
- * the tolerance, but leaves the PID loop running to maintain the position.
- * Other commands using the pivot should make sure they disable PID!
- */
-class SetPivotSetpoint : public frc::Command {
- public:
- explicit SetPivotSetpoint(double setpoint);
- void Initialize() override;
- bool IsFinished() override;
-
- private:
- double m_setpoint;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/Shoot.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/Shoot.h
deleted file mode 100644
index 242221c..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/Shoot.h
+++ /dev/null
@@ -1,18 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/CommandGroup.h>
-
-/**
- * Shoot the ball at the current angle.
- */
-class Shoot : public frc::CommandGroup {
- public:
- Shoot();
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/WaitForBall.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/WaitForBall.h
deleted file mode 100644
index b6d8d99..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/WaitForBall.h
+++ /dev/null
@@ -1,21 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-/**
- * Wait until the collector senses that it has the ball. This command does
- * nothing and is intended to be used in command groups to wait for this
- * condition.
- */
-class WaitForBall : public frc::Command {
- public:
- WaitForBall();
- bool IsFinished() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/WaitForPressure.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/WaitForPressure.h
deleted file mode 100644
index 49e1f17..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/commands/WaitForPressure.h
+++ /dev/null
@@ -1,20 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-/**
- * Wait until the pneumatics are fully pressurized. This command does nothing
- * and is intended to be used in command groups to wait for this condition.
- */
-class WaitForPressure : public frc::Command {
- public:
- WaitForPressure();
- bool IsFinished() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Collector.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Collector.h
deleted file mode 100644
index 3e237fa..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Collector.h
+++ /dev/null
@@ -1,76 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/DigitalInput.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/Solenoid.h>
-#include <frc/commands/Subsystem.h>
-
-/**
- * The Collector subsystem has one motor for the rollers, a limit switch for
- * ball
- * detection, a piston for opening and closing the claw, and a reed switch to
- * check if the piston is open.
- */
-class Collector : public frc::Subsystem {
- public:
- // Constants for some useful speeds
- static constexpr double kForward = 1;
- static constexpr double kStop = 0;
- static constexpr double kReverse = -1;
-
- Collector();
-
- /**
- * NOTE: The current simulation model uses the the lower part of the
- * claw
- * since the limit switch wasn't exported. At some point, this will be
- * updated.
- *
- * @return Whether or not the robot has the ball.
- */
- bool HasBall();
-
- /**
- * @param speed The speed to spin the rollers.
- */
- void SetSpeed(double speed);
-
- /**
- * Stop the rollers from spinning
- */
- void Stop();
-
- /**
- * @return Whether or not the claw is open.
- */
- bool IsOpen();
-
- /**
- * Open the claw up. (For shooting)
- */
- void Open();
-
- /**
- * Close the claw. (For collecting and driving)
- */
- void Close();
-
- /**
- * No default command.
- */
- void InitDefaultCommand() override;
-
- private:
- // Subsystem devices
- frc::PWMVictorSPX m_rollerMotor{6};
- frc::DigitalInput m_ballDetector{10};
- frc::Solenoid m_piston{1};
- frc::DigitalInput m_openDetector{6};
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/DriveTrain.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/DriveTrain.h
deleted file mode 100644
index 0afa3eb..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/DriveTrain.h
+++ /dev/null
@@ -1,79 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/AnalogGyro.h>
-#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
-#include <frc/commands/Subsystem.h>
-#include <frc/drive/DifferentialDrive.h>
-
-namespace frc {
-class Joystick;
-} // namespace frc
-
-/**
- * The DriveTrain subsystem controls the robot's chassis and reads in
- * information about it's speed and position.
- */
-class DriveTrain : public frc::Subsystem {
- public:
- DriveTrain();
-
- /**
- * When other commands aren't using the drivetrain, allow tank drive
- * with
- * the joystick.
- */
- void InitDefaultCommand();
-
- /**
- * @param leftAxis Left sides value
- * @param rightAxis Right sides value
- */
- void TankDrive(double leftAxis, double rightAxis);
-
- /**
- * Stop the drivetrain from moving.
- */
- void Stop();
-
- /**
- * @return The encoder getting the distance and speed of left side of
- * the drivetrain.
- */
- frc::Encoder& GetLeftEncoder();
-
- /**
- * @return The encoder getting the distance and speed of right side of
- * the drivetrain.
- */
- frc::Encoder& GetRightEncoder();
-
- /**
- * @return The current angle of the drivetrain.
- */
- double GetAngle();
-
- private:
- // Subsystem devices
- frc::PWMVictorSPX m_frontLeftCIM{1};
- frc::PWMVictorSPX m_rearLeftCIM{2};
- frc::SpeedControllerGroup m_leftCIMs{m_frontLeftCIM, m_rearLeftCIM};
-
- frc::PWMVictorSPX m_frontRightCIM{3};
- frc::PWMVictorSPX m_rearRightCIM{4};
- frc::SpeedControllerGroup m_rightCIMs{m_frontRightCIM, m_rearRightCIM};
-
- frc::DifferentialDrive m_robotDrive{m_leftCIMs, m_rightCIMs};
-
- frc::Encoder m_rightEncoder{1, 2, true, frc::Encoder::k4X};
- frc::Encoder m_leftEncoder{3, 4, false, frc::Encoder::k4X};
- frc::AnalogGyro m_gyro{0};
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pivot.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pivot.h
deleted file mode 100644
index f9a3c25..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pivot.h
+++ /dev/null
@@ -1,74 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/AnalogPotentiometer.h>
-#include <frc/DigitalInput.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/commands/PIDSubsystem.h>
-
-/**
- * The Pivot subsystem contains the Van-door motor and the pot for PID control
- * of angle of the pivot and claw.
- */
-class Pivot : public frc::PIDSubsystem {
- public:
- // Constants for some useful angles
- static constexpr double kCollect = 105;
- static constexpr double kLowGoal = 90;
- static constexpr double kShoot = 45;
- static constexpr double kShootNear = 30;
-
- Pivot();
-
- /**
- * No default command, if PID is enabled, the current setpoint will be
- * maintained.
- */
- void InitDefaultCommand() override {}
-
- /**
- * @return The angle read in by the potentiometer
- */
- double ReturnPIDInput() override;
-
- /**
- * Set the motor speed based off of the PID output
- */
- void UsePIDOutput(double output) override;
-
- /**
- * @return If the pivot is at its upper limit.
- */
- bool IsAtUpperLimit();
-
- /**
- * @return If the pivot is at its lower limit.
- */
- bool IsAtLowerLimit();
-
- /**
- * @return The current angle of the pivot.
- */
- double GetAngle();
-
- private:
- // Subsystem devices
-
- // Sensors for measuring the position of the pivot
- frc::DigitalInput m_upperLimitSwitch{13};
- frc::DigitalInput m_lowerLimitSwitch{12};
-
- /* 0 degrees is vertical facing up.
- * Angle increases the more forward the pivot goes.
- */
- frc::AnalogPotentiometer m_pot{1};
-
- // Motor to move the pivot
- frc::PWMVictorSPX m_motor{5};
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pneumatics.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pneumatics.h
deleted file mode 100644
index d321895..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pneumatics.h
+++ /dev/null
@@ -1,53 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/AnalogInput.h>
-#include <frc/Compressor.h>
-#include <frc/commands/Subsystem.h>
-
-/**
- * The Pneumatics subsystem contains the compressor and a pressure sensor.
- *
- * NOTE: The simulator currently doesn't support the compressor or pressure
- * sensors.
- */
-class Pneumatics : public frc::Subsystem {
- public:
- Pneumatics();
-
- /**
- * No default command
- */
- void InitDefaultCommand() override;
-
- /**
- * Start the compressor going. The compressor automatically starts and
- * stops as it goes above and below maximum pressure.
- */
- void Start();
-
- /**
- * @return Whether or not the system is fully pressurized.
- */
- bool IsPressurized();
-
- /**
- * Puts the pressure on the SmartDashboard.
- */
- void WritePressure();
-
- private:
- frc::AnalogInput m_pressureSensor{3};
-
-#ifndef SIMULATION
- frc::Compressor m_compressor{1}; // TODO: (1, 14, 1, 8);
-#endif
-
- static constexpr double kMaxPressure = 2.55;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Shooter.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Shooter.h
deleted file mode 100644
index 43f111a..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Shooter.h
+++ /dev/null
@@ -1,127 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/DigitalInput.h>
-#include <frc/DoubleSolenoid.h>
-#include <frc/Solenoid.h>
-#include <frc/commands/Subsystem.h>
-
-/**
- * The Shooter subsystem handles shooting. The mechanism for shooting is
- * slightly complicated because it has to pneumatic cylinders for shooting, and
- * a third latch to allow the pressure to partially build up and reduce the
- * effect of the airflow. For shorter shots, when full power isn't needed, only
- * one cylinder fires.
- *
- * NOTE: Simulation currently approximates this as as single pneumatic cylinder
- * and ignores the latch.
- */
-class Shooter : public frc::Subsystem {
- public:
- Shooter();
- void InitDefaultCommand() override;
-
- /**
- * Extend both solenoids to shoot.
- */
- void ExtendBoth();
-
- /**
- * Retract both solenoids to prepare to shoot.
- */
- void RetractBoth();
-
- /**
- * Extend solenoid 1 to shoot.
- */
- void Extend1();
-
- /**
- * Retract solenoid 1 to prepare to shoot.
- */
- void Retract1();
-
- /**
- * Extend solenoid 2 to shoot.
- */
- void Extend2();
-
- /**
- * Retract solenoid 2 to prepare to shoot.
- */
- void Retract2();
-
- /**
- * Turns off the piston1 double solenoid. This won't actuate anything
- * because double solenoids preserve their state when turned off. This
- * should be called in order to reduce the amount of time that the coils
- * are
- * powered.
- */
- void Off1();
-
- /**
- * Turns off the piston1 double solenoid. This won't actuate anything
- * because double solenoids preserve their state when turned off. This
- * should be called in order to reduce the amount of time that the coils
- * are
- * powered.
- */
- void Off2();
-
- /**
- * Release the latch so that we can shoot
- */
- void Unlatch();
-
- /**
- * Latch so that pressure can build up and we aren't limited by air
- * flow.
- */
- void Latch();
-
- /**
- * Toggles the latch postions
- */
- void ToggleLatchPosition();
-
- /**
- * @return Whether or not piston 1 is fully extended.
- */
- bool Piston1IsExtended();
-
- /**
- * @return Whether or not piston 1 is fully retracted.
- */
- bool Piston1IsRetracted();
-
- /**
- * Turns off all double solenoids. Double solenoids hold their position
- * when
- * they are turned off. We should turn them off whenever possible to
- * extend
- * the life of the coils
- */
- void OffBoth();
-
- /**
- * @return Whether or not the goal is hot as read by the banner sensor
- */
- bool GoalIsHot();
-
- private:
- // Devices
- frc::DoubleSolenoid m_piston1{3, 4};
- frc::DoubleSolenoid m_piston2{5, 6};
- frc::Solenoid m_latchPiston{1, 2};
- frc::DigitalInput m_piston1ReedSwitchFront{9};
- frc::DigitalInput m_piston1ReedSwitchBack{11};
- frc::DigitalInput m_hotGoalSensor{
- 7}; // NOTE: Currently ignored in simulation
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/triggers/DoubleButton.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/triggers/DoubleButton.h
deleted file mode 100644
index 562154b..0000000
--- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/triggers/DoubleButton.h
+++ /dev/null
@@ -1,26 +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. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/buttons/Trigger.h>
-
-namespace frc {
-class Joystick;
-} // namespace frc
-
-class DoubleButton : public frc::Trigger {
- public:
- DoubleButton(frc::Joystick* joy, int button1, int button2);
-
- bool Get();
-
- private:
- frc::Joystick& m_joy;
- int m_button1;
- int m_button2;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp
index afc10a3..5b6b024 100644
--- a/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <array>
#include <frc/AnalogInput.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/controller/PIDController.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a sample program to demonstrate how to use a soft potentiometer and a
@@ -20,6 +17,10 @@
*/
class Robot : public frc::TimedRobot {
public:
+ void RobotInit() override {
+ m_pidController.SetSetpoint(kSetPoints[m_index]);
+ }
+
void TeleopPeriodic() override {
// When the button is pressed once, the selected elevator setpoint is
// incremented.
@@ -27,10 +28,10 @@
if (currentButtonValue && !m_previousButtonValue) {
// Index of the elevator setpoint wraps around
m_index = (m_index + 1) % (sizeof(kSetPoints) / 8);
+ m_pidController.SetSetpoint(kSetPoints[m_index]);
}
m_previousButtonValue = currentButtonValue;
- m_pidController.SetSetpoint(kSetPoints[m_index]);
double output =
m_pidController.Calculate(m_potentiometer.GetAverageVoltage());
m_elevatorMotor.Set(output);
@@ -61,7 +62,7 @@
frc::AnalogInput m_potentiometer{kPotChannel};
frc::Joystick m_joystick{kJoystickChannel};
- frc::PWMVictorSPX m_elevatorMotor{kMotorChannel};
+ frc::PWMSparkMax m_elevatorMotor{kMotorChannel};
frc2::PIDController m_pidController{kP, kI, kD};
};
@@ -69,5 +70,7 @@
constexpr std::array<double, 3> Robot::kSetPoints;
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp
index 1ad76de..aae646f 100644
--- a/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp
@@ -1,13 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <cstdio>
#include <cameraserver/CameraServer.h>
#include <frc/TimedRobot.h>
-#include <wpi/raw_ostream.h>
/**
* Uses the CameraServer class to automatically capture video from a USB webcam
@@ -18,15 +16,17 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
-#if defined(__linux__)
- frc::CameraServer::GetInstance()->StartAutomaticCapture();
+#if defined(__linux__) || defined(_WIN32)
+ frc::CameraServer::StartAutomaticCapture();
#else
- wpi::errs() << "Vision only available on Linux.\n";
- wpi::errs().flush();
+ std::fputs("Vision only available on Linux or Windows.\n", stderr);
+ std::fflush(stderr);
#endif
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Constants.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Constants.cpp
index 46ffde3..d462c24 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Constants.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Constants.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Constants.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp
index 2f39216..49ee31b 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
+#include <utility>
+
#include <frc/controller/PIDController.h>
#include <frc/controller/RamseteController.h>
#include <frc/shuffleboard/Shuffleboard.h>
@@ -29,9 +28,8 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp
index a82d22d..78355a2 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -20,6 +17,11 @@
m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]},
m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]},
m_odometry{m_gyro.GetRotation2d()} {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotors.SetInverted(true);
+
// Set the distance per pulse for the encoders
m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
@@ -53,9 +55,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
@@ -65,9 +71,13 @@
return m_gyro.GetRotation2d().Degrees();
}
-double DriveSubsystem::GetTurnRate() { return -m_gyro.GetRate(); }
+double DriveSubsystem::GetTurnRate() {
+ return -m_gyro.GetRate();
+}
-frc::Pose2d DriveSubsystem::GetPose() { return m_odometry.GetPose(); }
+frc::Pose2d DriveSubsystem::GetPose() {
+ return m_odometry.GetPose();
+}
frc::DifferentialDriveWheelSpeeds DriveSubsystem::GetWheelSpeeds() {
return {units::meters_per_second_t(m_leftEncoder.GetRate()),
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h
index 7d3ea8f..cdd3a43 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/trajectory/constraint/DifferentialDriveKinematicsConstraint.h>
@@ -12,7 +9,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
#pragma once
@@ -43,7 +40,8 @@
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterInches * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
// These characterization values MUST be determined either experimentally or
@@ -69,5 +67,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/RobotContainer.h
index d6e4288..3d6a36f 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h
index 73c6c21..8ea14da 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h
@@ -1,19 +1,16 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/ADXRS450_Gyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/geometry/Pose2d.h>
#include <frc/kinematics/DifferentialDriveOdometry.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include <units/voltage.h>
@@ -120,16 +117,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1;
- frc::PWMVictorSPX m_left2;
- frc::PWMVictorSPX m_right1;
- frc::PWMVictorSPX m_right2;
+ frc::PWMSparkMax m_left1;
+ frc::PWMSparkMax m_left2;
+ frc::PWMSparkMax m_right1;
+ frc::PWMSparkMax m_right2;
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp
index f52ddec..1871688 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Drivetrain.h"
@@ -11,9 +8,9 @@
const auto leftFeedforward = m_feedforward.Calculate(speeds.left);
const auto rightFeedforward = m_feedforward.Calculate(speeds.right);
const double leftOutput = m_leftPIDController.Calculate(
- m_leftEncoder.GetRate(), speeds.left.to<double>());
+ m_leftEncoder.GetRate(), speeds.left.value());
const double rightOutput = m_rightPIDController.Calculate(
- m_rightEncoder.GetRate(), speeds.right.to<double>());
+ m_rightEncoder.GetRate(), speeds.right.value());
m_leftGroup.SetVoltage(units::volt_t{leftOutput} + leftFeedforward);
m_rightGroup.SetVoltage(units::volt_t{rightOutput} + rightFeedforward);
@@ -34,4 +31,6 @@
m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
}
-frc::Pose2d Drivetrain::GetPose() const { return m_odometry.GetPose(); }
+frc::Pose2d Drivetrain::GetPose() const {
+ return m_odometry.GetPose();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp
index 61e5d85..f47da51 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp
@@ -1,16 +1,15 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc/SlewRateLimiter.h>
#include <frc/TimedRobot.h>
+#include <frc/Timer.h>
#include <frc/XboxController.h>
#include <frc/controller/RamseteController.h>
+#include <frc/filter/SlewRateLimiter.h>
+#include <frc/smartdashboard/Field2d.h>
+#include <frc/smartdashboard/SmartDashboard.h>
#include <frc/trajectory/TrajectoryGenerator.h>
-#include <frc2/Timer.h>
#include "Drivetrain.h"
@@ -20,14 +19,23 @@
// Start the timer.
m_timer.Start();
+ // Send Field2d to SmartDashboard.
+ frc::SmartDashboard::PutData(&m_field);
+
// Reset the drivetrain's odometry to the starting pose of the trajectory.
m_drive.ResetOdometry(m_trajectory.InitialPose());
+
+ // Send our generated trajectory to Field2d.
+ m_field.GetObject("traj")->SetTrajectory(m_trajectory);
}
void AutonomousPeriodic() override {
// Update odometry.
m_drive.UpdateOdometry();
+ // Update robot position on Field2d.
+ m_field.SetRobotPose(m_drive.GetPose());
+
if (m_timer.Get() < m_trajectory.TotalTime()) {
// Get the desired pose from the trajectory.
auto desiredPose = m_trajectory.Sample(m_timer.Get());
@@ -46,16 +54,14 @@
void TeleopPeriodic() override {
// Get the x speed. We are inverting this because Xbox controllers return
// negative values when we push forward.
- const auto xSpeed = -m_speedLimiter.Calculate(
- m_controller.GetY(frc::GenericHID::kLeftHand)) *
+ const auto xSpeed = -m_speedLimiter.Calculate(m_controller.GetLeftY()) *
Drivetrain::kMaxSpeed;
// Get the rate of angular rotation. We are inverting this because we want a
// positive value when we pull to the left (remember, CCW is positive in
// mathematics). Xbox controllers return positive values when you pull to
// the right by default.
- const auto rot = -m_rotLimiter.Calculate(
- m_controller.GetX(frc::GenericHID::kRightHand)) *
+ const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
Drivetrain::kMaxAngularSpeed;
m_drive.Drive(xSpeed, rot);
@@ -81,9 +87,14 @@
frc::RamseteController m_ramseteController;
// The timer to use during the autonomous period.
- frc2::Timer m_timer;
+ frc::Timer m_timer;
+
+ // Create Field2d for robot and trajectory visualizations.
+ frc::Field2d m_field;
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h
index a707014..11fa523 100644
--- a/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h
@@ -1,23 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/AnalogGyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/SimpleMotorFeedforward.h>
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/kinematics/DifferentialDriveOdometry.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <units/angular_velocity.h>
#include <units/length.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -26,12 +23,18 @@
public:
Drivetrain() {
m_gyro.Reset();
+
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightGroup.SetInverted(true);
+
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_leftEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
+ m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
- m_rightEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
+ m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -41,7 +44,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::math::pi}; // 1/2 rotation per second
+ wpi::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,
@@ -55,13 +58,13 @@
static constexpr double kWheelRadius = 0.0508; // meters
static constexpr int kEncoderResolution = 4096;
- frc::PWMVictorSPX m_leftLeader{1};
- frc::PWMVictorSPX m_leftFollower{2};
- frc::PWMVictorSPX m_rightLeader{3};
- frc::PWMVictorSPX m_rightFollower{4};
+ frc::PWMSparkMax m_leftLeader{1};
+ frc::PWMSparkMax m_leftFollower{2};
+ frc::PWMSparkMax m_rightLeader{3};
+ frc::PWMSparkMax m_rightFollower{4};
- frc::SpeedControllerGroup m_leftGroup{m_leftLeader, m_leftFollower};
- frc::SpeedControllerGroup m_rightGroup{m_rightLeader, m_rightFollower};
+ frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower};
+ frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower};
frc::Encoder m_leftEncoder{0, 1};
frc::Encoder m_rightEncoder{2, 3};
diff --git a/wpilibcExamples/src/main/cpp/examples/Relay/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Relay/cpp/Robot.cpp
index 8225b1c..b4db999 100644
--- a/wpilibcExamples/src/main/cpp/examples/Relay/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Relay/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/Joystick.h>
#include <frc/Relay.h>
@@ -56,5 +53,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/Robot.cpp
new file mode 100644
index 0000000..fa9438d
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/Robot.cpp
@@ -0,0 +1,71 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "Robot.h"
+
+#include <frc2/command/CommandScheduler.h>
+
+void Robot::RobotInit() {}
+
+/**
+ * This function is called every robot packet, no matter the mode. Use
+ * this for items like diagnostics that you want to run during disabled,
+ * autonomous, teleoperated and test.
+ *
+ * <p> This runs after the mode specific periodic functions, but before
+ * LiveWindow and SmartDashboard integrated updating.
+ */
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
+
+/**
+ * This function is called once each time the robot enters Disabled mode. You
+ * can use it to reset any subsystem information you want to clear when the
+ * robot is disabled.
+ */
+void Robot::DisabledInit() {}
+
+void Robot::DisabledPeriodic() {}
+
+/**
+ * This autonomous runs the autonomous command selected by your {@link
+ * RobotContainer} class.
+ */
+void Robot::AutonomousInit() {
+ m_autonomousCommand = m_container.GetAutonomousCommand();
+
+ if (m_autonomousCommand != nullptr) {
+ m_autonomousCommand->Schedule();
+ }
+}
+
+void Robot::AutonomousPeriodic() {}
+
+void Robot::TeleopInit() {
+ // This makes sure that the autonomous stops running when
+ // teleop starts running. If you want the autonomous to
+ // continue until interrupted by another command, remove
+ // this line or comment it out.
+ if (m_autonomousCommand != nullptr) {
+ m_autonomousCommand->Cancel();
+ m_autonomousCommand = nullptr;
+ }
+}
+
+/**
+ * This function is called periodically during operator control.
+ */
+void Robot::TeleopPeriodic() {}
+
+/**
+ * This function is called periodically during test mode.
+ */
+void Robot::TestPeriodic() {}
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp
new file mode 100644
index 0000000..3cbad01
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp
@@ -0,0 +1,36 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "RobotContainer.h"
+
+#include <frc/smartdashboard/SmartDashboard.h>
+#include <frc2/command/PrintCommand.h>
+#include <frc2/command/button/Button.h>
+
+#include "commands/TeleopArcadeDrive.h"
+
+RobotContainer::RobotContainer() {
+ // Configure the button bindings
+ ConfigureButtonBindings();
+}
+
+void RobotContainer::ConfigureButtonBindings() {
+ // Also set default commands here
+ m_drive.SetDefaultCommand(TeleopArcadeDrive(
+ &m_drive, [this] { return -m_controller.GetRawAxis(1); },
+ [this] { return m_controller.GetRawAxis(2); }));
+
+ // Example of how to use the onboard IO
+ m_onboardButtonA.WhenPressed(frc2::PrintCommand("Button A Pressed"))
+ .WhenReleased(frc2::PrintCommand("Button A Released"));
+
+ // Setup SmartDashboard options.
+ m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance);
+ m_chooser.AddOption("Auto Routine Time", &m_autoTime);
+ frc::SmartDashboard::PutData("Auto Selector", &m_chooser);
+}
+
+frc2::Command* RobotContainer::GetAutonomousCommand() {
+ return m_chooser.GetSelected();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp
new file mode 100644
index 0000000..dcb59e3
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "commands/DriveDistance.h"
+
+#include <units/math.h>
+
+void DriveDistance::Initialize() {
+ m_drive->ArcadeDrive(0, 0);
+ m_drive->ResetEncoders();
+}
+
+void DriveDistance::Execute() {
+ m_drive->ArcadeDrive(m_speed, 0);
+}
+
+void DriveDistance::End(bool interrupted) {
+ m_drive->ArcadeDrive(0, 0);
+}
+
+bool DriveDistance::IsFinished() {
+ return units::math::abs(m_drive->GetAverageDistance()) >= m_distance;
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveTime.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveTime.cpp
new file mode 100644
index 0000000..52670a0
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveTime.cpp
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "commands/DriveTime.h"
+
+void DriveTime::Initialize() {
+ m_timer.Start();
+ m_drive->ArcadeDrive(0, 0);
+}
+
+void DriveTime::Execute() {
+ m_drive->ArcadeDrive(m_speed, 0);
+}
+
+void DriveTime::End(bool interrupted) {
+ m_drive->ArcadeDrive(0, 0);
+ m_timer.Stop();
+ m_timer.Reset();
+}
+
+bool DriveTime::IsFinished() {
+ return m_timer.HasElapsed(m_duration);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TeleopArcadeDrive.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TeleopArcadeDrive.cpp
new file mode 100644
index 0000000..0f58527
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TeleopArcadeDrive.cpp
@@ -0,0 +1,20 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "commands/TeleopArcadeDrive.h"
+
+#include "subsystems/Drivetrain.h"
+
+TeleopArcadeDrive::TeleopArcadeDrive(
+ Drivetrain* subsystem, std::function<double()> xaxisSpeedSupplier,
+ std::function<double()> zaxisRotateSuppplier)
+ : m_drive{subsystem},
+ m_xaxisSpeedSupplier{xaxisSpeedSupplier},
+ m_zaxisRotateSupplier{zaxisRotateSuppplier} {
+ AddRequirements({subsystem});
+}
+
+void TeleopArcadeDrive::Execute() {
+ m_drive->ArcadeDrive(m_xaxisSpeedSupplier(), m_zaxisRotateSupplier());
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp
new file mode 100644
index 0000000..2d6c148
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp
@@ -0,0 +1,39 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "commands/TurnDegrees.h"
+
+#include <units/math.h>
+#include <wpi/numbers>
+
+void TurnDegrees::Initialize() {
+ // Set motors to stop, read encoder values for starting point
+ m_drive->ArcadeDrive(0, 0);
+ m_drive->ResetEncoders();
+}
+
+void TurnDegrees::Execute() {
+ m_drive->ArcadeDrive(0, m_speed);
+}
+
+void TurnDegrees::End(bool interrupted) {
+ m_drive->ArcadeDrive(0, 0);
+}
+
+bool TurnDegrees::IsFinished() {
+ // Need to convert distance travelled to degrees. The Standard Romi Chassis
+ // found here https://www.pololu.com/category/203/romi-chassis-kits, has a
+ // wheel placement diameter (149 mm) - width of the wheel (8 mm) = 141 mm
+ // or 5.551 inches. We then take into consideration the width of the tires.
+ static auto inchPerDegree = (5.551_in * wpi::numbers::pi) / 360_deg;
+
+ // Compare distance traveled from start to distance based on degree turn.
+ return GetAverageTurningDistance() >= inchPerDegree * m_angle;
+}
+
+units::meter_t TurnDegrees::GetAverageTurningDistance() {
+ auto l = units::math::abs(m_drive->GetLeftDistance());
+ auto r = units::math::abs(m_drive->GetRightDistance());
+ return (l + r) / 2;
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnTime.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnTime.cpp
new file mode 100644
index 0000000..80c4bd2
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnTime.cpp
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "commands/TurnTime.h"
+
+void TurnTime::Initialize() {
+ m_timer.Start();
+ m_drive->ArcadeDrive(0, 0);
+}
+
+void TurnTime::Execute() {
+ m_drive->ArcadeDrive(0, m_speed);
+}
+
+void TurnTime::End(bool interrupted) {
+ m_drive->ArcadeDrive(0, 0);
+ m_timer.Stop();
+ m_timer.Reset();
+}
+
+bool TurnTime::IsFinished() {
+ return m_timer.HasElapsed(m_duration);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp
new file mode 100644
index 0000000..08a537b
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/sensors/RomiGyro.cpp
@@ -0,0 +1,79 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "sensors/RomiGyro.h"
+
+RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") {
+ if (m_simDevice) {
+ m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true);
+ m_simRateX =
+ m_simDevice.CreateDouble("rate_x", hal::SimDevice::kInput, 0.0);
+ m_simRateY =
+ m_simDevice.CreateDouble("rate_y", hal::SimDevice::kInput, 0.0);
+ m_simRateZ =
+ m_simDevice.CreateDouble("rate_z", hal::SimDevice::kInput, 0.0);
+ m_simAngleX =
+ m_simDevice.CreateDouble("angle_x", hal::SimDevice::kInput, 0.0);
+ m_simAngleY =
+ m_simDevice.CreateDouble("angle_y", hal::SimDevice::kInput, 0.0);
+ m_simAngleZ =
+ m_simDevice.CreateDouble("angle_z", hal::SimDevice::kInput, 0.0);
+ }
+}
+
+double RomiGyro::GetRateX() {
+ if (m_simRateX) {
+ return m_simRateX.Get();
+ }
+
+ return 0.0;
+}
+
+double RomiGyro::GetRateY() {
+ if (m_simRateY) {
+ return m_simRateY.Get();
+ }
+
+ return 0.0;
+}
+
+double RomiGyro::GetRateZ() {
+ if (m_simRateZ) {
+ return m_simRateZ.Get();
+ }
+
+ return 0.0;
+}
+
+double RomiGyro::GetAngleX() {
+ if (m_simAngleX) {
+ return m_simAngleX.Get() - m_angleXOffset;
+ }
+
+ return 0.0;
+}
+
+double RomiGyro::GetAngleY() {
+ if (m_simAngleY) {
+ return m_simAngleY.Get() - m_angleYOffset;
+ }
+
+ return 0.0;
+}
+
+double RomiGyro::GetAngleZ() {
+ if (m_simAngleZ) {
+ return m_simAngleZ.Get() - m_angleZOffset;
+ }
+
+ return 0.0;
+}
+
+void RomiGyro::Reset() {
+ if (m_simAngleX) {
+ m_angleXOffset = m_simAngleX.Get();
+ m_angleYOffset = m_simAngleY.Get();
+ m_angleZOffset = m_simAngleZ.Get();
+ }
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp
new file mode 100644
index 0000000..13ec2d8
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp
@@ -0,0 +1,89 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/Drivetrain.h"
+
+#include <wpi/numbers>
+
+#include "Constants.h"
+
+using namespace DriveConstants;
+
+// The Romi has the left and right motors set to
+// PWM channels 0 and 1 respectively
+// The Romi has onboard encoders that are hardcoded
+// to use DIO pins 4/5 and 6/7 for the left and right
+Drivetrain::Drivetrain() {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotor.SetInverted(true);
+
+ m_leftEncoder.SetDistancePerPulse(wpi::numbers::pi * kWheelDiameter.value() /
+ kCountsPerRevolution);
+ m_rightEncoder.SetDistancePerPulse(wpi::numbers::pi * kWheelDiameter.value() /
+ kCountsPerRevolution);
+ ResetEncoders();
+}
+
+void Drivetrain::Periodic() {
+ // This method will be called once per scheduler run.
+}
+
+void Drivetrain::ArcadeDrive(double xaxisSpeed, double zaxisRotate) {
+ m_drive.ArcadeDrive(xaxisSpeed, zaxisRotate);
+}
+
+void Drivetrain::ResetEncoders() {
+ m_leftEncoder.Reset();
+ m_rightEncoder.Reset();
+}
+
+int Drivetrain::GetLeftEncoderCount() {
+ return m_leftEncoder.Get();
+}
+
+int Drivetrain::GetRightEncoderCount() {
+ return m_rightEncoder.Get();
+}
+
+units::meter_t Drivetrain::GetLeftDistance() {
+ return units::meter_t(m_leftEncoder.GetDistance());
+}
+
+units::meter_t Drivetrain::GetRightDistance() {
+ return units::meter_t(m_rightEncoder.GetDistance());
+}
+
+units::meter_t Drivetrain::GetAverageDistance() {
+ return (GetLeftDistance() + GetRightDistance()) / 2.0;
+}
+
+double Drivetrain::GetAccelX() {
+ return m_accelerometer.GetX();
+}
+
+double Drivetrain::GetAccelY() {
+ return m_accelerometer.GetY();
+}
+
+double Drivetrain::GetAccelZ() {
+ return m_accelerometer.GetZ();
+}
+
+double Drivetrain::GetGyroAngleX() {
+ return m_gyro.GetAngleX();
+}
+
+double Drivetrain::GetGyroAngleY() {
+ return m_gyro.GetAngleY();
+}
+
+double Drivetrain::GetGyroAngleZ() {
+ return m_gyro.GetAngleZ();
+}
+
+void Drivetrain::ResetGyro() {
+ m_gyro.Reset();
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/OnBoardIO.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/OnBoardIO.cpp
new file mode 100644
index 0000000..b178ec0
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/OnBoardIO.cpp
@@ -0,0 +1,80 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "subsystems/OnBoardIO.h"
+
+#include <frc/DigitalInput.h>
+#include <frc/DigitalOutput.h>
+#include <frc/Errors.h>
+#include <frc/Timer.h>
+
+OnBoardIO::OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2) {
+ if (dio1 == ChannelMode::INPUT) {
+ m_buttonB = std::make_unique<frc::DigitalInput>(1);
+ } else {
+ m_greenLed = std::make_unique<frc::DigitalOutput>(1);
+ }
+ if (dio2 == ChannelMode::INPUT) {
+ m_buttonC = std::make_unique<frc::DigitalInput>(2);
+ m_redLed = std::make_unique<frc::DigitalOutput>(2);
+ }
+}
+
+bool OnBoardIO::GetButtonAPressed() {
+ return m_buttonA.Get();
+}
+
+bool OnBoardIO::GetButtonBPressed() {
+ if (m_buttonB) {
+ return m_buttonB->Get();
+ }
+
+ auto currentTime = frc::Timer::GetFPGATimestamp();
+ if (currentTime > m_nextMessageTime) {
+ FRC_ReportError(frc::err::Error, "Button {} was not configured", "B");
+ m_nextMessageTime = currentTime + kMessageInterval;
+ }
+ return false;
+}
+
+bool OnBoardIO::GetButtonCPressed() {
+ if (m_buttonC) {
+ return m_buttonC->Get();
+ }
+
+ auto currentTime = frc::Timer::GetFPGATimestamp();
+ if (currentTime > m_nextMessageTime) {
+ FRC_ReportError(frc::err::Error, "Button {} was not configured", "C");
+ m_nextMessageTime = currentTime + kMessageInterval;
+ }
+ return false;
+}
+
+void OnBoardIO::SetGreenLed(bool value) {
+ if (m_greenLed) {
+ m_greenLed->Set(value);
+ } else {
+ auto currentTime = frc::Timer::GetFPGATimestamp();
+ if (currentTime > m_nextMessageTime) {
+ FRC_ReportError(frc::err::Error, "{} LED was not configured", "Green");
+ m_nextMessageTime = currentTime + kMessageInterval;
+ }
+ }
+}
+
+void OnBoardIO::SetRedLed(bool value) {
+ if (m_redLed) {
+ m_redLed->Set(value);
+ } else {
+ auto currentTime = frc::Timer::GetFPGATimestamp();
+ if (currentTime > m_nextMessageTime) {
+ FRC_ReportError(frc::err::Error, "{} LED was not configured", "Red");
+ m_nextMessageTime = currentTime + kMessageInterval;
+ }
+ }
+}
+
+void OnBoardIO::SetYellowLed(bool value) {
+ m_yellowLed.Set(value);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Constants.h
new file mode 100644
index 0000000..e5cee33
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Constants.h
@@ -0,0 +1,19 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+/**
+ * The Constants header provides a convenient place for teams to hold robot-wide
+ * numerical or bool constants. This should not be used for any other purpose.
+ *
+ * It is generally a good idea to place constants into subsystem- or
+ * command-specific namespaces within this header, which can then be used where
+ * they are needed.
+ */
+
+namespace DriveConstants {
+constexpr double kCountsPerRevolution = 1440.0;
+constexpr double kWheelDiameterInch = 2.75;
+} // namespace DriveConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Robot.h
new file mode 100644
index 0000000..eb35fab
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Robot.h
@@ -0,0 +1,29 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/TimedRobot.h>
+#include <frc2/command/Command.h>
+
+#include "RobotContainer.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void RobotInit() override;
+ void RobotPeriodic() override;
+ void DisabledInit() override;
+ void DisabledPeriodic() override;
+ void AutonomousInit() override;
+ void AutonomousPeriodic() override;
+ void TeleopInit() override;
+ void TeleopPeriodic() override;
+ void TestPeriodic() override;
+
+ private:
+ // Have it null by default so that if testing teleop it
+ // doesn't have undefined behavior and potentially crash.
+ frc2::Command* m_autonomousCommand = nullptr;
+ RobotContainer m_container;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h
new file mode 100644
index 0000000..821542c
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.h
@@ -0,0 +1,61 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/Joystick.h>
+#include <frc/smartdashboard/SendableChooser.h>
+#include <frc2/command/Command.h>
+#include <frc2/command/button/Button.h>
+
+#include "Constants.h"
+#include "commands/AutonomousDistance.h"
+#include "commands/AutonomousTime.h"
+#include "subsystems/Drivetrain.h"
+#include "subsystems/OnBoardIO.h"
+
+/**
+ * This class is where the bulk of the robot should be declared. Since
+ * Command-based is a "declarative" paradigm, very little robot logic should
+ * actually be handled in the {@link Robot} periodic methods (other than the
+ * scheduler calls). Instead, the structure of the robot (including subsystems,
+ * commands, and button mappings) should be declared here.
+ */
+class RobotContainer {
+ // NOTE: The I/O pin functionality of the 5 exposed I/O pins depends on the
+ // hardware "overlay"
+ // that is specified when launching the wpilib-ws server on the Romi raspberry
+ // pi. By default, the following are available (listed in order from inside of
+ // the board to outside):
+ // - DIO 8 (mapped to Arduino pin 11, closest to the inside of the board)
+ // - Analog In 0 (mapped to Analog Channel 6 / Arduino Pin 4)
+ // - Analog In 1 (mapped to Analog Channel 2 / Arduino Pin 20)
+ // - PWM 2 (mapped to Arduino Pin 21)
+ // - PWM 3 (mapped to Arduino Pin 22)
+ //
+ // Your subsystem configuration should take the overlays into account
+ public:
+ RobotContainer();
+ frc2::Command* GetAutonomousCommand();
+
+ private:
+ // Assumes a gamepad plugged into channnel 0
+ frc::Joystick m_controller{0};
+ frc::SendableChooser<frc2::Command*> m_chooser;
+
+ // The robot's subsystems
+ Drivetrain m_drive;
+ OnBoardIO m_onboardIO{OnBoardIO::ChannelMode::INPUT,
+ OnBoardIO::ChannelMode::INPUT};
+
+ // Example button
+ frc2::Button m_onboardButtonA{
+ [this] { return m_onboardIO.GetButtonAPressed(); }};
+
+ // Autonomous commands.
+ AutonomousDistance m_autoDistance{&m_drive};
+ AutonomousTime m_autoTime{&m_drive};
+
+ void ConfigureButtonBindings();
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/AutonomousDistance.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/AutonomousDistance.h
new file mode 100644
index 0000000..8991ce6
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/AutonomousDistance.h
@@ -0,0 +1,23 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandHelper.h>
+#include <frc2/command/SequentialCommandGroup.h>
+
+#include "commands/DriveDistance.h"
+#include "commands/TurnDegrees.h"
+#include "subsystems/Drivetrain.h"
+
+class AutonomousDistance
+ : public frc2::CommandHelper<frc2::SequentialCommandGroup,
+ AutonomousDistance> {
+ public:
+ explicit AutonomousDistance(Drivetrain* drive) {
+ AddCommands(
+ DriveDistance(-0.5, 10_in, drive), TurnDegrees(-0.5, 180_deg, drive),
+ DriveDistance(-0.5, 10_in, drive), TurnDegrees(0.5, 180_deg, drive));
+ }
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/AutonomousTime.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/AutonomousTime.h
new file mode 100644
index 0000000..e25e5ea
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/AutonomousTime.h
@@ -0,0 +1,21 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandHelper.h>
+#include <frc2/command/SequentialCommandGroup.h>
+
+#include "commands/DriveTime.h"
+#include "commands/TurnTime.h"
+#include "subsystems/Drivetrain.h"
+
+class AutonomousTime
+ : public frc2::CommandHelper<frc2::SequentialCommandGroup, AutonomousTime> {
+ public:
+ explicit AutonomousTime(Drivetrain* drive) {
+ AddCommands(DriveTime(-0.6, 2_s, drive), TurnTime(-0.5, 1.3_s, drive),
+ DriveTime(-0.6, 2_s, drive), TurnTime(0.5, 1.3_s, drive));
+ }
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.h
new file mode 100644
index 0000000..34a1e93
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.h
@@ -0,0 +1,30 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandBase.h>
+#include <frc2/command/CommandHelper.h>
+#include <units/length.h>
+
+#include "subsystems/Drivetrain.h"
+
+class DriveDistance
+ : public frc2::CommandHelper<frc2::CommandBase, DriveDistance> {
+ public:
+ DriveDistance(double speed, units::meter_t distance, Drivetrain* drive)
+ : m_speed(speed), m_distance(distance), m_drive(drive) {
+ AddRequirements({m_drive});
+ }
+
+ void Initialize() override;
+ void Execute() override;
+ void End(bool interrupted) override;
+ bool IsFinished() override;
+
+ private:
+ double m_speed;
+ units::meter_t m_distance;
+ Drivetrain* m_drive;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.h
new file mode 100644
index 0000000..a0135e5
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.h
@@ -0,0 +1,31 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/Timer.h>
+#include <frc2/command/CommandBase.h>
+#include <frc2/command/CommandHelper.h>
+#include <units/time.h>
+
+#include "subsystems/Drivetrain.h"
+
+class DriveTime : public frc2::CommandHelper<frc2::CommandBase, DriveTime> {
+ public:
+ DriveTime(double speed, units::second_t time, Drivetrain* drive)
+ : m_speed(speed), m_duration(time), m_drive(drive) {
+ AddRequirements({m_drive});
+ }
+
+ void Initialize() override;
+ void Execute() override;
+ void End(bool interrupted) override;
+ bool IsFinished() override;
+
+ private:
+ double m_speed;
+ units::second_t m_duration;
+ Drivetrain* m_drive;
+ frc::Timer m_timer;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TeleopArcadeDrive.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TeleopArcadeDrive.h
new file mode 100644
index 0000000..859b6b7
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TeleopArcadeDrive.h
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandBase.h>
+#include <frc2/command/CommandHelper.h>
+
+#include "subsystems/Drivetrain.h"
+
+class TeleopArcadeDrive
+ : public frc2::CommandHelper<frc2::CommandBase, TeleopArcadeDrive> {
+ public:
+ TeleopArcadeDrive(Drivetrain* subsystem,
+ std::function<double()> xaxisSpeedSupplier,
+ std::function<double()> zaxisRotateSupplier);
+ void Execute() override;
+
+ private:
+ Drivetrain* m_drive;
+ std::function<double()> m_xaxisSpeedSupplier;
+ std::function<double()> m_zaxisRotateSupplier;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.h
new file mode 100644
index 0000000..7ce65df
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.h
@@ -0,0 +1,32 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc2/command/CommandBase.h>
+#include <frc2/command/CommandHelper.h>
+#include <units/angle.h>
+#include <units/length.h>
+
+#include "subsystems/Drivetrain.h"
+
+class TurnDegrees : public frc2::CommandHelper<frc2::CommandBase, TurnDegrees> {
+ public:
+ TurnDegrees(double speed, units::degree_t angle, Drivetrain* drive)
+ : m_speed(speed), m_angle(angle), m_drive(drive) {
+ AddRequirements({m_drive});
+ }
+
+ void Initialize() override;
+ void Execute() override;
+ void End(bool interrupted) override;
+ bool IsFinished() override;
+
+ private:
+ double m_speed;
+ units::degree_t m_angle;
+ Drivetrain* m_drive;
+
+ units::meter_t GetAverageTurningDistance();
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.h
new file mode 100644
index 0000000..395825d
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.h
@@ -0,0 +1,31 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/Timer.h>
+#include <frc2/command/CommandBase.h>
+#include <frc2/command/CommandHelper.h>
+#include <units/time.h>
+
+#include "subsystems/Drivetrain.h"
+
+class TurnTime : public frc2::CommandHelper<frc2::CommandBase, TurnTime> {
+ public:
+ TurnTime(double speed, units::second_t time, Drivetrain* drive)
+ : m_speed(speed), m_duration(time), m_drive(drive) {
+ AddRequirements({m_drive});
+ }
+
+ void Initialize() override;
+ void Execute() override;
+ void End(bool interrupted) override;
+ bool IsFinished() override;
+
+ private:
+ double m_speed;
+ units::second_t m_duration;
+ Drivetrain* m_drive;
+ frc::Timer m_timer;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h
new file mode 100644
index 0000000..0e93d48
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/sensors/RomiGyro.h
@@ -0,0 +1,60 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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 <hal/SimDevice.h>
+
+class RomiGyro {
+ public:
+ RomiGyro();
+
+ /**
+ * Gets the rate of turn in degrees-per-second around the X-axis
+ */
+ double GetRateX();
+
+ /**
+ * Gets the rate of turn in degrees-per-second around the Y-axis
+ */
+ double GetRateY();
+
+ /**
+ * Gets the rate of turn in degrees-per-second around the Z-axis
+ */
+ double GetRateZ();
+
+ /**
+ * Gets the currently reported angle around the X-axis
+ */
+ double GetAngleX();
+
+ /**
+ * Gets the currently reported angle around the X-axis
+ */
+ double GetAngleY();
+
+ /**
+ * Gets the currently reported angle around the X-axis
+ */
+ double GetAngleZ();
+
+ /**
+ * Resets the gyro
+ */
+ void Reset();
+
+ private:
+ hal::SimDevice m_simDevice;
+ hal::SimDouble m_simRateX;
+ hal::SimDouble m_simRateY;
+ hal::SimDouble m_simRateZ;
+ hal::SimDouble m_simAngleX;
+ hal::SimDouble m_simAngleY;
+ hal::SimDouble m_simAngleZ;
+
+ double m_angleXOffset = 0;
+ double m_angleYOffset = 0;
+ double m_angleZOffset = 0;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h
new file mode 100644
index 0000000..98ae957
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h
@@ -0,0 +1,122 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/BuiltInAccelerometer.h>
+#include <frc/Encoder.h>
+#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/Spark.h>
+#include <frc2/command/SubsystemBase.h>
+#include <units/length.h>
+
+#include "sensors/RomiGyro.h"
+
+class Drivetrain : public frc2::SubsystemBase {
+ public:
+ static constexpr double kCountsPerRevolution = 1440.0;
+ static constexpr units::meter_t kWheelDiameter = 70_mm;
+
+ Drivetrain();
+
+ /**
+ * Will be called periodically whenever the CommandScheduler runs.
+ */
+ void Periodic() override;
+
+ /**
+ * Drives the robot using arcade controls.
+ *
+ * @param xaxisSpeed the commanded forward movement
+ * @param zaxisRotate the commanded rotation
+ */
+ void ArcadeDrive(double xaxisSpeed, double zaxisRotate);
+
+ /**
+ * Resets the drive encoders to currently read a position of 0.
+ */
+ void ResetEncoders();
+
+ /**
+ * Gets the left drive encoder count.
+ *
+ * @return the left drive encoder count
+ */
+ int GetLeftEncoderCount();
+
+ /**
+ * Gets the right drive encoder count.
+ *
+ * @return the right drive encoder count
+ */
+ int GetRightEncoderCount();
+
+ /**
+ * Gets the left distance driven.
+ *
+ * @return the left-side distance driven
+ */
+ units::meter_t GetLeftDistance();
+
+ /**
+ * Gets the right distance driven.
+ *
+ * @return the right-side distance driven
+ */
+ units::meter_t GetRightDistance();
+
+ /**
+ * Returns the average distance traveled by the left and right encoders.
+ *
+ * @return The average distance traveled by the left and right encoders.
+ */
+ units::meter_t GetAverageDistance();
+
+ /**
+ * Returns the acceleration along the X-axis, in Gs.
+ */
+ double GetAccelX();
+
+ /**
+ * Returns the acceleration along the Y-axis, in Gs.
+ */
+ double GetAccelY();
+
+ /**
+ * Returns the acceleration along the Z-axis, in Gs.
+ */
+ double GetAccelZ();
+
+ /**
+ * Returns the current angle of the Romi around the X-axis, in degrees.
+ */
+ double GetGyroAngleX();
+
+ /**
+ * Returns the current angle of the Romi around the Y-axis, in degrees.
+ */
+ double GetGyroAngleY();
+
+ /**
+ * Returns the current angle of the Romi around the Z-axis, in degrees.
+ */
+ double GetGyroAngleZ();
+
+ /**
+ * Reset the gyro.
+ */
+ void ResetGyro();
+
+ private:
+ frc::Spark m_leftMotor{0};
+ frc::Spark m_rightMotor{1};
+
+ frc::Encoder m_leftEncoder{4, 5};
+ frc::Encoder m_rightEncoder{6, 7};
+
+ frc::DifferentialDrive m_drive{m_leftMotor, m_rightMotor};
+
+ RomiGyro m_gyro;
+ frc::BuiltInAccelerometer m_accelerometer;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/OnBoardIO.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/OnBoardIO.h
new file mode 100644
index 0000000..0bb5225
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/OnBoardIO.h
@@ -0,0 +1,72 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <memory>
+
+#include <frc/DigitalInput.h>
+#include <frc/DigitalOutput.h>
+#include <frc2/command/SubsystemBase.h>
+
+/**
+ * This class represents the onboard IO of the Romi
+ * reference robot. This includes the pushbuttons and
+ * LEDs.
+ *
+ * <p>DIO 0 - Button A (input only)
+ * DIO 1 - Button B (input) or Green LED (output)
+ * DIO 2 - Button C (input) or Red LED (output)
+ * DIO 3 - Yellow LED (output only)
+ */
+class OnBoardIO : public frc2::SubsystemBase {
+ public:
+ enum ChannelMode { INPUT, OUTPUT };
+ OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2);
+
+ static constexpr auto kMessageInterval = 1_s;
+ units::second_t m_nextMessageTime = 0_s;
+
+ /**
+ * Gets if the A button is pressed.
+ */
+ bool GetButtonAPressed();
+
+ /**
+ * Gets if the B button is pressed.
+ */
+ bool GetButtonBPressed();
+
+ /**
+ * Gets if the C button is pressed.
+ */
+ bool GetButtonCPressed();
+
+ /**
+ * Sets the green LED.
+ */
+ void SetGreenLed(bool value);
+
+ /**
+ * Sets the red LED.
+ */
+ void SetRedLed(bool value);
+
+ /**
+ * Sets the yellow LED.
+ */
+ void SetYellowLed(bool value);
+
+ private:
+ frc::DigitalInput m_buttonA{0};
+ frc::DigitalOutput m_yellowLed{3};
+
+ // DIO 1
+ std::unique_ptr<frc::DigitalInput> m_buttonB;
+ std::unique_ptr<frc::DigitalOutput> m_greenLed;
+
+ // DIO 2
+ std::unique_ptr<frc::DigitalInput> m_buttonC;
+ std::unique_ptr<frc::DigitalOutput> m_redLed;
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp
index dbc9d2a..0c2e79c 100644
--- a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
@@ -48,12 +45,15 @@
// Configure your button bindings here
// Run instant command 1 when the 'A' button is pressed
- frc2::JoystickButton(&m_driverController, 0).WhenPressed(&m_instantCommand1);
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA)
+ .WhenPressed(&m_instantCommand1);
// Run instant command 2 when the 'X' button is pressed
- frc2::JoystickButton(&m_driverController, 3).WhenPressed(&m_instantCommand2);
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kX)
+ .WhenPressed(&m_instantCommand2);
// Run instant command 3 when the 'Y' button is held; release early to
// interrupt
- frc2::JoystickButton(&m_driverController, 4).WhenHeld(&m_waitCommand);
+ frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kY)
+ .WhenHeld(&m_waitCommand);
}
frc2::Command* RobotContainer::GetAutonomousCommand() {
diff --git a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Constants.h
index 9fb2281..ae5d02d 100644
--- a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -18,5 +15,5 @@
*/
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h
index 6e3f321..715b9c5 100644
--- a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp
index b06845e..573fcac 100644
--- a/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Constants.h
index 9fb2281..ae5d02d 100644
--- a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -18,5 +15,5 @@
*/
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h
index c93e320..40eea33 100644
--- a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp
index 3447504..a114b92 100644
--- a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/AnalogPotentiometer.h>
#include <frc/Encoder.h>
#include <frc/Joystick.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/shuffleboard/Shuffleboard.h>
#include <frc/shuffleboard/ShuffleboardLayout.h>
#include <frc/shuffleboard/ShuffleboardTab.h>
@@ -64,9 +61,9 @@
}
private:
- frc::PWMVictorSPX m_left{0};
- frc::PWMVictorSPX m_right{1};
- frc::PWMVictorSPX m_elevatorMotor{2};
+ frc::PWMSparkMax m_left{0};
+ frc::PWMSparkMax m_right{1};
+ frc::PWMSparkMax m_elevatorMotor{2};
frc::DifferentialDrive m_robotDrive{m_left, m_right};
@@ -80,5 +77,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp
new file mode 100644
index 0000000..05d99f3
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp
@@ -0,0 +1,61 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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 "Drivetrain.h"
+
+#include <frc/RobotController.h>
+
+void Drivetrain::SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds) {
+ auto leftFeedforward = m_feedforward.Calculate(speeds.left);
+ auto rightFeedforward = m_feedforward.Calculate(speeds.right);
+ double leftOutput = m_leftPIDController.Calculate(m_leftEncoder.GetRate(),
+ speeds.left.value());
+ double rightOutput = m_rightPIDController.Calculate(m_rightEncoder.GetRate(),
+ speeds.right.value());
+
+ m_leftGroup.SetVoltage(units::volt_t{leftOutput} + leftFeedforward);
+ m_rightGroup.SetVoltage(units::volt_t{rightOutput} + rightFeedforward);
+}
+
+void Drivetrain::Drive(units::meters_per_second_t xSpeed,
+ units::radians_per_second_t rot) {
+ SetSpeeds(m_kinematics.ToWheelSpeeds({xSpeed, 0_mps, rot}));
+}
+
+void Drivetrain::UpdateOdometry() {
+ m_odometry.Update(m_gyro.GetRotation2d(),
+ units::meter_t(m_leftEncoder.GetDistance()),
+ units::meter_t(m_rightEncoder.GetDistance()));
+}
+
+void Drivetrain::ResetOdometry(const frc::Pose2d& pose) {
+ m_leftEncoder.Reset();
+ m_rightEncoder.Reset();
+ m_drivetrainSimulator.SetPose(pose);
+ m_odometry.ResetPosition(pose, m_gyro.GetRotation2d());
+}
+
+void Drivetrain::SimulationPeriodic() {
+ // To update our simulation, we set motor voltage inputs, update the
+ // simulation, and write the simulated positions and velocities to our
+ // simulated encoder and gyro. We negate the right side so that positive
+ // voltages make the right side move forward.
+ m_drivetrainSimulator.SetInputs(units::volt_t{m_leftLeader.Get()} *
+ frc::RobotController::GetInputVoltage(),
+ units::volt_t{-m_rightLeader.Get()} *
+ frc::RobotController::GetInputVoltage());
+ m_drivetrainSimulator.Update(20_ms);
+
+ m_leftEncoderSim.SetDistance(m_drivetrainSimulator.GetLeftPosition().value());
+ m_leftEncoderSim.SetRate(m_drivetrainSimulator.GetLeftVelocity().value());
+ m_rightEncoderSim.SetDistance(
+ m_drivetrainSimulator.GetRightPosition().value());
+ m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetRightVelocity().value());
+ m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value());
+}
+
+void Drivetrain::Periodic() {
+ UpdateOdometry();
+ m_fieldSim.SetRobotPose(m_odometry.GetPose());
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp
new file mode 100644
index 0000000..a6eeef4
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp
@@ -0,0 +1,77 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/TimedRobot.h>
+#include <frc/Timer.h>
+#include <frc/XboxController.h>
+#include <frc/controller/RamseteController.h>
+#include <frc/filter/SlewRateLimiter.h>
+#include <frc/trajectory/TrajectoryGenerator.h>
+
+#include "Drivetrain.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void RobotInit() override {
+ // Flush NetworkTables every loop. This ensures that robot pose and other
+ // values are sent during every iteration.
+ SetNetworkTablesFlushEnabled(true);
+
+ m_trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
+ frc::Pose2d(2_m, 2_m, 0_rad), {}, frc::Pose2d(6_m, 4_m, 0_rad),
+ frc::TrajectoryConfig(2_mps, 2_mps_sq));
+ }
+
+ void RobotPeriodic() override { m_drive.Periodic(); }
+
+ void AutonomousInit() override {
+ m_timer.Reset();
+ m_timer.Start();
+ m_drive.ResetOdometry(m_trajectory.InitialPose());
+ }
+
+ void AutonomousPeriodic() override {
+ auto elapsed = m_timer.Get();
+ auto reference = m_trajectory.Sample(elapsed);
+ auto speeds = m_ramsete.Calculate(m_drive.GetPose(), reference);
+ m_drive.Drive(speeds.vx, speeds.omega);
+ }
+
+ void TeleopPeriodic() override {
+ // Get the x speed. We are inverting this because Xbox controllers return
+ // negative values when we push forward.
+ const auto xSpeed = -m_speedLimiter.Calculate(m_controller.GetLeftY()) *
+ Drivetrain::kMaxSpeed;
+
+ // Get the rate of angular rotation. We are inverting this because we want a
+ // positive value when we pull to the left (remember, CCW is positive in
+ // mathematics). Xbox controllers return positive values when you pull to
+ // the right by default.
+ auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
+ Drivetrain::kMaxAngularSpeed;
+
+ m_drive.Drive(xSpeed, rot);
+ }
+
+ void SimulationPeriodic() override { m_drive.SimulationPeriodic(); }
+
+ private:
+ frc::XboxController m_controller{0};
+
+ // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0
+ // to 1.
+ frc::SlewRateLimiter<units::scalar> m_speedLimiter{3 / 1_s};
+ frc::SlewRateLimiter<units::scalar> m_rotLimiter{3 / 1_s};
+
+ Drivetrain m_drive;
+ frc::Trajectory m_trajectory;
+ frc::RamseteController m_ramsete;
+ frc::Timer m_timer;
+};
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h
new file mode 100644
index 0000000..d8c58c2
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h
@@ -0,0 +1,110 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/AnalogGyro.h>
+#include <frc/Encoder.h>
+#include <frc/controller/PIDController.h>
+#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/kinematics/DifferentialDriveKinematics.h>
+#include <frc/kinematics/DifferentialDriveOdometry.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc/simulation/AnalogGyroSim.h>
+#include <frc/simulation/DifferentialDrivetrainSim.h>
+#include <frc/simulation/EncoderSim.h>
+#include <frc/smartdashboard/Field2d.h>
+#include <frc/smartdashboard/SmartDashboard.h>
+#include <frc/system/plant/LinearSystemId.h>
+#include <units/angle.h>
+#include <units/angular_velocity.h>
+#include <units/length.h>
+#include <units/velocity.h>
+#include <wpi/numbers>
+
+/**
+ * Represents a differential drive style drivetrain.
+ */
+class Drivetrain {
+ public:
+ Drivetrain() {
+ m_gyro.Reset();
+
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightGroup.SetInverted(true);
+
+ // Set the distance per pulse for the drive encoders. We can simply use the
+ // distance traveled for one rotation of the wheel divided by the encoder
+ // resolution.
+ m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ kEncoderResolution);
+ m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
+ kEncoderResolution);
+
+ m_leftEncoder.Reset();
+ m_rightEncoder.Reset();
+
+ m_rightGroup.SetInverted(true);
+
+ frc::SmartDashboard::PutData("Field", &m_fieldSim);
+ }
+
+ static constexpr units::meters_per_second_t kMaxSpeed =
+ 3.0_mps; // 3 meters per second
+ static constexpr units::radians_per_second_t kMaxAngularSpeed{
+ wpi::numbers::pi}; // 1/2 rotation per second
+
+ void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
+ void Drive(units::meters_per_second_t xSpeed,
+ units::radians_per_second_t rot);
+ void UpdateOdometry();
+ void ResetOdometry(const frc::Pose2d& pose);
+
+ frc::Pose2d GetPose() const { return m_odometry.GetPose(); }
+
+ void SimulationPeriodic();
+ void Periodic();
+
+ private:
+ static constexpr units::meter_t kTrackWidth = 0.381_m * 2;
+ static constexpr double kWheelRadius = 0.0508; // meters
+ static constexpr int kEncoderResolution = 4096;
+
+ frc::PWMSparkMax m_leftLeader{1};
+ frc::PWMSparkMax m_leftFollower{2};
+ frc::PWMSparkMax m_rightLeader{3};
+ frc::PWMSparkMax m_rightFollower{4};
+
+ frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower};
+ frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower};
+
+ frc::Encoder m_leftEncoder{0, 1};
+ frc::Encoder m_rightEncoder{2, 3};
+
+ frc2::PIDController m_leftPIDController{8.5, 0.0, 0.0};
+ frc2::PIDController m_rightPIDController{8.5, 0.0, 0.0};
+
+ frc::AnalogGyro m_gyro{0};
+
+ frc::DifferentialDriveKinematics m_kinematics{kTrackWidth};
+ frc::DifferentialDriveOdometry m_odometry{m_gyro.GetRotation2d()};
+
+ // Gains are for example purposes only - must be determined for your own
+ // robot!
+ frc::SimpleMotorFeedforward<units::meters> m_feedforward{1_V, 3_V / 1_mps};
+
+ // Simulation classes help us simulate our robot
+ frc::sim::AnalogGyroSim m_gyroSim{m_gyro};
+ frc::sim::EncoderSim m_leftEncoderSim{m_leftEncoder};
+ frc::sim::EncoderSim m_rightEncoderSim{m_rightEncoder};
+ frc::Field2d m_fieldSim;
+ frc::LinearSystem<2, 2, 2> m_drivetrainSystem =
+ frc::LinearSystemId::IdentifyDrivetrainSystem(
+ 1.98_V / 1_mps, 0.2_V / 1_mps_sq, 1.5_V / 1_mps, 0.3_V / 1_mps_sq);
+ frc::sim::DifferentialDrivetrainSim m_drivetrainSimulator{
+ m_drivetrainSystem, kTrackWidth, frc::DCMotor::CIM(2), 8, 2_in};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp
index 523a227..82e481b 100644
--- a/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp
@@ -1,12 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* 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 <frc/DoubleSolenoid.h>
#include <frc/Joystick.h>
+#include <frc/PneumaticsControlModule.h>
#include <frc/Solenoid.h>
#include <frc/TimedRobot.h>
@@ -57,10 +55,11 @@
frc::Joystick m_stick{0};
// Solenoid corresponds to a single solenoid.
- frc::Solenoid m_solenoid{0};
+ frc::Solenoid m_solenoid{frc::PneumaticsModuleType::CTREPCM, 0};
// DoubleSolenoid corresponds to a double solenoid.
- frc::DoubleSolenoid m_doubleSolenoid{1, 2};
+ frc::DoubleSolenoid m_doubleSolenoid{frc::PneumaticsModuleType::CTREPCM, 1,
+ 2};
static constexpr int kSolenoidButton = 1;
static constexpr int kDoubleSolenoidForward = 2;
@@ -68,5 +67,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp
index 5efe04c..0f03d37 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp
@@ -1,27 +1,22 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
-#include <frc/GenericHID.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/StateSpaceUtil.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/controller/LinearPlantInversionFeedforward.h>
#include <frc/controller/LinearQuadraticRegulator.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/estimator/KalmanFilter.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/system/LinearSystemLoop.h>
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/angle.h>
#include <units/moment_of_inertia.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -69,7 +64,8 @@
// qelms. Velocity error tolerance, in radians and radians per second.
// Decrease this to more heavily penalize state excursion, or make the
// controller behave more aggressively.
- {1.0 * 2.0 * wpi::math::pi / 360.0, 10.0 * 2.0 * wpi::math::pi / 360.0},
+ {1.0 * 2.0 * wpi::numbers::pi / 360.0,
+ 10.0 * 2.0 * wpi::numbers::pi / 360.0},
// relms. Control effort (voltage) tolerance. Decrease this to more
// heavily penalize control effort, or make the controller less
// aggressive. 12 is a good starting point because that is the
@@ -87,7 +83,7 @@
// An encoder set up to measure arm position in radians per second.
frc::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel};
- frc::PWMVictorSPX m_motor{kMotorPort};
+ frc::PWMSparkMax m_motor{kMotorPort};
frc::XboxController m_joystick{kJoystickPort};
frc::TrapezoidProfile<units::radians>::Constraints m_constraints{
@@ -96,25 +92,25 @@
frc::TrapezoidProfile<units::radians>::State m_lastProfiledReference;
public:
- void RobotInit() {
+ void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
- m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi / 4096.0);
+ m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
}
- void TeleopInit() {
+ void TeleopInit() override {
m_loop.Reset(
- frc::MakeMatrix<2, 1>(m_encoder.GetDistance(), m_encoder.GetRate()));
+ Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
m_lastProfiledReference = {
units::radian_t(m_encoder.GetDistance()),
units::radians_per_second_t(m_encoder.GetRate())};
}
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
// Sets the target position of our arm. This is similar to setting the
// setpoint of a PID controller.
frc::TrapezoidProfile<units::radians>::State goal;
- if (m_joystick.GetBumper(frc::GenericHID::kRightHand)) {
+ if (m_joystick.GetRightBumper()) {
// We pressed the bumper, so let's set our next reference
goal = {kRaisedPosition, 0_rad_per_s};
} else {
@@ -127,11 +123,11 @@
.Calculate(20_ms);
m_loop.SetNextR(
- frc::MakeMatrix<2, 1>(m_lastProfiledReference.position.to<double>(),
- m_lastProfiledReference.velocity.to<double>()));
+ Eigen::Vector<double, 2>{m_lastProfiledReference.position.value(),
+ m_lastProfiledReference.velocity.value()});
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetDistance()));
+ m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -145,5 +141,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Constants.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Constants.cpp
index 75849f1..be6bfe0 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Constants.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Constants.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Constants.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp
index 26d7499..0920db7 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -12,7 +9,11 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>
-void Robot::RobotInit() {}
+void Robot::RobotInit() {
+ // Flush NetworkTables every loop. This ensures that robot pose and other
+ // values are sent during every iteration.
+ SetNetworkTablesFlushEnabled(true);
+}
/**
* This function is called every robot packet, no matter the mode. Use
@@ -22,7 +23,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -31,6 +34,7 @@
*/
void Robot::DisabledInit() {
frc2::CommandScheduler::GetInstance().CancelAll();
+ m_container.ZeroAllOutputs();
}
void Robot::DisabledPeriodic() {}
@@ -81,5 +85,7 @@
}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp
index 7608122..554de50 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
+#include <utility>
+
#include <frc/controller/PIDController.h>
#include <frc/controller/RamseteController.h>
#include <frc/shuffleboard/Shuffleboard.h>
@@ -29,20 +28,26 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.ArcadeDrive(
- m_driverController.GetY(frc::GenericHID::kLeftHand),
- m_driverController.GetX(frc::GenericHID::kRightHand));
+ m_drive.ArcadeDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightX());
},
{&m_drive}));
}
-const DriveSubsystem& RobotContainer::GetRobotDrive() const { return m_drive; }
+void RobotContainer::ZeroAllOutputs() {
+ m_drive.TankDriveVolts(0_V, 0_V);
+}
+
+const DriveSubsystem& RobotContainer::GetRobotDrive() const {
+ return m_drive;
+}
void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here
// While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController, 6)
+ frc2::JoystickButton(&m_driverController,
+ frc::XboxController::Button::kRightBumper)
.WhenPressed(&m_driveHalfSpeed)
.WhenReleased(&m_driveFullSpeed);
}
@@ -64,12 +69,12 @@
// An example trajectory to follow. All units in meters.
auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory(
- // Start at the origin facing the +X direction
- frc::Pose2d(),
+ // Start at (1, 2) facing the +X direction
+ frc::Pose2d(1_m, 2_m, 0_deg),
// Pass through these two interior waypoints, making an 's' curve path
- {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)},
+ {frc::Translation2d(2_m, 3_m), frc::Translation2d(3_m, 1_m)},
// End 3 meters straight ahead of where we started, facing forward
- frc::Pose2d(3_m, 0_m, 0_deg),
+ frc::Pose2d(4_m, 2_m, 0_deg),
// Pass the config
config);
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp
index d8cc462..a94b860 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -12,15 +9,22 @@
#include <frc/geometry/Rotation2d.h>
#include <frc/kinematics/DifferentialDriveWheelSpeeds.h>
#include <frc/simulation/SimDeviceSim.h>
+#include <frc/smartdashboard/SmartDashboard.h>
using namespace DriveConstants;
DriveSubsystem::DriveSubsystem() {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotors.SetInverted(true);
+
// Set the distance per pulse for the encoders
m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
ResetEncoders();
+ frc::SmartDashboard::PutData("Field", &m_fieldSim);
}
void DriveSubsystem::Periodic() {
@@ -28,6 +32,7 @@
m_odometry.Update(m_gyro.GetRotation2d(),
units::meter_t(m_leftEncoder.GetDistance()),
units::meter_t(m_rightEncoder.GetDistance()));
+ m_fieldSim.SetRobotPose(m_odometry.GetPose());
}
void DriveSubsystem::SimulationPeriodic() {
@@ -41,18 +46,12 @@
frc::RobotController::GetInputVoltage());
m_drivetrainSimulator.Update(20_ms);
- m_leftEncoderSim.SetDistance(m_drivetrainSimulator.GetState(
- frc::sim::DifferentialDrivetrainSim::State::kLeftPosition));
- m_leftEncoderSim.SetRate(m_drivetrainSimulator.GetState(
- frc::sim::DifferentialDrivetrainSim::State::kLeftVelocity));
- m_rightEncoderSim.SetDistance(m_drivetrainSimulator.GetState(
- frc::sim::DifferentialDrivetrainSim::State::kRightPosition));
- m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetState(
- frc::sim::DifferentialDrivetrainSim::State::kRightVelocity));
- m_gyroAngleSim.SetAngle(
- -m_drivetrainSimulator.GetHeading().Degrees().to<double>());
-
- m_fieldSim.SetRobotPose(m_odometry.GetPose());
+ m_leftEncoderSim.SetDistance(m_drivetrainSimulator.GetLeftPosition().value());
+ m_leftEncoderSim.SetRate(m_drivetrainSimulator.GetLeftVelocity().value());
+ m_rightEncoderSim.SetDistance(
+ m_drivetrainSimulator.GetRightPosition().value());
+ m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetRightVelocity().value());
+ m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees());
}
units::ampere_t DriveSubsystem::GetCurrentDraw() const {
@@ -78,9 +77,13 @@
return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0;
}
-frc::Encoder& DriveSubsystem::GetLeftEncoder() { return m_leftEncoder; }
+frc::Encoder& DriveSubsystem::GetLeftEncoder() {
+ return m_leftEncoder;
+}
-frc::Encoder& DriveSubsystem::GetRightEncoder() { return m_rightEncoder; }
+frc::Encoder& DriveSubsystem::GetRightEncoder() {
+ return m_rightEncoder;
+}
void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput);
@@ -90,9 +93,13 @@
return m_gyro.GetRotation2d().Degrees();
}
-double DriveSubsystem::GetTurnRate() { return -m_gyro.GetRate(); }
+double DriveSubsystem::GetTurnRate() {
+ return -m_gyro.GetRate();
+}
-frc::Pose2d DriveSubsystem::GetPose() { return m_odometry.GetPose(); }
+frc::Pose2d DriveSubsystem::GetPose() {
+ return m_odometry.GetPose();
+}
frc::DifferentialDriveWheelSpeeds DriveSubsystem::GetWheelSpeeds() {
return {units::meters_per_second_t(m_leftEncoder.GetRate()),
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h
index 77e1184..307d408 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/system/plant/DCMotor.h>
@@ -15,7 +12,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
#pragma once
@@ -46,7 +43,7 @@
constexpr auto kWheelDiameter = 6_in;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameter.to<double>() * wpi::math::pi) /
+ (kWheelDiameter.value() * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
@@ -55,11 +52,11 @@
// Toolsuite provides a convenient tool for obtaining these values for your
// robot.
constexpr auto ks = 0.22_V;
-constexpr auto kv = 1.98 * 1_V * 1_s / 1_m;
-constexpr auto ka = 0.2 * 1_V * 1_s * 1_s / 1_m;
+constexpr auto kv = 1.98 * 1_V / 1_mps;
+constexpr auto ka = 0.2 * 1_V / 1_mps_sq;
-constexpr auto kvAngular = 1.5 * 1_V * 1_s / 1_rad;
-constexpr auto kaAngular = 0.3 * 1_V * 1_s * 1_s / 1_rad;
+constexpr auto kvAngular = 1.5 * 1_V / 1_mps;
+constexpr auto kaAngular = 0.3 * 1_V / 1_mps_sq;
extern const frc::LinearSystem<2, 2, 2> kDrivetrainPlant;
@@ -82,5 +79,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Robot.h
index 5050999..00271e6 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/RobotContainer.h
index 06cbf7c..012e3c6 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -30,6 +27,7 @@
public:
RobotContainer();
+ void ZeroAllOutputs();
frc2::Command* GetAutonomousCommand();
const DriveSubsystem& GetRobotDrive() const;
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h
index 2cbc990..395133c 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h
@@ -1,23 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
-#include <frc/AnalogGyro.h>
+#include <frc/ADXRS450_Gyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/geometry/Pose2d.h>
#include <frc/kinematics/DifferentialDriveOdometry.h>
-#include <frc/simulation/AnalogGyroSim.h>
+#include <frc/motorcontrol/MotorControllerGroup.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <frc/simulation/ADXRS450_GyroSim.h>
#include <frc/simulation/DifferentialDrivetrainSim.h>
#include <frc/simulation/EncoderSim.h>
-#include <frc/simulation/Field2d.h>
+#include <frc/smartdashboard/Field2d.h>
#include <frc2/command/SubsystemBase.h>
#include <units/voltage.h>
@@ -131,16 +128,16 @@
// declared private and exposed only through public methods.
// The motor controllers
- frc::PWMVictorSPX m_left1{DriveConstants::kLeftMotor1Port};
- frc::PWMVictorSPX m_left2{DriveConstants::kLeftMotor2Port};
- frc::PWMVictorSPX m_right1{DriveConstants::kRightMotor1Port};
- frc::PWMVictorSPX m_right2{DriveConstants::kRightMotor2Port};
+ frc::PWMSparkMax m_left1{DriveConstants::kLeftMotor1Port};
+ frc::PWMSparkMax m_left2{DriveConstants::kLeftMotor2Port};
+ frc::PWMSparkMax m_right1{DriveConstants::kRightMotor1Port};
+ frc::PWMSparkMax m_right2{DriveConstants::kRightMotor2Port};
// The motors on the left side of the drive
- frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2};
+ frc::MotorControllerGroup m_leftMotors{m_left1, m_left2};
// The motors on the right side of the drive
- frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2};
+ frc::MotorControllerGroup m_rightMotors{m_right1, m_right2};
// The robot's drive
frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors};
@@ -154,22 +151,24 @@
DriveConstants::kRightEncoderPorts[1]};
// The gyro sensor
- frc::AnalogGyro m_gyro{0};
+ frc::ADXRS450_Gyro m_gyro;
// Odometry class for tracking robot pose
frc::DifferentialDriveOdometry m_odometry{m_gyro.GetRotation2d()};
// These classes help simulate our drivetrain.
frc::sim::DifferentialDrivetrainSim m_drivetrainSimulator{
- DriveConstants::kDrivetrainPlant, DriveConstants::kTrackwidth,
- DriveConstants::kDrivetrainGearbox, DriveConstants::kDrivetrainGearing,
- DriveConstants::kWheelDiameter / 2};
+ DriveConstants::kDrivetrainPlant,
+ DriveConstants::kTrackwidth,
+ DriveConstants::kDrivetrainGearbox,
+ DriveConstants::kDrivetrainGearing,
+ DriveConstants::kWheelDiameter / 2,
+ {0.001, 0.001, 0.0001, 0.1, 0.1, 0.005, 0.005}};
frc::sim::EncoderSim m_leftEncoderSim{m_leftEncoder};
frc::sim::EncoderSim m_rightEncoderSim{m_rightEncoder};
- frc::sim::AnalogGyroSim m_gyroAngleSim{m_gyro};
+ frc::sim::ADXRS450_GyroSim m_gyroSim{m_gyro};
- // The Field2d class simulates the field in the sim GUI. Note that we can have
- // only one instance!
+ // The Field2d class shows the field in the sim GUI.
frc::Field2d m_fieldSim;
};
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp
index e0eda4c..4c9d65e 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp
@@ -1,19 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/Encoder.h>
-#include <frc/GenericHID.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/StateSpaceUtil.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/controller/LinearQuadraticRegulator.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/estimator/KalmanFilter.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/system/LinearSystemLoop.h>
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
@@ -22,7 +17,7 @@
#include <units/length.h>
#include <units/mass.h>
#include <units/velocity.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -84,7 +79,7 @@
// An encoder set up to measure elevator height in meters.
frc::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel};
- frc::PWMVictorSPX m_motor{kMotorPort};
+ frc::PWMSparkMax m_motor{kMotorPort};
frc::XboxController m_joystick{kJoystickPort};
frc::TrapezoidProfile<units::meters>::Constraints m_constraints{3_fps,
@@ -93,26 +88,26 @@
frc::TrapezoidProfile<units::meters>::State m_lastProfiledReference;
public:
- void RobotInit() {
+ void RobotInit() override {
// Circumference = pi * d, so distance per click = pi * d / counts
- m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi *
- kDrumRadius.to<double>() / 4096.0);
+ m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi * kDrumRadius.value() /
+ 4096.0);
}
- void TeleopInit() {
+ void TeleopInit() override {
// Reset our loop to make sure it's in a known state.
m_loop.Reset(
- frc::MakeMatrix<2, 1>(m_encoder.GetDistance(), m_encoder.GetRate()));
+ Eigen::Vector<double, 2>{m_encoder.GetDistance(), m_encoder.GetRate()});
m_lastProfiledReference = {units::meter_t(m_encoder.GetDistance()),
units::meters_per_second_t(m_encoder.GetRate())};
}
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
// Sets the target height of our elevator. This is similar to setting the
// setpoint of a PID controller.
frc::TrapezoidProfile<units::meters>::State goal;
- if (m_joystick.GetBumper(frc::GenericHID::kRightHand)) {
+ if (m_joystick.GetRightBumper()) {
// We pressed the bumper, so let's set our next reference
goal = {kRaisedPosition, 0_fps};
} else {
@@ -125,11 +120,11 @@
.Calculate(20_ms);
m_loop.SetNextR(
- frc::MakeMatrix<2, 1>(m_lastProfiledReference.position.to<double>(),
- m_lastProfiledReference.velocity.to<double>()));
+ Eigen::Vector<double, 2>{m_lastProfiledReference.position.value(),
+ m_lastProfiledReference.velocity.value()});
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetDistance()));
+ m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetDistance()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -143,5 +138,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
index ca3d909..636916f 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp
@@ -1,25 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/DriverStation.h>
#include <frc/Encoder.h>
-#include <frc/GenericHID.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/StateSpaceUtil.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/controller/LinearQuadraticRegulator.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/estimator/KalmanFilter.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/system/LinearSystemLoop.h>
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
#include <units/angular_velocity.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -80,32 +75,32 @@
// An encoder set up to measure flywheel velocity in radians per second.
frc::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel};
- frc::PWMVictorSPX m_motor{kMotorPort};
+ frc::PWMSparkMax m_motor{kMotorPort};
frc::XboxController m_joystick{kJoystickPort};
public:
- void RobotInit() {
+ void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
- m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi / 4096.0);
+ m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
}
- void TeleopInit() {
- m_loop.Reset(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
+ void TeleopInit() override {
+ m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
}
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
// Sets the target speed of our flywheel. This is similar to setting the
// setpoint of a PID controller.
- if (m_joystick.GetBumper(frc::GenericHID::kRightHand)) {
+ if (m_joystick.GetRightBumper()) {
// We pressed the bumper, so let's set our next reference
- m_loop.SetNextR(frc::MakeMatrix<1, 1>(kSpinup.to<double>()));
+ m_loop.SetNextR(Eigen::Vector<double, 1>{kSpinup.value()});
} else {
// We released the bumper, so let's spin down
- m_loop.SetNextR(frc::MakeMatrix<1, 1>(0.0));
+ m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
}
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
+ m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -119,5 +114,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
index 02883fb..69d1953 100644
--- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp
@@ -1,25 +1,20 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/DriverStation.h>
#include <frc/Encoder.h>
-#include <frc/GenericHID.h>
-#include <frc/PWMVictorSPX.h>
-#include <frc/StateSpaceUtil.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/controller/LinearPlantInversionFeedforward.h>
#include <frc/controller/LinearQuadraticRegulator.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/estimator/KalmanFilter.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/system/LinearSystemLoop.h>
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
-#include <wpi/math>
+#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -81,32 +76,32 @@
// An encoder set up to measure flywheel velocity in radians per second.
frc::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel};
- frc::PWMVictorSPX m_motor{kMotorPort};
+ frc::PWMSparkMax m_motor{kMotorPort};
frc::XboxController m_joystick{kJoystickPort};
public:
- void RobotInit() {
+ void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
- m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi / 4096.0);
+ m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
}
- void TeleopInit() {
- m_loop.Reset(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
+ void TeleopInit() override {
+ m_loop.Reset(Eigen::Vector<double, 1>{m_encoder.GetRate()});
}
- void TeleopPeriodic() {
+ void TeleopPeriodic() override {
// Sets the target speed of our flywheel. This is similar to setting the
// setpoint of a PID controller.
- if (m_joystick.GetBumper(frc::GenericHID::kRightHand)) {
+ if (m_joystick.GetRightBumper()) {
// We pressed the bumper, so let's set our next reference
- m_loop.SetNextR(frc::MakeMatrix<1, 1>(kSpinup.to<double>()));
+ m_loop.SetNextR(Eigen::Vector<double, 1>{kSpinup.value()});
} else {
// We released the bumper, so let's spin down
- m_loop.SetNextR(frc::MakeMatrix<1, 1>(0.0));
+ m_loop.SetNextR(Eigen::Vector<double, 1>{0.0});
}
// Correct our Kalman filter's state vector estimate with encoder data.
- m_loop.Correct(frc::MakeMatrix<1, 1>(m_encoder.GetRate()));
+ m_loop.Correct(Eigen::Vector<double, 1>{m_encoder.GetRate()});
// Update our LQR to generate new voltage commands and use the voltages to
// predict the next state with out Kalman filter.
@@ -120,5 +115,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp
index fcc0bcd..7044fd7 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Drivetrain.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp
index 10e550b..39cfa14 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp
@@ -1,13 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc/SlewRateLimiter.h>
+#include <frc/MathUtil.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
+#include <frc/filter/SlewRateLimiter.h>
#include "Drivetrain.h"
@@ -34,14 +32,14 @@
// Get the x speed. We are inverting this because Xbox controllers return
// negative values when we push forward.
const auto xSpeed = -m_xspeedLimiter.Calculate(
- m_controller.GetY(frc::GenericHID::kLeftHand)) *
+ frc::ApplyDeadband(m_controller.GetLeftY(), 0.02)) *
Drivetrain::kMaxSpeed;
// Get the y speed or sideways/strafe speed. We are inverting this because
// we want a positive value when we pull to the left. Xbox controllers
// return positive values when you pull to the right by default.
const auto ySpeed = -m_yspeedLimiter.Calculate(
- m_controller.GetX(frc::GenericHID::kLeftHand)) *
+ frc::ApplyDeadband(m_controller.GetLeftX(), 0.02)) *
Drivetrain::kMaxSpeed;
// Get the rate of angular rotation. We are inverting this because we want a
@@ -49,7 +47,7 @@
// mathematics). Xbox controllers return positive values when you pull to
// the right by default.
const auto rot = -m_rotLimiter.Calculate(
- m_controller.GetX(frc::GenericHID::kRightHand)) *
+ frc::ApplyDeadband(m_controller.GetRightX(), 0.02)) *
Drivetrain::kMaxAngularSpeed;
m_swerve.Drive(xSpeed, ySpeed, rot, fieldRelative);
@@ -57,5 +55,7 @@
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
index 720d554..24a6527 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
@@ -1,33 +1,38 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "SwerveModule.h"
#include <frc/geometry/Rotation2d.h>
-#include <wpi/math>
+#include <wpi/numbers>
SwerveModule::SwerveModule(const int driveMotorChannel,
- const int turningMotorChannel)
- : m_driveMotor(driveMotorChannel), m_turningMotor(turningMotorChannel) {
+ const int turningMotorChannel,
+ const int driveEncoderChannelA,
+ const int driveEncoderChannelB,
+ const int turningEncoderChannelA,
+ const int turningEncoderChannelB)
+ : m_driveMotor(driveMotorChannel),
+ m_turningMotor(turningMotorChannel),
+ m_driveEncoder(driveEncoderChannelA, driveEncoderChannelB),
+ m_turningEncoder(turningEncoderChannelA, turningEncoderChannelB) {
// Set the distance per pulse for the drive encoder. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
- m_driveEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
+ m_driveEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
// Set the distance (in this case, angle) per pulse for the turning encoder.
- // This is the the angle through an entire rotation (2 * wpi::math::pi)
+ // This is the the angle through an entire rotation (2 * wpi::numbers::pi)
// divided by the encoder resolution.
- m_turningEncoder.SetDistancePerPulse(2 * wpi::math::pi / kEncoderResolution);
+ m_turningEncoder.SetDistancePerPulse(2 * wpi::numbers::pi /
+ kEncoderResolution);
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
- m_turningPIDController.EnableContinuousInput(-units::radian_t(wpi::math::pi),
- units::radian_t(wpi::math::pi));
+ m_turningPIDController.EnableContinuousInput(
+ -units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
}
frc::SwerveModuleState SwerveModule::GetState() const {
@@ -35,10 +40,15 @@
frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))};
}
-void SwerveModule::SetDesiredState(const frc::SwerveModuleState& state) {
+void SwerveModule::SetDesiredState(
+ const frc::SwerveModuleState& referenceState) {
+ // Optimize the reference state to avoid spinning further than 90 degrees
+ const auto state = frc::SwerveModuleState::Optimize(
+ referenceState, units::radian_t(m_turningEncoder.Get()));
+
// Calculate the drive output from the drive PID controller.
const auto driveOutput = m_drivePIDController.Calculate(
- m_driveEncoder.GetRate(), state.speed.to<double>());
+ m_driveEncoder.GetRate(), state.speed.value());
const auto driveFeedforward = m_driveFeedforward.Calculate(state.speed);
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h
index fed7ada..6ff5b48 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -11,7 +8,7 @@
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
#include <frc/kinematics/SwerveDriveOdometry.h>
-#include <wpi/math>
+#include <wpi/numbers>
#include "SwerveModule.h"
@@ -30,7 +27,7 @@
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
- wpi::math::pi}; // 1/2 rotation per second
+ wpi::numbers::pi}; // 1/2 rotation per second
private:
frc::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m};
@@ -38,10 +35,10 @@
frc::Translation2d m_backLeftLocation{-0.381_m, +0.381_m};
frc::Translation2d m_backRightLocation{-0.381_m, -0.381_m};
- SwerveModule m_frontLeft{1, 2};
- SwerveModule m_frontRight{2, 3};
- SwerveModule m_backLeft{5, 6};
- SwerveModule m_backRight{7, 8};
+ SwerveModule m_frontLeft{1, 2, 0, 1, 2, 3};
+ SwerveModule m_frontRight{2, 3, 4, 5, 6, 7};
+ SwerveModule m_backLeft{5, 6, 8, 9, 10, 11};
+ SwerveModule m_backRight{7, 8, 12, 13, 14, 15};
frc::AnalogGyro m_gyro{0};
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h
index bf82df4..00a938b 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h
@@ -1,27 +1,26 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
#include <frc/controller/SimpleMotorFeedforward.h>
#include <frc/kinematics/SwerveModuleState.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
class SwerveModule {
public:
- SwerveModule(int driveMotorChannel, int turningMotorChannel);
+ SwerveModule(int driveMotorChannel, int turningMotorChannel,
+ int driveEncoderChannelA, int driveEncoderChannelB,
+ int turningEncoderChannelA, int turningEncoderChannelB);
frc::SwerveModuleState GetState() const;
void SetDesiredState(const frc::SwerveModuleState& state);
@@ -30,15 +29,15 @@
static constexpr int kEncoderResolution = 4096;
static constexpr auto kModuleMaxAngularVelocity =
- wpi::math::pi * 1_rad_per_s; // radians per second
+ wpi::numbers::pi * 1_rad_per_s; // radians per second
static constexpr auto kModuleMaxAngularAcceleration =
- wpi::math::pi * 2_rad_per_s / 1_s; // radians per second^2
+ wpi::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
- frc::PWMVictorSPX m_driveMotor;
- frc::PWMVictorSPX m_turningMotor;
+ frc::PWMSparkMax m_driveMotor;
+ frc::PWMSparkMax m_turningMotor;
- frc::Encoder m_driveEncoder{0, 1};
- frc::Encoder m_turningEncoder{2, 3};
+ frc::Encoder m_driveEncoder;
+ frc::Encoder m_turningEncoder;
frc2::PIDController m_drivePIDController{1.0, 0, 0};
frc::ProfiledPIDController<units::radians> m_turningPIDController{
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Constants.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Constants.cpp
index a60d803..80fb825 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Constants.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Constants.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Constants.h"
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
index 4bb69bb..4ee98ae 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
@@ -1,12 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
+#include <utility>
+
#include <frc/controller/PIDController.h>
#include <frc/geometry/Translation2d.h>
#include <frc/shuffleboard/Shuffleboard.h>
@@ -33,13 +32,10 @@
// Set up default drive command
m_drive.SetDefaultCommand(frc2::RunCommand(
[this] {
- m_drive.Drive(units::meters_per_second_t(
- m_driverController.GetY(frc::GenericHID::kLeftHand)),
- units::meters_per_second_t(
- m_driverController.GetY(frc::GenericHID::kRightHand)),
- units::radians_per_second_t(
- m_driverController.GetX(frc::GenericHID::kLeftHand)),
- false);
+ m_drive.Drive(
+ units::meters_per_second_t(m_driverController.GetLeftY()),
+ units::meters_per_second_t(m_driverController.GetRightY()),
+ units::radians_per_second_t(m_driverController.GetLeftX()), false);
},
{&m_drive}));
}
@@ -68,8 +64,8 @@
AutoConstants::kPThetaController, 0, 0,
AutoConstants::kThetaControllerConstraints};
- thetaController.EnableContinuousInput(units::radian_t(-wpi::math::pi),
- units::radian_t(wpi::math::pi));
+ thetaController.EnableContinuousInput(units::radian_t(-wpi::numbers::pi),
+ units::radian_t(wpi::numbers::pi));
frc2::SwerveControllerCommand<4> swerveControllerCommand(
exampleTrajectory, [this]() { return m_drive.GetPose(); },
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp
index 37bb83d..7ef4af3 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/DriveSubsystem.h"
@@ -68,7 +65,7 @@
}
void DriveSubsystem::SetModuleStates(
- std::array<frc::SwerveModuleState, 4> desiredStates) {
+ wpi::array<frc::SwerveModuleState, 4> desiredStates) {
kDriveKinematics.NormalizeWheelSpeeds(&desiredStates,
AutoConstants::kMaxSpeed);
m_frontLeft.SetDesiredState(desiredStates[0]);
@@ -88,11 +85,17 @@
return m_gyro.GetRotation2d().Degrees();
}
-void DriveSubsystem::ZeroHeading() { m_gyro.Reset(); }
+void DriveSubsystem::ZeroHeading() {
+ m_gyro.Reset();
+}
-double DriveSubsystem::GetTurnRate() { return -m_gyro.GetRate(); }
+double DriveSubsystem::GetTurnRate() {
+ return -m_gyro.GetRate();
+}
-frc::Pose2d DriveSubsystem::GetPose() { return m_odometry.GetPose(); }
+frc::Pose2d DriveSubsystem::GetPose() {
+ return m_odometry.GetPose();
+}
void DriveSubsystem::ResetOdometry(frc::Pose2d pose) {
m_odometry.ResetPosition(pose,
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp
index 22b3f0d..4d20ec8 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp
@@ -1,14 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/SwerveModule.h"
#include <frc/geometry/Rotation2d.h>
-#include <wpi/math>
+#include <wpi/numbers>
#include "Constants.h"
@@ -30,15 +27,15 @@
ModuleConstants::kDriveEncoderDistancePerPulse);
// Set the distance (in this case, angle) per pulse for the turning encoder.
- // This is the the angle through an entire rotation (2 * wpi::math::pi)
+ // This is the the angle through an entire rotation (2 * wpi::numbers::pi)
// divided by the encoder resolution.
m_turningEncoder.SetDistancePerPulse(
ModuleConstants::kTurningEncoderDistancePerPulse);
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
- m_turningPIDController.EnableContinuousInput(units::radian_t(-wpi::math::pi),
- units::radian_t(wpi::math::pi));
+ m_turningPIDController.EnableContinuousInput(
+ units::radian_t(-wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
}
frc::SwerveModuleState SwerveModule::GetState() {
@@ -46,10 +43,15 @@
frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))};
}
-void SwerveModule::SetDesiredState(frc::SwerveModuleState& state) {
+void SwerveModule::SetDesiredState(
+ const frc::SwerveModuleState& referenceState) {
+ // Optimize the reference state to avoid spinning further than 90 degrees
+ const auto state = frc::SwerveModuleState::Optimize(
+ referenceState, units::radian_t(m_turningEncoder.Get()));
+
// Calculate the drive output from the drive PID controller.
const auto driveOutput = m_drivePIDController.Calculate(
- m_driveEncoder.GetRate(), state.speed.to<double>());
+ m_driveEncoder.GetRate(), state.speed.value());
// Calculate the turning motor output from the turning PID controller.
auto turnOutput = m_turningPIDController.Calculate(
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h
index 8911b5f..3a3b75a 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
@@ -15,7 +12,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
-#include <wpi/math>
+#include <wpi/numbers>
#pragma once
@@ -42,17 +39,17 @@
constexpr int kFrontLeftTurningEncoderPorts[2]{0, 1};
constexpr int kRearLeftTurningEncoderPorts[2]{2, 3};
constexpr int kFrontRightTurningEncoderPorts[2]{4, 5};
-constexpr int kRearRightTurningEncoderPorts[2]{5, 6};
+constexpr int kRearRightTurningEncoderPorts[2]{6, 7};
constexpr bool kFrontLeftTurningEncoderReversed = false;
constexpr bool kRearLeftTurningEncoderReversed = true;
constexpr bool kFrontRightTurningEncoderReversed = false;
constexpr bool kRearRightTurningEncoderReversed = true;
-constexpr int kFrontLeftDriveEncoderPorts[2]{0, 1};
-constexpr int kRearLeftDriveEncoderPorts[2]{2, 3};
-constexpr int kFrontRightDriveEncoderPorts[2]{4, 5};
-constexpr int kRearRightDriveEncoderPorts[2]{5, 6};
+constexpr int kFrontLeftDriveEncoderPorts[2]{8, 9};
+constexpr int kRearLeftDriveEncoderPorts[2]{10, 11};
+constexpr int kFrontRightDriveEncoderPorts[2]{12, 13};
+constexpr int kRearRightDriveEncoderPorts[2]{14, 15};
constexpr bool kFrontLeftDriveEncoderReversed = false;
constexpr bool kRearLeftDriveEncoderReversed = true;
@@ -77,14 +74,15 @@
namespace ModuleConstants {
constexpr int kEncoderCPR = 1024;
-constexpr double kWheelDiameterMeters = .15;
+constexpr double kWheelDiameterMeters = 0.15;
constexpr double kDriveEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameterMeters * wpi::math::pi) / static_cast<double>(kEncoderCPR);
+ (kWheelDiameterMeters * wpi::numbers::pi) /
+ static_cast<double>(kEncoderCPR);
constexpr double kTurningEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
- (wpi::math::pi * 2) / static_cast<double>(kEncoderCPR);
+ (wpi::numbers::pi * 2) / static_cast<double>(kEncoderCPR);
constexpr double kPModuleTurningController = 1;
constexpr double kPModuleDriveController = 1;
@@ -113,5 +111,5 @@
} // namespace AutoConstants
namespace OIConstants {
-constexpr int kDriverControllerPort = 1;
+constexpr int kDriverControllerPort = 0;
} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h
index 8b36617..3466121 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h
index 562af50..5233f3f 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h
@@ -1,15 +1,11 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/ADXRS450_Gyro.h>
#include <frc/Encoder.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/drive/MecanumDrive.h>
#include <frc/geometry/Pose2d.h>
#include <frc/geometry/Rotation2d.h>
@@ -17,6 +13,7 @@
#include <frc/kinematics/ChassisSpeeds.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
#include <frc/kinematics/SwerveDriveOdometry.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include "Constants.h"
@@ -46,7 +43,7 @@
*/
void Drive(units::meters_per_second_t xSpeed,
units::meters_per_second_t ySpeed, units::radians_per_second_t rot,
- bool feildRelative);
+ bool fieldRelative);
/**
* Resets the drive encoders to currently read a position of 0.
@@ -54,9 +51,9 @@
void ResetEncoders();
/**
- * Sets the drive SpeedControllers to a power from -1 to 1.
+ * Sets the drive MotorControllers to a power from -1 to 1.
*/
- void SetModuleStates(std::array<frc::SwerveModuleState, 4> desiredStates);
+ void SetModuleStates(wpi::array<frc::SwerveModuleState, 4> desiredStates);
/**
* Returns the heading of the robot.
@@ -92,9 +89,9 @@
void ResetOdometry(frc::Pose2d pose);
units::meter_t kTrackWidth =
- .5_m; // Distance between centers of right and left wheels on robot
+ 0.5_m; // Distance between centers of right and left wheels on robot
units::meter_t kWheelBase =
- .7_m; // Distance between centers of front and back wheels on robot
+ 0.7_m; // Distance between centers of front and back wheels on robot
frc::SwerveDriveKinematics<4> kDriveKinematics{
frc::Translation2d(kWheelBase / 2, kTrackWidth / 2),
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h
index f8d816a..4208b35 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h
@@ -1,20 +1,17 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <frc/Encoder.h>
-#include <frc/Spark.h>
#include <frc/controller/PIDController.h>
#include <frc/controller/ProfiledPIDController.h>
#include <frc/geometry/Rotation2d.h>
#include <frc/kinematics/SwerveModuleState.h>
+#include <frc/motorcontrol/Spark.h>
#include <frc/trajectory/TrapezoidProfile.h>
-#include <wpi/math>
+#include <wpi/numbers>
#include "Constants.h"
@@ -30,7 +27,7 @@
frc::SwerveModuleState GetState();
- void SetDesiredState(frc::SwerveModuleState& state);
+ void SetDesiredState(const frc::SwerveModuleState& state);
void ResetEncoders();
@@ -40,11 +37,11 @@
// meters per second squared.
static constexpr units::radians_per_second_t kModuleMaxAngularVelocity =
- units::radians_per_second_t(wpi::math::pi); // radians per second
+ units::radians_per_second_t(wpi::numbers::pi); // radians per second
static constexpr units::unit_t<radians_per_second_squared_t>
kModuleMaxAngularAcceleration =
units::unit_t<radians_per_second_squared_t>(
- wpi::math::pi * 2.0); // radians per second squared
+ wpi::numbers::pi * 2.0); // radians per second squared
frc::Spark m_driveMotor;
frc::Spark m_turningMotor;
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp
new file mode 100644
index 0000000..f132f76
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp
@@ -0,0 +1,41 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "Drivetrain.h"
+
+#include <frc/Timer.h>
+
+#include "ExampleGlobalMeasurementSensor.h"
+
+void Drivetrain::Drive(units::meters_per_second_t xSpeed,
+ units::meters_per_second_t ySpeed,
+ units::radians_per_second_t rot, bool fieldRelative) {
+ auto states = m_kinematics.ToSwerveModuleStates(
+ fieldRelative ? frc::ChassisSpeeds::FromFieldRelativeSpeeds(
+ xSpeed, ySpeed, rot, m_gyro.GetRotation2d())
+ : frc::ChassisSpeeds{xSpeed, ySpeed, rot});
+
+ m_kinematics.NormalizeWheelSpeeds(&states, kMaxSpeed);
+
+ auto [fl, fr, bl, br] = states;
+
+ m_frontLeft.SetDesiredState(fl);
+ m_frontRight.SetDesiredState(fr);
+ m_backLeft.SetDesiredState(bl);
+ m_backRight.SetDesiredState(br);
+}
+
+void Drivetrain::UpdateOdometry() {
+ m_poseEstimator.Update(m_gyro.GetRotation2d(), m_frontLeft.GetState(),
+ m_frontRight.GetState(), m_backLeft.GetState(),
+ m_backRight.GetState());
+
+ // Also apply vision measurements. We use 0.3 seconds in the past as an
+ // example -- on a real robot, this must be calculated based either on latency
+ // or timestamps.
+ m_poseEstimator.AddVisionMeasurement(
+ ExampleGlobalMeasurementSensor::GetEstimatedGlobalPose(
+ m_poseEstimator.GetEstimatedPosition()),
+ frc::Timer::GetFPGATimestamp() - 0.3_s);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp
new file mode 100644
index 0000000..3f5f675
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp
@@ -0,0 +1,57 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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/TimedRobot.h>
+#include <frc/XboxController.h>
+#include <frc/filter/SlewRateLimiter.h>
+
+#include "Drivetrain.h"
+
+class Robot : public frc::TimedRobot {
+ public:
+ void AutonomousPeriodic() override {
+ DriveWithJoystick(false);
+ m_swerve.UpdateOdometry();
+ }
+
+ void TeleopPeriodic() override { DriveWithJoystick(true); }
+
+ private:
+ frc::XboxController m_controller{0};
+ Drivetrain m_swerve;
+
+ // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0
+ // to 1.
+ frc::SlewRateLimiter<units::scalar> m_xspeedLimiter{3 / 1_s};
+ frc::SlewRateLimiter<units::scalar> m_yspeedLimiter{3 / 1_s};
+ frc::SlewRateLimiter<units::scalar> m_rotLimiter{3 / 1_s};
+
+ void DriveWithJoystick(bool fieldRelative) {
+ // Get the x speed. We are inverting this because Xbox controllers return
+ // negative values when we push forward.
+ const auto xSpeed = -m_xspeedLimiter.Calculate(m_controller.GetLeftY()) *
+ Drivetrain::kMaxSpeed;
+
+ // Get the y speed or sideways/strafe speed. We are inverting this because
+ // we want a positive value when we pull to the left. Xbox controllers
+ // return positive values when you pull to the right by default.
+ const auto ySpeed = -m_yspeedLimiter.Calculate(m_controller.GetLeftX()) *
+ Drivetrain::kMaxSpeed;
+
+ // Get the rate of angular rotation. We are inverting this because we want a
+ // positive value when we pull to the left (remember, CCW is positive in
+ // mathematics). Xbox controllers return positive values when you pull to
+ // the right by default.
+ const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
+ Drivetrain::kMaxAngularSpeed;
+
+ m_swerve.Drive(xSpeed, ySpeed, rot, fieldRelative);
+ }
+};
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp
new file mode 100644
index 0000000..968ccad
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp
@@ -0,0 +1,65 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source 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 "SwerveModule.h"
+
+#include <frc/geometry/Rotation2d.h>
+#include <wpi/numbers>
+
+SwerveModule::SwerveModule(const int driveMotorChannel,
+ const int turningMotorChannel,
+ const int driveEncoderChannelA,
+ const int driveEncoderChannelB,
+ const int turningEncoderChannelA,
+ const int turningEncoderChannelB)
+ : m_driveMotor(driveMotorChannel),
+ m_turningMotor(turningMotorChannel),
+ m_driveEncoder(driveEncoderChannelA, driveEncoderChannelB),
+ m_turningEncoder(turningEncoderChannelA, turningEncoderChannelB) {
+ // Set the distance per pulse for the drive encoder. We can simply use the
+ // distance traveled for one rotation of the wheel divided by the encoder
+ // resolution.
+ m_driveEncoder.SetDistancePerPulse(2 * wpi::numbers::pi *
+ kWheelRadius.value() / kEncoderResolution);
+
+ // Set the distance (in this case, angle) per pulse for the turning encoder.
+ // This is the the angle through an entire rotation (2 * wpi::numbers::pi)
+ // divided by the encoder resolution.
+ m_turningEncoder.SetDistancePerPulse(2 * wpi::numbers::pi /
+ kEncoderResolution);
+
+ // Limit the PID Controller's input range between -pi and pi and set the input
+ // to be continuous.
+ m_turningPIDController.EnableContinuousInput(
+ -units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
+}
+
+frc::SwerveModuleState SwerveModule::GetState() const {
+ return {units::meters_per_second_t{m_driveEncoder.GetRate()},
+ frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))};
+}
+
+void SwerveModule::SetDesiredState(
+ const frc::SwerveModuleState& referenceState) {
+ // Optimize the reference state to avoid spinning further than 90 degrees
+ const auto state = frc::SwerveModuleState::Optimize(
+ referenceState, units::radian_t(m_turningEncoder.Get()));
+
+ // Calculate the drive output from the drive PID controller.
+ const auto driveOutput = m_drivePIDController.Calculate(
+ m_driveEncoder.GetRate(), state.speed.value());
+
+ const auto driveFeedforward = m_driveFeedforward.Calculate(state.speed);
+
+ // Calculate the turning motor output from the turning PID controller.
+ const auto turnOutput = m_turningPIDController.Calculate(
+ units::radian_t(m_turningEncoder.Get()), state.angle.Radians());
+
+ const auto turnFeedforward = m_turnFeedforward.Calculate(
+ m_turningPIDController.GetSetpoint().velocity);
+
+ // Set the motor outputs.
+ m_driveMotor.SetVoltage(units::volt_t{driveOutput} + driveFeedforward);
+ m_turningMotor.SetVoltage(units::volt_t{turnOutput} + turnFeedforward);
+}
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h
new file mode 100644
index 0000000..81f8bb7
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h
@@ -0,0 +1,54 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/AnalogGyro.h>
+#include <frc/estimator/SwerveDrivePoseEstimator.h>
+#include <frc/geometry/Translation2d.h>
+#include <frc/kinematics/SwerveDriveKinematics.h>
+#include <frc/kinematics/SwerveDriveOdometry.h>
+#include <wpi/numbers>
+
+#include "SwerveModule.h"
+
+/**
+ * Represents a swerve drive style drivetrain.
+ */
+class Drivetrain {
+ public:
+ Drivetrain() { m_gyro.Reset(); }
+
+ void Drive(units::meters_per_second_t xSpeed,
+ units::meters_per_second_t ySpeed, units::radians_per_second_t rot,
+ bool fieldRelative);
+ void UpdateOdometry();
+
+ static constexpr auto kMaxSpeed = 3.0_mps; // 3 meters per second
+ static constexpr units::radians_per_second_t kMaxAngularSpeed{
+ wpi::numbers::pi}; // 1/2 rotation per second
+
+ private:
+ frc::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m};
+ frc::Translation2d m_frontRightLocation{+0.381_m, -0.381_m};
+ frc::Translation2d m_backLeftLocation{-0.381_m, +0.381_m};
+ frc::Translation2d m_backRightLocation{-0.381_m, -0.381_m};
+
+ SwerveModule m_frontLeft{1, 2, 0, 1, 2, 3};
+ SwerveModule m_frontRight{2, 3, 4, 5, 6, 7};
+ SwerveModule m_backLeft{5, 6, 8, 9, 10, 11};
+ SwerveModule m_backRight{7, 8, 12, 13, 14, 15};
+
+ frc::AnalogGyro m_gyro{0};
+
+ frc::SwerveDriveKinematics<4> m_kinematics{
+ m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation,
+ m_backRightLocation};
+
+ // Gains are for example purposes only - must be determined for your own
+ // robot!
+ frc::SwerveDrivePoseEstimator<4> m_poseEstimator{
+ frc::Rotation2d(), frc::Pose2d(), m_kinematics,
+ {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
new file mode 100644
index 0000000..a4caff4
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h
@@ -0,0 +1,24 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/StateSpaceUtil.h>
+#include <frc/geometry/Pose2d.h>
+
+/**
+ * This dummy class represents a global measurement sensor, such as a computer
+ * vision solution.
+ */
+class ExampleGlobalMeasurementSensor {
+ public:
+ static frc::Pose2d GetEstimatedGlobalPose(
+ const frc::Pose2d& estimatedRobotPose) {
+ auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1);
+ return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)),
+ estimatedRobotPose.Y() + units::meter_t(randVec(1)),
+ estimatedRobotPose.Rotation() +
+ frc::Rotation2d(units::radian_t(randVec(3))));
+ }
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h
new file mode 100644
index 0000000..7456584
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h
@@ -0,0 +1,53 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#pragma once
+
+#include <frc/Encoder.h>
+#include <frc/controller/PIDController.h>
+#include <frc/controller/ProfiledPIDController.h>
+#include <frc/controller/SimpleMotorFeedforward.h>
+#include <frc/kinematics/SwerveModuleState.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+#include <units/angular_velocity.h>
+#include <units/time.h>
+#include <units/velocity.h>
+#include <units/voltage.h>
+#include <wpi/numbers>
+
+class SwerveModule {
+ public:
+ SwerveModule(int driveMotorChannel, int turningMotorChannel,
+ int driveEncoderChannelA, int driveEncoderChannelB,
+ int turningEncoderChannelA, int turningEncoderChannelB);
+ frc::SwerveModuleState GetState() const;
+ void SetDesiredState(const frc::SwerveModuleState& state);
+
+ private:
+ static constexpr auto kWheelRadius = 0.0508_m;
+ static constexpr int kEncoderResolution = 4096;
+
+ static constexpr auto kModuleMaxAngularVelocity =
+ wpi::numbers::pi * 1_rad_per_s; // radians per second
+ static constexpr auto kModuleMaxAngularAcceleration =
+ wpi::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
+
+ frc::PWMSparkMax m_driveMotor;
+ frc::PWMSparkMax m_turningMotor;
+
+ frc::Encoder m_driveEncoder;
+ frc::Encoder m_turningEncoder;
+
+ frc2::PIDController m_drivePIDController{1.0, 0, 0};
+ frc::ProfiledPIDController<units::radians> m_turningPIDController{
+ 1.0,
+ 0.0,
+ 0.0,
+ {kModuleMaxAngularVelocity, kModuleMaxAngularAcceleration}};
+
+ frc::SimpleMotorFeedforward<units::meters> m_driveFeedforward{1_V,
+ 3_V / 1_mps};
+ frc::SimpleMotorFeedforward<units::radians> m_turnFeedforward{
+ 1_V, 0.5_V / 1_rad_per_s};
+};
diff --git a/wpilibcExamples/src/main/cpp/examples/TankDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/TankDrive/cpp/Robot.cpp
new file mode 100644
index 0000000..c003762
--- /dev/null
+++ b/wpilibcExamples/src/main/cpp/examples/TankDrive/cpp/Robot.cpp
@@ -0,0 +1,39 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include <frc/Joystick.h>
+#include <frc/TimedRobot.h>
+#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
+
+/**
+ * This is a demo program showing the use of the DifferentialDrive class.
+ * Runs the motors with tank steering.
+ */
+class Robot : public frc::TimedRobot {
+ frc::PWMSparkMax m_leftMotor{0};
+ frc::PWMSparkMax m_rightMotor{1};
+ frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor};
+ frc::Joystick m_leftStick{0};
+ frc::Joystick m_rightStick{1};
+
+ public:
+ void RobotInit() override {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotor.SetInverted(true);
+ }
+
+ void TeleopPeriodic() override {
+ // Drive with tank style
+ m_robotDrive.TankDrive(m_leftStick.GetY(), m_rightStick.GetY());
+ }
+};
+
+#ifndef RUNNING_FRC_TESTS
+int main() {
+ return frc::StartRobot<Robot>();
+}
+#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp
index 3ca31ed..466fdcd 100644
--- a/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp
@@ -1,35 +1,39 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
-#include <frc/GenericHID.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a demo program showing the use of the DifferentialDrive class.
* Runs the motors with tank steering and an Xbox controller.
*/
class Robot : public frc::TimedRobot {
- frc::PWMVictorSPX m_leftMotor{0};
- frc::PWMVictorSPX m_rightMotor{1};
+ frc::PWMSparkMax m_leftMotor{0};
+ frc::PWMSparkMax m_rightMotor{1};
frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor};
frc::XboxController m_driverController{0};
public:
- void TeleopPeriodic() {
+ void RobotInit() override {
+ // We need to invert one side of the drivetrain so that positive voltages
+ // result in both sides moving forward. Depending on how your robot's
+ // gearbox is constructed, you might have to invert the left side instead.
+ m_rightMotor.SetInverted(true);
+ }
+
+ void TeleopPeriodic() override {
// Drive with tank style
- m_robotDrive.TankDrive(
- m_driverController.GetY(frc::GenericHID::JoystickHand::kLeftHand),
- m_driverController.GetY(frc::GenericHID::JoystickHand::kRightHand));
+ m_robotDrive.TankDrive(m_driverController.GetLeftY(),
+ m_driverController.GetRightY());
}
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp
index 9f9c01d..e8f805d 100644
--- a/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp
@@ -1,15 +1,12 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogInput.h>
-#include <frc/MedianFilter.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/filter/MedianFilter.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a sample program demonstrating how to use an ultrasonic sensor and
@@ -52,11 +49,13 @@
frc::AnalogInput m_ultrasonic{kUltrasonicPort};
- frc::PWMVictorSPX m_left{kLeftMotorPort};
- frc::PWMVictorSPX m_right{kRightMotorPort};
+ frc::PWMSparkMax m_left{kLeftMotorPort};
+ frc::PWMSparkMax m_right{kRightMotorPort};
frc::DifferentialDrive m_robotDrive{m_left, m_right};
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp
index 47bd62d..62d4106 100644
--- a/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp
@@ -1,16 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <frc/AnalogInput.h>
-#include <frc/MedianFilter.h>
-#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/controller/PIDController.h>
#include <frc/drive/DifferentialDrive.h>
+#include <frc/filter/MedianFilter.h>
+#include <frc/motorcontrol/PWMSparkMax.h>
/**
* This is a sample program demonstrating how to use an ultrasonic sensor and
@@ -58,13 +55,15 @@
frc::AnalogInput m_ultrasonic{kUltrasonicPort};
- frc::PWMVictorSPX m_left{kLeftMotorPort};
- frc::PWMVictorSPX m_right{kRightMotorPort};
+ frc::PWMSparkMax m_left{kLeftMotorPort};
+ frc::PWMSparkMax m_right{kRightMotorPort};
frc::DifferentialDrive m_robotDrive{m_left, m_right};
frc2::PIDController m_pidController{kP, kI, kD};
};
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/examples.json b/wpilibcExamples/src/main/cpp/examples/examples.json
index 93bfad4..b639188 100644
--- a/wpilibcExamples/src/main/cpp/examples/examples.json
+++ b/wpilibcExamples/src/main/cpp/examples/examples.json
@@ -52,6 +52,14 @@
"commandversion": 2
},
{
+ "name":"Mechanism2d",
+ "foldername":"Mechanism2d",
+ "gradlebase":"cpp",
+ "description":"An example usage of Mechanism2d to display mechanism states on a dashboard.",
+ "tags":["Mechanism2d"],
+ "commandversion": 2
+ },
+ {
"name": "Solenoids",
"description": "Demonstrate controlling a single and double solenoid from Joystick buttons.",
"tags": [
@@ -90,6 +98,19 @@
"commandversion": 2
},
{
+ "name": "Tank Drive",
+ "description": "An example program which demonstrates the use of Tank Drive with the DifferentialDrive class",
+ "tags": [
+ "Getting Started with C++",
+ "Robot and Motor",
+ "Joystick",
+ "Complete List"
+ ],
+ "foldername": "TankDrive",
+ "gradlebase": "cpp",
+ "commandversion": 2
+ },
+ {
"name": "Mecanum Drive",
"description": "An example program which demonstrates the use of Mecanum Drive with the MecanumDrive class",
"tags": [
@@ -262,17 +283,6 @@
"commandversion": 2
},
{
- "name": "PacGoat",
- "description": "A fully functional example CommandBased program for FRC Team 190's 2014 robot. This code can run on your computer if it supports simulation.",
- "tags": [
- "CommandBased Robot",
- "Complete List"
- ],
- "foldername": "PacGoat",
- "gradlebase": "cpp",
- "commandversion": 1
- },
- {
"name": "HAL",
"description": "A program created using the HAL exclusively. This example is for advanced users",
"tags": [
@@ -544,6 +554,17 @@
"commandversion": 2
},
{
+ "name": "RomiReference",
+ "description": "An example command-based robot program that can be used with the Romi reference robot design.",
+ "tags": [
+ "Drivetrain",
+ "Romi"
+ ],
+ "foldername": "RomiReference",
+ "gradlebase": "cppromi",
+ "commandversion": 2
+ },
+ {
"name": "StateSpaceFlywheel",
"description": "An example state-space controller for a flywheel.",
"tags": [
@@ -621,7 +642,8 @@
"Digital",
"Sensors",
"Simulation",
- "Physics"
+ "Physics",
+ "Mechanism2d"
],
"foldername": "ElevatorSimulation",
"gradlebase": "cpp",
@@ -629,6 +651,38 @@
"commandversion": 2
},
{
+ "name": "DifferentialDrivePoseEstimator",
+ "description": "Demonstrates the use of the DifferentialDrivePoseEstimator as a replacement for differential drive odometry.",
+ "tags": [
+ "Drivetrain",
+ "State space",
+ "Vision",
+ "Filter",
+ "Odometry",
+ "Pose"
+ ],
+ "foldername": "DifferentialDrivePoseEstimator",
+ "gradlebase": "cpp",
+ "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
+ "name": "MecanumDrivePoseEstimator",
+ "description": "Demonstrates the use of the MecanumDrivePoseEstimator as a replacement for mecanum odometry.",
+ "tags": [
+ "Drivetrain",
+ "State space",
+ "Vision",
+ "Filter",
+ "Odometry",
+ "Pose"
+ ],
+ "foldername": "MecanumDrivePoseEstimator",
+ "gradlebase": "cpp",
+ "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
"name": "ArmSimulation",
"description": "Demonstrates the use of physics simulation with a simple single-jointed arm.",
"tags": [
@@ -637,7 +691,8 @@
"Digital",
"Sensors",
"Simulation",
- "Physics"
+ "Physics",
+ "Mechanism2d"
],
"foldername": "ArmSimulation",
"gradlebase": "cpp",
@@ -645,6 +700,24 @@
"commandversion": 2
},
{
+ "name": "SimpleDifferentialDriveSimulation",
+ "description": "An example of a minimal drivetrain simulation project without the command-based library.",
+ "tags": [
+ "Differential Drive",
+ "State space",
+ "Digital",
+ "Sensors",
+ "Simulation",
+ "Physics",
+ "Drivetrain",
+ "Field2d"
+ ],
+ "foldername": "SimpleDifferentialDriveSimulation",
+ "gradlebase": "cpp",
+ "mainclass": "Main",
+ "commandversion": 2
+ },
+ {
"name": "StateSpaceDriveSimulation",
"description": "Demonstrates the use of physics simulation with a differential drivetrain and the Field2d class.",
"tags": [
@@ -661,5 +734,22 @@
"gradlebase": "cpp",
"mainclass": "Main",
"commandversion": 2
+ },
+ {
+ "name": "SwerveDrivePoseEstimator",
+ "description": "Demonstrates the use of the SwerveDrivePoseEstimator as a replacement for mecanum drive odometry.",
+ "tags": [
+ "Drivetrain",
+ "State space",
+ "Vision",
+ "Filter",
+ "Odometry",
+ "State",
+ "Swerve"
+ ],
+ "foldername": "SwerveDrivePoseEstimator",
+ "gradlebase": "cpp",
+ "mainclass": "Main",
+ "commandversion": 2
}
]
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp
index cd19aeb..8cd7b02 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -20,7 +17,9 @@
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
-void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
+void Robot::RobotPeriodic() {
+ frc2::CommandScheduler::GetInstance().Run();
+}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -67,5 +66,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp
index 8210645..8ba2094 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "RobotContainer.h"
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp
index 0e709aa..e551aa1 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/ExampleCommand.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "commands/ExampleCommand.h"
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp
index 0cfda95..4a31aee 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/subsystems/ExampleSubsystem.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "subsystems/ExampleSubsystem.h"
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h
index 5ac2de0..20cc88a 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Constants.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h
index fa173d3..a82f2ac 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h
index 46609ac..2988968 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/RobotContainer.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/commands/ExampleCommand.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/commands/ExampleCommand.h
index c36477f..8ecd864 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/commands/ExampleCommand.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/commands/ExampleCommand.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h
index b64c26f..a805151 100644
--- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h
+++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/OI.cpp b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/OI.cpp
deleted file mode 100644
index 2a9ef50..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/OI.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "OI.h"
-
-OI::OI() {
- // Process operator interface input here.
-}
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/Robot.cpp
deleted file mode 100644
index b2a8884..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/Robot.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "Robot.h"
-
-#include <frc/commands/Scheduler.h>
-#include <frc/smartdashboard/SmartDashboard.h>
-
-ExampleSubsystem Robot::m_subsystem;
-OI Robot::m_oi;
-
-void Robot::RobotInit() {
- m_chooser.SetDefaultOption("Default Auto", &m_defaultAuto);
- m_chooser.AddOption("My Auto", &m_myAuto);
- frc::SmartDashboard::PutData("Auto Modes", &m_chooser);
-}
-
-/**
- * This function is called every robot packet, no matter the mode. Use
- * this for items like diagnostics that you want ran during disabled,
- * autonomous, teleoperated and test.
- *
- * <p> This runs after the mode specific periodic functions, but before
- * LiveWindow and SmartDashboard integrated updating.
- */
-void Robot::RobotPeriodic() {}
-
-/**
- * This function is called once each time the robot enters Disabled mode. You
- * can use it to reset any subsystem information you want to clear when the
- * robot is disabled.
- */
-void Robot::DisabledInit() {}
-
-void Robot::DisabledPeriodic() { frc::Scheduler::GetInstance()->Run(); }
-
-/**
- * This autonomous (along with the chooser code above) shows how to select
- * between different autonomous modes using the dashboard. The sendable chooser
- * code works with the Java SmartDashboard. If you prefer the LabVIEW Dashboard,
- * remove all of the chooser code and uncomment the GetString code to get the
- * auto name from the text box below the Gyro.
- *
- * You can add additional auto modes by adding additional commands to the
- * chooser code above (like the commented example) or additional comparisons to
- * the if-else structure below with additional strings & commands.
- */
-void Robot::AutonomousInit() {
- // std::string autoSelected = frc::SmartDashboard::GetString(
- // "Auto Selector", "Default");
- // if (autoSelected == "My Auto") {
- // m_autonomousCommand = &m_myAuto;
- // } else {
- // m_autonomousCommand = &m_defaultAuto;
- // }
-
- m_autonomousCommand = m_chooser.GetSelected();
-
- if (m_autonomousCommand != nullptr) {
- m_autonomousCommand->Start();
- }
-}
-
-void Robot::AutonomousPeriodic() { frc::Scheduler::GetInstance()->Run(); }
-
-void Robot::TeleopInit() {
- // This makes sure that the autonomous stops running when
- // teleop starts running. If you want the autonomous to
- // continue until interrupted by another command, remove
- // this line or comment it out.
- if (m_autonomousCommand != nullptr) {
- m_autonomousCommand->Cancel();
- m_autonomousCommand = nullptr;
- }
-}
-
-void Robot::TeleopPeriodic() { frc::Scheduler::GetInstance()->Run(); }
-
-void Robot::TestPeriodic() {}
-
-#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
-#endif
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/commands/ExampleCommand.cpp b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/commands/ExampleCommand.cpp
deleted file mode 100644
index a5596ef..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/commands/ExampleCommand.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "commands/ExampleCommand.h"
-
-#include "Robot.h"
-
-ExampleCommand::ExampleCommand() {
- // Use Requires() here to declare subsystem dependencies
- Requires(&Robot::m_subsystem);
-}
-
-// Called just before this Command runs the first time
-void ExampleCommand::Initialize() {}
-
-// Called repeatedly when this Command is scheduled to run
-void ExampleCommand::Execute() {}
-
-// Make this return true when this Command no longer needs to run execute()
-bool ExampleCommand::IsFinished() { return false; }
-
-// Called once after isFinished returns true
-void ExampleCommand::End() {}
-
-// Called when another command which requires one or more of the same
-// subsystems is scheduled to run
-void ExampleCommand::Interrupted() {}
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/commands/MyAutoCommand.cpp b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/commands/MyAutoCommand.cpp
deleted file mode 100644
index 1389447..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/commands/MyAutoCommand.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "commands/MyAutoCommand.h"
-
-#include "Robot.h"
-
-MyAutoCommand::MyAutoCommand() {
- // Use Requires() here to declare subsystem dependencies
- Requires(&Robot::m_subsystem);
-}
-
-// Called just before this Command runs the first time
-void MyAutoCommand::Initialize() {}
-
-// Called repeatedly when this Command is scheduled to run
-void MyAutoCommand::Execute() {}
-
-// Make this return true when this Command no longer needs to run execute()
-bool MyAutoCommand::IsFinished() { return false; }
-
-// Called once after isFinished returns true
-void MyAutoCommand::End() {}
-
-// Called when another command which requires one or more of the same
-// subsystems is scheduled to run
-void MyAutoCommand::Interrupted() {}
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/subsystems/ExampleSubsystem.cpp b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/subsystems/ExampleSubsystem.cpp
deleted file mode 100644
index ed60550..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/cpp/subsystems/ExampleSubsystem.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#include "subsystems/ExampleSubsystem.h"
-
-#include "RobotMap.h"
-
-ExampleSubsystem::ExampleSubsystem() : frc::Subsystem("ExampleSubsystem") {}
-
-void ExampleSubsystem::InitDefaultCommand() {
- // Set the default command for a subsystem here.
- // SetDefaultCommand(new MySpecialCommand());
-}
-
-// Put methods for controlling this subsystem
-// here. Call these from Commands.
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/OI.h b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/OI.h
deleted file mode 100644
index 77007bb..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/OI.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-class OI {
- public:
- OI();
-};
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/Robot.h
deleted file mode 100644
index 94c2314..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/Robot.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/TimedRobot.h>
-#include <frc/commands/Command.h>
-#include <frc/smartdashboard/SendableChooser.h>
-
-#include "OI.h"
-#include "commands/ExampleCommand.h"
-#include "commands/MyAutoCommand.h"
-#include "subsystems/ExampleSubsystem.h"
-
-class Robot : public frc::TimedRobot {
- public:
- static ExampleSubsystem m_subsystem;
- static OI m_oi;
-
- void RobotInit() override;
- void RobotPeriodic() override;
- void DisabledInit() override;
- void DisabledPeriodic() override;
- void AutonomousInit() override;
- void AutonomousPeriodic() override;
- void TeleopInit() override;
- void TeleopPeriodic() override;
- void TestPeriodic() override;
-
- private:
- // Have it null by default so that if testing teleop it
- // doesn't have undefined behavior and potentially crash.
- frc::Command* m_autonomousCommand = nullptr;
- ExampleCommand m_defaultAuto;
- MyAutoCommand m_myAuto;
- frc::SendableChooser<frc::Command*> m_chooser;
-};
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/RobotMap.h b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/RobotMap.h
deleted file mode 100644
index 875d3aa..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/RobotMap.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-/**
- * The RobotMap is a mapping from the ports sensors and actuators are wired into
- * to a variable name. This provides flexibility changing wiring, makes checking
- * the wiring easier and significantly reduces the number of magic numbers
- * floating around.
- */
-
-// For example to map the left and right motors, you could define the
-// following variables to use with your drivetrain subsystem.
-// constexpr int kLeftMotor = 1;
-// constexpr int kRightMotor = 2;
-
-// If you are using multiple modules, make sure to define both the port
-// number and the module. For example you with a rangefinder:
-// constexpr int kRangeFinderPort = 1;
-// constexpr int kRangeFinderModule = 1;
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/commands/ExampleCommand.h b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/commands/ExampleCommand.h
deleted file mode 100644
index 558fced..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/commands/ExampleCommand.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-class ExampleCommand : public frc::Command {
- public:
- ExampleCommand();
- void Initialize() override;
- void Execute() override;
- bool IsFinished() override;
- void End() override;
- void Interrupted() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/commands/MyAutoCommand.h b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/commands/MyAutoCommand.h
deleted file mode 100644
index f1892a7..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/commands/MyAutoCommand.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Command.h>
-
-class MyAutoCommand : public frc::Command {
- public:
- MyAutoCommand();
- void Initialize() override;
- void Execute() override;
- bool IsFinished() override;
- void End() override;
- void Interrupted() override;
-};
diff --git a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/subsystems/ExampleSubsystem.h b/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/subsystems/ExampleSubsystem.h
deleted file mode 100644
index 0f7d470..0000000
--- a/wpilibcExamples/src/main/cpp/templates/oldcommandbased/include/subsystems/ExampleSubsystem.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
-
-#pragma once
-
-#include <frc/commands/Subsystem.h>
-
-class ExampleSubsystem : public frc::Subsystem {
- public:
- ExampleSubsystem();
- void InitDefaultCommand() override;
-
- private:
- // It's desirable that everything possible under private except
- // for methods that implement subsystem capabilities
-};
diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp
index 4bfae1f..29bae0b 100644
--- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -24,8 +21,6 @@
void Robot::Test() {}
void Robot::StartCompetition() {
- auto& lw = *frc::LiveWindow::GetInstance();
-
RobotInit();
// Tell the DS that the robot is ready to be enabled
@@ -33,35 +28,47 @@
while (!m_exit) {
if (IsDisabled()) {
- m_ds.InDisabled(true);
+ frc::DriverStation::InDisabled(true);
Disabled();
- m_ds.InDisabled(false);
- while (IsDisabled()) m_ds.WaitForData();
+ frc::DriverStation::InDisabled(false);
+ while (IsDisabled()) {
+ frc::DriverStation::WaitForData();
+ }
} else if (IsAutonomous()) {
- m_ds.InAutonomous(true);
+ frc::DriverStation::InAutonomous(true);
Autonomous();
- m_ds.InAutonomous(false);
- while (IsAutonomousEnabled()) m_ds.WaitForData();
+ frc::DriverStation::InAutonomous(false);
+ while (IsAutonomousEnabled()) {
+ frc::DriverStation::WaitForData();
+ }
} else if (IsTest()) {
- lw.SetEnabled(true);
+ frc::LiveWindow::SetEnabled(true);
frc::Shuffleboard::EnableActuatorWidgets();
- m_ds.InTest(true);
+ frc::DriverStation::InTest(true);
Test();
- m_ds.InTest(false);
- while (IsTest() && IsEnabled()) m_ds.WaitForData();
- lw.SetEnabled(false);
+ frc::DriverStation::InTest(false);
+ while (IsTest() && IsEnabled()) {
+ frc::DriverStation::WaitForData();
+ }
+ frc::LiveWindow::SetEnabled(false);
frc::Shuffleboard::DisableActuatorWidgets();
} else {
- m_ds.InOperatorControl(true);
+ frc::DriverStation::InTeleop(true);
Teleop();
- m_ds.InOperatorControl(false);
- while (IsOperatorControlEnabled()) m_ds.WaitForData();
+ frc::DriverStation::InTeleop(false);
+ while (IsTeleopEnabled()) {
+ frc::DriverStation::WaitForData();
+ }
}
}
}
-void Robot::EndCompetition() { m_exit = true; }
+void Robot::EndCompetition() {
+ m_exit = true;
+}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.h
index 0057778..9b63fb2 100644
--- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/templates/templates.json b/wpilibcExamples/src/main/cpp/templates/templates.json
index c31d41c..59d4084 100644
--- a/wpilibcExamples/src/main/cpp/templates/templates.json
+++ b/wpilibcExamples/src/main/cpp/templates/templates.json
@@ -7,7 +7,7 @@
],
"foldername": "timed",
"gradlebase": "cpp",
- "commandversion": 1
+ "commandversion": 2
},
{
"name": "Timed Skeleton (Advanced)",
@@ -17,7 +17,7 @@
],
"foldername": "timedskeleton",
"gradlebase": "cpp",
- "commandversion": 1
+ "commandversion": 2
},
{
"name": "RobotBase Skeleton (Advanced)",
@@ -27,7 +27,7 @@
],
"foldername": "robotbaseskeleton",
"gradlebase": "cpp",
- "commandversion": 1
+ "commandversion": 2
},
{
"name": "Command Robot",
@@ -40,13 +40,23 @@
"commandversion": 2
},
{
- "name": "Old Command Robot",
- "description": "Old-Command style (deprecated)",
+ "name": "Romi - Timed Robot",
+ "description": "Romi - Timed style",
"tags": [
- "Command"
+ "Timed", "Romi"
],
- "foldername": "oldcommandbased",
- "gradlebase": "cpp",
- "commandversion": 1
+ "foldername": "timed",
+ "gradlebase": "cppromi",
+ "commandversion": 2
+ },
+ {
+ "name": "Romi - Command Robot",
+ "description": "Romi - Command style",
+ "tags": [
+ "Command", "Romi"
+ ],
+ "foldername": "commandbased",
+ "gradlebase": "cppromi",
+ "commandversion": 2
}
]
diff --git a/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp
index dfb6993..577de89 100644
--- a/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp
@@ -1,13 +1,10 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
-#include <iostream>
+#include <fmt/core.h>
#include <frc/smartdashboard/SmartDashboard.h>
@@ -42,7 +39,7 @@
m_autoSelected = m_chooser.GetSelected();
// m_autoSelected = SmartDashboard::GetString("Auto Selector",
// kAutoNameDefault);
- std::cout << "Auto selected: " << m_autoSelected << std::endl;
+ fmt::print("Auto selected: {}\n", m_autoSelected);
if (m_autoSelected == kAutoNameCustom) {
// Custom Auto goes here
@@ -72,5 +69,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.h
index fe4ea1f..b887605 100644
--- a/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
diff --git a/wpilibcExamples/src/main/cpp/templates/timedskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/timedskeleton/cpp/Robot.cpp
index 425fa84..92f5df1 100644
--- a/wpilibcExamples/src/main/cpp/templates/timedskeleton/cpp/Robot.cpp
+++ b/wpilibcExamples/src/main/cpp/templates/timedskeleton/cpp/Robot.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "Robot.h"
@@ -23,5 +20,7 @@
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
-int main() { return frc::StartRobot<Robot>(); }
+int main() {
+ return frc::StartRobot<Robot>();
+}
#endif
diff --git a/wpilibcExamples/src/main/cpp/templates/timedskeleton/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/timedskeleton/include/Robot.h
index d4bcbb6..99f84f7 100644
--- a/wpilibcExamples/src/main/cpp/templates/timedskeleton/include/Robot.h
+++ b/wpilibcExamples/src/main/cpp/templates/timedskeleton/include/Robot.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once