Welcome to this new post about ROS. In today’s post, we are going to learn what is the ROS_PACKAGE_PATH variable and how it is used by the ROS ecosystem.
The commands used here can be executed in your own computer if you have ROS installed, but for simplicity, we are going to use Robot Ignite Academy.
Before we start, if you are new to ROS, I highly recommend you taking the following course:
In a computer with ROS installed, we have many variables with the ROS_ prefix. If we run env | grep ROS , for example, we may have something like the output below:
Among these variables we can find the one we are looking for: ROS_PACKAGE_PATH
This variable is used by ROS in order to find ROS Packages. To better understand this, let’s consider the command below, used to control robots using the keyboard:
roslaunch turtlebot_teleop keyboard_teleop.launch
The first parameter of the roslaunch command is the package name, which in this case is turtlebot_teleop .
When we run the command exemplified above, in order to find the turtlebot_teleop package, ROS will look for the ROS_PACKAGE_PATH variable.
If we run roscd turtlebot_teleop to enter on the that package, for instance, on Robot Ignite Academy the package is located at /home/simulations/public_sim_ws/src/all/turtlebot/turtlebot_teleop as can be seen below:
If you look carefully, you can notice that the turtlebot_telop package is on the “Public Simulations Workspace”, which is /home/simulations/public_sim_ws/src. Now, with a closer look at the ROS_PACKAGE_PATH variable, we can find that path on it:
So, the turtlebot_teleop package only was found because its workspace path is set on ROS_PACKAGE_PATH.
If we unset that variable and try to roscd on that package again, it is not going to work, as can be seen with the commands unset ROS_PACKAGE_PATH and roscd turtlebot_teleop.
user:~$ cd
user:~$ unset ROS_PACKAGE_PATH
user:~$ roscd turtlebot_teleop
roscd: No such package/stack 'turtlebot_teleop'
Here we can see that ROS wasn’t able to find the package. If we look at the ROS_ prefixed environment variables again, we won’t find ROS_PACKAGE_PATH:
If we source our catkin_ws again with source ~/catkin_ws/devel/setup.bash, the variable will be exported and ROS will be able to find the package again:
Now let’s go a bit further and create a package in a place that nobody would do it. We are going to create it in the /tmp folder, just to let you better understand the importance of ROS_PACKAGE_PATH.
We can use the cd /tmp/ and catkin_create_pkg tutorial_package commands to achieve that:
user:~$ cd /tmp/
user:/tmp$ catkin_create_pkg tutorial_package
Created file tutorial_package/package.xml
Created file tutorial_package/CMakeLists.txt
Successfully created files in /tmp/tutorial_package. Please adjust the values in package.xml.
We can clearly see that the package was created in /tmp/tutorial_package, but if we try to navigate to it using roscd tutorial_package, ROS won’t be able to find it:
user:/tmp$ roscd tutorial_package
roscd: No such package/stack 'tutorial_package'
That happens because the /tmp folder is not on the ROS_PACKAGE_PATH variable. We can easily add it using the next command:
export ROS_PACKAGE_PATH=/tmp:$ROS_PACKAGE_PATH
Now if we check the value of the variable with env | grep ROS_P , we can find /tmp there:
So easy to understand the ROS_PACKAGE_PATH variable, isn’t it?
Remember that we also have a video version of this post on YouTube:
I hope you liked the post (and the video), if that is the case, please consider subscribing to our channel on YouTube. Additionally, should you have any questions or suggestions, please leave your comment on the comments section of the video.
In this video, we will see what rosed is, and how to use and configure it, in less than five minutes! We’ll be using a very simple sample package to demonstrate this.
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:
Please make sure you follow that post first since the client we will create here will call that server.
Creating the ROS Action Client
If you followed the post on how to create an Action Server, we should have the following output after running the tree . command on the ~/catkin_ws/srcfolder.
As you can see we have a scripts folder with our action_server.py there. We will create our action_client.py in the same folder. Let’s use the commands below for that:
cd ~/catkin_ws/src/actions_tutorial/scripts/
touch action_client.py
chmod +x action_client.py
With the code above we created an empty python file and gave it execute permissions. With the tree ~/catkin_ws/src command you should have something like:
Now let’s paste the following code on the action_client.py file:
#! /usr/bin/env python
import rospy
import actionlib
from actions_tutorial.msg import WashTheDishesAction, WashTheDishesGoal
def feedback_cb(msg):
print 'Feedback received:', msg
def call_server():
client = actionlib.SimpleActionClient('wash_dishes_as', WashTheDishesAction)
client.wait_for_server()
goal = WashTheDishesGoal()
goal.number_of_minutes = 7
client.send_goal(goal, feedback_cb=feedback_cb)
client.wait_for_result()
result = client.get_result()
return result
if __name__ == '__main__':
try:
rospy.init_node('action_client')
result = call_server()
print 'The result is:', result
except rospy.ROSInterruptException as e:
print 'Something went wrong:', e
In this file what we do is basically call the Action Server defined in the previous post and print the feedback and the result messages sent by the server.
Running the ROS Action Client
With everything in place, let’s now launch our server and our client and see they work together. To launch the server we can use the command below:
So, congratulations, you now know how to create an Action Server as well as an Action Client.
To make your life easier, we have also prepared a video showing all the process explained in this post.
I hope you have enjoyed the post and the video, if so, please consider giving us a thumbs up. You can also subscribe to our channel and press the bell so that you won’t miss our updates.
We love feedback, so, whether you like the video or not, please share your thoughts on the comments section of the video.
In this post, we will see what a ROS Action is. We’ll also see the difference between a ROS Service and a ROS Action.
Let’s go!
Step 1: Understand blocking and non-blocking activities: two possible ways to buy Pizza
Let’s assume you wish to order some pizza. There are two possible ways you could go about it:
Go the Pizza shop
Place your order.
Wait for the order.
Get the Pizza.
Order online.
Place your order.
Order confirmation notice.
Possibly cancel the order.
Check up your order status once in a while.
Do other things.
Pizza is delivered.
Option 1 is a blocking activity because you have to wait (in theory not able to do anything else) for the pizza, while option 2 is non-blocking because you can do some other things while your order is being processed.
Step 2: Apply blocking and non-blocking concept to ROS
Option 1 (Going to Pizza shop) is similar to a ROS Service, while option 2 is similar to a ROS Action. Not 100% the same, but I suppose you get the point. But what is a ROS Action specifically, in ROS terminology?
An action is an asynchronous call to another node’s functionality. “Asynchronous” means you don’t have to wait for the result. You can do other things pending the result.
The node that provides the functionality has to implement an Action Server (Pizza shop). The node that uses the functionality has to use an Action Client (online ordering system).
Step 3: Dive a bit deeper – ROSified pizza ordering
Now, let’s see what ROS calls each of the steps for buying pizza:
Go the Pizza shop
Place your order (request).
Wait for the order.
Get the Pizza (response).
Order online
Place your order (request).
Order confirmation notice (feedback).
Possibly cancel the order (cancel).
Check up your order status once in a while (status).
Do other things.
Pizza is delivered (response).
To wrap up, consider the image below, saying roughly saying the same thing we have been saying, only in a “thousand words”:
Extra: Video
Prefer to listen to the “sights and sounds” version of this post? We have one for you below; happy watching!
Further Learning
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: