So in the last two lectures, we are able to create our very own RAS nodes, which are able to communicate
with each other using publisher and subscriber Python scripts.
After writing the Python code, we would open a terminal, go into the scripts folder in our package
and run the Python terminal command followed by our script name.
Well, there's a better way to go about doing this.
In this lecture, we will be configuring our package so that we can run our node from any location in
the terminal.
When we created our package earlier in the course, we had to specify the build type which we specified
as amend make.
This tells Ros to compile our package based on instructions specified in our packages.
See make list, text file, see, make list files which are generally used for compiling C and C++ code.
So this may seem unfamiliar to some of you, and that's okay.
Since we will cover what you need to know to help with your ROS development.
Let's get to it.
When we created our package, we had to specify the build type, which we specified as a meant to make.
What we are telling the compiler is that we will compile our package based on instructions specified
in our make list text file.
So let's go ahead and configure our package to include our Python nodes.
In Visual Studio code, I will open up our package XML file and make list text file.
So let's go ahead and configure our package XML file.
I will add build tool dependencies for MNC.
Make and amend.
See make python.
And I will add our RC LP library as a dependency.
All right.
I'll go ahead and save this package on XML file and move on to our make list text file.
Here, I will add our packages for amend c, make python and rcl py using the find packages function.
Now I know this make list text file can seem a little confusing and daunting at first, but trust me,
we'll get used to this as we utilize it throughout the course.
I meant Python needs to be pointed to a python package.
A python package is simply a folder that has a init python file.
In this case, we want our python package to be our scripts folder so I will create a new file in our
scripts folder called underscore.
Underscore in it.
Underscore underscore dot pi.
Now I don't need to put anything in this file so I can just close it.
Now that our scripts folder looks like a Python package, we can configure it by using the meant python
install command followed by the folder name, which is scripts.
Then lastly, we need to specify our individual Python nodes.
We do this with the install function.
Use the programs keyword.
Followed by the location of the script.
And then we set the destination for our workspace to place it.
In this case, we'll need to put it in the lib folder, followed by our package name.
And the last thing in our make list text file should always be this amount package function, so don't
put code below this line as it will not get properly called when we build our project.
Be sure to save this file when you're done editing.
And now there's actually one more thing we need to do.
Since Cement C make is primarily meant to run a C++ code, we have to tell Ros how we want this script
to be executed.
We do this by opening up our Python scripts that we want to run with Ros and then at the top add a Unix
shebang character sequence, which is the pound sign followed by an exclamation mark, and then point
it to our python three environment for Ubuntu.
This will be located at forward slash us r forward slash bin forward slash in v space.
Python three.
We will have to do this for all of our python scripts.
So would that be sure to save the changes you've made to all these files?
And now if we go ahead and open up a terminal.
I'll go ahead and clear the screen.
And now we'll go ahead and change into our workspace directory here.
So I'll go back a few directories.
And now we can run our calc and build command.
Well, and it seems I ran into an error with using the immense python install package.
Command says target may not contain a slash, so I must have accidentally included a slash when I was
implementing the script folder name.
So go ahead and get rid of the slash in this function call.
Save it.
And now if I go ahead and clear the screen and rerun that Culkin build command.
We see it builds successfully.
Once it's built, we can source the setup file in the install directory.
Now we can check that we configured our package properly by using the ROS to package executables command
and we will specify our package, which in this case is Udemy ROS package.
Here we see a list of executables available in these packages, which in this case is our publisher
API and subscriber pie notes.
Now we can run our nodes using the RAS to run command to launch our publisher node.
Just run RAS to run Udemy RAS two package publisher PI and we see our publisher node running as we did
when we ran it using the Python three command.
Just to show you that this works for our subscriber node as well.
I will open a new terminal tab and again I'll have to source that install setup file.
Since this is a new environment and run our subscriber script.
And here we are receiving the messages in our subscriber node that are being published over here by
our publisher Node.
So I can go ahead and stop these with control C.
So here we are able to run our Python scripts using the ROS to run command because we configured our
package.
This way we can distribute the package to other developers and they can easily run the scripts like
so.
OC.
We got our nodes to properly compile by modifying our make lists, text file and packaged XML files.
Most popular ROS packages use C++ so it's good to get you better situated to this way of building ROS
packages so you can understand the format when you use other packages.
But it's worth noting there is another way to compile our package.
There's a second build type called Amend Python, which is generally used if your package is solely
composed of Python scripts.
This will make our package show more resemblance to that of a standard Python package.
But note the downside of this method is it does not allow you to use any C++ nodes in your ROS package.
Should you want to include C++ code later on down the line.
This is one of the reasons why I recommend using the C make build type.
I will go ahead and show you this layout anyway on a new package so that you are aware of it in case
you see other developers using this build type.
So I'll go ahead and clear the screens.
I'll actually close the second terminal and then I'll head over to the source folder of this workspace.
All right.
So here we see our original Udemy Ross two package, which is now configured with our make list text
file.
And now instead, I'm going to create a new package which I will just call my py package and pass the
build type amount python.
All right.
So we see some text, but the terminal and if I open up a file explorer.
We now have our IP package and instead of having RC make list text file configuration, it now has a
Python package, a resource folder, test folder.
We still have a package of XML, but instead of make lists we have a setup config and set up pie files
before we modify our setup py file, let's include our publisher and subscriber code into this new package.
So instead of the scripts directory we will put it into this my py package which already has an init
py file in it.
So open a new window.
And we'll copy these two nodes we just created.
Now I will go ahead and rename these files just so that we can distinguish them.
So go ahead and click on this and you can right click and go to rename or use the F two shortcut.
And I'll just call this publisher to py just so that we can see that there is a difference between where
these files are located.
All right.
So let's get to configuring our new package XML file for this new ROS package.
So now if I head over to source, go over to my PIP package, I can go ahead and configure our new package
XML file to contain exec dependencies for our cl py.
And the standard message is library.
I'll go ahead and save this.
And next we can edit our setup file.
So here we're going to create our node executables.
This is done in the entry points section towards the end of the file.
So within console scripts we will add an entry to the list.
First, I will add our publisher node.
I'll give it an executable name.
In this case, my publisher and I will set it equal to the name of my package.
Dot the same name of our Python script, which is publisher two and then a semi colon and the name of
the function we want to run, which in this case will be our main function.
And we can do the same for our subscriber node.
All right with this, I'll go ahead and save the file.
We'll go back to our terminal and we will rerun our call.
Can build command within the workspace.
Since we only made changes to the new package, we can use the packages select parameter of colon built
to specify to only build that particular package.
Since that's the only package in this case we made changes to.
So here we see set up tools, depreciation warning.
This will be addressed by the Ross community in later Ross distributions, but for now you can just
ignore it.
It's just a warning our workspace has compiled successfully and I can test that by sourcing our install
setup file.
And then trying to run our publisher node from that new my PY package.
So here we see again our publisher node is running and we can do it once more with our subscriber node
below.
And here we see we're receiving our messages just as we were in our other package.
So this is just two ways to go about creating a Ross package.
One is specific to only being able to run Python files, and one allows you to do C++ files along with
the Python scripts like we were doing earlier.
So feel free to use either version either by configuring a make list text file with your particular
scripts or by using the immense Python method and configuring your console scripts in a setup file.
But again, I will refer to the make list text file version using a C build type because that is the
most common build type you will see amongst ROS packages.
Well, congratulations.
You just learned how to configure your workspace in two different ways to run your Python nodes within
your ROS package.
Let's review what we learned.
In this lecture, we learned how to configure our packages so we can run our Python scripts using the
ROS to run command for packages that use the C make build type.
We configured the package xml file by including build tool dependencies for a meant c, make c make
python and rcl py.
Then we configured our to make list text files where we used find package to include the same dependencies.
Then we set our scripts folder as our python package directory by using a mint python install package.
Remember that the folder must have an init script in it.
Then we use the install programs to include each of our scripts and set the destination to lib slash
and the package name which we are able to call with the project name variable.
We configured our Python files by telling the compiler how to run our scripts.
And once we did all of that, we were able to build source and run our python nodes using the ROS to
run command.
We also took a look at how to configure our package XML and setup files.
If you use the omit python as your build type for your package.
So configuring our package XML, we have to include these exec dependencies for RC, LP and any message
types we are using as well as configuring our setup py file which will be created in place of a make
list text file where you will edit your console scripts to include the executable name you want and
point it to the package name specific script file name with a particular function to run when we run
the RAR to run command.