Hands-on

Let us develop a package that simulates the work of a flush-tank. Assuming that we have the (above explained) MySimulator package at hand let's start the development.

First we need to develop a principle diagram on how the thing is working. A quick sketch could look as follows:

A skech flush-tank diagram

From there we can identify the following components:

The tank can be modeled as a combination of an Adder and an Integrator. Assuming that the water throughput from the valve and the flusher is different, we can set the multipliers of the Adder accordingly. Let the valve throughput be one and and the flusher throughput be 3 times larger, then the multipliers would be 1 and -3 (as the flusher lets water out of the tank). The level of the tank can be found by integrating the Adders output. Hence the diagram of the tank in terms of CoCoViLa Dynamic System Simulation package would look as follows:

A tank diagram

Next, let's develop the Flusher component. For that we need to create a new diagram (Package>Load and MySimulator.xml. For more details see Creating a Mealy state chart).

Let's design the Flusher as an independent Mealy machine that from time to time opens the flushing valve of the tank. The first thing to do with the current implementation is always adding a Supervisor to the diagram.

In case of a Flusher it should have 2 states: Waiting and Flushing. These states correspond to the situation where the flusher (flushing valve) is open or closed. We model it by introducing a variable flushing. When moving over from one state to another the flusher is opened or closed and the flushing is evaluated to 1 or 0 accordingly. We are going to propagete the value of flushing outside the Flusher, hence it has to be declared as an output.

Flushing should stop when the level of water in the tank drops below some threshold. Let's introduce two more variables: minLevel (the threshold) and level (input from outside). We are going to change the state Open to Close when the level drops below minLevel

To imitate the operation of a flush-tank, flushing should take place every now and then. We can make it happen by measuring the elapsed time and setting randomly a waiting time until the flushing takes place next. For that we introduce variables waitingTime, timeElapsed and timeStep. The latter is acquired from the Supervisor and denotes the period of the machine execution.

All together the diagram would look as follows:

Flusher diagram

Below the diagram is the specification extension (Scheme>Extend...) where all the variables must be declared as well as the inputs and outputs. To finish developing the flusher component export it as a scheme object (as it is described in Create a new Scheme Object from a diagram). I would be advisable to define the minLevel as a field of the component.

The Valve component can be created similarly. It would be advisable to have some open and close levels set where the valve is opened and closed according to the tank level. These could be defined as fields as well.

Valve control diagram

Now, having the two Mealy machine components at hand we can complete our flush-tank diagram:

Flush-tank diagram

Do not forget to evaluate the fileds:

Flush-tank scheme objets' properties

And run your simulation. The output could look (as we use randomisation it definitely would look somewhat different in your case ;) ) the following:

Flush-tank operation simulation result

That's it. We hope you enjoied!