Configuring ROS Environment , Navigating ROS Filesystem and Creating ROS package
Before starting these tutorials please complete installation
configuring ROS Environment:
If you are ever having problems finding or using your ROS packages make sure that you have your environment properly setup. A good way to check is to ensure that environment variables like ROS_ROOT and ROS_PACKAGE_PATH are set :
printenv | grep ROS
If they are not then you might need to 'source' some setup.*sh files.
If you just installed ROS from apt on Ubuntu then you will have setup.*sh files in '/opt/ros/<distro>/', and you could source them like so:
$ source /opt/ros/<distro>/setup.bash
Using the short name of your ROS distribution instead of <distro>
If you installed ROS Melodic, that would be:
source /opt/ros/melodic/setup.bash
You will need to run this command on every new shell you open to have access to the ROS commands, unless you add this line to your .bashrc.
Create a ROS Workspace
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
but when you run catkin_make command then you may get error
ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
CMake Error at /opt/ros/melodic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
execute_process(/usr/bin/python3
"/opt/ros/melodic/share/catkin/cmake/parse_package_xml.py"
"/opt/ros/melodic/share/catkin/cmake/../package.xml"
"/home/vboxuser/catkin_ws/build/catkin/catkin_generated/version/package.cmake")
returned error code 1
Call Stack (most recent call first):
/opt/ros/melodic/share/catkin/cmake/catkin_package_xml.cmake:74 (safe_execute_process)
/opt/ros/melodic/share/catkin/cmake/all.cmake:168 (_catkin_package_xml)
/opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:20 (include)
CMakeLists.txt:58 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/vboxuser/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/vboxuser/catkin_ws/build/CMakeFiles/CMakeError.log".
Makefile:320: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed
To resolve this error we have to install some package which are:
sudo apt-get install python3-catkin-pkg-modules
After installing catkin_pkg
, try running catkin_make
again in your catkin_ws
:
cd ~/catkin_ws
catkin_make
The catkin_make command is a convenience tool for working with catkin workspaces. Running it the first time in your workspace, it will create a CMakeLists.txt link in your 'src' folder.
Python 3 users in ROS Melodic and earlier: note, if you are building ROS from source to achieve Python 3 compatibility, and have setup your system appropriately (ie: have the Python 3 versions of all the required ROS Python packages installed, such as catkin) the first catkin_make command in a clean catkin_workspace must be:
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3
This will configure catkin_make in python 3. You may then proceed to use just catkin_make for subsequent builds.
Additionally, if you look in your current directory you should now have a 'build' and 'devel' folder. Inside the 'devel' folder you can see that there are now several setup.*sh files. Sourcing any of these files will overlay this workspace on top of your environment.
To make sure your workspace is properly overlayed by the setup script, make sure ROS_PACKAGE_PATH environment variable includes the directory you're in.
echo $ROS_PACKAGE_PATH
Navigating the ROS Filesystem
Code is spread across many ROS packages. Navigating with command-line tools such as ls and cd can be very tedious which is why ROS provides tools to help you.
Using rospack
rospack allows you to get information about packages. In this tutorial, we are only going to cover the find option, which returns the path to package.
rospack find [package_name]
#example
rospack find roscpp
Using roscd
roscd is a part of the rosbash suite. It allows you to change directory (cd) directly to a package or a stack.
roscd <package-or-stack>[/subdir]
roscd roscpp
Subdirectories
roscd can also move to a subdirectory of a package or stack.
roscd roscpp/cmake
pwd
roscd log
roscd log will take you to the folder where ROS stores log files. Note that if you have not run any ROS programs yet, this will yield an error saying that it does not yet exist.
If you have run some ROS program before, try:
roscd log
Using rosls
rosls is a part of the rosbash suite. It allows you to ls directly in a package by name rather than by absolute path.
Usage:
rosls roscpp_tutorials
Tab Completion
It can get tedious to type out an entire package name. In the previous example, roscpp_tutorials is a fairly long name. Luckily, some ROS tools support TAB COMPLETION.
After pushing the TAB key, the command line should fill out the rest.
You may have noticed a pattern with the naming of the ROS tools:
rospack = ros + package
roscd = ros + cd
rosls = ros + ls
Creating a ROS Package
catkin package contains package.xml file, CMakeLists.txt and also Each package must have its own folder
my_package/ CMakeLists.txt package.xml
Packages in a catkin Workspace
workspace_folder/ -- WORKSPACE
src/ -- SOURCE SPACE
CMakeLists.txt -- 'Toplevel' CMake file, provided by catkin
package_1/
CMakeLists.txt -- CMakeLists.txt file for package_1
package.xml -- Package manifest for package_1
...
package_n/
CMakeLists.txt -- CMakeLists.txt file for package_n
package.xml -- Package manifest for package_n
Creating a catkin Package
first create the catkin workspace and move into it
cd ~/catkin_ws/src
Now use the catkin_create_pkg script to create a new package called 'beginner_tutorials' which depends on std_msgs, roscpp, and rospy:
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, which have been partially filled out with the information you gave catkin_create_pkg.
catkin_create_pkg requires that you give it a package_name and optionally a list of dependencies on which that package depends:
# This is an example, do not try to run this
# catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
Building a catkin workspace and sourcing the setup file
cd ~/catkin_ws
catkin_make
After the workspace has been built it has created a similar structure in the devel subfolder as you usually find under /opt/ros/$ROSDISTRO_NAME.
To add the workspace to your ROS environment you need to source the generated setup file:
. ~/catkin_ws/devel/setup.bash
package dependencies
1 First-order dependencies :
When using catkin_create_pkg earlier, a few package dependencies were provided. These first-order dependencies can now be reviewed with the rospack tool.
rospack depends1 beginner_tutorials
As you can see, rospack lists the same dependencies that were used as arguments when running catkin_create_pkg. These dependencies for a package are stored in the package.xml file:
roscd beginner_tutorials
cat package.xml
2 Indirect dependencies
In many cases, a dependency will also have its own dependencies. For instance, rospy has other dependencies.
rospack depends1 rospy
A package can have quite a few indirect dependencies. Luckily rospack can recursively determine all nested dependencies.
rospack depends beginner_tutorials
Customizing Your Package
This part of the tutorial will look at each file generated by catkin_create_pkg and describe, line by line, each component of those files and how you can customize them for your package.
Customizing the package.xml
First update the description tag:
Change the description to anything you like, but by convention the first sentence should be short while covering the scope of the package. If it is hard to describe the package in a single sentence then it might need to be broken up.
vim package.xml
Maintainer tags : we have to do the changes in the package.xml file
<maintainer email="you@yourdomain.tld">Your Name</maintainer>
This is a required and important tag for the package.xml because it lets others know who to contact about the package.
license tags
You should choose a license and fill it in here. Some common open source licenses are BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, and LGPLv3.
dependencies tags
All of our listed dependencies have been added as a build_depend for us, in addition to the default buildtool_depend on catkin. In this case we want all of our specified dependencies to be available at build and run time, so we'll add a exec_depend tag for each of them as well.
lets build our package
Building Packages
As long as all of the system dependencies of your package are installed, we can now build your new package.
I hope you guys enjoys the blog do share and like it
want to connect with me ๐๐๐
My Contact Info:
๐ฉEmail:-mayank07082001@gmail.com
LinkedIn:-linkedin.com/in/mayank-sharma-devops
Subscribe to my newsletter
Read articles from Mayank Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mayank Sharma
Mayank Sharma
๐น๐น Enter the world of Maya Hey everyone This is Mayank Sharma , a disciplined ,openminded ,enthusiastic & highly dedicated guy for achieving the excellence in life. For me learning is a never ending process, I believe in ๐๐จ๐ง๐ญ๐ข๐ง๐ฎ๐จ๐ฎ๐ฌ ๐๐๐๐ซ๐ง๐ข๐ง๐ & ๐๐จ๐ง๐ญ๐ข๐ง๐ฎ๐จ๐ฎ๐ฌ ๐๐๐ฏ๐๐ฅ๐จ๐ฉ๐ฆ๐๐ง๐ญ . My goal is to be a successful Professional Engineer by hard work through my knowledge, skills & commitment which will help me grow, explore and excel along with a great team . With a natural curiosity and a talent for problem-solving, I am constantly exploring new ways to innovate the things and improve processes. Mail me ๐ mayank07082001@gmail.com ๐น๐น I am persuing B.Tech in information technology with the specialisation of Artificial Intelligence and robotic from M.I.T.S Gwalior (M.P) . I'm passionate about learning cutting edge technologies & implement them to solve real world problems. I have devoted my time for them & gained experience in the following tools & technologies . ๐ ๐๐ฉ๐๐ซ๐๐ญ๐ข๐ง๐ ๐๐ฒ๐ฌ๐ญ๐๐ฆ : Wษชษดแด แดแดกs, CแดษดแดOS, Rแดแด Hแดแด,Fedora,Ubuntu ๐ ๐๐๐ง๐ ๐ฎ๐๐ ๐๐ฌ : Pสแดสแดษด, Sสแดสส Sแดสษชแดแดษชษดษข, c++, java ๐ ๐๐จ๐ง๐ญ๐๐ข๐ง๐๐ซ ๐๐ง๐ ๐ข๐ง๐ : Dแดแดแดแดส, CRI-O, openshift ๐ ๐๐จ๐ง๐ญ๐๐ข๐ง๐๐ซ ๐๐๐ง๐๐ ๐๐ฆ๐๐ง๐ญ ๐๐จ๐จ๐ฅ๐ฌ : Kแดสแดสษดแดแดแดs ๐ ๐๐ฎ๐ญ๐จ๐ฆ๐๐ญ๐ข๐จ๐ง ๐๐จ๐จ๐ฅ๐ฌ : Aษดsษชสสแด, Gษชแด/GษชแดHแดส ๐ ๐๐ฅ๐จ๐ฎ๐ ๐๐จ๐ฆ๐ฉ๐ฎ๐ญ๐ข๐ง๐ ๐๐ฅ๐๐ญ๐๐จ๐ซ๐ฆ : AWS(EC2,s3,EBs,vpc,loadbalancers,Autosg,rds,cloudwatch,route53, lamda , EFS, snapshot, serverless, EKS) ๐DATABASE : MongoDB, Mysql Also I have worked on Wแดส Dแดแด แดสแดแดแดแดษดแด. I enjoy working on new ideas and helping others in these areas. ๐น๐น Apart from being a technology enthusiast, travelling & photography has remained my constant passion. I always keep a right attitude & try to maintain positive vibe in every situation. I also spend time in playing Cricket & Football. Hence I understand the importance of team play & responsibility of a team player very well. Hobbies: โจI am very interested in cyber security . whatever I see I try to find out the loopholes in it and then try to hack it or trying that how can i breach / break the security โจ I love to see cricket (IPL) also very much interested in playing cricket . โจI also love watching various tv and movie series, Top3 is Money heist, Gangs of wasseypur and comedy movies(like hera pheri) and college related webseries etc.