www.pudn.com > truetime-1.2-compiled.zip > README


----------------------------------------------
 TrueTime version 1.2
 Example: PID-control of a DC servo
 Directory: $DIR/examples/simple_pid
----------------------------------------------

1. INTRODUCTION

This example is intended to give a basic introduction to the
TrueTime simulation environment. The example considers simple PID
control of a DC-servo process. The process is controlled by a
controller task implemented in a TrueTime kernel block. Four different 
implementations of the controller task are provided.


2. COMPILING THE SIMULATION FILES

2.1 Configuring the TrueTime Environment

    Before starting Matlab, you must set the environment variable
    TTKERNEL to point to the directory with the TrueTime kernel files:

        Unix/Linux: > export TTKERNEL=$DIR/kernel
        Windows:  Control Panel / System / Advanced / Environment Variables

    Then add the following lines to your MATLAB startup script. This
    will set up all necessary paths to the TrueTime kernel files.

        addpath(getenv('TTKERNEL'))
        init_truetime;

2.2 Compilation

    As described in the reference manual it is possible to write a
    TrueTime simulation (i.e. the code functions for the tasks and the
    initialization commands) either as m-files or as C++ functions.
    Both approaches are provided for this example and the compilations
    needed for the respective alternatives are described below.

    2.2.1 Matlab version
   
	TrueTime in the MATLAB version is compiled once and for all 
	by running the command make_truetime from the command prompt.
	This should be done the first time you are using TrueTime and
	no further compilation is then required.

    2.2.2 C++ version
    
        Compilation of the init script of the computer block is
        performed by the command:

        >> ttmex servo_init.cpp
    
	NOTE: If changes are made to the code function or the
        initialization commands (for example when changing implementations
        as described below), the init-file needs to be re-compiled.


3. SIMULATIONS

Open the model servo.mdl to run the simulation. 

- Run a simulation and verify that the controller behaves as
  expected. Notice the computational delay in the control signal.
  Compare with the code function. Study the schedule plot.

- Try changing the execution time of the first segment of the code
  function, to simulate the effect of different input-output delays.

- Also try changing the sampling period and study the resulting
  control performance.

- A PID controller is implemented in the Simulink block
  controller.mdl. Change the initialization file (servo_init) so that
  it uses implementation 1b instead. Study the corresponding code 
  function, blockcode. This code function is using use the Simulink block 
  to compute the control signal in each sample.

- Implementation 2 implements a periodic task by using the TrueTime
  primitive ttSleepUntil. Study the code function, pidcode2, and run a 
  simulation.

- Implementation 3 samples using a periodic timer which triggers task jobs.
  Study the code function, pidcode3, and run the simulation again. Study the
  schedule to see the inclusion of the periodic interrupt handler.