版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16481211/article/details/82841788
Matlab的机器人工具箱提供了ROS模拟器,我们可以在上面设置ROS并获取ROS的相关信息。
初始化ROS网络节点
使用rosinit初始化ROS。默认情况下在Matlab中创建ROS主机并且启动连接到主机的全局节点。
>> rosinit
Initializing ROS master on http://DESKTOP-AKNUDCB:11311/.
Initializing global node /matlab_global_node_68516 with NodeURI http://DESKTOP-AKNUDCB:18475/
我们可以使用rosnode list来查看所有的节点。
>> rosnode list
/matlab_global_node_68516
使用exampleHelperROSCreateSampleNetwork在ROS网络中添加三个节点。
>> exampleHelperROSCreateSampleNetwork
>> rosnode list
/matlab_global_node_68516
/node_1
/node_2
/node_3
ROS话题
查看当前的话题
rosout是一个默认的日志话题。
>> rostopic list
/pose
/rosout
/scan
使用rostopic info来获取关于一个专门话题的信息。
下面的意思是/node_1发布/pose话题,/node_2订阅/pose话题。
>> rostopic info /pose
Type: geometry_msgs/Twist
Publishers:
* /node_1 (http://DESKTOP-AKNUDCB:18541/)
Subscribers:
* /node_2 (http://DESKTOP-AKNUDCB:18552/)
查看关于/node_1的话题
>> rosnode info /node_1
Node: [/node_1]
URI: [http://DESKTOP-AKNUDCB:18541/]
Publications (2 Active Topics):
* /pose
* /rosout
Subscriptions (1 Active Topics):
* /scan
Services (0 Active):
服务services
>> rosservice list
/add
/reply
>> rosservice info /add
Node: /node_3
URI: rosrpc://DESKTOP-AKNUDCB:18577/
Type: roscpp_tutorials/TwoInts
Args: A B
消息Messages
发布节点和订阅节点使用ros messages来交换信息,每条ROS消息都有一个关联的消息类型,用于定义该消息中的数据类型和布局。
>> rostopic type /pose
geometry_msgs/Twist
>> rosmsg show geometry_msgs/Twist
% This expresses velocity in free space broken into its Linear and Angular parts.
Vector3 Linear
Vector3 Angular
>> rosmsg show geometry_msgs/Vector3
% This represents a vector in free space.
double X
double Y
double Z
关闭ROS Network
从ROS网络中删除示例节点
>>exampleHelperROSShutDownSampleNetwork
在MATLAB中关闭ROS网络
>> rosshutdown
Shutting down global node /matlab_global_node_68516 with NodeURI http://DESKTOP-AKNUDCB:18475/
Shutting down ROS master on http://DESKTOP-AKNUDCB:11311/.