Esta página fue traducida por una máquina y aún no ha sido revisada por una persona. El inglés es la referencia; las correcciones son bienvenidas en GitHub. GitHub
Cookwala / SDK y escenarios / 033
A counter arm makes salad: washing alone, cutting with a person nearby
The counter arm washes, cuts under its camera, whisks and mixes. Washing may run alone; the knife may not, even when the camera verifies every cut.
Leer primero: /docs/CORE/ /docs/QUICKSTART/
Pasos
Nobody home: the two washing steps are planned, then cutting is refused.
dryRunA person nearby: the arm does seven of nine steps; the cuts are verified by its camera; chilling and serving are the person's.
dryRunThe camera is a rung for cutting even with nobody present. The ladder verifies the cut; the envelope's unattended rule is what requires the person.
ladderThe rung is the camera.
Resultado
You know what an arm on the counter can do while you are out (wash) and what waits for you (anything with a blade). Verification and presence are two separate rules.
Línea de comandos
cookwala dryrun examples/salata-baladi.cookwala.json --device examples/capabilities/demo-arm.json
cookwala dryrun examples/salata-baladi.cookwala.json --device examples/capabilities/demo-arm.json --human-presentSalida grabada
Estado: ok
[1] dryRun: {"state": "refused", "refusal": {"reason": "needs_human_present", "node": "n2", "detail": "cw.op.cut may not run unattended"}, "plan": [{"node": "n1", "op": "cw.op.wash", "by": "device", "verifiedBy": "time", "rung": "time"}, {"node": "n8", "op": "cw.op.wash", "by": "device", "verifiedBy": "time", "rung": "time"}]}
[2] dryRun: {"state": "accepted", "plan": [{"node": "n1", "op": "cw.op.wash", "by": "device", "verifiedBy": "time", "rung": "time"}, {"node": "n8", "op": "cw.op.wash", "by": "device", "verifiedBy": "time", "rung": "time"}, {"node": "n2", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n9", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n3", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n4", "op": "cw.op.whisk", "by": "device", "verifiedBy": "time", "rung": "…
[3] ladder: "cw.sense.vision"Código
Ejecutar: python scenarios/out/033-counter-arm-for-salad/python.py
# Scenario 033: A counter arm makes salad: washing alone, cutting with a person nearby
# The counter arm washes, cuts under its camera, whisks and mixes. Washing may run alone; the knife may not, even when the camera verifies every cut.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem
def load(path):
with open(path, encoding="utf-8") as f:
return json.load(f)
def pick(obj, path):
for part in path.replace("]", "").replace("[", ".").split("."):
obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
return obj
c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))
# Step 1: Nobody home: the two washing steps are planned, then cutting is refused.
alone = c.dry_run(recipe_id="salata-baladi", device_id="demo-arm", human_present=False)
assert pick(alone, "state") == "refused", pick(alone, "state")
print("ok", "state", "=", "refused")
assert pick(alone, "refusal.reason") == "needs_human_present", pick(alone, "refusal.reason")
print("ok", "refusal.reason", "=", "needs_human_present")
assert pick(alone, "refusal.node") == "n2", pick(alone, "refusal.node")
print("ok", "refusal.node", "=", "n2")
assert pick(alone, "plan.length") == 2, pick(alone, "plan.length")
print("ok", "plan.length", "=", 2)
assert pick(alone, "plan[0].op") == "cw.op.wash", pick(alone, "plan[0].op")
print("ok", "plan[0].op", "=", "cw.op.wash")
# Step 2: A person nearby: the arm does seven of nine steps; the cuts are verified by its camera; chilling and serving are the person's.
withPerson = c.dry_run(recipe_id="salata-baladi", device_id="demo-arm", human_present=True)
assert pick(withPerson, "state") == "accepted", pick(withPerson, "state")
print("ok", "state", "=", "accepted")
assert pick(withPerson, "plan.length") == 9, pick(withPerson, "plan.length")
print("ok", "plan.length", "=", 9)
assert pick(withPerson, "plan[2].by") == "device", pick(withPerson, "plan[2].by")
print("ok", "plan[2].by", "=", "device")
assert pick(withPerson, "plan[2].rung") == "cw.sense.vision", pick(withPerson, "plan[2].rung")
print("ok", "plan[2].rung", "=", "cw.sense.vision")
assert pick(withPerson, "plan[7].op") == "cw.op.chill", pick(withPerson, "plan[7].op")
print("ok", "plan[7].op", "=", "cw.op.chill")
assert pick(withPerson, "plan[7].by") == "human", pick(withPerson, "plan[7].by")
print("ok", "plan[7].by", "=", "human")
assert pick(withPerson, "plan[8].by") == "human", pick(withPerson, "plan[8].by")
print("ok", "plan[8].by", "=", "human")
# Step 3: The camera is a rung for cutting even with nobody present. The ladder verifies the cut; the envelope's unattended rule is what requires the person.
cutRung = c.ladder("cw.op.cut", ["cw.sense.vision"], False, False)
# Step 4: The rung is the camera.
assert cutRung == "cw.sense.vision", cutRung
print("ok", "cutRung", "=", "cw.sense.vision")
print("scenario complete")