Is there alternatives for coder.extrinsic call?

3 次查看(过去 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 CenterFile Exchange 中查找有关 General Applications 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by