Embedded Motion Control/Tutorials/Creating a ROS package: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
 
(6 intermediate revisions by one other user not shown)
Line 52: Line 52:
:<pre>~/ros/emc/emc<YOUR_GROUP_NR>/beginner_tutorials_<YOUR_NAME></pre>
:<pre>~/ros/emc/emc<YOUR_GROUP_NR>/beginner_tutorials_<YOUR_NAME></pre>


If this fails, it means ROS can't find your new package, which may be an issue with your ROS_PACKAGE_PATH. Make sure you correctly followed the steps in [ Embedded Motion Control/Tutorials/Installing and configuring your ROS environment#Environment Set-up | this previous tutorial ].
If this fails, it means ROS can't find your new package, which may be an issue with your ROS_PACKAGE_PATH. Make sure you correctly followed the steps in [[ Embedded Motion Control/Tutorials/Installing and configuring your ROS environment#Environment Set-up | this previous tutorial ]].


Try moving to the directory for the package.
Try moving to the directory for the package.


<pre>
<pre>
roscd beginner_tutorials
roscd beginner_tutorials_<YOUR_NAME>
pwd
pwd
</pre>
</pre>
Line 63: Line 63:
Results in:  
Results in:  


:<pre>YOUR_PACKAGE_PATH/beginner_tutorials</pre>
:<pre>/home<YOUR_NAME>/ros/emc/emc<YOUR_GROUP_NR>/beginner_tutorials_<YOUR_NAME></pre>


= First-order package dependencies =
= First-order package dependencies =
When using roscreate-pkg earlier, a few package dependencies were provided. These first-order dependencies can now be reviewed with the rospack tool.
When using roscreate-pkg earlier, a few package dependencies were provided. These first-order dependencies can now be reviewed with the ''rospack'' tool.


<pre>rospack depends1 beginner_tutorials_<YOUR_NAME> </pre>


(Jan 9, 2013) There is a bug reported and already fixed in rospack in groovy; it may take some time to be reflected in the packages. If you see an issue similar to this with the next command, you can skip to the following command.
Result in:


 
<pre>
$ rospack depends1 beginner_tutorials
std_msgs
std_msgs
rospy
rospy
roscpp
roscpp
As you can see, rospack lists the same dependencies that were used as arguments when running roscreate-pkg. These dependencies for a package are stored in the manifest file. Take a look at the manifest file.
</pre>


As you can see, rospack lists the same dependencies that were used as arguments when running ''roscreate-pkg''. These dependencies for a package are stored in the manifest file. Take a look at the manifest file.


$ roscd beginner_tutorials
<pre>
$ cat manifest.xml
roscd beginner_tutorials<YOUR_NAME>
cat manifest.xml
</pre>
 
Gives:
 
<pre>
<package>
<package>


Line 90: Line 97:


</package>
</package>
</pre>
= Indirect package dependencies  =
= Indirect package dependencies  =
In many cases, a dependency will also have its own dependencies. For instance, rospy has other dependencies.
In many cases, a dependency will also have its own dependencies. For instance, rospy has other dependencies.


<pre>rospack depends1 rospy</pre>


(Jan 9, 2013) There is a bug reported and already fixed in rospack in groovy; it may take some time to be reflected in the packages. If you see an issue similar to this with the next command, you can skip to the following command.
Results in:


 
<pre>
$ rospack depends1 rospy
roslib
roslib
roslang
roslang
A package can have quite a few indirect dependencies. Luckily rospack can recursively determine all nested dependencies.
</pre>


$ rospack depends beginner_tutorials
A package can have quite a few indirect dependencies. Luckily ''rospack'' can recursively determine all nested dependencies.
 
<pre>rospack depends beginner_tutorials_<YOUR_NAME></pre>
 
<pre>
cpp_common
rostime
roscpp_traits
roscpp_serialization
genmsg
genpy
message_runtime
std_msgs
rosgraph
rosgraph_msgs
catkin
rospack
rospack
roslib
roslib
std_msgs
rosgraph_msgs
rosbuild
roslang
rospy
rospy
cpp_common
rosconsole
roscpp_traits
rostime
roscpp_serialization
xmlrpcpp
xmlrpcpp
rosconsole
roscpp
roscpp
Note: in Fuerte, the list is much shorter:
</pre>


