Commit Graph

340 Commits

Author SHA1 Message Date
Tyler Veness
c2259d42a8 [wpilib] Add Toggle() function to solenoid classes (#2635)
Toggling a solenoid on a button press is a common idiom, so this
provides a more readable way of accomplishing that.
2020-08-15 08:16:32 -07:00
Peter Johnson
42993b15c6 [wpimath] Move math functionality into new wpimath library (#2629)
The wpimath library is a new library designed to separate the reusable math functionality
from the common utility library (wpiutil) and the hardware-dependent library (wpilibc/j).

Package names / include file names were NOT changed to minimize breakage.  In a future year
it would be good to revamp these for a more uniform user experience and to reduce the risk
of accidental naming conflicts.

While theoretically all of this functionality could be placed into wpiutil, several pieces
of this library (e.g. DARE) are very time-consuming to compile, so it's nice to avoid this
expense for users who only want cscore or ntcore.  It also allows for easy future separation
of build tasks vs number of workers on memory-constrained machines.

This moves the following functionality from wpiutil into wpimath:
- Eigen
- ejml
- Drake
- DARE
- wpiutil.math package (Matrix etc)
- units

And the following functionality from wpilibc/j into wpimath:
- Geometry
- Kinematics
- Spline
- Trajectory
- LinearFilter
- MedianFilter
- Feed-forward controllers
2020-08-06 23:57:39 -07:00
Gabe Deml
ceea1f9d44 [sim] Add Mechanism2D to Simulation GUI (#2607) 2020-08-03 22:38:12 -07:00
Prateek Machiraju
5ca2702083 [wpilib] Add HolonomicDriveController class and tests 2020-08-02 00:03:21 -07:00
Peter Johnson
23ba3ca19e [wpilib] Change Watchdog to use HAL notifier (#2602)
This makes it follow simulation timing instead of wall clock time.
2020-07-21 22:58:16 -07:00
Peter Johnson
9778445a74 [sim] Change stepTiming to take seconds (#2599)
This is consistent with other WPILib timer functions.
2020-07-16 22:15:59 -07:00
Peter Johnson
c2cc90b27d [sim] Move WPILib C++ sim implementations out of line (#2598)
This makes the sim classes consistent with the rest of the WPILibC classes.
2020-07-15 23:48:09 -07:00
Peter Johnson
16ef372b53 [hal] Merge WaitForCachedData into WaitForDSData (#2587)
Remove WaitForCachedData as it's no longer required.

Also properly handle caching / transition detection logic that occurs at the
WPILib level.

This also changes DriverStation::IsNewControlData() to check for WPILib-level
caching instead of wrapping the HAL function.
2020-07-13 21:57:54 -07:00
Prateek Machiraju
ac4b0a3118 [wpilib] AnalogPotentiometer: Use average voltage (#2583)
Using GetAverageVoltage will reduce the noise in potentiometer reading. Potentiometers are unlikely to be used where the minimal lag averaging introduces would impact control loop stability.
2020-07-09 21:29:23 -07:00
Prateek Machiraju
b3b2aa6359 [wpilib] Fix SplineHelper cubic spline bug (#2572) 2020-07-05 22:13:28 -07:00
Peter Johnson
3050e935a1 [sim] Add WPILib-class-taking constructors (#2538)
When not direct mapped, make index constructors private and add factory
functions for channel and index.

Co-authored-by: GabrielDeml <gabrielddeml@gmail.com>
2020-07-04 10:10:43 -07:00
Tyler Veness
a3881bb452 [wpilibc] Add implicit conversion from degree_t to Rotation2d (#2564)
There's already an implicit conversion for radian_t, but there's no
implicit conversion from degree_t to radian_t.
2020-07-03 21:58:19 -07:00
Tyler Veness
2a0f79b90f [wpilib] Add X and Y component getters to Pose2d and Transform2d (#2563)
pose.Translation().X() and pose.Translation.Y() are common operations,
so shortening them to pose.X() and pose.Y() would be convenient.

Java uses the getX() convention so that is used instead of X() for Java.
2020-07-02 18:09:36 -07:00
Tyler Veness
d30d1088da [wpiutil] Split units.h into separate headers for each unit (#2551)
Closes #2508.

Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
2020-06-29 22:25:09 -07:00
Peter Johnson
ce3bc91946 [sim] Move Sim classes from HAL to wpilibc/j (#2549)
Also move some things in HAL for consistency.

WAS:
C++:
- C APIs: #include "mockdata/AccelerometerData.h"
- User side class: #include "simulation/AccelerometerSim.h"
Java:
- JNI APIs: hal.sim.mockdata.AccelerometerData (and a few classes in hal.sim)
- User side classes: hal.sim.AccelerometerSim

IS:
C++:
- C APIs: #include "hal/simulation/AccelerometerData.h"
- C++ class: #include "frc/simulation/AccelerometerSim.h"
Java:
- JNI APIs: hal.simulation.AccelerometerData
- User side class: wpilibj.simulation.AccelerometerSim
2020-06-27 22:11:24 -07:00
Tyler Veness
22c0e2813a [build] Upgrade CI to clang-format 10.0 (#1961)
MacOS no longer ships 6.0, and Arch Linux's mesa GPU drivers are no longer compatible with LLVM 6.0.
2020-06-27 20:39:00 -07:00
Prateek Machiraju
762347f005 [wpilibj] Throw separate exception for constraint misbehavior (#2510)
The most common mistake users (including contributors to WPILib) seem to make while creating new constraints is ignoring some sort of edge case that causes the calculated minimum acceleration to be greater than the calculated maximum acceleration.

This specialized exception, with its detailed error message, should make it easier and quicker for said users to debug and fix bugs within their constraints.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2020-06-08 10:38:47 -07:00
sciencewhiz
4b76adf15b [wpilibc] Remove incorrect timer rollover (#2523)
If the 64 bit FPGA timer rolls over, a 32 bit value is added for
the rollover, an artifact of when it was a 32 bit timer.
The 64 bit microsecond timer won't rollover for 500k years so remove the
check for simplicity.
Fixes #2504
2020-06-08 10:37:27 -07:00
Starlight220
1b395fa21d [wpilib] Implement Trajectory.equals() (#2517) 2020-05-27 20:43:32 -07:00
Starlight220
27f9a21a2c [wpilib] Moved Watchdog output to reportWarning() (#2413) 2020-05-20 20:57:06 -07:00
Prateek Machiraju
e5935a4737 [wpilibc] Fix const-qualification in kinematics and constraints (#2478) 2020-04-13 22:32:25 -07:00
Prateek Machiraju
a3a8472b82 [wpilib] Trajectory: Add MaxVelocity and Region constraints (#2466)
Co-Authored-By: Tyler Veness <calcmogul@gmail.com>
2020-04-12 10:39:43 -07:00
Tyler Veness
fac4e3fcfc [wpilibc] Add real-time priority constructor to Notifier (#2303)
Using this overload makes the thread backing the Notifier run at
real-time priority. This improves scheduling jitter substantially (5ms
+- 2ms down to 5ms +- 1ms).

A version isn't provided for Java because making threads real-time can
cause GC deadlocks.
2020-04-05 23:26:23 -07:00
Peter Johnson
b46b5df16a [wpilibc] Output Tracer to DriverStation by default (#2469)
This matches the Java behavior.

Also optimizes Java to only create a StringBuffer and call
DriverStation.reportWarning if there is data to output.
2020-04-05 23:09:21 -07:00
Prateek Machiraju
cb51029335 [wpilib] Add Color.fromHSV() static helper (#2461)
Keep AddressableLEDBuffer.setHSV() implementation separate in Java
for performance reasons.
2020-04-05 23:08:52 -07:00
Peter Johnson
576d427f03 [wpilib] SpeedControllerGroup: Add vector-taking constructor (#2194)
This allows the list to be constructed dynamically.

Co-authored-by: Thad House <thadhouse1@gmail.com>
2020-04-03 08:39:57 -07:00
Prateek Machiraju
a308dd4471 [wpilib] Fix SplineHelper quintic spline generation bug (#2429) 2020-04-01 20:31:29 -07:00
Prateek Machiraju
8f33d21bc2 [wpilib] Add init methods to Preferences (#2443) 2020-04-01 20:26:49 -07:00
Prateek Machiraju
b9ee3ae030 [wpilibc] Refactor Tracer functionality out of Watchdog class (#2456) 2020-04-01 20:10:28 -07:00
Prateek Machiraju
1c28b729ad Move curvature_t to units namespace (#2444)
Note: this is a breaking change.
2020-03-22 22:57:52 -07:00
Joshua Shannon
272eaf184f DutyCycleEncoder: Fix simulation support (#2387)
The DutyCycleEncoder class initializes AnalogTrigger, which is not supported in simulation.

To avoid this, do not use AnalogTrigger (or Counter) in simulation mode.

Fixes #2367

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2020-03-20 14:32:52 -07:00
Tyler Veness
4228d3609e Fix Watchdog epoch prints being off by three orders of magnitude (#2414)
This was caused by m_epochs storing the timestamps as nanoseconds while
the epoch printing code expects microseconds. Adding a duration cast
fixes this.

Java stores the epoch timestamps in a double as microseconds, so it
doesn't exhibit this bug. The comments were updated to make this more
obvious.

Fixes #2392.
2020-03-15 19:56:08 -07:00
Tyler Veness
84e300739c Fix ProfiledPIDController profile direction for continuous input (#2279)
Previously, it could take the long way around. This recomputes the
profile goal with the shortest error, thus taking the shortest path.

Also removed the setpoint clamping from PIDController::SetSetpoint()
because it's unnecessary to make PIDController behave correctly for
a modular arithmetic input, and it breaks the setpoint calculation in
ProfiledPIDController otherwise.

Fixes #2277.
2020-03-14 22:13:57 -07:00
Peter Johnson
5a1acaaefc Update copyright dates for #2121 (#2415) 2020-03-14 22:11:36 -07:00
Joshua Shannon
4fd7c210d8 Shuffleboard: Fixed mix up of title and type parameters (#2121) 2020-03-14 22:06:57 -07:00
Tyler Veness
3be83784cd Add Transform2d::Inverse() (#2407)
This is useful for undoing transformations. One application my FRC team
found was converting perspective n-point data from a "camera to target"
coordinate frame transformation to a "target to camera" coordinate frame
transformation.
2020-03-14 22:01:52 -07:00
Tyler Veness
b6c163acd7 Const-qualify frc2::Timer::HasElapsed() (#2397) 2020-02-29 20:12:31 -08:00
Dustin Spicuzza
761f79385a Add SimulationInit and SimulationPeriodic functions (#2377)
Fixes #2375
2020-02-18 23:05:16 -08:00
Thad House
60c09ea51f Fix notifier race happening with very fast notifiers (#2370)
What would happen is the Stop() call would happen between the notifier loop being triggered and calling UpdateAlarm(). This would cause the Update to overwrite the stop.
2020-02-18 20:38:05 -08:00
Oblarg
65eab93527 Fix DifferentialDriveVoltageConstraint for tight turns w/ zero velocity (#2341) 2020-02-15 12:36:16 -08:00
Oblarg
f0a18f31e7 Timer: add hasElapsed, advanceIfElapsed (#2322)
The current hasPeriodPassed() function is confusing.  In preparation for deprecating it,
add new advanceIfElapsed() function with same functionality and hasElapsed() function
which only checks that the time period has elapsed and does not advance the timer.

Also fix a couple of incorrect usages of hasPeriodPassed().
2020-02-08 10:23:29 -08:00
Vasista Vovveti
29c82527a5 Fix typo in ADXL sim double creation (#2332)
Sets m_simY to the virtual Y acceleration.
2020-02-04 20:15:25 -08:00
Peter Johnson
c165dc5e50 Simulation GUI: Add 2D field view (#2261)
The field image and robot image can be loaded or just a wireframe used.
The robot can be moved and rotated with a mouse click + drag.
The robot position is settable in robot code via the Field2d class.
2020-02-01 21:30:23 -08:00
Declan Freeman-Gleason
ff5d3e5b36 RamseteController: Add setEnabled method (#2313) 2020-01-27 21:53:00 -08:00
Prateek Machiraju
558c020cca Fix duplicated state when using quintic splines (#2307)
Generating a trajectory using quintic splines caused a duplicated state at all knot points.
2020-01-24 23:10:28 -08:00
Peter Johnson
d0cf4e8882 Change sim Filesystem.getDeployDirectory() to src/main/deploy (#2293) 2020-01-19 16:34:45 -08:00
Peter Johnson
b1357cace7 Fix LiveWindow SetEnabled C++ std::bad_function_call (#2281)
It was missing a null check.
2020-01-16 00:34:51 -08:00
Thad House
37202b6f28 Add missing SensorUtil::kAnalogOutputs (#2276) 2020-01-15 21:34:28 -08:00
Peter Johnson
dcb96cb50c TrajectoryGenerator: Allow replacement of error reporting function (C++) (#2267)
C++ version of #2234.
2020-01-13 20:36:16 -08:00
Austin Shalit
ee8475d21f Run wpiformat (#2270) 2020-01-13 12:19:08 -08:00