Is there alternatives for coder.extrinsic call?

3 visualizaciones (últimos 30 días)
Gergely Hunyady
Gergely Hunyady el 30 de Sept. de 2019
Respondida: Gergely Hunyady el 30 de Sept. de 2019
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

Respuesta aceptada

Gergely Hunyady
Gergely Hunyady el 30 de Sept. de 2019

Más respuestas (0)

Categorías

Más información sobre General Applications en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by