Merging Organised Point Clouds together in MATLAB Function block in Simulink

16 views (last 30 days)
Tong Zhao
Tong Zhao on 18 May 2021
Hi, In an autonomous vehicle point-cloud simulation, I have organised point cloud data from two different sources: one from other traffic actors (generated from the "Lidar Point Cloud Generator" block in Simulink), one from the scene itself (generated from the "Simulation 3D Lidar" block in Simulink). How do I overlap them in Simulink and create one overall organised point cloud? The point cloud size is 32x2250x3 each.
I tried pcmerge() in MATLAB command line for two pointCloud objects, and it worked. But when I try to wrap this workflow in a MATLAB Function block in Simulink, it failed. Here's the error message:
Cannot pass an object of a handle class 'pointclouds.internal.codegen.pc.pointCloud' to MATLAB function 'pcmerge'
Function 'Point Cloud Merge' (#70.495.501), line 15, column 14:
"ptCld1"
And the MATLAB Function I implemented in Simulink is:
function pc = fcn(pc1, pc2)
% DESCRIPTION: merging two point cloud data together with pcmerg(). The
% function first creates/updates the point-cloud objects for the two
% inputs, then feed the two objects to pcmerge() function who takes
% pointCloud objects as inputs;
%#codegen
coder.extrinsic('pcmerge');
% generate two pointCloud objects
ptCld1 = pointCloud(pc1);
ptCld2 = pointCloud(pc2);
% pass two pointCloud objects to pcmerge()
pc = zeros(32,2250,3); % initialize output
pc = pcmerge(ptCld1,ptCld2,1);
end
Seems that in a Simulink MATLAB Function situation, compiler is crying about the two generated pointCloud objects being objects of a handle class.
My second attempt was to exclude the "pointCloud" constructor function from code generation by typing coder.extrinsic('pointCloud'); this time the previous error message is gone but a new one came:
An error occurred while running the simulation and the simulation was terminated
Caused by:
MATLAB expression '<output of pcmerge>' is not numeric.
Ok this time it seems pcmerge() is not complaining about the inputs to pcmerge(), but now the output of pcmerge is not accepted by compiler. I guessed it could be that pcmerge() returned a pointCloud object (which is a non-numeric class type object), and thus not acceptable. So I looked up the documentation of pointCloud, and decided to just use the "Location" property of pointCloud, which is numeric. So the third and final attemp I tried was:
function pc = fcn(pc1, pc2)
%#codegen
coder.extrinsic('pcmerge');
coder.extrinsic('pointCloud');
% generate two pointCloud objects
ptCld1 = pointCloud(pc1);
ptCld2 = pointCloud(pc2);
% pass two pointCloud objects to pcmerge()
pc = zeros(32,2250,3); % initialize output
pc = pcmerge(ptCld1,ptCld2,1).Location;
But unfortunately there's still an error that said:
Attempt to extract field 'Location' from 'mxArray'.
Function 'Point Cloud Merge' (#70.518.542), line 16, column 6:
"pcmerge(ptCld1,ptCld2,1)"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
Errors occurred during parsing of MATLAB function 'mCrvSimulink/Point Cloud Merge'
Now I'm confused and out of idea. The message says I was trying to extract field 'Location' from mxArray, but no, I was trying to extract 'Location' from an 'pointCloud' class object. Need some help here, appreciate it!

Answers (0)

Community Treasure Hunt

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

Start Hunting!