ROS-Matlab ROS Custom Message Support的安装、使用与报错

前言

在用笔记本Ubuntu下的ROSwin7台式机Matlab进行通信时,需要自定义一个service类型。
Matlab具有相关功能,只不过需要先安装一个插件ROS Custom Message Support

安装插件并生成自定义文件

  • 1.在台式机安装插件,下载时需关闭防火墙,关闭代理,并使用管理者权限启动 matlab,否则可能报错无法下载第三方。
  • 2.生成自定义文件,在ROS内生成包含srvpackage.xml的完整package
  • 3.将整个package放入台式机下指定文件夹,并在该指定文件夹中创建一个m文件,内容如下:
path=pwd
rosgenmsg(path)
  • 4.按照rosgenmsg运行以后的提示进行余下操作:

    • a) 在 javaclasspath.txt 中添加指定路径
    • b) 添加自定义消息文件路径并保存
    • c) 重启并rosmsg list查看
  • 5.对于srv,生成两个消息文件,命名分别是[package名]/[service文件名]+[Request/Response]

  • 6.注:如果srv文件是小写字母开头,或者包含下划线,下划线后面是小写字母
    matlab中,将把开头字母自动转化成大写,删去下划线,下划线后面的小写字母变为大写

使用报错一

在确认能用rosmsg看到生成的自定义文件后,且确认UbuntuROS已启用roecoreservice节点,matlab端使用rosinit进行连接后,使用rosservice list可以查到在ROS端启用的service, 但查询该类型信息或类型时,出现如下报错:

……………… org.jboss.netty.channel.DefaultChannelPipeline

An exception was thrown by a user handler while handling an exception event ([id: 0x7c974942] EXCEPTION:
java.nio.channels.UnresolvedAddressException)
org.ros.exception.RosRuntimeException:
java.nio.channels.UnresolvedAddressException
at org.ros.internal.transport.ConnectionTrackingHandler.exceptionCaught(ConnectionTrackingHandler.java:94)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:533)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:157)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:102)
at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:55)
at org.jboss.netty.channel.Channels.connect(Channels.java:642)
at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:205)
at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:230)
at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:183)
at org.ros.internal.transport.tcp.TcpClient.connect(TcpClient.java:114)
at org.ros.internal.transport.tcp.TcpClientManager.connect(TcpClientManager.java:69)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:101)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:139)
… 8 more
Cannot find a MATLAB message class for type Request.

报错原因一

在使用serviceclient时, 使用hostname进行匹配连接,而不是IP。我直接使用rosinit('http://xxx.xxx.xx.x:11311')进行连接,所以报错。

处理方法一

  • 在Ubuntu和Win7下都修改hosts文件,添加
# edited file C:\Windows\system32\drivers\etc\hosts and on Ubuntu /etc/hosts by adding : 

192.168.65.82 UBUNTUPCIP 
192.168.65.80 WINDOWSPCIP
  • 重启电脑,是修改生效
  • 在ubuntu中设置环境变量
$ cd ~
$ sudo gedit ~/.bashrc

# 添加如下内容:
export ROS_MASTER_URI=http://UbuntuPCIP:11311 
export ROS_IP=UbuntuPCIP
  • 在matlab中使用如下代码进行连接:
setenv('ROS_MASTER_URI','http://Ubuntu_PC_IP:11311')
setenv('ROS_IP','Windows_PC_IP')
rosinit

使用报错二

:rosjava_messages is spawning subprojects: [test_drec]
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: “mavenRepository” on “org.ros.gradle_plugins.RosPluginExtension_Decorated@701fa10f”, value: “null”.
:test_drec:bugfixtask
:test_drec:generateSources
:test_drec:compileJava警告: [options] 未与 -source 1.6 一起设置引导类路径
F:\ROSCustomMessage\matlab_gen\build\rosjava_build\test_drec\build\generated-src\test_drec\ROSMatlabRequest.java:10: 错误: 程序包moveit_msgs不存在
moveit_msgs.RobotTrajectory getROBTRAJ();
^
F:\ROSCustomMessage\matlab_gen\build\rosjava_build\test_drec\build\generated-src\test_drec\ROSMatlabRequest.java:11: 错误: 程序包moveit_msgs不存在
void setROBTRAJ(moveit_msgs.RobotTrajectory value);
^
2 个错误
1 个警告
FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:test_drec:compileJava’.

    Compilation failed; see the compiler error output for details.

  • Try: Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

BUILD FAILED

Total time: 5.332 secs

错误使用 CustomService (line 4) An error occurred while building custom
messages. See the full error message above. Possible reasons for the
error:
1. The msg or srv files may have syntax errors.
2. The dependencies on other message packages may not be declared correctly in the build_depends tags in the package.xml.
3. Messages packages declared as dependencies may not be available.
4. The custom message packages may be missing a build dependency on “message_generation”.

See the ROS Custom Messages documentation for more information.

报错原因二

ROS支持的package.xml应当使用标签,而我直接使用了标签
更改标签后,顺利文档

处理方法二

更改packagepackage.xml文件中moveit_msgs标签

  
  <build_depend>moveit_msgsbuild_depend>

至此,顺利实现使用rosservice info查看自定义服务内容

参考

报错原因与方法
https://answers.ros.org/question/242920/unresolved-address-when-instantiating-a-service-client-on-rosjava-android/
https://ww2.mathworks.cn/matlabcentral/answers/387794-call-ros-service-java-error
https://ww2.mathworks.cn/matlabcentral/answers/196911-use-matlab-robotics-system-toolbox-to-receive-ros-message
https://ww2.mathworks.cn/matlabcentral/answers/119559-why-is-the-ros-subscriber-callback-in-matlab-not-triggered-when-messages-are-published-from-an-exter

你可能感兴趣的:(ROS)