Main Content

连接到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至pic

  • Receivesgeometry_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 likehttp://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_veland/odom

  • 笔记:geometry_msgs/Twist速度命令消息在 /cmd_vel topic.

配置Simulink金宝app以连接到ROS网络

1。来自Simulation选项卡,选择ROS工具箱>ROS网络

2。在里面ROS Master(ROS 1)部分,选择Customfrom the网络地址dropdown.

  • Option A (MATLAB Simulator): Ensure that the主机名/IP地址is set tolocalhost,,,,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 ishttp://192.168.60.165:11311,然后输入192.168.60.165in the主机名/IP地址盒子和11311in the港口box.

Send Velocity Commands To the Robot

创建一个将控制命令(线性和角速度)发送到模拟器的发布者。通过使用这些速度可调节Slider Gainblocks.

ROS使用右手坐标系,因此X轴向前,Y轴剩下,Z轴向上。控制命令是使用geometry_msgs/Twist消息,哪里线性。X表示线性向前速度(以m/s为单位),并且Angular.Zindicates angular velocity around the Z-axis (in rad/s).

Configure a Publisher Block

  1. Open a new Simulink model.

  2. 来自ROS工具箱>ROS库浏览器中的标签,拖动Publish块到模型。双击块。

  3. 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.

配置消息块

  1. 来自ROS工具箱>ROS库浏览器中的选项卡,丢弃一个空白消息块到模型。双击块。

  2. 点击选择旁边消息类型并选择geometry_msgs/Twist

  3. 采样时间0.01然后单击OK

Configure Message Inputs

  1. 来自金宝app>Signal Routing库浏览器中的标签,拖动巴士分配块到模型。

  2. 连接Msgoutput of the空白消息块到达公共汽车输入巴士分配街区和公共汽车output to theMsg输入Publish堵塞。

  3. 来自造型选项卡,单击Update Model确保公交信息正确传播。如果出现在输入总线信号中,则忽略“总线分配块”中的“选定信号'Signal1'”,如果出现在输入总线信号中”。下一步将解决此错误。

  4. 双击巴士分配堵塞。选择???信号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.02。0,,,,and1。0分别。将转向增益滑块的相应参数设置为-1.01。0,,,,and0.1

从机器人接收位置信息

Create a subscriber to receive messages sent to the/odom话题。提取机器人的位置并在xy平面中绘制其路径。

Configure a Subscriber block

  1. 来自ROS工具箱>ROS库浏览器中的标签,拖动订阅块到模型。双击块。

  2. Topic source选择From ROS network,然后单击选择旁边theTopicbox. Select "/odom" for the topic and clickOK。请注意消息类型nav_msgs/Odometryis set automatically.

读取消息输出

  1. 来自金宝app>Signal Routing库浏览器中的标签,拖动总线选择器块到模型。

  2. 连接output port of the订阅块到达input port of the总线选择器堵塞。在里面造型选项卡,单击Update Model确保公交信息正确传播。

  3. 双击总线选择器堵塞。选择???信号1and???信号2在右图框中,单击消除。在左列表框中,展开姿势>姿势>位置并选择Xandy。点击选择接着OK

  4. 来自金宝app>水槽库浏览器中的标签,拖动nXyGraph块到模型。连接Xandy输出端口总线选择器块到输入端口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以上

配置并运行模型

  1. 来自造型选项卡,单击模型设置。在里面Solver窗格,设置Type固定步骤and固定步骤的大小0.01

  2. 放simulation Stop time toInf

  3. 点击至start the simulation.

  4. 在模拟器和XY图中,您应该看到机器人在圆圈中移动。

  5. 在模拟运行时,请更改Slider Gainblocks to control the robot. Double-click theXyGraphblock and change theXandy如果需要,轴线限制。(您可以在模拟运行时执行此操作。)

  6. 要停止模拟,请单击停止