mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-13 21:57:35 +08:00
e9ccfdd484
Work around limitation in Symbolic toolbox environment space by incrementally saving and clearing workspace Remove vehicle vertical position from optical flow prediction equations (use range measurement instead) and regenerate auto-code Remove legacy optical flow auto-code conversion method as it is not required now a work around for symbolic toolbox limitations has been developed Fix out of date syntax
46 lines
1.4 KiB
Matlab
46 lines
1.4 KiB
Matlab
function ConvertToM(nStates)
|
|
%% Initialize variables
|
|
fileName = strcat('SymbolicOutput',int2str(nStates),'.txt');
|
|
delimiter = '';
|
|
|
|
%% Format string for each line of text:
|
|
% column1: text (%s)
|
|
% For more information, see the TEXTSCAN documentation.
|
|
formatSpec = '%s%[^\n\r]';
|
|
|
|
%% Open the text file.
|
|
fileID = fopen(fileName,'r');
|
|
|
|
%% Read columns of data according to format string.
|
|
% This call is based on the structure of the file used to generate this
|
|
% code. If an error occurs for a different file, try regenerating the code
|
|
% from the Import Tool.
|
|
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false);
|
|
|
|
%% Close the text file.
|
|
fclose(fileID);
|
|
|
|
%% Create output variable
|
|
SymbolicOutput = [dataArray{1:end-1}];
|
|
|
|
%% Clear temporary variables
|
|
clearvars filename delimiter formatSpec fileID dataArray ans;
|
|
|
|
%% replace brackets and commas
|
|
for lineIndex = 1:length(SymbolicOutput)
|
|
SymbolicOutput(lineIndex) = regexprep(SymbolicOutput(lineIndex), '_l_', '(');
|
|
SymbolicOutput(lineIndex) = regexprep(SymbolicOutput(lineIndex), '_c_', ',');
|
|
SymbolicOutput(lineIndex) = regexprep(SymbolicOutput(lineIndex), '_r_', ')');
|
|
end
|
|
|
|
%% Write to file
|
|
fileName = strcat('M_code',int2str(nStates),'.txt');
|
|
fid = fopen(fileName,'wt');
|
|
for lineIndex = 1:length(SymbolicOutput)
|
|
fprintf(fid,char(SymbolicOutput(lineIndex)));
|
|
fprintf(fid,'\n');
|
|
end
|
|
fclose(fid);
|
|
clear all;
|
|
|
|
end |