Difference between revisions of "ROS Tutorials"

From Lofaro Lab Wiki
Jump to: navigation, search
(Understanding ROS Nodes)
(Beginner Level)
Line 207: Line 207:
  
 
==Understanding ROS Topics==
 
==Understanding ROS Topics==
 +
==Understanding ROS Services and Parameters==
 +
==Using rqt_consol and roslaunch==
 +
==Using rosed to Edit Files in ROS==
 +
==Creating a ROS msg and srv==
 +
==Writing a Simple Publisher and Subscriber (C++)==
 +
==Writing a Simple Publisher and Subscriber (Python)==
 +
==Examining the Simple Publisher and Subscriber==
 +
==Writing a Simpler Service and Client (C++)==
 +
==Writing a Simpler Service and Client (Python)==
 +
==Examining the Simpler Service and Client==
 +
==Recording and Playing Back Data==
 +
==Getting Started with roswtf==
 +
==Navigating the ROS wiki==
 +
==Where Next?==

Revision as of 11:04, 11 October 2014

Practicing writing a wiki page- all information below is incomplete until otherwise noted.

Aside to editor, to improve:

This tutorial assumes that you will be working in ROS-hydro on Ubuntu 12.04. This wiki is based on the tutorials given here.

Beginner Level

Open the terminal. To complete each step, type in the following commands in the order shown.

Installing and configuring your ROS environment

We recommend ROS-hydro on Ubuntu 12.04, instructions given on this link. The commands are given below. Complete all of these in the same Terminal during the same session.

If not using Ubuntu 12.04 and installing hydro: please refer to instructions given here.

1) Setup sources list:

   sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list'

You may be prompted for your super-user password. This should be your username password. Type it into the terminal and press ENTER.

2) Setup keys:

   wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -O - | sudo apt-key add -

3) Update Debian package:

   sudo apt-get update

4) Install Desktop-Full:

  sudo apt-get install ros-hydro-desktop-full

5) Initialize rosdep:

  sudo rosdep init
  rosdep update

6) Setup Enviornment:

  echo "source /opt/ros/hydro/setup.bash" >> ~/.bashrc
  source ~/.bashrc

7) Install rosinstall:

  sudo apt-get install python-rosinstall

Navigating the ROS Filesystem

First, if catkin is not already installed, we need to settle some dependencies and install catkin.

Settle dependencies:

  sudo apt-get install cmake python-catkin-pkg python-empty python-nose python-setuptools libgtest-dev build-essential

Install catkin:

  sudo apt-get install ros-hydro-catkin

Now we can focus on navigation. Here is a list of commands to navigate around the ROS files and folders.

  • To find the path of a package: rospack find [package-name]

Example:

  rospack find roscpp
  • To change directory: roscd [locationname[/subdir]]

Example:

  roscd roscpp
  • To see your working (current) directory:
  pwd
  • To see your ROS environment path:
  echo $ROS_PACKAGE_PATH
  • To move to the folder ROS stores its logs:
  roscd log
  • To see contents of a particular package: rosls [locationname[/subdir]]

Example:

  rosls roscpp_tutorials
  • TAB completion is also supported.

Creating a ROS Package

A workspace is created, then a ROS package within the workspace.

Creating a Workspace for Catkin

1) We create a src file in the catkin_ws folder, move into it, and create a workspace called catkin_init_workspace:

  mkdir -p ~/catkin_ws/src
  cd ~/catkin_ws/src
  catkin_init_workspace

2) Then we build the workspace:

  cd ~/catkin_ws/
  catkin_make

3) And create the setup.*sh file:

  source devel/setup.bash

Creating a ROS Package

4) Make sure you are in the src folder you had created earlier:

  cd ~/catkin_ws/src

5) Now we create a new ROS package: catkin_create_pkg <package_name> [depend1] [depend2] [depend3]

  catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

This will create a beginner_tutorials folder which contains a package.xml and a CMakeLists.txt 5a) The package.xml contains the names of the dependenices. These can be checked by looking at the folder or typing:

  rospack depends1 beginner_tutorials

5b) To see all dependencies for the package and dependencies given in the xml:

  rospack depends beginner_tutorials

