Software Overview  |  Sitemap  |  Downloads  |  Developers  |  Forums
Small_clear_logo_llc

State Machine, Examples of Tables in Compact YAML

# Anything on the same line after a '#' is a comment

# Tables for building logic functions

# Not, And, Or, Xor


# Not function
"not": [
  {When: {in: "on"}, Then: {out: "off"}},
  {When: {in: "off"}, Then: {out: "on"}}
]


# And function
"and": [
  # check state on all input terminal assertions
  # for illustrative purposes, use don't care inputs in the "When" clause
  # don't care means the "When" is true for any value of the input terminal
  # so these "When" clauses are true for any assertion on "in1" or "in2"
  {When: {in1: "*", in2: "*"},  State: {in1: "on", in2: "on"}, Then: {out: "on"}},
  {When: {in1: "*", in2: "*"},  State: {in1: "off"}, Then: {out: "off"}},
  {When: {in1: "*", in2: "*"},  State: {in2: "off"}, Then: {out: "off"}}
]


# Or function
"or": [
  # check state on all input terminal assertions
  # for illustrative purposes, list "When" transition states explicitly
  # also for illustrative purposes, use sets for defining "When" transition states
  # if the input value is in the set, the "When" is true
  {When: {in1: ["on", "off"], in2: ["on", "off"]},
    State: {in1: "on"}, Then: {out: "on"}},
  {When: {in1: ["on", "off"], in2: ["on", "off"]},
    State: {in2: "on"}, Then: {out: "on"}},
  {When: {in1: ["on", "off"], in2: ["on", "off"]},
    State: {in1: "off", in2: "off"}, Then: {out: "off"}}
]


# Xor function
"xor": [
  # "in1" and "in2" are don't care in "When" - check state for any assertion
  {When: {in1: "*", in2: "*"}, State: {in1: "on",in2: "off"}, Then: {out: "on"}},
  {When: {in1: "*", in2: "*"}, State: {in1: "off",in2: "on"}, Then: {out: "on"}},
  {When: {in1: "*", in2: "*"}, State: {in1: "off",in2: "off"}, Then: {out: "off"}},
  {When: {in1: "*", in2: "*"}, State: {in1: "on",in2: "on"}, Then: {out: "off"}}
]


# Counter function
# Counts when something stimulates its "in" input.
# When gets an "off" on its input, resets.
# Illustrates hidden state - counts input stimulations and then sets
# out to "on", if 5 non-"off" stimulations in a row.
# Table symbols which start with an underscore are not visible as terminals.
"count5": [
  {When: {in: "off"}, Then: {out: "off", _state: 0}}, # reset
  {When: {in: "*"}, State: {_state: 0}, Then: {_state: 1}},
  {When: {in: "*"}, State: {_state: 1}, Then: {_state: 2}},
  {When: {in: "*"}, State: {_state: 2}, Then: {_state: 3}},
  {When: {in: "*"}, State: {_state: 3}, Then: {_state: 4}},
  {When: {in: "*"}, State: {_state: 4}, Then: {out: "on"}}, # stay here
  # If get here, state not yet initialized.
  # Act like was just in 0 state.
  {When: {in: "*"}, Then: {out: "off", _state: 1}}
]

Catalina Computing, LLC.

Copyright © Catalina Computing, LLC. (2013-2018)




Page last updated: Thu Apr 10 15:55:22 2014 (UTC)