KEMBAR78
ROS-I Basic Developers Training (ROS2) - Session 1 | PDF | Integer (Computer Science) | Boolean Data Type
0% found this document useful (0 votes)
120 views86 pages

ROS-I Basic Developers Training (ROS2) - Session 1

ROS-I Basic Developers Training (ROS2) - Session 1

Uploaded by

vickailiu.ca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views86 pages

ROS-I Basic Developers Training (ROS2) - Session 1

ROS-I Basic Developers Training (ROS2) - Session 1

Uploaded by

vickailiu.ca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

ROS-Industrial Basic Developer’s

Training Class
July 2023

Southwest Research Institute


1
Session 1:
ROS Basics

Southwest Research Institute


2
Outline

• Intro to ROS
• ROS Workspaces & Colcon
• Installing packages (existing)
• Packages (create)
• Nodes
• Messages / Topics

3
An Introduction to ROS

(Image taken from Willow Garage’s “What is ROS?” presentation)

4
ROS1 and ROS2

• ROS1 has been around since 2008


– Uses custom TCP/IP middleware
• ROS2 is a ground-up reimagining of ROS
– Started in 2014
– Built on DDS, middleware proven in industry
– Now on 9th named release (Iron)

This class will focus on


ROS2 Humble

5
ROS1 and ROS2

• Community is currently in transition!


– Final ROS1 release (Noetic) is out (EOL in 2025)
– All critical features are now supported in ROS2
• ROS-Industrial will take time to transition
– Many breaking changes / conceptual differences
– Vision is industrial robots will become native ROS
devices

6
ROS Versions

Box Turtle … Lunar Melodic Noetic EOL


ROS 1 Mar 2010 … 2017 - 2019 2018 - 2023 2020 - 2025

ROS 2 Ardent … Foxy (LTS) Galactic Humble


Dec 2018 … 2020 - 2023 2021 - 2022 2022-2027

7
ROS : The Big Picture

software

sensors actuators

environment

All robots are:


Software connecting Sensors to Actuators
to interact with the Environment
(Adapted from Morgan Quigley’s “ROS: An Open-Source Framework for Modern Robotics” presentation)

8
ROS : The Big Picture
Our Approach: Collaboration, Modularity, and Simulation

sensors actuators

environment

• Break Complex Software into Smaller Pieces


• Provide a framework, tools, and interfaces for distributed development
• Encourage re-use of software pieces
• Easy transition between simulation and hardware
(Adapted from Morgan Quigley’s “ROS: An Open-Source Framework for Modern Robotics” presentation)

9
What is ROS?

ROS is…

= + + +

Plumbing Tools Capabilities Ecosystem

(Adapted from Willow Garage’s “What is ROS?” Presentation)

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

(Adapted from Willow Garage’s “What is ROS?” Presentation)

13
ROS is…Capabilities

Planning

Perception Execution

(Adapted from Willow Garage’s “What is ROS?” Presentation)

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

visitors per million people

1. Singapore: 683
2. Hong Kong: 475
3. Taiwan: 252
4. South Korea: 244
5. Germany: 175
...
9. USA: 96

