0% found this document useful (0 votes)
2 views

Lecture 2. Ros Basic

The document provides an overview of the Robot Operating System (ROS), covering key components such as ROS Master, nodes, topics, and the Catkin build system. It explains how to set up a ROS workspace, manage nodes and topics, and utilize launch files for running multiple nodes. Additionally, it introduces the Gazebo simulator for 3D simulation and offers references for further learning.

Uploaded by

22027505
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 2. Ros Basic

The document provides an overview of the Robot Operating System (ROS), covering key components such as ROS Master, nodes, topics, and the Catkin build system. It explains how to set up a ROS workspace, manage nodes and topics, and utilize launch files for running multiple nodes. Additionally, it introduces the Gazebo simulator for 3D simulation and offers references for further learning.

Uploaded by

22027505
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

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

You might also like