How to publish image to ROS in Simulink
Ältere Kommentare anzeigen
I use the function writeImage() in matlab function to write a MATLAB image to the ROS image message,but when I run the simulink model, an error appears: Undefined function or variable 'writeImage'. How to solve this problem? How to publish image to ROS in Simulink?
Antworten (1)
JAI PRAKASH
am 4 Nov. 2018
If your matlab image is 'RGB' matrix, you can use following matlab function block + Bus assignment block as shown in figure.
function [H, W, Enc, EncLength, IsBig, Step, Data, DataLength] = fcn(im)
[H, W, n] = size(im);
H =uint32(H); W =uint32(W);
im = permute(im,[2 1 3]);
Data1 = im(:);
Data2 = reshape(Data1,[H*W,n])';
Data = Data2(:);
Enc = zeros(1,128, 'uint8');
Enc(1:4) = uint8('rgb8'); % uint8('rgb8')
EncLength = uint32(4);
IsBig = uint8(0);
Step = uint32(W*n);
DataLength = uint32(H*W*n);

See the attached simulink readymade block also to convert MAT image to ros image message.
3 Kommentare
snow John
am 27 Mai 2019
Help please!I got this error below:
Inferred size ('scalar') for data 'Data' does not match back propagated size ('[556416]') from Simulink.
Component:MATLAB Function | Category:Coder errorOpen
Simulink cannot determine sizes and/or types of the outputs for block 'PubImage1/Data to fill me Blank msg' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'PubImage1/Data to fill me Blank msg' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
What should i do?
Pavan Anandareddy
am 17 Sep. 2020
Hi,
Were you able to solve this error?
Syed Adil Ahmed
am 21 Okt. 2020
For those interested you can fix the non matching size of the Data bus variable by changing array sizes in Simulink for ros. This option is under tools> ROS in simulink.
Kategorien
Mehr zu ROS 2 Network Access in Simulink finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!