MATLAB Answers


Is it possible to use simulink coder incompatible robotics toolbox functions using S-functions?

I am trying to develop a stand-alone ROS node in simulink that utilizes the robotics toolbox matchScansGrid() function.
But as simulink coder does not support code generation for the matchScansGrid() function (or any of the lidarSLAM tools), I was proposed an alternate method to use the matchScansGrid() in simulink:
  1. Make a matlab function {eg testScanMatching() } that utilizes (or calls) the matchScansGrid().
  2. Generate C code of this function (testScanMatching) using Matlab coder. This is possible as matchScansGrid() is supported by matlab coder.
  3. Use the packNGo functionality
  4. Unzip the output of step 3.
  5. Use the legacy code to generate a compatible S-function (of testScanMatching)
  6. Import it in simulink
  1. Does this method work? Can I really use matchScansGrid() in simulink using this round-about way?
  2. Is there a guide to implement S-functions from matlab coder generated C/C++ code ?
Thanks in advance.
note: I am testing this method but currently I have trouble building an S function from the code generated of testScanMatching


If you just put the use of matchScansGrid into a MATLAB Function block, that should work fine in Simulink Coder. E.g. have a block with four inputs and one output, like this:
function relPose = useMatchScansGrid(ranges1, angles1, ranges2, angles2)
x = lidarScan(ranges1, angles1);
y = lidarScan(ranges2, angles2);
relPose = matchScansGrid(x,y);

Sign in to comment.

1 Answer

Answer by soorajanilkumar on 16 Sep 2019
 Accepted Answer

Thanks Denis,
It worked now.
I'm not sure, but when I tried before I was not successful. In addition I had to enable dynamic memory allocation to generate code for the matlab function.


Sign in to comment.