Cookwala / حزمة التطوير والسيناريوهات / 036

Knife work: what the vocabulary says, what the ladder says, what the dry run says

Cutting carries a cut hazard, may not run unattended and is verified by a camera or a person. Read the three rules in the vocabulary, the ladder and a dry run, and see how they fit together.

الفئة: teacher · الهدف: روبوتات في خدمة الناس, صحة أفضل للناس · المستوى: beginner

اقرأ أولًا: /docs/CORE/ /docs/QUICKSTART/

الخطوات

  1. The vocabulary: cutting is attended, hazardous, and verified by vision or a person. getOps

  2. No camera, nobody: no rung. ladder

  3. A person present verifies the cut. ladder

  4. A camera verifies the cut. ladder

  5. The robot has a camera and nobody is home: the dry run still refuses the first cut, because unattended is false. dryRun

  6. With a person in the room the robot cuts, verified by its camera. dryRun

  7. The three ladder answers.

النتيجة

A class can trace one safety rule from the vocabulary to a refusal and see that verification (the camera) and presence (the person) are two different requirements that both have to hold.

سطر الأوامر

curl -s http://localhost:7878/v1/tools/vocab/ops
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.cut", "sensors": [], "allowModel": true, "humanPresent": false}'
cookwala dryrun examples/salata-baladi.cookwala.json --device examples/capabilities/demo-hob-robot-basic.json

المخرجات المسجلة

الحالة: ok

[1] getOps: {"name": "ops", "version": "0.2.0", "entries": [{"id": "cw.op.dispense", "label": {"en": "Dispense / measure", "ar": "قياس وإضافة"}, "definition": "Measure an ingredient by mass, volume or count and add it to a target.", "classes": ["cw.opfamily.handle"], "paramsSchema": {"type": "object", "properties": {"precision": {"type": "number"}}}, "sensors": ["cw.sense.mass"], "links": {"ieee1872": "IEEE 1872.1-2024 Task (to be mapped)"}}, {"id": "cw.op.transfer", "label": {"en": "Transfer", "ar": "نقل"}, "definition": "Move food or a vessel's contents from one place to another.", "classes": ["cw.opfam…
[2] ladder: null
[3] ladder: "human"
[4] ladder: "cw.sense.vision"
[5] 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"}]}
[6] 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": "…

الكود

التشغيل: python scenarios/out/036-knife-work-needs-a-person-or-a-camera/python.py

# Scenario 036: Knife work: what the vocabulary says, what the ladder says, what the dry run says
# Cutting carries a cut hazard, may not run unattended and is verified by a camera or a person. Read the three rules in the vocabulary, the ladder and a dry run, and see how they fit together.
# 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: The vocabulary: cutting is attended, hazardous, and verified by vision or a person.
ops = c.get_ops()
assert pick(ops, "entries[8].id") == "cw.op.cut", pick(ops, "entries[8].id")
print("ok", "entries[8].id", "=", "cw.op.cut")
assert pick(ops, "entries[8].envelope.unattended") == False, pick(ops, "entries[8].envelope.unattended")
print("ok", "entries[8].envelope.unattended", "=", False)
assert pick(ops, "entries[8].envelope.attention") == "continuous", pick(ops, "entries[8].envelope.attention")
print("ok", "entries[8].envelope.attention", "=", "continuous")
assert pick(ops, "entries[8].envelope.hazards[0]") == "cw.hz.cut", pick(ops, "entries[8].envelope.hazards[0]")
print("ok", "entries[8].envelope.hazards[0]", "=", "cw.hz.cut")
assert pick(ops, "entries[8].envelope.sensorLadder[0]") == "cw.sense.vision", pick(ops, "entries[8].envelope.sensorLadder[0]")
print("ok", "entries[8].envelope.sensorLadder[0]", "=", "cw.sense.vision")
assert pick(ops, "entries[8].envelope.sensorLadder[1]") == "human", pick(ops, "entries[8].envelope.sensorLadder[1]")
print("ok", "entries[8].envelope.sensorLadder[1]", "=", "human")

# Step 2: No camera, nobody: no rung.
nothing = c.ladder("cw.op.cut", [], True, False)

# Step 3: A person present verifies the cut.
person = c.ladder("cw.op.cut", [], True, True)

# Step 4: A camera verifies the cut.
camera = c.ladder("cw.op.cut", ["cw.sense.vision"], True, False)

# Step 5: The robot has a camera and nobody is home: the dry run still refuses the first cut, because unattended is false.
alone = c.dry_run(recipe_id="salata-baladi", device_id="demo-hob-robot-basic", 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")

# Step 6: With a person in the room the robot cuts, verified by its camera.
withPerson = c.dry_run(recipe_id="salata-baladi", device_id="demo-hob-robot-basic", human_present=True)
assert pick(withPerson, "state") == "accepted", pick(withPerson, "state")
print("ok", "state", "=", "accepted")
assert pick(withPerson, "plan[2].op") == "cw.op.cut", pick(withPerson, "plan[2].op")
print("ok", "plan[2].op", "=", "cw.op.cut")
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")

# Step 7: The three ladder answers.
assert nothing == None, nothing
print("ok", "nothing", "=", None)
assert person == "human", person
print("ok", "person", "=", "human")
assert camera == "cw.sense.vision", camera
print("ok", "camera", "=", "cw.sense.vision")

print("scenario complete")

scenarios/036-knife-work-needs-a-person-or-a-camera.json

السابق: 035 التالي: 037