Difference between revisions of "Scilab/C4/Conditional-operations-in-Xcos/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''Title of script''': Conditional operations in Xcos '''Author: Rupak Rokade and Utkarsh''' '''Keywords: Xcos, conditional operation, scilab, if-else, loops''' {|border...")
 
Line 1: Line 1:
'''Title of script''': Conditional operations in Xcos
+
'''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'''
| '''Visual Cue'''
+
| '''Narration'''
+
 
|-
 
|-
 
|
 
|
Line 23: Line 21:
 
|
 
|
 
In this tutorial, we will learn how to:
 
In this tutorial, we will learn how to:
 +
 +
<ul>
 +
<li><blockquote><p>Use the '''If then Else''' conditional operator in '''Xcos'''.</p></blockquote></li>
 +
<li><blockquote><p>Display the output of the conditional operations.</p></blockquote></li>
 +
<li><blockquote><p>Halt the simulation after a condition is reached.</p></blockquote></li></ul>
 
|-
 
|-
 
|
 
|
Line 28: Line 31:
  
 
'''System Requirements'''
 
'''System Requirements'''
| To record this tutorial, I am using
+
|
 +
To record this tutorial, I am using
 +
 
 +
<ul>
 +
<li><blockquote><p>'''Ubuntu 18.04 OS''' and</p></blockquote></li>
 +
<li><blockquote><p>'''Scilab 6.1.0'''</p></blockquote></li></ul>
 
|-
 
|-
 
|
 
|
Line 37: Line 45:
 
To follow this tutorial, you should have :
 
To follow this tutorial, you should have :
  
 
+
<ul>
 +
<li><blockquote><p>Basic knowledge of '''Scilab and Xcos.'''</p></blockquote></li></ul>
  
 
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'''
 
|
 
|
 +
<ul>
 +
<li><blockquote><p>The files used in this tutorial are provided in the '''Code files''' link.</p></blockquote></li>
 +
<li><blockquote><p>Please download and extract the files.</p></blockquote></li>
 +
<li><blockquote><p>Make a copy and then use them while practising.</p></blockquote></li></ul>
 
|-
 
|-
 
| 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 68:
 
|
 
|
 
On the '''Untitled Xcos''' window,
 
On the '''Untitled Xcos''' window,
 
 
  
 
Cursor on '''Toolbar''' &gt;&gt; Click on '''Open file''' option &gt;&gt; Click on '''ConditionalOperations.xcos''' &gt;&gt; Click on '''OK.'''
 
Cursor on '''Toolbar''' &gt;&gt; Click on '''Open file''' option &gt;&gt; Click on '''ConditionalOperations.xcos''' &gt;&gt; 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''' simulation diagram.
+
 
|-
 
|-
 
| 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''' block.
Line 98: Line 94:
 
|
 
|
 
On '''palette browser''',
 
On '''palette browser''',
 
 
  
 
click on '''user-defined-functions''' &gt;&gt; click on '''Expression.'''
 
click on '''user-defined-functions''' &gt;&gt; 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.
Line 114: Line 108:
 
|
 
|
 
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''' Window,
 
On '''Scilab Multiple Request''' Window,
 
 
  
 
Double click on '''Number of Input''' textbox to highlight it &gt;&gt; Change it to '''1'''.
 
Double click on '''Number of Input''' textbox to highlight it &gt;&gt; Change it to '''1'''.
 
|
 
|
First is the '''number of inputs'''.  
+
First is the '''number of inputs'''.
 
+
 
+
 
+
By default it is '''2''' which means it can receive 2 input values.
+
 
+
  
 +
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 126:
 
On '''Scilab Multiple Request''' Window,
 
On '''Scilab Multiple Request''' Window,
  
 
+
Double click on '''scilab expression''' textbox to highlight it &gt;&gt; type '''(u1&gt;10)*1''' '''.'''
 
+
 
+
 
+
 
+
 
+
 
+
 
+
 
+
 
+
Double click on '''scilab expression '''textbox to highlight it &gt;&gt; type '''(u1&gt;10)*1 .'''
+
 
|
 
|
Next, is the '''conditional expression'''.  
+
Next, is the '''conditional expression'''.
 
+
 
+
  
 
This is the expression which will be evaluated by the '''Expression''' block.
 
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.
 
