Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB 1 MATLAB, dSPACE and Simulink

Similar presentations


Presentation on theme: "LAB 1 MATLAB, dSPACE and Simulink"— Presentation transcript:

1 LAB 1 MATLAB, dSPACE and Simulink

2 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 Measure the angular position of the shaft by using the pot; Acquire the data using dSPACE data acquisition system; Plot your data using MATLAB;

3 Hardware Make sure you know Where the pot is in the Quanser box;
Schematic for the Quanser Box Quanser Box of motor, gears, and potentiometer (pot) 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).

4 Hardware Wiring for data acquisition (measuring)
NOTE: Yellow signal line connects the data to the dSPACE channel 5; Connect dSPACE box to the "ground" on the Power module; +/- 12 volt to the potentiometer

5 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;

6 What do you need to learn about the Software?
How to make dSPACE and MATLAB work together; How to build the program (model) in Simulink to do the data acquisition; How to measure and save data using dSPACE environment; How to write MATLAB code to do data processing; Next, we will guide you through a step-by-step procedure!

7 Step 1: Open MATLAB and dSPACE
Click on “ ” to open Matlab; Choose RT1104 when this box comes up; Click on “ ” to open dSPACE (IMPORTANT: Open Matlab before you open dSPACE!!)

8 Step 2: Choose your working directory
Make a folder on a local drive (in C:\ or D:\ ) to save your data; Make sure both Matlab and dSPACE use that folder as the working directory; Matlab first:  Set the default directory to the folder you just made!

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

10 Step 3: Create Simulink Model
Type “Simulink” in theMATLAB command window and the Simulink menu will appear; To start a new model, choose: File>New>model; Go down to the bottom of the Simulink Library Browser and choose: dSPACE RT1104>DS1104 Master PPC, then select DS1104ADC_C5 Drag this block into your Simlink model window. This is the analog-to-digital connection to dSPACE. From the Simulink Library Browser, select: Sinks > Scope From the "Commonly Used Blocks" or "Math Operations", choose: Gain.   Then drag this to your model.

11 Step 3: Create Simulink Model
Once you use the cursor to connect the blocks, you should have a model that looks something like the right; 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. Save the model, then build the model by choose: Tools > Real-Time Workshop>Build Model (or use cntl +B!). 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

12 Step 4: Link the Simulink Model with dSPACE
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 ; 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

13 Step 4: Build the dSPACE layout
Select: Data Acquisition > Capture Settings; Drag in "layout" to desired size; Now we connect the MATLAB variables to the graphical output. Choose: Model Root>Scope> In1 Drag "In1" onto Plotter Array area, and that will connect the measured value to the display output;

14 Step 4: Build the dSPACE layout
Select : Data Acquisition > Capture Settings. Drag in "layout" to desired size. Choose "PPC Lab 1 Host services" and adjust the length of measurement to any desired time, 5 seconds will be good here.

15 Step 5: Start the measurement
Start the data collection by clicking the icon shown. Try using some of the other Virtual Instruments. Choose: Virtual Instruments > Display Drag and size on layout… Model Root > Gain drag "Out1" to "display”; First, read the voltage off of the digital readout, “Gain/Out1”. (Verify at least one reading using an external voltmeter. )

16 Next, you need to move the potentiometer and plot both the position and velocity as a function of time. Step 5:

17 Step 6: Process data in MATLAB
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”. Load it into the MATLAB workspace by typing the following line in MATLAB command window: load filename 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; Convert the “volts” to degrees, using the information you collected in the first part of the lab; To obtain rate (i.e., angular velocity), you need to write a MATLAB m-file that implements the finite difference equation for the velocity: Here is some sample code: for k=2:length(volt); dv(k)=(volt(k)-volt(k-1))/(time(k)-time(k-1)); end

18 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).

19 Lab Report Show a graph of volts vs degree and determine the gain between the measured voltage and the angle. What units is this gain in? Show the continuous motion in a graph with position vs time, 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. 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 deg/sec or 100,000 deg/sec, your measurements are probably wrong. Use the guidelines in "Report Writing for Fun and Profit", found on the class website, to write up this report.


Download ppt "LAB 1 MATLAB, dSPACE and Simulink"

Similar presentations


Ads by Google