Skip to content

Commit

Permalink
Validate various commands with minor adjustments
Browse files Browse the repository at this point in the history
- Update docs
- Change member variables to be prefixed with _
- Add initSendable
  • Loading branch information
virtuald committed Jan 20, 2024
1 parent d280859 commit 1cb70ee
Show file tree
Hide file tree
Showing 35 changed files with 520 additions and 224 deletions.
52 changes: 25 additions & 27 deletions commands2/button/commandgenerichid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# validated: 2024-01-20 DS 92149efa11fa button/CommandGenericHID.java
from typing import Optional

from wpilib.event import EventLoop
Expand All @@ -9,7 +10,7 @@

class CommandGenericHID:
"""
A version of GenericHID with Trigger factories for command-based.
A version of :class:`wpilib.interfaces.GenericHID` with :class:`.Trigger` factories for command-based.
"""

def __init__(self, port: int):
Expand All @@ -31,7 +32,10 @@ def button(self, button: int, loop: Optional[EventLoop] = None) -> Trigger:
Constructs an event instance around this button's digital signal.
:param button: The button index
:param loop: the event loop instance to attache the event to.
:param loop: the event loop instance to attach the event to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: A trigger instance attached to the event loop
"""
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
Expand All @@ -48,8 +52,9 @@ def pov(
:param angle: POV angle in degrees, or -1 for the center / not pressed.
:param pov: index of the POV to read (starting at 0). Defaults to 0.
:param loop: the event loop instance to attach the event to. Defaults to {@link
CommandScheduler#getDefaultButtonLoop() the default command scheduler button loop}.
:param loop: the event loop instance to attach the event to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance based around this angle of a POV on the HID.
"""
if loop is None:
Expand All @@ -59,8 +64,7 @@ def pov(
def povUp(self) -> Trigger:
"""
Constructs a Trigger instance based around the 0 degree angle (up) of the default (index 0) POV
on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
scheduler button loop}.
on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance based around the 0 degree angle of a POV on the HID.
"""
Expand All @@ -69,8 +73,7 @@ def povUp(self) -> Trigger:
def povUpRight(self) -> Trigger:
"""
Constructs a Trigger instance based around the 45 degree angle (right up) of the default (index
0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default
command scheduler button loop}.
0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the 45 degree angle of a POV on the HID.
"""
Expand All @@ -79,8 +82,7 @@ def povUpRight(self) -> Trigger:
def povRight(self) -> Trigger:
"""
Constructs a Trigger instance based around the 90 degree angle (right) of the default (index 0)
POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
scheduler button loop}.
POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the 90 degree angle of a POV on the HID.
"""
Expand All @@ -89,8 +91,7 @@ def povRight(self) -> Trigger:
def povDownRight(self) -> Trigger:
"""
Constructs a Trigger instance based around the 135 degree angle (right down) of the default
(index 0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the
default command scheduler button loop}.
(index 0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the 135 degree angle of a POV on the HID.
"""
Expand All @@ -99,8 +100,7 @@ def povDownRight(self) -> Trigger:
def povDown(self) -> Trigger:
"""
Constructs a Trigger instance based around the 180 degree angle (down) of the default (index 0)
POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
scheduler button loop}.
POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the 180 degree angle of a POV on the HID.
"""
Expand All @@ -109,8 +109,7 @@ def povDown(self) -> Trigger:
def povDownLeft(self) -> Trigger:
"""
Constructs a Trigger instance based around the 225 degree angle (down left) of the default
(index 0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the
default command scheduler button loop}.
(index 0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the 225 degree angle of a POV on the HID.
"""
Expand All @@ -119,8 +118,7 @@ def povDownLeft(self) -> Trigger:
def povLeft(self) -> Trigger:
"""
Constructs a Trigger instance based around the 270 degree angle (left) of the default (index 0)
POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
scheduler button loop}.
POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the 270 degree angle of a POV on the HID.
"""
Expand All @@ -129,8 +127,7 @@ def povLeft(self) -> Trigger:
def povUpLeft(self) -> Trigger:
"""
Constructs a Trigger instance based around the 315 degree angle (left up) of the default (index
0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default
command scheduler button loop}.
0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the 315 degree angle of a POV on the HID.
"""
Expand All @@ -139,8 +136,7 @@ def povUpLeft(self) -> Trigger:
def povCenter(self) -> Trigger:
"""
Constructs a Trigger instance based around the center (not pressed) position of the default
(index 0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the
default command scheduler button loop}.
(index 0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
:returns: a Trigger instance based around the center position of a POV on the HID.
"""
Expand All @@ -150,14 +146,15 @@ def axisLessThan(
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
) -> Trigger:
"""
Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
Constructs a Trigger instance that is true when the axis value is less than ``threshold``,
attached to the given loop.
:param axis: The axis to read, starting at 0
:param threshold: The value below which this trigger should return true.
:param loop: the event loop instance to attach the trigger to
:returns: a Trigger instance that is true when the axis value is less than the provided
threshold.
threshold.
"""
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
Expand All @@ -167,14 +164,15 @@ def axisGreaterThan(
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
) -> Trigger:
"""
Constructs a Trigger instance that is true when the axis value is greater than {@code
threshold}, attached to the given loop.
Constructs a Trigger instance that is true when the axis value is greater than
``threshold``, attached to the given loop.
:param axis: The axis to read, starting at 0
:param threshold: The value above which this trigger should return true.
:param loop: the event loop instance to attach the trigger to.
:returns: a Trigger instance that is true when the axis value is greater than the provided
threshold.
threshold.
"""
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
Expand Down
27 changes: 16 additions & 11 deletions commands2/button/commandjoystick.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# validated: 2024-01-20 DS 92aecab2ef05 button/CommandJoystick.java
from typing import Optional

from wpilib import Joystick
Expand All @@ -10,7 +11,7 @@

class CommandJoystick(CommandGenericHID):
"""
A version of Joystick with Trigger factories for command-based.
A version of :class:`wpilib.Joystick` with :class:`.Trigger` factories for command-based.
"""

_hid: Joystick
Expand All @@ -25,7 +26,7 @@ def __init__(self, port: int):
super().__init__(port)
self._hid = Joystick(port)

def getHID(self):
def getHID(self) -> Joystick:
"""
Get the underlying GenericHID object.
Expand All @@ -37,7 +38,9 @@ def trigger(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs an event instance around the trigger button's digital signal.
:param loop: the event loop instance to attach the event to.
:param loop: the event loop instance to attach the event to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: an event instance representing the trigger button's digital signal attached to the
given loop.
"""
Expand All @@ -49,9 +52,11 @@ def top(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs an event instance around the top button's digital signal.
:param loop: the event loop instance to attach the event to.
:param loop: the event loop instance to attach the event to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: an event instance representing the top button's digital signal attached to the given
loop.
loop.
"""
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
Expand Down Expand Up @@ -121,21 +126,21 @@ def getZChannel(self) -> int:
"""
return self._hid.getZChannel()

def getThrottleChannel(self) -> int:
def getTwistChannel(self) -> int:
"""
Get the channel currently associated with the throttle axis.
Get the channel currently associated with the twist axis.
:returns: The channel for the axis.
"""
return self._hid.getThrottleChannel()
return self._hid.getTwistChannel()

def getTwistChannel(self) -> int:
def getThrottleChannel(self) -> int:
"""
Get the channel currently associated with the twist axis.
Get the channel currently associated with the throttle axis.
:returns: The channel for the axis.
"""
return self._hid.getTwistChannel()
return self._hid.getThrottleChannel()

def getX(self) -> float:
"""
Expand Down
Loading

0 comments on commit 1cb70ee

Please sign in to comment.