coscup 2016 - ros + gazebo機器人模擬器工作坊

63
ROS + Gazebo 機器人模擬器 工作坊 Presenter: 賴柏任 https://www.facebook.com/PoJenLai 08.20.2016 Brought to you by COSCUP 2016

Upload: po-jen-lai

Post on 23-Feb-2017

3.518 views

Category:

Technology


8 download

TRANSCRIPT

Page 1: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS + Gazebo 機器人模擬器工作坊

Presenter: 賴柏任

https://www.facebook.com/PoJenLai

08.20.2016

Brought to you by COSCUP 2016

Page 2: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 3: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Who am I

• 順便推薦一下 ROS.Taipei 社群

https://www.facebook.com/groups/122728288090359/

3

Page 4: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Outline

• ROS Introduction

• ROS Basic Mechanism

• ROS Tool Overview

• Gazebo Introduction

• Gazebo Usage

• Navigation & SLAM

4

Page 5: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS Introduction

5

Page 6: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 7: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

What is ROS ?

7

• Before we move on, we should clarify something

• Robot software = Distributed computing system

Decision Maker

Object Recognition

Object GraspingNavigation

Page 8: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 9: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Why is ROS preferred ?

9

• It encourages users not to reinvent the wheel

Page 10: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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)

Page 11: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 12: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Can ROS be used on different robot?

12

• Of course!

• Check all robots using ROS - http://wiki.ros.org/Robots

https://vimeo.com/146183080

Page 13: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS Basic Mechanism & Tool

13

Page 14: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

建立ROS workspace

• 建立一個空的環境並編譯

– $ mkdir -p ~/catkin_ws/src

– $ cd ~/catkin_ws/src

– $ catkin_init_workspace

– $ cd ~/catkin_ws

– $ catkin_make

14

Page 15: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

File System

• Basic unit - package

– CMakeLists.txt

– package.xml

• ROS package 使用catkin 這工具來進行編譯

– 按照 ROS 規定的格式寫code,就可以用catkin編譯

15

Page 16: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

rosbuild v.s. catkin

• rosbuild

– ROS Groovy之前的編譯系統

– 有部分package仍未porting到catkin上,故仍需略懂

– 所有原始碼和編譯後的檔案都在同一資料夾下

• Catkin

– ROS Groovy之後的編譯系統

– 原始碼和編譯後的檔案分離

• 接著直接來寫個node看看怎麼編譯

16

Page 17: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS Node

• Basic unit of program

17

Decision Maker

Object Recognition

Object GraspingNavigation

Node 1

Node 2 Node 3 Node 4

Page 18: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

讓我們開始實作

• 你們需要的code應該都在這了

– https://github.com/Po-Jen/coscup2016-ROS-workshop

18

Page 19: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 20: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS Master

• How do node knows each other? => ROS Master

• Control the graph of nodes

20

Page 21: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

rqt_graph

• Visualization of nodes and topics

• Part of rqt (integrates lots of debugging tools)

21

Page 22: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

How do ROS node communicate?

• ROS master as a message hub?

– What if there are many nodes?

22

Page 23: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 24: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS Topic

• Publisher/Subscriber mechanism (topic == bucket)

24

Perception

ObjectRecognition

Semantic Map

Camera data

Recognition result

Page 25: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 26: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

rqt_graph

• Now, it should looks like

26

Page 27: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 28: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

rqt_graph

• Now, it should looks like

28

Page 29: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

rqt

• We can try console

29

Page 30: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 31: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

package.xml

• Add build dependency and run dependency

31

Page 32: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

CMakeLists.txt (1)

• Add package dependency

• Or you can

– catkin_create_pkg coscup_2_topic rospy std_msgsmessage_generation

32

Page 33: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

CMakeLists.txt (2)

• Add build dependency

• Add msg file

• We use std_msgs/int64 in our msg file

33

Page 34: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 35: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

One more example

• geometry_msgs/Twist

35

Page 36: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

One more example

• geometry_msgs/Vector3

36

Page 37: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

How is the abstraction implemented?

37

/cmd_veltopic

Base Controller

Motor Speed

geometry_msgs/Twist

將速度和角速度轉成馬達命令

Page 38: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS Service

• Query/Response Style

38

Object Recognition

Brain

1 query 2 response

Page 39: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 40: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

package.xml

• Add build dependency and run dependency

40

Page 41: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

CMakeLists.txt

• Add service file

• Add std_msgs dependency

41

Page 42: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 43: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 44: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 45: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Find out more on ROS Cheat Sheet

• https://github.com/ros/cheatsheet45

Page 46: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Gazebo Introduction

46

Page 47: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

What is Gazebo ?

• 3D物理模擬器

–機器人控制

–環境模擬

–物體物理特性模擬

• 用途廣泛

–DARPA Challenge也是用Gazebo來開發

47

Page 48: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

看個影片就有概念了

• https://www.youtube.com/watch?v=_8AhNWKzv2k

48

Page 49: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Gazebo Usage

49

Page 50: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Started Gazebo

• 先確保該安裝的東西都有被安裝– $ sudo apt-get install ros-indigo-gazebo-*

– $ sudo apt-get install ros-indigo-pr2-*

• 啟動Gazebo– $ gazebo

• 加入一些模型並存成world file

50

Page 51: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Play around with Rviz

51

Page 52: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

SLAM & Navigation

52

Page 53: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

先來個 SLAM 的 DEMO

• Gazebo 開啟 PR2 進行 SLAM

53

Page 54: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

讓我們來實際操作

• 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

Page 55: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 56: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Map representation

56

Page 57: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 58: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 59: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

ROS 2.0

• 欲改進的點

– 多機器人協作 (ROS 1.0是for PR2開發的)

– 嵌入式平台開發 (不必再透過一層額外driver)

– real-time系統 (能有更精準的控制能力)

– 適用於產品開發 (原本偏向學術研究用)

– 設計模式的建立

59

Page 60: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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

Page 61: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Thanks for joining, you guys rock!

61

Page 62: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

Appendix I如何使用第三方提供的

package

62

Page 63: COSCUP 2016 - ROS + Gazebo機器人模擬器工作坊

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