Command Scheduler Reference
kevinbotlib.scheduler
kevinbotlib.scheduler.Command
Bases: ABC
Synchronous command interface that users will implement
init()
abstractmethod
Ran once when the command is initialized.
execute()
abstractmethod
Ran continuously while the command is active.
end()
abstractmethod
Ran once when the command is finished.
finished()
abstractmethod
Get if the command has finished execution.
Returns:
Type | Description |
---|---|
bool
|
True if the command is finished, False otherwise. |
then(next_command)
Chain commands to run sequentially
Parameters:
Name | Type | Description | Default |
---|---|---|---|
next_command
|
Command
|
Command to run next |
required |
Returns:
Type | Description |
---|---|
SequentialCommand
|
Sequential Command |
alongside(next_command)
Chain commands to run in parallel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
next_command
|
Command
|
Command to run alongside this command. |
required |
Returns:
Type | Description |
---|---|
ParallelCommand
|
Parallel Command |
kevinbotlib.scheduler.SequentialCommand
kevinbotlib.scheduler.ParallelCommand
kevinbotlib.scheduler.TriggerActions
dataclass
Trigger types to be used internally within the command scheduler
on_true = None
class-attribute
instance-attribute
Triggers when a value becomes True
on_false = None
class-attribute
instance-attribute
Triggers when a value becomes False
while_true = None
class-attribute
instance-attribute
Triggers while a value is True
while_false = None
class-attribute
instance-attribute
Triggers while a value is False
kevinbotlib.scheduler.Trigger
__init__(trigger_func, command_system)
Create a new Command trigger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trigger_func
|
Callable[[], bool]
|
Function that returns the value that is polled in the scheduler loop. |
required |
command_system
|
CommandScheduler
|
Command scheduler instance to apply the trigger. |
required |
check()
Check the current state of the trigger and determine if it has changed. To be used internally within the scheduler lopp.
Returns:
Type | Description |
---|---|
tuple[bool, bool]
|
Current state and whether it has changed since the last check. |
on_true(command_instance)
on_false(command_instance)
while_true(command_instance)
kevinbotlib.scheduler.CommandScheduler
__init__()
Create a new Command Scheduler.
get_instance()
Get the singleton instance of the CommandScheduler.
Returns:
Type | Description |
---|---|
CommandScheduler
|
CommandScheduler instance. |
schedule(command)
Manually schedule a command to run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command
|
Command
|
Command to schedule. |
required |
register_trigger(trigger)
Register a new command trigger. To be used internally in Trigger
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trigger
|
Trigger
|
Trigger to register. |
required |
iterate()
Executes one iteration of the command scheduler, processing all scheduled commands and their triggers according to their current state and conditions.