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 / 031

Compare two devices on the same recipe: same plan length, different rungs

Two kitchen robots with the same operations and different sensors both plan lentil soup. The plans have the same eleven steps; the verification column is where they differ.

Audiencia: developer · Objetivo: Robots para las personas · Nivel: beginner

Leer primero: /docs/CORE/ /docs/QUICKSTART/

Pasos

  1. Without thermometers: heating, boiling and hot holding are logged estimates. dryRun

  2. With thermometers: pan surface, liquid and core temperature verify the same three steps. dryRun

  3. The difference is four sensors in the capability documents. getDevices

  4. Both robots cut the vegetables under their camera; the knife step is identical.

Resultado

You can diff two devices by the rung each step gets, which is a fair way to compare products: not what they accept, but what they verify. Next: scenario 010 does the same with estimates forbidden.

Línea de comandos

cookwala dryrun examples/lentil-soup.cookwala.json --device examples/capabilities/demo-hob-robot-basic.json --human-present
cookwala dryrun examples/lentil-soup.cookwala.json --device examples/capabilities/demo-hob-robot.json --human-present
curl -s http://localhost:7878/v1/tools/devices

Salida grabada

Estado: ok

[1] dryRun: {"state": "accepted", "plan": [{"node": "n1", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n2", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n3", "op": "cw.op.crush", "by": "device", "verifiedBy": "time", "rung": "time"}, {"node": "n4", "op": "cw.op.heat", "by": "device", "verifiedBy": "model", "rung": "model"}, {"node": "n5", "op": "cw.op.saute", "by": "device", "verifiedBy": "model", "rung": "model"}, {"node": "n6", "op": "cw.op.boil", "by": "device", "verifiedBy": "model", "rung": "model"…
[2] dryRun: {"state": "accepted", "plan": [{"node": "n1", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n2", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n3", "op": "cw.op.crush", "by": "device", "verifiedBy": "time", "rung": "time"}, {"node": "n4", "op": "cw.op.heat", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.pan_surface_temp"}, {"node": "n5", "op": "cw.op.saute", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.pan_surface_temp"}, {"node": "n6", "op": "cw.op.boil", "by": "devic…
[3] getDevices: {"devices": {"demo-arm": {"cookwala": "0.1.0", "actor": {"kind": "robot", "id": "demo:arm", "vendor": "Cookwala demo presets", "model": "Counter robot arm (cuts, cracks, mixes, moves)"}, "roles": ["executor"], "location": {"zone": "kitchen", "mobile": false}, "capabilities": {"ops": [{"op": "cw.op.cut"}, {"op": "cw.op.crack"}, {"op": "cw.op.transfer"}, {"op": "cw.op.mix"}, {"op": "cw.op.whisk"}, {"op": "cw.op.wash"}, {"op": "cw.op.drain"}, {"op": "cw.op.crush"}, {"op": "cw.op.grate"}, {"op": "cw.op.layer"}, {"op": "cw.op.garnish"}, {"op": "cw.op.form"}], "sensors": [{"sensor": "cw.sense.vision…

Código

Ejecutar: python scenarios/out/031-compare-two-devices-on-one-recipe/python.py

# Scenario 031: Compare two devices on the same recipe: same plan length, different rungs
# Two kitchen robots with the same operations and different sensors both plan lentil soup. The plans have the same eleven steps; the verification column is where they differ.
# 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: Without thermometers: heating, boiling and hot holding are logged estimates.
basic = c.dry_run(recipe_id="lentil-soup", device_id="demo-hob-robot-basic", human_present=True)
assert pick(basic, "state") == "accepted", pick(basic, "state")
print("ok", "state", "=", "accepted")
assert pick(basic, "plan.length") == 11, pick(basic, "plan.length")
print("ok", "plan.length", "=", 11)
assert pick(basic, "plan[3].rung") == "model", pick(basic, "plan[3].rung")
print("ok", "plan[3].rung", "=", "model")
assert pick(basic, "plan[5].rung") == "model", pick(basic, "plan[5].rung")
print("ok", "plan[5].rung", "=", "model")
assert pick(basic, "plan[9].rung") == "model", pick(basic, "plan[9].rung")
print("ok", "plan[9].rung", "=", "model")

# Step 2: With thermometers: pan surface, liquid and core temperature verify the same three steps.
thermometers = c.dry_run(recipe_id="lentil-soup", device_id="demo-hob-robot", human_present=True)
assert pick(thermometers, "state") == "accepted", pick(thermometers, "state")
print("ok", "state", "=", "accepted")
assert pick(thermometers, "plan.length") == 11, pick(thermometers, "plan.length")
print("ok", "plan.length", "=", 11)
assert pick(thermometers, "plan[3].rung") == "cw.sense.pan_surface_temp", pick(thermometers, "plan[3].rung")
print("ok", "plan[3].rung", "=", "cw.sense.pan_surface_temp")
assert pick(thermometers, "plan[5].rung") == "cw.sense.liquid_temp", pick(thermometers, "plan[5].rung")
print("ok", "plan[5].rung", "=", "cw.sense.liquid_temp")
assert pick(thermometers, "plan[9].rung") == "cw.sense.core_temp", pick(thermometers, "plan[9].rung")
print("ok", "plan[9].rung", "=", "cw.sense.core_temp")

# Step 3: The difference is four sensors in the capability documents.
devices = c.get_devices()
assert pick(devices, "devices.demo-hob-robot.capabilities.sensors.length") == 5, pick(devices, "devices.demo-hob-robot.capabilities.sensors.length")
print("ok", "devices.demo-hob-robot.capabilities.sensors.length", "=", 5)
assert pick(devices, "devices.demo-hob-robot-basic.capabilities.sensors.length") == 1, pick(devices, "devices.demo-hob-robot-basic.capabilities.sensors.length")
print("ok", "devices.demo-hob-robot-basic.capabilities.sensors.length", "=", 1)

# Step 4: Both robots cut the vegetables under their camera; the knife step is identical.
assert pick(basic, "plan[0].rung") == "cw.sense.vision", pick(basic, "plan[0].rung")
print("ok", "plan[0].rung", "=", "cw.sense.vision")
assert pick(thermometers, "plan[0].rung") == "cw.sense.vision", pick(thermometers, "plan[0].rung")
print("ok", "plan[0].rung", "=", "cw.sense.vision")

print("scenario complete")

scenarios/031-compare-two-devices-on-one-recipe.json

Anterior: 030 Siguiente: 032