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
Bases: Command
startup_commands = commands
instance-attribute
remaining_commands = [{'command': command, 'has_init': False} for command in commands]
instance-attribute
__init__(commands)
Construct a new sequential command.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commands
|
list[Command]
|
List of commands to run sequentially. |
required |
init()
execute()
end()
finished()
kevinbotlib.scheduler.ParallelCommand
Bases: Command
startup_commands = commands
instance-attribute
remaining_commands = [{'command': command, 'has_init': False} for command in commands]
instance-attribute
__init__(commands)
Construct a new parallel command.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commands
|
list[Command]
|
Commands to run in parallel. |
required |
init()
execute()
end()
finished()
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
__init__(on_true=None, on_false=None, while_true=None, while_false=None)
kevinbotlib.scheduler.Trigger
trigger_func = trigger_func
instance-attribute
command_system = command_system
instance-attribute
last_state = None
instance-attribute
actions = TriggerActions()
instance-attribute
__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, Callable[[], 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
instance = None
class-attribute
instance-attribute
overrun_time = 0.01
class-attribute
instance-attribute
trigger_overrun_time = 0.005
class-attribute
instance-attribute
command_overrun
property
writable
Get the amount of time in seconds that the scheduler will execute a command that will cause an overrun warning Returns: Overrun time in seconds.
trigger_overrun
property
writable
Get the amount of time in seconds that the scheduler will check a trigger that will cause an overrun warning Returns: Overrun time in seconds.
__init__()
Create a new Command Scheduler.
get_instance()
staticmethod
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.