ROS 與 MATLAB 通信
2022-02-27 09:39 作者:永遠(yuǎn)的修伊 | 我要投稿
基本環(huán)境概述:
1、主機(jī) win10+MATLAB 2021b
2、虛擬機(jī) ubuntu 20.04 + ROS noetic
網(wǎng)絡(luò)通信


添加 export ROS_IP=192.168.230.129 到 .bashrc


在matlab下輸入命令
setenv('ROS_MASTER_URI','http://192.168.230.129:11311/')
%? 建立網(wǎng)絡(luò)通信
rosinit
% 啟動(dòng)內(nèi)核
rostopic list
rosnode list
% 測(cè)試連接

rosshutdown
% 關(guān)閉連接
同樣,可以在ubuntu系統(tǒng)里測(cè)試
roscore
rostopic list
rosnode list
%%%%% matlab 是 ros 的一個(gè) node

新建一個(gè)自動(dòng)化腳本,命名matlab2ros1.m
rosshutdown
setenv('ROS_MASTER_URI','http://192.168.230.129:11311/');
rosinit
for i = 1:10
cmdpub = rospublisher('/turtle1/cmd_vel',rostype.geometry_msgs_Twist);
cmdmsg = rosmessage(cmdpub);
pause(5), % ensure the publisher successfully
cmdmsg.Linear.X = 8;
cmdmsg.Angular.Z = 8;
send(cmdpub,cmdmsg)
end

標(biāo)簽: