lab 1 matlab, dspace and simulink. lab objectives familiarize yourself with the hardware used in...

19
LAB 1 MATLAB, dSPACE and Simulink

Upload: lizbeth-mckenzie

Post on 28-Dec-2015

251 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

LAB 1 MATLAB, dSPACE and Simulink

Page 2: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Lab Objectives

• Familiarize yourself with the hardware used in this course;

• Learn how to do data acquisition using dSPACE;• Learn basic MATLAB programing;

To achieve these objectives, you need to 1.Measure the angular position of the shaft by using the pot;2.Acquire the data using dSPACE data acquisition system;3.Plot your data using MATLAB;

Page 3: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Hardware

Quanser Box of motor, gears, and potentiometer (pot)

Schematic for the Quanser Box

Make sure you know• Where the pot is in the Quanser box;• How a pot works (Measure the pot output voltage using a multimeter as you rotate the pot).

Page 4: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Hardware Wiring for data acquisition (measuring)

NOTE:1. Yellow signal line connects the data to the

dSPACE channel 5;2. Connect dSPACE box to the "ground" on the

Power module;3. +/- 12 volt to the potentiometer

Page 5: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Overview of the Software

We will:• Build a user interface in the dSPACE environment to observe

the response, and save the measured data;• Use Matlab-Simulink to build the program to drive the

dSPACE data acquisition card (that is, to tell dSPACE how we want to do the measurement);

• Transfer the data into Matlab, and use Matlab to plot the data;

Page 6: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

What do you need to learn about the Software?

1. How to make dSPACE and MATLAB work together;2. How to build the program (model) in Simulink to do the data

acquisition;3. How to measure and save data using dSPACE environment;4. How to write MATLAB code to do data processing;

Next, we will guide you through a step-by-step procedure!

Page 7: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 1: Open MATLAB and dSPACE

1. Click on “ ” to open Matlab;2. Choose RT1104 when this box comes up;

3. Click on “ ” to open dSPACE (IMPORTANT: Open Matlab

before you open dSPACE!!)

Page 8: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 2: Choose your working directory

1. Make a folder on a local drive (in C:\ or D:\ ) to save your data;2. Make sure both Matlab and dSPACE use that folder as the working

directory;3. Matlab first: Set the default directory to the folder you just made!

Page 9: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 2-2: Set the directory for dSPACE1. In dSPACE enviornment, click “File> New Experiment”;2. Choose whatever name you want for “Experiment name”.3. Direct the "Working root" to the folder you just make—same one you just

set for MATLAB;

Page 10: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 3: Create Simulink Model1. Type “Simulink” in theMATLAB

command window and the Simulink menu will appear;

2. To start a new model, choose: File>New>model;

3. Go down to the bottom of the Simulink Library Browser and choose: dSPACE RT1104>DS1104 Master PPC, then select DS1104ADC_C5

4. Drag this block into your Simlink model window. This is the analog-to-digital connection to dSPACE.

5. From the Simulink Library Browser, select: Sinks > Scope

6. From the "Commonly Used Blocks" or "Math Operations", choose: Gain.

Then drag this to your model.

Page 11: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 3: Create Simulink Model7. Once you use the cursor to connect

the blocks, you should have a model that looks something like the right;

8. Adjust the "Gain" to 10 by double clicking on it (NOTE: We need the "Gain" block because the dSpace ADC converts the measured voltage to a range of +/- 1. Since we have dSPACE set to read +/- 10 volts, we correct the returned measurement by a factor of 10.

9. Save the model, then build the model by choose: Tools > Real-Time Workshop>Build Model (or use cntl +B!).

10. Wait MATLAB to do the “building”, until you see the message:

### Successful completion of Real-Time Workshop build procedure for model: lab1 *** Finished RTI build procedure for model lab1

Page 12: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 4: Link the Simulink Model with dSPACE

1. Go to the dSPACE window (Control Desk Developer window). After the "build" in MATLAB, a new tab appears at the bottom with the name of your model on it ;

2. Choose this tab, and we'll start a new experiment "Layout“: File > New > Layout. (Your workspace should look the one on the bottom right);

New tab

Page 13: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 4: Build the dSPACE layout

3. Select: Data Acquisition > Capture Settings;

4. Drag in "layout" to desired size;

5. Now we connect the MATLAB variables to the graphical output. Choose: Model Root>Scope> In1

6. Drag "In1" onto Plotter Array area, and that will connect the measured value to the display output;

Page 14: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 4: Build the dSPACE layout

7. Select : Data Acquisition > Capture Settings. Drag in "layout" to desired size.

8. Choose "PPC Lab 1 Host services" and adjust the length of measurement to any desired time, 5 seconds will be good here.

Page 15: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 5: Start the measurement1. Start the data

collection by clicking the icon shown.

2. Try using some of the other Virtual Instruments. Choose: Virtual Instruments > Display

3. Drag and size on layout…

4. Model Root > Gain drag "Out1" to "display”;

5. First, read the voltage off of the digital readout, “Gain/Out1”. (Verify at least one reading using an external voltmeter. )

Page 16: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 5:Next, you need to move the potentiometer and plot both the

position and velocity as a function of time.

Page 17: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Step 6: Process data in MATLAB1. Make sure you have the file saved to your folder. DO NOT USE A NUMBER

TO START YOUR “filename”! “TenDeg” is OK, but not “10deg”.2. Load it into the MATLAB workspace by typing the following line in MATLAB

command window:load filename

3. Convert the data into arrays by typing the following commands (As the file is saved as a structure):time=filename.X.Data;volts=filename.Y(1).Data;

4. Convert the “volts” to degrees, using the information you collected in the first part of the lab;

5. To obtain rate (i.e., angular velocity), you need to write a MATLAB m-file that implements the finite difference equation for the velocity:

6. Here is some sample code:

for k=2:length(volt);dv(k)=(volt(k)-volt(k-1))/(time(k)-time(k-1));

end

Page 18: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Useful Matlab Commands

• “plot”, “label”, “legend”, “subplot”—for plotting data;

• “save”, “load”—for save and load data;(Read the help file from Matlab to learn how to use

them, ask your TA if you have question).

Page 19: LAB 1 MATLAB, dSPACE and Simulink. Lab Objectives Familiarize yourself with the hardware used in this course; Learn how to do data acquisition using dSPACE;

Lab Report 1. Show a graph of volts vs degree and determine the gain between the

measured voltage and the angle. What units is this gain in?2. Show the continuous motion in a graph with position vs time, 3. Show the velocity vs time in a graph. Be sure to choose some point in time

on the position graph, find the slope at that point and compare it with the corresponding velocity on the velocity graph. This is to validate your measurements.

4. Discuss: Do the speeds that you see on your graph correlate with the speed that you moved the gears? If you find that your measurements read 0.0001 deg/sec or 100,000 deg/sec, your measurements are probably wrong.

5. Use the guidelines in "Report Writing for Fun and Profit", found on the class website, to write up this report.