The xml file has a description (line 5), maintainer tag (lines 7,9, and 10), license tag (line 8), and dependency list (lines 12-20). Below is given a concise example of our beginner_tutorial xml file:

   1 <?xml version="1.0"?>
   2 <package>
   3   <name>beginner_tutorials</name>
   4   <version>0.1.0</version>
   5   <description>The beginner_tutorials package</description>
   6 
   7   <maintainer email="you@yourdomain.tld">Your Name</maintainer>
   8   <license>BSD</license>
   9   <url type="website">http://wiki.ros.org/beginner_tutorials</url>
  10   <author email="you@yourdomain.tld">Jane Doe</author>
  11 
  12   <buildtool_depend>catkin</buildtool_depend>
  13 
  14   <build_depend>roscpp</build_depend>
  15   <build_depend>rospy</build_depend>
  16   <build_depend>std_msgs</build_depend>
  17 
  18   <run_depend>roscpp</run_depend>
  19   <run_depend>rospy</run_depend>
  20   <run_depend>std_msgs</run_depend>
  21 
  22 </package>

Building a ROS Package

1) Source your environment (in case you skipped this step above)

  source /opt/ros/groovy/setup.bash

For information regarding cmake and catkin_make, see this link

For those who are creating there own code, a change to Cmake.txt may be in order. Please see later tutorials in C++ and Python for assistance.

2) Make sure you are in the catkin workspace. Look at the files listed there.

  cd ~/catkin_ws/
  ls src

beginner_tutorials, the folder we have previously made, will be listed there.

3) Let us build the package:

  catkin_make

4) After the build, take a look again at the folders listed there:

  ls

You will see folders build, devel, and src. catkin_make already knows where to place these new folders and automatically takes care of it for you.

Understanding ROS Nodes

1) First, please install this simulator:

  sudo apt-get install ros-hydro-ros-tutorials

Terminology:

  • Nodes: A node is an executable that uses ROS to communicate with other nodes.
  • Messages: ROS data type used when subscribing or publishing to a topic.
  • Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
  • Master: Name service for ROS (i.e. helps nodes find each other)
  • rosout: ROS equivalent of stdout/stderr
  • roscore: Master + rosout + parameter server (parameter server will be introduced later)

2) To use ROS, start by running the core:

  roscore

It will display a summary. If it fails to initialize, try changing the ownership of the root:

  sudo chown -R <your_username> ~/.ros

Then attempt to bring up roscore again.

3) In a new terminal (we will call this terminal 2) see what nodes are running:

  rosnode list

Likely, you will only see one called /rosout.

4) In terminal 2 try seeing more information about each node:

  rosnode info /rosout

This gives you information about the currently running nodes.

5) In a new terminal (terminal 3) we will initialize a new node.

To run a node, use rosrun [package_name] [node_name]:

  rosrun turtlesim turtlesim_node

A new window with a turtle will show up.

6) In terminal 2 (where we used rosnode list) run rosnode again:

  rosnode list

The nodes /rosout and /turtlesim now appear.

7) Close the turtle sim. In terminal 3 (where we had started the turtle sim) we will restart it again, but give the node a name:

  rosrun turtlesim turtlesim_node __name:=my_turtle

8) In terminal 2, look at the nodes again:

  rosnode list

You will see /rosout and /my_turtle. If not, try cleaning up the rosnode list:

  rosnode cleanup

Then try running the rosnode list command again.

9) In terminal 2, let us ping our simulation:

  rosnode ping my_turtle

This tests the simulation to see if it is in fact running. You will see time of replies printed to the command.

Understanding ROS Topics

Understanding ROS Services and Parameters

Using rqt_consol and roslaunch

Using rosed to Edit Files in ROS

Creating a ROS msg and srv

Writing a Simple Publisher and Subscriber (C++)

Writing a Simple Publisher and Subscriber (Python)

Examining the Simple Publisher and Subscriber

Writing a Simpler Service and Client (C++)

Writing a Simpler Service and Client (Python)

Examining the Simpler Service and Client

Recording and Playing Back Data

Getting Started with roswtf

Navigating the ROS wiki

Where Next?