Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magicbot: Allow integer feedbacks #208

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

magicbot: Allow integer feedbacks #208

wants to merge 2 commits into from

Conversation

auscompgeek
Copy link
Member

This inspects the return type hint on @feedback methods to determine what topic type they should publish. This allows publishing integers to NetworkTables instead of floating point numbers.

(This currently isn't possible due to the backwards compatibility in pyntcore's setValue method preferring to upcast integers to doubles.)

If the types are incompatible at runtime, the robot code will crash, e.g. in tests:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../.venv/lib/python3.11/site-packages/pytest_reraise/reraise.py:72: in __call__
    raise e
../../../pyfrc/pyfrc/test_support/controller.py:40: in _robot_thread
    robot.startCompetition()
../../../robotpy-wpilib-utilities/magicbot/magicrobot.py:370: in startCompetition
    self._disabled()
../../../robotpy-wpilib-utilities/magicbot/magicrobot.py:456: in _disabled
    self._do_periodics()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <robot.MyRobot object at 0x10687a0f0>

    def _do_periodics(self) -> None:
        """Run periodic methods which run in every mode."""
        watchdog = self.watchdog

        for method, setter in self._feedbacks:
            try:
                value = method()
            except:
                self.onException()
            else:
>               setter(value)
E               TypeError: set(): incompatible function arguments. The following argument types are supported:
E                   1. (self: ntcore._ntcore.IntegerPublisher, value: int, time: int = 0) -> None
E
E               Invoked with: <ntcore._ntcore.IntegerPublisher object at 0x1019ce5f0>, 0.0

../../../robotpy-wpilib-utilities/magicbot/magicrobot.py:729: TypeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant