forked from robotpy/robotpy-commands-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstantcommand.py
29 lines (23 loc) · 952 Bytes
/
instantcommand.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from __future__ import annotations
from typing import Callable, Optional
from .functionalcommand import FunctionalCommand
from .subsystem import Subsystem
class InstantCommand(FunctionalCommand):
"""
A Command that runs instantly; it will initialize, execute once, and end on the same iteration of
the scheduler. Users can either pass in a Runnable and a set of requirements, or else subclass
this command if desired."""
def __init__(
self, toRun: Optional[Callable[[], None]] = None, *requirements: Subsystem
):
"""
Creates a new InstantCommand that runs the given Runnable with the given requirements.
:param toRun: the Runnable to run
:param requirements: the subsystems required by this command"""
super().__init__(
toRun or (lambda: None),
lambda: None,
lambda _: None,
lambda: True,
*requirements,
)