+
In '''Xcos, '''by default variables like '''u1, u2''' are used while writing the conditional expressions.
+
 
+
 
+
  
 
Let us change the default expression.
 
Let us change the default expression.
 
 
  
 
Enter the expression as shown here.
 
Enter the expression as shown here.
Line 173: Line 141:
 
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 &gt; 10''''' then the block should return '''1'''.
Double click on the scilab''' expression '''textbox to highlight it.
+
|
+
This means that, if '''''u1 &gt; 10''''' then the block should return''' 1'''.
+
 
|-
 
|-
 
|
 
|
 
On '''Scilab Multiple Request''' Window,
 
On '''Scilab Multiple Request''' Window,
 
 
  
 
Click on the '''OK''' button.
 
Click on the '''OK''' button.
Line 190: Line 153:
 
|
 
|
 
Let us display the output of the '''Expression''' block.
 
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''' block.
Line 197: Line 158:
 
|
 
|
 
On '''palette browser''',
 
On '''palette browser''',
 
 
  
 
click on '''sinks''' &gt;&gt; click on '''AFFICH_m.'''
 
click on '''sinks''' &gt;&gt; click on '''AFFICH_m.'''
 
|
 
|
Go to the''' palette browser''' window.
+
Go to the '''palette browser''' window.
 
+
 
+
 
+
Click on the '''Sinks''' section.
+
 
+
  
 +
Click on the '''Sinks''' palette.
  
 
In the right panel, select the '''AFFICH_m''' block.
 
In the right panel, select the '''AFFICH_m''' block.
Line 221: Line 176:
 
|
 
|
 
Let us make the connections.
 
Let us make the connections.
 
 
  
 
Select the '''black input port''' of the '''EXPRESSION''' block.
 
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''' block.
+
 
|-
 
|-
 
|
 
|
Line 236: Line 187:
 
|
 
|
 
Next, Select the '''black output port''' of the '''EXPRESSION''' block.
 
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''' block.
Line 246: Line 195:
 
Connect as per narration'''.'''
 
Connect as per narration'''.'''
 
|
 
|
Lastly, Select the '''red input port''' of the '''AFFICH_m '''block.
+
Lastly, Select the '''red input port''' of the '''AFFICH_m''' block.
 
+
 
+
 
+
Connect it to the line joining the''' CLOCK_c''' and the '''CSCOPE''' block.
+
 
+
  
 +
Connect it to the line joining the '''CLOCK_c''' and the '''CSCOPE''' block.
  
 
Our file is ready for simulation.
 
Our file is ready for simulation.
 
|-
 
|-
 
|
 
|
On the''' menu bar,'''
+
On the '''menu bar,'''
  
 
Click on '''Simulation''' &gt;&gt; Click on '''Setup.'''
 
Click on '''Simulation''' &gt;&gt; Click on '''Setup.'''
 
|
 
|
 
Before that, we need to change the execution time to Real time.
 
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 &gt;&gt; Click on '''OK''' button.
 
Change '''Real Time Scaling''' to 1 &gt;&gt; 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 223:
 
|
 
|
 
On the '''ConditionalOperations.xcos''' window,
 
On the '''ConditionalOperations.xcos''' window,
 
 
  
 
Click on '''Start''' button on the toolbar &gt;&gt; click on '''OK''' button on the Warning Message.
 
Click on '''Start''' button on the toolbar &gt;&gt; click on '''OK''' button on the Warning Message.
Line 291: Line 228:
 
Let us run this simulation by clicking on the '''Start''' Button on the '''toolbar'''.
 
Let us run this simulation by clicking on the '''Start''' Button on the '''toolbar'''.
  
 
+
A '''Warning Message''' will appear.
 
+
An '''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 '''block displays '''0''' as long as the graph is less than '''10''' .
+
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'''.
 
After the graph exceeds '''10''' the '''AFFICH_m''' block displays '''1'''.
Line 315: Line 244:
 
|
 
|
 
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''' block. This is the '''IF-ELSE''' block.
 
|-
 
|-
 
| Close the '''Graphic Window.'''
 
| Close the '''Graphic Window.'''
| Let us close the '''Graphic window.'''
+
| Let’s close the '''Graphic window.'''
 