(http://wiki.ros.org/Metrics “Community Metrics Report” August 2020)


17
ROS is a Repository

only includes publicly released


code!

ros_comm desktop-full all buildfarm


("core") ("core+tools") ("universe")
100 KLOC 400 KLOC 4000 KLOC

(From Morgan Quigley’s “ROS: An Open-Source Framework for Modern Robotics”)


18
ROS Programming

• ROS uses platform-agnostic methods for most


communication
– DDS, TCP/IP Sockets, XML, etc.

• Can intermix programming languages


– Current 1st Tier support: C, C++, Python
– We will be using C++ for our exercises

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

• Quick responses to Good Questions


• Search by text or tag
• Don’t re-invent the wheel!
25
ROS is a Community

• No Central “Authority” for Help/Support


– Many users can provide better (?) support
– ROS-I Consortium can help fill that need

• Most ROS-code is open-source


– can be reviewed / improved by everyone
– we count on YOU to help ROS grow!

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

camera robot robot


interface planning interface

motion
logic

• A Node is a standalone piece of functionality


– Most communication happens between nodes
– Nodes can run on many different devices
– Often one node per process, but not always

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

• ROS Packages are groups of related nodes/data


– Files grouped in a single directory, with key metafiles
– Many ROS commands are package-oriented

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

• Some “MetaPackages” don’t have any content


– Only dependency references to other packages
– Mostly for convenient install/deployment
31
Day 1 Progression

❑Install ROS ROS Resource


❑Create Workspace Package

❑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

✓ Install ROS (check install) ROS Resource


❑Create Workspace Package

❑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 uses a specific directory structure:


– each “project” typically gets its own workspace
– all packages/source files go in the src directory
– temporary build-files are created in build
– results are placed in install

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

✓ Install ROS ROS Resource


✓ Create Workspace Package
❑ Add “resources”
❑ Create Package
ROS
❑ Create Node
Workspace
❑ Basic ROS Node
❑ Interact with other nodes
❑Messages
❑Services My Package

❑ Run Node Node


❑ ros2 run
❑ ros2 launch

44
Add 3rd-Party Packages
(a.k.a. “Resource” Packages)

45
Install options

Debian Packages Source Repositories


• Nearly “automatic” • Access “latest” code
• Recommended for • Most at Github.com
end-users • More effort to setup
• Stable • Unstable*
• Easy

Can mix both options, as needed

46
Finding the Right Package

• ROS Website (http://index.ros.org)


– Search for known packages

• ROS Answers (http://answers.ros.org)


– When in doubt... ask someone!
– Migrating to https://robotics.stackexchange.com

47
Install using Debian Packages

sudo apt install ros-humble-package

admin manage install all ROS pkgs ROS ROS package


permissions “.deb” new “.deb” start with ros- distribution name
Use “-” not “_”
• Fully automatic install:
• Download .deb package from central ROS repository
• Copies files to standard locations (/opt/ros/humble/...)
➢ Also installs any other required dependencies

• sudo apt-get remove ros-<distro>-<package>


• Removes software (but not dependencies!)

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

✓ Install ROS ROS Resource


✓ Create Workspace Package
✓ Add “resources”
❑ Create Package
ROS
❑ Create Node
Workspace
❑ Basic ROS Node
❑ Interact with other nodes
❑Messages
❑Services My Package

❑ Run Node Node


❑ ros2 run
❑ ros2 launch

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

• Metadata: name, description, author, license ...

54
package.xml

• Metadata: name, description, author, license ...


• Dependencies:
– Common
• <buildtool_depend>: Needed to build itself. (Typically ament_cmake)
• <build_depend>: Needed to build this package.
• <exec_depend>: Needed to run code in this package.
• <depend>: Needed to build, export, and execution dependency.
– Uncommon
• <build_export_depend>: Needed to build against this package.
• <test_depend>: Only additional dependencies for unit tests.
• <doc_depend>: Needed to generate documentation.

55
CMakeLists.txt

• Provides rules for building software


– template file contains many examples

add_executable(myNode src/myNode.cpp src/widget.cpp)


Builds program myNode, from myNode.cpp and widget.cpp

ament_target_dependencies(myNode rclcpp std_msgs)


Links node myNode to dependency headers and libraries

install(TARGETS myNode DESTINATION lib/${PROJECT_NAME})


Copies nodes/libraries to workspace’s “install” directory

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

– ros2 pkg prefix package_name


Show directory where package_name is installed

– ros2 pkg list


List all ros packages installed (this is a BIG LIST!)

– ros2 pkg xml package_name


Show the package.xml file of package_name

57
Create New Package
ros2 pkg create mypkg --node-name mynode
--dependencies dep1 dep2

Easiest way to start a new package


– create directory, required template files
– mypkg : name of package to be created
– mynode : name of node (main executable)
– dep1/2 : dependency package names
• automatically added to CMakeLists and package.xml
• can manually add additional dependencies later

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

✓ Install ROS ROS


✓ Create Workspace Resource
Package
✓ Add “resources”
✓ Create Package
❑ Create Node ROS
❑ Basic ROS Node Workspace
❑ Interact with other nodes
❑Messages
❑Services
My Package
❑ Run Node
❑ ros2 run
❑ ros2 launch

60
ROS Nodes

61
A Simple C++ ROS Node

Simple C++ Program Simple C++ ROS2 Node

#include <iostream> #include <rclcpp/rclcpp.h>

int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
rclcpp::init(argc, argv);
auto node = make_shared<rclcpp::Node>(“hello”);

std::cout << "Hello World!"; RCLCPP_INFO(node->get_logger(), "Hello World!“);

return 0; return 0;
} }

62
ROS2 Node Commands

• ros2 run package_name node_name


execute ROS node

• 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

✓ Install ROS ROS Resource


✓ Create Workspace Package
✓ Add “resources”
✓ Create Package
ROS
✓ Create Node
Workspace
✓ Basic ROS Node
❑ Interact with other nodes
❑Messages
❑Services My Package

✓ Run Node Node


✓ ros2 run
❑ ros2 launch

66
Topics and Messages

67
ROS Topics/Messages

Topics are for Streaming Data

Publisher Node Subscriber Node


/topic
Publishing
Advertises msg
/topic data
is available Listening for
Subscribed to/topic
/topic
msg … msg … msg
Onwith
channel
type /topic
msg with type msg

68
Topics vs. Messages

• Topics are channels, Messages are data types


– Different topics can use the same Message type

/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

• Many nodes can pub/sub to same topic


– comms are direct node-to-node

/camera_1/rgb
image_processing

camera_1 image … image … logger

viewer

71
Topics : Details

• Each Topic is a stream of Messages:


– sent by publisher(s), received by subscriber(s)

• Messages are asynchronous


– publishers don’t know if anyone’s listening
– messages may be dropped
– subscribers are event-triggered (by incoming messages)

• Typical Uses:
– Sensor Readings: camera images, distance, I/O
– Feedback: robot status/position
– Open-Loop Commands: desired position

72
Quality of Service

• All ROS2 comms define a “Quality of Service” (QoS)


– History/Depth - buffer N prior messages
– Reliability - retry or discard dropped messages?
– Durability - cache messages for late-joining subscribers?
– Deadline - expected interval between messages
– etc.
• All participants in a topic must have compatible QoS
– Publishers - maximum QoS they can provide
– Subscribers - minimum QoS they require
– e.g. “reliable” subscriber won’t connect to “best-effort” publisher

73
QoS Profiles

• ROS provides default QoS profiles for different


comms types.
– Use these defaults, tweak them, or define your
own application-specific QoS.

– Default Profile (messages) queue=10, reliable, volatile


– Services Profile queue=10, reliable, volatile
– Sensor Profile queue=5, best-effort, volatile
– Parameters Profile queue=1000, reliable, volatile

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

• All Messages are defined by a .msg 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

• Custom message types


are defined in msg
subfolder of packages

• Modify CMakeLists.txt
to enable message
generation.

77
CMakeLists.txt

• Lines needed to generate custom msg types

find_package(rosidl_default_generators
REQUIRED)

rosidl_generate_interfaces(
msg/CustomMsg.msg
DEPENDENCIES ...)

78
package.xml

<build_depend> rosidl_default_generators </build_depend>

<exec_depend>rosidl_default_runtime</exec_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

79
ROS Interface Commands

These commands show info about known ROS message


types (+ services/actions, discussed later)

• ros2 interface list


– Show all ROS message types currently available
• ros2 interface package <package>
– Show all ROS message types in package <package>
• ros2 interface show <package>/<message_type>

– Show the structure of the given message type

80
ROS Topic Commands

• ros2 topic list


– List all topics currently subscribed to and/or publishing
• ros2 topic type <topic>
– Show the message type of the topic
• ros2 topic info <topic>
– Show topic message type, subscribers, publishers, etc.
• ros2 topic echo <topic>
– Echo messages published to the topic to the terminal
• ros2 topic find <message_type>
– Find topics of the given message type

81
“Real World” – Messages

• Use rqt_msg to view:


– sensor_msgs/JointState
– trajectory_msgs/JointTrajectory
– sensor_msgs/Image
– rcl_interfaces/Log

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

auto pub = node->create_publisher<PathPosition>(“/position”, qos);

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)

Callback Function Message Type Message Data (IN)

void msg_callback(const PathPosition& msg) {


RCLCPP_INFO_STREAM(node->get_logger(), “Received msg: “ << msg);
}

auto sub = node->create_subscription(“/topic”, qos, msg_callback);

Server Object Service Name Callback Ref

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

image lft_camera/image /robot_1/lft_camera/image


lft_camera
/rosout

image rt_camera/image /robot_1/rt_camera/image


rt_camera
/rosout /rosout
/rosout
robot_2

image lft_camera/image /robot_2/lft_camera/image


lft_camera
/rosout

image rt_camera/image /robot_2/rt_camera/image


rt_camera
/rosout /rosout
85
Qt
Instead of text editor and building
from terminal…
Use an IDE! (detailed instructions here)
1. Launch QtCreator IDE from desktop shortcut
2. File -> New Project
3. Other Project -> ROS Workspace
4. Enter Project Properties:
1. Name = “ROS2_Training” (or whatever)
2. Distribution (should be auto-detected)
3. Build System = Colcon
4. Path = ~/ros2_ws
5. Build -> Build All
1. you should see success in the “Compile” tab

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

You might also like