ECE 5463 Introduction To Robotics Spring 2018: ROS Tutorial 1
ECE 5463 Introduction To Robotics Spring 2018: ROS Tutorial 1
ECE 5463 Introduction To Robotics Spring 2018: ROS Tutorial 1
Spring 2018
ROS
TUTORIAL 1
01/2018
ECE5463 (Sp18) Previous Steps
Outline
• Previous Steps
• Installing VM, Ubuntu 16.04.3, ROS Kinetic Distribution
• Possible problems
• ROS
• Understanding ROS Basics
• ROS Packages
• Creating ROS workspace and ROS Package
• Understanding ROS Filesystem
• ROS Program
• First ROS Program – Hello world
• Python scripts, launch files.
• Turtlesim simulation
2
ECE5463 (Sp18) Previous Steps
Possible problems
• The ROS ENVIRONMENT VARIABLE is not defined properly.
• Solution
Run the following commands:
3
ECE5463 (Sp18) Previous Steps
Possible problems
• Installation of Anaconda changes the default path for python.
• Solution
Open the bashrc file with the following command:
gedit ~/.bashrc
Erase or comment the line
export PATH="/home/guillermo/anaconda3/bin:$PATH“
• Alternative solution
Every time you open a new terminal run the following command:
export $PATH="/usr/bin:$PATH„
4
ECE5463 (Sp18) ROS Basics
General Overview
5
ECE5463 (Sp18) ROS Packages
What is a package?
• All the files that a specific ROS program contains; all its cpp files,
python files, configuration files, compilation files, launch files, and
parameters files.
• Generally all those files in the package are organized with the
following structure:
launch folder: Contains launch files
Not always
src folder: Source files (cpp, python)
CMakeLists.txt: List of cmake rules for compilation
package.xml: Package information and dependencies
6
ECE5463 (Sp18) ROS Packages
• The package_name is the name of the package you want to create, and
the package_dependencies are the names of other ROS packages that your
package depends on.
catkin_create_pkg tutorial rospy
• The launch and src folder are not always created automatically, but we can
create them manually.
mkdir ~/catkin_ws/src/tutorial/launch
• Package commands:
rospack list: Gives a list of all the packages in your ROS system.
rospack list | grep [my_package]: Filters packages that contain [my_package]
roscd [my_package]: Takes you to the location of [my_package]
8
ECE5463 (Sp18) ROS Packages
Compile a package
• When you create a package, you will usually need to compile it in order to
make it work.
• This command will compile your whole src directory, and it needs to be called
in your catkin_ws directory. If you try to compile from another directory, it won't
work.
cd ~/catkin_ws/
catkin_make
Do not forget!
• Build the package when you install or create a new one, and
• Source the workspace so that ROS can find the new package.
9
ECE5463 (Sp18) ROS Program
• Then, we will create a ROS node that print the message on the screen.
Usually this nodes are initiated by a python or cpp script.
10
ECE5463 (Sp18) ROS Program
11
ECE5463 (Sp18) ROS Program
Python script
• NOTE: If you create your Python file from the shell, it may happen that it is
created without execution permissions. If this happens, ROS will not be able to
find it. If this is your case, you can give execution permissions to the file by
typing the next command: chmod +x name_of_the_file.py
chmod +x printer.py
12
ECE5463 (Sp18) ROS Program
13
ECE5463 (Sp18) ROS Program
Launch file
• All launch files are contained within a <launch> tag. Inside that tag, you can
see a <node> tag, where we specify the following parameters:
1. pkg="package_name" # Name of the package that contains the code
2. type="python_file_name.py" # Name of the program file to execute
3. name="node_name" # Name of the ROS node that will launch our .py file
4. output="type_of_output" # Through which channel you will print the
output of the .py file
cd ~/catkin_ws/src/tutorial/launch
gedit node_launcher.launch
<launch>
<node pkg="tutorial" type="printer.py" name="printer_node"
output="screen">
</node>
</launch>
14
ECE5463 (Sp18) ROS Program
• Now, let’s check what nodes are actually running using the command:
rosnode list
15
ECE5463 (Sp18) ROS Program
16
ECE5463 (Sp18) ROS Program
• A topic is a channel that acts as an information high way, where other ROS
nodes can either publish or read information.
CREATE A PUBLISHER
cd ~/catkin_ws/src/tutorial/src
gedit publisher.py
17
ECE5463 (Sp18) ROS Program
• To get information about the topic such as the message type, or the topic’s
publishers and subscribers: rostopic echo [name_of_the_topic]
rostopic info /phrases
18
ECE5463 (Sp18) ROS Program
Messages
• Topics handle information through messages.
•You can even create your own messages, but it is recommended to use ROS
default messages when possible.
• To get information about a message, use the next command: rosmsg show
[message_type]
rosmsg show std_msgs/String
• In this case, the String message has only one variable named data of type
string. This String message comes from the package std_msgs.
19
ECE5463 (Sp18) ROS Program
Subscriber
• A subscriber is a node that reads information from a topic.
CREATE A SUBSCRIBER
cd ~/catkin_ws/src/tutorial/src
gedit subscriber.py
20
ECE5463 (Sp18) ROS Program
<launch>
<node pkg="tutorial" type="subscriber.py"
name="topic_subscriber" output="screen">
</node>
</launch>
• Notice that the subscriber will print nothing if there is no information published
in the topic “phrases”
21
ECE5463 (Sp18) ROS Program
• You can also launch more than one package at the same time from the same
launch file.
<launch>
<node pkg="tutorial" type="publisher.py" name="topic_publisher"
output="screen">
</node>
<node pkg="tutorial" type="subscriber.py"
name="topic_subscriber" output="screen">
</node>
</launch>
Important
• RECALL: rosrun is used to execute Python, cpp files, which initiate the
nodes and perform actions, while roslaunch is used to execute the .launch
file that can run one or more nodes at the same time. (This automate the
above process)
23
ECE5463 (Sp18) ROS Program
Turtlesim Simulation
• Start simulation by running nodes (this package uses cpp files to initiate the
nodes). Run the following commands in different terminal’s windows.
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
• Use the command learned in this tutorial to get information about the nodes,
topics, messages.
rosnode list
rostopic list
rostopic info /turtle1/pose
rosmsg show /turtlesim/pose
rostopic echo /turtle1/cmd_vel
References
• http://wiki.ros.org/urdf/Tutorials/
• http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics
• http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28pyth
on%29
• http://wiki.ros.org/turtlesim/Tutorials
• https://www.robotigniteacademy.com
• O’Kane, Jason. A Gentle Introduction to ROS
25
ECE5463 (Sp18)
26