Hello World ROS: Creating ROS workspace and a empty node.

The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms.

Creating the ROS work space

  • ROS has package management system called catkin.
  • All the packages are maintained usually in a single workspace under different directories.
  • Catkin workspace is a directory where the catkin packages are build, maintained and modified.
  • First, you need to create the top level catkin workspace directory and a sub-directory named src. The top level directory’s name is arbitrary, it can be anything, but is often called catkin_ws (an abbreviation of catkin_workspace),
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
  • Initialize and building the workspace.
$ catkin_init_workspace
$  cd ~/catkin_ws && catkin_make

You now have two new directories: build and devel. The aptly named build directory is the build space for C++/Python packages. The devel directory contain  a file named setup.bash. This setup.bash script must be sourced before using the catkin workspace.

Creating a package

  • ROS softwares are distributed and maintained as catkin packages.
  • Its again a directory containing variety of resources.
  • Let’s clone an existing package and add it to our newly created workspace.
  • You will start by navigating to the src directory and cloning the simple_arm package for this lesson from its github repo.
$ cd ~/catkin_ws/src
$ git clone https://github.com/udacity/simple_arm_01.git simple_arm

After the repo has finished cloning, you can change directory to the top-level of the ros workspace and build the new package.

$ cd ../../
$ catkin_make

If you see the following error

I see a CMake Error. “Could not find a package configuration file provided by controller_manager”,

The following is missing just install it using the command below,

$ sudo apt-get install ros-kinetic-controller-manager

build again

$ cd ~/catkin_ws
$ catkin_make

Once the workspace has been built, now source the setup script

$ source devel/setup.bash

 Now launch simple_arm:

$ roslaunch simple_arm robot_spawn.launch

Creating the node

Step 1: In order to create a new node in python, you must first create the scripts directory within the simple_arm package.

$ cd ~/catkin_ws/src/simple_arm/
$ mkdir scripts

Step 2: Create scripts inside the script folder, give execution permission to the script

$ cd scripts
$ echo '#!/bin/bash' >> hello
$ echo 'echo Hello World' >> hello
$ chmod u+x hello

Step 3: Rebuild the workspace

$ cd ~/catkin_ws
$ catkin_make

Step 4: Source the setup.bash

$ source devel/setup.bash

Step 5: Use rosrun to run the node

rosrun <package name> <script name>
$ rosrun simple_arm hello

We have created a empty node.