matlab ros 通信

通信过程如果设置不当会出现,rosnode list下面可以看到matlab 的节点,但是从ros中发出的消息却不能读出data

如果rostopic echo topic名称 在ros下能输出,但是在matlab下面无法输出,则可以定位为通信问题,既然可以看到matlab的节点说明matlab 与ros是可以通信的,此时应该反向思考,ros与matlab通信应该存在问题。

https://www.mathworks.com/matlabcentral/answers/347809-matlab-ros-subscriber-basic-example

这里说明了较为详细的解决办法:

In my case, the IP adress are

PC with Matlab : 192.168.1.41

ROS computer : 192.168.1.28

In the .bashrc, I have

source /opt/ros/indigo/setup.bash

export ROS_MASTER_URI=http//192.168.1.28:11311

export ROS_HOSTNAME=192.168.1.28

export ROS_IP=192.168.1.28

.

In Matlab 2 solutions are possible:

solution 1:

setenv('ROS_IP','192.168.1.41') % adress PC with Matlab

setenv('ROS_HOSTNAME','192.168.1.41')

setenv('ROS_MASTER_URI','http://192.168.1.28:11311/')

 

读数据ROS与matlab存在一些差异,其中ROS读取数据是通过节点subscribe所访问的topic,而在matlab中则不是如此。

rosshutdown
% setenv('ROS_MASTER_URI','http://192.168.1.21:11311')
% setenv('ROS_IP','192.168.1.18')
setenv('ROS_IP','192.168.1.18') % adress PC with Matlab
setenv('ROS_HOSTNAME','192.168.1.18')
setenv('ROS_MASTER_URI','http://192.168.1.21:11311/') % adress turtlebot
rosinit()
sub=rossubscriber('chatter')
while (1)
    msg2 = receive(sub)
    disp(msg2)
end

不需要创建节点。

https://www.mathworks.com/help/ros/ug/connect-to-a-ros-network.html

这个网站是配置matlab与ros的官方文档,其中下面这段描述了如何编辑ROS环境变量,

ROS Environment Variables

In advanced use cases, you might want to specify the address of a ROS master and your advertised node address through standard ROS environment variables. The syntaxes that were explained in the previous sections should be sufficient for the majority of your use cases.

If no arguments are provided to rosinit, the function will also check the values of standard ROS environment variables. These variables are ROS_MASTER_URIROS_HOSTNAME, and ROS_IP. You can see their current values using the getenv command:

getenv('ROS_MASTER_URI')
getenv('ROS_HOSTNAME')
getenv('ROS_IP')

You can set these variables using the setenv command. After setting the environment variables, call rosinit with no arguments. The address of the ROS master is specified by ROS_MASTER_URI, and the global node's advertised address is given by ROS_IP or ROS_HOSTNAME. If you specify additional arguments to rosinit, they override the values in the environment variables.

setenv('ROS_MASTER_URI','http://192.168.1.1:11311')
setenv('ROS_IP','192.168.1.100')
rosinit

You do not have to set both ROS_HOSTNAME and ROS_IP. If both are set, ROS_HOSTNAME takes precedence.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值