Matlab与ROS

Introduction

本文主要介绍Matlab与ROS通信过程。主要参考古月老师https://www.guyuehome.com/1006

实验准备:
主机:Win10 Matlab2018b
从机:ubuntu16.04 kinetic
连接:同一网络下

Matlab尝试

打开Maltab,运行

help robotics.ros

在这里插入图片描述
这里的Matlab(rosinit)=ROS(roscore)。
在这里插入图片描述
尝试案例:

exampleHelperROSCreateSampleNetwork

在这里插入图片描述
至此,我们在Matlab有一个简单的认识,下面开始两者通信!

二者通信

确定IP

在Win中CMD键入

ipconfig

在Ubuntu中键入

ifconfig

获得两者IP

在Matlab中设置IP

在Matlab中键入

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

其中http://192.168.0.120是你Ubuntu地址。并进行下一步检测
在这里插入图片描述

ROS->Matlab

在ROS中启动一个talker,在matlab中接受。
在这里插入图片描述
在Matlab中用rostopic echo把talker中的发布的信息全都print出来。截取部分如下:
在这里插入图片描述

Matlab->ROS

写一个.m文件,以此作为Matlab数据发送的talker。

%Setting ROS_MASTER_URI
setenv('ROS_MASTER_URI','http://192.168.0.120:11311')

%Starting ROS MASTER
rosinit

%Creating ROS publisher handle
chatpub = rospublisher('/talker', 'std_msgs/String');

%This is to create the message definition
msg = rosmessage(chatpub);

%Inserting data to message
msg.Data = 'Hello, From Matlab!';

%Sending message to topic
send(chatpub,msg);

%Latching the message on topic
latchpub = rospublisher('/talker', 'IsLatching', true);

在这里插入图片描述
ROS如图,毕。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章