How to publish image to ROS in Simulink

조회 수: 3 (최근 30일)
Kun Yan
Kun Yan 2018년 6월 11일
댓글: Syed Adil Ahmed 2020년 10월 21일
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?

답변 (1개)

JAI PRAKASH
JAI PRAKASH 2018년 11월 4일
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
Pavan Anandareddy
Pavan Anandareddy 2020년 9월 17일
Hi,
Were you able to solve this error?
Syed Adil Ahmed
Syed Adil Ahmed 2020년 10월 21일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 ROS 2 Network Access in Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by