Scilab/C4/Conditional-operations-in-Xcos/English

From Script | Spoken-Tutorial
Revision as of 17:37, 21 September 2021 by Nancyvarkey (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 version 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