Is there alternatives for coder.extrinsic call?
4 views (last 30 days)
Show older comments
Gergely Hunyady
on 30 Sep 2019
Answered: Gergely Hunyady
on 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
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!