ifconfig #enp3s0 --看ip
sudo ~/.bashrc #修改文件
export ROS_IP=192.168.1.101 #添加本机ip
roscore #新开终端启动
rosrun turtlesim turtlesim_node #打开一个实例
在同机上打开matlab:
setenv('ROS_MASTER_URI','http://192.168.1.101:11311')#主节点ip
setenv('ROS_IP','192.168.1.101') #若另外一台机器上的matlab则要独自iP,需要改为另外台机ip,比如setenv('ROS_IP','192.168.1.102')
matlab上开启节点:
rosinit
测试:
rostopic list
rostopic echo /turtle1/pose
控制ROS例子的matlab代码:test.m
cmdpub = rospublisher('/turtle1/cmd_vel',rostype.geometry_msgs_Twist)
pause(3) % Wait to ensure publisher is setup
cmdmsg = rosmessage(cmdpub);
cmdmsg.Linear.X = 10;
cmdmsg.Angular.Z = 15;
send(cmdpub,cmdmsg)
chatterpub = rospublisher('/chatter',rostype.std_msgs_String)
pause(3) % Wait to ensure publisher is setup
chattermsg = rosmessage(chatterpub);
chattermsg.Data = 'hello world'
send(chatterpub,chattermsg)
pause(5)
运行,即可。
参考:点击打开链接