0% found this document useful (0 votes)
5 views65 pages

Introduction to Mobile Robot Programming

Uploaded by

Larry Nelson
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)
5 views65 pages

Introduction to Mobile Robot Programming

Uploaded by

Larry Nelson
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

AULA 01

1001501 - INTRODUÇÃO DE
PROGRAMAÇÃO DE ROBÔS MÓVEIS
CCO728 - ROBÔS MÓVEIS AUTÔNOMOS

Introduction to ROS

Departamento de Computação
Prof. Dr. Kelen Cristiane Teixeira Vivaldini
Summary

• ROS architecture & philosophy


• ROS master, nodes, and topics
• Console commands
• Catkin workspace and build system
• Launch-files
• Gazebo simulator

PROF. DR. KELEN TEIXEIRA VIVALDINI 2


catkin Build System

catkin is the ROS build system to generate executables, libraries,


and interfaces
$ catkin build
Navigate to your catkin workspace with
$ cd ~/workspace

Build a package with


$ catkin build package_name

Whenever build a new package, update your environment


$ source ./devel/[Link]
More info
[Link]

PROF. DR. KELEN TEIXEIRA VIVALDINI


Apresentação baseada nos slides do:
ETHZ - Péter Fankhauser, Dominic Jud, Martin Wermelinger, Prof. Dr. Marco
Hutter
Carnegie Mellon University – Gianni A. Di Caro

PROF. DR. KELEN TEIXEIRA VIVALDINI 4


What is ROS?

PROF. DR. KELEN TEIXEIRA VIVALDINI


History of ROS

Original author:
Willow Garage (2007) -
Stanford Artificial Intelligence
Laboratory
• Since 2013 managed by OSRF
• Written in C++ or Python
• License BSD
• Operating System:
Linux, MacOS
• Today used by many robots,
universities and companies
• De facto standard for
robot programming

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Distribution

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS
Industrial Development Process

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS requirement

• Laptop and machine


• CMD linux administration
• Knowledge of
– C for firmware
– Python, C++, OPP
– Algorithms

PROF. DR. KELEN TEIXEIRA VIVALDINI


PROF. DR. KELEN TEIXEIRA VIVALDINI
ROS Philosophy

• Peer to peer
Individual programs communicate over defined API (ROS messages,
services, etc.).
• Distributed
Programs can be run on multiple computers and communicate over the
network.
• Multi-lingual
ROS modules can be written in any language for which a client library
exists (C++, Python, MATLAB, Java, etc.).
• Light-weight
Stand-alone libraries are wrapped around with a thin ROS layer.
• Free and open-source
Most ROS software is open-source and free to use.
PROF. DR. KELEN TEIXEIRA VIVALDINI
ROS Master

• Manages the communication between nodes


• Every node registers at startup with the master

Start a master with


$ roscore

More info:
[Link]

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Master

Start a master with


$ roscore

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Nodes

• Single-purpose, executable program


• Individually compiled, executed, and managed
• Organized in packages

Run a node with


$ rosrun package_name node_name

See active nodes with


$ rosnode list

More info
Retrieve information about a node with [Link]
$ rosnode info node_name

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Nodes
Retrieve information about a node with
> rosnode info rosout

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Topics
• Nodes communicate over topics
– Nodes can publish or subscribe to a topic
– Typically, 1 publisher and n subscribers
• Topic is a name for a stream of messages

List active topics with


$ rostopic list

Subscribe and print the contents of a topic with


$ rostopic echo /topic

Show information about a topic with


$ rostopic info /topic
More info:
[Link]

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Messages
• Data structure defining the type of a topic
• Comprised of a nested structure of integers, floats,
booleans, strings etc. and arrays of objects
• Defined in *.msg files

See the type of a topic


$ rostopic type /topic

Publish a message to a topic


$ rostopic pub /topic type args

More info:
[Link]

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Messages

• Pose Stamped Example

PROF. DR. KELEN TEIXEIRA VIVALDINI


ROS Workspace Environment

• Defines context for the current workspace


• Default workspace loaded with
$ source /opt/ros/kinetic/[Link]

Overlay your catkin workspace with


$ cd ~/workspace
$ source ./devel/[Link]

Check your workspace with


$ printenv | grep ROS
$ echo $ROS_PACKAGE_PATH More info
[Link]
$ catkin --version
$ catkin_make -v

