Receiving the error Undefined function or variable 'getOccupancy'. in simulink but not in matlab
Mostrar comentarios más antiguos
I am attempting to make some ramdom waypoints for a robot to follow.
I run the attached code in Matlab and do not have any issues however when I try to run it in simulink I receave the following message.
Undefined function or variable 'getOccupancy'.
As this runs in matlab I do not think it is a toolbox related issue but I am open to any suggesstions.
Attached below is my code that runs in matlab. (for simulink implementation I add this function line to it : function [WP_OUT_X, WP_OUT_Y] = fcn(map))
key = 0;
%%% Waypoint generator
if key < 1
%% Generate multiple the waypoints
Xarry = linspace(2,52,51); % Generate x values between 2 and 51 (1 and 52 will always be a wall)
Yarry = linspace(2,41,40); % Generate y values between 2 and 40 (1 and 41 will always be a wall)
Smplx = randsample(Xarry, 39); % Choose 39 random samples from the above 2 vectors
Smply = randsample(Yarry, 39); % Limited to 39 due to the size of the algorithm
Position_Matrix = [Smplx; Smply]; % Change them into 2 columns
Position_Matrix1 = Position_Matrix; % Duplicate Pos matrix so we can keep original and do work on the copy
%% This makes the map into a logical grid
occVal = zeros(1,51); % Preallocation
j = 2; % start at 2 as 1 is always a wall
while j < 51 % Finish at 51 as 52 is awlways a wall
i = 2; % start at 2 as 1 is always a wall
while i < 40 % Finish at 40 as 41 is awlways a wall
interum = getOccupancy(map,[j, i]); % Will test if the map is a wall or not at each x and y co-ord
occVal(i, j) = interum(:); % Stores the co-ords
if occVal(i, j) == 1 % If occVal is a wall
Position_Matrix1(:,i) = nan; % The current position is a nan value this will run for each j value but only the last one will be kept
end
i = i + 1; % Increase i counter
end
j = j + 1; % Increase j counter
end
%%
tv = rmmissing(Position_Matrix1(1,:)); % Check the top numbers of the vector for nan values then remove them
bv = rmmissing(Position_Matrix1(2,:)); % Check and remove all nan values from the bottom vector
bta = [tv;bv]; % Splice the vector back together
WP_OUT = bta(:,1:5); % Take the first 5 values of the splice vector and output them
WP_OUT_X = WP_OUT(1,:) % Outputs
WP_OUT_y = WP_OUT(2,:) % Outputs
key = 1; % Key variable so code only runs once (May Not Need)
end
%% Experimental Code zone
1 comentario
Walter Roberson
el 1 de Oct. de 2021
coder.external('getOccupancy')
This might not work if you need to do code generation
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Axes Transformations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!