See also News, release AFSM 2.0
Aug 15, 2019. Busy with the make of a control for a fish tank. At the moment i have made a basic set of controlblocks and made the functionallity for the lightning (3 groups). started this week with a base for the control, check the movie!
In the movie a lot of the possibilties of the AFSM are presented, like the masking and forcing of I/O, the presentation of fully automatical or manual mode. New in the standard is made the presentation of the FSM mode and the uptime of the board in the dashboard part of the HMI screen. Lot of challanges; what is the best level transmitter, what sort of extra instruments do i need...?
Just for fun, i started this project with a demo of a PID control. The proces is simple; take two plastic boxes, half full water and mount 2 pumps and a ultrasonic device for measuring the volume of water in one of the boxes. For a PID control you need at least a setpoint, a procesvalue, the parameters for the controller (P, I, D actions) and the ibrary for the PID control and the "field". The picture below is the P&ID (proces instrumentation diagram):
It is very simple and easy to explain (... and not very usefull but a nice example for a PID control). P02 (pump 2), is pumping the water from Tank 02 into Tank 01 with a predifined speed. P01 (pump 1) has to keep the same volume into Tank 01 by means of the PID-control. P02 can be set on different fixed outputs, so P01 has to control speed to keep te same volume in Tank 01. The volume is measured by the LT called DM1. DM1 is the ultrasonic device above Tank 01 and measures the distance of the sensor to the water surface (and so the volume in tank 01).
Some info about the hardware:
- For the pumps i used two 12Vdc pumps
- For regulating the pumps one L298N Dual H bridge stepper motor control
- The HC SR04 Ultrasonic device
- Some plastic hoses and 2 plastic boxes of about 2 ltr each.
- The PID-1.2.0 library and the AFSM standard software
- A serial to UBS converter to communicate with HMI
Explanation for "START" state:
In the start state the setpoint and the parameters for the controller are set. An array is filled to get rid of some disruptions from the Ultrasonic device. The average of 5 measurements is used as Process value for the control. Also pay attention for the controller direction. A "reverse" control means; when the input is accending the output of the control has to do same. In this case; when the level in Tank 1 is going up, P01 has to speed up for keeping the setpoint level. The opposite of "reverse" is "direct". For example an autopilot in a car; when the speed is dropping, the motor has to increase power to keep the disired speed.
When the "START" button is pressed; the state will got to "REGULATE".
Explanation of "REGULATE" state:
Every 200ms the input is measured and the output value is calculated by the PID control. After computing the ouput, it is set as a PWN value for the H bridge for P01. The output will only be set when it is greater then 155. If the value is lower than 155 the pump is not producing water. EN1 is set to command -start- P01 in the positive direction. If the "STOP" button is pressed, the state is again set to "START" (PID control is stopped).
How does it look on the plotter:
Red is the PV, process value; water level
Blue is the ouput of the controller; P01
Orange is the ouput of the fixed pump; P02
The plot show a flat line -with some noise- for the water level (as expected for this controller)
... and the installation of it on photo:
Initial HMI screen:
The states 25, 50, 75, 100 are run in a second FSM thread, parallel on the PID control thread. Every 5 minutes P02 is set on a new speed. As you can see in the plotter screen, P01 is following this "disturbance". For example, see the P02 states below. At the end of state "100", the thread is stopt; transition to the "END" state. P02 is stopt.
- The Python3 program for the serial connection with the MEGA board is now also capable of presenting and forcing Markers. Until now only DI/DO/AI/AO, Ultrasonics and TT's where possible tags.
- Also extra is the presentation of tooltips under the tagnames. When clicking on the tagname, extra hardware information is presented (like e.g. the used hardware pin number). The info is automatic obtained from the MEGA board with the GMI metadata message.
- Next step will be the writing of other variable types like AI/AO, TT and markers to the MySql database on the Raspberry PI3b. At the moment it is only possible to write digital IO to the MySql database.
The new software is available in the download part.
Example sketch: The floor lamp
In the new standard, serial3 is used for communication between boards. It must be activated by setting the global boolean UseIntercard to true (Userconfiguration.h). At the end of every FSM cycle serial3 is checked on available data. If there is data, just one message will be processed each time (leaving available data for the next cycle). By processing the message, one of the global variables for intercard communication is set for just one cycle in the FSM loop. After one cycle all global strings are blanked. It is possible to send 4 different messages to another board; @CHAR01 followed by one character; @CHAR10, followed by max 10 characters; @INT001, followed by just one number and @INT003, followed by 3 numbers. When receiving an Intercard message, the following global strings are set for just one FSM cycle; IntercardChar01, IntercardChar10, IntercardInt001 and IntercardInt003 (depending on the "expected" Intercard message). While using this communication, be aware to check on the globals while running the cycles (it is easy to miss the message).
At the moment the software is in a test phase. A possible application of the Intercard protocol is project "Notification call systems". See under "Projects" for the full description or click here.
figure. simple Intercard communication.