I've made a Matlab program where it detects if 2 circles intersect each other and outputs the coordinates of the intersections. Now, I'm trying to convert the code into vhdl for FPGA implementation.
One of the functions within my code where there is still an error in the HDL Workflow Advisor is:
function theta = angle2Points(p1,p2)
%ANGLE2POINTS Compute horizontal angle between 2 points
%
% ALPHA = angle2Points(P1, P2),
% Pi are either [1*2] arrays, or [N*2] arrays, in this case ALPHA is a
% [N*1] array. The angle computed is the horizontal angle of the line
% (P1 P2)
% Result is always given in radians, between 0 and 2*pi.
%
% See Also:
% points2d, angles2d, angle3points, normalizeAngle, vectorAngle
%
%
% ---------
dp = zeros(1,2);
% angle of line (P2 P1), between 0 and 2*pi.
dp = p2 - (size(p2, 1) * p1)
theta = mod(atan2(dp(:,2), dp(:,1)) + 2*pi, 2*pi)
The errors:
- Variable 'p1'. Variable-Size data is not supported.
- Variable 'p2'. Variable-Size data is not supported.
- Variable 'theta'. Variable-Size data is not supported.
With a little test file to simulate the incoming data:
% P = [x,y]
P1 = [0,3];
P2 = [5,10];
f=angle2Points(P1,P2);
P1 = [0,3];
P2 = [5,3];
f2=angle2Points(P1,P2
Within the Workflow Advisor I receive the: Variable-Size data is not supported - error on line 1.
I understand this is because statically-typed languages like C must be able to determine variable properties at compile time, while within Matlab it happens dynamically.
I'd like some help with this simple function on how to correctly rewrite the code to make it hdl ready.
Thanks in advance
Coder is complaining because you have both a variable number of inputs as well as variable size inputs (
P1can be either 2x2 or 1x2). What you need to do is write your function so that it requires bothp1andp2and that they are a known size (1 x 2).You will also need to update all the functions that call this function so that they are compatible.
As a side note, you don't have to pre-allocate variables unless you are putting data into them in a loop structure. If you're simply assigning the entire variable at once (i.e.
dpabove), you don't need any pre-allocation.