Skip to content

Use MrcLib to talk to DS#8858

Open
ThadHouse wants to merge 29 commits into
wpilibsuite:mainfrom
ThadHouse:mrclibds
Open

Use MrcLib to talk to DS#8858
ThadHouse wants to merge 29 commits into
wpilibsuite:mainfrom
ThadHouse:mrclibds

Conversation

@ThadHouse
Copy link
Copy Markdown
Member

Using MrcLib on the robot is going to be the plan for the future, to make things easier.

MrcLib is how sim is supported going forward. The desktop version of mrclib can act as a robot server.

This is set up where the mrclib interface is in shared code. On robot, that is the only backend used. On desktop, a default sim backend is used. However, the sim plugin can switch that to the real robot backend, so the robot code will exactly look like a real robot.

@ThadHouse ThadHouse requested review from a team as code owners May 6, 2026 00:21
@ThadHouse
Copy link
Copy Markdown
Member Author

Even if this passed, don't merge this yet. Haven't done the console line stuff, nor have I actually tested it on systemcore.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Driver Station communications toward an MrcLib-backed implementation (robot + sim), while also extending the error/crash reporting surface so failures can be reported to the DS consistently across runtimes.

Changes:

  • Added a DS “program crash” reporting path and hooked it into RobotBase exception handling.
  • Refactored HAL DriverStation error/console APIs to use WPI_String and routed DS operations through an MrcLibDs backend (systemcore + sim).
  • Reworked the halsim_ds_socket extension to use mrclib instead of the legacy DS socket packet parsing implementation, and added mrclib build definitions for Gradle/Bazel.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
wpilibj/src/main/java/org/wpilib/framework/RobotBase.java Emits DS crash reports on robot instantiation/runtime exceptions.
wpilibj/src/main/java/org/wpilib/driverstation/internal/DriverStationBackend.java Adds reportCrash() and updates DS error JNI call signature usage.
wpilibj/src/main/java/org/wpilib/driverstation/DriverStationErrors.java Exposes reportCrash() to user code.
wpilibc/src/main/native/include/wpi/framework/RobotBase.hpp Switches to C++ DriverStation wrapper header and new SendError() API.
wpilibc/src/main/native/cpp/system/Notifier.cpp Updates error sending to new C++ SendError() wrapper.
wpilibc/src/main/native/cpp/system/Errors.cpp Updates error sending to new C++ SendError() wrapper.
wpilibc/src/main/native/cpp/simulation/DriverStationSim.cpp Updates HALSim DS callback signatures to WPI_String.
simulation/halsim_ds_socket/src/test/native/cpp/DSCommPacketTest.cpp Removes tests for legacy DS socket packet parser (parser removed).
simulation/halsim_ds_socket/src/main/native/include/wpi/halsim/ds_socket/DsSocket.h Adds placeholder header for packaging.
simulation/halsim_ds_socket/src/main/native/include/wpi/halsim/ds_socket/DSCommPacket.hpp Removes legacy DS packet parser API.
simulation/halsim_ds_socket/src/main/native/include/wpi/halsim/ds_socket/DSCommJoystickPacket.hpp Removes legacy joystick packet struct.
simulation/halsim_ds_socket/src/main/native/cpp/main.cpp Reimplements DS socket extension around mrclib + forced DS backend.
simulation/halsim_ds_socket/src/main/native/cpp/DSCommPacket.cpp Removes legacy DS packet parser implementation.
simulation/CMakeLists.txt Disables building ds_socket via CMake.
shared/libmrclib.gradle Adds mrclib as a Gradle native dependency.
shared/bazel/thirdparty/mrclib/mrclib.MODULE.bazel Adds Bazel http_archives for mrclib artifacts.
shared/bazel/thirdparty/mrclib/BUILD.bazel Adds Bazel cc_import for mrclib shared library.
MODULE.bazel Includes mrclib module definition.
hal/src/main/python/semiwrap/DriverStation.yml Exposes new DS-related HAL functions to python semiwrap.
hal/src/main/python/semiwrap/DriverStation_c.yml Exposes HAL_SendProgramCrash to C semiwrap.
hal/src/main/python/hal/src/hal.cpp Updates to new DriverStation.hpp + WPI_String print callback signature.
hal/src/main/native/systemcore/HALInitializer.hpp Removes legacy FIRST DS init symbol.
hal/src/main/native/systemcore/HAL.cpp Stops calling removed FIRST DS initializer.
hal/src/main/native/systemcore/FIRSTDriverStation.cpp Removes legacy systemcore DS implementation.
hal/src/main/native/systemcore/DriverStation.cpp Provides systemcore default DS backend (mrclib).
hal/src/main/native/sim/HALInitializer.hpp Removes legacy sim DS init symbol.
hal/src/main/native/sim/HAL.cpp Drops redundant HAL_GetSystemTimeValid impl and relies on DS backend.
hal/src/main/native/sim/DriverStation.cpp Reworks sim DS to an MrcLibDs implementation + updated callback signatures.
hal/src/main/native/include/wpi/hal/simulation/MockHooks.h Updates mock hook callback typedefs to WPI_String.
hal/src/main/native/include/wpi/hal/DriverStationTypes.h Adjusts HAL_MatchInfo::eventName sizing.
hal/src/main/native/include/wpi/hal/DriverStation.hpp Adds C++ wrappers for SendError/SendConsoleLine/SendProgramCrash.
hal/src/main/native/include/wpi/hal/DriverStation.h Changes C API signatures to use WPI_String + adds HAL_SendProgramCrash.
hal/src/main/native/include/wpi/hal/cpp/MrcLibDs.hpp Introduces the backend interface for DS implementations.
hal/src/main/native/cpp/mrclib/MrcLibDs.cpp Adds mrclib-backed DS implementation.
hal/src/main/native/cpp/jni/simulation/DriverStationDataJNI.cpp Updates lambdas for new HALSim DS callback signatures.
hal/src/main/native/cpp/jni/HALUtil.cpp Updates HAL error reporting call to new HAL_SendError signature.
hal/src/main/native/cpp/jni/DriverStationJNI.cpp Updates JNI signatures and adds sendProgramCrash.
hal/src/main/native/cpp/FIRSTDriverStation.cpp Adds the HAL entrypoint layer routing calls to the selected DS backend.
hal/src/main/java/org/wpilib/hardware/hal/DriverStationJNI.java Updates sendError signature and adds sendProgramCrash.
hal/build.gradle Wires mrclib into native build dependencies.
hal/BUILD.bazel Adds mrclib dependency for Bazel builds of hal.
glass/src/lib/native/cpp/other/FMS.cpp Updates robot mode string from “Test” to “Utility”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +8
#include <algorithm>
#include <exception>
// the WPILib BSD license file in the root directory of this project.

