Main Content

Get Started with ROS

机器人操作系统(ROS)是一个通信界面,可实现机器人系统的不同部分互相发现,并在它们之间发送和接收数据。MATLAB®通万博1manbetx过功能库支持ROS,使您可以与ROS启用的物理机器人或机器人模拟器(例如Guazebo®)交换数据。

此示例介绍了如何:

  • Set up ROS within MATLAB

  • Get information about capabilities in a ROS network

  • 获取有关ROS消息的信息

ROS术语

  • 一个ROS network包括机器人系统的不同部分(例如计划器或摄像机界面),该部分通过ROS通信。该网络可以在几台计算机上分布。

  • 一个罗斯主人协调ROS网络的不同部分。它是由Master URI(Uniform Resource Identifier) that specifies the hostname or IP address of the machine where the master is running.

  • 一个ROS节点包含相关ROS功能的集合(例如发布者,订户和服务)。ROS网络可以具有许多ROS节点。

  • Publishers,,,,订户,,,,and服务are different kinds of ROS entities that process data. They exchange data using消息

  • 发布者将消息发送到特定topic(such as "odometry"), and subscribers to that topic receive those messages. A single topic can be associated with multiple publishers and subscribers.

For more information, seeRobot Operating System (ROS)概念ROS网站上的部分。

初始化ROS网络

Userosinit初始化ROS。默认,rosinit创建一个罗斯主人in MATLAB and starts a全局节点这与主人有关。全局节点由其他ROS函数自动使用。

rosinit
启动ROS Core ...在0.77356秒内完成。在http://172.29.207.151:57188​​初始化ROS Master。初始化带有Nodeuri的全局节点/Matlab_global_node_12045 http://dcc345885glnxa64:35297/and Masteruri http:// localhost:57188​​。

Use罗斯诺德列表to see all nodes in the ROS network. Note that the only available node is the global node created byrosinit

罗斯诺德列表
/matlab_global_node_12045

Use示例HelperroscreateSamplenetworkto populate the ROS network with three additional nodes and sample publishers and subscribers.

示例HelperroscreateSamplenetwork

Use罗斯诺德列表again to see the three new nodes (node_1,,,,node_2,,,,andnode_3)。

罗斯诺德列表
/matlab_global_node_12045 /node_1 /node_2 /node_3

这figure shows the current state of the ROS network. The MATLAB global node is disconnected since it currently does not have any publishers, subscribers or services.

话题

Userostopic列表to see available topics in the ROS network. There are four active topics:/pose,,,,/rosout,,,,/scanand/tf。默认主题:rosoutandTF始终存在于ROS网络中。其他两个主题是作为示例网络的一部分创建的。

rostopic列表
/姿势 /rosout /扫描 /TF

Userostopic信息to get specific information about a specific topic. The command below shows that/node_1发布消息(发送消息)/posetopic, and/node_2订阅(接收消息)到该主题。看Exchange Data with ROS Publishers and Subscribers了解更多信息。

rostopic信息/pose
Type: geometry_msgs/Twist Publishers: * /node_1 (http://dcc345885glnxa64:42939/) Subscribers: * /node_2 (http://dcc345885glnxa64:42477/)

Use罗斯诺德信息得到一个特定的节点的信息。command below shows thatnode_1发布到/pose,,,,/rosoutand/tftopics, subscribes to the/scantopic and provides services: /node_1/get_loggers and /node_1/set_logger_level. The default logging services: get_loggers and set_logger_level are provided by all the nodes created in ROS network.

罗斯诺德信息/node_1
节点:[ /node_1] uri:[http:// dcc345885glnxa64:42939 /]出版物(3个活动主题): * /pose * /rosout * /rosout * /tf订阅(1个活动主题):* /node_1 /get_loggers * /node_1 /set_logger_level

服务

ROS services provide a mechanism for procedure calls across the ROS network. A服务客户端sends a request message to a服务服务器,哪个处理请求中的信息并使用响应消息返回(请参阅Call and Provide ROS Services)。

UseRosservice列表to see all available service servers in the ROS network. The command below shows that two services (/添加and/回复)可与所有节点的默认记录器服务一起使用。

Rosservice列表
/添加/matlab_global_node_12045/get_loggers /matlab_global_node_12045/set_logger_level /node_1/get_loggers /node_1/set_logger_level /node_2/get_loggers /node_2/set_logger_level /node_3/get_loggers /node_3/set_logger_level /reply

UseRosservice信息获取有关特定服务的信息。

Rosservice信息/添加
节点:/node_3 uri:rosrpc:// dcc345885glnxa64:48307类型:roscpp_tutorials/twinters/tixints args:messageType a b

消息

Publishers, subscribers, and services use ROS messages to exchange information. Each ROS message has an associated消息类型that defines the datatypes and layout of information in that message (See使用基本的ROS消息)。

Userostopic类型查看主题使用的消息类型。下面的命令表明/pose主题使用类型的消息geometry_msgs/Twist

rostopic类型/pose
geometry_msgs/Twist

Userosmsg节目查看消息类型的属性。这geometry_msgs/Twist消息类型有两个属性,线性and一个ngular。每个属性都是类型的消息geometry_msgs/Vector3,又有三种类型的属性双倍的

rosmsg节目geometry_msgs/Twist
%这表达在损坏其线性和角度部分的自由空间中的速度。向量3线性矢量3角
rosmsg节目geometry_msgs/Vector3
% This represents a vector in free space. % It is only meant to represent a direction. Therefore, it does not % make sense to apply a translation to it (e.g., when applying a % generic rigid transformation to a Vector3, tf2 will only apply the % rotation). If you want your data to be translatable too, use the % geometry_msgs/Point message instead. double X double Y double Z

Userosmsg列表要查看MATLAB中可用的消息类型的完整列表。

关闭ROS网络

UseexampleHelperROSShutDownSampleNetwork从ROS网络中删除示例节点,发布者和订户。仅当使用示例helperrosstartsamplenetwork

exampleHelperROSShutDownSampleNetwork

UseRosshutdown关闭MATLAB中的ROS网络。这关闭了启动的ROS主人rosinitand deletes the global node. UsingRosshutdownis the recommended procedure once you are done working with the ROS network.

Rosshutdown
Shutting down global node /matlab_global_node_12045 with NodeURI http://dcc345885glnxa64:35297/ and MasterURI http://localhost:57188. Shutting down ROS master on http://172.29.207.151:57188.

下一步