【PX4-AutoPilot教程-TIPS】Matlab使用ROS Toolbox编译MAVROS2消息报错缺少geographic_msgs消息

Matlab使用ROS Toolbox编译MAVROS2消息报错缺少geographic_msgs消息的解决方法

环境:

MATLAB : R2022b

ROS Toolbox : 1.6

Windows :Windows 10 22H2

ROS :ROS2 Foxy

问题描述

在使用Matlab的ROS Toolbox工具箱编译与PX4联合调试的代码,Matlab官方给出的示例是使用ROS2配合microRTPS连接无人机,并发送控制命令来导航模拟无人机。

Control a Simulated UAV Using ROS 2 and PX4 Bridge

但是实际中使用更多的是MAVROS2连接的方法,所以这里选择了编译MAVROS2消息来实现与Matlab的联合调试。

MAVROS2

在官网下载MAVROS2的源码,使用Matlab中的ros2genmsg命令生成ROS2消息。

Generate custom messages from ROS 2 definitions

新建一个PX4-ROS2-Simulink文件夹用来存储工程文件(名字可以任取),在其下新建custom文件夹、others文件夹。

将下载的MAVROS2包的Zip压缩包放在PX4-ROS2-Simulink/others文件夹下。

解压,将其中的mavros_msgs文件夹放在PX4-ROS2-Simulink/custom文件夹下。

最后的结构为下列所示。

PX4-ROS2-Simulink
├─custom
|  └─mavros_msgs
|      ├─include
|      ├─msg
|      ├─srv
|      ├─CHANGELOG.rst
|      ├─CMakeLists.txt
|      ├─mavros_msgs_mapping_rule.yaml
|      └─package.xml
└─others
   └─mavros-ros2.zip

用Matlab打开PX4-ROS2-Simulink文件夹,在Matlab命令行中输入以下命令。

folderPath = fullfile(pwd,"custom");
ros2genmsg(folderPath);

编译过程中报错如下:

>> ros2genmsg(folderPath);
Identifying message files in folder 'F:/PX4-ROS2-Simulink/custom'..Done.
Validating message files in folder 'F:/PX4-ROS2-Simulink/custom'..Done.
[0/1] Generating MATLAB interfaces for custom message packages... 0%错误使用 ros.internal.utilities.locateMessage
Specified message package geographic_msgs does not exist. Check the message package specified.

出错 ros.internal.MessageParser/getMessageDefinitionHelper (第 143 行)
            filePath = ros.internal.utilities.locateMessage(...

出错 ros.internal.MessageParser/nestedMessageParser (第 662 行)
            dataStructure = getMessageDefinitionHelper(obj, CirDependList);

出错 ros.internal.MessageParser/getDataStructure (第 356 行)
                                nestedMessageParser(obj,dataType,CirDependList);

出错 ros.internal.MessageParser/getMessageDefinitionHelper (第 160 行)
            messageDefinition = getDataStructure(obj,filePath,contentsOfFile,...

出错 ros.internal.MessageParser/getMessageDefinition (第 135 行)
            messageDefinition = getMessageDefinitionHelper(obj,CirDependList);

出错 ros.internal.pubsubEmitter (第 47 行)
    msgDefn = getMessageDefinition(parser);

出错 ros2genmsg (第 233 行)
            [genFiles, dependencies] = ros.internal.pubsubEmitter(msgFullName{end}, ...

原因是Matlab的内置ROS2中缺少geographic_msgs这个消息包。

Matlab安装路径的D:\MATLAB\R2022b\sys\ros2\win64\ros2\share文件夹中没有geographic_msgs这个消息包。

但是在Matlab的帮助文档中,Supported Messages栏目中是有列出这个消息的。

Built-In Message Support

在这里插入图片描述

这可能是一个BUG。

解决方法

解决方法就是下载geographic_msgs这个消息包,一起放到custom文件夹下进行编译。

打开官网链接进行下载,注意需要下载的是ROS2版本的。

ros-geographic-info/geographic_info

解压后将其中的geographic_msgs文件夹复制到custom文件夹下

将下载的geographic_msgs包的Zip压缩包放在PX4-ROS2-Simulink/others文件夹下。

解压,将其中的geographic_msgs文件夹放在PX4-ROS2-Simulink/custom文件夹下。

最后的结构为下列所示。

PX4-ROS2-Simulink
├─custom
|  ├─geographic_msgs
|  |   ├─include
|  |   ├─msg
|  |   ├─srv
|  |   ├─test
|  |   ├─CHANGELOG.rst
|  |   ├─CMakeLists.txt
|  |   ├─geographic_msgs_mapping_rule.yaml
|  |   ├─mainpage.dox
|  |   └─package.xml
|  └─mavros_msgs
|      ├─include
|      ├─msg
|      ├─srv
|      ├─CHANGELOG.rst
|      ├─CMakeLists.txt
|      ├─mavros_msgs_mapping_rule.yaml
|      └─package.xml
└─others
   └─mavros-ros2.zip

用Matlab打开PX4-ROS2-Simulink文件夹,再次编译即可。

folderPath = fullfile(pwd,"custom");
ros2genmsg(folderPath);

参考资料:

Generate custom messages from ROS 2 definitions

Built-In Message Support

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

后厂村路练习生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值