Page tree
Skip to end of metadata
Go to start of metadata

If we want to adjust the execution time of Simulink so that it executes in sync with the wall clock, i.e., real-time simulation, we can use Real-Time Pacer for Simulink.

There are at least two ways of integrating the Pacer Block into and existing MATLAB/Simulink installation

1. Adding Real-Time Pacer From File Exchange

The Real-Time Pacer for Simulink allows the user to control the execution timing of a Simulink program.  For our purposes this will allow us to execute the program in near real-time (where the simulation executes on the same time basis as the real-world, aka wall-clock.)  The process of adding these blocks to your MATLAB/Simulation environment is a bit convoluted, but it is functionality we will need.

Setup path definition to be user configurable

We'll need to add the blocks to our local Simulink system, but because doing so affects the MATLAB path, we'll need to do some preliminaries:

  • Make sure that you user account is the owner of the MATLAB directory

    cd ~/Documents
    sudo chown -R USERNAME:USERNAME MATLAB    # Recursively changes ownership of the MATLAB directory
    cd MATLAB
    touch pathdef.m     # Creates an empty file

    Make sure to change USERNAME above to your username, e.g., sudo chown -R bbingham:bbingham MATLAB

  • Make MATLAB use the new pathdef.m file
    • Create a new file in the directory ~/Documents/MATLAB called startup.m
    • Open the file with a text editor, and put the following text in the file

      % save starting directory
      startdir = pwd ;
      % specify arbitrary directory containing pathdef.m
      pathdir = '~/Documents/MATLAB' ;
      % change directory so that target 'pathdef.m' has highest precedence
      % in the MATLAB search path
      cd(pathdir)
      % set the MATLAB search path using PATH
      path(pathdef)
      % change directory back to the starting directory
      cd(startdir)
    • Save the startup.m file
  • Restart MATLAB

Download Real-Time Pacer from File Exchange

  • Download the zip archive for the Real-Time Pacer for Simulink (if you don't want to sign in to the Mathworks, the archive is attached here: RealTime_Pacer.zip )
  • Create a new local directory ~/simulinkblocks
  • Unzip the RealTime_Pacer.zip archive into the  ~/simulinkblocks directory.
    • You should now have *.m and *.mdl files in the directory ~/simulnkblocks/RealTime_Pacer

Add the Real-Time Pacer location to the MATLAB path

  • In MATLAB, open the Set Path tool from the command window:
    • Choose Add Folder...
      • Navigate to  ~/simulnkblocks/RealTime_Pacer and click Open
      • Now you should see the path at the top of the search path...
    • Choose Save - this way the path will also be added next time you open MATLAB.
    • Click Close
  • Open Simulink
    • Open the Library Browser (slLibraryBrowser from the MATLAB command window)
      You should see warning message, "Some libraries are missing repository information" in red like this...

      • Click on the Fix link at the top which should open this dialog
        • Select "Resave libraries in SLX file format" and click OK1

Now in the library browser you should see the Real-Time Pacer blocks...

 

2. Adding Simulation Pace From Aerospace Blockset

An alternative is the Simulation Pace block included in the Aerospace Blockset.  Currently this is not installed on the ME4823 machines ,but it may be an alternative in the future.

  • No labels