Is there alternatives for coder.extrinsic call?

4 vues (au cours des 30 derniers jours)
Gergely Hunyady
Gergely Hunyady le 30 Sep 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

Réponse acceptée

Gergely Hunyady
Gergely Hunyady le 30 Sep 2019

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by