Commit Graph

292 Commits

Author SHA1 Message Date
Joseph Eng
1f3ef019ce [wpiutil] Return wpi::expected from MemoryBuffer::GetFile (#7069) 2024-09-12 23:45:35 -07:00
Gold856
dc25c13051 [build] CMake: remove redundant logic (#6971) 2024-08-15 21:36:45 -07:00
PJ Reiniger
6922b9dd5e [upstream_utils] Add imgui and friends (#6822) 2024-07-20 22:11:54 -07:00
Wispy
7d64d4e24c [sim] Add GUI support for the REV PH (#6704) 2024-07-15 17:28:05 -07:00
Gold856
cd6b70af0e [docs] Add documentation for simulation extensions (#6729) 2024-07-15 17:26:25 -07:00
Jade
6b9d41182f [sim] Fix WS sending 1 and 0 instead of booleans (#6836) 2024-07-15 10:17:35 -07:00
Gold856
bf75c03218 [build] Clean up CMake files (#6802)
Explicitly list required components when using FindJava and FindJNI
Consolidate find_package calls for Java, JNI, and OpenCV into the root CMakeLists.txt file
Remove references to main_lib_dest
Install missing generated headers
Flatten some if statements
Use LinkMacOSGUI macro instead of hand rolling it
Stop installing OpenCV libraries and an extra ntcorejni library; OpenCV JAR will still be installed to make it easy to use
Only print platform version on Windows
Prevent GUI modules from being built when wpimath is off, which would otherwise cause a build failure
Simplify build configuration checks
Clean up fieldImages JAR creation
Place built JARs in the same subdir as installed JARs
Remove unnecessary JAR includes
Remove extra directories in target_include_directories
Improve CMake docs
2024-07-11 16:01:05 -06:00
Tyler Veness
19ea73ef69 [upstream_utils] Upgrade to fmtlib 11.0.0 (#6796) 2024-07-02 13:34:59 -07:00
beardedone55
7366a03fc9 [xrp] Add Support for Encoder Period on XRP (#6795)
The XRP firmware has been updated to provide the
encoder period along with the encoder count.

This change allows WPILIB to use the encoder period
data from the XRP so that the GetRate function can
be used to determine the motor speed.
2024-07-02 13:29:52 -07:00
Wispy
ca92ef89d3 [sim] Don't send joystick data during auto (#6732)
Testing on a Rio showed that the joystick inputs are not zeroed, they just don't update.
2024-06-21 20:56:23 -07:00
Joseph Eng
d6b66bfa55 [wpiutil] Add remove_prefix() and remove_suffix() (#6118) 2024-06-04 21:01:52 -07:00
CoolSpy3
c1fc86033a [sim] Clarify Sim CAN Device Documentation (#6679) 2024-05-30 05:32:45 -07:00
CoolSpy3
a6ac4228c3 [sim] WebSockets Documentation Fixes (#6668) 2024-05-27 06:52:25 -07:00
CoolSpy3
98fcbdb44e [sim] Update WebSockets API Specification (#6664)
Also update AddressableLED data to be output instead of input.
2024-05-26 14:58:32 -07:00
Dean Brettle
237ebfd0f2 [sim] Add CAN message schema to wpilib-ws.yaml and add 2 CANMotor props (#6651)
Co-authored-by: CoolSpy3 <coolspythree@gmail.com>
2024-05-24 12:56:34 -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
Tyler Veness
d88c71ffdc [wpiutil] Upgrade to fmt 10.2.1, add wpi::print (#6161)
We now use a wrapper (wpi::print) to catch exceptions since we can't patch
std::print() to not throw when we ultimately migrate to it.

fmtlib and std format/print throw the same exceptions and always have. We previously patched fmt::print() to not throw a write failure exception, but we can't do that for std::print(); wpi::print() is the migration plan.
2024-05-12 06:25:42 -07:00
Tyler Veness
74f648689e [build] Add exports to CMake subprojects (#6505)
This allows consuming allwpilib via FetchContent.
2024-04-10 22:04:22 -07:00
Peter Johnson
fbd239d15e [sim] GUI: Use shift to enable docking features (#6429) 2024-03-10 20:29:20 -07:00
Peter Johnson
3928ed5647 [sim] Sim GUI DS: Add "Disconnected" state and start in it (#6218)
The default state for the DS in the simulated HAL is changed to disconnected.

The FMS view is now only editable in DS disconnected state.

This enables more robot and field-like testing of robot code, as the
alliance color and other parameters start in invalid states and are
only set when the DS connects.
2024-01-20 21:10:02 -08:00
Gold856
66172ab288 Remove submodule (#6003) 2023-12-03 16:18:45 -08:00
Gold856
890992a849 [hal] Commit generated usage reporting files (#5993) 2023-12-03 15:53:24 -08:00
Tyler Veness
ca272de400 [build] Fix Gradle compile_commands.json and clang-tidy warnings (#5977) 2023-12-02 21:20:43 -08:00
Gold856
4fcf0b25a1 [build] Apply a formatter for CMake files (#5973) 2023-11-30 16:52:21 -08:00
Ryan Blue
33e0089afb Cleanup usages of std::function<void(void)> (#5864) 2023-11-03 18:22:47 -07:00
Gold856
80c47da237 [sim] Disable the robot program when DS disconnects (#5818) 2023-10-28 10:10:23 -07:00
Gold856
cfc6a47f76 [sim] DS plugin: Fix off-by-one error when setting alliance station (#5819) 2023-10-24 09:15:40 -07:00
sciencewhiz
f4cbcbc984 Fix typos (NFC) (#5804) 2023-10-23 09:15:58 -07:00
Tyler Veness
5f651df5d5 [build] Clean up Gradle configs (#5685)
Putting an early exit if statement at the top instead of wrapping the
whole file contents unbreaks unit test configs, as was discovered for
SysId. It reduces nesting as well.

Unused plugins were removed from the beginnings of files as well.
2023-09-27 21:45:25 -07:00
PJ Reiniger
dd5612fbee [json] Add forward definition header (#5676) 2023-09-22 13:01:27 -07:00
Tyler Veness
5ab54ff760 Replace wpi::raw_istream with wpi::MemoryBuffer (#5675)
Instances of wpi::raw_istream were left that are reading incrementally
from file descriptors like USB devices.
2023-09-21 23:20:09 -07:00
Tyler Veness
1b6ec5a95d [wpiutil] Upgrade to LLVM 17.0.1 (#5482) 2023-09-21 19:54:33 -07:00
Tyler Veness
17f1062885 Replace std::snprintf() with wpi::format_to_n_c_str() (#5645)
fmtlib uses consteval format string processing, which makes it more
efficient than std::snprintf().

snprintf()s in libuv, mpack, processstarter, and wpigui were left alone.
processstarter uses stdlib only, and wpigui only depends on imgui.

fmt::format_to_n() is analogous to std::format_to_n()
(https://en.cppreference.com/w/cpp/utility/format/format_to_n)

wpi::format_to_n_c_str() is a wrapper which adds the trailing NUL.
2023-09-17 20:00:16 -07:00
autoantwort
cb99517838 [build] cmake: Use default install location on windows for dlls (#5580) 2023-09-17 16:17:32 -07:00
Zhiquan Yeo
9047682202 [sim] Add XRP-specific plugin (#5631)
Provides an implementation of a XRP-specific plugin that sends binary messages over UDP (to account for the less performant hardware on the XRP).

This plugin leverages the work already done for the WebSocket protocol and does a translation to/from JSON/binary.
2023-09-15 20:08:02 -07:00
Tyler Veness
8e2a7fd306 Include thirdparty libraries with angle brackets (#5578) 2023-08-28 15:13:34 -07:00
Thad House
fc56f8049a [wpilib] DriverStation: Change alliance station to use optional (#5229)
Many teams have issues trying to read the DS too early. By switching to an optional, we cause teams to check 2 things. Either 1) they explicitly check, and their code is correct, or 2) they just read .value() and their code reboots in a loop. However, because the DS will eventually connect, this 2nd case is ok, and should theoretically be undetectable on the field.
2023-07-22 15:19:28 -07:00
Tyler Veness
1af224c21b Add missing <functional> includes (#5459) 2023-07-18 21:18:32 -07:00
Thad House
c1a01569b4 [wpilib][hal] PWM Raw using microseconds (#5283)
Co-authored-by: Joe <sciencewhiz@users.noreply.github.com>
2023-06-22 19:43:16 -07:00
Zhiquan Yeo
c4dc697192 [hal] WS Simulation: Add message filtering capability (#5395) 2023-06-20 08:26:03 -07:00
Tyler Veness
5fac18ff4a Update formatting to clang-format 16 (#5370) 2023-05-31 22:10:53 -07:00
Peter Johnson
27fb47ab10 [glass] Field2D: Embed standard field images (#5159) 2023-05-12 21:31:38 -07:00
Peter Johnson
83ef8f9658 [simulation] GUI: Fix buffer overflow in joystick axes copy (#5036)
This was using an incorrect sizeof which would copy excessive data and
overwrite the button data.
2023-01-31 23:40:22 -08:00
Peter Johnson
cb9b8938af [sim] Enable docking in the GUI (#4960) 2023-01-18 20:42:58 -08:00
Ryan Blue
bde383f763 [hal] Replace const char* with std::string_view in Driver Station sim functions (#4532) 2022-12-09 13:10:23 -08:00
Jordan McMichael
8618dd4160 [glass, wpilib] Replace remaining references to Speed Controller with Motor Controller (#4769) 2022-12-05 20:06:43 -08:00
Tyler Veness
23bfc2d9ab [sim] Remove unmaintained Gazebo support (#4736) 2022-12-01 20:46:47 -08:00
Thad House
5e74ff26d8 [apriltag, build] Update native utils, add apriltag impl and JNI (#4733)
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
2022-11-30 00:16:29 -08:00
Thad House
648ab6115c [wpigui,dlt,glass,ov] Support arm in GUI tools (#4527) 2022-10-26 23:16:23 -07: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