Skip to content

Commit

Permalink
Merge pull request #184 from robotpy/2022
Browse files Browse the repository at this point in the history
2022
  • Loading branch information
virtuald committed Jan 17, 2022
2 parents 80f753a + 809b303 commit 8580885
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 92 deletions.
76 changes: 8 additions & 68 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,11 @@ on:
- '*'

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable

#
# Test wheels
#

test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-18.04]
python_version: [3.6, 3.7, 3.8, 3.9]
architecture: [x86, x64]
exclude:
- os: macos-latest
architecture: x86
- os: ubuntu-18.04
architecture: x86

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}
architecture: ${{ matrix.architecture }}

- uses: robotpy/build-actions/install-pure-build-deps@v2021
- uses: robotpy/build-actions/build-wheel@v2021
- uses: robotpy/build-actions/test-native-wheel@v2021

- uses: robotpy/build-actions/validate-sphinx@v2021
if: ${{ matrix.python_version == '3.7' && matrix.os == 'ubuntu-18.04' }}


publish-pypi:
runs-on: ubuntu-latest
needs: [check, test]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: 3.8
- run: pip install wheel

- name: Build packages
run: python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}

ping:
runs-on: ubuntu-latest
needs: [publish-pypi]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

steps:
- uses: robotpy/build-actions/ping-meta@v2021
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
ci:
uses: robotpy/build-actions/.github/workflows/package-pure.yml@v2022
secrets:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_PASSPHRASE: ${{ secrets.SSH_PASSPHRASE }}
META_REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
PYPI_API_TOKEN: ${{ secrets.PYPI_PASSWORD }}
28 changes: 14 additions & 14 deletions magicbot/magicrobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,19 @@ def robotInit(self):
# Next, create the robot components and wire them together
self._create_components()

# cache these
self.__is_ds_attached = wpilib.DriverStation.isDSAttached
self.__sd_update = wpilib.SmartDashboard.updateValues
self.__lv_update = wpilib.LiveWindow.updateValues
# self.__sf_update = Shuffleboard.update

self.__nt = NetworkTables.getTable("/robot")

self.__nt_put_is_ds_attached = self.__nt.getEntry("is_ds_attached").setBoolean
self.__nt_put_mode = self.__nt.getEntry("mode").setString

self.__nt.putBoolean("is_simulation", self.isSimulation())
self.__nt_put_is_ds_attached(self.ds.isDSAttached())

# cache these
self.__sd_update = wpilib.SmartDashboard.updateValues
self.__lv_update = wpilib.LiveWindow.getInstance().updateValues
# self.__sf_update = Shuffleboard.update
self.__nt_put_is_ds_attached(self.__is_ds_attached())

self.watchdog = SimpleWatchdog(self.control_loop_wait_time)

Expand Down Expand Up @@ -290,7 +291,7 @@ def teleopPeriodic(self):
set this to True
"""
# If the FMS is not attached, crash the robot program
if not self.ds.isFMSAttached():
if not wpilib.DriverStation.isFMSAttached():
raise

# Otherwise, if the FMS is attached then try to report the error via
Expand All @@ -302,7 +303,7 @@ def teleopPeriodic(self):
forceReport
or (now - self.__last_error_report) > self.error_report_interval
):
wpilib.DriverStation.reportError("Unexpected exception", True)
wpilib.reportError("Unexpected exception", True)
except:
pass # ok, can't do anything here

Expand Down Expand Up @@ -378,7 +379,7 @@ def autonomous(self) -> None:
"""

self.__nt_put_mode("auto")
self.__nt_put_is_ds_attached(self.ds.isDSAttached())
self.__nt_put_is_ds_attached(self.__is_ds_attached())

self._on_mode_enable_components()

Expand Down Expand Up @@ -427,7 +428,7 @@ def _disabled(self) -> None:

with NotifierDelay(self.control_loop_wait_time) as delay:
while not self.__done and self.isDisabled():
if ds_attached != self.ds.isDSAttached():
if ds_attached != self.__is_ds_attached():
ds_attached = not ds_attached
self.__nt_put_is_ds_attached(ds_attached)

