ROS2: Unrecognized message without using it in script

Hello Everyone,
i managed to import custom massages via the command ros2genmsg. But now i get allways the error, that some massage type is not recognisable by matlab. Even when i dont use any commands that need the custom commands. See code snippet:
clc
clear
topicName="/sensor_state";
matlabNode = ros2node("matlabNode");
SensorState = ros2subscriber(matlabNode,topicName);
This example gives me now the following error massage:
Error using ros.internal.getEmptyMessage>getMessageDataAndInfo
Unrecognized message type turtlebot3_msgs/SensorState. Use ros2 msg list to see available types.
Error in ros.internal.getEmptyMessage>getCachedMap (line 46)
[structInfo.data,structInfo.info] = getMessageDataAndInfo(msg, msgInfo, rosver);
Error in ros.internal.getEmptyMessage (line 35)
[data,info] = getCachedMap(msgMapROS2,msg,msgInfo,rosver);
Error in ros.internal.utilities.findMsgDepends (line 17)
[msgStruct,info] = ros.internal.getEmptyMessage(msgName,rosver);
Error in ros.internal.utilities.getPathOfDependentDlls (line 14)
pkgNamesMap = ros.internal.utilities.findMsgDepends(msgType,map,rosver);
Error in ros2subscriber/createSubscriber (line 669)
dllPaths = ros.internal.utilities.getPathOfDependentDlls(obj.MessageType,'ros2');
Error in ros2subscriber (line 330)
createSubscriber(obj, ordinalParser.Results.node.ServerNodeHandle, ...
Error in Turtlebot3_Subscription_SensorState (line 21)
SensorState = ros2subscriber(matlabNode,topicName);
I used turtlebot3_msgs/SensorState in the past, but deleted it afterwards because it was not longer necessary in my project. Is there any kind of storage in matlab that i have to reset when i delete packages on my disc?
EDIT: I can subscribe every topic, but not /sensor_state. E.g. /rosout.. Anyone a guess what it could be?
I use Matlab 2022a and ROS Toolbox 1.5.
I would much appreciate your help.
greetings, André

 채택된 답변

Andre Below
Andre Below 2022년 4월 20일

0 개 추천

It works now. I just createt a new package "turtlebot3_msgs" with a folder msg. The only msg defined there is SensorState.msg.
I have SensorState now two times. turtlebot3_matlab/SensorState and turtlebot3_msgs/SensorState.
thanks for your help.

추가 답변 (1개)

Hari Krishna Kakarla
Hari Krishna Kakarla 2022년 4월 11일

0 개 추천

Hi Andre,
When you generate any custom messages, It registers with MATLAB Preferences. And when you want to delete your custom messages, you need to delete your generated matlab_msg_gen folder. After deleting it, Doing "clear all" in MATLAB should actually remove the messages from preferences.
Else, call this command to update your MATLAB preferences:
reg = ros.internal.CustomMessageRegistry.getInstance('ros2',true)
This will update the MATLAB preferences correctly. I hope this information is helpful.
Thanks
Hari

댓글 수: 6

Hello Hari,
Unfortunately deleting the folder matlab_msg_gen, clear all or the command reg = ros.internal.CustomMessageRegistry.getInstance('ros2',true) doesnt remove the error massage.
The thing is, i already imported the custom massages via
ros2genmsg('C:\','dev','ros2_foxy','custom');
when i print the msg list with ros2 msg list, i can see my custom massages:
Also, the command
ros2 msg show turtlebot3_matlab/SensorState
shows me the exact same massage, that is shown in the programm rqt.
Hi Andre,
I see that, you are getting this error message, if I am correct:
"Unrecognized message type turtlebot3_msgs/SensorState. Use ros2 msg list to see available types."
It means your message type "turtlebot3_matlab/SensorState" is depending on "turtlebot3_msgs/SensorState" which is not existing. Or you might have created your custom messages in two different folders. Ideally you need to have all your custom message packages in a single folder and generate your custom messages.
Try verifying these things:
reg = ros.internal.CustomMessageRegistry.getInstance('ros2',true)
msgInfo = reg.getMessageInfo('turtlebot3_msgs/SensorState')
From the fields of msgInfo, you can know where you have generated your custom messages and you can delete if not required. I hope this helps.
Thanks
Hari
Andre Below
Andre Below 2022년 4월 14일
편집: Andre Below 2022년 4월 14일
Sorry, i forgot to mention, despite the fact that i can see my custom massages with the command ros2 msg list, that the CustomMessageRegistry is empty.
Andre Below
Andre Below 2022년 4월 14일
편집: Andre Below 2022년 4월 14일
Update: I tried to use the Subscribe Block in Simulink. When i choose there the topic /sensor_state, it gets correctly recognized as type turtlebot3_matlab/SensorState. However, it still gives an error massage, when i try to run the simulation. See picture below.
Following the error massage caused by ...\ros2subscriber.m line 316:
My question is: why is there a problem with determining the type? I don't know why the existingType is already used when i deletet the matlab_msg_gen folder and generated again the massages by matlab?
Hi Andre,
reg = ros.internal.CustomMessageRegistry.getInstance('ros2',true) will create a registry object. If you want to see the messages in the registry:
>> reg.getMessageList
Then check this:
>> reg.getMessageInfo('turtlebot3_msgs/SensorState');
If the above command says that there is no such message type in registry, then you can confirm that your previously generated custom messages are deleted from custom message registry.
Regarding your second question, I see that your topic is still subscring to the old message. It means some ROS 2 nodes are still active in background which earlier used those old messages. Please make sure to check all the ROS 2 nodes available in network and delete them. Please make sure to close all your MATLAB sessions running and start a new MATLAB session.
Thanks
Hari
Hello Hari,
the command reg.getMessageList shows me only the correct massages.
For the second question i looped over all DomainID`s (1 to 101) with the command curNodeList = ros2("node","list","DomainID",curDomainID); and it shows me no old nodes. when i close all programms that create nodes, all nodes are correctly gone.
i also allready reinstalled matlab2022a but nothing works.
greetins, André

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

카테고리

도움말 센터File Exchange에서 Publishers and Subscribers에 대해 자세히 알아보기

제품

릴리스

R2022a

태그

질문:

2022년 4월 8일

답변:

2022년 4월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by