Using ROS 1 message generated by rosgemmsg: calling rosmsg or rosmessage before addpath breaks later calls?

2 ビュー (過去 30 日間)
I was able to create a custom message using rosgenmsg (Matlab 2020a). While testing I discovered something a bit odd from my perspective. If I try to create a message using rosgenmsg before modifying the path with addpath, the creation fails. This is what I would expect. Then I add the path for this custom message and still can't create it. See below:
>> rosmsg('show', 'crtk_msgs/operating_state')
Could not find definition of message type crtk_msgs/operating_state. Check the spelling of the type, or use
"rosmsg list" to retrieve a list of available message types.
>> addpath('/home/anton/catkin_ws/src/crtk/matlab_gen/msggen')
>> rosmsg('show', 'crtk_msgs/operating_state')
Could not find definition of message type crtk_msgs/operating_state. Check the spelling of the type, or use
"rosmsg list" to retrieve a list of available message types.
If I then quit Matlab and add the path before trying to create the message, everything is fine.
>> addpath('/home/anton/catkin_ws/src/crtk/matlab_gen/msggen')
>> rosmsg('show', 'crtk_msgs/operating_state')
std_msgs/Header Header
char State
logical IsHomed
logical IsBusy
So it seems there a cache maintained somewhere with a list of existing message types. Is that true and if so, how can I force a re-hash after I add paths to custom messages?

採用された回答

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2020 年 11 月 20 日
Hi,
You might have to run the below two commands after adding the path, to refresh all message class definitions which in turn requires clearing the workspace.
clear classes
rehash toolboxcache
By doing this you would not need to restart matlab.
For more information refer to the following document
Hope this helps!
  1 件のコメント
Anton Deguet
Anton Deguet 2020 年 11 月 23 日
I tried from a clean environment, i.e. deleted my startup.m as well as the javaclasspath.txt. I then generated the ros custom messages, edited the javaclasspath, did addpath and the two commands you suggested (as well as clear path and this didn't help. It seems the messages are not found (using rosmsg command) unless I restart Matlab. This is honestly not a big deal, I don't see many cases where one would need to generate the messages and use them in the same Matlab session. Furthermore, 2020b has introduced a new way to generate custom messages. At that point, I don't think it's necessary to spend more time on this minor issue.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeROS 2 Network Access in MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by