In this lecture, we're going to take a look at different ways we can compile our package, which is
going to be a bit helpful for us later on in the future.
So if I open up Visual Studio Code and I head over to my make list text file when we were installing
our Python scripts, we call this install command, followed by the name of each of our scripts and
we specified a destination lib slash project name.
What this did was made a copy of our Python scripts in the install directory of our workspace.
So for example if I had to me Ross to package lib.
And then our package name, this is the lib package name that we're specifying here in the destination.
So here we see a publisher, py and a subscriber py file.
These are copies of the scripts we created when we ran cocaine build.
And these are the files that get referenced when we use the ROS to run command.
So why does this matter?
Well, because if we make any changes to our scripts, for example, let's go over to our publisher
file.
And we'll change the print statement to say new publisher and node running If I make changes and I hit
control SE.
We can go over to a terminal.
Source our workspace.
And use the RAR to run command like we did in the last lecture.
So notice here it says publisher node running, but we obviously changed it to new publisher node running.
Well, that's because, as I said, it's referencing this file which was copied when we ran Coal can
Build.
So this file only says publisher Node running.
The changes didn't take effect here.
So this can be kind of annoying because that means we need to recompile our whole package just to address
that one little change we made to our script.
So let's go ahead and compile our package in a different way so we don't have to worry about this.
So I'm going to go ahead and start with a clean slate workspace.
So I'm going to delete my build, install and log folders.
So now I only have the source folder which contains my packages.
Now I'm going to go back to my terminal.
I'll stop this Publisher note.
Clear the screen.
And if you actually notice, if I were to try and run that command, it says Rescue package not found.
That's because I actually deleted the files where everything was held, even though our source folder
is still intact.
But if I go over to my workspace directory, we can run the call, can build command.
But this time we're going to specify a special option by doing dash dash Simulink install and you can
use tab completion here.
So what Simulink install is going to do is whenever there are files that are copied over, instead of
creating a brand new version of that file, it's going to make a link to that existing file instead.
So let's just go ahead and see what this does.
So again, we get our depreciation warnings from our setup tools, depreciation warning from our IP
package.
For now, we're just going to go ahead and ignore that.
And now if I go into my install directory, as you can see, our build, install and log directory,
we're regenerated since we reran colon build.
But now if I go into our package.
We see these arrows.
And so this means that this is a linked file.
So if I go ahead and open this with the text editor, it says new publisher node running.
And if I go ahead and make more changes, so I'm going to say new new publisher, node running, I know
that's not original, but just to show the difference.
Now, if I reopen this file again, we see the changes immediately took effect.
So here we see that new new publisher note is running.
So this is super helpful in the sense that we can make changes to our source code and it'll immediately
take effect into our workspace without having to recompile.
I can also prove this by opening a terminal at this location and we can use the read link command.
So in this case, I'll do read Link publisher PI.
And here we see it is pointing to our source folder.
Now, we will still need to run and build regardless if we create new files.
And it can be easy to forget that dash dash Simulink install like when running call can build.
So let's go ahead and set up our VS code editor to remember.
For us to do this, we're going to head over to our Visual Studio code editor and add some contents
into this dot vs code folder you see here.
So I'm going to go ahead and right click on it hit new file and I'm going to create a tasks dot JSON
file and oops, I accidentally put a comma there instead of a period.
There we go, tasks, JSON, and now we're going to set up our tasks.
Here.
You can find more information on Vsco codes, documentation page on task, but for now, let's go ahead
and jump right into it.
So here all I'm doing is mapping the coal can build Simulink install command to the build labeled task
in VTS code, and we specified that these commands run in the shell.
Notice that I source my ROS installation before building.
That is because by default the VZ code shell does not source our bash, our c file in our home directory
like our normal terminal does.
So we have to manually specify the source of the Ross installation.
Or alternatively, you can change this to source your bash or C file if you want it to.
Then I use two ampersand symbols which specify to run the next command if the first one is successful.
So with that, I'll go ahead and save this file.
And now instead of having to run colon build from terminal, every time we want to make changes, we
can instead head over to terminal and run build task.
So this opens a terminal here at the bottom.
And as you can see, it compiled using the code that we just specified.
So it went ahead and source our Ross Humble set up bash file and then ran colon build Simulink install
where we see our code got compiled.
Then from here I can simply hit spacebar to close the terminal.
But all the changes have taken into effect and I can actually prove this really quickly by going ahead.
And deleting the build, install and log folders one more time.
And I will run that terminal run build task.
And we see they all get created again.
Now, for the time being, since we're not using that my PIP package.
And that was only for the example back in the Configuring Packages lecture.
I'm going to go ahead and delete this package for now just so that we stop getting that depreciation
warning from the.
The package resources, depreciation warnings.
Due to the setup copy files being depreciated.
And because we're not really using that package anyway throughout this course.
So since I made those changes, I should actually recompile one more time.
But now we see it's super easy.
We don't have to remember any commands.
Simply head over to this run, build task or use the control shift to be shortcut and any changes we've
made to our packages we'll get compiled in.
All right.
And there's one more thing I need to show you to make sure that all of this works as intended.
So if I head over to my terminal and I go over and change into my scripts directory, if I hit ls.
Notice that my Python scripts are in this white text.
Now this means that it's just a normal file with read write privileges.
Now we're actually using these files as executables, right?
We are executing these Python scripts to run our ROS code.
So the one bad thing about sym linking our files is we need to make sure that they are executable as
is because code can build actually used to take care of that for us.
And I can show this by trying to source our workspace and trying to list our executables.
So now if we run our ROS to package executables.
The name of our package.
Notice no executables get listed, and if I try to run one of our nodes, say our publisher node, it
says no executable found.
So the reason why this is happening is because our linked file is not configured as an executable.
So the way we go about changing this in UNIX is by using the Mod command, which changes the permissions
of a particular file.
So for example, if I wanted to change the permissions of my publisher node to be an executable, I
could do c h mod plus X in the name of the file, which in this case is publisher py.
Now if I hit LS.
Notice it's in this green text now which is symbolizing that this is an executable file.
And if I rerun that ROS to package executables lists, we see our publisher PY is now considered an
executable while our subscribers py is still not so you need to be sure that all of your source files
are considered as executables so we can actually go ahead and automate this in our test JSON file to
make sure it does that for us so that any python files that are within our packages get set to be executable.
You can feel free to change this if that's not a desired behavior, but for the most part, most people
won't have an issue with setting their Python scripts to be executable.
So I can do this by adding another set of double and percent symbols.
So after we finish building, let's make sure we look for all of our Python files and set them to be
executable.
And we can do that with the following command.
So I know this is a bit of a complex command, but essentially we're running the find command in our
directory and we're looking for the whole name within our source directory, any Python files.
So any python files within the packages within our source directory, we'll then execute the command
plus x command, which we ran earlier in our terminal so we can go ahead and save this and we can go
ahead and rebuild our workspace.
I'll go ahead and hit Control shift B to run the build task.
And we see that's running this whole command for us.
And now if I go over to terminal, I can go ahead and run.
LZ And now we see that all of my Python scripts are now green, meaning they are all executable.
And if I run Ros to package executables and Ros do package again, we see both the publisher and subscriber
node.
All right.
With that, we've successfully configured our Visual Studio workspace to automatically source our Ros
Humble installation run code can build with Simulink install so that any changes we make to our scripts
will automatically take effect in the ROS Terminal command line interface and make sure that any python
files we have within our workspace are marked as executable.
So all this is done at the click of a button and we no longer have to worry about it.