在MATLAB中使用自定义的ROS消息类型

MATLAB 2019b中提供了较为完整的ROS功能支持,其中包括使用自定义的ROS消息类型。下面给出使用方法和一个例子。

测试环境:

  • Ubuntu 18.04
  • ROS Melodic
  • MATLAB 2019b

使用步骤:

  1. 编写含有自定义ROS消息(服务)类型的程序包,并在catkin空间进行编译

    $ cd ~/ROS/hai_ws/src
    $ git clone https://github.com/hai-zhu/multiagent_srv.git
    $ cd ..
    $ catkin build
    
  2. 打开MATLAB,指定该程序包的位置,并使用rosgenmsg命令生成自定义消息文件

    >> folderpath = '/home/hai/ROS/hai_ws/src'
    >> rosgenmsg(folderpath)
    

    注意:使用rosgenmsg命令安装工具箱Robotics System Toolbox Interface for ROS Custom Messages。

    完成该命令后,将会在原ROS程序包所在的文件夹下(src)自动生成一个文件夹matlab_gen。同时在MATLAB的命令行窗口,会显示以下信息:

    Checking subfolder "multiagent_srv" for custom messages.
    
    Building custom message files for the following packages:
    	multiagent_srv
    
    Generating MATLAB classes for message packages in /home/hai/ROS/hai_ws/src/matlab_gen/jar.
    
    Loading file multiagent_srv-0.0.0.jar.
    Generating MATLAB code for multiagent_srv/CommMultiAgent message type.
    Generating MATLAB code for multiagent_srv/StepMultiAgentRequest message type.
    Generating MATLAB code for multiagent_srv/StepMultiAgentResponse message type.
    
    To use the custom messages, follow these steps:
    
    1. Edit javaclasspath.txt, add the following file locations as new lines, and save the file:
    
    /home/hai/ROS/hai_ws/src/matlab_gen/jar/multiagent_srv-0.0.0.jar
    
    2. Add the custom message folder to the MATLAB path by executing:
    
    addpath('/home/hai/ROS/hai_ws/src/matlab_gen/msggen')
    savepath
    
    3. Restart MATLAB and verify that you can use the custom messages. 
    	Type "rosmsg list" and ensure that the output contains the generated
    	custom message types.
    
  3. 根据提示信息对javaclasspath.txt文件进行修改,并添加相关文件夹到MATLAB的路径中。重启MATLAB,使用命令rosmsg list就可以看到自定义的消息类型了。

参考资料: https://nl.mathworks.com/help/ros/ug/ros-custom-message-support.html
https://nl.mathworks.com/help/ros/ug/create-custom-messages-from-ros-package.html

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值