Hi robotic enthusiast.
In this first laboratory lesson of the course, we will create our first Ros two workspace.
As mentioned in the previous lesson, the workspace is just a folder of our PC that will contain all
the packages with all the software for our robot.
So to create a folder, let's open a new Linux terminal and use the command make directory so mkdir
followed by the flag minus P and then we need to specify the name of the folder we want to create.
So let's call this one Arduino bot workspace and let's also create the source folder within this one.
So let's press enter.
And this command has created the Arduino bot workspace folder within our PC.
For now, if we enter in this folder, this is just a folder in our PC that contains another sub folder
that is called SRC.
And here inside the source folder, we will place all the code for our robot.
So here we will add packages that will contain all the functionalities of the robot.
This will be our Ros two overlay where we will have access to all the functionalities and packages of
Ros two as well as all the new packages that we will develop during the course.
Now let's initialize the workspace so that it is recognized by Ros two.
And so all the new packages and code that we are going to insert here will become available and executable.
So back in the Arduino bot workspace folder, let's use the command called con build and let's press
enter.
Call Con is a build tool that converts the source code and the scripts.
So the one that we are going to develop in C plus Plus or Python or any other programming language into
executable files that can be run, that can be executed as normal applications within the system by
running the call con build command inside the workspace.
So inside the Arduino bot workspace folder, it will automatically generate two more folders that we
can see are build and install.
And it also generated a folder called log.
Interest to our workspace is just a folder with a specific structure.
The source folder.
So the SRC folder contains all the source code and the scripts that we are going to develop during the
course.
Then the build folder and the install folders are automatically generated by the build command based
on the content.
So based on the scripts that we are going to insert within the source folder, the build folder contains
intermediate files and creates a sub folder for each package present in the source folder.
The install folder on the other end is the final destination, so each package is installed there in
the install folder and it contains the executable files for our application.
Now that we have created the structure of the workspace, we can proceed with the creation of the first
package.
So the first container of the source code within the workspace, as mentioned before, this package
should be placed inside the source folder of the workspace.
So let's navigate to the source folder and inside this folder to create a new package, we can use the
command Ros2 package create followed by the desired build tool for creating the package.
So let's use the flag build type.
And this build type depends on the programming language that we want to use in this package.
In this case, as we are going to create a package to include Python code, we use the amend Python
build type and then we also need to provide a name for our package.
For example, let's call it Arduino, but Pi examples.
So let's press enter.
And in this package we are going to include some example code, some templates in Python that you can
use as a starting point for creating your own nodes.
Let's also create another package to provide the same template and the same examples.
Also for Cplusplus still with the rescue package, create command and in this case let's use as a build
type the amend CMake since we are going to develop Cplusplus code in this package and let's name this
package Arduino board CP examples.
So let's press enter to create also this other package.
And now if we take a look to the content of the source folder, we can see that now there are two subfolder.
There's the Arduino CP examples and the Arduino bot Pi examples that were created by the Ros2 package.
Create Command.
Now back to our workspace.
We can run again the command called Build.
And now this command will rebuild the entire workspace, including the two new packages that we just
created.
And in fact, you may notice that the output of the build command is slightly different from what we
saw earlier.
And in fact, this is informing us that we have two new packages in our workspace that are Arduino bot
CP examples and Arduino bot Pi examples.
Now we also need to activate our workspace, which means making the Arduino bot workspace folder.
So this one recognized as an overlay for Ros two.
This way, all the packages that we added and that we are going to add in this workspace will be recognized
as Ros two packages and so we will be able to execute their content, their script with the Ros two
commands.
To do this, we need to source a certain file that is located into the install folder that, if you
remember, was automatically created by the build command.
And we need to source the file that is called setup dot bash.
So we can do this by typing dot setup dot bash.
So let's press enter and by doing this we have made the current terminal.
Remember only the current terminal, the one we are using.
And so to aware about the existence of the Arduino bot workspace and actually to verify that this command
has been successfully executed and that Ros2 recognizes the new to package that we have just created.
Let's get the list of all the currently available packages that are available in Ros2 with the command
Ros2 package list.
So let's press enter.
And among them we can see that there are already many packages that were installed by the default Ros2
installation.
And among them if we go to the letter A.
We can see that there is the Arduino board, CP examples and also the Arduino board Pi examples.
This demonstrates that these two packages have been recognized in the Ros two environment.
And so when we will add some code, some scripts to this folder, we will be able to execute and interface
them with Ros two.
However, note and remember that the source command that we used to make the environment aware of the
new overlay only as effect on the current terminal session.
So on this terminal that we have just opened so only applies for this terminal.
So to demonstrate this, if for example, we open a new terminal where we didn't source the workspace
yet, and if we navigate to our workspace now in this case, if we use again, the command Ros2 package
list.
And again, let's scroll to the letter A.
So we can see that the Arduino CP examples and the Arduino Pi examples are not there.
This is a common issue that you need to pay attention to.
Remember that whenever you open a new terminal before using the packages within your workspace, you
must source the workspace.
So namely, you must source the setup file that is located in the install folder of the workspace.
So let's source it also in this new terminal by typing dot install setup dot bash.
So let's press enter.
And now if we run again the command Ros2 package list.
Let's scroll back to the letter A.
Now we can see that also in this terminal.
Roscoe is aware of the existence of the Arduino board, CP examples and the Arduino board Pi Examples
packages.