Scilab

Chapter 9. Xcos-Finally!

Chapter 9.1 Introduction
Where does this “Finally” come from? Have you read or even watched the “Automatics” course? All experiments there are based on Scilab. For example, I modeled the response to a unit step of an oscillation unit and recorded it with ActivePresenter program. Thanks to this, the Dear Reader does not have to program anything, he just clicks on the video triangle and observes the reaction. But the poor author was tired of Scilab, or more precisely, its graphic application Xcos. I didn’t use any Scilab statements like if…then…else…while or for. I didn’t program anything in the classic sense of the word. And it was easy for me because I know what transmittance is. This is a basic concept of control theory, and more broadly, automatics. If you feel what the Inertial Unit, the Integrating Unit, the derivative… etc., I’m exaggerating a bit, but you don’t need to know differentiation and integration! All you need to do is draw a block diagram* in the Xcos program with a PID controller, a few transmittances, a unit step as an input and a disturbance, and what? And you see the answer at your fingertips. You can now change the PID controller settings and look for a “nicer” response. You tune the PID controller until the response is the “prettiest”, i.e. optimal. By the way, you can treat this and the following chapters as a mini automatics course.
Conclusion
If you know what transmittance is, modeling with Xcos will be a piece of cake for you. And you will rarely visit Scilab itself, of which Xcos is a part. Here I recommend chapters 1…10 of the “Automatics” course, where transmittance is presented mainly intuitively.
*Note to “you will draw a block diagram”
You will find that you can do it as easily as in Windows Paint. Especially since you download ready-made blocks from the so-called pallets.

Chapter 9.2 “Hello world” or Xcos welcomes you.
“Hello World” or 2+2=4 calculated with Xcos.
That is, not a Scilab instruction of the 2+2 Enter type, but a graphic program as below.

Rys. 9-1
2+2=4
calculated with Xcos
The graphical addition operation 2+2=4.0 is so obvious that I will spare the comment. The animation will show you how I programmed, sorry, drew it. But first I will place Xcos and the Palette Browser next to each other.

Chapter 9.3 How to set up Xcos and the Palette Browser side by side?
To easily create various block diagrams, i.e. program in Xcos.
But first, a very important note, maybe a request or even an order.
Below you will see an animation of how to place Xcos and the Palette Browser next to each other. Analyze it carefully.
Once you know, what is it about, REPEAT IT ON YOUR Xcos!
NOTE APPLIES TO ALL ANIMATIONS IN THE COURSE.
I even suggest being overzealous. Play with the parameters of the tested blocks. E.g. Change the jump amplitude, time offset by right clicking on the block.

Fig.9-2
Pallet Browser and Xcosa windows after animation.
After clicking the video “triangle”, you will see the next stages of the animation.
1. Clicking the Xcos icon in the Scilab console window
2. The Xcos and Palette Browser windows should appear. Here I don’t know why only Xcos. That’s why in the Xcos window I clicked View/Palette Browser.
3. The Palette Browser appeared in a strange place. That’s why I clicked on it, then I press the Windows key (aka Winkey, Start, Superkey) and the down cursor arrow key ← (move left) at the same time. The Palette browser is elegantly positioned in the left half of the screen and Xcos on the right. Sometimes there may be several smaller windows open on the right, including Xcos. Then click it.
4.Now we have the Palette Browser and Xcos next to each other.
We can start creating flowcharts. We will start with the simplest one in Fig.9-1.

Chapter 9.4 How does Xcos calculate 2+2=4?
So how did I program the diagram in Fig.9-1?

Fig.9-3
How did I create the diagram in Fig.9-1 performing the addition of 2+2=4?
On the left side we have a set of basic blocks grouped in the so-called pallets. I selected the necessary blocks from them and placed them on the right side of Xcos. Then I drew lines connecting the blocks and changed the parameters of the blocks, e.g. by setting 2 in const blocks. This is what programming is all about.
As you observe the animation, identify the steps below.
1. “Drag and drop” 2 const blocks from the Sources palette to the Xcos window.
2. “Drag and drop” the SUMMATION block from the Math Operations palette to the Xcos window.
3. “Drag and drop” the AFFICHE_m (“Digital Display”) block from the Sinks palette
4. “Drag and drop” the CLOCK_c (“Clock”) block from the Event Handling palette. I will mention the clock later. For now, take my word for it that it is necessary.
5. With the left mouse I drew lines connecting the blocks.
6. Notice that I have moved not the adder but the “subtractor” (symbol “-“) which subtracts . Therefore, I changed [1;-1] to [1;1] with the right mouse to create an adder.
7. I right-clicked on the const block and changed 1–>2.
8. I clicked the triangle icon to start the program. The result is 4 on the digital display. Victory–> 2+2=4. The graphics program works!
9. I changed blocks 2–>3 and 2–>4, it turns out that 3+4=4. And it should be 7! Guess why? I just didn’t press the “start” triangle.
10. After pressing the triangle “start” it is correct 3+4=7.
11. I saved the result of my work in a folder as the file ...Schems/9-3.zcos. You can save anywhere. You will find that it will come in handy.
Conclusion
The graphic from Fig.9-1 is a program that, like any other, has a beginning “start” and an ending “end”. By changing 2–>3 and 2–>4 I only changed the program. Only after execution it will it be 3+4=7. Xcos is so smart that it will change the graphics to a classic Scilab instruction program. There is no graphic advantage here over the 2+2 instructions written on the console. This will only work out with more complex blocks. E.g. Automatic Control System with PID controller. The scheme will be obvious to every automation engineer. And the appropriate Scilab text program? It’s better not to say. Especially since there are ODE functions with integration.
I advise you to implement the scheme yourself and calculate, for example, 3+5=8

Chapter 9.5 How does Xcos calculate 3×4=12?
We will modify the diagram from Fig.9-1 to the one below

Fig. 9-4
Scheme calculating 3×4=12
Just replace the adder from Fig.9-1 with a multiplier unit as in the animation.

Fig.9-5
Modification of the diagram from Fig.9-1 to Fig.9-5
1. Download the Scilab9-1 file from the place where you saved it in p.11 under Fig.9-4
2. Remove the adder
3. “Drag and drop” the Product block (“Multiply”) from the Math Operations palette to the Xcos window.
5. There is a “÷” symbol on the block. So, despite the name, it performs division. So I right-clicked on it and changed [1;-1] to [1;1]. Only now is it multiplying.
6. I drew the connecting lines and clicked the “Start” triangle. The diagram, or rather the “invisible” program associated with it, calculated 3×4=12.

Chapter 9.6 How does Xcos calculate 3:4=0.750?

Fig.9-6
Scheme calculating 3:4=0.750

Fig.9-7
Scheme calculating 3:4=0.750
1. Download the Scilab9-1 file from the place where you saved it in p.11 under Fig.9-4
2. Remove the adder
3. “Drag and drop” the Product block (“Multiply”) from the Math Operations palette to the Xcos window.
4. Despite its name, this block performs division! (“÷” symbol on the block). Therefore I don’t have to do anything.
5. I drew the connecting lines and clicked the “Start” triangle. The diagram, or rather the “invisible” program associated with it, calculated 3:4=0.8. He probably did it with an approximation, because it should be 0.75. Let’s find the reason.
6. I right-click on the AFFICH_m (“digital display”) block. Here in the settings I see 5 digits before the decimal point, but only 1 behind.
Therefore it was 3:4=0.8-->rounding up 0.75. I set 3 digits “after”.
7. After clicking the “Start” triangle, the program-scheme calculated correctly 3:4=0.750

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top