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

Operations that never fall back to time: toasting, reducing, cutting

Operations that need constant attention end their ladder with a person, not a timer. Without the sensor and without the person the answer is null, and a dry run refuses the step.

الفئة: researcher · الهدف: روبوتات في خدمة الناس · المستوى: beginner

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

الخطوات

  1. Toasting, no sensor, no person: null. Its ladder has no model rung either. ladder

  2. Toasting with a person: the human rung. ladder

  3. Toasting with a colour camera: the sensor rung, no person needed for verification. ladder

  4. Reducing a sauce without a thermometer, a scale or a person: null. ladder

  5. A scale verifies a reduction by mass. ladder

  6. Cutting with no camera and nobody present: null. ladder

  7. Three nulls and three rungs.

النتيجة

You can separate the vocabulary into operations a timer may verify and operations that need a sensor or a person, which is the first question for any unattended-cooking study. Next: scenario 030 shows the refusal this produces in a dry run.

سطر الأوامر

curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.toast", "sensors": [], "allowModel": true, "humanPresent": false}'
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.reduce", "sensors": ["cw.sense.mass"], "allowModel": false, "humanPresent": false}'

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

الحالة: ok

[1] ladder: null
[2] ladder: "human"
[3] ladder: "cw.sense.color_vision"
[4] ladder: null
[5] ladder: "cw.sense.mass"
[6] ladder: null

الكود

التشغيل: python scenarios/out/027-ops-that-never-fall-back-to-time/python.py

# Scenario 027: Operations that never fall back to time: toasting, reducing, cutting
# Operations that need constant attention end their ladder with a person, not a timer. Without the sensor and without the person the answer is null, and a dry run refuses the step.
# 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: Toasting, no sensor, no person: null. Its ladder has no model rung either.
toastAlone = c.ladder("cw.op.toast", [], True, False)

# Step 2: Toasting with a person: the human rung.
toastHuman = c.ladder("cw.op.toast", [], True, True)

# Step 3: Toasting with a colour camera: the sensor rung, no person needed for verification.
toastCamera = c.ladder("cw.op.toast", ["cw.sense.color_vision"], False, False)

# Step 4: Reducing a sauce without a thermometer, a scale or a person: null.
reduceAlone = c.ladder("cw.op.reduce", [], False, False)

# Step 5: A scale verifies a reduction by mass.
reduceScale = c.ladder("cw.op.reduce", ["cw.sense.mass"], False, False)

# Step 6: Cutting with no camera and nobody present: null.
cutAlone = c.ladder("cw.op.cut", [], True, False)

# Step 7: Three nulls and three rungs.
assert toastAlone == None, toastAlone
print("ok", "toastAlone", "=", None)
assert toastHuman == "human", toastHuman
print("ok", "toastHuman", "=", "human")
assert toastCamera == "cw.sense.color_vision", toastCamera
print("ok", "toastCamera", "=", "cw.sense.color_vision")
assert reduceAlone == None, reduceAlone
print("ok", "reduceAlone", "=", None)
assert reduceScale == "cw.sense.mass", reduceScale
print("ok", "reduceScale", "=", "cw.sense.mass")
assert cutAlone == None, cutAlone
print("ok", "cutAlone", "=", None)

print("scenario complete")

scenarios/027-ops-that-never-fall-back-to-time.json

السابق: 026 التالي: 028