Post

Control Unit Implementation

In this project, the control algorithms are executed in Simulink, with the data acquisition device interfacing with MATLAB through a serial COM port. Real-time communication is facilitated by the Real-Time Desktop package for MATLAB. To test new control algorithms, simply replace the controller block in the provided template.

The complete project repository is available on GitHub: Roman3D Project Repo

template

Real-Time Desktop Kernel Setup

Install the Real-Time Desktop Kernel on the host computer by executing the following command in the MATLAB command window:

1
 sldrtkernel -install

To verify the installation, use the command:

1
rtwho

Example output:

rtwho command output

After creating a Simulink project, configure it for the real-time kernel by following these steps:

  1. Go to Model settings.
  2. Navigate to Code Generation.
  3. Set the System target file to sldrt.tlc.

code generation

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:

run button

Encoder Input Configuration

To communicate with the device, add a Packet Input block from the Simulink Desktop Real-Time Library:

packet input

Install a new serial port board as shown:

input config

input config 2

Select the serial port according to the device manager:

Device manager

Configure the device to send encoder input in 16-bit integer format at Block output data types:

input config 3

Now, convert the encoder input to radians. First, convert int16 to double using a convert block:

input block

DAC Output Configurations

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:

output block

This post is licensed under CC BY 4.0 by the author.