PROF. DR. KELEN TEIXEIRA VIVALDINI


Install Package
roscpp tutorial
Console

Access the workspace


$ cd ~/workspace/src
$ git clone [Link]

$ cd ~/workspace/
$ catkin build

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 1 – Starting a roscore

Start a roscore with


$ roscore

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 2 – Starting a talker node

Run a talker demo node with


$ rosrun roscpp_tutorials talker

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 3 – Analyze talker node

See the list of active nodes


$ rosnode list

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 3 – Analyze talker node

Show information about the talker node


$ rosnode info /talker

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 3 – Analyze talker node

See information about the chatter topic


$ rostopic info /chatter

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 3 – Analyze chatter topic

Check the type of the chatter topic


$ rostopic type /chatter

Show the message contents of the topic


$ rostopic echo /chatter

Analyze the frequency


$ rostopic hz /chatter

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 4 – Starting a listener node

Run a listener demo node with


> rosrun roscpp_tutorials listener

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 3 – Analyze

See the new listener node with


$ rosnode list

Show the connection of the nodes over the chatter topic with
$ rostopic info /chatter

PROF. DR. KELEN TEIXEIRA VIVALDINI


Example

Console Tab Nr. 3 – Publish Message from Console

Close the talker node in console nr. 2 with Ctrl + C

Publish your own message with


$ rostopic pub /chatter std_msgs/String "data: Autonomous Robot Class 2023 ' "

Check the output of the listener in console nr. 4

PROF. DR. KELEN TEIXEIRA VIVALDINI


Turtlesim

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
Start the roscore:
$ roscore

To compile :
$ rosmake turtlesim

To initialize Turtlesim :

$ rosrun turtlesim turtlesim_node

You'll see the turtlesim window:

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim - rosrun
rosrun allows you to use the package name to directly run a node within a package
(without having to know the package path).
Usage:
$ rosrun [package_name] [node_name]

$ rosrun turtlesim turtlesim_node

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
Nodes
Now, look again at the nodes that are running in your ROS :

$ rosnode list

You will see a new node listed:

With the rosrun command you can modify the name of the created node:

$ rosrun turtlesim turtlesim_node _name:=my_turtle

Note: Run the above command without closing the turtlesim that has already been started. You will see that
you can initialize multiple equal nodes as long as they have different names.

$ rosnode list

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
Nodes
Turtlesim uses the geometry_msgs/Twist message instead of its
own custom one (turtlesim/Velocity in Groovy and older). Also
the topic has been changed to cmd_vel (instead
of command_velocitybefore).

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic
1.1 roscore
In a new terminal:
$ roscore

1.2 turtlesim
Please run in a new terminal:

$ rosrun turtlesim turtlesim_node

1.3 turtle keyboard teleoperation


We'll also need something to drive the turtle around with. Please run in a new
terminal:
$ rosrun turtlesim turtle_teleop_key

Use arrow keys to move the turtle.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

Place the turtlesim window and the


teleoperation node side by side.
Remember to keep the teleoperation
node window selected so that the node
captures the keypress. Use the arrow
keys on your keyboard and watch the
turtle move.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

$ rostopic list

$ rostopic type

$ rostopic info

$ rostopic pub

$ rostopic echo

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

$ rostopic list

$ rostopic type

$ rostopic info

$ rostopic pub

$ rostopic echo

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

$ rostopic list

$/rosout
$/rosout_agg
$/turtle1/cmd_vel
$/turtle1/color_sensor
$/turtle1/pose

These are all topics that the node are publishing or subscribing
to.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic
$ rostopic list

$ rostopic type

$ rostopic info

$ rostopic pub

$ rostopic echo

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic
rostopic type
The topic /turtle1/cmd_vel is responsible for moving our turtle.
Let's see what kind of message is used by this topic with the
following command:

$ rostopic type /turtle1/cmd_vel

$ geometry_msgs/Twist

$ rosmsg show geometry_msgs/Twist

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

rostopic type
geometry_msgs/Twist

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

$ rostopic list

$ rostopic type

$ rostopic info

$ rostopic pub

$ rostopic echo

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

rostopic info
$ rostopic info /turtle1/cmd_vel

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

$ rostopic list

$ rostopic type

$ rostopic info

$ rostopic pub

$ rostopic echo

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

rostopic pub
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 --
'[4.0, 0.0, 0.0]' '[0.0, 0.0, 2.8]'

