COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊
-
Upload
po-jen-lai -
Category
Technology
-
view
3.519 -
download
8
Transcript of COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊
ROS + Gazebo 機器人模擬器工作坊
Presenter: 賴柏任
https://www.facebook.com/PoJenLai
08.20.2016
Brought to you by COSCUP 2016
Who am I
• 大學時有幸透過專題接觸 ROS,並陸續發表一些 ROS 的介紹文章
https://pojenlai.wordpress.com/
• 研究所的論文內容也是用 ROS 來開發
https://github.com/Po-Jen/transparent_objects/tree/addedfeature
• 工作閒暇之餘希望可以持續學習、也提供更多資源給大家
http://blog.techbridge.cc/
http://weekly.techbridge.cc/2
Who am I
• 順便推薦一下 ROS.Taipei 社群
https://www.facebook.com/groups/122728288090359/
3
Outline
• ROS Introduction
• ROS Basic Mechanism
• ROS Tool Overview
• Gazebo Introduction
• Gazebo Usage
• Navigation & SLAM
4
ROS Introduction
5
What is ROS ?
6
http://answers.ros.org/question/12230/what-is-ros-exactly-middleware-framework-operating-system/#18055
• ROS is acronym for Robot OS, but it is not a traditional OS like Windows, Ubuntu or Mac OS
What is ROS ?
7
• Before we move on, we should clarify something
• Robot software = Distributed computing system
Decision Maker
Object Recognition
Object GraspingNavigation
What is ROS ?
8
• ROS is a set of tools which enables– Easy construction of distributed computing systems
(Programs can be individually designed and easily connected at runtime)
– Code reuse
– Configuring, starting, introspecting, debugging, visualizing, logging, testing, and stopping distributed computing systems
Why is ROS preferred ?
9
• It encourages users not to reinvent the wheel
Why is ROS preferred ?
10
• Many open-sourced libraries
– SLAM (OpenSLAM)
– Real-time control(OROCOS)
– Path Planning (Openrave)
– Vision (OpenCV, PCL)
– 3D Simulator (Gazebo)
– 3D Visualizer (Rviz)
Why is ROS preferred ?
11
• Package can be written in multiple programming languages
– C++
– Python
– Lisp
• And many more experimental support
– C#, Go, Haskell, Java, Node.js, Lua, R, Ruby
– http://wiki.ros.org/Client%20Libraries
Can ROS be used on different robot?
12
• Of course!
• Check all robots using ROS - http://wiki.ros.org/Robots
https://vimeo.com/146183080
ROS Basic Mechanism & Tool
13
建立ROS workspace
• 建立一個空的環境並編譯
– $ mkdir -p ~/catkin_ws/src
– $ cd ~/catkin_ws/src
– $ catkin_init_workspace
– $ cd ~/catkin_ws
– $ catkin_make
14
File System
• Basic unit - package
– CMakeLists.txt
– package.xml
• ROS package 使用catkin 這工具來進行編譯
– 按照 ROS 規定的格式寫code,就可以用catkin編譯
15
rosbuild v.s. catkin
• rosbuild
– ROS Groovy之前的編譯系統
– 有部分package仍未porting到catkin上,故仍需略懂
– 所有原始碼和編譯後的檔案都在同一資料夾下
• Catkin
– ROS Groovy之後的編譯系統
– 原始碼和編譯後的檔案分離
• 接著直接來寫個node看看怎麼編譯
16
ROS Node
• Basic unit of program
17
Decision Maker
Object Recognition
Object GraspingNavigation
Node 1
Node 2 Node 3 Node 4
讓我們開始實作
• 你們需要的code應該都在這了
– https://github.com/Po-Jen/coscup2016-ROS-workshop
18
Create our first package & write a node
• 步驟先全部列在這,接著讓我們一步步來做– cd ~/catkin_ws/src
catkin_create_pkg coscup_1_node rospycd coscup_1_nodevim src/node.pychmod +x src/node.pycd ../..catkin_makesource devel/setup.bashroscorerosrun coscup_1_node node.pyrqt_graph
19
ROS Master
• How do node knows each other? => ROS Master
• Control the graph of nodes
20
rqt_graph
• Visualization of nodes and topics
• Part of rqt (integrates lots of debugging tools)
21
How do ROS node communicate?
• ROS master as a message hub?
– What if there are many nodes?
22
How do ROS node communicate?
• Let nodes communicates with each other directly
– Topic, Service, ActionLib
• If ROS does not exists
– Socket
– Shared memory
– We have to take care of these tedious work.
23
ROS Topic
• Publisher/Subscriber mechanism (topic == bucket)
24
Perception
ObjectRecognition
Semantic Map
Camera data
Recognition result
rostopic• 寫一個publisher (一直丟字串到topic_name這個topic)
– catkin_create_pkg coscup_2_topic rospy std_msgscd coscup_2_topicvim src/publisher.pychmod +x src/publisher.pycd ../..catkin_makesource devel/setup.bashroscorerosrun coscup_2_topic publisher.pyrqt_graphrostopic echo topic_namerostopic listrostopic list | grep topic
25
rqt_graph
• Now, it should looks like
26
rostopic
• 寫一個subscriber (從topic_name這個topic取出data)– cd ~/catkin_ws/src
cd coscup_2_topicvim src/subscriber.pychmod +x src/subscriber.pyrosrun coscup_2_node subscriber.pyrqt
27
rqt_graph
• Now, it should looks like
28
rqt
• We can try console
29
Define our own msg for topic
• 創建一個只有一個int的msg– cd ~/catkin_ws/src
cd coscup_2_topicmkdir msgvim msg/Num.msgvim package.xmlvim CMakeLists.txtcd ../..catkin_makesource devel/setup.bashrosmsg show coscup_2_topic/Num
30
package.xml
• Add build dependency and run dependency
31
CMakeLists.txt (1)
• Add package dependency
• Or you can
– catkin_create_pkg coscup_2_topic rospy std_msgsmessage_generation
32
CMakeLists.txt (2)
• Add build dependency
• Add msg file
• We use std_msgs/int64 in our msg file
33
Publish自己寫的msg
• 步驟– cd ~/catkin_ws/src/coscup_2_topic/
vim src/my_msg_publisher.py
chmod +x src/my_msg_publisher.py
rosrun coscup_2_topic my_msg_publisher.py
rostopic echo my_msg_topic_name
34
One more example
• geometry_msgs/Twist
35
One more example
• geometry_msgs/Vector3
36
How is the abstraction implemented?
37
/cmd_veltopic
Base Controller
Motor Speed
geometry_msgs/Twist
將速度和角速度轉成馬達命令
ROS Service
• Query/Response Style
38
Object Recognition
Brain
1 query 2 response
ROS Service
• 建立一個自己的srv格式– cd ~/catkin_ws/src
catkin_create_pkg coscup_3_service rospy std_msgscd coscup_3_servicemkdir srvvim srv/AddTwoInts.srvvim package.xmlvim CMakeLists.txtcd ../..catkin_makesource devel/setup.bashrossrv show coscup_3_service/AddTwoInts
39
package.xml
• Add build dependency and run dependency
40
CMakeLists.txt
• Add service file
• Add std_msgs dependency
41
ROS Service
• 寫一個server
– cd coscup_3_servicevim src/add_two_ints_server.pycd ../..source devel/setup.bashchmod +x src/add_two_ints_server.py rosrun coscup_3_service add_two_ints_server.py
42
ROS Service
• 寫一個client,送出request給server
– cd coscup_3_servicevim src/add_two_ints_client.pychmod +x src/add_two_ints_client.pyrun coscup_3_service add_two_ints_client.py 5 6
43
Rviz
• An important tool for data visualization
• 先啟動你們的Rviz– $ sudo apt-get install ros-indigo-rviz-*
– $ roscore
– $ rviz
• Will be revisited when we use Gazebo
44
Find out more on ROS Cheat Sheet
• https://github.com/ros/cheatsheet45
Gazebo Introduction
46
What is Gazebo ?
• 3D物理模擬器
–機器人控制
–環境模擬
–物體物理特性模擬
• 用途廣泛
–DARPA Challenge也是用Gazebo來開發
47
看個影片就有概念了
• https://www.youtube.com/watch?v=_8AhNWKzv2k
48
Gazebo Usage
49
Started Gazebo
• 先確保該安裝的東西都有被安裝– $ sudo apt-get install ros-indigo-gazebo-*
– $ sudo apt-get install ros-indigo-pr2-*
• 啟動Gazebo– $ gazebo
• 加入一些模型並存成world file
50
Play around with Rviz
51
SLAM & Navigation
52
先來個 SLAM 的 DEMO
• Gazebo 開啟 PR2 進行 SLAM
53
讓我們來實際操作
• Gazebo 開啟 PR2 進行 SLAM– $ roslaunch pr2_gazebo pr2_empty_world.launch
– $ 加入自己喜歡的模型
– $ roslaunch pr2_build_map.launch
– $ rviz
– $ roslaunch pr2_teleop teleop_keyboard.launch
– $ rosrun map_server map_saver
54
SLAM 演算法簡介
• gmapping package (grid mapping)
http://wiki.ros.org/gmapping
• Grid map–Map is presented by 2D array
– Each grid• 0: free
• 1: occupied
55
Map representation
56
Map representation
• Given sensor data zt and the poses of the sensor xt, estimate the map
• 推導就不細講了– http://ais.informatik.uni-
freiburg.de/teaching/ws12/mapping/pdf/slam11-gridmaps-4.pdf
57
Resources you can leverage
• ROS wiki
http://wiki.ros.org/
• ROS Answers
http://answers.ros.org/questions/
• Gazebo Answers
http://answers.gazebosim.org/questions/
• ROS Taipei 中文資源整理
https://hackpad.com/-ROS-Blog--lnDeWhHXH4T
58
ROS 2.0
• 欲改進的點
– 多機器人協作 (ROS 1.0是for PR2開發的)
– 嵌入式平台開發 (不必再透過一層額外driver)
– real-time系統 (能有更精準的控制能力)
– 適用於產品開發 (原本偏向學術研究用)
– 設計模式的建立
59
ROS 2.0 學習資源
• Official website
– http://design.ros2.org/
• ROS 2.0 中文翻譯( under construction…)
– http://po-jen.github.io/design/
• Tutorials from Erle-Robotics
– http://erlerobotics.com/docs/Robot_Operating_System/ROS_2/Tutorials/index.html
60
Thanks for joining, you guys rock!
61
Appendix I如何使用第三方提供的
package
62
Example - ros_caffe
• Github page
– https://github.com/tzutalin/ros_caffe
• Tutorial
– http://www.artificialhumancompanions.com/integrating-ros-caffe-opencv-on-the-autonomous-deep-learning-robot/
• 使用topic_tools轉換Gazebo的PR2的topic name– rosrun topic_tools relay /wide_stereo/left/image_raw
/camera/rgb/image_raw
63