API Reference
Standard Library
Pre-built states for common tasks. Import from kenate.stdlib. Why reinvent the wheel?
Available States
| State | Purpose |
|---|---|
| WaitState | Pause for a duration |
| SequenceState | Chain states in order |
| ParallelState | Run states simultaneously |
| StopState | Emergency shutdown |
| LogState | Debug logging |
WaitState(duration, next_state)
Do nothing for a specified duration. Optionally transition to another state when done. Sometimes waiting is the correct thing to do.
from kenate.stdlib import WaitState
# Wait 2 seconds, then go to Patrol
engine.register_state("Wait", WaitState(2.0, "Patrol"))
# Wait 5 seconds, then return to previous state
engine.register_state("Pause", WaitState(5.0))SequenceState(states)
Execute a list of states in order. Great for scripted behaviors and not losing track of what comes next.
from kenate.stdlib import SequenceState
# Pick up object: move to it, grab it, return
pickup_sequence = SequenceState([
MoveToObjectState(),
GrabState(),
ReturnHomeState()
])
engine.register_state("Pickup", pickup_sequence)ParallelState(states)
Run multiple states at the same time. Useful for multitasking. Walk and chew gum simultaneously.
from kenate.stdlib import ParallelState
# Move AND scan at the same time
patrol = ParallelState([
MoveForwardState(),
ScanForTargetsState()
])
engine.register_state("Patrol", patrol)StopState()
Emergency shutdown. Sets all motors to 0 and locks the robot. Use sparingly. Hopefully never.
from kenate.stdlib import StopState
engine.register_state("EmergencyStop", StopState())
# Trigger from any state:
# self.change_state("EmergencyStop")LogState(message, level)
One-shot state that logs a message and immediately returns to the previous state. Handy for debugging.
from kenate.stdlib import LogState
# Debug your state chains
engine.register_state("Debug", LogState("Entered debug point", "INFO"))