- What is this "mytopic_msgs/MotorCmd"? Is it a custom message? If yes, have you created a custom message using rosgenmsg?
- Instead of rosinit(ipaddress), if you do "rosinit", and then create such publisher or subscriber, would that work?
- Is this a message already existed in the network? (e.g. published from or subscribed by a node in your virtual machine)
Fail to create a ROS publisher/ subcriber for individual project
15 次查看(过去 30 天)
显示 更早的评论
Hi,
I followed https://www.mathworks.com/help/ros/ug/communicate-with-the-turtlebot.html , and applied this idea to my specific project in my robot, not to the Turtlebot.
Basically, I have my own ROS project, and successfully built it in the Virtual Machine- Ubuntu-Gazebo 9.
After I used roslaunch to start my own project in VM, and in the Matlab I used rosinit(ipaddress) to successfully intialized Matlab global node and connected with ROS master,
and I successfuly got the names of all rostopic by using the command rostopic list in Matlab command window.
---------------------------------------------------------------------------
Now, I am trying to create a new publisher in Matlab to publish information to one topic (name as /mytopic, for example) in my own ROS project by using command: Matlab_Pub = rospublisher("/mytopic").
But I got an error: Failed to create a ROS publisher with topic name /mytopic and message type mytopic_msgs/MotorCmd.
----------------------------------------------------------------------------
And I also got the same issue when trying to creat a new subscriber in Matlab to subscribe to one topic in my own ROS project: Matlab_Sub = rossubscriber("/mytopic")
Could you please give me some insight on this issue and how to fix them?
Thank you so much for your help!
2 个评论
Josh Chen
2021-2-5
Hello Van,
Can you please share more details about project? From the error message it looks like something was missing.
Josh
采纳的回答
Josh Chen
2021-2-5
编辑:Josh Chen
2021-2-5
Hi Van,
Based on your reply, it did seem that you are missing custom message definition in MATLAB. So MATLAB has a set of predefined ROS messages (e.g. std_msgs/Float64) that you can directly use for publisher and subscriber. a full list of those predefined messages can be seen by typing in
>> rosmsg list
However, in this case, when you tried to publish or subscribe to a topic that has a message which does not shipped with MATLAB, MATLAB needs more information about such message. Once you provide the message definition files (*.msg) and run the rosgenmsg, you should be able to see it in the rosmsg list. After that, you should be able to use that message for publisher and subscriber.
Here you can find more about ROS custom message and here is a documentation page showing an example of generating a custom message in MATLAB.
Hope this helps,
Josh
2 个评论
Josh Chen
2021-2-5
编辑:Josh Chen
2021-2-5
Hello Van,
Yes, that is correct, the custom message should be the same type with the message of /mytopic. You can probably copy the message definition files from your project.
I would suggest to:
- play around the doc example and make sure you are able to generate the custom message as shown in the example
- copy your custom message and generate them following the same way you did before (make sure it shows up in >> rosmsg list)
- then have fun using publisher and subscriber. :)
Josh
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!