Example Code

Self-programming state machine

Code and Documents

Attachment

Overview

A pattern for re-sequencing machine states on the fly. This version is synchronous.

Description

The "self-programming" aspect of this example is in the "review experiment" case on the wiring diagram. A fixed number of new "tasks" are created by casting the random number to a defined "state". That "state" is injected into the queue. The content of the queue is unraveled at a controlled rate determined by the millisecond wait timer. The whole program stops when the "I'm done" state is tripped.

When used in actual code, the wait timer will typically be omitted. Calls to sub-vis will cause it to pause until data flow requirements are met. At which time it will proceed to the next state.

In actual use, an operator input or a real-world input would replace the random number generator, and cause a decision to be made about what step(s) to execute next.

A real-world use-case is to enable an operator to--in a limited way--resequence an experimental process in one of multiple conventional ways. The decomposition of the experiment is done in a way that each state corresponds to a small enough experimental step (activity | task) to program easily and independently into a given state. The particular experiment is hinted at by the activity names used in the example.


Imagining silly things to do with it:

  • Massively parallel simulation of monkeys-at-typewriters experiment to verify the probability of achieving a line of a Merton journal entry.
  • Create one node to simulate the behavior of a neuron. And another. Then hook them up... And have it call your cell. Where ever you are. [Lawn mower man.Flowers for Algernon.]

Steps to Implement or Execute Code

  1. Click the run button. Hopefully it stops soon for you. Depends on the random number generator seed on your box.
  2. Wait for it to finish.
  3. Study the code.

Requirements

Software

Hardware

Additional Images or Video



Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors