赞
踩
你是否一直纠结ros程序的单步调试呢?你是否一直纠结ros中的具体数据流呢?虽然单个ros Node 也可以进行单步调试,但多节点,roslaunch时就抓瞎了,
你是否也纠结ros是否也该将数据分析的可视化工具丰富下? 不要纠结,试试matlab 与ros 协调吧, 虽然也不是那么完美, 但ros的平台运行加上matlab强大的
数据处理,可视化绘图相结合,只要你充分合理的使用,相应一定能助你一臂之力。
一年前就听说matlab 有支持ros了,一直搁置没去实际尝试。最近由于调试ros程序需要,感觉matlab可以让我查看算法过程中的数据,与可视化的数据分
析更加方便,便开始了尝试。简单记录写下这篇入门指导。
一 . 入门级官方指导资料
ROS wiki http://wiki.ros.org/
matlab:Robotics System Toolbox : ROS http://cn.mathworks.com/help/robotics/robot-operating-system-ros.html
Document http://cn.mathworks.com/help/robotics/functionlist.html#buog82z
说明: matlab 只有在2015b的版本及以上才带机器人工具箱和ROS 。 软件请自行网上搜索(windows/mac/unix都有)
二. 简单使用说明
起始你按照matlab的指导一步步来就OK了。现就简单提提自己对理解上变化大点的谈下自己的感受。
1. 启动master的问题
直接在matlab终端输入:
>> rosinit
The value of the ROS_MASTER_URI environment variable, http://localhost:11311, will be used to connect to the ROS master.
Initializing ROS master on http://yhzhao:11311/.
Initializing global node /matlab_global_node_60577 with NodeURI http://yhzhao:36745/
它会启动一个master与一个global node . 这时如果你在ubuntu的终端启动roscore 就会有问题。提示已经有一个master启动了。
>> rostopic list
/rosout
如果你是在ubuntu终端先启动roscore ,再在matlab 终端启动rosinit. 就会连接rosmaster,并新创建一个global node.
>> rosinit
The value of the ROS_MASTER_URI environment variable, http://localhost:11311, will be used to connect to the ROS master.
Initializing global node /matlab_global_node_21319 with NodeURI http://yhzhao:56287/
若不在同一个IP。 可以分布式启动新节点,连接 master ip为10.0.253.95 。
>> rosinit('10.0.253.95')
Initializing global node /matlab_global_node_42437 with NodeURI http://10.0.253.95:52610/
2. 关闭master的问题
rosshutdown
3. 读取消息的简单操作:拿gazebo仿真来看。
3.1 ubuntu终端启动roscore 与gazebo
roslaunch turtlebot_gazebo gmapping_world.launch
3.2 在matlab 中启动ros
>> rosinit
The value of the ROS_MASTER_URI environment variable, http://localhost:11311, will be used to connect to the ROS master.
Initializing global node /matlab_global_node_26095 with NodeURI http://yhzhao:45774/
3.3 利用matlab 查看 topic的信息。
>>rostopic list
/clock
/cmd_vel_mux/active
/cmd_vel_mux/input/navi
/cmd_vel_mux/input/safety_controller
/cmd_vel_mux/input/teleop
/cmd_vel_mux/parameter_descriptions
/cmd_vel_mux/parameter_updates
/depthimage_to_laserscan/parameter_descriptions
/depthimage_to_laserscan/parameter_updates
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/joint_states
/laserscan_nodelet_manager/bond
/mobile_base/commands/motor_power
/mobile_base/commands/reset_odometry
/mobile_base/commands/velocity
/mobile_base/events/bumper
/mobile_base/events/cliff
/mobile_base/sensors/bumper_pointcloud
/mobile_base/sensors/core
/mobile_base/sensors/imu_data
/mobile_base_nodelet_manager/bond
/odom
/rosout
/rosout_agg
/scan
/tf
/tf_static
3.4 利用matlab 订阅topic 并用matlab显示
>> sub = rossubscriber('scan') %订阅
sub =
Subscriber with properties:
TopicName: '/scan'
MessageType: 'sensor_msgs/LaserScan'
LatestMessage: [0x1 LaserScan]
BufferSize: 1
NewMessageFcn: []
>> msg = receive(sub) %接收
msg =
ROS LaserScan message with properties:
MessageType: 'sensor_msgs/LaserScan'
Header: [1x1 Header]
AngleMin: -3.1416
AngleMax: 3.1416
AngleIncrement: 0.0175
TimeIncrement: 0
ScanTime: 0
RangeMin: 0.1000
RangeMax: 6
Ranges: [360x1 single]
Intensities: [360x1 single]
3.5 matlab 显示 laser
>> plot(msg)
3.6 以后像costMap 可以曲面的方式显示。
3.7 …… 还有很多等你去开发
4. 指令性操作指令与函数式操作
拿topic举个栗子。
rostopic list
rostopic echo topicname
rostopic info topicname
rostopic type topicname
topiclist = rostopic('list')
msg = rostopic('echo', topicname)
topicinfo = rostopic('info', topicname)
msgtype = rostopic('type', topicname)
5. 数据结构对应 matlab 的数据结构操作与 cell的操作。
>> msg.RangeMax
ans =
6
cell操作见bag。
6. rosbag数据读取感觉很必要,matlab单帧读bag成为了可能。 单帧运行对应这单步调试啊。
bag = rosbag(filename)
scanSelect = selesct(bag,'topic','/scan')
scanVector = readMessages(scanSelect)
scanData = scanVector{1,1}.RangeMax % cell 操作
想想以后可以matlab 自己写程序跑rosbag包,是不是爽一些。
7. matlab中你启动的节点与master, 不用时是要手动敲指令清理关闭的。
三. 其它强大功能的应用参看相应的函数说明。
你也赶紧去尝试下吧。
基本命令函数
Network Connection and Exploration
Connect to ROS network
Retrieve information about ROS messages and message types
Retrieve information about ROS network nodes
Access ROS parameter server values
Retrieve information about services in ROS network
Shut down ROS system
Retrieve information about ROS topics
Get ROS parameter value
Check if ROS parameter name exists
Search ROS network for parameter names
Set value of ROS parameter; add new parameter
Delete a ROS parameter
Start ROS node and connect to ROS master
Access ROS parameter server
Publishers, Subscribers, and Services
Create ROS messages
Retrieve information about ROS messages and message types
Retrieve definition of ROS message type
Display all ROS message contents
Retrieve information about ROS topics
Access available ROS message types
Publish messages on a topic
Subscribe to messages on a topic
Wait for new ROS message
Publish ROS message to topic
Call the ROS service server and receive a response
Retrieve information about services in ROS network
Create ROS service client
Create ROS service server
Connect to ROS service server
Execute loop at fixed frequency
Log Files and Transformations
Open and parse rosbag log file
Read messages from rosbag
Select subset of messages in rosbag
Creates a time series object for selected message properties
Access ROS time functionality
Access ROS transformations
Transform message entities into target frame
Transform message entities into target coordinate frame
Wait until a transformation is available
Retrieve the transformation between two coordinate frames
Send transformation to ROS network
Receive, send, and apply ROS transformations
Specialized Messages
Read binary occupancy grid
Write values from grid to ROS message
Convert ROS image data into MATLAB image
Write MATLAB image to ROS image message
Read laser scan ranges in Cartesian coordinates
Return scan angles for laser scan range readings
Display ROS laser scan messages on custom plot
Extract XYZ coordinates from point cloud data
Extract RGB values from point cloud data
Get all available field names from ROS point cloud
Read point cloud data based on field name
Display point cloud in scatter plot
Create compressed image message
Create image message
Create laser scan message
Create occupancy grid message
Access point cloud messages
Custom Message Support
Install add-ons for robotics
Generate custom messages from ROS definitions
参考: http://cn.mathworks.com/help/robotics/functionlist.html#buog82z
http://cn.mathworks.com/help/robotics/robot-operating-system-ros.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。