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如圖,畢。