mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[robotpy] Mirror robotpy's commands-v2 (#8369)
Project import generated by Copybara. GitOrigin-RevId: 715c8e8372d936f447f2937aab6b1a22dc619126
This commit is contained in:
41
commandsv2/src/main/python/commands2/waitcommand.py
Normal file
41
commandsv2/src/main/python/commands2/waitcommand.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# validated: 2024-01-20 DS f29a7d2e501b WaitCommand.java
|
||||
from __future__ import annotations
|
||||
|
||||
from wpilib import Timer
|
||||
from wpimath import units
|
||||
from wpiutil import SendableBuilder
|
||||
|
||||
from .command import Command
|
||||
|
||||
|
||||
class WaitCommand(Command):
|
||||
"""
|
||||
A command that does nothing but takes a specified amount of time to finish.
|
||||
"""
|
||||
|
||||
def __init__(self, seconds: units.seconds):
|
||||
"""
|
||||
Creates a new WaitCommand. This command will do nothing, and end after the specified duration.
|
||||
|
||||
:param seconds: the time to wait, in seconds
|
||||
"""
|
||||
super().__init__()
|
||||
self._duration = seconds
|
||||
self._timer = Timer()
|
||||
self.setName(f"{self.getName()}: {seconds}")
|
||||
|
||||
def initialize(self):
|
||||
self._timer.restart()
|
||||
|
||||
def end(self, interrupted: bool):
|
||||
self._timer.stop()
|
||||
|
||||
def isFinished(self) -> bool:
|
||||
return self._timer.hasElapsed(self._duration)
|
||||
|
||||
def runsWhenDisabled(self) -> bool:
|
||||
return True
|
||||
|
||||
def initSendable(self, builder: SendableBuilder) -> None:
|
||||
super().initSendable(builder)
|
||||
builder.addDoubleProperty("duration", lambda: self._duration, lambda _: None)
|
||||
Reference in New Issue
Block a user