|-
 
|-
 
|
 
|
 
On '''palette browser''',
 
On '''palette browser''',
 
 
  
 
click on '''Event-Handling''' &gt;&gt; click on '''IFTHEL_f.'''
 
click on '''Event-Handling''' &gt;&gt; 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''' block.
 
|-
 
|-
| Drag the '''IFTHEL_f ''' block and drop it on the '''ConditionalOperations.xcos window.'''
+
| 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.
 
| '''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.
+
Cursor on '''IFTHEL_m''' block.
 
| Now, to halt the simulation we would need the '''HALT_f''' block.
 
| Now, to halt the simulation we would need the '''HALT_f''' block.
 
|-
 
|-
 
|
 
|
 
On '''palette browser''',
 
On '''palette browser''',
 
 
  
 
click on '''Event-Handling''' &gt;&gt; click on '''HALT_f.'''
 
click on '''Event-Handling''' &gt;&gt; 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''' block.
 
|-
 
|-
| 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''' block on the '''ConditionalOperations.xcos''' window.
 
| '''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 '''block will end the simulation when the condition in the '''IFTHEL_f''' block is satisfied.
+
 
|-
 
|-
 
|
 
|
Line 385: Line 296:
 
|
 
|
 
Let us make the connections.
 
Let us make the connections.
 
 
  
 
Select the '''black input port''' of the '''IFTHEL_f''' block.
 
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''' block.
+
 
|-
 
|-
 
|
 
|
Line 400: Line 307:
 
|
 
|
 
Next, Select any of the '''red output ports''' of the '''IFTHEL_f''' block.
 
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''' block.
Line 412: Line 317:
 
Lastly, Select the '''red input port''' of the '''IFTHEL_f''' block.
 
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'''.'''
 
+
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 &gt;&gt; click on '''OK''' button on the Warning Message.
 
Click on '''Start''' button on the toolbar &gt;&gt; click on '''OK''' button on the Warning Message.
Line 425: Line 326:
 
Let us run this simulation again by clicking on the '''Start''' Button on the '''toolbar'''.
 
Let us run this simulation again by clicking on the '''Start''' Button on the '''toolbar'''.
  
 
+
A '''Warning Message''' will appear.
 
+
An '''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''' block becomes '''1''', the simulation stops.
 
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 346:
 
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:
  
 
+
<ul>
In this tutorial, we have learnt to:
+
<li><blockquote><p>Use the '''If then Else''' conditional operator in '''Xcos'''.</p></blockquote></li>
 +
<li><blockquote><p>Display the output of the conditional operations.</p></blockquote></li>
 +
<li><blockquote><p>Halt the simulation after a condition is reached.</p></blockquote></li></ul>
 
|-
 
|-
 
|
 
|
Line 464: Line 360:
 
As an assignment
 
As an assignment
  
 +
Create a '''Xcos''' Simulation file to:
  
 
+
<ul>
Create a '''Xcos''' Simulation file to:
+
<li><blockquote><p>Plot a straight line with slope 5.</p></blockquote></li>
 +
<li><blockquote><p>Apply a conditional operator which will output 1 if the value is divisible by 9.</p></blockquote></li>
 +
<li><blockquote><p>Halt the simulation when the condition evaluates to True.</p></blockquote></li></ul>
 
|-
 
|-
 
| 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 376:
 
|
 
|
 
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 383:
  
 
'''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 394:
 
|
 
|
 
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 site.
+
 
|-
 
|-
|
+
| 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 site.
+
 
|-
 
|-
|
+
| 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 411:
 
|
 
|
 
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.
 
|}
 
|}
 
''' '''
 

Revision as of 21:25, 4 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:

  • Use the If then Else conditional operator in Xcos.

  • Display the output of the conditional operations.

  • Halt the simulation after a condition is reached.

Show Slide:

System Requirements

To record this tutorial, I am using

  • Ubuntu 18.04 OS and

  • Scilab 6.1.0

Show Slide:

Pre-requisites

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.

Show Slide:

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.

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:

  • Use the If then Else conditional operator in Xcos.

  • Display the output of the conditional operations.

  • Halt the simulation after a condition is reached.

Show Slide:

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

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.

Contributors and Content Editors

Nancyvarkey, Utkarsha