连接到Simulink®的ROS-ENABLE机器人金宝app
you can use Simulink to connect to a ROS-enabled physical robot or to a ROS-enabled robot simulator such as凉亭。This example shows how to configure Simulink to connect to a separate robot simulator using ROS. It then shows how to send velocity commands and receive position information from a simulated robot.
您可以按照示例中的步骤来创建自己的模型,也可以使用此完成版本反而。
open_system('robotROSConnectToRobotExample');
先决条件:Get Started with ROS,,,,Exchange Data with ROS Publishers and Subscribers,,,,开始使用Simulink的ROS金宝app。
机器人模拟器
启动基于ROS的模拟器,用于差分驱动机器人。模拟器接收并发送有关以下主题的消息:
发送
nav_msgs/Odometry
消息给/odom
至picReceives
geometry_msgs/Twist
速度命令消息 /Mobile_base/命令
or/cmd_vel
主题,基于基于ROS的模拟器
您可以选择设置基于ROS的模拟器的两个选项之一。
选项A:MATLAB®中的模拟器
Use a simple MATLAB-based simulator to plot the current location of the robot in a separate figure window.
进入
rosinit
在MATLAB命令行。这会创建本地罗斯主人with network address (URI) ofhttp:// localhost:11311
。进入
示例Helpersimul金宝appinkrobotros
至start the Robot Simulator:
笔记:这
geometry_msgs/Twist
速度命令消息在 /Mobile_base/命令/速度
话题。
Option B: Gazebo Simulator
在凉亭中使用模拟Turtlebot®。
看在凉亭中添加,构建和删除对象有关设置凉亭环境的说明。在虚拟机中的Ubuntu®桌面中,单击“凉亭空”图标。
Note the network address (URI) of the ROS master. It will look like
http://192.168.84.128:11311
,,,,but with your specific IP address.通过键入核对环境,验证凉亭环境是否正确设置
rostopic
列表
in the Ubuntu terminal window. You should see a list of topics, including/cmd_vel
and/odom
。笔记:这
geometry_msgs/Twist
速度命令消息在 /cmd_vel topic.
配置Simulink金宝app以连接到ROS网络
1。来自Simulation选项卡,选择ROS工具箱>ROS网络。
2。在里面ROS Master(ROS 1)部分,选择Custom
from the网络地址dropdown.
Option A (MATLAB Simulator): Ensure that the主机名/IP地址is set to
localhost
,,,,and港口is set to11311
。Option B (Gazebo Simulator): Specify the IP address and port number of the ROS master in Gazebo. For example, if it is
http://192.168.60.165:11311
,然后输入192.168.60.165
in the主机名/IP地址盒子和11311
in the港口box.
Send Velocity Commands To the Robot
创建一个将控制命令(线性和角速度)发送到模拟器的发布者。通过使用这些速度可调节Slider Gainblocks.
ROS使用右手坐标系,因此X轴向前,Y轴剩下,Z轴向上。控制命令是使用geometry_msgs/Twist
消息,哪里线性。X
表示线性向前速度(以m/s为单位),并且Angular.Z
indicates angular velocity around the Z-axis (in rad/s).
Configure a Publisher Block
Open a new Simulink model.
来自ROS工具箱>ROS库浏览器中的标签,拖动Publish块到模型。双击块。
放Topic sourcefield to选择From ROS network。根据模拟器选择一个主题,如下所示。
选项A(MATLAB模拟器):单击选择旁边Topic, 选择
/Mobile_base/命令/速度
,然后单击OK。请注意消息类型(geometry_msgs/Twist
) is set automatically.Option B (Gazebo Simulator): Click选择旁边Topic, 选择
/cmd_vel
,然后单击OK。请注意消息类型(geometry_msgs/Twist
) is set automatically.
配置消息块
来自ROS工具箱>ROS库浏览器中的选项卡,丢弃一个空白消息块到模型。双击块。
点击选择旁边消息类型并选择
geometry_msgs/Twist
。放采样时间至
0.01
然后单击OK。
Configure Message Inputs
来自金宝app>Signal Routing库浏览器中的标签,拖动巴士分配块到模型。
连接
Msg
output of the空白消息块到达公共汽车
输入巴士分配街区和公共汽车
output to theMsg
输入Publish堵塞。来自造型选项卡,单击Update Model确保公交信息正确传播。如果出现在输入总线信号中,则忽略“总线分配块”中的“选定信号'Signal1'”,如果出现在输入总线信号中”。下一步将解决此错误。
双击巴士分配堵塞。选择
???
信号1
在右图框中,单击消除。在里面left list box, expand both Linear and Angular properties. Select线性>XandAngular>z然后单击选择。点击OK关闭块面膜。
Add aConstantblock, aGainblock, and twoSlider Gainblocks. Connect them together as shown in the figure, and set theGain价值为
-1。
将线性速度滑块的限制和当前参数设置为
0.0
至2。0
,,,,and1。0
分别。将转向增益滑块的相应参数设置为-1.0
至1。0
,,,,and0.1
。
从机器人接收位置信息
Create a subscriber to receive messages sent to the/odom
话题。提取机器人的位置并在xy平面中绘制其路径。
Configure a Subscriber block
来自ROS工具箱>ROS库浏览器中的标签,拖动订阅块到模型。双击块。
放Topic source至选择From ROS network,然后单击选择旁边theTopicbox. Select "/odom" for the topic and clickOK。请注意消息类型
nav_msgs/Odometry
is set automatically.
读取消息输出
来自金宝app>Signal Routing库浏览器中的标签,拖动总线选择器块到模型。
连接output port of the订阅块到达input port of the总线选择器堵塞。在里面造型选项卡,单击Update Model确保公交信息正确传播。
双击总线选择器堵塞。选择
???
信号1
and???
信号2
在右图框中,单击消除。在左列表框中,展开姿势>姿势>位置并选择Xandy。点击选择接着OK。来自金宝app>水槽库浏览器中的标签,拖动nXyGraph块到模型。连接
X
andy
输出端口总线选择器块到输入端口XyGraph堵塞。
This figure shows the completed model. A预配置模型为了方便起见。
笔记:出版商block in this model uses the
/Mobile_base/命令/速度
至pic for use with MATLAB simulator option. For Gazebo simulator option, select the/cmd_vel
至pic as shown以上。
配置并运行模型
来自造型选项卡,单击模型设置。在里面Solver窗格,设置Type至固定步骤and固定步骤的大小至
0.01
。放simulation Stop time to
Inf
。点击跑至start the simulation.
在模拟器和XY图中,您应该看到机器人在圆圈中移动。
在模拟运行时,请更改Slider Gainblocks to control the robot. Double-click theXyGraphblock and change the
X
andy
如果需要,轴线限制。(您可以在模拟运行时执行此操作。)要停止模拟,请单击停止。