ROS2 For Beginners - Build Robotics Applications with Robot Operating System 2 | Edouard Renard | Skillshare

ROS2 For Beginners - Build Robotics Applications with Robot Operating System 2

Edouard Renard, Software Engineer and Entrepreneur

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
90 Lessons (10h 50m) View My Notes
    • 1. Introduction

      3:02
    • 2. What is ROS2, When to use it, and Why?

      6:47
    • 3. Tips to get started with the class

      1:50
    • 4. Install ROS2 and Setup Your Environment

      1:00
    • 5. Which ROS2 Distribution to Use

      4:53
    • 6. Install Ubuntu 20.04 on a Virtual Machine

      16:09
    • 7. Programming Tools I Use During This Course

      3:44
    • 8. Install ROS2 Foxy Fitzroy on Ubuntu 20.04

      3:41
    • 9. Setup Your Environment for ROS2

      2:16
    • 10. Launch a ROS2 Program!

      2:48
    • 11. Write Your First ROS2 Program

      1:18
    • 12. Install the ROS2 Build Tool - colcon

      2:18
    • 13. Create a ROS2 Workspace

      4:08
    • 14. Create a Python Package

      5:57
    • 15. Create a C++ Package

      4:08
    • 16. What is a ROS2 Node?

      7:35
    • 17. Write a Python Node - Minimal Code

      14:57
    • 18. Write a Python Node - With OOP

      7:46
    • 19. Write a C++ Node - Minimal Code

      13:36
    • 20. Write a C++ Node - With OOP

      9:44
    • 21. OOP Template for Your Nodes

      1:54
    • 22. More About the ROS2 Client Libraries for Different Languages

      2:31
    • 23. Introduction to ROS2 Tools

      1:03
    • 24. Debug and Monitor Your Nodes with ros2 cli

      9:57
    • 25. Rename a Node at Runtime

      6:02
    • 26. Colcon

      5:00
    • 27. Rqt and rqt_graph

      3:48
    • 28. Discover Turtlesim

      4:53
    • 29. Activity 001 - ROS2 Nodes and Tools

      0:53
    • 30. Activity 001 - Solution

      4:25
    • 31. ROS2 Topics - Make Your Nodes Communicate

      0:45
    • 32. What is a ROS2 Topic?

      9:00
    • 33. Write a Python Publisher

      18:20
    • 34. Write a Python Subscriber

      9:36
    • 35. Write a C++ Publisher

      17:11
    • 36. Write a C++ Subscriber

      10:01
    • 37. Debug Topics with Command Line Tools

      7:07
    • 38. Remap a Topic at Runtime

      3:38
    • 39. Monitor Topics with rqt and rqt_graph

      6:18
    • 40. Experiment on Topics with Turtlesim

      4:53
    • 41. Activity 002 - ROS2 Topics

      1:01
    • 42. Activity 002 - Solution [1/2]

      8:47
    • 43. Activity 002 - Solution [2/2]

      11:09
    • 44. ROS2 Services - Client/Server Interactions Between Nodes

      0:54
    • 45. What is a ROS2 Service?

      7:00
    • 46. Write a Python Service Server

      13:40
    • 47. Write a Python Service Client - no OOP

      13:44
    • 48. Write a Python Service Client - OOP

      12:13
    • 49. Write a C++ Service Server

      14:43
    • 50. Write a C++ Service Client - no OOP

      14:23
    • 51. Write a C++ Service Client - OOP

      17:13
    • 52. Debug Services with ROS2 Tools

      4:50
    • 53. Remap a Service at Runtime

      3:09
    • 54. Experiment on Services with Turtlesim

      7:48
    • 55. Activity 003 - ROS2 Services

      0:51
    • 56. Activity 003 - Solution

      11:56
    • 57. Create Custom ROS2 Interfaces (Msg and Srv)

      0:45
    • 58. What are ROS2 Interfaces?

      11:34
    • 59. Create and Build Your First Custom Msg

      13:50
    • 60. Use your Custom Msg in a Python Node

      10:27
    • 61. Use your Custom Msg in a C++ Node

      4:27
    • 62. Create and Build your First Custom Srv

      4:32
    • 63. Debug Msg and Srv with ROS2 Tools

      7:06
    • 64. Activity 004 - Custom Interfaces

      1:53
    • 65. Activity 004 - Solution [1/3]

      10:54
    • 66. Activity 004 - Solution [2/3]

      13:31
    • 67. Activity 004 - Solution [3/3]

      19:32
    • 68. ROS2 Parameters - Change Node Settings at Runtime

      0:31
    • 69. What is a ROS2 Parameter?

      3:18
    • 70. Declare Your Parameters

      12:17
    • 71. Get Parameters from a Python Node

      11:32
    • 72. Get Parameters from a C++ Node

      9:38
    • 73. Activity 005 - ROS2 Parameters

      0:19
    • 74. Activity 005 - Solution [1/2]

      5:58
    • 75. Activity 005 - Solution [2/2]

      4:20
    • 76. ROS2 Launch Files - Scale Your Application

      0:49
    • 77. What is a ROS2 Launch File?

      2:31
    • 78. Create and Install a Launch File

      14:19
    • 79. Configure Your Nodes in a Launch File

      6:41
    • 80. Activity 006 - ROS2 Launch Files

      0:40
    • 81. Activity 006 - Solution

      11:17
    • 82. Turtlesim Project - Instructions

      1:39
    • 83. Turtlesim Project - Step 1/6

      28:29
    • 84. Turtlesim Project - Step 2/6

      15:40
    • 85. Turtlesim Project - Step 3/6

      17:09
    • 86. Turtlesim Project - Step 4/6

      19:09
    • 87. Turtlesim Project - Step 5/6

      7:26
    • 88. Turtlesim Project - Step 6/6

      12:24
    • 89. What You've Learned

      1:52
    • 90. What to do Next?

      2:29

About This Class

In this class, I will take you, step by step, in a few hours, from a complete beginner to a ROS2 developer who can write scalable robotics applications.

→ You are learning ROS2 from scratch?

And you may ask yourself: Where to start? How to learn? What to do first?

When I first got started using Robot Operating System, it was really hard for me to answer those questions. Thus, learning ROS/ROS2 was hard. But it doesn’t have to be, if you learn with the right resources.

Also, something I noticed is that when people are teaching ROS2 (in 2020), they are often making comparisons with ROS1. But, what if you don’t know ROS1 ???

I have created this class so you can properly learn ROS2 from the beginning, with no prior knowledge in Robot Operating System, and without having to waste weeks, or even months, trying to find what to do. You can say goodbye to this big learning curve everyone faces when learning ROS2.

The class is structured so that you can follow it, one step at a time, and get everything you need in the right order. At the end of the class, you’ll be confident enough to start your own Robot Operating System 2 application.

→ How do I teach?

Here’s my teaching method, in 3 points:

  • Step by step.
  • Going to the point.
  • Practice, practice, practice.

That’s it. No useless stuff and distraction, just the important things you need in order to create ROS2 applications.

My experience with Robot Operating System is very practical. I actually used it to build a robotic arm that is now on the market. So I had no other choice than being practical and going to the point. And that’s the way I want to teach you.

→ So, what are you going to learn?

Here are the main concepts you’ll see in this class:

  • ROS2 Installation, Workspace, Packages, …
  • ROS2 Nodes
  • ROS2 Topics
  • ROS2 Services
  • ROS2 Custom Messages
  • ROS2 Parameters
  • ROS2 Launch Files
  • ...

Each section/module of the class is focused on one ROS2 key concept. For each concept, you’ll get:

  • Concept explanation, with the context, and why you need to learn that.
  • Step by Step “how to” videos (for both Python and Cpp).
  • An activity to practice + detailed solution video.
  • A recap + code download of everything we did in the section.

I like to start with the “why” question, which is, to me, the most important question you can ask. If you understand the “why”, then everything after that will make sense because you know where you’re going, and why you’re going there.

I also take the time to write all the code with you. Some teachers and instructors like to show you a huge bunch of code and then tell you “ok this code does that”. I personally don’t do this. When I write code, I write it completely, with you, and I explain why I’m writing what I write.

At the end of the class, you will have the opportunity to work on a complete project, using the Turtlesim simulation. This will help you practice more on everything you’ll see in the class, and that will be your first real project from A to Z.

Along the class you’ll also learn how to use ROS2 tools to debug your application, monitor what’s going on, and build your code.

With everything you’ll learn + the best practices I’ll give you, you will be ready to start any ROS2 project with a good foundation.

 

--------------------

This class is for:

  • Students, Engineers, Researchers, Teachers, Developers, Hobbyists.
  • Anyone who wants to learn about ROS2 from scratch, and not waste time.
  • People who want to build scalable robotics applications, faster.
  • ROS1 developers who are still at a beginner level and want to start learning ROS2.

This class is not for you if you:

  • Are already a ROS2 advanced or expert developer.
  • Have never used Python or C++ before.
  • Also, this is not a “ROS1 to ROS2” guide. This is a class where you learn ROS2 from scratch, with no ROS1 knowledge required.

Pre-requisites for this class:

  • Programming basics in Python and/or C++
  • Some basics in Object Oriented Programming (OOP) are welcome, although not 100% mandatory
  • You need to know how to use basic commands in a terminal
  • And of course, a strong willingness to learn
  • Precision: No need to know anything about ROS1!

Transcripts

