Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ROS how to find all executables of a package?

Tags:

ros

I want to ask how to find all the executable names of a package in ROS (Robot Operating System)? For example, find spawn_model in gazebo_ros package. When I inspect the package in my system, it just shows some .xml, .cmake files, without any executables. But I can run it, such as: rosrun gazebo_ros spawn_model.

Thank you!

like image 983
Zhenjie Zhao Avatar asked Jul 03 '16 13:07

Zhenjie Zhao


People also ask

Where are the executables ROS?

ROS executables are installed in a per-package directory, not the distributions's global bin/ directory. There, they are accessible to rosrun and roslaunch, without cluttering up the shell's $PATH, and their names only need to be unique within each package.

How do I check my ROS package?

Each package might contain a mixture of code (e.g. ROS nodes), data, libraries, images, documentation, etc. Every program you write in ROS will need to be inside a package. To find the path of a package, you use the rospack command.

What is a ROS package?

A ROS package is simply a directory descended from ROS_PACKAGE_PATH (see ROS Environment Variables) that has a package. xml file in it. Packages are the most atomic unit of build and the unit of release.


2 Answers

An easy way to do this is to type: "rosrun name_of_package " and then press tab two times, it should show you all the executables built.

like image 83
Fabiobreo Avatar answered Nov 21 '22 20:11

Fabiobreo


After looking in the bash autocompletion script for rosrun, it looks like the command catkin_find is used to find the location of the executables for a package, and the executables are filtered with a find command.

If you want to create a script to give you a list of the executables follow the instructions below:

Save the following script in a file called rospack-list-executables:

#!/bin/bash

if [[ $# -lt 1 ]]; then
    echo "usage: $(basename $0) <pkg_name>"
    echo ""
    echo "       To get a list of all package names use the command"
    echo "          'rospack list-names'"
    exit
fi

pkgname=${1}

pkgdir="$(catkin_find --first-only --without-underlays --libexec ${pkgname})"


if [[ -n "${pkgdir}" ]]; then
    find -L "${pkgdir}" -executable -type f ! -regex ".*/[.].*" ! -regex ".*${pkgdir}\/build\/.*" -print0 | tr '\000' '\n' | sed -e "s/.*\/\(.*\)/\1/g" | sort
else
    echo "Cannot find executables for package '${pkgname}'." >&2
    exit 1
fi

Then make the rospack-list-executables script executable (chmod +x rospack-list-executables) and place it in a directory that can be found in your $PATH environment variable.

Run the script:

$ rospack-list-executables gazebo_ros
debug
gazebo
gdbrun
gzclient
gzserver
libcommon.sh
perf
spawn_model

You should get the same result that you get when you type the rosrun <pkgname> command and press Tab:

$ rosrun gazebo_ros 
debug         gazebo        gdbrun        gzclient      gzserver      libcommon.sh  perf          spawn_model

You can check the executables for all packages with the following bash code:

rospack list-names | while read pkgname; do
    echo "Executables for package '${pkgname}':";
    rospack-list-executables $pkgname; echo "";
done

To enable package autocompletion for your newly created command, type the following:

complete -F _roscomplete rospack-list-executables

If you do not want to have to type the complete command every time you login, you can append it to your .bashrc file:

echo "complete -F _roscomplete rospack-list-executables" >> ~/.bashrc

Now when you type the command rospack-list-executables and press the Tab key, you should get a list of all the available packages to choose from.

like image 39
Vangelis Tasoulas Avatar answered Nov 21 '22 18:11

Vangelis Tasoulas