打开虚拟机---打开一个终端---输入:roscore;
运行turtle的来作为实例:rosrun turtlesim turtlesim_node
windows下的MATLAB端,为避免有rosmaster运行,先输入:rosshutdown,
再输入:rosinit('192.168.244.129') %虚拟机IP,在虚拟机终端输入:ifconfig可查。
MATLAB中查看rostopic list(输入rostopic list即可),查看topic数据类型等信息如:
rostopic info /turtle1/cmd_vel
MATLAB代码控制虚拟机机器人运动:(直接在MATLAB命令窗口复制粘贴运行)
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)