Hey, miles

莫等闲,白了少年头q

0%

Matlab与mmWave联合使用文档

matlab联合mmWave Studio采集毫米波雷达原始数据相关官方文档

  1. From mmWaveStudio’s Lua Shell, call the RSTD.NetStart() command This command starts a listening server on port 2777 by default.
    (you can also add this command to “C:\ti\mmwave_studio_01_00_00_01\ mmWaveStudio\Scripts\Startup.lua” so that it is called automatically)

  2. There are two Matlab scripts shown below. Copy them and create scripts with names RSTD_Interface_Example.m and Init_RSTD_Connection.m. You can modify the path to the RtttNetClientAPI.dll in RSTD_Interface_Example.m, and then call the RSTD_Interface_Example from Matlab. This script demonstrates how to connect to mmWaveStudio from Matlab and allow Lua commands to be sent to mmWaveStudio. The script internally calls Init_RSTD_Connection.m to establish the connection to port 2777, and then displays a green message in the mmWaveStudio Output window.

    See lines 41-47 in Init_RSTD_Connection.m for an example of sending a single Lua Command. Basically, you construct the Lua command as a string in Matlab and pass it to the RtttNetClientAPI.RtttNetClient.SendCommand API. Also see commented lines 12-15 in RSTD_Interface_Example.m for an example on how to get mmWaveStudio to run an external Lua Script.

RSTD_Interface_Example.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
%% RSTD_Interface_Example.m
addpath(genpath('.\'))

% Initialize mmWaveStudio .NET connection
RSTD_DLL_Path = 'C:\ti\mmwave_studio_01_00_00_01\mmWaveStudio\Clients\RtttNetClientController\RtttNetClientAPI.dll';
ErrStatus = Init_RSTD_Connection(RSTD_DLL_Path);
if (ErrStatus ~= 30000)
disp('Error inside Init_RSTD_Connection');
return;
end

%Example Lua Command
%strFilename ='C:\\ti\\mmwave_studio_01_00_00_01\\mmWaveStudio\\Scripts\\Example_script_AllDevices.lua';
%Lua_String = sprintf('dofile("%s")',strFilename);
%ErrStatus =RtttNetClientAPI.RtttNetClient.SendCommand(Lua_String);

Init_RSTD_Connection.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%% Init_RSTD_Connection.m
function ErrStatus = Init_RSTD_Connection(RSTD_DLL_Path)
%This script establishes the connection with mmWaveStudio software
% Pre-requisites:
% Type RSTD.NetStart() in mmWaveStudio Luashell before running the script. This would open port 2777
% Returns 30000 if no error.
if (strcmp(which('RtttNetClientAPI.RtttNetClient.IsConnected'),'')) %First time the code is run after opening MATLAB
disp('Adding RSTD Assembly');
RSTD_Assembly = NET.addAssembly(RSTD_DLL_Path);
if ~strcmp(RSTD_Assembly.Classes{1},'RtttNetClientAPI.RtttClient')
disp('RSTD Assembly not loaded correctly. Check DLL path');
ErrStatus = -10;
return
end
Init_RSTD_Connection = 1;
elseif ~RtttNetClientAPI.RtttNetClient.IsConnected() %Not the first time but port is disconnected
% Reason:
% Init will reset the value of Isconnected. Hence Isconnected should be checked before Init
% However, Isconnected returns null for the 1st time after opening MATLAB (since init was never called before)
Init_RSTD_Connection = 1;
else
Init_RSTD_Connection = 0;
end
if Init_RSTD_Connection
disp('Initializing RSTD client');
ErrStatus = RtttNetClientAPI.RtttNetClient.Init();
if (ErrStatus ~= 0)
disp('Unable to initialize NetClient DLL');
return;
end
disp('Connecting to RSTD client');
ErrStatus = RtttNetClientAPI.RtttNetClient.Connect('127.0.0.1',2777);
if (ErrStatus ~= 0)
disp('Unable to connect to mmWaveStudio');
disp('Reopen port in mmWaveStudio. Type RSTD.NetClose() followed by RSTD.NetStart()')
return;
end
pause(1);%Wait for 1sec. NOT a MUST have.
end
disp('Sending test message to RSTD');
Lua_String = 'WriteToLog("Running script from MATLAB\n", "green")';
ErrStatus = RtttNetClientAPI.RtttNetClient.SendCommand(Lua_String);
if (ErrStatus ~= 30000)
disp('mmWaveStudio Connection Failed');
end
disp('Test message success');
end