Skip to content

Latest commit

 

History

History
72 lines (44 loc) · 2.49 KB

matlab_template.md

File metadata and controls

72 lines (44 loc) · 2.49 KB

Roman3D: Matlab/Simulink Template

Overview

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.

template

Contents

To use or understand how this template works, review the following sections:

  1. Real-Time Desktop Kernel Setup
  2. Simulink Configuration
  3. Encoder Input Configuration
  4. DAC Output Configuration

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:

sldrtkernel -install

To verify the installation, use the command:

rtwho

Example output:

rtwho command output

Simulink configuration

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