Commit Graph

71 Commits

Author SHA1 Message Date
Peter Johnson
764ada9b66 [hal] Change usage reporting to string-based (#7763) 2025-02-07 13:37:23 -07:00
Thad House
ad29d45dfb [hal] Remove HAL_GetPort (#7754) 2025-01-30 19:59:34 -07:00
Thad House
6e704370b3 [hal, wpilib] Remove DigitalSource and AnalogTrigger (#7753) 2025-01-30 19:58:21 -07:00
Thad House
5898cdd5c3 [hal, wpilib] Remove interrupt (#7724) 2025-01-23 21:45:18 -08:00
Thad House
5a6c895b87 [hal, wpilib] Remove built in accelerometer (#7702) 2025-01-17 14:06:09 -08:00
Thad House
f80874dd4b [hal, wpilib] Remove analog accumulator and analog gyro (#7697)
The 2 high level classes were temporarily kept to keep the examples compiling. We will remove those when we have the interface into the built in IMU.
2025-01-17 12:58:31 -08:00
Thad House
92f0a3c961 [hal, wpilib] Remove SPI support (#7678) 2025-01-17 00:22:29 -08:00
Thad House
ff1b2a205e [hal, wpilib] Remove analog output (#7696) 2025-01-16 23:20:44 -08:00
Thad House
5017393b3a [hal, wpilib] Remove relay (#7695) 2025-01-16 23:20:07 -08:00
Gold856
12885015ed [cscore,hal] Remove VS 2019 16.4.0 workaround (#7201) 2024-10-11 22:18:12 -07:00
Tyler Veness
554024767e Fix errors from new cpplint.py (#7105) 2024-09-20 17:43:39 -07:00
Ryan Blue
19b478a33b [hal] Expose more FPGA functionality (#6942)
- function to reset user rail fault counters
- function to get comms disable count
- correct docs for user rail count functions
2024-08-10 23:25:02 -07:00
Ryan Blue
ecfd3861e8 [hal] Fix Java sim timing on Windows (#6910)
Also set power throttling options correctly.
2024-08-02 18:56:58 -07:00
Peter Johnson
caf424e09c [hal] Windows sim: enable High QOS and honor timer resolution requests (#6908)
By default on Windows 11, power throttling will increase timer resolution
if a window is occluded.  Disable that behavior.  Also enable high QOS to
achieve maximum performance and turn off power saving.

Also use internal APIs to set timer precision to 500 us if available.
2024-08-01 19:51:02 -07:00
Thad House
4ce8f3f935 Change C APIs to a unified string implementation (#6299)
Currently in the entire C API of WPILib we have ~8 different ways of handling strings. The C API actually isn't built for pure C callers (We don't actually have any of those). Instead, they're built for interop between languages like LabVIEW and C# which can talk to C API's directly.

For output parameters, the choice was fairly obvious. An output struct containing a const string pointer and a length makes the most sense. Its easy to use these from most other languages, and doesn't require special null termination handling. Freeing these is also easy, as if you ever receive one of these string structures, theres just a single function call to free it.

Input parameters are a bit more complex. To be used from pure C, and from LabVIEW, a null terminated string is the best in most cases. However, null terminated strings in general have a lot of downsides. Additionally, from LabVIEW there are other considerations around encoding that having a wrapper struct helps make a bit easier. From a language like C#, a wrapper struct is by far the easiest, as custom marshalling can make it trivial to marshal both UTF8 and UTF16 strings down.

The final consideration is its nice to have an identical concept for both input and output. It makes the rules fairly easy to understand.

WPILib will not have any APIs that manipulate a string allocated externally. This means WPI_String can be const, as across the boundary it is always const.
If a WPILib API takes a const WPI_String*, WPILib will not manipulate or attempt to free that string, and that string is treated as an input. It is up to the caller to handle that memory, WPILib will never hold onto that memory longer than the call.
If a WPILib API takes a WPI_String*, that string is an output. WPILib will allocate that API with WPI_AllocateString(), fill in the string, and return to the caller. When the caller is done with the string, they must free it with WPI_FreeString().
If an output struct contains a WPI_String member, that member is considered read only, and should not be explicitly freed. The caller should call the free function for that struct.
If an array of WPI_Strings are returned, each individual string is considered read only, and should not be explicitly freed. The free function for that array should be called by the caller.
If an input struct containing a WPI_String, or an input array of WPI_Strings is passed to WPILib, the individual strings will not be manipulated or freed by WPILib, and the caller owns and should free that memory.
Callbacks also follow these rules. The most common is a callback either getting passed a const WPI_String* or a struct containing a WPI_String. In both of these cases, the callback target should consider these strings read only, and not attempt to free them or manipulate them.
2024-05-13 05:35:14 -07:00
PJ Reiniger
2676b77873 Fix compilation issues that occur when building with bazel (#6008) 2023-12-04 21:18:26 -08:00
Peter Johnson
d404af5f24 [wpilib] RobotController: Add isSystemTimeValid() (#5696)
This returns true when the system date/time (wall clock) is valid.
2023-09-30 09:22:51 -07:00
Ryan Blue
ac23f92451 [hal] Add GetTeamNumber (#5596) 2023-09-01 23:34:18 -07:00
Ryan Blue
463a90f1df [wpilib, hal] Add function to read the RSL state (#5312) 2023-05-12 21:30:19 -07:00
Ryan Blue
2ac41f3edc [hal, wpilib] Add RobotController.getComments() (#4463) 2022-12-26 11:39:51 -08:00
Ryan Blue
5a52b51443 [hal] Add RobotController.getSerialNumber() (#4783) 2022-12-08 21:58:55 -08:00
Thad House
4a401b89d7 [hal, wpilib] New DS thread model and implementation (#3787)
The current DS thread model has some pretty major issues. It makes it difficult to know if all data is from the same remote packet, and if the data changes while the robot loop is running. Additionally, the DS thread is used for a few other things (MotorSafety and State Tracking for EducationalRobot). This also makes sim difficult, as user code has to wait for the thread to know it has new data.

This change completely rethinks how threading works in the driver station model.

First, the DS HAL system receives a new data callback, either from Netcomm or DriverStationSim. Inside the context of this callback, all the low latency data is read and put into a cache. Doing some investigation on the robot side, this is perfectly safe to do, and also ensures a ds packet will not be parsed before we finish reading the current packet data.

After all data is read, the cache is swapped with a 2nd buffer. This buffer just stores the data, none of the HAL DS calls read from this buffer. An event is then fired, stating there is new data ready to go.

Robot code calls HAL_UpdateDSData(). This swaps the 2nd buffer with a 3rd buffer, which always contains the current data. This data will not be updated until HAL_UpdateDSData is called again. Which solves the state problem.

The high level driver station classes have. an updateData() call, which calls HAL_UpdateDSData, and then update button state variables, then data log and update the NT FMS data table (Java also caches across the JNI boundary here, but that could trivially be removed). An extra event provider is provided, allowing other threads to know when this call has been completed.

IterativeRobotBase calls DS.updateData() at the beginning of each loop, and only once per loop. This means all commands will always have the same state.

All of this means there is no longer a DS thread. Everything happens synchronously. This means Sim and testing is easier, as you can just call DriverStationSim.NotifyNewData(), and then DriverStation.UpdateData(), and you can guarantee that all the DriverStation.*** data is up to date.

As for Motor Safety and Educational Robot State Handling, those can all be handled by their own threads. The Educational Thread only needs to run under EducationalRobot, and MotorSafety will only be started if there is a motor safety object enabled.
2022-10-21 22:01:55 -07:00
Dustin Spicuzza
f88c435dd0 [hal] Add mechanism to cancel all periodic callbacks (#4049) 2022-02-23 09:46:01 -08:00
Tyler Veness
4647d09b50 [docs] Fix Doxygen warnings, add CI docs lint job (#3639)
The CI docs lint build is configured to fail on Doxygen warnings.
2021-10-14 18:09:38 -07:00
Thad House
10f19e6fc3 [hal, wpilib] Add REV PneumaticsHub (#3600) 2021-10-10 20:04:50 -07:00
Thad House
d347928e4d [hal] Use better error for when console out is enabled while attempting to use onboard serial port (#3622) 2021-10-10 15:52:50 -07:00
Thad House
66abb39880 [hal] Update runtime enum to allow selecting roborio 2 (#3565)
In some cases, knowing roborio 2 might be useful. This also creates a higher level enum that might be usable later for the discussion on more complex runtime types.
2021-09-13 22:05:38 -07:00
Thad House
1ac73a247e [hal] Rename PowerDistributionPanel to PowerDistribution (#3466)
Makes HAL more generic for the PDP, to enable the Rev PDH in the future.
2021-08-04 20:31:17 -07:00
Peter Johnson
b2c3b2dd8e Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed
- Logging now uses fmtlib style formatting
- Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or
std::puts()/std::fputs() (for unformatted strings).
- A wpi/fmt/raw_ostream.h header has been added to enable
fmt::print() with wpi::raw_ostream
2021-06-06 16:13:58 -07:00
Thad House
0e702eb799 [hal] Add a unified PCM object (#3331) 2021-06-05 22:36:39 -07:00
Thad House
5127380727 [hal] Add HAL_GetLastError to enable better error messages from HAL calls (#3320)
This uses thread local storage so a full error string can be provided, not just an error code.
2021-04-29 09:56:54 -07:00
Peter Johnson
6131f4e32b clang-tidy: modernize-concat-nested-namespaces (NFC) 2020-12-29 14:26:19 -08:00
Peter Johnson
2aed432b4b Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
2020-12-28 12:58:06 -08:00
Peter Johnson
8f1f64ffb6 Remove year from file copyright message (NFC) (#2972)
Also update copyright to include "and other WPILib contributors" and clarify
license referral language to not be restricted to FIRST teams.
2020-12-26 14:12:05 -08:00
Peter Johnson
339d7445b3 [sim] Add HAL hooks for simulationPeriodic (#2881)
This allows vendor libs to hook into the begin or end of simulationPeriodic().
2020-11-30 23:55:36 -08:00
Peter Johnson
f1b1bdb121 [hal] Add HAL_Shutdown and simulation shutdown callbacks
This is useful for clean shutdown of simulation extensions.
2020-09-04 16:26:09 -07:00
Peter Johnson
e127bac7fd [sim] Properly initialize AnalogTrigger (#2646) 2020-08-19 21:58:07 -07:00
Peter Johnson
5bd2dca463 [sim] Move HAL_LoadExtensions to end of HAL_Initialize (#2571)
Previously, HAL_InitializeDriverStation would reset any callbacks set in
extensions during load.
2020-07-05 22:12:12 -07:00
Vasista Vovveti
dac0e5b133 [sim] Set Windows timer precision to 1ms (#2557) 2020-06-28 17:45:40 -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
Peter Johnson
629e8b41f2 [sim] Provide method to set the runtime type (#2539)
This is needed for extensions that effectively access real hardware and
want to disable the "simulation" parts of user code.
2020-06-26 20:46:13 -07:00
Thad House
cf20b068ca [sim] Map HAL_GetSystemActive to HALSIM_GetDriverStationEnabled (#2501)
Vendors have requested this for testing purposes.
2020-05-01 09:05:54 -07:00
Thad House
2a968df779 Add method for releasing a waiting interrupt (#2347)
Useful for a new high level interrupt implementation.
2020-02-18 20:41:42 -08:00
Thad House
6f6c6da9f5 Updates to addressable LED (#2098)
Only PWM Headers are supported, so enforce that.

Also fixes some init checks and init order checks.
2019-11-18 15:25:04 -08:00
Peter Johnson
a4c9e4ec28 Add AddressableLED simulation support 2019-11-18 00:51:59 -08:00
Thad House
82b2170feb Add DMA support to HAL and WPILibC (#2080) 2019-11-14 22:52:34 -08:00
Thad House
326aecc9a0 Add error message for CAN Write Overrun (#2062) 2019-11-08 22:51:11 -08:00
Thad House
1d695a1660 Add FPGA Duty Cycle support (#1987) 2019-11-01 23:41:30 -07:00
Peter Johnson
81c2c8a7de Add simulation generic device/value support
This allows high-level library classes to implement enhanced simulation
support even if no low-level corresponding simulation library exists, and
avoids the need for bit-banging complex interfaces like SPI or CAN.
2019-10-05 22:39:00 -07:00
Peter Johnson
b23baf611a Add ability to run robot main loop in a separate thread (#1895)
Default behavior is still to run the robot main loop in the main thread.

The ability to run the robot main loop in a separate thread and add a hook
for running a different function in the main thread is needed for simulation
GUI support on some platforms.
2019-09-28 15:43:24 -07:00