Matlab generate ROS action message type from ROS packages

最近在做matlab通过action方式和ROS中的机器人通讯,控制gazebo中的机械臂运动。

在ROS中写好了action服务端DoDishes_server,但是在matlab中用rosactionclient定义客户端时报错,缺少对应的action type。

[actClient,goalMsg] = rosactionclient('/do_dishes');
Failed to create a simple action client with name /do_dishes and type action_tutorials/DoDishes. Verify that the action type is valid.
结合官方提供的例子‘/fibonacci’,查看安装路径中+actionlib_tutorials文件夹下对应的action message type文件(如下图所示),发现原来这些文件都是通过一个插件自动生成的。只怪自己起步太晚,且没有从最基础的开始着手,不知道matlab和ROS通讯时有些消息类型是要通过自己的packages生成的,否则matlab中就会提示没有该message type。下面就以action type为例说明一下这个过程,其他应该类似。


    %   This class was automatically generated by
    %   robotics.ros.msg.internal.gen.MessageClassGenerator.

1. 上matlab官网下载并安装一个插件“"Robotics System Toolbox Interface for ROS Custom Messages",该插件介绍如下:

Using the ROS Custom Messages Interface, you can extend the set of ROS messages supported by Robotics System Toolbox. You can define your own custom ROS message and service types, and use them in MATLAB and Simulink to communicate with other nodes in the ROS network. --来自matlab官网

2.ROS环境下编译功能包

ROS环境下通过命令编译功能包:

$ catkin_make -DCATKIN_WHITELIST_PACKAGES="action_tutorials"
在action_tutorials/msg文件夹下会生成各种 .msg 文件,后来发现matlab建立消息文件时都是基于msg文件夹下的文件。

3. 参照”create custom messages from ros package“建立自己的消息。

我的matlab和ROS都是装在ubuntu系统上的,为了方便我在home目录下新建了一个文件夹msg_gen,然后把功能包action_tutorials拷进这个文件夹。正如前面所说的,matlab建立消息文件是根据msg文件和package.xml文件进行的,程序会在msg_gen/action_tutorials目录下查找msg文件夹和package.xml文件,所以其他没用的文件基本都可以删掉。msg文件和package.xml文件中的内容可参考下面:

# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======
# Define the goal
uint32 action_id  # Specify which dishwasher we want to use
float64[] urpos
float64[] finger1
float64[] finger2
float64[] finger3
<?xml version="1.0"?>
<package format="2">
  <name>my_robot</name>
  <version>1.0</version>
  <description>The my_robot package</description>

  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>actionlib</build_depend>
  <build_depend>actionlib_msgs</build_depend>

</package>

然后直接在matlab命令窗口输入下面的命令就可以了。其他具体的步骤参照create custom messages from ros package“一步步走就可以了。

userfolder = '/home/robot/msg_gen';
rosgenmsg(userfolder)

如果matlab和ROS是在两台不同的电脑上的,应该需要把相关文件拷到装有matlab的电脑上。


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值