In today’s video we are going to see how to include a ROS launch file inside of another one, which is really useful specially if you are working with big projects.
But before we start, if you are new to ROS and want to Learn ROS Fast, I recommend you to take any of the following courses on Robot Ignite Academy:
Whether you like the video or not, please leave a comment on the comments section below, so we can interact and learn from each other.
Step1. Create a project in Robot Ignite Academy(RIA)
We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now! We’ll use the TF ROS 101 course as an example today.
Step2. Create a package
With the following command, you can create a package without any dependency from a shell
cd ~/catkin_ws/src
catkin_create_pkg tutorial
Let’s say we want to create a launch file called include_demo.launch to launch another launch file called listener_with_user_data.launch from rospy_tutorial package. We can use the include tag in our launch file like this
Then you run roslaunch tutorial include_demo.launch . You should see the talker nodes launched by the tutorial. You can also specify namespace like following to launch the same file with different namespace multiple times.
This technic is especially useful when you are running a huge project. You can also specify different TF coordinate to the different robot in a similar way.
If you are interested in how to define multiple robot joints coordinates using TF, please check our TF ROS 101 course.
Hello ROS developers! In this post, we will see what CMakeLists.txt is and it’s importance in ROS in just 5 minutes! We’ll see what happens when it’s absent and when it’s improperly modified.
Let’s go!
Step 1: Setup your development environment
I love coding, and I hope you do too. Because of this, we’re going to solve the problem in this section using a pseudo-Python code. Here you go:
def setup_ros_environ(you, ros, docker):
if you.prefer_not_to_embrace_the_cloud_revolution() or not you.want_something_that_works_for_sure():
if ros.is_installed() and ros.version <= 'kinetic' and ros.version < 'crystal':
return "You are good to go; just be ready to spin up a terminal at short notice."
elif docker.is_installed():
return "run docker run -it osrf/ros:kinetic-desktop in your terminal to pull a ROS docker image. "
"Please note: "
"- Docker will “pull” this image if you don’t have it locally already."
"- You need to run this command on every terminal you use in this post, before typing any other command!"
else:
return "Launch a ready-to-go development environment on ROS Development Studio (http://rosds.online) within your browser!"
"Click this link to get your copy of a ready-made ROS project: http://www.rosject.io/l/92ac9a3/"
"To 'open a terminal', pick the Shell app from the Tools menu. "
“Run” the program above, act on the output and proceed to the next section!
Step 2: See what CMakeLists.txt is by getting your hands dirty – on the Shell and/or IDE
Create a package in your catkin workspace (we won’t add any code here since it’s not needed for the demo). If you are using the ROS Development Studio and copied the ROS project, the package is already there!
user:~/catkin_ws/src$ catkin_create_pkg cmakelists_test rospy
Created file cmakelists_test/CMakeLists.txt
Created file cmakelists_test/package.xml
Created folder cmakelists_test/src
Successfully created files in /home/user/catkin_ws/src/cmakelists_test. Please adjust the values in package.xml.
After creating a package, we ought to compile it. But before that, we’ll tamper with the CMakeLists.txt file and see what happens.
Rename CMakeLists.txt to CMakeList.txt. Similar enough and should work, right? Let’s see.
user:~/catkin_ws/src$ cd cmakelists_test/
user:~/catkin_ws/src/cmakelists_test$ mv CMakeLists.txt CMakeList.txt
user:~/catkin_ws/src/cmakelists_test$ cd ../..
user:~/catkin_ws$ catkin_make
...(output truncated)
-- ~~ traversing 1 packages in topological order:
-- ~~ - cmakelists_test
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'cmakelists_test'
-- ==> add_subdirectory(cmakelists_test)
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkin_workspace.cmake:116 (add_subdirectory):
The source directory
/home/user/catkin_ws/src/cmakelists_test
does not contain a CMakeLists.txt file.
Call Stack (most recent call first):
CMakeLists.txt:63 (catkin_workspace)
-- Configuring incomplete, errors occurred!
See also "/home/user/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/user/catkin_ws/build/CMakeFiles/CMakeError.log".
Invoking "cmake" failed
Didn’t work for sure. Let’s perform another dastardly act:
2. Restore the original name but comment out the ‘project’ directive of the CMakeLists.txt file shown below:
cmake_minimum_required(VERSION 2.8.3)
# project(cmakelists_test) --> comment out this line
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
user:~/catkin_ws$ cd src/
user:~/catkin_ws/src$ cd cmakelists_test/
user:~/catkin_ws/src/cmakelists_test$ mv CMakeList.txt CMakeLists.txt
user:~/catkin_ws/src/cmakelists_test$ cd ../..
user:~/catkin_ws$ catkin_make
... (output truncated)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - cmakelists_test
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'cmakelists_test'
-- ==> add_subdirectory(cmakelists_test)
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkin_package.cmake:91 (message):
catkin_package() PROJECT_NAME is set to 'Project', which is not a valid
project name. You must call project() before calling catkin_package().
Call Stack (most recent call first):
cmakelists_test/CMakeLists.txt:103 (catkin_package)
-- Configuring incomplete, errors occurred!
See also "/home/user/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/user/catkin_ws/build/CMakeFiles/CMakeError.log".
Makefile:318: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed
We aren’t getting away with tampering with CMakeLists.txt, are we? Now, let’s repent and restore the file: remove the comment from the ‘project’ directive, save and run catkin_make again.
cmake_minimum_required(VERSION 2.8.3)
project(cmakelists_test) --> uncomment this line
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
user:~/catkin_ws$ catkin_make
... (output truncated)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - cmakelists_test
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'cmakelists_test'
-- ==> add_subdirectory(cmakelists_test)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/catkin_ws/build
####
#### Running command: "make -j2 -l2" in "/home/user/catkin_ws/build"
####
Moral lesson:CMakeLists.txt can make or mar a project, if not properly modified. Let’s talk more about that in the next section.
Step 3: Master the concept – what is CMakeLists.txt?
According to ROS Wiki (http://wiki.ros.org/catkin/CMakeLists.txt),
The file CMakeLists.txt is the input to the CMake build system for building software packages. Any CMake-compliant package contains one or more CMakeLists.txt file that describe how to build the code and where to install it to.
Well, now you can see why renaming the file isn’t a good idea. But what about commenting out parts of the file? Also according to ROS Wiki:
Your CMakeLists.txt file MUST follow this format otherwise your packages will not build correctly. The order in the configuration DOES count.
The configuration directives in CMakeLists.txt must follow a particular order; this is why commenting out the ‘project’ directive didn’t work, as the error message also hinted.
Visit http://wiki.ros.org/catkin/CMakeLists.txt to learn more.
We’re done here.
Extra: Video
Prefer “sights and sounds” to “black and white”? We have a video covering this same post, just for you!
Followup and Feedback
If you are a ROS beginner and want to learn ROS basics fast, we recommend you take any of the following courses on Robot Ignite Academy:
Whether you like the video or not, or if you want to learn about specific ROS subjects, please leave a comment on the comments section below, so we can interact and learn from each other.
Step1. Create a project in Robot Ignite Academy(RIA)
We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now!
Step2. Create a package
We’ll go to the ROS in 5 Days(C++) course today. Let’s go to 2nd part-ROS Basics and start by creating a package
cd ~/catkin_ws/src
catkin_create_pkg my_package rospy
With the command, ROS will create a package with the CMakeLists.txt and package.xml files automatically for compiling and building. The package is the basic building block for ROS project. Basically, every ROS application is built with packages. Take the following command as an example
roslaunch turtlebot_teleop keyboard_teleop.launch
Where the turtlebot_teleop is a ROS package and keyboard_teleop.launch is a launch file in this package.
In the RIA, all the packages you’ll need is already installed for you. The only thing you need to do is focus on learning ROS!
Hello ROS Developers! In this post, we will see what the ROS parameter server is in less than 5 minutes! We’ll see what it entails and some of the commands we can use to work with it within the ROS system.
Let’s go!
Step 1: Setup your development environment
To follow this post, you need a computer with ROS already installed. There are three options, but I strongly recommend option 3 as it’s the easiest and the only one I can guarantee will work. That’s the option I’m using for this post.
You have ROS installed locally, such that kinetic <= version < crystal. Good to go; just be ready to spin up a terminal.
You don’t have ROS installed but you have docker: run docker run -it osrf/ros:kinetic-desktop in your terminal to pull a ROS docker image. Please note:
Docker will “pull” this image if you don’t have it locally already.
You need to run this command on every terminal you use in this post, before typing any other command!
Neither ROS nor docker is installed? No problem – launch a ready-to-go development environment on ROS Development Studio (ROSDS) within your browser! If you don’t have an account yet, you can create a free account. Once you log in, create a project and call it rosparam_demo. In your project configuration, select Ubuntu 16.04 + ROS Kinetic + Gazebo 7. To “open a terminal”, pick the Shell app from the Tools menu.
Step 2: Run some commands to learn about the ROS Parameter Server
Open a terminal and run the following command:
user:~$ rosparam list
ERROR: Unable to communicate with master!
I got my fingers burned while trying that command…ouch! The parameter server is part of the ROS master, so we need to get it started first. If you didn’t get your fingers burned, then you “cheated” – you had the ROS master running previously 🙂 .
Now let’s do the right thing by starting the master first. In another terminal, run
user:~$ roscore
...
started roslaunch server http://instance:45696/
ros_comm version 1.12.14
SUMMARY
========
PARAMETERS
* /rosdistro: kinetic
* /rosversion: 1.12.14
NODES
auto-starting new master
process[master]: started with pid [22611]
...
We can already see two parameters listed under the heading “PARAMETERS”: /rosdistro and /rosversion, from the output of the command above. But back up there and let’s rerun the “finger-burning” command:
user:~$ rosparam list
ERROR: Unable to communicate with master!
user:~$ rosparam list
/rosdistro
/roslaunch/uris/host_instance__45696
/rosversion
/run_id
Great, now I got away with my fingers intact, and here we have a list of all current ROS parameters, including the ones mentioned earlier in the roscore command output. Next, let’s explore another sub-command of rosparam: get.
user:~$ rosparam get /roslaunch/uris/host_instance__45696
http://instance:45696/
user:~$ rosparam get /roslaunch/uris/
{host_instance__45696: 'http://instance:45696/'}
user:~$ rosparam get /roslaunch
uris: {host_instance__45696: 'http://instance:45696/'}
I decided to get one of the params from the list command that demonstrates that ROS parameters can be stored and retrieved in hierarchies, to store related parameters and to prevent parameter names from colliding.
Finally, let’s explore one more command: set.
user:~$ rosparam set /our_own_param "learning ROS params"
user:~$ rosparam list
/our_own_param
/rosdistro
/roslaunch/uris/host_instance__45696
/rosversion
/run_id
user:~$ rosparam get /our_own_param
learning ROS params
You get the gist! Finally, here’s a list of commands available for working with ROS parameters; have fun exploring them!
user:~$ rosparam -h
rosparam is a command-line tool for getting, setting, and del
eting parameters from the ROS Parameter Server.
Commands:
rosparam set set parameter
rosparam get get parameter
rosparam load load parameters from file
rosparam dump dump parameters to file
rosparam delete delete parameter
rosparam list list parameter names
And that’s it! Now’s let wrap up by doing some “small talk” about the topic.
Step 3: Master the concept – what is ROS Parameter Server?
I believe that by now you know what the ROS parameter server is in practice. In theory, according to ROS Wiki, “A parameter server is a shared, multi-variate dictionary that is accessible via network APIs. Nodes use this server to store and retrieve parameters at runtime.”
You can use the parameter server to store data that you want to access ‘globally’ from your ROS code. Since it exists on the ROS master, it’s available to all nodes and all machines connected to the master.
You can read more about the parameter server from the ROS Wiki: http://wiki.ros.org/Parameter%20Server.
endsmalltalk.
Extra: Video
Not a “postworm” and prefer to see the ‘sights and sounds’ version of this post? We made this video just for you!
Did you like this post? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other. Thank you!
Hello ROS Developers! In this ROS in 5 min tutorial, we’re going to see what catkin_make is, how it works, and what its advantages are.
For that, we are going to use Robot Ignite Academy.
But before we start, if you are new to ROS and want to Learn ROS fast, I recommend that you take any of the following courses in Robot Ignite Academy:
Whether you like the video or not, or if you want to learn about specific ROS subjects, please leave a comment in the comments section below, so we can interact and learn from each other.
ROS Basics for Beginners (Python)
ROS Basics for Beginners (C++)
Question: What is catkin_make
Step1. Create a project in Robot Ignite Academy(RIA)
We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now!
Step2. Create a package
Almost all the package you will need is already installed in RIA. We’ll create the package in the ROS Autonomous Vehicles 101 course as an example in this video, but you can choose any course you want to do this.
Please type the following command in shell to create a new package
cd ~/catkin_ws/src
catkin_create_pkg test roscpp
Step3. Compile the package with catkin_make
Now you can type catkin_make to compile the package.
cd ..
catkin_make
It shows a lot of outputs, but what did it really do?
The catkin_make is actually a macro which creates directories and runs cmake command for you. If you want to do it yourself, just delete the build and devel directories first.
rm -rf build/ devel/
Now you can create a build directory and run the cmake command by yourself to get the exact same result as catkin_make did.