Skip to content

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

__init__(commands)

Construct a new sequential command.

Parameters:

Name Type Description Default
commands list[Command]

List of commands to run sequentially.

required

kevinbotlib.scheduler.ParallelCommand

Bases: Command

__init__(commands)

Construct a new parallel command.

Parameters:

Name Type Description Default
commands list[Command]

Commands to run in parallel.

required

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)

Trigger a command once when a condition is met.

Parameters:

Name Type Description Default
command_instance Command

Command to trigger.

required

Returns:

Type Description
Trigger

This trigger

on_false(command_instance)

Trigger a command once when a condition is unmet.

Parameters:

Name Type Description Default
command_instance Command

Command to trigger.

required

Returns:

Type Description
Trigger

This trigger

while_true(command_instance)

Trigger a command once and keep running while a condition is met.

Parameters:

Name Type Description Default
command_instance Command

Command to trigger.

required

Returns:

Type Description
Trigger

This trigger

while_false(command_instance)

Trigger a command once and keep running while a condition is unmet.

Parameters:

Name Type Description Default
command_instance Command

Command to trigger.

required

Returns:

Type Description
Trigger

This trigger

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.