User:DukeEgr93/DSPACE

From PrattWiki
Jump to navigation Jump to search

This is a personal sandbox for using the dSpace systems in Hudson 149. Several parts of it will move to the main site eventually.

General Startup

The following describes how to begin an experiment from scratch. More information will be provided later on how to reload an already-completed experiment.

  1. Start dSpace ControlDesk (CD)
  2. In CD, go to File->New Experiment
    • Give the experiment a name, decide where you want all the files to go for the Working root, add author information and a description; when completed, the Experiment tab will have the name of the experiment as well as a .cdd link.
  3. Click on the Platform tab, right click Simulink, and Open Matlab - the first time MATLAB is started on a computer it will take quite some time to start up. When ready, the Simulink logo in the Platform window will be in color
  4. Within the new MATLAB window, type simulink
  5. In Simulink, go to File->New->Model; when the model comes up, save it inside the folder you chose when creating the experiment
  6. In the model's window, go to Simulation->Configuration Parameters
    • Solver: make sure to use a fixed-step solver; change the Fixed-step size if need be
    • Hardware Implementation: choose the following:
    • Device type: "Custom"
    • Byte ordering: "Big Endian"
    • Signed integer division rounds to: "zero"
  7. Back in the ControlDesk, the left window should still be Platform (if not, pick the Platform tab). At the bottom of the CD window, pick File Selector and find the Simulink model you have saved. Drag its name to the Simulink platform - the icon will change from the Matlab logo to a small red box with a green arrow, blue rectangle, and pink clock.
  8. Create the model (this must be done before variables can be generated in the next step; more information below about different models)
  9. In ControlDesk, right click the Simulink platform and select Build Variable Description File. Save the model if need be; at the bottom of the ControlDesk, a new tab for the "sdf" file will appear
  10. In the Simulink model window, type CTRL-B or go to Tools->Real-Time Workshop->Build model - this will compile the model, send it to the dSpace card, and start the process. Note that any time you change the model, you will need to save the model, go back to the Simulink platform and Build Variable

Resuming an Experiment

To resume work on a saved experiment;

  1. Start ControlDesk
  2. Go to File->Open Experiment and find your experiment
  3. Go to the Platform tab, right-click on Simulink and Open Matlab
  4. Drag the model you want to use from the File Selector onto the Simulink platform
  5. Right click the Simulink platform and select Build Variable Description File. Save the model if need be
  6. Now if you want to compile and run the model, just type CTRL-B or go to Tools->Real-Time Workshop->Build model - this will compile the model, send it to the dSpace card, and start the process. Note that any time you change the model, you will need to save the model, go back to the Simulink platform and Build Variable

Generate a Signal

Go through the steps in General Startup, stopping at "Create the model..." Then:

  1. Generate the signal - this is easily done by importing a Sources->Clocck and a User-Defined Functions->Fcn block. Connect the clock to the Fcn block, then put the function you want in the Fcn block.
  2. Tell dSpace to take data - go to the dSpace RTI1104 blockset in the Simulink library, expand it and click the DS1104 MASTER PPC set within it. Drag a DS1104DAC_C1 block into your model
  3. In the model, double-click the DS1104DAC_C1 block to set properties:
    • Unit: pick the channel (for this document, we will use DACH1)
    • Initialization: should already be set to 0 V
    • Termination: make sure the block will set the output to 0 volts on termination
    • Connect the Fcn block to the DAC block
  4. Save the model
  5. In ControlDesk, right click the Simulink platform and select Build Variable File. Save the model if need be; at the bottom of the ControlDesk, a new tab for the "sdf" file will appear
  6. In the model window in Simulink, type CTRL-B or go to Tools->Real-Time Workshop->Build model - this will compile the model, send it to the dSpace card, and start the process. Note: the process will continue until you stop the dSpace card in ControlDesk by selecting the ds1104 platform and then hitting the stop button in the menu bar.
    • Another way of stopping the process is to put a stop in the Simulink diagram that is triggered by a particular condition. The easiest way to do this is to add another User-Defined Functions->Fcn block and a Sinks->Stop block. Connect the clock to this new function block, but in a logical operator that is true when you want the simulation to stop (for example, u[1]>3 for a 3 second simulation), then connect this to the Stop block.

Accessing Experiment Values

If you want dSpace to save variables and dump them into MATLAB for analysis, you will use the Sinks->To Workspace blocks. Just drag a block onto your model, double-click it, set the name of the variable you want, and change the Save format to Array (unless you want it to be a Structure). Connect it to the line you want to measure. Then:

  1. Save the model
  2. In ControlDesk, right click the Simulink platform and select Build Variable File. Save the model if need be; at the bottom of the ControlDesk, a new tab for the "sdf" file will appear
  3. In the model window in Simulink, type CTRL-B or go to Tools->Real-Time Workshop->Build model