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

Ask the sensor ladder which rung a device can satisfy for simmering, sauteing and deep frying

Each operation envelope lists ways to verify the step, best first. The ladder tool returns the first rung a device can satisfy, or null when the step must be refused.

Audiencia: robot maker · Objetivo: Robots para las personas · Nivel: beginner

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

Pasos

  1. Simmering with a liquid thermometer: the sensor is the first rung. ladder

  2. No thermometer, estimates allowed: a logged model estimate. ladder

  3. No thermometer, no estimates: simmering may run on time alone, because it is unattended-safe. ladder

  4. Sauteing with nothing and nobody: null. Its last rung is a person watching. ladder

  5. The same with a person present: the human rung. ladder

  6. Deep frying with a person present but no oil thermometer: still null. The ladder has one rung. ladder

  7. The six answers.

Resultado

You can predict, per operation, which sensors a device needs so that a plan does not fall back to a person. Next: scenario 026 walks the boiling ladder rung by rung.

Línea de comandos

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

Salida grabada

Estado: ok

[1] ladder: "cw.sense.liquid_temp"
[2] ladder: "model"
[3] ladder: "time"
[4] ladder: null
[5] ladder: "human"
[6] ladder: null

Código

Ejecutar: python scenarios/out/009-sensor-ladder-for-several-ops/python.py

# Scenario 009: Ask the sensor ladder which rung a device can satisfy for simmering, sauteing and deep frying
# Each operation envelope lists ways to verify the step, best first. The ladder tool returns the first rung a device can satisfy, or null when the step must be refused.
# 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: Simmering with a liquid thermometer: the sensor is the first rung.
simmerSensor = c.ladder("cw.op.simmer", ["cw.sense.liquid_temp"], True, False)

# Step 2: No thermometer, estimates allowed: a logged model estimate.
simmerModel = c.ladder("cw.op.simmer", [], True, False)

# Step 3: No thermometer, no estimates: simmering may run on time alone, because it is unattended-safe.
simmerTime = c.ladder("cw.op.simmer", [], False, False)

# Step 4: Sauteing with nothing and nobody: null. Its last rung is a person watching.
sauteAlone = c.ladder("cw.op.saute", [], False, False)

# Step 5: The same with a person present: the human rung.
sauteHuman = c.ladder("cw.op.saute", [], False, True)

# Step 6: Deep frying with a person present but no oil thermometer: still null. The ladder has one rung.
fryHuman = c.ladder("cw.op.deep_fry", [], True, True)

# Step 7: The six answers.
assert simmerSensor == "cw.sense.liquid_temp", simmerSensor
print("ok", "simmerSensor", "=", "cw.sense.liquid_temp")
assert simmerModel == "model", simmerModel
print("ok", "simmerModel", "=", "model")
assert simmerTime == "time", simmerTime
print("ok", "simmerTime", "=", "time")
assert sauteAlone == None, sauteAlone
print("ok", "sauteAlone", "=", None)
assert sauteHuman == "human", sauteHuman
print("ok", "sauteHuman", "=", "human")
assert fryHuman == None, fryHuman
print("ok", "fryHuman", "=", None)

print("scenario complete")

scenarios/009-sensor-ladder-for-several-ops.json

Anterior: 008 Siguiente: 010