Robot Reference
kevinbotlib.robot
kevinbotlib.robot.BaseRobot
__init__(opmodes, serve_port=6379, log_level=Level.INFO, print_level=Level.INFO, default_opmode=None, cycle_time=250, log_cleanup_timer=10.0, metrics_publish_timer=5.0, battery_publish_timer=0.1, robot_heartbeat_interval=1.0, robot_heartbeat_expiry=2.5, *, enable_stderr_logger=False, allow_enable_without_console=False)
Initialize the robot
Parameters:
Name | Type | Description | Default |
---|---|---|---|
opmodes
|
list[str]
|
List of operational mode names. |
required |
serve_port
|
int
|
Port for comm server. Shouldn't have to be changed in most cases. Defaults to 8765. |
6379
|
log_level
|
Level
|
Level to logging. Defaults to Level.INFO. |
INFO
|
print_level
|
Level
|
Level for print statement redirector. Defaults to Level.INFO. |
INFO
|
enable_stderr_logger
|
bool
|
Enable logging to STDERR, may cause issues when using signal stop. Defaults to False. |
False
|
default_opmode
|
str
|
Default Operational Mode to start in. Defaults to the first item of |
None
|
cycle_time
|
float
|
How fast to run periodic functions in Hz. Defaults to 250. |
250
|
log_cleanup_timer
|
float
|
How often to clean up logs in seconds. Set to 0 to disable log cleanup. Defaults to 10.0. |
10.0
|
metrics_publish_timer
|
float
|
How often to publish system metrics. This is separate from |
5.0
|
battery_publish_timer
|
float
|
How often to publish battery voltages. Set to 0 to disable battery publishing. Defaults to 0.1. |
0.1
|
robot_heartbeat_interval
|
float
|
How often to send a heartbeat to the control console. Defaults to 1.0. |
1.0
|
robot_heartbeat_expiry
|
float
|
How long the robot heartbeat will stay valid. Must be longer than robot_heartbeat_interval. Defaults to 2.0. |
2.5
|
allow_enable_without_console
|
bool
|
Allow the robot to be enabled without an active control console. Defaults to False. |
False
|
run()
Run the robot loop and parse command-line arguments. Method is final.
robot_start()
Run after the robot is initialized
robot_end()
Runs before the robot is requested to stop via service or keyboard interrupt
robot_periodic(opmode, enabled)
Periodically runs every robot cycle
Parameters:
Name | Type | Description | Default |
---|---|---|---|
opmode
|
str
|
The current OpMode |
required |
enabled
|
bool
|
WHether the robot is enabled in this opmode |
required |
opmode_init(opmode, enabled)
Runs when entering an opmode state (either enabled or disabled)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
opmode
|
str
|
The OpMode being entered |
required |
enabled
|
bool
|
Whether the robot is enabled in this opmode |
required |
opmode_exit(opmode, enabled)
Runs when exiting an opmode state (either enabled or disabled)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
opmode
|
str
|
The OpMode being exited |
required |
enabled
|
bool
|
Whether the robot was enabled in this opmode |
required |
estop()
Immediately trigger an emergency stop.
kevinbotlib.robot.InstanceLocker
Generate and release a lockfile for an entire application. Useful when trying to prevent multiple instances of an app.
Verifies if the application was killed without releasing the lockfile.
__init__(lockfile_name)
Initialize the InstanceLocker
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lockfile_name
|
str
|
The name of the lockfile (e.g., 'robot.lock'). |
required |
lock()
Attempt to acquire the lock by creating a lockfile with the current PID.
Returns:
Type | Description |
---|---|
bool
|
True if the lock was successfully acquired, False if another instance is running. |
unlock()
Release the lock by removing the lockfile.
is_locked(lockfile_name)
staticmethod
Check if the lockfile exists and corresponds to a running process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lockfile_name
|
str
|
The name of the lockfile to check. |
required |
Returns:
Type | Description |
---|---|
int
|
-1 if not locked, PID of locking process |