1. Introduction: welcome to the schools on a Robert operating system. To you want to develop poor fool and scale where robotic applications you want to long rows to from scratch and master the cough functionalities but without the usual steep learning curve. Well, you are in the right place. I'm Ed Uar, a software engineer and entrepreneur. In the past, I have programmed an anti air, six axis robotic arm. We've Ross from scratch. Then I have worked extensively with this new vision of Frost named Ross, too. When I started using Ross, I had trouble finding well structured courses and two Toyotas to show me what's important to do at the beginning, where to start, what to focus on and which path to follow. That is why I created do girls that I wish I had when I began, so you can learn much faster than I did. This is a step by step course structure in a way that makes it easy to follow for beginners and directly going to the point through a turn off practice. At the end of the course, you would mustardy arrest to basics, and you would be able to create a complete to Robert X application using all the rose took our concepts. In this course, you will not only see the how, but also the why which is even more important. You will learn how to installing Set a brush to on a you going to operating system how to create, build and use for us to note topics, services, messages, parameters, launch flies and much more. All those points are key concepts that you need in order to use rushed to efficiently. And of course, you will discover some of the most important Ross to tools which will help you save some development time. You were so practice a lot, thanks to many activities, I would take the time to write to code with you, explain every single step and give you some challenges to make your progress on key concepts. Oh, and all the code will be written in python and also in C plus plus. So you can completely alone Russ to with those two languages if you want to. And that's not all. At the end of the course, you will work on a complete Russ. Too many project using the turtle seem simulation so you can practice on everything you would see in the schools. All you need is to know how to deal with a terminal and have some basic knowledge in programming during the schools. I will also give you some of the best practices I personally learned when developing. We've rushed to because what I want is that at the end of the course, you're able to develop not good, but great and scannable robotics applications. 2. What is ROS2, When to use it, and Why?: first of all before we even go to the why, when and what runs to is the 60 so off Russ one. It's basically the next version, but with the same goals and core concepts just better and with more functionalities. So when I talk about Ross, too, I also talk about Ross in general. All right, so why you're us to Let's start with those three robots. What is the common point between them? Well, on the robots you see here can be powered by Ross R. Us, too. Ross means robot operating system. It is something between a mirror where in a framework build, especially for robotics applications rose to go is to provide a standard for robotics software that developers can use and reuse in an era. But once you know how to use rose to efficiently, you will be able to set up a new software for your a boat. In no time, you first need to master the basics and call functionalities, which you were seeing the schools, and then for every in your about your program, you gain more skills that can apply toe other robots. The more you know about rush to the easiest. It will be for you toe program and understand the code of any robot. But in that it no, another part of the philosophy behind Ross is don't reinvent the wheel are inventing the wheel is a very common programming robotics. Many people always start building use software that is already existing, and thus they don't have the time to work on really valuable stuff. What if, instead, you could build on a strong software base to directly program high level functionalities and walk on use cases instead off load of a technical stuff that already exists anyway? So this is the why behind Ross know when to use Ross. Maybe you've already studied toe program Roberts with an Arduino board with a system code on a computer and what you will quickly experience it that the more sensors traders controllers you add on your application, the more complacent becomes until you reach a point where everything is mixed up and you can't add any code for nuisance or without having a huge headache For us to is here to help you develop powerful and scannable Robert applications, you can use it whenever you want to create a Robert software which needs a lot of communication between it's the programs. Are has some functionalities that go beyond a very simple use case so far, a Robert that will just open a door with a several model when it detects a movement. Maybe you don't need a rustic, but find more by Robert, which you want to control with a GPS and a camera in this case runs to might. Ready? Help? You all right? You've just seen the why behind rose to and went to use it. Now what is rusty? Well, it would be hard to describe exactly what is rushed to in about two minutes, even our But here are two main points that we give you a 90 of the big picture. First of all, rushed to provide you with a way off separating your code into raise able blocks along with a set of communication tools. Toe easily communicates between all yourself programs. Let's say that you are programming a worldwide robot. You can create a SER program called node for your camera. Another father navigation. I grayton another one for the how to a driver. And as I went for a joystick and so on, and each of those independent blocks will communicate between each other in a way that is powerful and scalable. The single main point is that Rose to provide you with many tools and plug and play libraries. That will save you a huge amount of time and, most importantly, that we prevent you from reinventing the wheel. If we come back to the move, I Robert, imagine how difficult it can be to compute a tragic story which will make the robot moving smoothly, avoid any of cycle on the way and also work with other robots at the same time. Well, impossible, you might think, unless you spend something like two years studying mathematics pass planning algorithm, etcetera. But what if I tell you these? You don't need two years? We've rushed to union maybe two days to install a library and figure out how to use it. So you have great communication tools and great libraries. That's not all. Ross is said to be language agnostic. It means that you can program some pats off your application in a problem in long wage and another path in another programming long wage, simply because the communication tools don't rely on a specific language. So in day, schools will not go into all the external libraries that exist. For many front Roberts, we will mostly focus on the roster basics call functionalities and tools that will allow you to Is that any robot application for world by rose to using python and see to finish? Russ two is also open source with a knack, active and growing community so you can directly see what's going on. You can easily get help. You can share your project and even contribute if you wish to. All right. With these quick introduction, you should get some ideas about what is the rush to and why is it useful? Don't bending, though, if you don't understand everything. Right now, the big picture behind Rose to is bread. We have to get at the beginning, but after some practice your started, get it, and I can guarantee you that you will quickly think at Ross. Two is out, some for your robotics projects 3. Tips to get started with the class: Here are a few tips to help you navigate the class and find the additional Russell sees. If you go on the projects and resources stab, you will find a bunch of things to download. So don't know that everything right now. So you're down with that. First, you have the projects and activities Pdf you will find here all instructions, complete instructions for our projects and activities inside the class. When it's time to do a project, you will get a quick video introduction, plus the PF and then another video for the solution. I find it a pdf version more appropriate for complete instructions about the project. Our activity so you can keep it under side to always have all the instructions, the label while you work on the project. And then you have a not drive containing all the code written in this class. We will start from scratch and every time we write some code, it will be added to what we already have. So to make it simpler for you, I have created occurred. Okay, for every step, when you finish the lessons about topics, for example, you can use the topic cut archive where you will find all the code written until this point and also containing the many projects I give you a long discuss. Now a few recommendations off course. Write the code as I write. Don't just watch it you can pose are rewind the video at any time and do the activities and projects by yourself. At least give you some time to try before you watch this solution. 4. Install ROS2 and Setup Your Environment: in the next few lessons, you will set up your undergarment and in Star Rush to. So I would explain which roster version you should use. Also, how to set up you into on a vehicle. Information. I will introduce you to some of the tools that I use when I program eso, it can help you 40 schools to follow the steps I do, and any wouldn't start rush to in all necessary. Rushed to tools. 40 schools. There is quite a bit of set up, but after this section you will be done with that and will be able to focus 100% on Rusty. Note that some installation steps may be quite long, and it would depend mostly on your Internet connection speed as well as your computer performance. Don't worry, though. All the steps are quite easy to follow, and I will detail everything, so let's get started so you can quickly run Rusty 5. Which ROS2 Distribution to Use: before we install Rose to. It's important to check, which rushed to distribution you need to use so you can find the least of distributions on the Ross Index website. You have the you are here, and you can easily find it on Google also. So here you can see all the rose to distributions in grain. You have the currently support E ones, and in grey you have the distributions that are notes reported anymore. So you can see in the past we had two distributions every year that now it will be only one distribution every year in around May. So next one will be in May 2021 then May 2022 etcetera. And it's quite easy to follow the other. You start with the letter A and then a B C D E f g h. Etcetera. It's simply the alphabetical order. So in order to choose which distribution, you want to use mainly two things. The first thing is to check the e o l date. So the hell that means end off life. And after this date, well, the vision will not be supported anymore, and you would see it in great here. So as you can see, we have the latest rose to distribution which is Rasta Foxy, which will be supported until May 2023. And we have the eloquent until end of 2020 and dashing May 2021. So you'd better choose a vision that has still a few years before You need to upgrade to a new vision. And now the second thing is to check if the vision is an LTs version. So LTs means longer term support. And in fact, you can see because long term support means that it will be supported for five years and foxy is the exception. It will be supported for three years. But the next LTs version will be supported for five years and you have one LTs version every two years. So division in 2021 won't be an anti s and division in 2022 will be an LTs version and these vision will be supported until 2027. So now which vision should you use? What I do and what I recommend you to do is to use the latest LTs version. In this case, we will choose rust to Foxy Fitzroy so you can start with Foxy. And then when a new LDS divisions in 2022 eso when his vision is released, you may wait a little bit before you switch to that version because not everything we reported at the beginning. OK, when the vision is up, just bear by cages, the label, but not everything. I mean, like not every bike age superteam. My community is a label, so you may have to wait between six months to year before everything you need for your project has been spotted. Also, I don't recommend working with non LTs versions. Those versions are just really is, so you can get the latest tools and figures, but it may be less stable. And also all known LTs versions from now will only be supported for one year and 1/2. So if you are learning, are if you want stability are simply to use rose to found actual product, then I advise you to use only LTs versions, and one thing to pay attention to is the link between the rows to distribution and the operating system for the ocean. So let's click on Ross to folksy and you can see here. There's supported platforms. So Ross to is supported on Lenox, Mac OS and windows for windows. Well, you will have windows 10 every time, I guess. And he especially for you. Been to we. Have you been to 21? Awful. The vision in 2022 would be for you. Been to 22 point off. So you may have toe. Also change the operating system when you change the rules to version. All right, so now that you understand, which rushed to distribution, we need to use. And as you can see, we also need to use you go to 20 points off, then we can start the installation. 6. Install Ubuntu 20.04 on a Virtual Machine: For us to mainly works on three operating systems. You're going to Mac OS and Windows. Here you will install Ubuntu 20.04 if you don't already have it. Now that I will only use human to form these goods. That is the OS with which you will probably have less problems, would be set up, tools and everything else. So as you are just starting with Ross to I advise you maybe to use you're going to at least for the duration of this course. So if you already have human to 20.04 installed on your computer than grade, just go ahead and jump to the next lecture. If not, then you have two choices. You setup a dual boot, Are you create a virtual machine. Here? I won't explain how to create a Jewel boot because this is not the doubling of discourse and it's longer to look. So I will show you how to install a virtual machine. We've went to 20.04 on Windows. So let's get started. First. We will need to download an image of you been to 20.04. So just type. You went to download and you can find the latest version here, which is you would do 20.04. So you can just download it. And you will get to a thank you page. And it should stop yet. Just download the fire. If it doesn't start, you can click here. And as it is an open source projects, they will ask you if you want to donate. So holy, that appeal when it is downloading and now we have quite some time before it's finished depends on your internet speed mostly. And we will use VirtualBox or you type, you type VirtualBox on Google and you can go to the VirtualBox website. And we will download whatever is the latest virtual books. They're shown here. Okay? And you can find all the different OSC or Windows, MacOS, and Linux. So here we are on Windows or on any other quadratic system you train, you choose your operating system version. So I will click on Windows and save the file. And now you can weight that the VirtualBox download is finished. So once VirtualBox is downloaded, you can just execute it and installed it like any other software. So you can show the location path is in French, but it's not too hard to follow. You just type next, next. And here, yes, for the network. And then you can click on install. So once the installation of VirtualBox is finished, you can start it ok. And here you can see I already have three virtual machines, but for you it will be empty here, okay? So we will create a virtual machine on this VirtualBox software. And then once the, the ISO, which should be about 2.5 gigabyte is downloaded. We will be able to, but the ISO on the virtual machine to start it. So what we can do, what you can do waiting for the day you went to ISO is to create a new virtual machine. Let's name it. You're going to 2004, so the name doesn't matter, you just choose what you want, but it's better to have a meaningful name. And then you make sure that you have Linux and you're going to 64 bit here. Next, you will have to choose memory size around. It's ready quite low here. I recommend at least but two gigabytes. And I have quite a powerful computers. I will put eight gigabytes, 16, but for two or four gigabytes is good. You click on Next. You can create a virtual hard disk now. So just choose that option VI, which is, which is fine, dynamically allocated, which is fine too. And you will have to choose the size of your hard disk. So virtual hard disk will be created for your digital animation. You will have to choose a size. And the default here is ten gigabyte, it's quite low, is shown to install ROS and other programs. I suggest you put at least 20 or 25 gigabytes. Here. I will use 30 gigabytes. You can put much more if you want. Depends on the space you already have on your computer. And let's create the machine. So we have a new virtual machine. And we can do a few more settings because not everything is correctly set up yet. So you go in general, here we don't change anything. You're gonna system and system. You have the memory allocating before. And if you go on processor, you have the CPU allocation, okay? So that by default you have only one CPU. So that will make your virtual machine quite slow and you can add more CPU. So my gaze, I have and we put three CPUs. It really depends on your machine. You can put three or four. Just don't Bongo at the maximum. Okay. Because this is the maximum of my computer. No, we go in network. Because if you want to have internet on your virtual machine, you will have to use a bridged adapter and the Internet from your host. So for example, Windows will go through your virtual machine and you will have internet on your virtual machine. Otherwise you will not have internet. And let's say OK. Ok. So now your virtual machine is configured. While we need is the isoquant. It's just finished to them loud. Okay, so now you can go to setting again. Go on storage. And you have Controller IDE here, which is empty. So you click here and you click on that icon to choose the isoprene. I already have it here, but you can just navigate here and find the ISO that you'd just, well, yeah, okay, so I choose it from there. And I click on OK. And then you can just start your virtual machine. So they will ask you startup disk. So it's just what I did previously. Here. It's already selected because I've already selected it. If not, you will be asked to choose it. So you will put the isolette, you download it from Ubuntu website. And now the machine is starting. Okay, so you get to the installation step for you, but it may take some time to get there depending on your computer performance, okay? And here we will choose, we have to choose between try and install Ubuntu. We will choose directly installed y12. And if you are using a dual boot with maybe better to dry first and then installed. But as we are using, a virtual machine would just install on the virtual disk. We have. So you select Install and you choose your keyboard layout. As you may have guessed, is French. So choose any keyword which matches yours. Continue. We will choose the minimal installation. We don't need all the media player, utilities and gangland stuff. Okay, we will download updates and continued. You will be asked to choose if you want to Erase disk and install you want to or not. And you have a big warning saying this will delete everything. But actually we are using a new virtual hard disk that we just created inside the virtual machine. Urine murder, 30 gigabyte hard disk. So it's a new empty hardest. We have no problem erasing it because there is nothing and nothing on your computer will be erased. And you click on install now. And it's like a reminder of what will be installed. Let's continue. You choose a trivial times on Chu's name and computer name. We make mine. Like that. Choose a buzzword K, so you choose a password and you can choose to login automatically or not. I would choose that become simpler. And now you wait so you can wait a few minutes. And when you're installation is complete, you will be asked to rust out. So let's click on raced up now and just press enter. Okay? Okay, let's keep that. You can choose to send data. Okay? And you are going to 2004 is now installed. And before we continue, just a few more things to setup. So if you tried to go full screen, as you can see, when you change the size of the window in the virtual machine resolution will not change accordingly. So that is something we're going to fix right now. First we're going to open a terminal. So you can click on here and type terminal, and then you can open it right here. Also, right click here and add two favorite son. Now as you close the terminal, it's still here. Okay. So you're going to do sudo APT update first. You put your password that you just selected before. Okay? We're going to deal with those packages later. And now you're going to install. So we should do a PET installed, you're going to install those packages. Will essential. Gcc make pearl and dk MS. Okay. So you press yes. Okay, and now you can reboot your machine. So polar of the machine right here and you can read it. You can always start from the VirtualBox. Okay, now that your virtual machine has been reboot, you can go to here devices, insert, Guest Additions, city image. And you can click on around. Okay, as you can see, there is a city here, so but your buzzword. Okay, and when you get this message, you can actually press enter our emptying to quit the window and now you into restart again. Okay, and actually as you can see, it still doesn't work. Which can do is be jacked and insert it again. Okay? And I actually wrote again. Yeah, you may have to do this twice. And now if you try to do that, it works. So now you can go and finally eject the guests. Elision city. Ok. So you may have to do this operation twice. Mixture, you inject it, and then you click on exam Guest, Addition city and executes what's on the screen and then reboot. Now what you can do. So you can go on devices, shared clipboard and okay, I've already set it up, put it would be like this for you and you choose by direct channel. This will make sure that you can copy and paste between your host. So here my windows for your book and your virtual mission. And you may have to reboot also when you do that. And finally, you can open the Terminal. And we'll make an, a grade of every package we have. We've saw pseudo APT date, we've already done that, but they do APT grade. So from my case, I have 63 packages. May be different for you. All right. And now everything is set up and ready so you can install it was to make sure you reboot again. And now we're going to install Ross too. 7. Programming Tools I Use During This Course: in this video, I'm going to show you which tools in which I d. I usedto program. We've rushed to anyone to so I'm on Lee making the video. So you honored, stuck when I use a tool that you don't know, don't understand But anyway, you use any tool any idea you want It will already not matter for discos and for your us to experience. So that's a full I will, of course, use the telling on its turned out you into terminal and I will also use the what's called Terminator. So tell me NATO is kind off improved terminal where you can split can easily split the screen and have multiple terminals like that. For example, I can split easily in four. Any layout on I want and I have for different terminals. If you want to install a Terminator or you can simply type, it's still a pretty and still in Terminator you have been I breakages for you want to and you can find documentation on Google. You can easily find the Terminator keyboard shortcuts. What I used here is control shift. Oh, and control shipped it to split the terminal and you can Well, you can find the rest of the documentation on the Internet, so I will use sometimes the standard terminal sometimes Terminator. Now, to write code, I will use visuals to do code as a main idee. So visual studio code is free to use and I find it quite convenient to write a python and C plus plus code for us, too. We just show you my extensions. So I have only three extension here to keep it very minimal and simple. The C and C plus plus from Microsoft, the bison from Microsoft and also this image for because we will need to edit some Simic files. So we have the make long which support when we write the fine. And one thing you can do if you are using the S code, is to install to a pretty installed python three b i B. Which anyway, I think you will need one day or another. You can install that so it's already installed for me. You can install that because when you start editing some python file, you will be able to use the auto formatting and to use the order form a team you can price control shift and I and first time you do that, it will ask you to install a P I P package, actually toe install it for you. But you will need to have a wife and three p i. P. Okay. And lastly, I will use jet it so jaded when I simply need to edit a very simple text document when it's the most basic text eight or you're right text you say even you close to find that it. So that's my main set up. I hope this will help you navigating the course. And just as a conclusion, you juice whatever you want. The point here to learn Rose to with the tools that you are more family we've 8. Install ROS2 Foxy Fitzroy on Ubuntu 20.04: Alright. You know, Have you been to 20.04 installed on your computer, whether it's a Jewel boot, our virtual machine, all the following instructions will work the same. So first you can go on Google and type in star rose to folks. And you will find this page actually on index.js dot org. We've installing morose to foxy Fitzroy and we're going to choose binary packages for human to right here. So a little bit. And that is all of the instructions you will need to follow to install ROS to foxy. Actually, I will show you which one you need and some of them you actually don't need, So, well, let's get started. You will set up the local first so you can copy and paste those instructions here. K, this one, then that one. Okay, let's set up the sauces. Okay? And add the repository to your socialist. Okay. So that's it for the first setup. Now you can install R was two packages. So you're going to update first because otherwise you will not find a new packages for the new sources here. And then you're going to install Ross foxy desktop. So you have a choice here between Ross foxy desktop and Ross boxy rules-based and basically borrows folksy aerospace is well the base of which we need, which means the communication messages come online tools, et cetera. And foxy desktop is Crosby's plus GUI tools and demos and tutorial and some other stuff that you will need later. Okay, so just install that one. And as you can see here, we have a lot of packages, okay? Because foxy desktop is basically a collection of many, many packages and everything will be installed just with one command. And as you can see here, almost 2.5 gigabytes will be installed. So you press yes, and then you may have to wait a few minutes. Ok. It's down, so actually great to quite some time. But now every package that you need to start installed, just one more thing that we will install right now is the completes. So let's do that. Anyway. You will need Python three PIP quite often. So that is a good thing to install. And let's install the conflict. Okay, now everything you need to get started is installed. What you can do first is to reboot again your virtual machine and make sure you watch the next lesson, which is very, very important on how to setup your under or not. 9. Setup Your Environment for ROS2: Okay, now refers to is installed, but to actually use it, you will need to source one setup scraped from the global Ross to installation folder. So what am I talking about here? If you go to slash OPT slash ross, OK, this is where you will have all your rows and rows, two distributions installed. You go to foxy, which is what we just installed now. And here you have setup the bash. You need to source that script here. And once you have solved that script, you can use Ross to in these terminal in this session. If you don't save that script, you will not be able to use Ross to when you will get an error. Ok, so if I open a new terminal, I will still need to let Sam here. I will still need to source slash poverty or OS foxy setup that Bash. And we need to Sue's that script in order to use cross two every time you open a new terminal. So one thing we can do, because it's quite annoying too, always solve discrete when we open a terminal, is to add that to our bash ESI, which is right here in our home directory. So you can use gedit to append the rash assay. And at the end of the Bash assay, right at the end, you can add a new line. And that line would be source setup, done bash. Ok. You can save your Bush messy. Close it. And when you open a new terminal, whether it's a new window or anything, you're gonna musician. Your bash assay will be sourced. And it will also source the setup dot Bash script from the global Horos to installation folder. So this step is actually very, very important. If you don't do that, you won't be able to use across two. 10. Launch a ROS2 Program!: after all these installation process led Simply launch your first rose to program. For that we won't right Any code? We just use existing examples that were downloaded during the installation. So just type what I type and it's just a preview off what we will do next. It's OK if you don't understand everything. Their point is just to get something walking quick so you can type rice too on space and then press tab twice. Okay, you first Awful. If you don't get that, it means that the rose to installation may not be complete are you may not have sourced the environment and put that in your bush s e So if you don't get that, make sure you followed the previous lecture and made every stick No, let's run our program. So we will do rust to Iran. We will select d move nodes CVP in Dhaka. So we are launching the talker program from the day more notes see PP by cage And as you can see, we have a log talker is publishing Hello world We've a counter and now in another terminal which is also sourced because the bush Jesse was executed with that line we can use Rose to ran. Um, they moved note sapping and least now and listener. So this program in this program are linked, Of course. And the listener will listen. Toe the tanker. Andhra Sprint. What gets so you can see here? We just brings the messages that were published by this program here. If I killed so you can kill a program by using control, See? Okay. And as we can see here, no new message. If I started again, we have the messages from detox. Great. So you have launched your first rusty program on. But the point of this lecture is that you can check if you're Rose to installation is correctly working. If you have that, it means, yes, it's working. And now you will be able to go to the following and actually write your arm rose to programs 11. Write Your First ROS2 Program: All right, Russ, to ease. No installed in, configured before you underlayment. Now, in the next few lessons, you would write and run your own rush to programs. All note, I would explain what is a rush to note, and then you would directly create one to set up. And, you know, do you will first create a roasting workspace in your home directory. Then you will create a package inside this workspace, and you were right. The node inside of black age. Set the note up, combine it and run it. As you can see, lectures are duplicated for bison N C plus plus. I start with Python then and do the same thing with C++ so you can learn with both languages and see the similarities and differences between a python rose to program and this SEPA space for us to problem, even if you want to learn rush to with only one language. I ready and courageous to at least watch lectures for the other language. And at the end of this section on nodes, you will be able to download the complete workspace we've owned code for both languages. Now go to the next lesson to create your US to work space 12. Install the ROS2 Build Tool - colcon: To create your own Ross to programs, you will need a build tool Specific to Ross to. So these build tool is called conquer and was specifically created for us too. So let's install it. Now. You can install, we've pseudo APT install Python three, coke on common extensions. Okay, so you install that. Great. So cocoa is now installed and you can use it. I will not go into too much details right now, but you will just see how to use it very soon. And along this course I will explain it a little bit more. And actually there is one more thing we need to set up with Qualcomm, which is the autocompletion feature, which is not enabled by default. So we would need to do that. You can go to Follow me. Their user share called cone are complete and hook. Okay, here you have a bash script, call con are completely bash and you will need to Sue's, that's great. In this terminal in order to use the Add complete focal cone in this terminal. So again, you can do that every time you need to use a complete with Coke on. Or you can also just go to your bash SE and add this line. Okay? Alright, lets add it right here. So what are we going to do? Source, and then I'm going to copy the path here. And then I'm going to copy the script and slash, OK and save the bushfires. So these first-line, very important, if you don't do that, you won't be able to use Ross throughout all. These line is less important. It's just when you use cold gone to build your packages, which we'll see later. It will allow you to use the autocompletion features. 13. Create a ROS2 Workspace: In this lecture, you will see how to create and setup a arose to workspace. This workspace will be the place where you write all your code for a roster application. And that's also where you will compile this code. So let's create a workspace. First. Let's go to the home directory and I will create a folder named Ross to an oscar WAS four workspace. You can name this workspace folder as you want. This is just a convention that you will often see in the earth to community, which is domain, your workspace for us to Ws. Inside this folder, we're going to create a SRC folder, which is source folder. Okay, so we have that, which is our workspace and all the code and packages that we are going to create in the following will be in the source folder of that workspace. So now if you go to the roster workspace directory, you can do Qualcomm revealed to actually build your workspace. And we've just installed Qualcomm before. So if you get an error here, make sure you've watched the previous videos. And as you can see, we have a successful and build them. And of course, we have 0 package because we didn't put anything in the source directory. If I check what's inside. Now, as you can see, we have three more folders, which contains log of the build process, and then a bill folder and install folder. If you go to this install folder, here, again, we have a setup dot Bash script. We also have a local setup dot bash script. Okay, so guess what we will have to do? Well, we will have to source that script on that one. So here for example, I'm going to solve the local setup dot dash. And which means that now I can use whatever I've created in this workspace. So we have local setup and setup. What is the difference? While a very basically local setup, dot dash will simply source that workspace, which we can call an overlay. And that's it. And setup.py ash will source this workspace here plus the underlay workspace, which is the global Ross to installation. While that is quite a nuance that you don't really need right now to start with Ross to. So basically in this course, I will use this setup that Bash script. It just brings a less confusion. So again, if I open a new terminal, where do I need to do? I need to source this set of dots Bash script if I want to use the functionalities from the workspace, which means the functionalities I've written. So we're going to the bash SEO again, which is in the home repository. And we already have souls. Opg Ross foxy settled the bash plus the cocoa are complete, but we don't care about that right now. And you're going to schools for us to workspace installed and setup dot. Okay, so again, I'm using the setup instead of the local setup just to make things simpler, save that file. And now when I open a new terminal, that script will be solved and thus create will be sourced. So I can be sure I can use neurosis, two functionalities. I can be sure I tend to use my own functionalities that I've added in the workspace. 14. Create a Python Package: to create a Ross to node, you need a pack. Age first packages will allow you to separate your code into radios able blocks. Each package is an independent unit. For example, you can have one by cage that will handle a genera, another package for the wheels off your Robert and yet another package that will handle motion planning for the robots in the environment. So let's create a bison package in your new rose to work space. So first, you we navigate to the Susan territory off your workspace. This is for no empty. And to create a package, you simply type Ross, too. BTG creates. So that is the command to create a new package. No, you need to give a name. We will call it my by pick a. G. So my bison package, that's simply a name. So we can use it during the ghost for all the python to toils. And now you need to add an argument to specify which kind of package you want because it rose to. There is a difference between a python a cage in a C plus, plus a cage, so you will use the real type argument with payment bite. Some island is the guild system, and Ayman Python means you want a python back age. You can also add some dependencies, so dependencies are simply packages. This new package relies and as we will write some code using a rush to, we need the rose to buy thunder library, which is called a seal by So LCL by you will basically use it in any off your US to by phone programs. You can no price enter. And as you can see, many folders and fives were created. We now have a new folder, my python package. So let's see what we got in that folder. I haven't been the source directory off the rust workspace on visual studio code. And as you can see, we have different folders and fights. The film's folder has the same name off your package and will always have. Okay. And in that folder you will put all your python notes. It already contains and in it that by fire, you don't need to touch that. Actually, and we had you notes here, then you have a resource folder. We don't need that phone. No. A test folder already containing three test file, you will be able to put your tests on the folder and then we will check the package Dog excrement. So each rose to my cage. Either A super Express are a python package will contain a package dot XML file. In that file, you have basically two things. The first is a bunch off information here. So the name the version off your back age a small description and then leased off Maintain airs followed by license. As you can see, this is Mt. Phono. If you ever want to release your package or share with the open source community, even at a commercial license there, you will need to edit on those tax. But for now, we don't need to do that. Then we have the dependencies. So the dependencies, as you can see, we have the sale by that we specified when we created the package. So if you need to add a new dependency, we had another depend tied below network. And here you can see the a Mount Python bill type for the package. Finally, we have to set up that CFT and by five we will see that when we actually create a rise to note that will be useful. Toe installed the node in your under a minute. So your package is now ready. We've just one line. You have set up everything. And if you want to compile your package, you will simply go to the rust to workspace doing your work space. And you will do coke on wields. Okay. And your package is no successfully built. Onda. If you want, you can also it's what we will use in this goes you skulk unveiled, followed by packages select And as you can see, I price stop and the competition works. If it doesn't work, please check the check out the previous lecture where I showed you how to any will do the condition for coca So packages select followed by the name off your package my bites on package. As you can see, the result is exactly the same because we only have one by cage for now. But if you have many packages, this will allow you to just compile what? My cage. If you want to make only a few tests in one package, you can come by on Lee That bike age and the development time would be much shorter. All right, you're bite on packages now already to host any python node 15. Create a C++ Package: In this lecture, you will see how to create a rush to C plus plus package. Police Make sure you've watched the precious lecture on how to create a python package. So you will better understand. So we will goto our workspace again in the source folder. And here we already have one package my bison budget. When we create a new package away for us toe p k g create. And let's name this package my sippy, please. My cage. So that's where we would but all our C plus plus code for this course Now you will also specify building type and instead, off a Mount Python, you will use a meant see image so that will create a super express package. We we also add a dependency Shell City P. So you have s here by for bison and LCL sippy for Cyprus press, which will allow you to use all the roads to functionalities in your C plus plus code so you can press enter and you can see we have in you a cage. Let's see what we have in that back age. So first off, you can see that the architecture off the super Express package is quite different from the architecture off the python package and that just because we changed the build type here, so that's very important. Okay, now, in that SIMPLEs press back age, we have an include in a Seuss directory, so it's quite common in super Special. But you're head of five in a include directory and your CPP fives in a source folder, and now you have the package, the excellent, which is basically the same thing. As for the python back age, we have the information's first, then we have the LCL City library. If you need causal dependence, easy would simply add another depend tight below that one, and you have the payment seem age flag that we used to create the super sports bike age and also you have a Simic lists that txt and when we use separate space, we need, of course, to combine our code. So that is where you will do that. That is where you will also say where you want to install the coat etcetera. And as you can see, we also have here the dependency for a seal syrupy. So if you need to add a new dependency for your super sports bike age. You will need to add it here in the package that XML and also in the Simic list that txt and we will talk about this fight more along the schools. So now if you want to compile this package again, you will go inside the rust to workspace directory and use gold cone build. So that may be quite long for first time. And you can see we have my seat prosperous back age and my wife on vacation that were built . No, if I do that Kalkan veal by catches select and I Onley right my CPP a cage. It will only build my sippy package so you can see how the packages select argument walks here and it will be quite useful when you're so you're simples press package isn't already . Now let's see what is a node so you can write your first note inside your felt packages 16. What is a ROS2 Node?: what is their US to know them? The note is a simple out off your application and should have a single purpose. Your application will contain many nodes which will be put into packages node. We then communicate with each other. But let's just see with the real life example, I will show you a very simplified example, so you can easily understand what is a node and why is it useful? Let's go back to the pregnant slide where I explain to you what's packages where? So a package is an independent unit inside your reputation. Now a package which is empty will not do anything, so we will create nodes inside the packages. We start with the camera package. This by Cage will handle camera as an independent unit. So what should we put inside? First, we need a driver for the camera to be ableto program it and get frames from it. We also need a program that will take those frames and do some major processing world. We could also add any other program related to the camera. We are using all those programs in blue note. Each node can be launched separately, so first you will launch the driver and then the image processing note. Now the nodes will communicate using Ross to communication functionalities, which would see later in this goes. All right, we have our camera cage field with older knows we need that. Sometimes it can be quite hard to know if you should. But to note in the same package on that, for example, the image processing note could be part off another package, which only handles image processing for any camera. We could add many other processing nodes, and this new package will communicate with any of the camera back age, which include drivers. But for this example, let's just say that the image processing is specific to the camera we're talking about. And both driver on image processing notes are using some common dependencies. We have another two packages in the application. Let's check the motion planning footage. So in this package you can expect to have a motion planning note, which will compute motion planning for your Roberts. We can also add a bath correction, know which role is to modify the motion planning due to external fighters so great we have to package ease field. We've known when we can do now is to make two nodes inside different packages. Communicate together, willing the image processing node to the path correction node. The image processing No will analyze frames coming from the camera, and we'll send an analysis of the umbrella and to the path correction load. These node will then be able to notify the motion planning node, and we finish report that by Cage, which is the hardware control, this package as an independent unit will control the hardware off the Robert that can be wheels, a robotic arm joint or anything else in this like a will find some drivers to control the models. The drivers are controlled from the main control look Norwood. And finally, let's say that the position data, which is coming back from the motor on cars, is sent back to the control group for precise control and is also published by a state publisher, Node. We have three nodes in this package, and now the motion blending node from the motion playing back age will send computed tragic Tory's tow. The main control look node inside the hardware controlled by cage, the complete the architecture the hard way studies of the Robert is published, and both demotion planning and path correction loads are getting those messages. Well, that is maybe quite complicated for you to get everything right now, but I think you have a better idea off what is node and why it is useful. Feel free to come back to this lecture after you make some progress on the schools, you would understand more things. So you've seen with a real life example how note I used. Now let's go back to the no definition. A node is a set programme off your application, which is responsible for one thing. Just as when you write a class with object oriented programming, you know that a class on Lee serves a single purpose. If you have truly from functionalities to implement, then you have two different classes. Well, that's similar for nodes. No, it's combined into a craft and communicate between each other using Ross topics, services and parameters. We will cover the communication toes in the next sections. So what are the characteristics and benefits off nodes? Faithful there reduce go to complexity. If you correctly separate your application into packages and nodes, then it will be much easier for you to scale your application. Trust me, if you write everything in one block, then after some time you spend more time fixing your code than actually developing. New functionalities. Nodes also provide a great fault tolerance. If you run your nodes in different processes, then they are not directly linked, and they can still continue to communicate, thanks to rose to communications. So if one not crashes, it will not make the other knows Crash first. That's great for they begin and signem. That's great. If you have, that's a critical node running your hardware that is well tested, and you just add another new note in your program. Even if this later noted can crash, it will not affect the critical Harlan node Russ To is long wage agnostic. It means that you can write one noting python. Another node in C plus plus, And both nodes can communicate without any problems by phone and see Christmas under two most common languages for Ross to through some other libraries, you can also use other languages to create other notes. This characteristic is really great. For example, you could choose to develop your entire application in bison wide. Some note we be written in simplest test because they need fast execution speed. Note that two nodes can't have the same name. So in your programs and in your code, you will have to make sure that all nodes names are unique. All right, so in following, we'll see how to actually create nodes in both by stone and c++, how to use them with common line tools and then how to make them communicate between each other. 17. Write a Python Node - Minimal Code: Now that you know what is a node, let's create a Python node in your new Python package. So first, you will write the node and then you will see how you can install it and run it. And then you will see how you can improve the node with object-oriented programming. And you will get a complete template you can use for all your Python node. So let's go into the Ross to workspace that you already created. In the source folder you have the my Python package. And in this package we have a folder which has the same name as the package what will go inside this folder? And here we will create our file to write the node. So for example, let's name this file, my first node, that Python. You can now edit the file. So let's find it. And first we will add the interpreter line for Python three. Okay, so gross to only works with Python three, know Python two anymore. And we will create a structure for the main K. We create a main function here. And we will put optional arguments. Okay, so that is very basic Python structure. And now we want to use the Ross to functionality. So to use Ross two functionalities. We will import by LCL by, if you remember, we added the dependency to LCL pi and you can find it here in package dot XML. This is the roster library for Python. So the first thing we will do in our program is to initialize cross to communication with partial pi dot in it. And we will pass the arguments from the main. So args equals Ax. And so the arguments from the main function will go to the argument's name, our dogs in the axial pilot in it. This line is the first line you need to write in every Ras to program. It basically starts the Rostow communication. And if you've tried to use any of the rows to feature without that line, it will ofcourse fail. So then you will write your code and at the end, you will write S hill by that. Shut down. That will be the last line of your program. So basically you first initialize Rostow communication, you do your program and then you shut down the communication. We will now add a node inside the main. So we will create a node. And to do that, we will import the node class from SCL. By that node, import the node class. And we will simply use the constructor here with the node name as a parameter. So let's call it python tests like that. That is the name for the node. And note that it's best practice not to. For example, you could say Python test node. But for the name of the node is better not to use node because it would be redundant. So your node will be created. And then immediately after that, the Rostow communication will be shut down and the program will exit. When the program exits, your node goes out of scope and it is destroyed with everything that you've created inside this node. So you don't need to do it manually. And because this program will not do anything, let's actually print something. We've get logger. So you will use the get logger function from denote objects. And then you have painful for example, and let's say hello, rows two, so that is your hello world in rows two. So to recap, you first initialize Rostow communications, then you create your node, you give it a name. You then print something and you shut down the rows to communication. The node is not the executable, the Nazis not define the node is created inside the file ok, that is important, and the name of the node is not the name of the file. So now let's try to run this node. The most basic way to run this file is simply to run the pythons rate. So we will market has executable and simply launch it. As you can see, we have the L0 Rostow, it's working. You have the info, they'll flight for the log functionality, the timestamp and the name of the node followed by the actual log. You will have that for every log, you do wait for us to, and we will come back to our program and add one more thing here, LCL pi dot spin, and we pass the node to the function. That function is very important and you will use it in almost all your programs. So what does it do? Spin will basically put the program here, will pose the program and will allow your node to continue to be alive. So for node, the node that has no real functionality. But later on, when you start to add some publishers, subscribers, services, et cetera, then you would have code to execute and you will have callbacks. And those call-backs will be able to be cold from the spin function. So let's see, actually let us see what it does. As you can see, we still have the hello Ross to line and now, now the program is still running. Okay, nothing is happening because we didn't ask it to do anything, but the program is still here. And if you press control C, then the program exit. And don't worry about the log here when you press Control-C doesn't really matter. So when you press control C, the spin, we stopped, so the node we stop spinning. And then the program will resume and you have the shutdown of the roast to communications. I would often come back to this spin function and you will understand it after some practice. So that is the most minimal node you can right? Now, we will see how to install this node. So with Python, of course, you don't need to compile the file to execute it. You just mark it as executable and you can just run it like that. But we rose to, we will install the file into your workspace. Because if you always want to run your node from the terminal directly like that, it's not that scaleable and you will be able to have much more functionalities if you install the file and we will see the benefits a little bit later. Let's see how to install this file. We will install it from the setup dot pi here. So you have set up the CFG, which will tell where you will install the file. And here you will say, in this array console scrapes the files on the nodes to actually installed. So if you take a look at this setup.py file, you have, for example, version maintainer description license. And that is quite similar to what you had in the package dot xml here. So if you ever need to release this package, you will need to edit that and also the lines here. So those will be identical to those in the package dot xml. So to install the node, we will add a new line here. And we will need to specify a name for the executable. So what will Ross to do when we installed fine. It will take this file here, it will copy it and make some modifications. So it becomes an executable for arose to end that executable will be installed in the install folder of your rows to workspace. So we need to specify a name for the executable. And let's, let's use something different here by so we use Python Node for the executable. Then you will need to put the name of the package, my Python package, that name of the file, My first node, and then point and name of the function you want to start. So we will start from the main function right here. That's why we created this main function instead of budding all the code right here. So that should be okay. We will go to our workspace and coke on wheels. We can use packages select, select. So we only build the Python package. And let's see where this node has been installed. So we will go inside the install folder. You have the my Python package. And inside that you have labor. So why leap? Because here you have leap, okay, that's from the CFG. You go to leap and inside Libya will go to my Python package. And here it is. So you can run it and it works. Then you press Control-C to kill the node. So you already have two ways to start your arose to know either directly from the file that you're creating or from the file that you installed and not hear. The name of the file is by node. Just as we requested here. It's not the name of the file year-old. Ok, that's very different. And we will not use either of those two options. When we actually start cross to note, we will use a rush to command line tools named Ross to run. So after you've compiled your package and install the node, going another terminal and it's better to source. First, you bash assay because this will source your roast workspace for this under unmanned. And when, for example, you create a new package or you create a new node, it's always better to source. You're under a month through the bash LC. So you are sure you have the latest version and you don't get any error when you try to access some load on other stuff. We will simply type Ross to. Then followed by the name of the package, my PI package, followed by the name of the executable you studied and it should work. Yes, the node has been started just as before and you can kill the node. So in the next section we will see more about this command and the other rows to command line tools and to recap quickly. So you have created a Python file here. And inside this file you have created a node. Okay, so the node will be created when you actually write this line, when you call the node constructor. And one important thing to be sure to understand is that here you have the name of the file, which can be different from the name of the node, which can be different from the name of the executable. Okay? That's often a common misunderstanding when you start wave Ross T2. And now that you can create and run and install you first Python node. Let's see how we can improve this structure here with object oriented programming. Because that is the recommended way to write journals. We have rows two, and it will make your life much, much easier in the future. 18. Write a Python Node - With OOP: Let's now improve this note over there with object oriented programming. It will make your note much more scalable. And it's also the irregularly way to write node in roast to directly from the roster on Tim . So first, we we create a class. Let's call it my node. So the classroom, of course, be named after what you want to do. If this is a camera driver, then you will call this camera driver No. Okay. And we will make this class any rate from node from the node object. So that is the way to create. They know what you create. A glass generating front node object. Then we will write the constructor off the class and we would direct tickle the super function in it so that we called it in its function from the node and we will give here the name off the node and then we can also use this line. So instead, off note, get longer. We will actually use self yourself for this object, which is a note so we can directly called the longer from self. And here we were removed that instead off creating a node object. When we create a my node object and well, that's it. This note is exactly the same as before, but using object oriented programming, let's run the notes. So we will compiled again. Let's find the Kalkan grilled lying, okay. And the free rent knowed everything is the same because we didn't change anything. And that will be your template for writing rusted by thunder. I will give you the template later on on this sanction. So you can directly kind of copy and paste that every time you won't create a new node, you we need to change. Of course, the node name here and the node name here. And if you want, you can put a log on that. And now let's, actually, because this note still does nothing about from printing alone, let's use one of the most basic and common functionality in Ross, which is a timer timer will allow you to call a function. We've given rate, for example. You want to call a function at 10 house, then you use a timer. So let's do that. We will do that directly inside the class that we've created here. And before we create the timer, we need a callback function. So let's go, old timer. Call back. Okay. And in this function, we will says, Get Lovera painful and let's say hello again. OK, so we have a function that say's hello And then in the in its function, we will do self create timer. So this is a function from the node object we can enjoy could get with self. The first argument is deep period between two callbacks. So let's say we want to bring at, uh, two hats. So, too, has the zero point five seconds. So one time every European, five signals and then we need to give a function toe called and we will leave the function of time or call back self time callback because the function is defined inside the node. And now let's run these so again we can build it so it will be installed and we can run it here. OK, we have hello printed every zero point file single Great. You can press control, see toe, kill the note and let's improve a little bit. Knowed we can, for example, add a country self counter zero and let's say that we increased the counter goingto by one every time the cold batch is cold and we will simply print hello, plus the counter value. Okay, so what this code will do is insure, right? Viable here 20 Then we print along. We create a timer with 0.5 2nd between each cold bite. And then we give a callback function, which is this function. And in that function we increased the counter every time and we print hello, Counter. Okay, So everything here will be executed when you write this line here when you call the my node constructor. Okay. And then the SQL guy speen will make the node speak so the timer will continue to run. Why the Spain is still running, the timer will run and you would see that lying printed until you press control. See? And when you press control, see, there's bean real exits and you'll note won't be spinning anymore. And this will not be able to do any kind off callback like timer subscriber. Everything else. So let's run this again. And as you can see, if you have in, there are a syntax error in your python five and you will get the era when you build the package. And when you try toe installed the executable, so it would not only create an executive ill, it would also check that the syntax is correct. So know that the syntax is correct. It should work. Okay. And we can now execute loading Hello, one juice free exit. So, as you can see, we can easily create a complete functionality with just a few lines of code and know that you can write your code inside your just. Um, no class. This main function here will always always be the same. You initialize roasted communication. You create your nose, you make your no spin. And when you press control, see this exits and you shut down Rusty communications. 19. Write a C++ Node - Minimal Code: In this picture you will learn how to create a C plus plus No, you were right. The note compassionate and ran it. We will follow the same order as we did for the python load. So you will go in the source folder off your workspace, and here we go in the simplest plus by Cage. In the simplest perspective, we will also go in the source folder, which is no empty. And we will create our 1st 5 here. For example, my first no nut cbb. And now we can edit this file right here. So let's write a may function. And to be able to use the last two functionalities, we've c++ we will actually include s he'll simply be So let's do that. Include you can find it under Aircell CPP slash s yield civility dot HBP Okay, and let's save the fight. As you can see, we get a warning from via scope. So this is only specific to the escort, right? This we work if we come by it. We've called comm build, but we ve a scope via Scott doesn't know the path here, so we we need to add it manually. So that's your price control shift and be okay. And you can actually type C and C plus plus off figuration. And you will find that line Any configuration, Jason. And this would create a that Vince got folder in the so territory here because we used that as the base folder for the escort and you would be able tow edit the C and C P properties. So what we do here, we will include another bath and which path is that? Is simply the include folder off your global rose to installation so you can find it under a slash hoppity ross and then folksy and include if you see what's inside include, well, you have older packages that you installed during the installation. You can see it's quite a lot, and that is all of the age and HBP fights you can use in your coat. If you install more packages than more HBP files will be available here. So what we do is simply we take this bath here and we can add it right here, save the fight and that should be it on. Yes, it's working now. Issue do that sippy. Okay, you have the auto completion, which is working. So the felt thing we do again is to initialize rose to communication with SCLC PP it and we need to pass the ag C in our grief from the main function. So we initialize roasted communication and yes, what? At the end, we will shut down just like a python. And now we will be able to create a node between those two lines and let's use the 02 type node and we will use STD make shared. The type is personal, See PP knows so you can directly find the node object from the SL city. Okay. And as a parameter, we need to keep the name of the note. So let's go it civically test, just as we need for bison by test here it's securitised. So as you can see, we used STD neck share toe, create a shared pointer so outer will be a shame. Goingto which has a node if you ask family. We've destiny shared pointer. Maybe you should check a little bit more on your own, the documentation for shut point or is quite complete and you have many examples on the Internet because for Cyprus press Ross to uses SharePoint tales everywhere. So basically it is great because you don't need to use new and deal it manually. When this point when these share pointer, we go out of scope, then it will automatically destroy no, which is inside and everything inside the note. We'll be destroyed and you don't need to manually check if the pointer goes out of scope. It's at the right side and no, let's make our node say something. So here we will not directly use a get longer function Liking python from the newly we will use else ill see PP in foot like that and node get logo. So we used to get longer inside the SCLC VP in Fort function and we can say hello here. Hello, CPP No Okay. And let's also make the no spin as you see PP Speen and we passed the note so that's being function expects to receive a shared pointer to a NCL CVP knows what she is correct in this case. All right, so that is a very minimal simples plus node you When the main gates executed first, it will initialize Ross to communications. Then you create the notes. So it's a SharePoint toe a node. You give it the name Note that the note is created inside the executable. It's not the executive, okay? And then you make it brings something and you spin. So when your spin, like in python when you spin it will pose the program here, and it will give the note alive and every functionality you implemented for this note. For now, we don't have any functional edges, so nothing will be down. And finally, after you press control, see, that's being will stop. So the note we stop spinning and shut down would be called so all of the rest of communications will be shut down. And then the program exits and simply No, it would be destroyed because we've shared pointer. You don't need to worry about that manually. So now let's run this goat so off course, we can't directly ran the C plus plus file like that from the terminal where we need to compile it anyway. So we will compile it, and then we will install it. To do that, we will use the Simic list. That text actually, are we playing some off the lines here? we don't really need the default to see 99 We only use the default toe c++ fortune and I will remove the tests. OK, just to make this course a little bit clearer with the minimal coat. So we have, uh, dependency to else you'll see. Very. It's already here and now we will use add execute table, and we need to give a name to the executable. Let's go eat C plus plus notes. So that is the executable. That is not the name of the file. And that is not the name. The note, which is different. Okay, those last three different things. And this is from the source folder and the night I first note that city fired. So the source folder here on this pile here, we will also need to link the differences with payment. Dugit. Dependencies. So this is not a standout seem Eight declaration. All right, It's specific to payment, which is the build system. So separately, note which is the executable. And then we will link the sl CPP library here. So those two line we actually create annexing table. But the executive alone will not be installed yet, so it should just combine that you won't be able to run your node. So that's why we will use install. We've dug its Okay, we will. But the CPP noted here, and the destination will be on a limb. We've the project name. Okay, so that is the lib folder, which will be inside the install folder off the rust workspace. Okay, that is similar to what we had with the python by cage in here. Okay, you have the lib folder here, so we will choose to put the executable in that father followed by the project name, which is simply the name off the package. So here we create executable and here, waiting for it inside the world space. Now we can go back to the workspace and coal can build and let's use packages select So we don't build everything. My simples place my cage. Okay. And if we go to the install folder, my c++ by cage inside, we have a lead folder, okay? And the name off our package, which is exactly what we asked for. And here what we get is an executable, which is CPP note. And that is what we asked here. We asked to create an executable and then to place this executable into the lib folder here so we can run this exactly table or and it's working. We have hello CPP note and the note is spinning so we can kill it with control. See? And now, of course, we not always have to go to install folder and go to this path and manually start all the node. It's installed so you can use the rest to come Online tools. Let's in a new terminal. Let's source the bash. Has he? So it would so skinny rasta workspace? Because you've created a new exit table. So it's always better when you create something new to source their workspace. And let's use Rose to run my CPP. You can brace tub. Okay, if you press tab Nope, not enter press tab two times you have the auto completion. If I pressed up two times, I get only the note that I can start. I mean, all the executor tables, of course, And simply node. Okay, it's working. So we've just this Come on line. Weekend starts. Well, note. And that is a minimal c++ node. And now we will see how to improve this note. We've object oriented programming to make it most cable, and so we would add a few functionalities to it. 20. Write a C++ Node - With OOP: That's no improve these C plus plus node by using object oriented programming which will make your node much more scalable. And we will only use that in the future. Also their class. We were right. He's a good template to write all your supplies. Pus note. So we create a class thing. For example, my know, if you were writing a robot controller No. Then it will be called Robert Controller Note. So we have a public in irritants to s you subject node. Okay, so we have public and private. We were right. The constructor. And in the constructor we were initialized the node with the node name. And so we have chosen CPP test so we can actually use these. So here in the constructor, we directly call the node constructor from the Mississippi node with the name like we did here. And then we can use sse pp to print something from the note and off course snows. No, it's this because the get longer is no, but off the class. So this God will do the sensing as that and we can actually remove that and simply create STD make share We my node and no argument here. So that main function will be the same for all your note. And you would not have more than five lines because everything you will write will be inside the node class. So again, here you initialize roster communications. Then you create a SharePoint toe note. So these constructor gets cold in it will create the node with city protests as a name. And then you will print something with the longer from the node. Hello, City note. Finally, the Spain is executed, so it will pose the program. The node will continue spinning and shut down. He's called when you price control seat so we can go back to our rock space and welcome reeled again. Okay. And the behavior will be that se. Now let's add something more interesting. Okay, we will see a basic functionality which is a roast two timer. So like we did in Bison, where we create the timer inside the mind node class and the timer will allow you to call a function at a given rate so fast we we create a time Merkel back. And when we make it private here, so time or cold match And what we do inside? This is simply get lo there we will just bring Hello Phono. Okay. And from the constructor, we will create the time. So to create the time where we first need to declare it, we will declare it here. As a private member of the class, you can use SCL a security timer, bays and then Chef Pointer. So this is specific to rush to its kind off a helper. OK, you can use shared pointer instead. Off using STD, Shep Winter off the timer based class. Okay, so for many off the castle sippy functionalities, you will have shared pointer share PTL Indian. So that is the time. And it's actually a shared pointer to the time. Okay? And no, we can initialize this time world say this create now it would be world timer. Okay, Not create timer. And again we need to give to arguments. The 1st 1 is a duration. And for that we will use STD chrono on let's say signals with an integer with one. So just one scene and the second parameter is the time or collect function. So because this is in a class, we can just use the time or call back like that where we need to use STD bind to bind this to the world timer function and in STD by new were right, my node like that time will call back so you can find a function here. Okay, So, reference Do the name of the function and then you will add this. So this is this No discuss, So the function will be bind to this. Okay, it's better like that. So you can price control shift and I in this code to but some other in your code. So there's syntax in Siplin press is always a little bit more complicated done in by phone . But for example, for STD buying, you just need to learn that you should use it like that and it would always be the same. When you create a wall timer, you will use an STD chrono where the duration and then STD buying. We've the Mitchell you want to call and this to restaurants. This object. So now we can, uh, compile a damn and executed, I guess. And as you can see, we have Hello. Every single I press control to see, and it stops so When I press control, see, the spin will end and there's all the callbacks. So, for example, here we have one called back and the one timer will not be able to call this function anymore. And then, of course, they know will be destroyed. Let's are a counter to make it a little bit more interesting. So we will add a counter here, has a metre bridge and initialize it here. Contraire. Zero. Okay, here we will do counter plus press and we can at the counter to our logo like this. So it's a little bit like a print of function. You will, uh but your string here on you can put the different via luz you want to use in your strength. So the counter is first declared. Then we initialize it when you create the node and then the world time we'll call the time of cold. But every once again here and every time the counter will be increased by one and we print Hello. Come toe. Let's do it again. So let's see if I simply starts it again. You can see that we don't have the new version. So you need toe. Actually build it so it will compile it and install it and let's run it. And hello, Warren, Hello to considering it's working. So congratulations. You have no return, a complete cross to note in both by phone and C plus plus. In the next lecture, I will give you a template that you can use for any off euros, toe python and surplus best notes. And that template will also be a template that we will use that I will doesn't use for the rest of discourse. Because, as you can guess, writing all the boilerplate code is quite annoying, especially if you can gain two or three minutes every time. 21. OOP Template for Your Nodes: So in the past few lessons you have seen how to create a template for your python and c++ nodes using object oriented programming. And if you actually want to get this template you can download, so you have the guard archive that you can don't know. Then you should already have it. Now you can find the code and Section three node. Okay. And if you get that, okay, you extract eight, and then you can open it and you will find the too dumb plates right here. So if you go in my python back age in my personal bike age folder, you will find a template python node right here. And that is the note that we've just written here with my first note, but only using the minimal code so you can copy and paste that in any off your programs. And actually, that's what we would do in the following of discuss. So I have put some commence here. We've modified name. When you create the class, of course, you will not name it my kristen. Nobody would do it. Name it accordingly to what you are doing in your application. And you will also need to rename the note here. So that is for a bison template here on day. If you go to the c press press back age, it is in the source repository complaints c++ Now that city. And, well, that is the exact same thing You will need to rename the note here. So here, here and here you have three Ren aiming for the no name and here also 22. More About the ROS2 Client Libraries for Different Languages: in this lecture you will learn a little bit more about the rust to architecture To understand the different client libraries you can use for different languages. So phone no, In bison, you have used SQL by and in some respects you have used SQL City. You might wonder, when does the libraries come from and why do they both start with our seal? Well, our seal is a rose to library and it means Ross Client Library. Our CEO is a pure C library which contains all the co functionalities under a sale. You have the roast two meter where with BDs BDs means data distribution service. This will handle all the communications in your application. I would give more details about that for now. All you need to know is that also is basically the lowest Ross to client library you can use and it is the bridge with the rust two meter. Well, the LCL is debased library forest, but you won't use it directly. Instead, you will use other client libraries that are built on top of house sale. For example, how seal cbb, which you've just seen before in this section as the LCP is a C plus plus client primary which basically provides P binding with us your functionalities in your code you simply use a C L civility and the same is valid for python. The scale by client primary is built on top of pass ill And then you just LCL pie in your python code. It means that whether you program we've see Christmas bison well, the basic library is the same. So simples present bison are the two most reported languages. But as you probably guessed it, we can add any other language on top of the library. In fact, some of them already exists, for example as hell. No Js for not Js hacia java for Java, etcetera. But all of that is a simplified view. But this should help you understand why we are using LCL CBP for Cyprus players and as yet by for python 23. Introduction to ROS2 Tools: great. You can create your first rust two nodes. Now, in the next few lessons, you will learn more about somebody. Most useful rush to tools those tools on important path of the arose to ecosystem. They will allow you to labour your nose and your whole roast to application. This is also a good opportunity for you to experiment more with note notes. Already full nation off anything. You were right in Ross too. So in this section you will use D rose to come online tool, especially we for us to run. And you will see more options so you can change for example, the nodes name you were also visualize the complete graph off your application using the Ark UT graft tool and or so you will discover total seem a to D simulation which is very practical to land, Russ. And that is also the simulation you will use for the Project Indian of this class 24. Debug and Monitor Your Nodes with ros2 cli: Now you can create your own by thon and suppress press node. You've also learned how to launch them for by stone. You can, for example, directly executive scraped and for both bison and c++. After you install the node, you get annexing que table inside, install folder off your rose to work space. And finally, you've also seen that you can use a common link tool named Ross to run. No need to navigate to a specific folder anymore. And as you're seeing this lecture, it will give you more control over. No, you are starting. So let's experiment with the rose to command line tool. You will see the rose to run that you already used and some other tools that you will use in the future. So when you open a terminal, uh, the bash, etc. Will be executed. And as you can see at the end, we have the line to Sousse. Our rushed to global installation and the line to Sousse, our Russ to workspace. So make sure you have those two lines inside your Bosch s and at any time you can also so strictly the bash and see if you are not sure that the new addition addition you made were sourced. So let's use the rose to come online toe. If you pressed up twice, you would see all day recommends that you get They are quite a few. And you've already seen Rose to right here and rose toe package to create a packet, and we would see some Howser wants in discourse. So issue press rushed to run. And this command expects you to be a pack age and an executable. Okay, so we can launch any executable from the rose to Global installation folder and from the rose to work space. So if you want to launch, for example, package from the demo nodes civilly, Chris Press and let's say the talker that we launched before this package was installed globally and this is an executable from this package, so you just press enter and it will start the note and issued press stopped twice here. Okay, tabby notes enter. Pay attention to death. You will see all the execute tables for this package. So, as you can see here, this demo package has quite a few execute tables. And of course, we can start our own node. So from my by phone by gauge, for example, and issue price that twice you have the least off execute tables. And as you can see here, we only have one. Executing will fall. No. So you can just type the impress tub and get the auto completion, okay? And it works. What you can do is type Ross to run Dash H for help, and you will get a help message for the command and for every command, you will be able to use that to get some help in some documentation. So, as you can see here, we need a position arguments by Cage name and the executable name. So now let's open a few more terminals, Okay, Like that will get screening for and here that's so every terminal here is a musician and the bash SC Waas. So just so rushed to global insulation and the rest workspace where sourced. So let's start our note again. So, Russ, to run my biting back age by phone, knowing which is exactly table and is acceptable will start the node by test. We can use the common line across to node. Okay. And if you pry step twice here you have a second on action so rushed to node and then reasonable least which will list all the nose in under a minute. And as you can see here we have one. No, which is by test here. If I killed the node, I stopped. Rushed to note least again. And of course, nothing is. Bring it here. So rushed to note lists will allow you to see all the nose running in your under. Let's start the note again. We can see Rose to noticed with brings my best. You can also use Russ to node thing full. Okay. This here with the name off the nude. And this will give you some information about subscribers. Belly shirts, etcetera. So, as you can see, we already have two publishes and we have 123 We have six service sellers, the publishers and service. Several you see here will be here for all you note. And here you can see very simple. We have rose out a publisher to rose out. We seek later What is a publisher? But when you print a log here when you send the log, this we go to rust out also and Russell. We get all the logs for your abdication, and then you have some publishers in seven sevens for the parameters. And so each node will handle its own parameter. You will see that also later. So if you want some more before you can do Russ to node Dash H and you also get help, Miss Age for these comments, Well, it's killed that here. And of course, if you try to get, for example, the information from the note that doesn't exist, you we get an era unable to find by test. Because this note is not currently in the graph. We can see it's we've rushed to note list. Okay, so now let's run this note again. And let's that for us to run my sippy people cage, that's down the other node that we've created. Okay, we have to note in our under announced now, and she wants to note least you can see that the two knows are present here. Okay, then you can do rushed to note in four with this one with this one. So far, no. You've seen the command rust to be cagey, create for a new pack age. You've seen Russ to ran. We've a cage name and executable name and you see rush to note, leased to list on the nodes in your graph and also cross to note in for with the name off the node to get the information. Thought this note. And it is very important to note that you should not have to note with the same name on your graph. And in the next lecture we would see how you can deal with that. And finally, I just want to show you what's happening if you don't sauce your environment correctly. Okay, so let's go to our bash SC on. Let's commend this lying here and also dislike you. So I opened a new Dimino. The bash Cassie will be executed, but those two lines commended so they will know the executing If I do rush to know the least rust to come and not found so that you get that Iraq, it means you have not sourced your global installation. Let's source are bash asi here, or you can simply open a new terminal and now our US, to note least will succeed. And of course we don't have any notes, so nothing sprinting but to command succeeded. Now I can do rust to Gran. For example, the D mu notice if BP will be found, I can launch the talk here. OK, but if I try to do rust to run my life in a cage, we've by no. Then we will get package not found because these packages not from the global installation but from the local rose to work space. We need to suit the workspace and this should woke okay, So you can see the kindof aero you we get if you have not source correctly your environment . So I hope that can help you in case you get that. They're also you, you know? Where does it come from? 25. Rename a Node at Runtime: in your rush to application, you may want to launch the same note multiple times, but we've a different configuration. For example, if you have a node for a temperature sensor and if you have five temperature sense ALS, then you would want to launch the same node five times and, of course, with a different name for each sensor. So one first important thing to know is that you can't launch the same note with the same name more than one time. Okay, so you won't get any raw when you do that. But let's see, let's see what it does. So for us to run my by phone by change, where we launched our first python node here. As you can see, Ross to node, least we have no here. We launch it again, Russ, to run my so in a different terminal. Okay? And we don't get a row here. Okay? It's walking. Or so we have to note with the same name. And if we do that for us to note, least we have a warning. Be aware that some notes in the graph share on exact name and this can have unintended side effects and As you can see, we have two notes with the same thing. And well, don't do that. If you do that, the notes will be able to start. But then you will have many problems in your graph on in your communications. Okay, if I do rust toe node info by test, you also get a warning here to nose with same name. And you are seeing the information about Onley one off them. OK, so previously in Ross one it was impossible to do that. But in Rose to now it's possible to start to note with the same name. I'm not sure why, but anyway, you should not do that, OK, it's important to know that. So how you can solve that problem with the temperature sensor where you still want to launch that note multiple times It's possible, and you can actually do that. You simply need to rename and know when you started. So let's start the nude again and we will remap the game for us to run my iPhone my cage. I know. So you just start like that and then you will add arguments like that Ross ag. So every rust to argument you real had after these dash, dash, roast, dash oz And then you have dash are you can do remap like that. And you're right. Double underscore node two point equal. And let's say ABC and the load is no named ABC. If I do rushed to note, least we have ABC. Okay, if you check the code for on the note here in my first node, you can see that we initialize the node with that name. But when you start the node we've cross to run, you can best some arguments to remap that name, and it will automatically change the name from there. Okay, so this actually is not a fixed value. It's not. It's like it's not like it's hard, Cody. Okay, You can always change it dynamically when you start the node with Russ to run So you can launch that? No. Here. And you can launch the note again, Rose to run my life in a cage. Cross odds that's used Ash park note. And let's say you can put any any name you want. Okay, Just follow the convention, and you start by a letter. Okay? You can then use letter on members and things like schools. Okay, so I stopped this. No, here. A nice stuff, This note here. And when I do roast to note least we have two different note. So that is correct. OK, and let's start another one rose to run, right? So it's down to C plus plus one gross odds and let's name it so of course, if I needed a B C, it's not correct because it will be the same as this one. So let's give it another name. And now we have three note running in our on there aren't so that future will be quite handy when you want to replicate some behave you and you would see in the next sections of this course You will also be able to re map almost anything from your no Dabic services at cetera. So you will get complete different and unique nodes all from the same executable. And that will follow you to configure your node at run time without having to change any code every time you want to try a different configuration 26. Colcon: in this lecture, I'm going to do a quick recap about Falcone and please stay until the end because I would show you a new option you can use to work faster with your python loads. So to build your cross to work space, you have seen that you can use coal can build a case, or Cancun is the build tool for rush to which will use a meant as a bit testing. And when you do Coke unveiled, it will build all the packages that are inside the source folder. You can use coal con grilled. We've packages select like that to build on Lee one on multiple packages. So if I do my python by cage, I would only build the bison package and not the other packages. Okay, And you can get the auto completion. Also, we've called on If you don't have the auto completion, make sure you have in your brashness e at the end of the bush Asi, make sure you have this line. And if you don't have that, then please watch Theo Kalkan auto completion lecture in the last section. So you know how to do that. And finally, here's a tip that will help you work much faster with your python fires. Okay. So far, we have built our python file off my first node, and that is the fire were built. So we have an execute table, we can run. We've rushed to run my by some by stage, by unknown and okay, you can see here is the output off the node. Now, if we modify something in the road, let's say I add an exclamation mark here. So if I start the note again, the exclamation mark is not prison. So we need to go here and to feel our package. Okay? And once the package is built, we can launch it again. And we have the exclamation lot. So every time you modify your fire, you will have to build it again. Unless you use the same bling install argument. So you just use this flag like that after the Kalkan Bill Clinton, you can press enter. And this means that instead off launching when you do rust run instead off lunching the execute table that waas installed, it will simply create a symbol inkling to your file which is directly here. So for the beginning during the development time, this would be very useful. So if I run the node, I still have one exclamation mark here. And now let's add two of the exclamation marks. Okay, I say the five, and if I run it again, I don't combine anything here, okay? I don't install anything, and we have three exclamation mark. OK, So as you can see, we don't need to combine the fight again. First, you need to use symbolic install, and then you can walk with your python fight without having to complain again. So off course you We need to combine once when you create a file. But after that, you can modify the fight and work like that during development time. So it is only for bison, because in Cyprus press you need to combine to fight every time. So, uh, it would only be useful for python. And also, if you wanted that it's very important that she goto your back age my iPhone by cage. So where the fight is, you have my first note. That tie is very important that this fight is an executable. Okay, If it's not an executable, there's symbol in clink. We'll not find the executable and you will get on air. Also, If you want to use the singling, install fly, make sure this is set as an execute table. 27. Rqt and rqt_graph: in his lecture, I will show you what is activity and after two graph. So activity is a direct tool. It's a G Y tool that you can use to de burgh your graph to label your notes and many other things. And we will see more off equity plug ins along this course. So to start amputee, you simply type activity. It is a no inside of vacation. You could use Ross to run, but instead we have a nice executable. Derek came stole. That's we can use. So you have a empty screen, OK? Because activity is a collection off plug ins and one we are interested about here is the node graph. Okay, so our kitty graph, which will show you the actual graphs so we don't have anything found out because we didn't start any node. Let's start and no to see what we get here. So for us to run my by from my cage by known, we have a bison node and no, we can refresh it and you can see we have the node here. If I start Russ to run my let's. That was unknown night bison note. But we were rematch to a test. Okay, If I refresh, we have the bite on test. No end, you simple test note. Okay. So as we can see those nodes here, which was that those knows are independent and they do not communicate between each other. So for every note you have in your graph, you can check with Russ to node least. Yeah, you will find those note inside the after tea. And as you can see, we have a new note in our list because this window here, the AC ut it's actually notes. So off course, it appeals in the list off nodes. If you remove the DeBerg fly, you can see and you take out the date sink option. You can see that we have the rose out topic, okay? And every node will publish to the rust out topics. Every note is independent, but still communicating with this topic. So when you that some log, it's, we go to the rose out and the rose to Clea Damon is something that is launched, or so when you start a note. So it would be easy off a note to find each other but fun. Or you don't need to worry about that. So basically, you can hide the burger and you have those two notes. You can also directly start our critic graph with the act photograph Executable. Okay, which is sane, but just just faster. Okay, So acute graft would be their useful. When you want to know what's going on in your roster graph, you will get a global off of you and you will easiness about mistakes. We will often come back to accurate a graph during the schools. 28. Discover Turtlesim: Let's experiment with an already existing package providing a simplified to the simulation off a Robert. This package is called Total Sing. This would be a good opportunity to apply what you've learned. We've rushed to tools in this section and will often come back to terror Seem during the cools and at the end of the course, you will also have a complete many project using terrorism. We will start the main Tillerson node. We've crossed two grand total seen from the debtors in package and she price tab. And you don't have the turtles in bank Agent means that it's not installed yet. So twins told it You can simply types should do a pretty installed Ross Dash. So the name off the distribution use a fuse, foxy. It would. Fox, if you use a different distribution, you will. But a different name here and little sim. Okay. And no, that doesn't seem is installed. We can open a new terminal to source Debussy, or we can directly source rush here because the package was installed. But this terminal doesn't know it's here, so we need to source it before I know Russ to run dental. See? Okay, I pressed up twice and we have a different note and we re launch the devil seem node and that we bring you a two D window with a total in the middle so you can see a node funnel. We've only seen node. We've only output in the terminal. But you can put anything you want in a note. It's just a program, and you start rusted communication. You create a note and then you can do anything if you want to create some to the visualizations. Really, if you want to do some networking anything. And finally you shut down the communication. But you are free to do anything you want in this note, so we can see Don't know here. If I do rush to know, least you can see the other sing a note. So again you can see the other scene. Node, this is the name off the executor table and this is the name off the node. Okay, which is in the front now we will kill. That's change the layout and that's and we will start. It doesn't node for us to run. Other seem. Tell me up t And that is a new node and you can use the arrows from your cable to move the total Okay, like that. So I move Simply moved to keep the the roads from make able and the totals moved in the screen. So they snow. Actually, when it gets your input, it will send it to return. It'll seem note and how to see it. So you have rushed to note least Okay, you can see we have a very a little known. Now, if I do After two graph with RTG graph and I refresh here, you can see we have tell unseen node and three up total and they are communicating between each other. That's news that Okay, so here, the syrup total would send a command velocity to each other. Same. And that is a topic. And if you want, you can also rename. So let's kill these and Achilles you can also rename. So let's use Russ Odds and the remap No, to my total. So and we can start this again. Okay, so it's walking again. If I do after photograph, we can see that we have the name, which is now my total. Okay, so you can rename also the node from dental see 29. Activity 001 - ROS2 Nodes and Tools: Here is your first activity. Your project for this class where we start with a very quick challenge. I have ransom note. We've different names, and here is what I see. We've argued a gruff your goal is simply to get the same thing. And you will find the complete instructions in a pdf that you can download from the project section. Make sure you don't know Jack. I extracted so you can get all pdf for all activities and projects in this class. So every time I give you an activity or project, I will give you a quick introduction with a video like this one. And then I leave you to the pdf instructions. So it would be more practical for you. All right, now take out the activity. One Ross to know them tools. Pdf work on the challenge I gave you. And I will see you in the next lesson for the solution. 30. Activity 001 - Solution: So this is the solution to reproduce activity where I challenged you to get these act a graph. So in order to get these rough you we need to start a no here and know that No, here which, for example, here you can stand the by thunder you've created here the Super Express node. And then you will need to start some Tillerson note. We've remapping. So let's starts. We will launch back into graph. And finally, this architect graph is empty. Would start Ross to run my by from my cage. We've the bison nude, and the bison note is name by test. So we will rename it to custom by like that Ross rematch. No custom pie. Okay, we have a node, and now we can refresh. And great, we have the first. No. Did he know? Let's start another node. This is a really long name for tpp noted, but it works. Yeah, Why? Nuts, Ross to run my cbb by cage Tpp node Rose hugs. This is a ready long name for a B road. But if works and we get this note here, so note that, um, this is just the name of the Okay. The change was to get this graph that you can also start this node using the bison node are any note? In fact, don't remodeler. Because here the challenges there's to get the same graph off course A zit can guess. Even if this works, it would be much better when you develop to give meaningful name to your notes. So, for example, issues that camera driver, then don't call. Eat. Don't Rachel Sensor. Try to always make sense. We've right, you're right And what you start. So we have to note here, and we will now start the other signal. Here it's Tillerson. Note. We've name Donatell that started here. Russ to Bran. Telsim. Tell the same node and Ross Hogs. Remap node Doing that till Oh, okay. We have a new, uh, window here. We can see it is no here and now we need a Philip turtle node to communicate. We've Donatello. No. And as you can see, this is the default node name. So I would just studied here, Rose to run, do a little Siemer and Turtle DiDio okay. And actually, we not re map this note, okay? And if I refresh here, we have, uh, she just go to nodes only. Okay, we have the exact same graph, and I encourage you to redo this activity and work with the previous section on load and all the tools to be confident using that because everything is so funnel, we will use it in the next few sections where we will see how to make the node communicate between each other. 31. ROS2 Topics - Make Your Nodes Communicate: it is now the time to explore all rush to communication features. After the next few lessons, you will be able to make your node communicate between each other. Using Russ two topics. You will understand what he's arrested. Topic things to Ariel life analogy. Then you rewrite your own topic with publisher and subscriber for both python and see prosperous. And then you will debug topic we for us to tools experiments on other Simpson later, and finally you will work on Amy Project, which I call an activity to practice on everything you've seen until this point and now what is a rushed to took it. 32. What is a ROS2 Topic?: what is a rose to topic Before going to the definition off a topic, I will give you an analogy with a real life example. So it would be much easier for you to understand. We make an analogy with a radio transmitter and receiver, as this is a simplified analogy, not everything that we say what radio will be correct. But the point here is to make you understand Rose two topics. So let's suppose we have one radio transmitter here. These radio transmitter will send some data on a given frequency and for people toe easily . Remember, this is represented by a number. For example here, 98.7, we can think off 98.7 also as a name. So you know that if you want to receive music from the original station, you need to connect your device to 98.7. You can see the green box here 98.7 as a Ross to topic, and the radio transmitter is a publisher to the Stop it. So for this case, data stream is sent over 98.7. Now, maybe you want to listen to the radio station from your phone. What you would do then, is to ask your phone to listen to 98.7. In this case, the phone is a subscriber to the topic. To play the music on your phone from the radio transmitter, you also need to send and receive the same kind of message here. If the radio transmitter is sending FM signal off topic, and if on your phone you are trying to decode am single, then it will not work. That's why you need to make sure that both the publisher and subscriber are sending messages with the same data stricter. So here you can see the radio transmitter as a culture, which will publish on the 98.7 topic within FM signal. The phone will subscribe to the 98.7 topic and will also decode offense. Single. Now, maybe you also want to listen to the radio station from another device off from your car. Then, as you know, you just need to listen to 98.7, and also both your device and your car should decode FM signal. You have no, in example, with a stoppage and three subscribers, so we can have many subscribers on a topic, but there's a side. We can also have many publishers on a topic imaging another radio transmitter, which is also publishing an FNC No to 98.7. It can be the same radio station. It can also be another one. Sometimes when you are driving, you arrive in a zone where two radio stations are publishing on the same frequency. In this case, you have to delicious on the 98.7 topic. All these subscribers will receive the messages from both coalitions. So here you can see all blue boxes are nodes. You have the radio transmitter No. One, the radio transmitter on a two. And then you have a node for the smartphone, the irregular player and the car. Some nodes contain a publisher to the 98.7 topic. Some notes contain a subscriber. As you can notice, all publishers and subscribers are sending a receiving the same kind of data. And as you can guess, a subscriber is not aware off the other subscribers and is not aware of who is publishing the data it on. Lee knows it is a receiving data from in 98.7. Top it on the publisher side. The publisher is not aware off the other publishers on the topic and is not aware off who is receiving the data. It only publishes data on the topic, and that says so. Each node, which is publishing are subscribing to the topic, is totally independent. Any combination is possible. For example, you could have three subscribers and no publisher in this case. Well, it's working, but the subscribers we just received nothing. But it's working if you have to. Publishers on the topic and no subscriber, the later is just sent and the one receives it. But it's still working. And as a combination you have only one radio transmitter, which is publishing, and only the radio player is subscribing. Well, I guess you see the point so far, no with so that you can publish data on the topic and subscribe to it to receive the data. A rose to node is not limited to that. In fact, the node can publish on many different topics. Let's say that the radio transmitter No. Two is publishing FM signal on the 98.7 topic and AM signal on the 11.3 topic. The driver of the car just chose to listen to the one on 1.3 frequency, so the car is no subscribing to the one on 1.3 topic and decoding AM signal, and this it reverses data from the radio. Number two, the known can contain multiple publishers, but also subscribers now imagine like the car while listening to the radio, is publishing its coordinates. Tow a car location. Top it. The cow node has no one subscriber to the 98.7 top it and one publisher to the car location . Top it. The computer known is subscribing to the allocation topic and for the communication to be successful, both nodes ascending and receiving the same kind of stage. What that's it followed the an emoji. Now you should have a better comprehension off what is a top it and when it is useful. So to recap, according to the Ross to documentation, a topic is the name the bus over which nodes exchange messages. Note that for the real world analogy, we used numbers with dots, ice topic names that was just to provide you with an easy example, but this is not valid. A topic name starts with the letter and then can have letters numbers under schools, tiles and slashes. I went to use a top pitch is often when you need to send a data stream. The data stream is uni directional. Some note can publish to the topic, and some notes can subscribe to the topic. There is no response from a subscriber to a publisher. The data is only going one way. Publishers and subscribers are anonymous. The publisher only knows it is publishing to a topic. A subscriber. Harmony knows it is subscribing to a topic. Nothing more. Ate a bit. Has a message time, our publishers and subscribers to the top. It must use the same message type associating with the topic. As you already know, you can write a note in multiple languages using, for example, the LCL CPP Library for Cyprus players and unsealed by library for python. Well, those libraries also include the topic functionality, so you can create a publisher off subscriber in any rose to super t long wait you want directly inside nodes. Finally, a note can contain many publishers and subscribers from many different topics. Toe conclude. You can see that you can easily separate your code into independent neighborhood and make them communicate between each other using data streams off topics. 33. Write a Python Publisher: Now that you understand what is their US to topic? Let's create a publisher. We buy some. So let's go to our US to work space. So directory. And in the bite from my cage of Created before and in the my front by Cage folder where we create all your note. So you already have my first node Fine Here. And also the template python note that I give you on the section on nodes. So let's create a new node. We will follow the analogy from the last lecture and when we create a robot use station fire So this no will be responsible for publishing on a robot news station. Let's make it executable. So it's important to make it executable here because we will use the singling install flight on Falcon Field. OK, so the fight is here and we can no edit it. So let's use the term plate here. I have provided okay if you go back to knife is no that by, uh this is exactly what we wrote in the first time to start our node and this will be the same every time you start a new node. So we will need to change the name off the node. Let's go it, Robert, use station node, and we need to change it here. Of course. Okay, we can do that. And we will also change the node name, which will be robot news station. And as you can see here on purpose, I chose to use the same name for the file and the node name, which is also correct. And it's often like that when you look at other packages built by the community. Usually you have the same name for the file for the no and 40 executable. Not every time. With sometimes it's the case. So you still have to remember that those three rd France five No name and exit a table name . But if you want, you can make them. I don't tickle. Okay? We have are known here, which is just basic. You can launch it. It will not do anything. So we will add line here to install it. So but comma here and we add a new line Robert use station. So that would be the name of the executable. And I also chose toe use the same name as the five end node. My boyfriend Cage that Robert news station. So that is the name of the file right here. And we would start with the main function. So the main function will be called when we start the robots. New station executive. So that's it for the set about by No, we can write our publisher. So to create a publisher, we will store it first in a publisher attributing our class. We will use the method create publisher, which is from the node class. Okay. And we need to give three on arguments. The 1st 1 is the message type. So you've seen that to define a topic, you need a name. Okay, which is a common interface at all Notes can find and a message type. So all knows, using the topic as publisher, our subscriber would need to use the same message type for the communication to be successful. And so what kind of message will be sent here? Because we haven't created any message. And we'll we will actually use an existing message that you installed when you install Rose to, so you can just type Okay, let's take that rose to in face show example, then press tab interfaces and SG and train. So let's see what we got here. So the Rust Toe interface interface is another common line tour with rose toe, and it can help you find the interfaces to interfaces its father messages, and we've show you again print on the screen what's inside a specific message. So we will see more about that later on the schools and the messages we will use firstly from the example interfaces packets. So this packages ready. Great. When you want to use an existing message with a basic time and for close, it would be perfect for the beginning until we create our own custom messages. So in that package you have MSG folder, which is for messages. So we just that for topics and you have a string message inside that. So the show verb here with rust interface, which we what's inside this mess? Age and you can see. So we have some comments saying that it's just for examples, and the most important thing here is that streaming data. So the first thing is the type which is strain, which is a primitive data type for Ross to miss ages and that are is simply name off the field. So we will need to create a string miss age and feel the data field with a string type. Okay, so how do we import this in our code? Well, simply from example interfaces dot msg OK, in vault stream. So it is no imported in our fighter. And of course, these aids from an other package. So as we needed to use, specify your dependency in the package. That, except for a sealed by we we need to do this thing, for example, in the face is so I will go to the package that XML off your, um, bites on bike age and below that line, we will add another depend example interfaces. So every time your package depends on another package, you will need to add a dependency here. Okay, so, no, it is set up. We can use it here so simply but strengths. So we create a publisher, we've got a string, and then we need to give a name. Let's say robot use. Okay, So the Robert New Station no will publish on the Robert Muse topic, and we need to give a que size. So the Q size basically on when you publish our when you subscribe, we need to give that argument. You will send some messages okay between nodes, and sometimes it can happen if you publish very fast, or if you publish also big messages like a complete image, it can happen that some messages are late toe arrive and in that case, the q size with a low you. It's like a buffalo. Okay, it will alot the application toe. Keep some messages before they are processed. So basically it's It means here that if some messages are late, up to 10 messages will be kept and then some messages will be lost for these girls and for many a few applications, these setting we not be so important. So we just but then as a default value every time. Okay, so we have our publisher. We've a name on we've data type Now. We we create a function toe publish on this publisher publish use where we could publish news. So it's a good practice to create a function to publish on a topic, and here we will first need to create a message. So then they said, which simply be a strain object that we got from here. So we have army stage that data. Okay, We have the data field, which is directly what we saw here. Okay, So message that data is equal to let's a helped funnel. We will change it later. So we have a message. And now everything we need to do is just to self publisher. We will take the publisher object that we got from the create publisher method and we will use the publish. I thought here to publish the message. So when we call this function a message, hello will be published on the topic Robot news. And now to publish it, we we create a timer. So it's quite common to create a timer with the right to publish on a topic. For example, that's what we did here in the first note. We created the time era toe just we didn't publish, which we just printed some text on the screen. So we will do basically the same thing, but instead off using the longer we will publish the message. So we create a time itself time create time and again this is from self. So this is from the node object. We give it a time. A period. So there are going five so we can publish to health. And we will give you a call back itself. Publish news. Okay, so let's actually but along here, self get longer and, uh, thankful rowboats use station has bean stop. So it's often it's something I usually do when you create a no idea of the constructor, we can put a lot here within four fly just to say that, you know that has been started. Okay, so when you actually start the execute table, you will be sure that this line is executed. So everything has bean executive before and you're not stuck somewhere. It's quite a good practice for their begging again before we launch the No, let's see what it does. So we will start with the main function were initialized Ross to communications and then we create the note so the constructor will be called. We call the constructor off the node. We've this name so Robert new station note will be initialized. And then inside the node, we create a publisher. We've that I've string and the name we then create a timer OK, which we call this function at two heads. So the timer is not working yet. It's just created, and then we print something for the begging. So the constructor we exit and we go to the SL by spin. So the node with starts pain until we price controls. And when the notes being where we can still continue to call the publish news function and publishing message at two hells And when we finally decided to kill the node than the spin will stop and, uh, the shutdown will be called so rustic communications will be shut down, and then the node and publisher and time and everything inside the note will be destroyed automatically. So let's start. There is no to start it. We need to compare it first. I mean, we need to combine the package so we can install the node. So let's, um, here call Cone reeled and we will use packages. Sediq. So we only really are back. Age are fighting back age, and also we will use singling installed, so make sure you have again the file, which is a marked as executable so you can use singling installed and in another terminal. So let's that Suze the mush. That's if I so against us, our workspace. And then we can do rushed to run my bison like age and price stopped twice. We get the least off execute tables inside the package. So we have new by final, which is our first. No. Then we have a new executable Robert news station as defined in the Sited by right here. So let's run it. Probably new station. So we have a lot of Robert New Station has been studied. And then, as you can see, the known is still alive until we price control. See? So the log is quite useful because you can know the it has bean finished. So the constructor has been finished. So, Russ to now, at least we can see the node directly. Here in the in this terminal rose two news station on now. Well, we have a publisher, but how can we check where he's going? Do information and what is the information sent on the top? It you have an ounce of common line toe. We will come back to that also later in this section which is rose to topic, and you have the roster topic list, which will list all the topics on your graph. So you already have perimeter events and rose out, which are always here. Result for the log and you have the Robert news topic that we created in our code. So if we go back to the fine, that's exactly what we have here. So you can see if you just provide the name, you will have a slash for the global name. Space will be added before the topic, and we've rushed to top it. Echo. You can print what's coming from the Robert use topic and we get Oh, nice. We get the data, which is printed at Wells. So we have that data, which is the field from the strained his age. And we have the help. Let's improve a little bit. We will add a name for there were Robert. Let's say self or but a 30 Okay. I guess you get the reference and we can print here. Hi, this is and let's print promote name. This is the seat Threepio from the Robert news station. Okay, so what? We print that name, so basically, you can see the strain you can feel the string as you want, and we will find it useful for the rest of the course. And as you OK will kill that as you build the node. The package with singling install you can directly start it again. And you should have been You okay, you should have the new data printing. Here you have the new string. So our publisher is now complete. And as you can guess, we will need to write some kind off subscriber because here it's nice. We can subscribe to the topic directly from the terminal, but in your in riel applications, you will create other notes that are subscribing to this data. 34. Write a Python Subscriber: Let's create a bison subscriber to listen to the radio station we've just created in the previous lecture. So we will create here a smartphone note and inside you to create a topic. Subscribe, as you can guess. A. No, which is handling a smartphone, can have many features such as reading and publishing the battery State, sending a text message to a contact increase. Our decrease the speaker volume, etcetera, etcetera. So the subscriber that we create here is just one part of this note. Let's go again in the source, folding off our across toe workspace, and we would go again in the by some by the age where we write older notes and we would create a smartphone note by file and also make it executable so we can get it to file from there. And as you can guess, we will use the template again, so it would be quite easy to create the base layer for the known And let's call it it's not phone node. Okay, And let's go the node simply smart for okay. And what we need to do is to actually install the notes. So in the set of the by we will add Smart phone my by phone by cage smartphone. So, as you can see, maybe the first time it's quite difficult to understand everything, but now is ready. Easy to create a note. You just have the time rates that you know you should understand. And now you add one line here, then, well, that's it. So again, here have used the same name for the executable, the fire name here and the note name. So let's add a long self get longer. And for smartphone I was being started and now we can create the subscriber inside that node. So to create a subscriber says subscriber, we create here we store to subscriber. Yeah, anyway created. We've said create subscription. So when you create a publisher, you have created publisher and when you create a subscriber, you have create subscription we to give four arguments here. The first is the message type again, we will use from example interface message strength. So we will use the exact same message that we used in the rubble news station. Okay, it's very important that you used the exact same and so it's from and external package, but you already but the dependency before so you don't need to do that again. It's already here for that package, Okay, Only for that footage. So train, then we need to give the name off the topic. And the name of the page is this one. I would just but the exact same name, because if, for example, if you just add a new letter, it's a totally different topic, and both topic will not be synchronized. And then the third argument is the callback. So basically, when you create a subscriber and when the notice spinning every time the subscriber gets a message. So when the publisher publishes something, a callback will be called and you will process the message inside a call back. So let's create a function called back Well, but news and this function will have a message as a perimeter, usually for collections. For topics I write Colback followed by the name off the topic. So it's easy to find out which function does what. And well, now, being that function, you will get the message that you sent here so you would get a strain message on. Do you can process it here? We were simply break it with self, get longer in full and use MSG. But data. Okay, data again. Because from the string object, we have a data field. So we can add the callback function here says callback rowboat news. And we also need to give a que size. So in case messages arrive late are is there is like too many messages at the same time. This we create a buffer so we can process the messages. So I repressed control shift and I make it better with the odor of for mating. And well, the subscriber part is finished. So that's ready. Not so much go to right. Okay. You have, of course, the base structure for the node. And then you create a subscriber. We've create subscription. You create a callback to handle the message a goat and you specify this. Go back inside the create subscription with off course the topic name and the topic type which would be the same as for the publisher. So when you stop the node, the rest of communication will be started. Then the notes will be created. We go here So off course you Nisshin. I didn't know we've the name smartphone and then the subscriber is creating. So it's just created. Nothing is happening yet. We print something to say that. Okay, everything in the constructor has been down. And then when you spend the note, the Colback would be able to be called. So the subscriber, whenever it receives a message, it would call dysfunction from this being fortunate. And finally, when you kill on No, with control, See, that's being well stop. So no callbacks will be processed anymore. And rusty communication, which we shut down with that said by shut down and then everything will be destroyed included the subscriber. Great. So we have the correct installation step here. We can go back to the cross to workspace, and we still need to compare again. Okay, because similar install will work for existing node. So if it's a new node, we will need to do that. Actually, kill that and let's so if you're not sure, just source your bash NCCU sauce your US to work space when you create a new file on your package. So we will start again. Are Robert News Station So that is the publisher known. Okay, so he doesn't mean started we can see the messages coming on the Robert News topic and we will start rushed to run my by from my cage. I pressed that twice and we see we have a smartphone Knowed that we can start and that's not for known. Husband started and we get the exact same string that these No, he's publishing. Okay, great. And if I killed the publisher If I kill the publisher, you can see on the subscriber We don't receive anything, but it's still working it still it's still up. If I start the publisher again, we start to receive the messages here. Okay? And so both are animals on are not directly linked. They are only linked to the topic interface they both Polish are subscribed to But no one is aware off the other way. I can just start the note like that. It's started and while it's working, there is no publisher. So there was no message. And then I start this one and we start to receive messages. So congratulations, you know, have to node which are communicating through a rush to top it. As you can see once you understand how topics work creating a double publisher our subscriber inside of notice is really not that hard 35. Write a C++ Publisher: In this lecture, you will write a C plus plus publisher. We will do the same thing as we did for the python publisher, but this time in C plus plus. So you will be able to compare the two codes for all the same functionalities in the two languages. So let's go in our rush to work space in the source directory and we will go now to my C plus plus package in the source folder off this package. Here you have my first note and or Saudi complete for the Super Express node that I provided in the node section. So let's create robot use station. So we will use the same name as for the bison example and let's get it this fire so we will not start from scratch. We will use the template here, okay, that you can find in a produce section. And as you can see, the template is just what you wrote in the first. Nobody's while the same thing as the town blade. Here, you just added a functionality with a timer. But once you know how to write that, well, you can use it in every node you create So let's rename the class Robert use station node. Okay, we can replace it here and here. And rowboat news station for the name of the node. Okay, so here you have a good structure for your node. And now we will create the publisher inside the constructor like we did for Python. To do that, we we need toe include the message. So the string message from the example interfaces a cage, Include, So we have a HBP head. Oh, we can use example Interfaces slash msg from a sage slash spring that HBP and make sure you use the HBP head of. And of course, as we are using an external package So we depend on this package. We also need to add a dependency in our package. That's XML. It banned example into faces and depend. So that is the same thing that we needed in the bison. Patrick. Okay, you need to do that in every package where you use example, interfaces and also in C plus Plus, you also need to provide the dependency here in the Sinica's that txt. You can add another line fine back age example interfaces and required. All right, so Now we will be able to link this a cage toe any node we create. So let's go back to our Robert New station. No, we would create the publisher here. And before we created, we need to actually declare the publisher. So where can you find publisher? Were simply from the air seal stripy publisher. You have a publisher object you can use directly from essence therapy. So you need a template. You need to give the example. Interfaces, Miss Age, string object that we got from this include life and we will add shared pointer. So if you remember, I told you that in C plus Plus, we've rushed to We will use shared pointer everywhere for almost any unroasted functionality. And here you can see that these just type that you can use instead off using directly STD shell pointer. So it may be a little bit more or reliable for you. So let's initialize our Alicia. Really? Sure, Uh, which will be initialize with these create Probably show. And as you can see, I use these when using the rose to functionality. I don't use these fathers stuff I created. I could use this for everything off are nothing. Okay, It would also work like that. But we use it as a convention for this course on Lee. So you know that when I write this, it's from this note. So it's clear that this functionality is from the node, and it is a rose to function it. So create position we need to give ourselves It died. Okay? And we need to give to arguments. The 1st 1 is the name off the big Robert news, and this is gonna want the size. Great. So our publisher is no initialized when we are able to publish on this Robert news that began. This is the same we used here Robert used. Okay. And as you can see, the name of the noon Robert New Station is the same off the new here. So it means that if you want to launch multiple instances off this node, are this no, together, you will need to remap the no name at runtime. So to publish on on this topic, we will actually create first a function delish news, and we put this function as a private one. And the first thing we need to do is to create the string miss Ages. So let's just go to MSG. Simple interfaces. I miss Jake Spring. So we create a string object. An empty string object. Okay. Using auto here is quite convenient, because anyway, you already know the diet. It's not that hard. Any tweets saves on space, so message that later. Because this is the field. Okay, lets but an anti strengthen. No, we we feel that later. And publisher, as this is a share pointer, you can use the arrow to directly get access to the functionality. So we use the myth of polish and we pass the Miss age. So we publish the message. Now we will estimize a little bit this strength Here I will add a STD string Robert name that we will initialize it here but him two okay. At two. D two, that would be our default Robert name and he lets say hi. This is so I will need to actually use a STD string. So we can contine eight strings plus Robert Aim, which is already in Estes train, plus from the room, But use addition and now publish news function is complete on how we will call it is from a timer. So we would create a tanker has still acidity time of bays. Okay. And we also use share. So we create our time When we first declare it has a natural bit off the class and we can initialize it here, timer. So again, these create world timer. That's what you did actually, in your first No, here we'll do the exact same thing, but instead off just printing something we will call the publish news function. So we wanted to call the function tradition that to hair So it is every 0.5 Cygan eso we will use STD crow. No. And because we need to give Inter GIs, we will use me second but 500 which is 0.5 2nd and then we need to give the call back and off course because this is a class we need to use Has to be buying to bind the callback, actually, to this time. So that's what ads and we will. But the reference to but new station node publish news function and this forest class. So I pressed control shift and I for the photo for my team in just good And finally we can add of one more lying just to print something that's you'll see pp in full this get logo. We've, uh, remote use station Has bean studied. Okay, so this log is quite useful. So we know when sprinted that the node has bean completely initialized. All right. It seems that the snow is complete now. So again, when we enter the main function first, the roster communications will be initialized. Then the notice creating the publisher is created. The time now is created and we print a miss age. And then they know we spin with sincerity. Spain. And why didn't it? Spinning the time will work and then dysfunction will be able to publish at two hurts. When you press control, see, this will exit. The knoll will stop spinning. And then you call shut down toe, shut down our rest of communications and then everything will be automatically destroyed because you are using shared 0.2. And to run this cold, we first need to compile it. So we will go to Simic lists that the X t and we will add a new executable like weed for the first no had executive table Let's go. It Robots use station. So here again, I used public new station for the executive name which, uh is the same as the filing and the node name. Okay, But you have to remember that those three are different. You can use the same name if you want, but those three different stuff So it is in the source for their here. Hum public use station that city and we will use also payment target dependencies for the Robert New station. So what do we need here? We need s here city, of course, like every rose to program with civilised place. And we will also add example interfaces. So we are saying that these executable needs both those libraries here in both those packages. This one doesn't need example interface. Okay, so we don't write you here, but this one needed so we had it and way already have the structure to install the exit table. So let's simply add problem news station here. So I thought every new news You're right. C plus press. You will add those two lines and which simply add the executable name here. Okay, That is the executable name, and it seems that everything is ready. We can go back to our US to walk space and use COCOM wield and let's use again The packages select with my super express back age and see what we get here. Okay, so it has Bean will successfully now in another terminal That's so star bash NC And let's Russ to run my Citrus place like yogis again A price Deb twice. And I get the notes. I get the execute tables. I can start syrupy node and Robert News Station where we use that word. Robert News station has me studied and you can see the program is running because it is spinning. If I kill it, it stops and I can start it again. And now we've rushed to note the least you can see. Note here, Rose to node info, Robert New Station. You can see that we have a publisher here. Krabat News. It's a during here because we are publishing from this note. So, Robert news is the name off the topic, and the interface is right here. Okay, so, Russ, to note in four, it's quite convenient to find the topic. So we would you, Russ to topic least and the topic is right here. Roberts News. Let's see. Rush to pick, he cool, Robert used. Let's see what we get here and you can see Hi, this is actually to from the Robert used station. Okay, so it's working and know that you have seen how to write a publisher. Of course, we will go to write the subscriber. But before you do that, in fact, you already have a subscriber for these notes and you have a bison subscriber, and you will really see here that this is really the magic off Russ to I told you that trust to he's language agnostic and you were really understand it. Here it means that you can create a noting super Express. For example, you can create another note in Fife in, and both node can communicate between each other because it doesn't rely on the language itself. For the communication, it relies on the no well event, which is the same for all note. So if I start Rose to run my by phone package, if I start the subscriber so it is in a smartphone node. So the smartphone here will subscribe to the Robert use the pick. And what are we doing here? We are publishing on the Robert news topic. Okay, so I'm just starting the by thing load. And as you can see, we are getting the messages from the C plus plus node. If you can see that if I kill this soup is personal. We don't get any message here anymore. So that is a already a really powerful functionality off Russ to. And now let's see how to write the subscriber in secret spurs. 36. Write a C++ Subscriber: in this lecture, I will show you how to create a SIMPLES plus subscriber. So we will use again the same example. Eyes waited for Bytom and we create a smartphone subscriber for the Robert New Station publisher we've created just before. So again we will go into R C plus plus package in the source folder where we already have a node and we we create a new smart phone five smartphone. Okay, we can know edit this fire here. So So we will he and copy and paste these and right smartphone No to you a copy and paste that and right smart for Okay, I'll structure is no right. We will off course include the example interface message string, but HPV OK, and we don't need to add it here again because it's already here for packaging the Simic list and in the package that excellent, so we can directly use it. So let's create our subscriber. We will actually need two things a subscriber object and a call back so we can manage the and handle the message. That's William. So let's go this Go back. Go back! Rowboat news. What we will get here is a comes off a example into faces Amos Jeep strained and shared pointer. Okay, so we get a shell pointer off the message, and again you have the easy way to right. The ship, entire, we've rose to. So for every message you will get in some respects, you will use for every call back for every subscriber. Really? We use const. Then the name off the Miss Age. And finally you add Shell Porter. Okay, so it's always the same. And let's simply print this message with her seal civility in four, we get the longer for the known, and we will bring a string. As this is the chef pointer, we use Dicterow and data. Actually, this is a STD string. So we'll use the C s chair function to make it yours able. With this a sensitivity and for fortune, right, So I'll call back is already And what we need to do now is to create a subscriber to actually call this girl back when it receives a new message. So let's first declare our subscriber see PP So descriptions that we create a subscription . We need to give the type example interface msg. It's train and this is a shipment again. Subscribe. So I would go into subscribing the CO the right. Okay. And we can no initialized the subscriber inside the node Constructor subscriber, We will use this again, create said description and we need to give the example interfaces, sage strength. So we need to do the interface. And now we need to give three arguments. The 1st 1 is the topic Name public use. The 2nd 1 will be the intention to that The 2nd 1 will be the shoe size. Okay. And the 3rd 1 will be the callback. So for the cold back, we will need to add these. And of course, we will use STD bind so well for a nickel back you we create with C plus plus in the node class, we estimate buying. We put the reference to smart. So node go back for. But you these And we need to add another argument here in the STD buying function because we have here a perimeter for a function. When we used here in my first node, when we use our just in the role of your station doubly shirt, we created a timer for this function, but this function has no perimeter. So we just had to learn details. Why city by But now, Because there is a perimeter here for this function, we need to add Destiny place holders and one Okay, so this is a required for every perimeter you have in a callback function. If you have two parameters that will write, another argument here is to replace all those to. So let's make it more credible like that. And let's are a longer personal sippy info we've It's get longer and a smart fish is not fun. Smartphone has bean about in, so we know it has been initialized and our subscriber is no ready to be used. So to return quickly, we initialize rustic complication. We create the node. A subscriber will be created with the callback function here. It is not working yet. It's just initialize. And then we spin the node so it would be able to receive and process any callback. And when it receives miss age, this combat will be called for the Robert News topic. And when we price control, see this being stop So we don't receive any new miss age, and we can shut down the rest of communications. So to use it, we will add it here. Ad exec Table smartphone, which will be executable name. Okay. Yes, I'll see smartphone duds. Baby, we are payment target dependencies. For me, it's not fun. Picnic table. And we need a seal sippy and also example interfaces so that we create the executable and no, we install it. Smart phone. Okay, you can go back to your for us to work space and again build the package. Okay, so let's try our new subscribers. That was sauce. Um, the bash as it is. So the undergarment and Russ to Gran my, um civically my cage. We've smartphone node, which would here? Yes. So the smartphone has bean created. We can sit here, was to know least okay. And this smartphone has subscribed to the euro. But news topic. But actually no one is publishing on this topic. So let's polish with the simplest plus Robert news station and we are getting some messages here. Great. Now I killed the publisher and we don't receive menacing from the subscriber. Let's try actually your us to Iran Knipe by thumb, But age public news station. So now I will launch the python doubly Charlotte we've created before, Okay? And we get some messages here. Okay? As you can see, I chose a different name for the python and simples preservation, and you can see it here. Ok, this is coming from the c++. Know that this is coming from the Lytham note, but actually, the subscriber account made a difference. Okay? It's just a topic. So anything that is sent to the topic with the correct data type will be processed. Great. So, you know, have a complete surprise press publisher and subscriber. 37. Debug Topics with Command Line Tools: in this lecture, you will see how to debug your topics with come online tools. So we will again use the Ross to come online interface. You've already seen how to use that to work with nose with rust to node. We also rose to pick, age it, create baggies and roast to run to start your node. And no, you can have the rose to stop it to handle topics. And if you price that twice you would see all the other functionalities you get fucked a bit. In fact, in this section you already so Rosta ph list and cross the peak equal. So let's start, Ross to run my let's start any node, my iPhone, my cage, the station. So we start publisher for a topic. Let's see Ross to pick. Least we now have the robot and use Come pick here. If I killed the node, you don't have the pits Animal. Okay? And if I started? Note again. Robert, you stop it. Now if you want to get more information about that depict you can do for us to pitch in fort and for the name of the topic and this is very useful you can see the type and the number off publishers and subscriber. So here we have one publisher and zero subscriber. Okay, So if you want to create a new publisher, a subscriber, you know that you need to send that out to the Robert used name. And with this type, No, we can Russ to pitch ico. We can decode the message so we can create a subscriber inside the terminal. A cool robots use the whip of the name off the topic and we have the data which is printed here. If I do rushed to top it in for again, you can see we have one subscriber here. If I kill that, we still have one party shirt. But, you know, subscriber and there is a common line that you can use to complete. These is roast to interface that you saw already before you can do rushed to interface show . We've the type. Okay. And this will print the actual message definition. So you know what you need to send for this topic. So we've rushed to topic. You can also use the h said, um functionality, which mean helps and you can actually get the publishing frequency for a topic. So let's experiment with the Roberts use topic. And if you wait a little bit so it will listen to the topic and it will print the average right, which is here to help. So it's great because we have to help us here. And we know that we are publishing at two hertz from the publisher. So everything is functioning correctly and this common can be great for the begging. For example, if you have a very high publish right and you see that the messages are not following quickly enough, then you can see that maybe the rights has dropped and you can monitor all that with age said. You can also use Rose to took it B w for Ben with remote use, and to see okay subscribed so you can see the bend with used for the note. So here it's just some fixed at very low frequencies. So we have 200 like 140 bites bursts again. OK, this season average you get and finally, you can also publish directly from the terminal. So usually you will often use the rust to topic. EKO Command the tub command us to top it that you will not usually use it a lot, but it's still good to know it. So let's say you want to publish a 10 hertz you can use. Dash are with then and let's publish only robot news topic you can use. You can use the auto completion. OK, we've tab, example interfaces straying. And then you will need to give the message so you can use like that's two brackets to curly brackets and we need to send data, which is let's say hello from Tim New. Not really. That's used that okay and its publishing. So if we are subscribing here, Okay, you can see that we get messages from the publisher here, and we also get the messages from the publisher here. So we have to publishers and watch subscriber. So to recap, rights to peak. Let's see what we get here with two time the most important ones. You have ICO so you can see what is actually going through your topic. The least the least are your toe pick in four to get in for about a topic, and then you can use Also be able, U N H. Said to debug topic. And if we look at the No, let's see Rose to know least we have the notice you that he's running in the stimulus. If we do Ross to node info with this note, we will get all the publisher than everything that are created for this note. And you can see we have the publisher Robert use here. So from the node information, we can see which topics this note is actually publishing to our subscribing to rent. From that, you can then use the rest to top it in four to get more information about that. 38. Remap a Topic at Runtime: in the previous section with no then rushed to run. You have seen that you can rename a node at runtime so as a remainder you can do, for example, rushed to run my life. My cage. We've the Robert New Station and you can rename the note you first, but cross ours and then we've dash, uh, and note like that's you can rename, Let's say my station. So this note is no running my station. Okay, if you do rush to node, least you get my station and should rush to topic list. You can see that these notice publishing on the Robert news topic. So now how to rename that debate? Well, you simply keep the same thing. You add Ross odds, and then you add another dash our argument with simply the nay off the topic robot. You, I that let's say we wanted just to me my use. So if you do that, then when those two will start your nose is to search for something that has the same name as Robert News. Any Twitter, right name with my news. Okay, so I start the node and if I do roast to typically East then we have my new stop it. So the Robert News topic has been renamed to my news. Stop it it has, Bean remarked. And as you can see in the code, eso any any cool here in Super Express Off by From is the same. We have specified the name here, and even though we have specified the name in defined directly, how could it? Here? We can still modify it at runtime with this argument. So no, let's see what happens if we launch a subscriber, for example, Rose to run my life in a cage. Let's start the smartphone subscriber and let's see if we get some messages. Oh, we don't get any messages, But we have launched the publisher. Yes, that the publisher is no publishing to a different topic. If you do rushed to topic list here you have my news, which is what this notice publishing to. And now you have Robert news because we now have a subscriber for this topic, but those two different topics. So if you want to get information from that topic, you will also need to rename it here. Ross Ha's with ash pop and roll, but views my news and now you will get messages. Okay, so remapping topics will be quite useful in your applications. For example, when you have an existing publisher and you can't change the topic name, then you can change the topic, meaning for the subscriber. If it's not the same in the code and this goes, we will also work more with remapping, and you wish is some of the benefits you get with that. 39. Monitor Topics with rqt and rqt_graph: Let's see how to monitor topics. We've AC UT graph. So I would first launch AC UT graph here in this terminal acuity graph. Okay, which is no empty because we don't have anything in the graph and I will start a first node here. So Ross to run my slashed, my secrets plus Robert use station We have a leisure. And let's that rose to grant my by phone. Back age smartphone notes. So we have a subscriber for the same. It's working. We can no go to the AC UT graph here. Refresh. And you see what's a name? We have public new Station node, which is publishing on the Robert News topic and a smartphone notice Subscribing to the Robert News topic. You can change the view here. Okay, this is maybe better. So you have a topic. Square is the topic in This is a note. So this is publishing on that topic, and this is subscribing to that topic. And now let's experiment a little bit more to see what we can do with this graph. So we will start another publisher rose to run my So let's let's you by someone it doesn't really matter or about new station off course. We need to change the name Ross. Because if we don't change his name, it will also have the Robert New Station name and it is not valid. So we will change. The node name here would not change the topic. Name knowed, Let's say my station, we have my station. And as you can see, the subscriber is no getting messages from both publishers. If I refresh here, you can see we have no to publishers on this topic. I turned hard yet another. Really? Sure. We just rename my station to okay and we're refreshing. We have three publishers on that topic. Okay, It's quite simple. And no, we can add another subscriber here, Rose to run my bison by Kage. Let's front another smartphone and rename it so we need to do for us. Odds are node on da smartphone to okay And we get, of course a lot off the data because they are sweet publishers and right, so both the smart phone and smartphone to node, We'll get the messages from Robert use So those three will publish on that topic on those two will process all the messages from that topic. And these node, as you can see the sun No, the existence off all the other nodes. It's completely Anna limbs. And now let's add some remapping father topic so I wouldn't keep that. And I will add here I will add to other No. So I wish that cross to run My, uh, by from my cage I was sort of knows our robot new station. So I will remap uh, the road first like that. Let's say also, station and I will also remap the week so far, but use and let's use my news, okay? And what we get here and now you have the other station node, which is publishing but is not publishing on the Robert News. So you don't see in a row here, okay? And now we we create a subscriber Ross to run I, um, by phone, like age smartphone, we would actually also change the nose name. Well, we name it other. It's not for just for convenience, and we will rename the topic rowboat use in. This has to be the same topic. Name. If we want to listen to that garbage and we get the message is from this show. So as you can see here what we did, we have a different orbit. So this basically from the note is the same node and the same to bake and saying subscriber . But at one time we were able to make a complete different configuration, so you can see how RA mapping notes and topics is very powerful. In this case, For