15
הנושא: Matlab-Scilab Comparison מגישים: אלי ציבן גיא דור לדרפיין מנחה: אריה נחמני סמסטר: אביב תשע"א שנה: 1122 הטכניון- מכון טכנולוגי לישראלTECHNION - ISRAEL INSTITUTE OF TECHNOLOGY הפקולטה להנדסת חשמל המעבדה לבקרה ורובוטיקה

DAQ in Scilab and Matlab

Embed Size (px)

DESCRIPTION

DAQ sing scilab and matlab

Citation preview

Page 1: DAQ in Scilab and Matlab

:הנושא

Matlab-Scilab

Comparison

:מגישים

גיא דור לדרפיין אלי ציבן :מנחה

אריה נחמני

אביב תשע"א סמסטר:

1122 :שנה

מכון טכנולוגי לישראל -הטכניון TECHNION - ISRAEL INSTITUTE OF TECHNOLOGY

הפקולטה להנדסת חשמל

המעבדה לבקרה ורובוטיקה

Page 2: DAQ in Scilab and Matlab

Contents

Matlab – Scilab Comparison

Introduction

Simulating Simple Linear Systems

Simulating Dynamic Systems Using Xcos

Differences in Workflow using Xcos compared to Simulink

Components Library

Connecting the Components

The Resulting Diagrams

Execution Time

DAQ using Scilab

Video Tracking using Scilab

Converting Matlab Code to Scilab

ATOMS

Page 3: DAQ in Scilab and Matlab

Introduction In this project, our goal is to determine whether the Control Lab of the Electrical

Engineering Faculty of the Technion (and thereafter all labs of Electrical Engineering)

can gradually switch all lab experiments and projects to use Scilab instead of Matlab.

The reason that the faculty is considering this transformation is that it can save the

faculty great amount of money. At the current situation, the price of maintaining

Matlab and its additional needed toolboxes is becoming a great financial burden on

the faculty.

In order to test if this switch is possible within the near future, we decided to test

Scilab's performance in the following aspects:

1. Solve simple linear systems and calculate LQR gain

2. Simulate dynamic models built from block diagrams using Scilab's Xcos