#include <atomic>
#include <cstdio>
Comment thread hal/src/main/native/cpp/FIRSTDriverStation.cpp
Comment thread hal/src/main/native/cpp/FIRSTDriverStation.cpp
Comment on lines +58 to 59
static std::atomic<bool> gDSConnected = true;

Comment on lines +60 to +66
static void WriteSimBackend() {
MRC_Joysticks joysticks;
MRC_ControlData controlData;

client->data.connect([t](Buffer& buf, size_t len) {
HandleTcpDataStream(buf, len, *t->GetData<DataStore>());
});
client->StartRead();
client->end.connect([c = client.get()] {
c->Close();
gDSConnected = false;
});
});
}
int32_t status =
MRC_DsComms_GetControlDataWithJoysticks(&controlData, &joysticks);
if (status != 0) {
Comment on lines +70 to +71
printf("Control data status: 0x%x\n", controlData.controlFlags);
fflush(stdout);
Comment thread shared/libmrclib.gradle
artifactId = "mrclib-cpp"
headerClassifier = "headers"
ext = "zip"
version = '+'
PeterJohnson pushed a commit that referenced this pull request May 15, 2026
The initial build file generation for robotpy projects was relatively
naive and purpose built to get `allwpilib` compiling, without supporting
all the available features.

This modifies the generation scripts to be able to support multiple
embedded libraries, which will be necessary for #8858, since `mrclib.so`
will need to be bundled along with the hal libraries. In addition some
cleanup was done to get the wheels looking more like what is in pypi.
PeterJohnson pushed a commit that referenced this pull request May 23, 2026
This pulls in the `mrclib` maven repository as shared libraries, as a
prereq for #8858.

Alternative to #8869, which avoids the unnecessary lockfile entry. This
should be a one-to-one replacement for that PR.

Closes #8869

---------

Co-authored-by: PJ Reiniger <pj.reiniger@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Monorepo organization, Gradle/CMake/Bazel, upstream_utils, etc component: glass Glass app and backend component: hal Hardware Abstraction Layer component: wpilibc WPILib C++ component: wpilibj WPILib Java os: simulation type: testing Related to testing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants