mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[copybara] mostrobotpy to allwpilib (#8545)
Project import generated by Copybara. GitOrigin-RevId: f10284b37498bb6a088891ca41f160793ec7fd90
This commit is contained in:
18
simulation/halsim_gui/src/main/python/README.md
Normal file
18
simulation/halsim_gui/src/main/python/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
robotpy-halsim-gui
|
||||
==================
|
||||
|
||||
Installing this package will allow you to utilize the 2020+ WPILib GUI
|
||||
simulation from a RobotPy program.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
First, install pyfrc. Then run your robot with the 'sim' argument:
|
||||
|
||||
# Windows
|
||||
py -3 -m robotpy sim
|
||||
|
||||
# Linux/OSX
|
||||
python3 -m robotpy sim
|
||||
|
||||
WPILib's documentation for using the simulator can be found at http://docs.wpilib.org/en/latest/docs/software/wpilib-tools/robot-simulation/simulation-gui.html
|
||||
@@ -0,0 +1 @@
|
||||
from .main import loadExtension
|
||||
@@ -0,0 +1 @@
|
||||
from . import _init__halsim_gui_ext
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
#include <semiwrap_init.halsim_gui._ext._halsim_gui_ext.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <wpi/halsim/gui/HALSimGuiExt.hpp>
|
||||
#include <wpi/hal/Extensions.h>
|
||||
|
||||
std::function<void()> g_gui_exit;
|
||||
|
||||
SEMIWRAP_PYBIND11_MODULE(m) {
|
||||
|
||||
initWrapper(m);
|
||||
|
||||
m.def("_kill_on_signal", []() {
|
||||
HAL_RegisterExtensionListener(
|
||||
nullptr, [](void *, const char *name, void *data) {
|
||||
std::string_view name_view{name};
|
||||
if (name_view == HALSIMGUI_EXT_GUIEXIT) {
|
||||
g_gui_exit = (halsimgui::GuiExitFn)data;
|
||||
} else if (name_view == HALSIMGUI_EXT_ADDGUILATEEXECUTE) {
|
||||
auto AddGuiLateExecute = (halsimgui::AddGuiLateExecuteFn)data;
|
||||
AddGuiLateExecute([] {
|
||||
py::gil_scoped_acquire gil;
|
||||
if (PyErr_CheckSignals() == -1) {
|
||||
|
||||
// If a python signal has been triggered, the GUI needs to exit. It's
|
||||
// not safe to throw an exception here on all platforms so we just
|
||||
// assume that the only eventual caller of this function is HAL_RunMain,
|
||||
// and our wrapper around that function will check if a python error is
|
||||
// set and throw from there.
|
||||
//
|
||||
// Reference: https://github.com/wpilibsuite/allwpilib/issues/8528
|
||||
if (g_gui_exit) {
|
||||
g_gui_exit();
|
||||
} else {
|
||||
throw py::error_already_set();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
27
simulation/halsim_gui/src/main/python/halsim_gui/main.py
Normal file
27
simulation/halsim_gui/src/main/python/halsim_gui/main.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import logging
|
||||
import os
|
||||
from os.path import abspath, dirname, join
|
||||
|
||||
logger = logging.getLogger("halsim_gui")
|
||||
|
||||
|
||||
def loadExtension():
|
||||
try:
|
||||
import hal
|
||||
except ImportError as e:
|
||||
# really, should never happen...
|
||||
raise ImportError("you must install robotpy-hal!") from e
|
||||
|
||||
from .version import version
|
||||
|
||||
logger.info("WPILib HAL Simulation %s", version)
|
||||
|
||||
root = join(abspath(dirname(__file__)), "lib")
|
||||
ext = join(root, os.listdir(root)[0])
|
||||
retval = hal.loadOneExtension(ext)
|
||||
if retval != 0:
|
||||
logger.warn("loading extension may have failed (error=%d)", retval)
|
||||
|
||||
from ._ext._halsim_gui_ext import _kill_on_signal
|
||||
|
||||
_kill_on_signal()
|
||||
57
simulation/halsim_gui/src/main/python/pyproject.toml
Normal file
57
simulation/halsim_gui/src/main/python/pyproject.toml
Normal file
@@ -0,0 +1,57 @@
|
||||
[build-system]
|
||||
build-backend = "hatchling.build"
|
||||
requires = [
|
||||
"semiwrap~=0.2.1",
|
||||
"hatch-meson~=0.1.0",
|
||||
"hatch-robotpy~=0.2.1",
|
||||
"hatchling",
|
||||
"robotpy-wpiutil==0.0.0",
|
||||
"robotpy-wpimath==0.0.0",
|
||||
"robotpy-hal==0.0.0",
|
||||
"pyntcore==0.0.0",
|
||||
]
|
||||
|
||||
[project]
|
||||
name = "robotpy-halsim-gui"
|
||||
version = "0.0.0"
|
||||
description = "WPILib simulation GUI"
|
||||
authors = [
|
||||
{name = "RobotPy Development Team", email = "robotpy@googlegroups.com"},
|
||||
]
|
||||
license = "BSD-3-Clause"
|
||||
dependencies = [
|
||||
"robotpy-wpiutil==0.0.0",
|
||||
"robotpy-wpimath==0.0.0",
|
||||
"robotpy-hal==0.0.0",
|
||||
"pyntcore==0.0.0",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
"Source code" = "https://github.com/robotpy/mostrobotpy"
|
||||
|
||||
|
||||
[tool.hatch.build.hooks.robotpy]
|
||||
version_file = "halsim_gui/version.py"
|
||||
|
||||
[[tool.hatch.build.hooks.robotpy.maven_lib_download]]
|
||||
artifact_id = "halsim_gui"
|
||||
group_id = "org.wpilib.halsim"
|
||||
repo_url = ""
|
||||
version = "0.0.0"
|
||||
use_headers = true
|
||||
|
||||
libs = ["halsim_gui"]
|
||||
extract_to = "halsim_gui"
|
||||
|
||||
[tool.hatch.build.hooks.semiwrap]
|
||||
|
||||
[tool.hatch.build.hooks.meson]
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["halsim_gui"]
|
||||
|
||||
|
||||
[tool.semiwrap]
|
||||
[tool.semiwrap.extension_modules."halsim_gui._ext._halsim_gui_ext"]
|
||||
name = "halsim_gui_ext"
|
||||
depends = ["wpihal", "wpimath", "ntcore"]
|
||||
Reference in New Issue
Block a user