Expand Down Expand Up @@ -463,7 +464,7 @@ def _operatorControl(self) -> None:
self.__nt_put_mode("teleop")
# don't need to update this during teleop -- presumably will switch
# modes when ds is no longer attached
self.__nt_put_is_ds_attached(self.ds.isDSAttached())
self.__nt_put_is_ds_attached(self.__is_ds_attached())

# initialize things
self._on_mode_enable_components()
Expand Down Expand Up @@ -506,10 +507,9 @@ def _test(self) -> None:
watchdog.reset()

self.__nt_put_mode("test")
self.__nt_put_is_ds_attached(self.ds.isDSAttached())
self.__nt_put_is_ds_attached(self.__is_ds_attached())

lw = wpilib.LiveWindow.getInstance()
lw.setEnabled(True)
wpilib.LiveWindow.setEnabled(True)
# Shuffleboard.enableActuatorWidgets()

try:
Expand Down
14 changes: 7 additions & 7 deletions robotpy_ext/autonomous/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
:param kwargs: Keyword args to pass to created autonomous modes
"""

self.ds = wpilib.DriverStation.getInstance()
self.modes = {}
self.active_mode = None

Expand Down Expand Up @@ -112,7 +111,7 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
module = importlib.import_module("." + module_name, autonomous_pkgname)
# module = imp.load_source('.' + module_name, module_filename)
except:
if not self.ds.isFMSAttached():
if not wpilib.DriverStation.isFMSAttached():
raise

#
Expand All @@ -136,13 +135,13 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
instance = obj(*args, **kwargs)
except:

if not self.ds.isFMSAttached():
if not wpilib.DriverStation.isFMSAttached():
raise
else:
continue

if mode_name in self.modes:
if not self.ds.isFMSAttached():
if not wpilib.DriverStation.isFMSAttached():
raise RuntimeError(
"Duplicate name %s in %s" % (mode_name, module_filename)
)
Expand Down Expand Up @@ -187,7 +186,7 @@ def __init__(self, autonomous_pkgname, *args, **kwargs):
if len(default_modes) == 0:
self.chooser.setDefaultOption("None", None)
elif len(default_modes) != 1:
if not self.ds.isFMSAttached():
if not wpilib.DriverStation.isFMSAttached():
raise RuntimeError(
"More than one autonomous mode was specified as default! (modes: %s)"
% (", ".join(default_modes))
Expand Down Expand Up @@ -263,9 +262,10 @@ def watchdog_check_expired():
#

observe = hal.observeUserProgramAutonomous
isAutonomousEnabled = wpilib.DriverStation.isAutonomousEnabled

with NotifierDelay(control_loop_wait_time) as delay:
while self.ds.isAutonomousEnabled():
while isAutonomousEnabled():
observe()
try:
self._on_iteration(timer.get())
Expand Down Expand Up @@ -367,5 +367,5 @@ def _on_iteration(self, time_elapsed):
self.active_mode.on_iteration(time_elapsed)

def _on_exception(self, forceReport=False):
if not self.ds.isFMSAttached():
if not wpilib.DriverStation.isFMSAttached():
raise
2 changes: 1 addition & 1 deletion robotpy_ext/autonomous/stateful_autonomous.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def on_enable(self):

# print out the details of this autonomous mode, and any tunables

self.battery_voltage = wpilib.DriverStation.getInstance().getBatteryVoltage()
self.battery_voltage = wpilib.DriverStation.getBatteryVoltage()
logger.info("Battery voltage: %.02fv", self.battery_voltage)

logger.info("Tunable values:")
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers =
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Software Development
Topic :: Scientific/Engineering

Expand All @@ -29,9 +30,9 @@ include_package_data = True
packages = find:
install_requires =
pynetworktables>=2020.0.0
wpilib>=2021.1.2.0,<2022.0.0
wpilib>=2022.2.1.0,<2023.0.0
setup_requires =
setuptools_scm == 5.0.*
setuptools_scm > 6
python_requires = >=3.6

[options.package_data]
Expand Down

0 comments on commit 8580885

Please sign in to comment.