Cette page a été traduite par une machine et n'a pas encore été révisée par une personne. L'anglais est la référence ; les corrections sont les bienvenues sur GitHub. GitHub

Cookwala / SDK et scénarios / 039

Operations without a thermal envelope: mixing, cutting, peeling

Not every operation has a temperature band. Mixing has no envelope at all and is verified by time; cutting and peeling have an envelope without temperatures, with hazards and a ladder but nothing for a thermometer to check.

Audience: developer · Objectif: Des robots pour les gens · Niveau: beginner

Lire d'abord: /docs/CORE/ /docs/QUICKSTART/

Étapes

  1. A trace for mixing: nothing thermal to check, so envelopeOk is true with the reason no_thermal_envelope. checkEnvelope

  2. The same for cutting, which has an envelope but no temperature band. checkEnvelope

  3. Mixing has no ladder in the vocabulary; the default is time. ladder

  4. Peeling has a ladder (vision, then a person) and no time rung: alone, null. ladder

  5. In the vocabulary: mix has no envelope; peel has one that says unattended is false and names the cut hazard. getOps

  6. Time for mixing, nothing for peeling alone.

Résultat

You know the three shapes an operation can take: a thermal envelope, an envelope with hazards and a ladder but no band, or no envelope at all, and how each behaves in the two checks.

Ligne de commande

printf '[{"t": 0, "tempC": 20}]' > trace.json && cookwala envelope cw.op.mix trace.json
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.mix", "sensors": [], "allowModel": false, "humanPresent": false}'
curl -s -X POST http://localhost:7878/v1/tools/ladder -H 'Content-Type: application/json' -d '{"op": "cw.op.peel", "sensors": [], "allowModel": true, "humanPresent": false}'

Sortie enregistrée

Statut: ok

[1] checkEnvelope: {"envelopeOk": true, "targetOk": null, "reason": "no_thermal_envelope"}
[2] checkEnvelope: {"envelopeOk": true, "targetOk": null, "reason": "no_thermal_envelope"}
[3] ladder: "time"
[4] ladder: null
[5] 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…

Code

Exécuter: python scenarios/out/039-ops-without-a-thermal-envelope/python.py

# Scenario 039: Operations without a thermal envelope: mixing, cutting, peeling
# Not every operation has a temperature band. Mixing has no envelope at all and is verified by time; cutting and peeling have an envelope without temperatures, with hazards and a ladder but nothing for a thermometer to check.
# 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: A trace for mixing: nothing thermal to check, so envelopeOk is true with the reason no_thermal_envelope.
mix = c.check_envelope("cw.op.mix", [{"t": 0, "tempC": 20}])
assert pick(mix, "envelopeOk") == True, pick(mix, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(mix, "targetOk") == None, pick(mix, "targetOk")
print("ok", "targetOk", "=", None)
assert pick(mix, "reason") == "no_thermal_envelope", pick(mix, "reason")
print("ok", "reason", "=", "no_thermal_envelope")

# Step 2: The same for cutting, which has an envelope but no temperature band.
cut = c.check_envelope("cw.op.cut", [{"t": 0, "tempC": 20}])
assert pick(cut, "envelopeOk") == True, pick(cut, "envelopeOk")
print("ok", "envelopeOk", "=", True)
assert pick(cut, "reason") == "no_thermal_envelope", pick(cut, "reason")
print("ok", "reason", "=", "no_thermal_envelope")

# Step 3: Mixing has no ladder in the vocabulary; the default is time.
mixRung = c.ladder("cw.op.mix", [], False, False)

# Step 4: Peeling has a ladder (vision, then a person) and no time rung: alone, null.
peelRung = c.ladder("cw.op.peel", [], True, False)

# Step 5: In the vocabulary: mix has no envelope; peel has one that says unattended is false and names the cut hazard.
ops = c.get_ops()
assert pick(ops, "entries[11].id") == "cw.op.mix", pick(ops, "entries[11].id")
print("ok", "entries[11].id", "=", "cw.op.mix")
assert pick(ops, "entries[11].envelope") == None, pick(ops, "entries[11].envelope")
print("ok", "entries[11].envelope", "=", None)
assert pick(ops, "entries[5].id") == "cw.op.peel", pick(ops, "entries[5].id")
print("ok", "entries[5].id", "=", "cw.op.peel")
assert pick(ops, "entries[5].envelope.unattended") == False, pick(ops, "entries[5].envelope.unattended")
print("ok", "entries[5].envelope.unattended", "=", False)
assert pick(ops, "entries[5].envelope.hazards[0]") == "cw.hz.cut", pick(ops, "entries[5].envelope.hazards[0]")
print("ok", "entries[5].envelope.hazards[0]", "=", "cw.hz.cut")

# Step 6: Time for mixing, nothing for peeling alone.
assert mixRung == "time", mixRung
print("ok", "mixRung", "=", "time")
assert peelRung == None, peelRung
print("ok", "peelRung", "=", None)

print("scenario complete")

scenarios/039-ops-without-a-thermal-envelope.json

Précédent: 038 Suivant: 040