你是否一直纠结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都有)
安装参考 ubuntu14.04 matlab2015 64bits
二. 简单使用说明
起始你按照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]
>> 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, 不用时是要手动敲指令清理关闭的。
三. 其它强大功能的应用参看相应的函数说明。
你也赶紧去尝试下吧。
基本命令函数
rosinit | Connect to ROS network |
rosmsg | Retrieve information about ROS messages and message types |
rosnode | Retrieve information about ROS network nodes |
rosparam | Access ROS parameter server values |
rosservice | Retrieve information about services in ROS network |
rosshutdown | Shut down ROS system |
rostopic | Retrieve information about ROS topics |
get | Get ROS parameter value |
has | Check if ROS parameter name exists |
search | Search ROS network for parameter names |
set | Set value of ROS parameter; add new parameter |
del | Delete a ROS parameter |
Using Core Objects | Create ROS Core |
Using Node Objects | Start ROS node and connect to ROS master |
Using ParameterTree Objects | Access ROS parameter server |
rosmessage | Create ROS messages |
rosmsg | Retrieve information about ROS messages and message types |
definition | Retrieve definition of ROS message type |
showdetails | Display all ROS message contents |
rostopic | Retrieve information about ROS topics |
rostype | Access available ROS message types |
rospublisher | Publish messages on a topic |
rossubscriber | Subscribe to messages on a topic |
receive | Wait for new ROS message |
send | Publish ROS message to topic |
call | Call the ROS service server and receive a response |
rosservice | Retrieve information about services in ROS network |
rossvcclient | Create ROS service client |
rossvcserver | Create ROS service server |
Using Publisher Objects | Create ROS publisher |
Using Subscriber Objects | Create a ROS subscriber |
Using ServiceServer Objects | Create ROS service server |
Using ServiceClient Objects | Connect to ROS service server |
robotics.Rate | Execute loop at fixed frequency |
rosbag | Open and parse rosbag log file |
readMessages | Read messages from rosbag |
select | Select subset of messages in rosbag |
timeseries | Creates a time series object for selected message properties |
rostime | Access ROS time functionality |
rostf | Access ROS transformations |
apply | Transform message entities into target frame |
transform | Transform message entities into target coordinate frame |
waitForTransform | Wait until a transformation is available |
getTransform | Retrieve the transformation between two coordinate frames |
sendTransform | Send transformation to ROS network |
Using BagSelection Objects | Create rosbag selection |
Using TransformationTree Objects | Receive, send, and apply ROS transformations |
Using TransformStamped Objects | Create transformation message |
readBinaryOccupancyGrid | Read binary occupancy grid |
writeBinaryOccupancyGrid | Write values from grid to ROS message |
readImage | Convert ROS image data into MATLAB image |
writeImage | Write MATLAB image to ROS image message |
readCartesian | Read laser scan ranges in Cartesian coordinates |
readScanAngles | Return scan angles for laser scan range readings |
plot | Display ROS laser scan messages on custom plot |
readXYZ | Extract XYZ coordinates from point cloud data |
readRGB | Extract RGB values from point cloud data |
readAllFieldNames | Get all available field names from ROS point cloud |
readField | Read point cloud data based on field name |
scatter3 | Display point cloud in scatter plot |
Using CompressedImage Objects | Create compressed image message |
Using Image Objects | Create image message |
Using LaserScan Objects | Create laser scan message |
Using OccupancyGrid Objects | Create occupancy grid message |
Using PointCloud2 Objects | Access point cloud messages |
roboticsAddons | Install add-ons for robotics |
rosgenmsg | 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