📄 readme
字号:
---------------------------------------------- TrueTime 1.5 Example: PID-control of a DC servo Directory: $DIR/examples/simple_pid----------------------------------------------1. INTRODUCTIONThis example is intended to give a basic introduction to theTrueTime simulation environment. The example considers simple PIDcontrol of a DC-servo process. The process is controlled by acontroller task implemented in a TrueTime kernel block. Four different implementations of the controller task are provided.2. COMPILING THE SIMULATION FILES2.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 Since the TrueTime archive contains pre-compiled files, no compilation is required to run TrueTime in the Matlab version. However, if needed, the files may be re-compiled by issuing the command make_truetime from the command prompt. 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. SIMULATIONSOpen 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 kernel init function argument from 1 to 2, so that implementation 2 is used instead of 1. Study the corresponding code function, blockcode. This code function is using use the Simulink block to compute the control signal in each sample.- Implementation 3 implements a periodic task by using the TrueTime primitive ttSleepUntil. Study the code function, pidcode2, and run a simulation.- Implementation 4 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -