Is there alternatives for coder.extrinsic call?

3 ビュー (過去 30 日間)
Gergely Hunyady
Gergely Hunyady 2019 年 9 月 30 日
回答済み: Gergely Hunyady 2019 年 9 月 30 日
Hy,
I would like to solve a simple 2 variable equation in Simulink and found this method, but it seems to be unprofessional and slows down simulation (maybe) because of the iterative call for the function.
Is there any other method to solve symbolic functions in Simulink Matlab Function module?
function RefPoint = SymsFcn(P, CTPosition, RefLineNormVector, ErrLineNormVector)
syms x y;
f1 = RefLineNormVector(1)*x + RefLineNormVector(2)*y ...
== RefLineNormVector(1)*P(1) + RefLineNormVector(2)*P(2);
f2 = ErrLineNormVector(1)*x + ErrLineNormVector(2)*y ...
== ErrLineNormVector(1)*CTPosition(1) + ErrLineNormVector(2)*CTPosition(2);
RefPoint = solve([f1 f2], [x y]);
end
function [LateralError,OrientationError] = ErrorCalculation(XPosition, YPosition, Orientation, ID, TestPath)
RefLine = [(TestPath(ID+1,1) - TestPath(ID,1)), (TestPath(ID+1,2) - TestPath(ID,2))];
RefOrient = CalcDeg(RefLine(1), RefLine(2), 'deg');
OrientationError = Orientation - RefOrient;
RefLineNormVector = Transform(RefLine', [0 0], 90); %90 degrees CCW rotation
ErrLineNormVector = Transform(RefLine', [0 0], 180); %180 degrees CCW rotation
coder.extrinsic('SymsFcn');
ErrorRefPoint = double(SymsFcn(TestPath(ID,:), [XPosition, YPosition], RefLineNormVector, ErrLineNormVector));
LateralError = sqrt((XPosition - ErrorRefPoint(1))^2 + (YPosition - ErrorRefPoint(2))^2);
end
Thanks for your help in advance.
Gergely Hunyady

採用された回答

Gergely Hunyady
Gergely Hunyady 2019 年 9 月 30 日

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by