Closed etiennebeaulac closed 10 months ago
The current button trigger implementation in commands2 uses getRawButtonPressed, but it should use getRawButton, as done here : https://github.com/wpilibsuite/allwpilib/blob/84ef71ace0648a71bd6e60e16c38be75914bb59d/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java#L57
getRawButtonPressed
getRawButton
The consequence is that commands scheduled with whileTrue end instantly because getRawButtonPressed returns False right after a True state.
whileTrue
Windows
bcrypt 4.1.2 cffi 1.16.0 colorama 0.4.6 cryptography 41.0.7 iniconfig 2.0.0 numpy 1.26.3 packaging 23.2 paramiko 3.4.0 Pint 0.23 pip 23.3.2 pluggy 1.3.0 pycparser 2.21 pyfrc 2024.0.1 PyNaCl 1.5.0 pynetconsole 2.0.4 pyntcore 2024.2.1.2 pytest 7.4.4 pytest-reraise 2.1.2 robotpy 2024.2.1.1 robotpy-apriltag 2024.2.1.2 robotpy-cli 2024.0.0 robotpy-commands-v2 2024.2.1 robotpy-cscore 2024.2.1.2 robotpy-hal 2024.2.1.2 robotpy-halsim-ds-socket 2024.2.1.2 robotpy-halsim-gui 2024.2.1.2 robotpy-halsim-ws 2024.2.1.2 robotpy-installer 2024.1.3 robotpy-rev 2024.2.0 robotpy-wpilib-utilities 2024.0.0 robotpy-wpimath 2024.2.1.2 robotpy-wpinet 2024.2.1.2 robotpy-wpiutil 2024.2.1.2 setuptools 69.0.3 tomli 2.0.1 typing_extensions 4.9.0 wheel 0.42.0 wpilib 2024.2.1.2
import commands2 import wpilib from commands2 import CommandScheduler from commands2.button import CommandJoystick, Trigger class TestCommand(commands2.Command): def initialize(self): print("initialized") def execute(self): print("execute") def isFinished(self) -> bool: return False def end(self, interrupted: bool): print("end", f"{interrupted=}") class Robot(wpilib.TimedRobot): def robotInit(self): self.joystick = CommandJoystick(0) self.joystick.button(1).whileTrue(TestCommand()) # Trigger(lambda: self.joystick._hid.getRawButton(1)).whileTrue(TestCommand()) def robotPeriodic(self): CommandScheduler.getInstance().run()
Problem description
The current button trigger implementation in commands2 uses
getRawButtonPressed
, but it should usegetRawButton
, as done here : https://github.com/wpilibsuite/allwpilib/blob/84ef71ace0648a71bd6e60e16c38be75914bb59d/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java#L57The consequence is that commands scheduled with
whileTrue
end instantly becausegetRawButtonPressed
returns False right after a True state.Operating System
Windows
Installed Python Packages
Reproducible example code