Note: The commands moves the turtle with linear velocity at x


equal to 2.0 and angular velocity at z equal to 1.8.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

rostopic pub
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 --
'[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8] '

Note: To the turtle continues to move around without stopping.


The -r option indicates the frequency in Hz that we wish to
publish the message, in this case, 1 Hz.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

$ rostopic list

$ rostopic type

$ rostopic info

$ rostopic pub

$ rostopic echo

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic

rostopic echo
$ rostopic echo /turtle1/cmd_vel

Note: A sequence of messages in your window with the


information being published in the / turtle1 / cmd_vel topic.
Ctrl+C to exit.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
ROS Topic
The turtlesim_node and the turtle_teleop_key node are communicating with
each other over a ROS Topic.
turtle_teleop_key is publishing the key strokes on a topic, while turtlesim
subscribes to the same topic to receive the key strokes.
Let's use rqt_graph which shows the nodes and topics currently running.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
rqt_graph
rqt_graph creates a dynamic graph of what's going on in the system.
rqt_graph is part of the rqt package.

In a new terminal:

$ rosrun rqt_graph rqt_graph

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
rqt_graph
If you place your mouse over /turtle1/command_velocity it will highlight the
ROS nodes (here blue and green) and topics (here red). As you can see,
the turtlesim_node and the turtle_teleop_key nodes are communicating on
the topic named /turtle1/command_velocity.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
rqt_graph

In a new terminal:
$ rostopic echo /turtle1/command_velocity

Now let's look at rqt_graph again. Press the refresh button in the upper-left to
show the new node. As you can see rostopic echo, shown here in red, is now
also subscribed to the turtle1/command_velocity topic.

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
rqt_plot

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
rqt_plot
rqt_plot displays a scrolling time plot of the data published on topics. Here
we'll use rqt_plot to plot the data being published on the /turtle1/pose topic.
First, start rqt_plot by typing in a new terminal.

$ rosrun rqt_plot rqt_plot

PROF. DR. KELEN TEIXEIRA VIVALDINI


TurtleSim
rqt_plot
In the new window that should pop up, a text box in the upper left corner
gives you the ability to add any topic to the plot. Typing /turtle1/pose/x will
highlight the plus button, previously disabled. Press it and repeat the same
procedure with the topic /turtle1/pose/y. You will now see the turtle's x-y
location plotted in the graph.

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise
Theory
- ROS architecture
- ROS master, nodes, and topics
- Console commands
- Linux commands

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise
Get to know ROS by inspecting the TurtleBot3.
3 different models:
● burger
● waffle
● waffle_pi

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise
Check if you have the package "turtlebot3_gazebo" installed:

$ rospack list | grep turtlebot3_gazebo

If the package "turtlebot3_gazebo" is not installed in your ROS environment, you will
need to install it.

First, update your package list to make sure you have the latest information about
available packages:

$ cd ~/workspace
$ sudo apt-get update
$ sudo apt-get install ros-noetic-turtlebot3-gazebo
$ sudo apt-get install [Link]

After the installation is complete, repeat the following command:

$ rospack list | grep turtlebot3_gazebo


PROF. DR. KELEN TEIXEIRA VIVALDINI
Exercise
Finally, let's launch the simulation using the following code:

$ export TURTLEBOT3_MODEL=waffle_pi

$ roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise
1. Launch the simulation and inspect the created nodes and their topics using:
rosnode list
rostopic list
rostopic type
rostopic echo [TOPIC]
rostopic info [TOPIC]
rqt_graph
For more information take a look at the slides or:
[Link]
[Link]

Insert a box in the scenario.

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise
2. Let's try and visualize the data in RViz.

$ export TURTLEBOT3_MODEL=waffle_pi
$ roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise
3. Command a desired velocity to the robot from the terminal (rostopic pub
[TOPIC])

$ rostopic pub /cmd_vel geometry_msgs/Twist -r 1 -- '[4.0, 0.0,


0.0]' '[0.0, 0.0, 2.8]'

PROF. DR. KELEN TEIXEIRA VIVALDINI


Exercise
4. Turtlebot_teleop package

For a keyboard teleoperation use:


$ roslaunch turtlebot_teleop keyboard_teleop.launch

PROF. DR. KELEN TEIXEIRA VIVALDINI

You might also like