필터 지우기
필터 지우기

MATLAB coder error while using 'rospublisher'

조회 수: 4 (최근 30일)
JhenMin Hung
JhenMin Hung 2023년 7월 26일
댓글: JhenMin Hung 2023년 8월 1일
I'm facing the error while using MATLAB coder. The error shows 'Value cannot be displayed because the output of 'coder.ceval' does not have a known type. To display the output, first assign the result to a variable of known type.' , and the error was due to
pub = rospublisher("/path", "geometry_msgs/Point", "DataFormat", "struct");
And below is part of my code:
r = rosrate(10);
pub = rospublisher("/path", "geometry_msgs/Point", "DataFormat", "struct");
% ...
while true
% Create a new ROS message
msg = rosmessage(pub);
msg.Data = struct_target_path;
% Publish the message
send(pub, msg);
waitfor(r);
end
What I want to do is to publish a structure message(struct_target_path) with the topic named "/path".
I have already tried various methods, but all of them didn't work.
Thank you for anyone who can help me to fix it.

답변 (1개)

Karthik Reddy Vennapureddy
Karthik Reddy Vennapureddy 2023년 7월 31일
Hi JhenMin,
The message struct you are creating in while loop using rosmessage API, is of message type "geometry_msgs/Point". This type has no such field 'Data'. Instead it has fields X, Y and Z. So, it is not allowed to do the following:
msg.Data = struct_target_path;
Instead the below syntax is allowed
msg.X = 10;
Thanks,
Karthik Reddy
  댓글 수: 5
Karthik Reddy Vennapureddy
Karthik Reddy Vennapureddy 2023년 7월 31일
Hi JhenMin,
Are you able to directly run the above script without any issues in MATLAB, but facing issues only using MATLAB Coder when generating the code?
Thanks,
Karthik Reddy
JhenMin Hung
JhenMin Hung 2023년 8월 1일
Yes, it runs well in MATLAB, but only facing the issue while generating the code. And it also faced the same error when i used the function
[ros_msg,status,statustext] = receive(segnet_img_sub);

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

카테고리

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

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by