Masterclass V1.0.6
Autonomous Delivery
Warehouse Suite Fail-Safe Architecture
Introduction
"Step-by-step, we're going to build a professional-grade delivery system. Instead of just looking at code, let's walk through how we build this thing from scratch."
01. Install Engine
$ pip install kenate --no-cache-dir
02. Scaffold Workspace
$ kenate init WarehouseBot
$ cd WarehouseBot
$ cd WarehouseBot
03. The Implementation
from kenate import Robot, BaseState
from kenate.stdlib import WaitState, BlackBoxLogger
from kenate.diag import TerminalVisualizer
# PHASE 1: THE SAFETY LAYER (EMERGENCY LOCKDOWN)
class SafetyLockdown(BaseState):
def on_enter(self):
print("\n[CRITICAL] EMERGENCY LOCKDOWN TRIGGERED.")
# Kill power to actuators here
def on_update(self):
pass
# PHASE 2: THE STARTUP AUDIT (BATTERY CHECK)
class BatteryCheck(BaseState):
def on_enter(self):
self.logger = BlackBoxLogger()
print("[SYSTEM] Pre-Flight Energy Audit...")
def on_update(self):
battery = self.get_battery_level()
if battery > 20:
self.transition_to("Navigation")
else:
self.transition_to("SafetyLockdown")
# PHASE 3: THE HEARTBEAT LOOP (NAVIGATION)
class Navigation(BaseState):
def on_enter(self):
self.viz = TerminalVisualizer(robot_id="MASTER-TRANS-01")
self.traveled = 0.0
def on_update(self):
# 1. SENSE: Gather data
dist = self.get_distance_sensor()
temp = self.get_system_temperature()
# 2. THINK: Logic transitions (Fail-safe)
if temp > 80.0:
self.transition_to("SafetyLockdown")
return
if dist < 30:
print("\n[ALERT] Obstacle! Braking...")
self.transition_to("WaitState")
return
# 3. ACT: Move and render
self.traveled += 0.1
self.viz.render(self.name, {'distance': self.traveled})
def main():
robot = Robot(port="SIMULATION")
robot.create_state("StartUp", BatteryCheck)
robot.create_state("Navigation", Navigation)
robot.create_state("SafetyLockdown", SafetyLockdown)
robot.start()Breakdown: To The Bone
The Safety Layer
In a professional warehouse, we want a "Safe Zone" we can jump to if things break. The SafetyLockdown state is isolated, ensuring that even if navigation logic crashes, the actuators are powered down.
Pre-Flight Audit
We don't want a robot dying in the middle of a hallway. The BatteryCheck phase records every audit in the Black Box Logger before the wheels ever turn—providing an engineering "paper trail."
04. Deploying to Hardware
Once the code is on the Raspberry Pi, run:
$ kenate run src/delivery_bot.py
The Python script wakes up the C++ engine inside the robot's brain, and the navigation begins!