Common ROS Package Commands in ROS Noetic

Locate the Package on Your Computer

Here are some common ROS package commands.

rospack find [name of package]

For example, 

rospack find noetic_basics_part_1
6-locate-packageJPG

Note that you can type only the first letter or two of the name of the package and press the Tab button on your keyboard, and the system will automatically complete the rest of command. For example, type:

rospack find noe

Then press the Tab button, and press Enter.

You should see the directory where the noetic_basics_part_1 package is located.

Determine What Packages a Package Depends on

To determine the dependencies of a package, you need to make sure you have rosdep installed. You only need to do this one time after you’ve installed ROS Noetic.

First we need to install rosdep.

sudo apt-get install python3-rosdep

Now initialize rosdep.

sudo rosdep init

Now update rosdep.

rosdep update

That’s it. You only need to do that process once for your ROS Noetic installation.

7-thats-itJPG

Now, let’s find out the dependencies of our newly built noetic_basics_part_1 package.

rospack depends [name of package]

For example, to find the dependencies of the noetic_basics_part_1 package, we write:

rospack depends noetic_basics_part_1
8-dependencies-of-packageJPG

You can see our package depends on a lot of stuff. It depends on std_msgs and roscpp, as we expected. However, there are other packages which are added as dependencies by default.

How to Build a Package in ROS Noetic

Let’s say that you write a bunch of code inside your noetic_basics_part_1 package as well as other packages inside your workspace.

You now need to build the packages. “Building” the packages means compiling all the code you’ve written as well as the code generated by ROS’s processes. This process makes sure that all that code you wrote can be properly executed within ROS.

To build all your packages in your catkin workspace, you execute the following commands in a new terminal window.

cd ~/catkin_ws/
catkin_make

How to Create a New Package in ROS Noetic

To create a package in ROS, you use the catkin_create_pkg command followed by your desired name for the package and then a list of any packages that your package depends on.

Here is the syntax:

catkin_create_pkg <package_name> [depend1] [depend2] [depend3]

For example, let’s create a new package named noetic_basics_part_1 that depends on two packages, std_msgs (a package for handling common data types like integers, strings, and arrays) and roscpp (the standard C++ package for ROS).

In a new terminal window, move to the src (source) folder of your workspace.

cd ~/catkin_ws/src

Now create the package.

catkin_create_pkg noetic_basics_part_1 std_msgs roscpp
4-create-new-packageJPG

If you go inside the package, you’ll see we have all the basic files of a ROS package.

5-all-the-basic-filesJPG
  • CMakeLists.txt (contains the commands to build the ROS source code inside the noetic_basics_part_1 package)
  • include (where the package header files are located)
  • package.xml (contains descriptive information about the package)
  • src (the folder that will contain your C++ source code…note that if you write Python code, you’ll want to create another folder inside the package named scripts).