In this experimental setup, the control algorithms run on Simulink. The data acquisition device communicates with MATLAB through a serial COM port. The Real-Time Desktop package for MATLAB enables real-time serial port communication. To test new control algorithms, simply replace the controller block in the provided template.
To use or understand how this template works, review the following sections:
- Real-Time Desktop Kernel Setup
- Simulink Configuration
- Encoder Input Configuration
- DAC Output Configuration
Install the Real-Time Desktop Kernel on the host computer by executing the following command in the MATLAB command window:
sldrtkernel -install
To verify the installation, use the command:
rtwho
Example output:
After creating a Simulink project, configure it for the real-time kernel by following these steps:
- Go to Model settings.
- Navigate to Code Generation.
- Set the System target file to
sldrt.tlc
.
After this configuration, a new tab named Desktop Real-Time will appear in Simulink. Start simulations from this tab using the Run In Real Time button:
To communicate with the device, add a Packet Input block from the Simulink Desktop Real-Time Library:
Install a new serial port board as shown:
Select the serial port according to the device manager:
Configure the device to send encoder input in 16-bit integer format at Block output data types:
Now, convert the encoder input to radians. First, convert int16 to double using a convert block:
To send DAC values to the device, use the Packet Output block from the Simulink Desktop Real-Time library. Calculate the real DAC value by converting +/- 10V to a 0-4096 range in MATLAB. Also, include a Rate Transition block before outputting DAC values: