A tank level simulation and control #1187
Replies: 2 comments 1 reply
-
This is cool! For the |
Beta Was this translation helpful? Give feedback.
-
In v0.6.0, the application was refactored to use containers. The containers comprise:
This necessitated changing the observer pattern previously used between the UI For ease of use, on Linux you can run the dev_install.sh script to install and run the application. (Separately, I measured ~4 ms for a message to be sent via pubsub) |
Beta Was this translation helpful? Give feedback.
-
Not sure how many on this list are interested in industrial process control, apologies if none. Maybe the video is useful. This is simple demonstration of Toit implementing a tank level simulation, level control and display.
The system is a 100 gal water tank, filled from a valve with a 0-20 gpm (gallons/minute) range, with a random outflow from the tank of 4-12gpm. The tank level is to be controlled.
The control scheme to maintain the level is shown in the block diagram Tank Level Simulation. Engineers typically design and program modern controllers using control blocks rather than code. In main.toit you can see a textual representation of this, as below:
The scheme elements are declared (input, PID controller and output) and then connected. In older control systems interconnections were declared with block numbers and input/output numbers, both tedious and error prone. Textual references are used above for clarity. The scheme is an object model which is executed, rather than a compiled artifact. To eliminate runtime overhead in looking up block input/output references, a technique from HotDraw is used. When a connection is made from tank_lvl/out to pid01/pv, a connection object (of type Wire) is put in the pid01 input list. Then a method is declared in the PID class
the Wire class is defined as
so the pv value for pid01 is resolved at runtime via a series of message sends, rather than any lookup via Maps.
The process scheme just iterates over the modules, sending
tick
to each, where they update their outputs based on their inputs.A very crude user interface comprising a single Faceplate, is defined for the 128x128 TFT display. To communicate with the user interface, a Faceplate (an engineering term) module is defined in the control scheme, to allow variables to be displayed and user input gathered. An observer pattern is used, between the Faceplate and UI_Faceplate. In ui_elements.toit the class UI_Faceplate is responsible for drawing the Faceplate on the display and responding to update messages. The display and jog shuttle events are handled in ui_manager.toit.
The PID algorithm used to control the tank level is shown schematically in pid_block.pdf, implemented in the PID class in control_scheme.toit. It provides for auto/manual control transitions, options on SP tracking and does not suffer from "integral windup".
Containers and pubsub v2 could be used to refactor this demo, puting the controls in one container and the UI, whether to a local screen or web UI, in other containers.
demo.mp4
Beta Was this translation helpful? Give feedback.
All reactions