Difference between revisions of "Scilab/C4/Conditional-operations-in-Xcos/English"
(Created page with "'''Title of script''': Conditional operations in Xcos '''Author: Rupak Rokade and Utkarsh''' '''Keywords: Xcos, conditional operation, scilab, if-else, loops''' {|border...") |
Nancyvarkey (Talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
− | ''' | + | '''tTitle of script''': Conditional operations in Xcos |
'''Author: Rupak Rokade and Utkarsh''' | '''Author: Rupak Rokade and Utkarsh''' | ||
Line 5: | Line 5: | ||
'''Keywords: Xcos, conditional operation, scilab, if-else, loops''' | '''Keywords: Xcos, conditional operation, scilab, if-else, loops''' | ||
− | + | {|border=1 | |
− | + | ! '''Visual Cue''' | |
− | {|border = 1 | + | ! '''Narration''' |
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
Line 23: | Line 21: | ||
| | | | ||
In this tutorial, we will learn how to: | In this tutorial, we will learn how to: | ||
+ | |||
+ | *Use the '''If then Else conditional operator''' in '''Xcos'''. | ||
+ | *Display the output of the '''conditional operations.''' | ||
+ | *Halt the '''simulation''' after a '''condition''' is reached. | ||
|- | |- | ||
| | | | ||
Line 28: | Line 30: | ||
'''System Requirements''' | '''System Requirements''' | ||
− | | To record this tutorial, I am using | + | | |
+ | To record this tutorial, I am using | ||
+ | |||
+ | *'''Ubuntu 18.04 OS''' and | ||
+ | *'''Scilab version 6.1.0''' | ||
|- | |- | ||
| | | | ||
Line 37: | Line 43: | ||
To follow this tutorial, you should have : | To follow this tutorial, you should have : | ||
− | + | *Basic knowledge of '''Scilab''' and '''Xcos.''' | |
− | + | *If not, then go through the '''Scilab''' spoken tutorials on this website. | |
− | If not, then go through the '''Scilab''' spoken tutorials on this website. | + | |
|- | |- | ||
| | | | ||
− | Show Slide: | + | Show Slide: |
'''Code Files''' | '''Code Files''' | ||
| | | | ||
+ | *The files used in this tutorial are provided in the '''Code files''' link. | ||
+ | *Please download and extract the files. | ||
+ | *Make a copy and then use them while practising. | ||
|- | |- | ||
| Cursor on the '''Untitled Xcos''' window. | | Cursor on the '''Untitled Xcos''' window. | ||
− | | | + | |I have already opened the '''Xcos''' window. |
− | I have already opened the '''Xcos''' window. | + | |
− | + | ||
− | + | ||
We can see two windows named '''Untitled Xcos''' and the '''Palette browser.''' | We can see two windows named '''Untitled Xcos''' and the '''Palette browser.''' | ||
Line 57: | Line 62: | ||
| | | | ||
On the '''Untitled Xcos''' window, | On the '''Untitled Xcos''' window, | ||
− | |||
− | |||
Cursor on '''Toolbar''' >> Click on '''Open file''' option >> Click on '''ConditionalOperations.xcos''' >> Click on '''OK.''' | Cursor on '''Toolbar''' >> Click on '''Open file''' option >> Click on '''ConditionalOperations.xcos''' >> Click on '''OK.''' | ||
| | | | ||
Go to the '''Untitled Xcos''' window. | Go to the '''Untitled Xcos''' window. | ||
− | |||
− | |||
Click on the '''Open File''' icon on the '''Toolbar'''. | Click on the '''Open File''' icon on the '''Toolbar'''. | ||
− | |||
− | |||
A window will appear. | A window will appear. | ||
− | |||
− | |||
Go to the '''Downloads''' folder and select the file '''ConditionalOperations.xcos.''' | Go to the '''Downloads''' folder and select the file '''ConditionalOperations.xcos.''' | ||
− | |||
− | |||
Then click on the '''OK''' button. | Then click on the '''OK''' button. | ||
− | |||
− | |||
I have already created this file for demonstration. | I have already created this file for demonstration. | ||
|- | |- | ||
− | | cursor on the '''ConditionalOperations.xcos '''window. | + | | cursor on the '''ConditionalOperations.xcos''' window. |
− | | | + | | This file has a simple '''Xcos simulation''' diagram. |
− | This file has a simple '''Xcos''' | + | |
|- | |- | ||
| Cursor on '''ConditionalOperations.xcos window''' | | Cursor on '''ConditionalOperations.xcos window''' | ||
| | | | ||
− | Let us add conditional expressions to this file. | + | Let us add '''conditional expressions''' to this file. |
− | + | To add '''conditional expressions''' we will use the '''Expression block'''. | |
− | + | ||
− | To add conditional expressions we will use the '''Expression''' | + | |
|- | |- | ||
| | | | ||
On '''palette browser''', | On '''palette browser''', | ||
− | |||
− | |||
click on '''user-defined-functions''' >> click on '''Expression.''' | click on '''user-defined-functions''' >> click on '''Expression.''' | ||
| | | | ||
− | Go to the''' palette browser''' window. | + | Go to the '''palette browser''' window. |
Click on the '''User-Defined-Functions''' section. | Click on the '''User-Defined-Functions''' section. | ||
− | In the right panel, select the '''Expression''' | + | In the right panel, select the '''Expression block'''. |
|- | |- | ||
− | | Drag the ''' | + | | Drag the '''Expression block''' and drop it on the '''ConditionalOperations.xcos window.''' |
− | | | + | | Drag and drop the '''Expression block''' on the '''ConditionalOperations.xcos''' window. |
|- | |- | ||
| | | | ||
On '''ConditionalOperations.xcos window''', | On '''ConditionalOperations.xcos window''', | ||
− | |||
− | |||
Double click on the '''Expression''' block. | Double click on the '''Expression''' block. | ||
− | | Double click on the''' Expression block''' to configure its properties. | + | | Double click on the '''Expression block''' to '''configure''' its properties. |
|- | |- | ||
| | | | ||
− | On '''Scilab Multiple Request''' | + | On '''Scilab Multiple Request''' window, |
− | + | ||
− | + | ||
Double click on '''Number of Input''' textbox to highlight it >> Change it to '''1'''. | Double click on '''Number of Input''' textbox to highlight it >> Change it to '''1'''. | ||
| | | | ||
− | First is the ''' | + | First is the '''Number of inputs'''. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | By default it is '''2''' which means it can receive 2 input values. | ||
Let us change it to '''1'''. | Let us change it to '''1'''. | ||
Line 140: | Line 120: | ||
On '''Scilab Multiple Request''' Window, | On '''Scilab Multiple Request''' Window, | ||
− | + | Double click on '''scilab expression''' textbox to highlight it >> type '''(u1>10)*1''' '''.''' | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Double click on '''scilab expression '''textbox to highlight it >> type '''(u1>10)*1 .''' | + | |
| | | | ||
− | Next, is the '''conditional expression'''. | + | Next, is the '''conditional expression'''. |
+ | This is the '''expression''' which will be evaluated by the '''Expression block'''. | ||
+ | In '''Xcos,''' by default '''variables''' like '''u1, u2''' are used while writing the '''conditional expressions'''. | ||
− | + | Let us change the default '''expression'''. | |
− | + | Enter the '''expression''' as shown here. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
On '''Scilab Multiple Request''' Window, | On '''Scilab Multiple Request''' Window, | ||
− | + | Double click on the scilab '''expression''' textbox to highlight it. | |
− | + | | This means that, if '''''u1 > 10''''' then the '''block''' should '''return 1'''. | |
− | Double click on the scilab''' expression '''textbox to highlight it. | + | |
− | | | + | |
− | This means that, if '''''u1 > 10''''' then the block should | + | |
|- | |- | ||
| | | | ||
On '''Scilab Multiple Request''' Window, | On '''Scilab Multiple Request''' Window, | ||
− | |||
− | |||
Click on the '''OK''' button. | Click on the '''OK''' button. | ||
Line 189: | Line 146: | ||
| Cursor on '''ConditionalOperations.xcos window''' | | Cursor on '''ConditionalOperations.xcos window''' | ||
| | | | ||
− | Let us display the output of the '''Expression''' | + | Let us display the output of the '''Expression block'''. |
− | + | To do this, we will use the '''AFFICH_m block'''. | |
− | + | ||
− | To do this, we will use the '''AFFICH_m''' | + | |
|- | |- | ||
| | | | ||
− | On ''' | + | On '''Palette browser''', |
− | + | ||
− | + | ||
click on '''sinks''' >> click on '''AFFICH_m.''' | click on '''sinks''' >> click on '''AFFICH_m.''' | ||
| | | | ||
− | Go to the''' | + | Go to the '''Palette browser''' window. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | Click on the '''Sinks palette'''. | ||
− | In the right panel, select the '''AFFICH_m''' | + | In the right panel, select the '''AFFICH_m block'''. |
|- | |- | ||
| Drag the '''AFFICH_m''' block and drop it on the '''ConditionalOperations.xcos window.''' | | Drag the '''AFFICH_m''' block and drop it on the '''ConditionalOperations.xcos window.''' | ||
− | | | + | | Drag and drop the '''AFFICH_m block''' on the '''ConditionalOperations.xcos''' window. |
|- | |- | ||
| | | | ||
On '''ConditionalOperations.xcos Window''', | On '''ConditionalOperations.xcos Window''', | ||
− | Connect as per narration | + | Connect as per narration |
| | | | ||
Let us make the connections. | Let us make the connections. | ||
+ | Select the '''black input port''' of the '''EXPRESSION block'''. | ||
− | + | Connect it to the line joining the '''RAMP''' and the '''CSCOPE block'''. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Connect it to the line joining the''' RAMP''' and the '''CSCOPE''' | + | |
|- | |- | ||
| | | | ||
Line 235: | Line 180: | ||
Connect as per narration'''.''' | Connect as per narration'''.''' | ||
| | | | ||
− | Next, Select the '''black output port''' of the '''EXPRESSION''' | + | Next, Select the '''black output port''' of the '''EXPRESSION block'''. |
− | + | Connect it to the '''black input port''' of the '''AFFICH_m block'''. | |
− | + | ||
− | Connect it to the '''black input port''' of the '''AFFICH_m''' | + | |
|- | |- | ||
| | | | ||
Line 246: | Line 189: | ||
Connect as per narration'''.''' | Connect as per narration'''.''' | ||
| | | | ||
− | Lastly, | + | Lastly, select the '''red input port''' of the '''AFFICH_m block'''. |
+ | Connect it to the line joining the '''CLOCK_c''' and the '''CSCOPE block'''. | ||
− | + | Our file is ready for '''simulation'''. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
− | On the''' menu bar,''' | + | On the '''menu bar,''' |
Click on '''Simulation''' >> Click on '''Setup.''' | Click on '''Simulation''' >> Click on '''Setup.''' | ||
| | | | ||
− | Before that, we need to change the execution time to | + | Before that, we need to change the '''execution''' time to real-time. |
− | + | ||
− | + | ||
On the '''menu bar''', click on '''Simulation.''' | On the '''menu bar''', click on '''Simulation.''' | ||
− | |||
− | |||
Click on '''Setup.''' | Click on '''Setup.''' | ||
|- | |- | ||
| | | | ||
− | On '''Set parameters '''window''',''' | + | On '''Set parameters''' window''',''' |
Change '''Real Time Scaling''' to 1 >> Click on '''OK''' button. | Change '''Real Time Scaling''' to 1 >> Click on '''OK''' button. | ||
| | | | ||
Change '''Real Time Scaling''' to '''1'''. | Change '''Real Time Scaling''' to '''1'''. | ||
− | |||
− | |||
Click on the '''OK''' button. | Click on the '''OK''' button. | ||
Line 284: | Line 217: | ||
| | | | ||
On the '''ConditionalOperations.xcos''' window, | On the '''ConditionalOperations.xcos''' window, | ||
− | |||
− | |||
Click on '''Start''' button on the toolbar >> click on '''OK''' button on the Warning Message. | Click on '''Start''' button on the toolbar >> click on '''OK''' button on the Warning Message. | ||
| | | | ||
− | Let us run this simulation by clicking on the '''Start''' | + | Let us '''run''' this '''simulation''' by clicking on the '''Start''' button on the '''toolbar'''. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | A '''Warning Message''' will appear. | ||
Ignore the message and click on the '''OK''' button. | Ignore the message and click on the '''OK''' button. | ||
|- | |- | ||
| | | | ||
− | On the '''ConditionalOperations.xcos '''window, | + | On the '''ConditionalOperations.xcos''' window, |
− | + | ||
− | + | ||
Cursor on '''AFFICH_m''' block. | Cursor on '''AFFICH_m''' block. | ||
| | | | ||
− | We can see the '''AFFICH_m ''' | + | We can see that the '''AFFICH_m block''' displays '''0''' as long as the graph is less than '''10''' . |
− | + | ||
− | + | ||
− | After the graph exceeds '''10''' the '''AFFICH_m''' | + | After the graph exceeds '''10''' the '''AFFICH_m block''' displays '''1'''. |
|- | |- | ||
| Cursor on the '''Graphic Window.''' | | Cursor on the '''Graphic Window.''' | ||
| | | | ||
− | Suppose we want our simulation to end after some condition has been achieved. | + | Suppose we want our '''simulation''' to end after some '''condition''' has been achieved. |
− | + | To do this, we will use the '''IFTHEL_f block'''. This is the '''IF-ELSE block'''. | |
− | + | ||
− | To do this, we will use the '''IFTHEL_f''' | + | |
|- | |- | ||
| Close the '''Graphic Window.''' | | Close the '''Graphic Window.''' | ||
− | | | + | | Let’s close the '''Graphic window.''' |
|- | |- | ||
| | | | ||
On '''palette browser''', | On '''palette browser''', | ||
− | |||
− | |||
click on '''Event-Handling''' >> click on '''IFTHEL_f.''' | click on '''Event-Handling''' >> click on '''IFTHEL_f.''' | ||
| | | | ||
− | Go to the''' palette browser''' window. | + | Go to the '''palette browser''' window. |
− | + | ||
− | + | ||
Click on the '''Event Handling''' section. | Click on the '''Event Handling''' section. | ||
− | + | In the right panel, select the '''IFTHEL_f block'''. | |
− | + | ||
− | In the right panel, select the '''IFTHEL_f''' | + | |
|- | |- | ||
− | | Drag the '''IFTHEL_f ''' | + | | Drag the '''IFTHEL_f block''' and drop it on the '''ConditionalOperations.xcos''' window. |
− | | '''Drag and drop''' the '''IFTHEL_f''' | + | | '''Drag and drop''' the '''IFTHEL_f block''' on the '''ConditionalOperations.xcos''' window. |
|- | |- | ||
| | | | ||
− | On the '''ConditionalOperations.xcos '''window, | + | On the '''ConditionalOperations.xcos''' window, |
− | + | Cursor on '''IFTHEL_m''' block. | |
− | + | | Now, to halt the '''simulation''' we would need the '''HALT_f block'''. | |
− | Cursor on '''IFTHEL_m '''block. | + | |
− | | Now, to halt the simulation we would need the '''HALT_f''' | + | |
|- | |- | ||
| | | | ||
On '''palette browser''', | On '''palette browser''', | ||
− | |||
− | |||
click on '''Event-Handling''' >> click on '''HALT_f.''' | click on '''Event-Handling''' >> click on '''HALT_f.''' | ||
| | | | ||
− | Go to the''' palette browser''' window. | + | Go to the '''palette browser''' window. |
− | + | ||
− | + | ||
Click on the '''Event Handling''' section. | Click on the '''Event Handling''' section. | ||
− | + | In the right panel, select the '''HALT_f block'''. | |
− | + | ||
− | In the right panel, select the '''HALT_f''' | + | |
|- | |- | ||
− | | Drag the '''HALT_f ''' block and drop it on the '''ConditionalOperations.xcos window.''' | + | | Drag the '''HALT_f''' block and drop it on the '''ConditionalOperations.xcos window.''' |
− | | '''Drag and drop''' the '''HALT_f''' | + | | '''Drag and drop''' the '''HALT_f block''' on the '''ConditionalOperations.xcos''' window. |
|- | |- | ||
| | | | ||
− | On the '''ConditionalOperations.xcos '''window, | + | On the '''ConditionalOperations.xcos''' window, |
− | + | Cursor on '''HALT_f''' block. | |
− | + | | The '''HALT_f block''' will end the '''simulation''' when the '''condition''' in the '''IFTHEL_f block''' is satisfied. | |
− | Cursor on '''HALT_f '''block. | + | |
− | | The''' HALT_f ''' | + | |
|- | |- | ||
| | | | ||
Line 386: | Line 291: | ||
Let us make the connections. | Let us make the connections. | ||
+ | Select the '''black input port''' of the '''IFTHEL_f block'''. | ||
− | + | Connect it to the line joining the '''EXPRESSION''' and the '''AFFICH_m block'''. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Connect it to the line joining the''' EXPRESSION''' and the '''AFFICH_m''' | + | |
|- | |- | ||
| | | | ||
Line 399: | Line 300: | ||
Connect as per narration'''.''' | Connect as per narration'''.''' | ||
| | | | ||
− | Next, | + | Next, select any of the '''red output ports''' of the '''IFTHEL_f block'''. |
− | + | Connect it to the '''red input port''' of the '''HALT_f block'''. | |
− | + | ||
− | Connect it to the '''red input port''' of the '''HALT_f''' | + | |
|- | |- | ||
| | | | ||
Line 410: | Line 309: | ||
Connect as per narration'''.''' | Connect as per narration'''.''' | ||
| | | | ||
− | Lastly, | + | Lastly, select the '''red input port''' of the '''IFTHEL_f block'''. |
− | + | ||
− | + | ||
− | Connect it to the line entering the '''red input port''' of the '''AFFICH_m | + | Connect it to the line entering the '''red input port''' of the '''AFFICH_m block'''. |
|- | |- | ||
| | | | ||
On the '''ConditionalOperations.xcos''' window, | On the '''ConditionalOperations.xcos''' window, | ||
− | |||
− | |||
Click on '''Start''' button on the toolbar >> click on '''OK''' button on the Warning Message. | Click on '''Start''' button on the toolbar >> click on '''OK''' button on the Warning Message. | ||
| | | | ||
− | Let us run this simulation again by clicking on the '''Start''' | + | Let us '''run''' this '''simulation''' again by clicking on the '''Start''' button on the '''toolbar'''. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | A '''Warning Message''' will appear. | ||
Ignore the message and click on the '''OK''' button. | Ignore the message and click on the '''OK''' button. | ||
|- | |- | ||
| | | | ||
− | On the '''ConditionalOperations.xcos '''window, | + | On the '''ConditionalOperations.xcos''' window, |
− | + | Cursor on '''AFFICH_m''' block. | |
− | + | ||
− | Cursor on '''AFFICH_m '''block. | + | |
| | | | ||
− | Observe that as soon as the value in the '''AFFICH_m''' | + | Observe that as soon as the value in the '''AFFICH_m block''' becomes '''1''', the '''simulation''' stops. |
− | + | So this way we can use '''conditional operations''' in '''Xcos'''. | |
− | + | ||
− | So this way we can use conditional operations in '''Xcos'''. | + | |
|- | |- | ||
| | | | ||
Line 453: | Line 340: | ||
This brings us to the end of this tutorial. Let us summarise. | This brings us to the end of this tutorial. Let us summarise. | ||
+ | In this tutorial, we have learnt to: | ||
− | + | *Use the '''If then Else conditional operator''' in '''Xcos'''. | |
− | + | *Display the output of the '''conditional operations'''. | |
+ | *Halt the '''simulation''' after a '''condition''' is reached. | ||
|- | |- | ||
| | | | ||
Line 464: | Line 353: | ||
As an assignment | As an assignment | ||
+ | Create a '''Xcos Simulation''' file to: | ||
− | + | *Plot a straight line with slope 5. | |
− | + | *Apply a '''conditional operator''' which will output 1 if the value is divisible by 9. | |
+ | *Halt the '''simulation''' when the '''condition''' evaluates to '''True'''. | ||
|- | |- | ||
| Show Slide: '''About Spoken Tutorial project''' | | Show Slide: '''About Spoken Tutorial project''' | ||
| | | | ||
The video at the following link summarises the Spoken Tutorial project. | The video at the following link summarises the Spoken Tutorial project. | ||
− | |||
− | |||
Please download and watch it | Please download and watch it | ||
Line 479: | Line 368: | ||
| | | | ||
The Spoken Tutorial Project team conducts workshops and gives certificates. | The Spoken Tutorial Project team conducts workshops and gives certificates. | ||
− | |||
− | |||
For more details, please write to us. | For more details, please write to us. | ||
Line 488: | Line 375: | ||
'''Answers for THIS Spoken Tutorial''' | '''Answers for THIS Spoken Tutorial''' | ||
− | | | + | | Please post your timed queries in this forum. |
− | Please post your timed queries in this forum. | + | |
|- | |- | ||
| Show Slide: '''FOSSEE Forum''' | | Show Slide: '''FOSSEE Forum''' | ||
Line 500: | Line 386: | ||
| | | | ||
The FOSSEE team coordinates the Textbook Companion project. | The FOSSEE team coordinates the Textbook Companion project. | ||
− | |||
− | |||
We give Certificates and Honorarium to the contributors. | We give Certificates and Honorarium to the contributors. | ||
− | + | For more details, please visit this website. | |
− | + | ||
− | For more details, please visit this | + | |
|- | |- | ||
− | | | + | | Show Slide: '''Lab Migration''' |
− | Show Slide: '''Lab Migration''' | + | |
| | | | ||
The FOSSEE team coordinates the Lab Migration project. | The FOSSEE team coordinates the Lab Migration project. | ||
− | + | For more details, please visit this website. | |
− | + | ||
− | For more details, please visit this | + | |
|- | |- | ||
− | | | + | | Show Slide: '''Acknowledgement''' |
− | Show Slide: '''Acknowledgement''' | + | |
| Spoken Tutorial and FOSSEE projects are funded by the Ministry of Education, Government of India. | | Spoken Tutorial and FOSSEE projects are funded by the Ministry of Education, Government of India. | ||
|- | |- | ||
Line 525: | Line 403: | ||
| | | | ||
This is Utkarsh, FOSSEE intern 2021, IIT Bombay signing off. | This is Utkarsh, FOSSEE intern 2021, IIT Bombay signing off. | ||
− | |||
− | |||
Thanks for joining. | Thanks for joining. | ||
|} | |} | ||
− | |||
− |
Latest revision as of 17:37, 21 September 2021
tTitle of script: Conditional operations in Xcos
Author: Rupak Rokade and Utkarsh
Keywords: Xcos, conditional operation, scilab, if-else, loops
Visual Cue | Narration |
---|---|
Show Slide: Title Slide |
Hello and welcome to the Spoken Tutorial on “Conditional Operations in Xcos”. |
Show Slide: Learning Objectives |
In this tutorial, we will learn how to:
|
Show Slide: System Requirements |
To record this tutorial, I am using
|
Show Slide: Pre-requisites |
To follow this tutorial, you should have :
|
Show Slide: Code Files |
|
Cursor on the Untitled Xcos window. | I have already opened the Xcos window.
We can see two windows named Untitled Xcos and the Palette browser. |
On the Untitled Xcos window, Cursor on Toolbar >> Click on Open file option >> Click on ConditionalOperations.xcos >> Click on OK. |
Go to the Untitled Xcos window. Click on the Open File icon on the Toolbar. A window will appear. Go to the Downloads folder and select the file ConditionalOperations.xcos. Then click on the OK button. I have already created this file for demonstration. |
cursor on the ConditionalOperations.xcos window. | This file has a simple Xcos simulation diagram. |
Cursor on ConditionalOperations.xcos window |
Let us add conditional expressions to this file. To add conditional expressions we will use the Expression block. |
On palette browser, click on user-defined-functions >> click on Expression. |
Go to the palette browser window. Click on the User-Defined-Functions section. In the right panel, select the Expression block. |
Drag the Expression block and drop it on the ConditionalOperations.xcos window. | Drag and drop the Expression block on the ConditionalOperations.xcos window. |
On ConditionalOperations.xcos window, Double click on the Expression block. |
Double click on the Expression block to configure its properties. |
On Scilab Multiple Request window, Double click on Number of Input textbox to highlight it >> Change it to 1. |
First is the Number of inputs. By default it is 2 which means it can receive 2 input values. Let us change it to 1. |
On Scilab Multiple Request Window, Double click on scilab expression textbox to highlight it >> type (u1>10)*1 . |
Next, is the conditional expression. This is the expression which will be evaluated by the Expression block. In Xcos, by default variables like u1, u2 are used while writing the conditional expressions. Let us change the default expression. Enter the expression as shown here. |
On Scilab Multiple Request Window, Double click on the scilab expression textbox to highlight it. |
This means that, if u1 > 10 then the block should return 1. |
On Scilab Multiple Request Window, Click on the OK button. |
Click on the OK button. |
Cursor on ConditionalOperations.xcos window |
Let us display the output of the Expression block. To do this, we will use the AFFICH_m block. |
On Palette browser, click on sinks >> click on AFFICH_m. |
Go to the Palette browser window. Click on the Sinks palette. In the right panel, select the AFFICH_m block. |
Drag the AFFICH_m block and drop it on the ConditionalOperations.xcos window. | Drag and drop the AFFICH_m block on the ConditionalOperations.xcos window. |
On ConditionalOperations.xcos Window, Connect as per narration |
Let us make the connections. Select the black input port of the EXPRESSION block. Connect it to the line joining the RAMP and the CSCOPE block. |
On ConditionalOperations.xcos Window, Connect as per narration. |
Next, Select the black output port of the EXPRESSION block. Connect it to the black input port of the AFFICH_m block. |
On ConditionalOperations.xcos Window, Connect as per narration. |
Lastly, select the red input port of the AFFICH_m block. Connect it to the line joining the CLOCK_c and the CSCOPE block. Our file is ready for simulation. |
On the menu bar, Click on Simulation >> Click on Setup. |
Before that, we need to change the execution time to real-time. On the menu bar, click on Simulation. Click on Setup. |
On Set parameters window, Change Real Time Scaling to 1 >> Click on OK button. |
Change Real Time Scaling to 1. Click on the OK button. |
On the ConditionalOperations.xcos window, Click on Start button on the toolbar >> click on OK button on the Warning Message. |
Let us run this simulation by clicking on the Start button on the toolbar. A Warning Message will appear. Ignore the message and click on the OK button. |
On the ConditionalOperations.xcos window, Cursor on AFFICH_m block. |
We can see that the AFFICH_m block displays 0 as long as the graph is less than 10 . After the graph exceeds 10 the AFFICH_m block displays 1. |
Cursor on the Graphic Window. |
Suppose we want our simulation to end after some condition has been achieved. To do this, we will use the IFTHEL_f block. This is the IF-ELSE block. |
Close the Graphic Window. | Let’s close the Graphic window. |
On palette browser, click on Event-Handling >> click on IFTHEL_f. |
Go to the palette browser window. Click on the Event Handling section. In the right panel, select the IFTHEL_f block. |
Drag the IFTHEL_f block and drop it on the ConditionalOperations.xcos window. | Drag and drop the IFTHEL_f block on the ConditionalOperations.xcos window. |
On the ConditionalOperations.xcos window, Cursor on IFTHEL_m block. |
Now, to halt the simulation we would need the HALT_f block. |
On palette browser, click on Event-Handling >> click on HALT_f. |
Go to the palette browser window. Click on the Event Handling section. In the right panel, select the HALT_f block. |
Drag the HALT_f block and drop it on the ConditionalOperations.xcos window. | Drag and drop the HALT_f block on the ConditionalOperations.xcos window. |
On the ConditionalOperations.xcos window, Cursor on HALT_f block. |
The HALT_f block will end the simulation when the condition in the IFTHEL_f block is satisfied. |
On ConditionalOperations.xcos Window, Connect as per narration. |
Let us make the connections. Select the black input port of the IFTHEL_f block. Connect it to the line joining the EXPRESSION and the AFFICH_m block. |
On ConditionalOperations.xcos Window, Connect as per narration. |
Next, select any of the red output ports of the IFTHEL_f block. Connect it to the red input port of the HALT_f block. |
On ConditionalOperations.xcos Window, Connect as per narration. |
Lastly, select the red input port of the IFTHEL_f block. Connect it to the line entering the red input port of the AFFICH_m block. |
On the ConditionalOperations.xcos window, Click on Start button on the toolbar >> click on OK button on the Warning Message. |
Let us run this simulation again by clicking on the Start button on the toolbar. A Warning Message will appear. Ignore the message and click on the OK button. |
On the ConditionalOperations.xcos window, Cursor on AFFICH_m block. |
Observe that as soon as the value in the AFFICH_m block becomes 1, the simulation stops. So this way we can use conditional operations in Xcos. |
Show Slide: Summary |
This brings us to the end of this tutorial. Let us summarise. In this tutorial, we have learnt to:
|
Show Slide: Assignment |
As an assignment Create a Xcos Simulation file to:
|
Show Slide: About Spoken Tutorial project |
The video at the following link summarises the Spoken Tutorial project. Please download and watch it |
Show Slide: Spoken Tutorial Workshops |
The Spoken Tutorial Project team conducts workshops and gives certificates. For more details, please write to us. |
Show Slide: Answers for THIS Spoken Tutorial |
Please post your timed queries in this forum. |
Show Slide: FOSSEE Forum | Please post your general and technical queries on Scilab in this forum. |
Show Slide: Textbook Companion project. |
The FOSSEE team coordinates the Textbook Companion project. We give Certificates and Honorarium to the contributors. For more details, please visit this website. |
Show Slide: Lab Migration |
The FOSSEE team coordinates the Lab Migration project. For more details, please visit this website. |
Show Slide: Acknowledgement | Spoken Tutorial and FOSSEE projects are funded by the Ministry of Education, Government of India. |
Show Slide: Thank you |
This is Utkarsh, FOSSEE intern 2021, IIT Bombay signing off. Thanks for joining. |