L2.
ROS BASIC
Contents
• Ros master, nodes, and topic
• Console commands
• Catkin workspace and build system
• Launch-files
• Gazebo simulator
Robot Operating System
ROS Workspace Environment
• Defines context for the current workspace
• Default workspace loaded with
> source /opt/ros/melodic/setup.bash
• Overlay your catkin workspace with • See setup with
> cd ~/catkin_ws > cat ~/.bashrc
> source devel/setup.bash
• Check your catkin workspace with
> echo $ROS_PACKAGE_PATH http://wiki.ros.org/melodic/Installation/Ubuntu
http://wiki.ros.org/catkin/workspaces
Robot Operating System
ROS Master
• Manages the communication between nodes
• Every node registers at starup with the master
> roscore
Robot Operating System
ROS Nodes
• Single-purpose, executable program
o E.g. sensor driver(s), UI, map building, etc.
• Individually compiled, executed, and mangaged
• Organized in packages
ROS Master
Run a node with
Registration Registration
> rosrun package_name node_name
See active node with
> rosnode list Node 1 Node 2
Retrieve information about a node with
> rosnode info node_name
Robot Operating System
ROS Topics
• Nodes communicate over topics
o Node can publish or subscribe to a topic
o Typically, 1 publisher and n subscribers
• Topic is a name for a stream of messages
ROS Master
List active topics with
Registration Registration
> rostopic list
Subscribe and print the contents of a topic with
Messages
Node 1 Node 2
> rostopic echo /topic_name
Show information about a topic with
Publish Subscribe
> rostopic info /topic_name Topic
Robot Operating System
ROS Messages
• Data structure defining the type of a topic
• Compromised of a nested structure of integers, floats, boolens, string,..
• Defined in *.msg files
ROS Master
See the type of a topic
Registration Registration
> rostopic type /topic_name
Publish a message to a topic Messages
Node 1 Node 2
> rostopic pub /topic_name type args
*.msg
Publish Subscribe
Int velx
Topic
Int vely
String description Message definition
Robot Operating System
ROS Messages
Robot Operating System
Example
Console Tab 1: Start a roscore
> roscore
Robot Operating System
Example
Console Tab 2: Starting a talker node
> rosrun rospy_tutorials talker
Robot Operating System
Example
Console Tab 3: Analyze talker node
List active topics with
> rosnode list
Show information about a topic with
> rosnode info /node_name
Robot Operating System
Example
Console Tab 3: Analyze talker node
Check the type off the chatter topic
> rostopic type /chatter
Show the message contents of the topic
> rostopic echo /chatter
Analyze the frequency
> rostopic hz /chatter
Robot Operating System
Example
Console Tab 4: Starting a listener node
> rosrun rospy_tutorials listener
Robot Operating System
Example
Console Tab 4: Publish Message from Console
Publish your message with
> rostopic pub /chatter std_msgs/String
“data: ‘Robotics UET’ ”
Check the output of the listener in console 4
Robot Operating System
Catkin Build System
• Catkin is the ROS build system to generate executables, libraries, and interfaces
• Suggest to use the Catkin Command Line Tools
Use catkin build instead of catkin_make
Navigate to your catkin workspace with
> cd ~/catkin_ws
Uild a package with
> catkin build package_name
Whenever you build a new package, update your environment
> source devel/setup.bash http://wiki.ros.org/catkin/Tutorials
https://catkin-tools.readthedocs.io/
Robot Operating System
Catkin Build System
The catkin workspace contains the following spaces
Work here Don’t touch Don’t touch
The source space contains the The build space is where The development (devel) space
source code. This is where you CMake is invoked to build the is where built targets are placed
can clone, create, and edit packages in the source space. (prior to being installed).
source code for the packages Cache information and other
you want to build. intermediate files are kept here
If necessary, clean the entire build and devel space with
> catkin clean
Robot Operating System
Catkin Build System
The catkin workspace setup can be checked with
> catkin config
For example, to set the Cmake build type to
Release (or Debug etc.), use
> catkin build –cmake-srgs –
DCMAKE_BUILD_TYPE=Release
http://catkin-tools.readthedocs.io/en/latest/verbs/catkin_config.html
http://catkin-tools.readthedocs.io/en/latest/cheat_sheet.html
Robot Operating System
Example
Clone Git repository with
> git clone link
https://emanual.robotis.com/docs/en/platform/turtlebot3/overview/
http://wiki.ros.org/turtlesim
Robot Operating System
Ros Launch
• launch is a tool for launching multiple
nodes (as well as setting parameters)
• Are written in XML as *.launch files
• If not yet running, launch automatically
starts a roscore
Start a launch file from a package with
> roslaunch package_name filename.launch http://wiki.ros.org/roslaunch
Robot Operating System
Ros Launch (File Structure)
talker_listener.launch
• launch: Root element of the launch file
• node: Each <node> tag specifies a node to be launched
• name: Name of the node (free to choose)
• pkg: Package containing the node
• type: Type of the node, there must be a corresponding
executable with the same name
• output: Specifies where to output log messages (screen:
console, log: log file)
http://wiki.ros.org/roslaunch/XML
http://wiki.ros.org/roslaunch/Tutorials/Roslaunch%20tips%20for%20larger%20projects
Robot Operating System
Ros Launch (Argument)
Create re-usable launch files with <arg> tag, which
works like a parameter (default optional)
<arg name=“name” default=“default_value”/>
Use arguments in launch file with
$(arg arg_name)
When launching, arguments can be set with
> roslaunch launch_file.launch arg_name:=value
http://wiki.ros.org/roslaunch/XML/arg
Robot Operating System
Ros Launch (Including Orther Laucnh File)
Include other launch files with <include> tag to
organize large projects
<include file=“package_name”/>
Find the system path to other packages with
$(find package_name)
Pass arguments to the included file
<arg name=“name” value=“value”/>
http://wiki.ros.org/roslaunch/XML/include
Robot Operating System
Gazebo Simulation
• Simulate 3d rigid-body dynamics
• Simulate a variety of sensors including noise
• 3d visualization and user interaction
• Includes a database of many robots and
environments (Gazebo worlds)
• Provides a ROS interface
• Extensible with plugins
> rosrun gazebo_ros gazebo
http://gazebosim.org/
http://gazebosim.org/tutorials
Robot Operating System
Further References
• Ros Wiki • ROS Cheat Sheet
• http://wiki.ros.org/ • https://github.com/ros/cheatsheet/r
• Installation eleases/dow
• http://wiki.ros.org/ROS/Installa nload/0.0.1/ROScheatsheet_catkin.
tion pdf
• Tutorials • ROS Best Practices
• http://wiki.ros.org/ROS/Tutoria • https://github.com/ethzasl/ros_best
ls _practices/wiki
• Available packages • ROS Package Template
• http://www.ros.org/browse/ • https://github.com/ethzasl/ros_best
_practices/tree/master/ros_packag
e_template
Robot Operating System