All the code we will develop in this course is available on GitHub using the link provided in the resources
of this lesson.
As you can see, this repository is organized by section.
So here and here you will always have access to the most up to date, functional and tested version
of all the nodes and features that we are going to develop in this course.
You can use this material as a starting point to follow the laboratory lessons, and also as a template
to develop new features.
For instance, let's say that you are in the section three and that you are following the laboratory
lesson in which we create for the Python the simple publisher.
So this one here.
So let's say that you are developing this node here.
So if you want you can simply copy paste all this code here in your workspace.
Also that in the laboratory lesson you can just focus on the explanation of all these lines of code
here, instead of rushing for copying all the code that I'm going to type.
Otherwise, if you prefer to rewrite the code from the laboratory lesson yourself, you can use this
material.
So you can use all the code that you find here on GitHub.
In order to check for any bugs or typos that can occur in your code.
Let me show you how you can do this.
For example, let's go to Visual Studio Code and let's say that you are writing for the Arduino Bot
Pi examples packages.
So let's say that you are developing this one here the simple subscriber node.
So let's say that you have followed the laboratory lesson and that you have typed all this code here
in order to implement this node here.
And so then you try to execute it.
So let's say that you open a terminal.
You go to the workspace.
So to the Arduino bot workspace you build it with Qualcomm build.
And then once the build is completed in a new window of the terminal, you source it and then you run
this node here.
So the simple subscriber with Ros to run and from the Arduino boot Pi examples.
So you start the simple subscriber node.
So you press enter.
And this one here.
So the node is crashing.
So it throws an error even though everything works perfectly in the course lesson.
Classic right.
It always runs smoothly in the video but never on your PC.
I know the feeling in this case.
As a first step, I recommend you carefully reading the error that is printed in the terminal, and
this is normally going to highlight you the error.
And also it's going to provide you some useful insights on which will be the line that is affected by
the error in your code.
While debugging can be challenging and even frustrating, it is an invaluable part of the learning process.
It encourages you to understand each line of code more deeply, and this is a skill that you will rely
on in all your robotics projects.
You can also start by searching this error here.
So this is the error message.
We can start by searching this one on Google for example.
So we can go here and we can paste the error that we are getting.
And here.
So as we can see this not only can help you to find a solution to the problem that you are having,
but also it can introduce you to a lot of forums and communities where robotic software developers can
collaborate and can share solutions to their problems.
For example, we have StackOverflow.
We have answers.
So the heroes wiki.
Then we have this one here Robotic Stack Exchange.
So all of these are invaluable examples of communities where developers of all levels and backgrounds
Grounds can collaborate to solve problems if this step doesn't solve your issue.
You can also try using ChatGPT.
So here, try to be as descriptive as possible with your problem, and also try to include all the relevant
details, including, for example, code snippets and also the errors that you are having in your terminal.
For example, let's copy all the code that is throwing the error.
Let's say.
So let's ask this code.
Then let's paste all the code and let's say is causing this issue.
And then let's simply paste.
So let's copy paste the error message.
So this one here let's copy it and let's paste it here.
So let's try asking it.
And normally this tool is incredible because not only it will solve your problem in seconds, but also
will provide you with an accurate explanation of the issue that you are facing, why it occurred, and
this will further enhance your understanding of the topic.
If you are still stuck.
Let me show you another debugging strategy that is one of comparing your code.
So the one that you are developing here in Visual Studio Code.
So in your Arduino board workspace.
So to compare this one with this one here.
So with the one that I developed and that I uploaded here on GitHub.
Now in order to do so the first thing that we need to do is to download this code here.
So to download all these folders so we can use this button here in order to clone.
So we can copy this link here.
And then we can open a terminal.
Here we go.
And so here we can use the command git clone.
And let's paste the link that we have just copied.
So basically this command here now is downloading all the code that I uploaded here.
So all of this code it is downloading it in your PC.
So now we can see here that this one is the folder that I uploaded here.
And that contains all the code for all these actions of the course.
Now what we want to do is to compare your code.
So the one that you are developing here in the Arduino workspace with my code.
So the one that I uploaded here.
To do so we can use the amazing tool that is git.
So we can go to your workspace.
Go to the Arduino bot workspace in which you have the error or the typo.
And here we can use the command git init.
So this will initialize this repository here.
So this folder as a git repository.
Then we can use git add dot in order to add all the files that are here.
So all the code that you develop in the Arduino workspace.
So this will be added to git.
Perfect.
And now we can save.
So we can create a checkpoint.
We can create a commit for this code here.
So for the code that we have developed so far in this code here, because then we want to compare this
checkpoint.
So we want to compare your code with my code.
So with this one here that we have just downloaded.
So we can create a commit with git commit.
And for example let's call it checkpoint perfect.
So we are adding all the code that is in your workspace.
So we are adding all of these to the checkpoint so that now we can compare this checkpoint with this
code here.
And in order to do so is as simple as opening this folder here.
So this folder that we have just downloaded and that contains all the code that I uploaded on GitHub.
So let's open it here.
Let's go to the section that you are following.
Let's say that you are following the section number three.
So here you can see this one.
Here is the workspace that you will have at the end of this section number three.
So let's open it then let's go to the source folder and let's copy all the packages that are here in
the source folder.
So let's copy it and then we can paste them in your workspace.
So we can go here.
Then we can go to the source folder.
Here we can remove your packages.
And simply we can paste the packages that I'm using here.
This is not only copy pasting.
So this is not just copy pasting my code into your workspace.
But as we have used git.
So if we go back to Visual Studio Code, the fact that we used git is very useful because now if we
go here, go to the source control.
And if we open this one here.
So here we can see all the changes between my code and your code which we added to the checkpoint.
So which we added here to this checkpoint here.
And so this is going to highlight all the changes between my code.
So the one that I uploaded on GitHub and your code and most likely this is also going to highlight as
you can see here.
So this is going to highlight any typo or bug in your code.