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

The boiling ladder rung by rung: thermometer, boil detector, estimate, time

Boiling is unattended-safe, so its ladder ends in time. Walk it with different sensor sets and see that a pan thermometer does not verify a pot of water.

Audience: robot maker · Objectif: Des robots pour les gens · Niveau: beginner

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

Étapes

  1. A liquid thermometer is the first rung. ladder

  2. A boil detector (bubbles, sound or steam) is the second. ladder

  3. Neither, estimates allowed: a logged model estimate. ladder

  4. Neither, estimates forbidden: time alone. ladder

  5. A pan-surface thermometer is not on the boiling ladder, so it changes nothing: time again. ladder

  6. Four rungs, in order.

Résultat

You can choose sensors for a product by reading ladders: a boil detector is enough for boiling, a pan thermometer is not. Next: scenario 027 lists the operations that never fall back to time.

Ligne de commande

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

Sortie enregistrée

Statut: ok

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

Code

Exécuter: python scenarios/out/026-boil-ladder-rung-by-rung/python.py

# Scenario 026: The boiling ladder rung by rung: thermometer, boil detector, estimate, time
# Boiling is unattended-safe, so its ladder ends in time. Walk it with different sensor sets and see that a pan thermometer does not verify a pot of water.
# 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 liquid thermometer is the first rung.
thermometer = c.ladder("cw.op.boil", ["cw.sense.liquid_temp"], True, False)

# Step 2: A boil detector (bubbles, sound or steam) is the second.
detector = c.ladder("cw.op.boil", ["cw.sense.boil_detect"], True, False)

# Step 3: Neither, estimates allowed: a logged model estimate.
estimate = c.ladder("cw.op.boil", [], True, False)

# Step 4: Neither, estimates forbidden: time alone.
time = c.ladder("cw.op.boil", [], False, False)

# Step 5: A pan-surface thermometer is not on the boiling ladder, so it changes nothing: time again.
wrongSensor = c.ladder("cw.op.boil", ["cw.sense.pan_surface_temp"], False, False)

# Step 6: Four rungs, in order.
assert thermometer == "cw.sense.liquid_temp", thermometer
print("ok", "thermometer", "=", "cw.sense.liquid_temp")
assert detector == "cw.sense.boil_detect", detector
print("ok", "detector", "=", "cw.sense.boil_detect")
assert estimate == "model", estimate
print("ok", "estimate", "=", "model")
assert time == "time", time
print("ok", "time", "=", "time")
assert wrongSensor == "time", wrongSensor
print("ok", "wrongSensor", "=", "time")

print("scenario complete")

scenarios/026-boil-ladder-rung-by-rung.json

Précédent: 025 Suivant: 027