(similar to Matlab's Simulink)

3. Interface with a DAQ card used in the Control Lab (used for various

experiments in the lab)

4. Replicate a video tracing algorithm using Scilab

In each of these aspects, we measured whether the results Scilab returned were

identical to those returned by Matlab; compared the execution times; and reviewed

how difficult the interaction with the program was.

Page 4: DAQ in Scilab and Matlab

Simulating Simple Linear Systems For simple examples of linear systems, we chose to implement the project given in the

course "Control Systems 2".

First of all, we wanted to examine how Scilab deals with small projects (homework

assignments etc.).

The example we chose is a State Space System controlled by a LQR feedback

controller. In addition, we wanted to examine how Scilab deals with noise added to

the model. For example, here is the model we built in Xcos (with noise):

Scilab produced the same feedback controller and gave the same output as Matlab.

The execution time was also very similar to Matlab (with a small advantage to

Matlab).

It is very easy to convert a small project from Simulink to Xcos, because the UI and

parameter configuration are almost identical, as you can see in the following

screenshots:

Page 5: DAQ in Scilab and Matlab

MATLAB:

Scilab:

Page 6: DAQ in Scilab and Matlab

In conclusion, it is very easy to learn how to use Xcos for someone who has prior

knowledge in working with Simulink. We found that the learning curve of Xcos

should be the same as that of Simulink. In terms of number of components, we had all

we needed for producing this project. Therefore, the case should be similar for other

small projects and homework assignments in control systems.

Page 7: DAQ in Scilab and Matlab

Simulating Dynamic Systems Using Xcos In order to test whether Xcos can serve as an alternative to Matlab's Simulink, we

decided to take a project which makes extensive use of Simulink and to replicate it in

Scilab. Unfortunately, there is no program that we found which can convert Simulink

files to files which Xcos can process. Therefore, the conversion had to be done

manually.

The project which we decided to test is called "Auto-Park", done by Limor Greenberg

and Yaniv Romano. Their Matlab code performs some initialization of variables and

then calls a Simulink simulation. The Matlab code was converted using an automatic

script included with Scilab. The Simulink diagram was built from scratch in Xcos.

Differences in Workflow using Xcos compared to Simulink

Components Library

Xcos has a smaller variety of components to choose from when creating a diagram.

However, for the project we chose, Xcos contained all the components we needed in

order to replicate the Simulink diagram. Adding new components to the diagram and

editing the properties of the components was simple and intuitive.

Other than the smaller variety of components, there was also a small difference in that

in Xcos, all components which are synchronous (To Workflow, Scope…) have a

synchronization port, which needs to be connected to a clock component. In Simulink,

each of these components has an option of sample time, which may be inherited or

supplied manually.

In addition, Xcos does not have (so far) a simulation solver which can run with a

variable step. It simply runs using a fixed step clock, according to the one given by

the clock component in the diagram.

Connecting the Components

The difficulty we had, dealing with Xcos, was connecting the different components.

Connecting the components of the diagram usually involved many clicks and it was

difficult to select the end points of the lines (at the ports of the components). There

was much flexibility as to the shape of the lines (adding points to the line was simple)

however the lines usually did not turn-out straight and elegant. Alternatively, in

Simulink, there is a simple keyboard shortcut (Ctrl + Click) which allows connecting

components quickly and simply.

Furthermore, Xcos didn't have the feature of creating incomplete lines, whereas in

Simulink this feature exists and allows editing the connections in an easier manner.

Page 8: DAQ in Scilab and Matlab

The Resulting Diagrams

Original Matlab Diagram:

Corresponding Scilab diagram:

Page 9: DAQ in Scilab and Matlab

Simulation results in Matlab:

0 10 20 30 40 50 60-15

-10

-5

0

5

10

15Prallel Parking

X [m]

Y [

m]

Simulation results in Scilab:

Page 10: DAQ in Scilab and Matlab

Execution Time

The results of the simulation were identical in both MATLAB and Scilab. However,

the execution time of the simulation under Scilab was 22.9 times longer than that of

MATLAB, as you can see in the table below:

MATLAB Scilab

Execution Time [sec] 79.477 1820.969

Page 11: DAQ in Scilab and Matlab

DAQ using Scilab Another aspect we wanted to examine is the use of the DAQ card used in the control

lab. Currently, the control lab performs many projects using the "NI PCI 6024E" card.

In order to communicate with the card, we tried searching for toolboxes for data

acquisition that use that card. We found some outdated toolboxes which use the driver

"NI DAQmx Base 2.x", but we didn't manage to compile the code of the toolbox,

since it is written for an old version of Scilab. Here is a link to the referred toolbox:

DATA ACQUISITION AND REAL-TIME - DAQ Toolbox

We also found a toolbox that deals with many drivers by communicating with a DAQ

program called "COMEDI". COMEDI supports many DAQ cards (including our

card), but it is written for a Linux environment. Therefore, the toolbox itself can only

run under Linux. We decided that due to the large learning curve of Linux, it is not

recommended to use this toolbox in the lab. In addition, this toolbox is also outdated,

and it would probably be difficult to use it in new version of Scilab. Here is a link to

the referred toolbox: SCICOS - COMEDI

After we found there are no suitable toolboxes for our purpose, we decided to create a

primitive interface between Scilab and the DAQ card, which includes simple reading

and writing functions. We built this interface in order to estimate how difficult it

would be to implement a fully-functional toolbox which interacts with the card.

In order to build this interface, we used the ability of Scilab to run external C

functions and use them to create appropriate Scilab functions. We decided to go in

this direction, since we found a C API for the driver "NI DAQmx" which our card

uses.

Our reading function, receives an integer which specifies how many samples to read

from the card. The output of the function is a Scilab vector containing the sampling

results.

Our writing function, receives a vector from Scilab, which is written to the card. The

result, in this case, is the activation of the device that is connected to the card.

We tested these functions on the "Flexible Robotic Arm" which has a motor and is

connected to the DAQ card. Using the reading function, we managed to receive a

signal specifying the angle of the robotic arm. Using the writing function, we

managed to move the robotic arm in different directions according to the vector we

sent the function.

According to our experience of implementing these simple functions, we assume that

implementing a fully-functional toolbox could be performed as part of a student

project in the Control Lab. It may also be possible to request from the company that

supports the card to build this toolbox for Scilab.

In addition, we found that Scilab can be easily extended through C/Fortran functions.

Page 12: DAQ in Scilab and Matlab

Video Tracking using Scilab We wanted to examine how Scilab deals with video tracking.

The first problem we encountered is trying to read video files from Scilab. For this

action, there is a toolbox called SIVP (Scilab Image and Video Processing toolbox).

This toolbox has a function for reading ".avi" files called "aviopen". This function

relies on OpenCV. When trying to run this function under Windows, we were unable

to read simple avi files. We also ran the same function in a Linux environment

(Ubuntu) and managed to read video files, but this doesn't help us since we want to

test Scilab only in a Windows environment.

Because of this obstacle, we decided to focus our attention on the image processing

capabilities of Scilab. There are three main toolboxes for dealing with image

processing in Scilab:

SIP – Scilab Image Processing Toolbox: This is a rather old toolbox, written

originally for Linux. It contains many useful functions (selecting ROI, dilation

and erosion etc.). It uses ImageMagick implementation of many of its

functions. A fork to Windows may be developed soon.

Image Processing Design Toolbox: This toolbox contains many useful image

processing functions (morphological filters, edge detection etc.). The toolbox

has a syntax which is different from that of similar Matlab functions.

Currently works only in a Windows environment.

SIVP: Contains many image and video editing functions. It is inspired by SIP,

but uses OpenCV instead of ImageMagick for its image processing

capabilities. Its video support is currently experimental and works only on

Linux. It also has a function that is not present in other image processing

toolboxes which is able to detect faces within an image.

Page 13: DAQ in Scilab and Matlab

Converting Matlab Code to Scilab Scilab contains a script for converting ".m" files to ".sci" files (built into Scilab). We

used this script extensively in the project, and we found some places where it can be

improved.

The script does not detect some functions which can be easily converted,

especially those which are added by toolboxes installed.

Many temporary variables are added in the conversion, which makes the

converted code, in some cases, unclear.

Conversion of functions does not work if there is an "end" at the end of the

Matlab function.

Converting complex conditions from Matlab is sometimes incorrect.

In conclusion, this conversion script is not useful for projects which contain functions

that are not so common and complicated logic. However, this script will not have to

be used if the projects will be written in Scilab beforehand.

Page 14: DAQ in Scilab and Matlab

ATOMS Since Scilab 5.2, adding external modules/toolboxes to Scilab has become simpler,

due to the addition of a new feature named ATOMS (AuTomatic mOdules

Management for Scilab). This new platform encourages developers to write their own

modules for ATOMS, which will then be added to the ATOMS portal website, and

will be available for download for all users. ATOMS support is built into Scilab, and

searching for new modules or updating existing modules can be done from within

Scilab very easily.

As we followed the progress of ATOMS, we learned that there is much progress in

this direction. Some old toolboxes are being rewritten to comply with ATOMS (and

therefore can be more easily installed on multiple platforms). Additionally, new

modules are constantly being added to the portal, and it is worth checking for new

modules in order to added capabilities and functions that may be useful for different

projects.

Page 15: DAQ in Scilab and Matlab

Conclusion We found that it is rather easy to learn how to use Scilab and Xcos. For now it cannot

replace Matlab in all areas. However, in some cases for small projects Scilab can be a

good alternative. Once the video processing toolboxes will be available on windows,

it will probably be possible to build video tracking projects in Scilab. In order for the

"NI PCI 6024E" card to work fully on Scilab, an interface needs to be built which

communicates with the driver. We found this task to be possible to perform within the

scope of a student project. Finally, the execution time we found of a complex Xcos

model was much higher than that of an equivalent Matlab model. In order for Scilab

to become a worthy alternative in this aspect, the execution times must be reduced.