ROS-I Basic Developers Training (ROS2) - Session 1
ROS-I Basic Developers Training (ROS2) - Session 1
Training Class
July 2023
• Intro to ROS
• ROS Workspaces & Colcon
• Installing packages (existing)
• Packages (create)
• Nodes
• Messages / Topics
3
An Introduction to ROS
4
ROS1 and ROS2
5
ROS1 and ROS2
6
ROS Versions
7
ROS : The Big Picture
software
sensors actuators
environment
8
ROS : The Big Picture
Our Approach: Collaboration, Modularity, and Simulation
sensors actuators
environment
9
What is ROS?
ROS is…
= + + +
10
ROS is… plumbing
Publisher Subscriber
/topic
Publisher Subscriber
11
ROS Plumbing : Drivers
● 2d/3d cameras
● laser scanners
● robot actuators
● inertial units
● audio
● GPS
● joysticks
● etc.
(Adapted from Morgan Quigley’s “ROS: An Open-Source Framework for Modern Robotics” presentation)
12
ROS is …Tools
•logging/plotting
•graph visualization
•diagnostics
•visualization
13
ROS is…Capabilities
Planning
Perception Execution
14
ROS is… an Ecosystem
http://metrorobots.com/rosmap.html
15
ROS is a growing Ecosystem
https://metrics.ros.org/
16
ROS is International
unique wiki visitors Jul 2020
1. Singapore: 683
2. Hong Kong: 475
3. Taiwan: 252
4. South Korea: 244
5. Germany: 175
...
9. USA: 96
19
ROS Resources
Package
wiki
ROS ROS-I
website ? wiki/github
ROS
Answers
20
ROS.org Website
http://ros.org
ROS1
but still relevant
• Install Instructions
• ROS Answers
• Forums (Discourse)
21
ROS2 Documentation
http://docs.ros.org
• Install
• Tutorials
• Concepts
• APIs
22
ROS Package Index
http://index.ros.org
• Install Instructions
• Tutorials
• Package Info
• Still NEW – see ROS1 Wiki
23
Package Wiki
http://wiki.ros.org/<packageName>
• Description / Usage
• Tutorials “ROS1 Only”
• Code / Msg API But still relevant for most
packages
• Source-Code Link
• Bug Reporting
24
ROS Answers
http://answers.ros.org
https://robotics.stackexchange.com
26
What is ROS to you?
Training Goals:
• Show you ROS as a software framework
• Show you ROS as a tool for problem solving
• Apply course concepts to a sample application
• Ask lots of questions and break things.
27
Scan & Plan “Application”
28
ROS Architecture: Nodes
image
processing
motion
logic
29
ROS Architecture: Packages
ROS Package
(e.g. Pick-and-Place Task)
robot
planning
camera image motion robot
interface processing logic interface
robot
model
multiple no
nodes nodes
30
ROS Architecture: MetaPkg
ROS MetaPackage
(e.g. fanuc, ros_industrial, ros_desktop, ...)
robot
planning
camera image motion robot
interface processing logic interface
robot
model
❑Add “resources”
❑Create Package ROS
❑Create Node Workspace
❑Basic ROS Node
❑Interact with other nodes
❑Messages My Package
❑Services
Node
❑Run Node
❑ros2 run
❑ros2 launch
32
Installing ROS
33
Getting ROS2
https://index.ros.org/doc/ros2/Installation/humble/
34
Exercise 1.0
Exercise 1.0
Basic ROS Install/Setup
35
Day 1 Progression
❑Add “resources”
❑Create Package ROS
❑Create Node Workspace
❑Basic ROS Node
❑Interact with other nodes
❑Messages My Package
❑Services
Node
❑Run Node
❑ros2 run
❑ros2 launch
36
Creating a ROS Workspace
37
ROS Workspace
ros_workspace
src
package_1
package_2
build
install
38
Build System
• ROS2 uses the ament build system
– based on CMake
– cross-platform (Ubuntu, Windows, embedded...)
– simplifies depending on packages and exporting
outputs to other packages
39
Build System
• ROS2 also uses the colcon build tool
– Pure Python framework
– Generates the workspace outputs:
• Finds all packages in the src directory
• Defines the build order based on dependencies
• Invokes the build system for each package
– CMake/Ament for C++ packages
– Setuptools for pure Python packages
– Can build ROS1 packages
• but some packages may prefer to be built with the ROS1-
legacy “catkin” build tools.
40
Colcon Build Process
Setup (one-time)
1. Create a workspace (arbitrary name and location)
• ros_ws
• src sub-directory must be created manually
• build, install directories created automatically
2. Download/create packages in src subdir
Compile-Time
1. Run colcon build from the workspace root
2. Run source install/setup.bash to make this
workspace visible to ROS
41
Colcon Build Notes
Colcon Build
– Always run from the workspace root
– Source workspaces of any dependencies before running build.
• e.g. source /opt/ros/humble/setup.bash
– Can chain multiple workspaces together:
• base humble -> pcl_ws -> my_ws
– Don’t run from a terminal where you have “sourced” this
workspace’s setup file (can cause circular issues).
➢ Best Practice: Use a dedicated terminal window for building.
• Don’t do anything in that terminal window other than colcon build.
Source install/setup.bash
– Remember to source this setup file in EACH new terminal
– No need to also source the underlays’ setup files
– May need to re-source after adding new packages
– Can add to ~/.bashrc to automate this step
• not recommended if using multiple ROS distros or working on
multiple projects in parallel
42
Exercise 1.1
Exercise 1.1
Create a ROS Workspace
fake_ar_pub myworkcell_node
myworkcell_support
vision_node
descartes_node
myworkcell_moveit_cfg ur5_driver
43
Day 1 Progression
44
Add 3rd-Party Packages
(a.k.a. “Resource” Packages)
45
Install options
46
Finding the Right Package
47
Install using Debian Packages
48
Installing from Source
• Find GitHub repo
• Clone repo into your workspace src directory
cd ros_ws/src
git clone http://github.com/user/repo.git
• Build your colcon workspace
cd ros_ws
colcon build
• Now the package and its resources are
available to you
49
Exercise 1.2
Exercise 1.2
Install “resource” packages
fake_ar_pub myworkcell_node
myworkcell_support
vision_node
descartes_node
myworkcell_moveit_cfg ur5_driver
50
Day 1 Progression
51
ROS Packages
52
ROS Package Contents
• ROS components are organized into packages
• Packages contain several required files:
– package.xml
• metadata for ROS: package name, description, dependencies, ...
– CMakeLists.txt
• build rules for ament
package
directory
ros_ws
src
robotpkg package source-files
(vs. workspace src dir)
package
build
install required
files
53
package.xml
54
package.xml
55
CMakeLists.txt
56
ROS Package Commands
• ros2 pkg
– ros2 pkg create package_name
Create a new package, including template files
Common options (not required, but will help pre-fill templtes):
--build-type ament_cmake
--node-name my_node
--dependencies dep_pkg_1 dep_pkg_2
57
Create New Package
ros2 pkg create mypkg --node-name mynode
--dependencies dep1 dep2
58
Exercise 1.3.1
Exercise 1.3.1
Create Package
fake_ar_pub myworkcell_node
myworkcell_support
vision_node
descartes_node
myworkcell_moveit_cfg ur5_driver
59
Day 1 Progression
60
ROS Nodes
61
A Simple C++ ROS Node
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
rclcpp::init(argc, argv);
auto node = make_shared<rclcpp::Node>(“hello”);
return 0; return 0;
} }
62
ROS2 Node Commands
• ros2 node
– ros2 node list
View running nodes
– ros2 node info node_name
View node details (publishers, subscribers, services, etc.)
63
Exercise 1.3.2
Exercise 1.3.2
Create a Node:
In myworkcell_core package
called vision_node
fake_ar_pub myworkcell_node
myworkcell_support
vision_node
descartes_node
myworkcell_moveit_cfg ur5_driver
65
Day 1 Progression
66
Topics and Messages
67
ROS Topics/Messages
68
Topics vs. Messages
/camera_1/rgb
camera_1 image … image …
/camera_2/rgb image_processing
camera_2 image … image …
69
Practical Example
/Basler1/image_rect
Basler Calibration Node
sensor_msgs/Image
Camera Node Subscribes to
Images from:
/Basler1/image_rect
/Basler2/image_rect /Basler2/image_rect
Basler sensor_msgs/Image /Basler3/image_rect
Camera Node …
70
Multiple Pub/Sub
/camera_1/rgb
image_processing
viewer
71
Topics : Details
• Typical Uses:
– Sensor Readings: camera images, distance, I/O
– Feedback: robot status/position
– Open-Loop Commands: desired position
72
Quality of Service
73
QoS Profiles
74
ROS Messages Types
• Similar to C structures
• Standard data primitives
– Boolean: bool
– Integer: int8,int16,int32,int64
– Unsigned Integer: uint8,uint16,uint32,uint64
– Floating Point: float32, float64
– String: string
• Fixed length arrays: bool[16]
• Variable length arrays: int32[]
• Other: Nest message types for more complex data
structure
75
Message Description File
PathPosition.msg
comment # A 2D position and orientation
other Msg type std_msgs/Header header
float64 x # X coordinate
float64 y # Y coordinate
float64 angle # Orientation
data field
type name
76
Custom ROS Messages
• Modify CMakeLists.txt
to enable message
generation.
77
CMakeLists.txt
find_package(rosidl_default_generators
REQUIRED)
rosidl_generate_interfaces(
msg/CustomMsg.msg
DEPENDENCIES ...)
78
package.xml
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
79
ROS Interface Commands
80
ROS Topic Commands
81
“Real World” – Messages
82
Topics: Syntax
• Topic Publisher
– Advertises available topic (Name, Data Type, QoS)
– Populates message data
– Periodically publishes new data
Node Object Create Publisher Message Type Topic Name Quality of
Service
PathPosition msg;
msg.x=xVal; msg.y=yVal; ... Message Data
pub->publish(msg); Publish Message
rclcpp::spin_some(node);
Background
Process
83
Topics: Syntax
• Topic Subscriber
– Defines callback function
– Listens for available topic (Name, Data Type, QoS)
84
Namespaces
• ROS requires unique names for nodes/topics/etc.
• Namespaces allow separation:
– Similar nodes can co-exist, in different “namespaces”
– relative vs. absolute name references
robot_1
86
Exercise 1.4
Exercise 1.4
Subscribe to fake_ar_publisher
fake_ar_pub myworkcell_node
AR pose
myworkcell_support
vision_node
descartes_node
myworkcell_moveit_cfg ur5_driver
87