std_msgs
roslang
rospy
roscpp
= ROS Client Libraries  =
= ROS Client Libraries  =
You may be wondering what rospy and roscpp dependencies are from the previous examples. rospy and roscpp are Client Libraries. The client libraries allow different programming languages to communicate through ROS. rospy is the client library for Python. roscpp is the client library for C++.
You may be wondering what rospy and roscpp dependencies are from the previous examples. rospy and roscpp are [http://wiki.ros.org/Client%20Libraries Client Libraries]. The client libraries allow different programming languages to communicate through ROS. rospy is the client library for Python. roscpp is the client library for C++.


= Review =
= Review =
Line 133: Line 145:
rosstack = ros+stack : provides information related to ROS stacks
rosstack = ros+stack : provides information related to ROS stacks


Now that you've made a new ROS package, let's build our ROS package.
Now that you've made a new ROS package, let's see how we can [[Embedded Motion Control/Tutorials/Using Subversion to share and manage your project | use an SVN to share it among different systems with version history]].

Latest revision as of 20:08, 29 April 2014

Description: This tutorial covers using roscreate-pkg or catkin to create a new package, and rospack to list package dependencies.

Using roscreate

Before we create a package, let's see how the roscreate-pkg command-line tool works. This creates a new ROS package. All ROS packages consist of the many similar files : manifests, CMakeLists.txt, mainpage.dox, and Makefiles. roscreate-pkg eliminates many tedious tasks of creating a new package by hand, and eliminates common errors caused by hand-typing build files and manifests.

To create a new package in the current directory:

roscreate-pkg [package_name]

You can also specify dependencies of that package:

roscreate-pkg [package_name] [depend1] [depend2] [depend3]

Creating a New ROS Package

Now we're going to go into your home or project directory and create our beginner_tutorials package. We are going to make it depend on std_msgs, roscpp, and rospy, which are common ROS packages.

Now go your EMC group directory:

cd ~/ros/emc/emc<YOUR_GROUP_NR>

We can now use roscreate-pkg to create our first ROS package. However, there is a small problem: every package in ROS must have a unique name. This means if you and your group members all use the same package name and share these packages using the SVN, ROS won't know which of the packages to use. Therefore, create a package with a unique name:

roscreate-pkg beginner_tutorials_<YOUR_NAME> std_msgs rospy roscpp

You will see something similar to:

Created package directory /home/sdries/ros/emc/emc01/beginner_tutorials_sjoerd
Created include directory /home/sdries/ros/emc/emc01/beginner_tutorials_sjoerd/include/beginner_tutorials_sjoerd
Created cpp source directory /home/sdries/ros/emc/emc01/beginner_tutorials_sjoerd/src
Created package file /home/sdries/ros/emc/emc01/beginner_tutorials_sjoerd/Makefile
Created package file /home/sdries/ros/emc/emc01/beginner_tutorials_sjoerd/manifest.xml
Created package file /home/sdries/ros/emc/emc01/beginner_tutorials_sjoerd/CMakeLists.txt
Created package file /home/sdries/ros/emc/emc01/beginner_tutorials_sjoerd/mainpage.dox

Please edit beginner_tutorials_sjoerd/manifest.xml and mainpage.dox to finish creating your package

You're going to want to spend some time looking at the manifest.xml file in your newly created package. Manifests play an important role in ROS as they define how packages are built, run, and documented.

Now lets make sure that ROS can find your new package. It is often useful to call rospack profile after making changes to your path so that new directories will be indexed:

rospack profile
rospack find beginner_tutorials_<YOUR_NAME>

Should result in:

~/ros/emc/emc<YOUR_GROUP_NR>/beginner_tutorials_<YOUR_NAME>

If this fails, it means ROS can't find your new package, which may be an issue with your ROS_PACKAGE_PATH. Make sure you correctly followed the steps in this previous tutorial .

Try moving to the directory for the package.

roscd beginner_tutorials_<YOUR_NAME> 
pwd

Results in:

/home<YOUR_NAME>/ros/emc/emc<YOUR_GROUP_NR>/beginner_tutorials_<YOUR_NAME>

First-order package dependencies

When using roscreate-pkg earlier, a few package dependencies were provided. These first-order dependencies can now be reviewed with the rospack tool.

rospack depends1 beginner_tutorials_<YOUR_NAME> 

Result in:

std_msgs
rospy
roscpp

As you can see, rospack lists the same dependencies that were used as arguments when running roscreate-pkg. These dependencies for a package are stored in the manifest file. Take a look at the manifest file.

roscd beginner_tutorials<YOUR_NAME>
cat manifest.xml

Gives:

<package>

...

  <depend package="std_msgs"/>
  <depend package="rospy"/>
  <depend package="roscpp"/>

</package>

Indirect package dependencies

In many cases, a dependency will also have its own dependencies. For instance, rospy has other dependencies.

rospack depends1 rospy

Results in:

roslib
roslang

A package can have quite a few indirect dependencies. Luckily rospack can recursively determine all nested dependencies.

rospack depends beginner_tutorials_<YOUR_NAME>
cpp_common
rostime
roscpp_traits
roscpp_serialization
genmsg
genpy
message_runtime
std_msgs
rosgraph
rosgraph_msgs
catkin
rospack
roslib
rospy
rosconsole
xmlrpcpp
roscpp

ROS Client Libraries

You may be wondering what rospy and roscpp dependencies are from the previous examples. rospy and roscpp are Client Libraries. The client libraries allow different programming languages to communicate through ROS. rospy is the client library for Python. roscpp is the client library for C++.

Review

Lets just list some of the commands we've used so far:

roscreate-pkg = ros+create-pkg : generates all the files needed to create a ROS package rospack = ros+pack(age) : provides information related to ROS packages rosstack = ros+stack : provides information related to ROS stacks

Now that you've made a new ROS package, let's see how we can use an SVN to share it among different systems with version history.