Learn ROS2 as a ROS1 Developer and Migrate your ROS Projects | Edouard Renard | Skillshare

Learn ROS2 as a ROS1 Developer and Migrate your ROS Projects

Edouard Renard, Software Engineer and Entrepreneur

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
49 Lessons (6h 41m) View My Notes
    • 1. Welcome!

    • 2. When to Switch From ROS1 to ROS2?

    • 3. How to get the mot out of this class

    • 4. Setup for the class

    • 5. Install ROS2 and Discover the Main Differences With ROS1

    • 6. Install ROS2 Foxy (Ubuntu 20.04) and Setup Your Environment

    • 7. Start a ROS2 Node and Get Familiar with ROS2 Tools

    • 8. ROS1 vs ROS2: First Differences (quick overview)

    • 9. Re-write a ROS1 App into ROS2

    • 10. Install ROS1 Noetic to Test the ROS1 App

    • 11. The ROS1 App We'll Use

    • 12. Install colcon

    • 13. Create a ROS2 Workspace

    • 14. Create a Package (Python)

    • 15. Create a Package (C++)

    • 16. Create a Node (Python)

    • 17. Create a Node (Python) with OOP

    • 18. Create a Node (C++)

    • 19. Create a Node (C++) with OOP

    • 20. Template for your OOP Nodes

    • 21. Write a Topic Publisher/Subscriber (Python)

    • 22. Write a Topic Publisher/Subscriber (C++)

    • 23. Create Custom Interfaces (Msg/Srv)

    • 24. Write a Service (Python)

    • 25. Write a Service (C++)

    • 26. Remapping in ROS2

    • 27. ROS2 Parameters - What Has Changed?

    • 28. Declare Your Parameters (Python/C++)

    • 29. Get Parameters From Your Code (Python)

    • 30. Get Parameters From Your Code (C++)

    • 31. Create a Launch File

    • 32. ros1_bridge Intro and Migration Guide

    • 33. Steps to Migrate a Code base using ros1_bridge

    • 34. Install and Test ros1_bridge

    • 35. Bridge Custom Messages [1/4] - Why + Setup

    • 36. Bridge Custom Messages [2/4] - Installation Process

    • 37. Bridge Custom Messages [3/4] - Running Your App

    • 38. Bridge Custom Messages [4/4] - Mapping Rules

    • 39. Use ros1_bridge With Our Number App

    • 40. Migration Project - Intro - Discover the ROS1 app

    • 41. Migration Project - Intro - Steps

    • 42. Step 0: Port the code to ROS1 Noetic

    • 43. BEFORE GOING FURTHER - Download the Seed For the ROS2 Project

    • 44. Step 1: Setup ros1_bridge for Your Custom Interfaces

    • 45. Step 2: Port the Target Publisher Node

    • 46. Step 3: Port the Turtle Controller Node

    • 47. Step 4: Create a Launch File for The App

    • 48. Project Conclusion - Improvements

    • 49. What to do next


About This Class

At the end of this class - starting from your ROS1 experience - you will be able to create complete ROS2 applications, and migrate a ROS1 code base to ROS2.

IMPORTANT: If you’re a complete beginner and have no knowledge in Robot Operating System at all, please don’t take this class. You must know how to work with core concepts (nodes, services, parameters, launch files) to understand the class.

Please read the entire description to know what to expect from this class :)

→ First of all, Why this class?

Well, if you already know ROS1, you might want to start learning ROS2, but... not from scratch.

And/or if you’re currently working on a ROS1 project, you might be looking into a way to port it to ROS2.

I myself was a ROS1 developer before learning ROS2. What I was looking for was simply some documentation of how I could quickly get up to speed with ROS2, as I already knew ROS1. I didn’t find any good resources, so I had to go through all of the beginner documentation for ROS2. 

Now that I use ROS2 every day, I’ve decided to create the class I wish I had when I first started. So you don’t have to spend days and days studying ROS2, find out what are the differences, and what you should do to switch from ROS1 to ROS2.

In this class I won’t start from the very beginning of each ROS concept, since you already know them. I’ll just focus on the most important points that will allow you to write ROS2 applications in no time, thanks to your pre-existing ROS1 knowledge.

And I also understand the need to know what to do with an existing ROS1 project, now that ROS2 is starting to get bigger and more stable. What I’ll teach you is what I personally do with my own projects. I don’t “invent” a method, I create it from real practical needs I have and other people have.

My goal is that you get the main take-aways you really need, in a short period of time.

At the end of the class, you will be able to:

  • Write your own ROS2 project
  • Clearly understand the main differences between ROS1 and ROS2
  • Work with ROS1 and ROS2 at the same time
  • Migrate a ROS1 project to ROS2

→ Class structure

This class is divided into 2 main parts.

  1. First, you’re going to learn how to write ROS2 programs, using your ROS1 experience. We’ll start from an existing ROS1 application, and step by step, we’ll go through every core concept and see how to translate the app in ROS2. Note that we won’t dive into advanced functionalities, we’ll stick to the ROS2 core functionalities.
  2. Then, it’s migration time! (If you already have some basics in ROS2, you might go quickly with the first part, and then focus on this migration part.)

You will get answers to some of the questions you may have: when to switch to ROS2? Which ROS1/ROS2 distribution to use now and in the future? Etc.

I will give you a process to migrate your ROS1 code base to ROS2. Also you’ll see how to run a ROS1 application along with a ROS2 application, communicating between them thanks to the ros1_bridge package.

And finally: a complete project for you to practice on migrating a code base and writing ROS2 code. I’ll give you a project I made with Turtlesim in ROS1, and you’ll migrate it to ROS2.

→ What if you already know ROS1 and have some ROS2 basics?

Well, you can still benefit from the class . You can skim through the first part (as a refresher) and then go to the second part, which can be seen as a complete mini-class by itself.

This second part + the final project will give you the answers you need to start working with both ROS1 and ROS2, and also to migrate your own code base.

→ How do I teach?

My method is quite simple:

  • Step by step
  • Going to the point
  • Practice over theory, although a little bit of theory doesn’t hurt when combined with practice

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, also giving you the best practices right from the start, to make you a better ROS developer.



This class is for:

  • Students, Engineers, Researchers, Teachers, Developers, Hobbyists.
  • ROS1 developers who want to learn ROS2, not from scratch, but by comparing ROS2 with ROS1
  • ROS1/ROS2 developers who want to migrate a ROS1 codebase into ROS2
  • ROS developers who want to be able to work with both ROS1 and ROS2.

This class it not for you if:

  • You don’t have any knowledge in ROS1
  • You’re already an expert in both ROS1 and ROS2.
  • You’re just getting started with programming and Linux.

Pre-requisites for this class:

  • You have a fair understanding in ROS1 and can write simple ROS1 programs
  • Ubuntu 20.04 installed on your computer (dual boot or virtual machine) + you know how to use basic commands in a terminal
  • Programming basics in Python and/or C++
  • Some basics in Object Oriented Programming (OOP) are welcome, although not 100% mandatory


1. Welcome!: Hi and welcome to this course on Ross too far, ROS1 developers. You already know ROS1 and you want to quickly get up to speed. We've rushed to and learn about how to migrate a Roslyn codebase into rows to, well, you just found the perfect curves for you. At the end of the course, you will be able to write complete Rostow applications on your own, understand all the most important differences. We have ROS1 and migrate your ROS1 project in eros 2c. You will also get the answers to many questions you may have, such as, when should you actually switch two rows two. Which rows one and rows two distributions should you use, etc, etc. Now, before going any further, a big warning here, this goes, is not a course book complete Ross beginners. You must have a fair understanding of Ross one to be able to understand the kudos. Because I will mainly teach Ross to, by comparing it to Ross one. I won't explain what the core concept are. So for example, if you don't know how to write a publisher subscriber in ROS1, please don't take this course. Alright, now let's get back to it. I'm Edward, a software engineer, an entrepreneur. In the past, I have programmed and untie or six axis robotic arm from scratch. We've rows. Then I have experimental quite a lot with rows one and rows two. And well, switching two rows two was not that easy at first. I didn't find many good resources online to teach me how to apply my arose one experience to efficiently start working on a roast 2k. So after a long time of struggle, I want to share my experience through this class and teach you the way I want it to be taught. My goal is to go to the point and not waste your time. Now, what will you do in this course? Well, the course is mainly structured in two different parts. First, you will learn how to write Ross to programs. We will start from a working ROS1 application and step-by-step, we will kind of translated to Ross to note that we won't dive into advanced functionalities. We will stick to the curve functionalities here. Then you will learn how to migrate arrows, one code base. You will discover how to use the Roswell enrich package to be able to communicate between ROS1 en Rose too. And finally, I will give you a complete project to practice even more. In this project, you will have another ROS1 application to migrate to rows two based on the turtle. Same package knows that if you already know ROS1 and rose to, then you might still be interested in the southern part of the coast plus the final project, which you can see as a mini-course inside the course. Alright, so if you are arrows one developer and you want to learn ROS tube or if you're interested about how to migrate arrows when codebase into Ross to weight normal. And let's get started. 2. When to Switch From ROS1 to ROS2?: Before we even begin to see the practical differences, I think it's important to know why you should use rows two and when you should switch from ROS1 tours to and to better understanding. First, I'm going to give you a little bit of context. Refers to is the new version of Ros. Ros by itself means Robot Operating System and the term arose is also often used for Ross one. So to be clear, in this course, I will use the term arose without any number to talk about Ross Robot Operating System in general. And I will use ROS1 when talking about the first version of for us. And rose to when talking about the Seguin version or for us. All right, so first of all, arouse in general is really growing more and more each year. It is truly becoming huge in the robotics community. Thanks to many years of experience and feedback, that team behind ross decided to make huge improvements and add a few important functionalities to Ross. They chose to create a complete num_rows from scratch named Ross to while still supporting or ROS1 far wider in rows two, all the way to write code has changed. But good news here, most of the core concepts are the same. And we'll explain what other technical differences in the next section while we write some code. So now you might wonder which runs version should you use? And if you are using a ROS1 when to switch to Rostow. Let's see the roadmap for Roswell and Ross. Two distributions here. I'm only displaying the long term support, our LTS distributions, which are what you are going to use so far, Ross one, you can see that the latest LTS release is noetic supported until 2025. And well, if you didn't know that after noetic, there will be no more ROS1 version. So the end of life far Roswell is simply 2025. It means that if you steal, rely on ROS1 a lot, don't worry because you asked it good for awhile and you still have some time. Now let's look at the Roth to distributions in orange. They follow the same pattern. One LTS version every two years. Those are the versions you will use as funnel Ross to foxy will be our main target. Now, coming back to the question, when should you switch and start using a Ross to? Well, unfortunately, this is not a black or white question. The real answer is, it depends. But here I'm going to give you some clues so you can better early side. One thing to consider is that funnel, Roswell, it's much more mature and Ross to its most stable. There are more packages, etc. But this is changing a little bit every day for now runs one is stronger, but within the next few months or years, ross too, will become very stable. All the important ROS1 packages will be plotted two rows, two, and you will have new exclusive packages for us to only and at the end or OS1 will end. So I'm going to make two different cases here. First, if you're starting a new project, then starts wave rose to, this is a good opportunity for you and maybe your team to learn the newest available technology and to start a project that has more long-term perspective if you are liking some of the ROS1 functionality, while in fact you can still be able to use them sinks to the rows when breached package, which we will see later in this course. Now if you already have a arose when project, this is a little bit more complicated. You can look at all the existing packages and functionalities that you are using and see if they are also available in Ross to foxy. If too many are missing, it is maybe a better solution to wait for a few months and still use Roswell. Remember, you still have time. There is no hurry right now. But if everything seems possible in Ross to, then you can start. Anyway. A good first step would be to bolt Euros when code to Roswell New Age if that's not already done. And then a transition to Ross to foxy will be a little bit easier because of two things. Nordic and foxy are both supported on the same operating system. For example, you're going to 20.04 and both versions support Python three, if you look at Ross, melodic or kinetic, they still only used Python to. So you can already switched to noisy right now and then decide if you are going to Ross to foxy now are a little bit later. And one additional node for both cases. Let's say some ROS1 packages are not supported yet in rows two, and you still want to port your code to Ross too. Well, you can still do that and use the existing ROS1 package along with your Ross to application thanks to Euros when breached by Kd, which we will see later in this course. Okay, so now you should have a better understanding of the different ROS1, n rows two distributions. And also have a better idea of when to make the switch. To conclude on that, one thing I am positive about is whether you decide to switch to Ras to now are later. It is definitely a good choice to start learning Ross to right now. It can only be useful to you in the near future. 3. How to get the mot out of this class: To get the most out of the schools, here is what I recommend. First, watch on the lessons. In the other. I will add a lot of details and tips during each lesson. And each lesson is built on top of the previous one. During the first part of the course. Writing the code at the same time as I write might help you get a better understanding. During the second part, pay extra attention to the instructions I will give. Otherwise, you will easily run into a lot of arrows. Take enough time to do the final project by yourself. Come back to the previous lessons if needed. But try to finish the project on your own. This is truly where your brain will absorb the knowledge you got from the course. And one more tip that may not apply to everyone. If you already know how to work with Ross tube and you came here for the migration path. I still advise you to skim through the first part and play a little bit with the nav application in Roswell and rose to before you go to the migration section. And now let's get started. 4. Setup for the class: Here is the setup you will need for this course. It is quite simple. In fact, we will use u1 to 20.04, so make sure you install it, whether as a dual boot on your computer with a virtual machine, like I have done here, we've VirtualBox. I'm not going to explain how to do that because as you already know Ross, when you certainly already have a human operating system running on your computer. And it's also part of the prerequisites of the course. And well, that's pretty much all you need for this course. Now, as for the text editor or IDE to write the code, just choose the one you prefer. It doesn't matter. I will personally use Visual Studio Code. Okay, now you're ready for the course. We will see how to install Ross to very soon, and I will guide you through all the installation steps. What additional and optional thing to do is also to have Ubunto 18.04 installed in two or three lessons of this course. I'm going to also use rows, one melody on human to 18.04. I chose to still show some ROS1 parts in melodic because that is what many of ROS1 developers are currently using now. So it will make the course more relevant. If you already have you been to 18.04 wave Ross melodic on your computer, then that's fine. Otherwise it's up to you to install it. Honored. But know that if you don't install it, that's perfectly fine to you will still be able to follow along without any problem. 5. Install ROS2 and Discover the Main Differences With ROS1: These quick section, you're going to install ROS to end starts some existing nodes to see some of the main differences between the ROS1 enter Rs two. I will also give you some explanations about the architectural changes so you can better understand. Alright, let's get started and installers to. 6. Install ROS2 Foxy (Ubuntu 20.04) and Setup Your Environment: In this lesson, I'm going to show you how to install ROS to foxy on human to 20 for first, make sure you've already installed. You will do 20 for us. It was asked previously in the introduction. So whether it's dual boot on a virtual machine, the instructions will be the same. Well, you can append and one terminal and on Google you can just type installer Ross to Foxy. And you will find the installation biologists right here. And as you can see, a website is index dot dot r. That is the first difference. We have ROS1. The documentation for ROS1 is on Wiki Dot Rosal.org and everything here you will find on index would be about us tool. So let's click on that. And actually you can see you can install binary packages and from sauce that we will choose binary packages here with Linux, initially we've, you wouldn't do 20.04. So you click on Debian packages and we are going to follow the tutorial right here. The first we're going to setup located, we can just copy and paste those lines right here. So tutorial here, the instructions are really similar to what you did in ROS1. Ok. First, a little bit of setup. Ok. You will need to setup some sources because the sources are not what you already have. You need to set up new sources to be able to get ross too, as you can see here by cages.org. Okay. You don't have that. You won't be able to install ROS too. So you can execute that, that this command also. And that's it. Now you can install ROS tool. So first, make sure to update, okay, good the new packages. And you can install Ross to Foxy. And this is also quite similar to what you had in Ross who are here, you will simply do Ross dash in the name of the distribution, which is, for example, in Roswell New would do Ross dash, melodic, Ross dash, noetic. Here. You do Ross dash Foxy and foxy is the Ross to distribution. And then you have Ross dashed foxy for us, bays, which is just the bare bones like communication and just things you need to run Ross T2. But we will actually install ROS oxy desktop, which is the rules-based plus GUI tools and some other packages that we need for the scores. So you can install that. Ok, and as you can see, I have nothing here to install because it's already installed for me. But he will have many packages. And the dollar size, I guess is something like 2.5 gigabytes. So this may take some time. Alright? And then It's quite easy if you want to install a new package, you simply do sue epigenes, dollar rows, dash, foxy dash, and then the name of the package. So that's how you can install any Ross to package. Now, rows two is installed. Great. Actually, you are going to install one more thing here. We saw the setup script. Later. You will install our complete. Okay? So you can simply execute those commands and you can see it's already installed for me, so nothing new will happen. Okay? If you don't install our completes, then when you use the Ross to command line tools, you won't be able to use the auto-completion, which is quite useful. Okay, so Install are complete and now you're going to source your undergarments. So that is something that you already know because in ROS1, when you installed across any Ross distributions, then you would have to source the setup dot Bash script from the global Ross installation folder. And that is exactly the same forest to okay, I need to do that in other to be able to use Rostow in that session in that terminal. If I open a new terminal, then ross T2 is not sourced here. I can't use Ross to. What we're going to do is to add this line into your assay. And actually so I will use gedit here, can use VMM, anything you want. And we're going to go in the bash SEO. And right at the end, okay, you have the bash assay arrived at the end of the brush assay. We are going to copy and paste this line right here and save the bash assay. So now we can close that. And if i sub sc, then it will source that script right here. And if I open a new terminal now, I can use the arrows to functionalities. Alright, so that's it for installing Ross to ends setting up your environment. 7. Start a ROS2 Node and Get Familiar with ROS2 Tools: Alright, so now you have rows two installed on your computer. And before we continue, please make sure that you have correctly setup your environment. So make sure you've done every step in the installation process for us to end that you've correctly sourced, you're under on land in the Bash assay. Okay. If I print bash assay at the end, you need to have that right here. Okay. When I opened doors for terminals, I already had that in my brush assay. So every terminal is already set up for us too. And now we're going to launch a few rust two nodes just so you can see how things are working and how to use the tools in how it is different with grass alone. Okay. So first of all, when you used ROS1 felt thing you would have to do is to launch a raw score, to launch eros master. Ok. There is no such thing in Rostow. Okay. You don't have any Ross muster anymore and we'll come back to that on the next lecture. But you can just launch any node like that without having to set up anything before with arrows master. So to start node, you will use Ross to run then the name of the package. So for example, demo nodes, TB, which is a package that was installed with the Ross foxy desktop installation. But that is the name of the package. And then you will have the name of the executable, let's say talker. Okay, so we start at a node and as you can see here, we have some logs. And the Tokyo will actually publish a message with a counter on and on a topic. You can kill this node with Control C. Though felt what you can see is that the common line tools are quite similar between ROS1 and Ross to in ROS1 you would do Ross run, okay, plus of the package name of the executable. Now you do Ross tube, right? And basically that will be the same with all the verbs. So if you do 4s2 and press Tab twice, you have every command you can use that you have Ross to know. Ok, in Roswell and this would be Ross node. You have rows to service instead of Forest Service. Rose to Larry. They'll topic here. Instead of frost or big etcetera. You have OK, you don't have rows, MSG and Rrose Selavy anymore. It is Ross to interface. Okay. Well, we'll talk about interface instead of MSG as RV right here. So if you do Ross to interface list, you have every message that is installed on your computer and available on your environment. So as you can see, a lot of messages and services. So let's start again. The Tokyo right here. For us to write in this terminal, let's do Ross to topic list. Okay? And we can see the topic here refers to the peak ICO chatter. Okay, so that is the same command in rows one and rows two. Cross two. Topic list will give you the list. Then equally, you can print what's inside topic, etc. Let's do Ross to node list. Okay, you can see that node and rush to node info talker. Okay? You can see some information about what are the subscribers, publisher services, et cetera. So in this terminal, let's launch Ross to run demo nodes. We have demoed CPP and I for Python. And we also have a listener. So let's start the listener. The listener will actually listen to the topic shutter here, and we'll print the result two as you can see here, helloworld 80, right here. If I kill the publisher and the subscriber is still up but doesn't receive any message. So as you can see here, the verbs and the commands may have some differences in the syntax, how you ride them. But basically, this is quite the same between Ross worn in a rush to write, you know, we've, we're asked to run, this node will be executing and then you can have some publishers, subscribers, et cetera. And from the command line tool, you can just debug everything using Ross to service rose to topic. You can actually, for us to do Ross to frequent topic pressed up twice. You can see everything. So you can just try a few things, experiment what you already knew in ROS1 and find out how to do the thing in rows two. And for example, you can but dash, dash help with every command line tool. And this will give you a nice the condition with all the commands and what it does. And one more thing I want to show you. So let's start the Tokyo again. We have the talker and the listener running. I'm going to run accurately graph. So in OS1 you had equity graph in Rust. Okay, let's refresh here. We need Luton and you can see we have two nodes here that Docker and the listener. And between them we have the chatter topic. And you can see which one is a subscriber, which one is a D-Sharp. They'll execute the graph would be the exact same tool between ROS1 and Rostow and form many GUI tools. You will see that basically in ROS1 animals to the commands and tools are exactly the same. Alright, so in this lesson you have seen some basic things you can do in rows two, which are pretty similar to what you previously did in ROS1. So how to start nodes, how to debug nodes from your terminals, how to use the GUI tools, et cetera. And we're actually going to use those command line tools in also jiugae tools in the following of this course. 8. ROS1 vs ROS2: First Differences (quick overview): In this lesson, I'm going to explain to you some of the main differences between ROS1 and Ross too, when it comes to the architecture. For all the other differences, which are more practical, I will use code examples instead, but here for the architecture, a diagram, we'll certainly make more sense. I will mainly focus on what you will need to use rows two and only show you the differences that matter to you as a developer. So here is the ROS1 architecture. Very basically. First, at the bottom, you have the operating system layer borrows one, only Linux with human to Israeli fully supported. On top of that, we have the middleware layer, but we have disappearance and UDP rows, also known as the Transport Layer. And based on the TCPIP protocol. Then you find the Ross pie and Ross CPP libraries that you already used in all your programs. Each of them is a complete independent library based on the eros Transport Layer. Finally, when you actually use ROS as a developer, you will write your own code based on Ross bike and Ross CPP. And you will also need to start arrows master before you can launch any of your nodes. Okay? And now what about Ross to, well, first of all, Frost who is now officially supported on both Linux, Windows and Mac OS, which is a great news. And note that for this course, we will still focus on Linux. We Have you been to, as it is a great operating system for software development. And this will make things just simpler 40 schools, so you can use, you went to for this course and then you can eventually change the operating system. So this multi-platform support is possible because the transport layer was totally changed. Instead of a customer OS layer, which is only specific to one operating system. Now, Rostow is using DTS, which means that our distribution service, I won't go into the details of DDS. You just have to know that it will handle communications at the middleware level. And some of the implementations for DDS are already supporting multiple operating systems. When you develop your application, you won't really need to care about that. That is quite a low level of the architecture. Then what do we have on top of DDS? First, a library called LCL, which means cross client library. This library is a pure C Library which directly deals with DDS. The LCL contains all the core functionality is you can use with Ross too. But again, you won't directly use ASL and you won't need to write pure C programs. On top of here, you have all the real client libraries you will use in your programs. For example, SEL by four Python, LCL, CBP, four siblings plus there are some other libraries for a given pole. Scl, Java, LCL, NodeJS, etcetera. Ok, so that is basically the differences in the architecture. But what does it change for you? Well, in ROS1, when a new functionality was added, will, It was very often added for C plus plus in the Ross CPP library. And then if you wanted to use this feature with Python, for example, you would need to completely rewrite the feature by Aerospike. Maybe wait a long time. Which means that practically speaking, many features were only accessible for C plus plus and not for Python or other languages because nobody had the time to do that development. Coming back to Ross to one great vantage of our ROS1 is that whenever a new functionality is added to the STL library, then it's quite easy to make the binding with any of the upper libraries. Which means that not only unsealed by We'll have more functionalities, but you will also be able to write complete applications in other languages than Python in C plus, plus or so. And this is a very important point. No more Ross muster. In Ross t2. You want need to start a raw score before you launch node. In fact, nodes up totally independent and have capabilities to find other nodes on the network is we make multi machine communication much simpler. So let's make a quick recap of the important points, and I will add a few other things here. Ros1 only truly supports Linux. We've Ross to you can use Linux, Windows ten and Mac OS. In ROS1, You have to start arrows muster first. You'll nodes can find each other. Roles too. It's a completely distributed system, are no more wars master. You have client libraries for both Ross wrong and Ross too. But in ROS1, each one of them is a totally different climber. Whereas in Ross to all of the client libraries are based on RCEL. All of the functionalities are implemented once in LCL and then abiding is made with SEL pi, SCLC, VP, et cetera. One additional point here. Ros1 targets Python two and C plus, plus up to c plus plus 11. Note that there is an exception here, forest noetic, which is the last Ross one distribution, and which also targets Python three in a rows to all of the distributions, target Python three. And you can use up to c plus plus 14, which is great. And finally, I wanted to add this last point in ROS1. You can write your program however you want. There is no given structure to follow for your nodes. And these changes for us to. The new way to write your node is to use object oriented programming. You will have to make your node class inherit from the node objects in either the axial py library, LCL, CVP, et cetera. This is quite a big difference and you will know all about it when we start writing some nodes. All right, I'll stop there for now. We could dive much more into theory and I could point you to many other differences. But those are the main important ones that I think you need to know in order to start writing some code. 9. Re-write a ROS1 App into ROS2: In this section, I will show you how to translate a or OS1 application into a arose to application. I will give you an existing or OS1 application, and we will rewrite the application together and focus on the main different points. At the end of this section, you will be able to write a complete Ross to application using packages, nodes, topics, services, diameters, and launch tries. You will also work with the most important Ross to Tools. Alright, let's get started. 10. Install ROS1 Noetic to Test the ROS1 App: So in the next lecture, just after this one, I'm going to introduce you to the Ross one application we are going to use as a starting point to write our Ross to application. But first, I'm going to show you very quickly how to install ROS noetic here. Why? Because, well, it could be nice to be able to test the ROS1 application, not just to pseudocode and translate into Ross to get actually two started in ROS1, see what it does, and then translate it into Ross too. So I won't provide the code or ROS1 melodic and roast one noetic. And here I'm going to show you very quickly how to install ROS1 noetic on your computer. You should already know how to do that, okay, because you already know ROS1. But more importantly, and please stay until the end. I will show you how not to mess things up with your environment because right now you already have Ross to foxy installed on your machine. And you will have, so you will have two distributions. Arrows to distribution was to foxy any arrows, one distribution, ROS1 noetic. So you will see that you need to be careful at what you set up if you don't want to mess things up. And first thing we'll do is actually to go to our bash assay, okay, in the Bash assay you already have this line. So sues OPT Ross foxy setup dot dash. This line will sauce Ross to in your environment. Okay, and now we are going to install ROS1 and news ROS1. So it's maybe better not to have sourced cross to when you use Ross one. Okay, what I'm going to do is to actually comment this line like that and save the Ashkenazy. So when we open a new terminal, Ross two will not be solved. So it is installed but not sourced. And we're going to close the bash assay. And the other problem is that when we opened this terminal, the bash Massey was sought, saw the rows to installation setup Donbass script was unwilling to close that window and append it. Again. And I'm sure that rose to is not sourced. You can go on Google and simply type in star rose nowadays. And you will have a link here on wiki dot ros.org, which is the ROS1 documentation. Though you click and you can click on Ubunto here because we have you went to and we are going to install it. So very quickly you set up the sources, the total keys. That command. Now you can update. Ok, and now you can choose one of the different option here, or you just have the bare-bones we've brought us noetic rules-based. Then you have desktop and desktop full. So actually if you want to use noite completely, you will need Ross noting desktop full. But for this course we only need Ross noting desktop. Okay, we don't need all of the additional packages from the full. So you can install that. And as you can see, it's already installed or me already. And for you, you can press yes and wait until it's done. Okay. And that's about it for starting Ross Nordic. And now as you can see, if you want to use ROS1 noetic in this session, you will need to set up your environment. You will need to source that scraped here, okay, so if you go to slash property slush rows, you can see we have the Foxy installation, so 4s2 and noetic. Roswell. Though, if you want to use, for example, a raw score and you want to start a raw score, you need to toss the setup that brush been noetic. And then you can do raw score to start Aeros muster in Roswell. Alright, so it's walking. And again, as you already know, if you open a new terminal, you will need to source that. Great. Again, what we're going to do is going to the lash assay again. Okay? And here we're going to add that right here. So we have one source line for us, 11, so sine four rows two. And here already pay attention to what's next. Okay? So if for example you do that two different distributions. For example here, eros to distribution and arrows one distribution. Well, first you would have a warning in your terminal, and then you may expect some unexpected behavior and you will basically mess things up. Okay? So, Well, you have different choices here. You can either not, but those line in the ESI and every time you open new Delano, you just source what you need. At least these k's. You are sure that you don't make single apps. Are you can add both those line and always make sure you comment one before you open a terminal. Though, converting that one when open Demi on Ross one noetic would be sourced. And the other option is to commands that line, so cross two will be sourced. Okay, what are the other? Not both. So I'm going to save it like that. Okay. So only ross, No, it will be source for now because we are going to use arrows to an application. So now if I open a new terminal or OS1 is sourced and not for us too. 11. The ROS1 App We'll Use: In this video, I'm going to introduce you to the ROS1 application we will use. So you can understand what are the different parts, the different packages, different nodes, and what are the results you will get. The once you understand this application, this is very basic application. Then we will step-by-step translate this application into Ras to application. So first of all, I'm going to go back again to the bash SEO. So make sure that you have solved only Ross noetic, okay, and that rose to foxy. Okay, when this is done, I'm going to open terminator. Okay? You can just have different windows. And here I have four terminals in each one of them has sourced the Ross one noetic setup dot bash script, but can use the ROS1 in all four terminals. So now what you can do is you can download the code archive and actually have done it here. Gotta archive name, number at ROS1 noetic, OK. If you are on melodic in Ubuntu 18.04 for example, then I also have a number up ROS1, middle Dick. And you can download and instructions here will be the same. So you can pause the video now make sure you download the color and then come back. You'll video. Okay, so what I'm going to do here, I'm going back to the home repository and I'm going to create a workspace. Okay, so usually in Roswell and you create a workspace name get kin. And oscar WAS for cat King workspace. Okay, that is quite a convention you use in Ross one. But actually for the purpose of this course, I'm just going to name it for OS1 underscore Ws because anyway, you can name the workspace as you want, doesn't matter. Ok? So I create the workspace. Inside the workspace, we should create a source folder, but in fact this was folder is already in the could archive, so I'm just going to move the color from the download number up here to this place here, and to unzip. And he and I have my source folder. So if I go into those, you have the you have the TXT that is automatically generated when you compile your package. So it's already here for you. And you have four different packages, okay? You have my robot bring up, which will contain a lunch fine. My robot messages, which will contain custom messages. And then you have Ross one app, CBP, which contains the complete cplusplus application, and Ross one app, Python package, which contains a Python application, okay? So you can already do that and can make. Inside the cross won an Oscar AWS repository. Ok, so the compilation we've kept Qin makes should not produce any error. If you have an arrow, then your setup is wrong. Please make sure you have correctly installed and setup everything. So now we have a build, a digital folder. In the folder, we have the setup dot Bash script that we need to source in order to be able to use the functionalities from that workspace. So you already know that. So what we can do is go back to our bash RC. Okay, and after this line, after setting up ROS1, we can cross one workspace. It will setup. So here I've added a new lane, we've rows one. And so if you ever want to go back to Ross Tulane unique to commend those two lights. Okay. And uncomment that once I'm going to save the file. And if I want to be able to use the workspace here, I need to source the setup, the dash here. I can just saws to bash c, k, m here also. And finally here because they can source it from there. Okay? Now before we see the code, I'm just going to start the application. So ross, launch. You have robots, may robot bring up, you have lunch phi in my robert bring up named number up, LOT launch. So the obligation is named number up. Okay? So you have a number publisher and a number of counter. The publisher will publish a number at a given frequency. So here the number is ten. And the number counter will actually subscribe to the number to get the number and print the number. If her QT graph. You can see we have one publisher. So this known Number Publisher, which is publishing on a number topic, number counter is subscribing to the number topic. Okay? And if I do, so, if I do Rostow peak, this, we have number topic and then we also have a service ross service list. We have breeze it counter and there is a contrast service and we'll actually use it here. Ross service called counter. And we have one field for the request, which is reasonable value. But you can set the value to reset the counter here, I'm just keeping 0. As you can see, the contour here has been reset to 0 in the number can turn node. Ok, so let's see actually what is inside the cone. And I'm going to use VS code. You can use whatever text editor IDE watt. Okay, and let's go to the Python one. So we have, well, you can basically browse all of that and see what it, what it is. It's simple. Ross on application. And in the script folder we have, so we have the number publisher first. You can see the number bullish on load, we have one publisher and the number topic with int 64, message from the standard messages package. And we then publish. This is a very simple structure here. We use a while not cross-price shutdown to publish with, right? Yeah, I create a rate, will publish frequency that we get from a parameter k, the number. We also get it from Ross parameter number published frequency n number to publish. And actually these will publish the number at a given rate, which are both parameter. And we have one log here, ross by login folk to say that it has started. So nothing really special here if we go under contract. So you can see I have number counter and O P number counter because as I told you in the last one, you don't have a specific structure to follow. So you can just write your node like that in the main function of your program. And then with some function at are just the root of your program. Or you can use also object oriented programming the way you want. Okay, here I just added functionalities in a number of counter class. Okay? And that is my way to write some nodes in ROS1 using her topic. So the number counter, you have the standard way and OOP way, what does it do? So we have the number counter loaded here, and basically we create a counter, we initialize it to 0. Then we have a subscriber for the number topic. In the callback of the number topic, we simply had the data from the message to the counter and we print the counter. Okay? So whenever the number publisher publishes on the number topic, we received the value here and we print it. And then I have service reset counter with a custom. As you can see, this is a custom service and this has a callback here. What it does is it checks the reset value field. If it is greater than 0, then the counter becomes that value, and so becomes that value. We have log and then return true because the result is a Boolean. So you can check the Python application here. Your siblings plus is the same thing. Ok? It is just the exact same functionality but using C plus plus. So you can also check that. And we have my wrote messages. As you can see, we have the reset counter service, which we use in the number counter levels. So you have all the setup for Ross warning messages here. And my robot bring up, which contains one launch file to start the entire application, which is the number pollution node, the number count on node. And of course we need two parameters. Number pollution though. Yeah, here I said the two parameters value. And I have started the Python version and commented here the surplus position so you can switch as you want. So that was a very quick explanation of the ROS1 application. I encourage you to read a little bit more of the code just to understand what it does. But actually we're going to go piece by piece and step by step, translate every functionality one at a time during this course. And I will come back to those packages more in details. At first, we are not going to use the app at the same time. We bras one anarobes to I will keep the ROS1 code on the side just so we can translate it into Ross T2 is by these only in the next section, we've Ross one bridge. We will use both the ROS1 version and the eros to version at the same time, but not for, not for now, we focused on the Ross to code and differences between rows 12. 12. Install colcon: So now that you have seen the ROS1 application, we are going back to Ross to 100%. So first thing we will do is go back to our bash assay. And we will actually put a comment here, but a common here and uncomment this line and save the bash assay. So now when we open a terminal, we have sourced bureaus to installation. If you ever need to come back to the ROS1 application, then you can come on this line and uncomment those two lines, plus open a new terminal. Okay. So I'm going to close that. And since ROS1 is already sought here, I'm going to close it and open a new terminal. So now we have Ross too soft. And before we can actually create and write our arose to reputation, there is just one more thing you need to install and setup. And this is the build tool for us to go in ROS1, you would use cat Kim, Okay, so you use get Kim to build your packages and your application. In rows two, this has changed and call Khan has now replaced cat Qin. There is no more cat Kim in rows two. And when you install Ross, too unlikely in ROS1 and the build tool is not installed. You're going to install the spill APT installed Python, Volkan common extensions. Okay, so for me it's already installed it because I did it before. But for you, you do that command and then you can use call gone to peel your workspace. And just one more thing. When you install call khan, Actually you don't have the autocompletion automatically setup. So we are going to do that and you will just follow me here. You are going to user share. Vulcan. And a score are complete book. And here you have called cannot complete that Bash. Or if you want to use the auto-completion of occult khan, You need to source that script. Okay? Everytime you need to use the autocompletion in a new terminal. So what we'll do here is that in our bash has c. Okay? So we can do that here. But we're going to source. But this path right here, flash, Glaucon are complete. But Bash saved abashed passing. Though we still have the global souls for setting up our under almond for OS2. And thus to get nickel autocompletion feature. Okay, this is actually not that important. To use roster. You don't need that, you just need that to get the auto-completion. 13. Create a ROS2 Workspace: Let's now create a Ross to workspace so we can put our Rostow code inside it. So I'm going to open a new terminal and make sure you have correctly sourced your environment because here you need the eros to functionality. So make sure you have sourced Ross to focus on government. So I am in my home directory. I already have the ROS1 workspace here. And I'm going to create a cross to underscore WAS older though. Now this is quite a convention in Rostow to name your workspace rows to an Oscar ws. Okay. You go into that workspace folder and you're going to create a SRC folder subfolder, okay? And that is the beginning of your workspace. And we will create, just like we did in ROS1, in Rostow, who will create any package inside that source directory right here. And what we can already do is to compile our workspace. So in ROS1 you would do Catlin made. Here. You will do Qualcomm build space between their collagen built. Okay, and it's working, but of course we don't have any package, so nothing will happen. Just one more thing, real. If you do dash, dash and you press Tab twice, you will have all the options you can use. And actually if you don't have that, makes sure you watched the previous lecture and correctly setup the autocompletion for conquer. So now I'm going to see what inside the workspace. And we have three new folders. We have a log folder which is well load about the compilation. And then we have build like in ROS1 and installed in ROS1 you have a diesel folder. Here we have installed folder. And inside this install folder, well, we also have a setup dot Bash script. So as you can see, whether you are in Roswell Ar 4s2, you first need to source your global installation, and then you need to source the workspace so you can actually use your custom functionalities. And here you will find that many people often use the local settable dash instead of the setup. What is the difference? Very quickly, when you execute, when you sous that script, it will source this workspace, which we can call an overlay. And it will also soul's, the underlay, which is the global Ross to installation. If you just sourced local setup dot bash, it would only source that workspace. Though you need to source the global rose to installation before. Okay? And here for this course, just to make things very simple, I will just use the set of the brush. Everytime. This will not change anything in the result. You will get on a. We go again in our bash assay because we don't want to source that every time we open a new terminal. Okay, and here I'm going to source, after the global installation, I'm willing to source rose to nanoscale Ws installed that the bash and saved lush pasture. So now you have five lines in Bash assay to that are commented, which are rows 13 for Ross to global installation workspace and the autocompletion for Kolkata. So I saved the file, I quit. And now if I open a new terminal, I know that I can use Ross to n. I can use my own custom workspace. 14. Create a Package (Python): In this lesson, I'm going to show you how to create arrows to Python package. And you will see the differences between a package in ROS1 and a package in Ross too. So let's come back to our ross weren't application. We'll just create a Python package to match the ROS1 Python package we have here. So we have all packages in our OS1 application bring up missing the cplusplus application and Python application. We're going to keep the bringing up and the messages for later. And right now I'm going to go with the Python package so, well, in ROS1, whether you create a Python package, it's just, I mean, I just put that in a name, right? But the package is just packaging inside. You can set it up for Python, for cplusplus. In Ross tool. You can also do that, but know there is a new way to set up the package. You can specifically create a package for Python and specifically create a package for C plus plus. And that's why I have but two different lessons, as you can see, this one for Python and the next one for C plus plus. But I'm going to open a new terminal. Okay? And again, I'm going to show you one last time in the Bash assay, you should have at least those two lines here. Okay, to source the global Rostow installation and to source your workspace and the lines for any other ROS1 or rows two distributions should be committed are not here at all. Okay? So I'm going to the grass to workspace. And in the source, in the sud directory. For now we have nothing because we didn't create any package. So in ROS1 to create a package, you would use kept skin create by Cage, then the name of the package, and then the dependencies in Ross to we don't have good Qin anymore and now we have a Ross to EKG create functionality. This is the same. Ok. You use Ross to command line tool with BIG AG and create. You can put the name of the package. So let's name this one rose to Python. And now you will need to provide a real type. As I told you. Now in rows two, you can choose if you want a C Plus Plus package or if you want a Python package. So I'm going to use the build type option. We've, Okay, let's make it bigger. So we'll type like that. Dash, dash will type. And actually you can press done autocompletion payment. Python. Okay? So if you do that build type Amun Python, you will create a Python package. And we will see just after that. The architecture for IPython RC plus perspective is quite different. So we have our Python package and now we can add dependencies. For that, we will actually use the dependencies option. They penalty. So first of all, because we are going to write some code with Python with the LCL py library. We need to include LCL pie in ROS1 you had wrought by. Now we have LCL. And to know what other dependencies we need to add here for this package. We are going back to the Ross one Python package here. Good truly package that XML. As you can see, we have a dependency for Ross pi. Ok. So here in rows two, it is CL by, we just made that. And we also have a dependency to STV messages. So standard message, then that message is also exist in rows two, and we're actually going to use it pretty soon, so I'm going to add it right here. Okay? And what do we have? We also have a dependency to my robot messages, but we didn't create this package yet, so we will add it a little bit later. So now we can press enter. And as you can see, we have some logs and a bunch of files where just created here. We have our package. And Let's go into the package. What do we have here? So we have a package that excellent. This, actually, this is the minimum unit for every package. You need the package dot XML. And then as you can see, we have a resource folder, eros to app by. So this is the same name as the package. These folder, we have a test folder and we have setup dot CMG and setup.py. So this is very specific to Python. I'm going to open this VS Code also. So this is the Ross to package. As you can see, it's quite different from the ROS1. We have in package dot xml. So what do we have here? Name, version, description, etc. This is just some information you need to fill. If you want to release your package. Then we have some depends tag just like we had in ROS1 for the different libraries and packages we need and a bunch of other stuff. As you can see, the build type is Amun Python. And we're going to go back to this a little bit later. We also have a setup.py. Ok. We are going to go back when we write SA node. This is something that doesn't exist in ROS1. Whoever said that the CFG also, then we have a resource folder, okay, with just an empty file. We will not use that folder is cause we have a test folder, okay, where you already have three tests, phi's. And the most important one is that. So you have a folder which name is the same as the package name, and you already have Eat five. Please don't remove that file and you can keep it untouched from now. And we would write actually our code inside that folder. 15. Create a Package (C++): Now that we have a Python package for the Python version of the application, let create the C Plus Plus package for the simplest version. So if we go back to the Ross one application here, we will actually create a simplest prospect age for that one or OS1 apps. So we're going to create the plus plus By cage in Ross too. But you go in the Ross to workspace in the source directory where you already have your Python package and not so you already know what to do. Cross two, EKG create, We're going to name that bras Tube app. We're going to use build type. Well for Python, you used payment. Python. Here we will use Daymond CMake, okay. That we create a C Plus Plus package and then we can add the dependencies. We will need air seal instead of porosity between or OS1. And let's check the package. Again, we can check the package dot XML for the Roswell CVP. And well, we have porosity BB and we also have a destiny MSG s And my robot messages package. But well, the functionalities are the same between the plus and the Python one. So we have the same dependencies here. So I'm going to keep that for later. And we're going to add steely MSDS. Okay? So R2 package creates name of the package, wildtype, Amun CMake for C plus plus, and then dependencies with axiom CBP because you want to write some code we've Rostow and every other dependency unit, right? We have a new package. Let's go inside that package. And as you can see, the structure is quite different from the Python one. And this one actually looks like, more like ROS1 package. I'm going to the here. This is our roster workspace. Now, we have the Python package and the C Plus Plus speculation. And as you can see, the architecture is really quite different. So what do we have in our civil package? Well, we have the package dot XML, which is what you will always have in arrows to bike age with the same information here that you need to fill if you want to release your package. We have some dependencies and you can see the build type is payment CMYK. Now we have a CMakeList.txt because this is plus, plus. And we're going to come back to that. This is where you will have executables. You will install the execute tables, etc. And you have include n source folder. Well, quite typical for a C Plus Plus folder. Okay, so we're going to use the source folder to write our cplusplus note. 16. Create a Node (Python): In this lesson, I'm going to show you how to write a Python Node in Ross too. I have opened here on Visual Studio Code, the current workspace that we already created before. We've the Python package and this C Plus Plus Package. Okay, so I'm going to work in the Python package for now. And when we create the simplest best known Next, we're going to go to the cplusplus backstage. So I'm going to take two steps to write this load. First, we are going to write kind of node like we did in Ross one. Ok? We have a very basic structure and then we're going to improve that node to match the rows to kind of stand out and use object oriented programming. So what I'm going to do here, I have a Ross to workspace and I am going to add the folder that workspace and add the rows one workspace here. Okay, so first I have my roast workspace and then my ROS1 workspace. Okay, I will keep that for the entire Ghosts when we walk on the number of application. So to create a node, let's go to our workspace in the source directory. Okay, we will go to our Python package. And where do we put the node here? In Ross warning you would create a script Fowler and but any Python inside. But in Ross to, you already have that. Although right here. Now you will go to the folder which has the same name as the package, and it's automatically created. And here you already have you needed by pi. So you're not going to touch anything in this file and you're going to create a new one. So in Ross one, we have we have number counter and number publisher. I'm going to start with the number publisher. Let's create. And Number Publisher. So Python, one animal will make it executable also. So we can launch it. And this will be quite convenient for the following. Great. So we have our fire right here, which should be in this folder. In ROS1, you would create a script further and put your Python files here, make it executable in Ross to you simply go to the folder which name is the same as the package name, and you create an executable Python file right here. Okay? So what do we have in our ross? We're node. Actually, I'm just going to write a very basic node. I will not do the parameters. And then we do the publisher things that we'll see a little bit later in this course. Right now I'm going to just write basic node. And so you can have kind of a template to write for any of your following node. So first, but the line for Python three, ok, we are going to import SCL. By K as yet by, because that's the library we need to use to write Python code we've Ross took. And then we're going to write if name main. So that is the main entrance for the program. And here we will define a main function or which we can pass arguments. And by default there is none. And we told the main right here. Okay, so what do we do in this main function? Well, the first thing we will do is to do LCL by that. And we will pass the hours. We feel the outs parameter from the init function with the ads that we get from the main. Ok. So this first line will initialize for us to communications. It will not create a node or anything. It will just initialize Ross to communication. Then we will create a load, etcetera, etcetera, do our functionalities. And at the end, we are going to do partial pi that shut down. As hell by shutdown will simply shut down Ross to communications in any of your rows, two nodes. That is something that you will do. First initializer 4s2, and then shut down. Whereas now we are going to create a node. So the difference here in Ross, when you hear the first thing you do is to do a rose by any node. So basically the node is linked to the executable, right? You do any note to initialize the roast one communications and to initialize the node with a main. And in Rostow That is different because in rows two you will first initialize rose to communications and then you recreate an object of the node. And so the executable itself is not the node, right? And we will not see that here because its basic course, but later on you will be able to create multiple nodes inside one executable, right? That you couldn't do with cross one in Python. So we're going to create a node. And to create a node, we're going to import from SEL pi dot node in part. No object with uppercase. And we're going to do node equals node. And we need to give a name. Let's call it number publishing. We have our node. Now what we can do, so we can if we want to print something. So let's do that. Get logger. So we've not get logger. You can have the logger functionality and then as you can see, you have Info, erato, etc.. So you can simply choose to kind of flow viewpoint to print. And let's see. Hello. And I save the phi. So that is also another difference in Ross one. Here we had a lug in ROS1 when you login, you call Ross by that login for. But the important part here is that you call the log functionality from frostbite in rice to you call the log functionality from the node object. Okay? As you will see in the following, everything is linked to denote, okay, we don't directly use the axial Bye. Functionalities. You use the Assyria by push ID through the node. Ok, so let's keep it like that funnel. This is a very big extruder. You'd just, so you just have a main where you initialize it rose to communications. You create a node, you do stuff with your node, and then you shut down Rostow communication and the node object will automatically be destroyed after that and everything and you know, it would be destroyed. Okay, so now I'm going to a new terminal here. And let's go to our rush to workspace source, which really are us too. Here we can do number publisher. So if you execute this file, you will see that these works. And we have a log here with info, the timestamp, name of the node here, and the actual log. Okay, so just like in Roswell and you can directly go to File New just written, and you can execute it just like that. But as you can get, this is not the best way to launch a node. If we always have to go to the folder where the No, that hasn't been created. This would be quite not convenient. So like in ROS1, will we be able to start a node with the Ross to run command. But in our asked one, when you do where aspirin, for example, here, when you do Ross run the number publisher, that pi here will be executed directly from that folder in Ross to, well, you first need to install the Python node, ok. So there is a little bit of extra set up you need to do if you want to use the Ross to run functionality. And what we're going to do is go to the setup.py. What do we have here? Well, this is a bifan fire with some stuff leg package name and you have some information, as you can see, name version, main donor, maintenance descriptions, those informations the same as in the package that XML right here. Okay? So if you ever need to raise your package, you will need to fill that in for here, and also the information here which are specific to Python package. And musically you bid the same thing. And What we're going to look at here is entry point with console script. Okay? You can forget about that for now. The important point is here we have an array console script. And in this array, we will define some executables. But we can install the executable from if I. Okay, so this is a completely new functionality in R2. Let's see how we can create one executable. So horizontal number publisher that we need the name of the executable. Then you put the name of the package. It was to app, which is here. Then you dot the name of the file number pollution. And to point, and you will need to choose the name of the function you want to launch. So here the function main is the function. We want to start with the name of the package dot name of the file without the dots by extension and two-point name of the function. And you want to start. And here this will be the name of the executable that you save that file. And now we are going to compile the package. So let's go to Russ to workspace. Okay. We will do coke on real. Okay. I will I will show you the different options would call convenient. Let's first simply do call compute. Okay, so as you can see, we have built here the cplusplus package and the Python package. And now if we go to the installed folder, we have a folder for the Python package. Okay? And if we go to the leap, here, we have another folder with the name of the package again. And here we have Number Publisher. These Number Publisher executable is actually the name here is what we have defined right here. Okay? So you might wonder, why do we need to compile the package to run Python node? Because Python, you just need to execute the script, okay? Right, but you need to make the difference between compiling a file and installing a file, okay? Combining in cyberspace, you need to compile the file. You need to create an executable. And then you make install the fire. Installing a fine simply means that you will put the file in another place, maybe modify some of it, maybe add some setup. So for Python, and now you need to install the phi, which means that if you look at what's inside, as you can see, this is, you don't need to care about that, but this has been generated by Qualcomm when you actually build the package. And it will automatically start the executive. If you want, you can also start the executable from there. But here, if I simply do that, I will have an error. Okay? So you need to source, you brush assay, which has the source line for the workspace. Okay? And now you can see that the number publisher, and you have number publisher node, which has been started. Alright, and now what you can also do it to use Ross to run. So you can only use Ross to run after you have soul's, your environment and your workspace. So we're asked to run the name of your package, rose to app icon. And if I press Tab twice, number approach, there is only one. Ok, so that is what you really want to do, like you just did in Roswell or OS to run a caged executable. And as you can see here, we don't have number publisher that by simply never publisher because that's the name of the executable here, right? And just one more thing here. You have the name of the executable, which is different from the name of the file. And inside the file you have the name of the node, which is also a different thing. Yeah, I have but the three names which are equal, but those are three different things. 17. Create a Node (Python) with OOP: Okay, so now you have seen how to create a very basic node and how to install it will set up. What we're going to do is actually to create now denote with the object oriented programming way. I'm going to create a class named let's say number publisher, node. And this class will inherit from the node object right here from the SCL pilot mode. Then we can directly read the init function for the node, which is the constructor and called Super Bowl. Super will call the constructor of the node object. Okay? When you inherit from an object, you have to call super init. And you can put the name of the node right here, number publisher. So this way you initialize the mode and then if you want to do that, for example, not get logger info. What you do is simply do self. Yet logger in folk. Okay, why cells? Because now our class is a node object, okay? So everything you will do, we've rushed to every Ross to functionality. You will actually call them from self, which is the node object from which the class inherits. And now that we've written that, we can simply remove the line and say that node will be number collusion node. And that's it. Ok, so actually now I'm going to append here. I'm going to open to run terminals. Let's go to workspace and for convenience, I will show you so Cole can build we again will every package we have. And maybe we don't want to build every package we have because Fano rate takes not too much time, but after a while, this may be too long. So what you can do is to conform with the option packages elect. And you can see I have the autocompletion here. I can just select and then the name of the package rose to high. Great. So when you do that, only the selected packages here you can put a list will be built. Ok, so we only build the Python package. And now in this terminal, I can source assay, gets the new version of the workspace. And let's do Ross to run for us too. At Python and Number Publisher. Okay? And we have, so this is the same thing, okay, we just print a lot. Now, we're going to go back here. Maybe changed that log to say Number. Publisher has been. Okay, even if we want to publish a number right now, but this is a practice that they often follow is to say the name of the node has been started. After you finish the construct or so. When you have the logo, it's clear that your application has been started. I'm going to add here SAL by that spin, okay, you already know spin in ROS1. Spin will allow your node to be alive, to continue to be alive until you kill it. So why wouldn't notice alive it can process any kilobytes. So as him by spin node. But as you can see here in class one, okay, we don't spin here in the number counter we speak. We just do Ross buy in because the node is actually linked completely to the executable. So we'll just been the node like that. In Ross T2. You will do SEL pilot spin. So that is quite similar, but you need to provide DOM nodes to spin, okay? So we create a node here and then we decide to spin that node, okay? Make sure to provide node has a parameter for the Asiana pilots pin. And now we're going back here. Note that if I just run the number publisher again, we still have the old version. So I need to compile Python package again. Now I can run it. Number Publisher has been started and yes, it's spinning. I press control C and it's done. So note that when you press control C on a Python Node, you may have this long, okay, you don't need to worry about that. I'm going to add a new option here when we build, because it will be quite annoying to always have to build your package every time you modify a Python file right there, what we can do is add link in stock like that. So I'm going to read it again. But now executing will that is installed. We'd have a symbolic link to the actual file we are writing. Okay, so for development purposes, using Simulink installed his great. Okay, so that is the actual number publisher that hasn't changed. But let's say I put an exclamation mark here. I save the file, come back here. I don't compile again. And now we have the exclamation mark here. We'll be able to modify this file and not compiled everytime. You need to compile one time first, at least when you create a new file, then you can use semantic install and just modify and execute the file again only for Python. And I'm going to do one last thing here. In the publisher, though. This is a quite Donald Trump tour in Roswell. You do why not ross, by each shut down, you use a rate, okay. So you can do stuff at a given rate here. You do read that sleep. So for example, if you have frequency at ten hertz, then when you do write it, we'll make sure that this will be executed had ten Hertz. In rows two. We will not use right anymore. Instead, we will use timers. So Timer already exists in ROS1, right? There are quite a good alternative to the right. And in fact, that's the only thing we will do in raster. So I'm going to create a new function. So when you create a function for the node, you will simply create a function inside the class. Let's say print. Okay, I'm not going to publish it right now. And yeah, we'll just, Let's say we have a number which is four. And we will do, they'll get logger info, has tear number. Ok, so in this function we simply print the number we have created in the class. And here I'm going to do that. Remember timer. And we will do self create timer. We need to give a period. So let's say 0.5. so the frequency would be two hertz. And we need to give a callback. Self brings number without the parentheses, right? So again, one thing to notice here is that we create the timer lyrically from self, which is the node. Every Rostow functionality will be created from the set. And this will simply create a dimer which will start right away. Every 0.5. signal, it will call the print function. And as long as you spin, the timer will continue to run. And when you press control C, then the spin will end. The timer we end and then rose to communication would shut down, the node will shut down everything which said that though, let's go back here and let's start node again. And as you get c, We have four, which is printed every 0.5. Alright, so now you know how to create a Python knows how to put these node with object oriented programming and you know how to install it. Plus, I'll do use some of the eros to functionalities inside that node. We're going to see the simplest version. And then I'm going to give you the template you can use for all your load. 18. Create a Node (C++): In this lesson, I'm going to show you how to write a C plus plus node. We were asked to make sure you watched the lecture on how to create a Python node, because some of the stuff will be identical and I will go a little bit quicker up on these lesson here. In Python, in Rostow, we have created the number publisher, but here in this folder. Now in the cplusplus package, here we will go into our source. Although. And actually, if I check the ROS1 app CBP package, we also have the same structure. Okay? So the simplest perspect aging or ASU is very quite similar to what you had in ROS1. Okay, so you have a number publisher dot CBP here, and then you will need to add executable in the CMakeLists.txt. And that will be quite similar in Ross to okay, so let's, let's create a new file. Let's go to our source directory folder workspace in the rush to app CBP package and the SUS, all of these package. This is empty phone up and we're going to create number publisher that CPP. So we can find the number publisher that CPP right here. Okay? And we're going to create an ODE. So now my publisher, CVP in grass one. So the functionality is the same as for the iPhone node we just saw in the previous lesson. First here you have a main, you initialize Ross one communication with the node. So you initialize the node right here, which is linked to the executable. You have a no, the handle, okay, in ROS1, in C plus plus you have to have them know the handle. And then every ROS1 functionality will come from the node hello. And you do your stuff. And then you can go in the counter, here. In the main. You can then. Okay. Let's go here. First thing we will need to include is SEL, CPP, flash, SCLC, pp dot HBP. Okay, I've got a warning here which is specific to VS code, but I'm just going to fix it very quickly. So you can see if you're using VS Code, are those work. You can press control shift and p. And if you can type C, C plus plus configuration, it's already here for me. You can type it and select it and saved folder. Yes, for the first one. So this will create a dot via Scott folder, wave, see CBP properties that JSON and Include path. You're going to add slash OPT, lush grass, rush, boxy because we are working with foxy right now. If you have a different Ross to distribution, then you will need to change the name just right here and then include. You can save that. You can close it. And now you don't have any warning and you will have the autocompletion for all of the global installed and arrows to functionalities. So let's create a main. And the first thing we will do in main is actually to initialize CVP in it. So we are going to initialize the roast to communication. And we give the arguments we will receive from the mayor. Though, then we can do some stuff. And at the end we are going to do LCL, CPP did down, okay? And this is the best program we can return 0. So whether you are writing a Python node R C plus, plus snowed in Rostow. You will first INET Rostow communication and then shut down Ross to communication. Now we are going to create a node and we can use the recent functionalities like auto, auto node. You follow me there. Std, make share. Here you put CPP node. And there aren't these with the name of the node, number, publisher and a semicolon. So what did I do here? I have created a SCL CBP node object with the name of the node here. And this node objects from SSE vp will be stored in a shared pointer. And to create a shared pointer, you can actually use STD make share. So again, we have a few things to notice here is that we create the node independently from SEL CBP in it and shut down. So the node is not necessarily directly linked to the executable. So you may be able to create multiple nodes. But for this course we'll stay with OneNote to keep things simple. And the second thing here is that we will use a lot of shared pointer in Ross 2i plus, plus, okay. Everything you will create, Let it be publishers, subscribers, etcetera. Any Ross to functionality will be stored in a shared pointer. Okay, so if you don't know shared pointers, where those are smart pointers in simplest persons that are very useful and well, you will get used to them very quickly. And if you look at the auto Here, we have STV shared pointer of SCLC Filipino. So you could write. That here, I'll just use auto in this case, which is quite more convenient. And if we want to do some logging. So in Python, this will be different from C plus plus and Python, Python forest to, you would do get logger on the node. And then in full, for example, in C plus plus, we will still use a macro fascial CPP wave for example, info, ok. You have one IRR. Ok, I will keep info. But in this macro we're going to use node, get, blogger, keynote. We use the URL, okay? Because this is a pointer, this is a SharePoint or so in order to get the objects we need to use the hero. And the second parameter will be hello, CPP load. Okay, and I'm going to add, it will be in note. So exactly like we did in Python, we spin with SCLC 3pm and we give it load. Okay? All right, this is like the minimal code you can write for a C plus plus node. And now, in order to be able to easily to this, as this is C plus plus, of course we need to compile it first and we will also need to install it. So let's go to the CMakeList.txt. This is the CMakeList.txt that you will get for every new package. And actually I will do some cleanup before we continue. Though. I'm going to remove that default to C99. And we keep the default 2i plus plus 14. And you can keep that. Here. You have the dependencies that you need, okay? And gt dependencies we added when creating a package and some stuff for testing. And we don't need that right now, so I'm going to remove it. And finally, Amun package to build a package. So let's, but the ROS1 CMake list under psi here. That is the ROS1 and browse tool. So here we do add executable and then target link libraries with the cat King libraries because we are using CAD came in Ross tool that we're going to do. Add executable also, we need to choose a name for the executable. So I'm going to choose number, publisher or slow. And this will be from the source. So the source, although the pike age and the file is Number Publisher dot. Now I need to also do something to link libraries, but I will not use target link libraries in cross to. Instead, we will do a meant target dependencies. Okay. This is a arose to specific construction. Okay. We've payment, which is the build system called Khan is the build tool a month in the built system eros to so number publisher. This is the name of the executable here. And we are going to add any package and we need it for this executable. And actually we need SCLC BOB. Okay, I'm going to save that. When we will add a standard missing genes, then we will need to add a sturdy messages right here. Okay? So this will create an executable like it did for ROS1. But we need to do one more additional step in parts two. And ROS1, you simply create an executable and it is automatically installed. Yeah, if you just compile it like that, lazy to table will be created but not installed. So you won't be able to access it. Though. We're going to add another instruction, install targets. But we're going to put our first target, which is number publisher. So this is the name of the executable here, which is the same here and same here. And we're going to add destination. And we're going to put that in the lib folder. And project name. Okay. Why project name, project name here is name of the package. That name. Okay, so let's see what it does. Let's go back to our Ross to workspace. You call convened. And actually, I don't want to build the Python package. So I'm just going to do packages direct for us to app Cbb. This will only build the simplest Plus package. And let's see if we get any error. Ok, so it's successful build. Now we can go into the install folder in our arose to app EBP. And here we have a folder. We have a leap folder because we're asking to create a leap folder here. But we're going to delete folder inside the lib folder. We have Ross to app CBP folder because again, that's what we asked from there. And here we have the execute table. And we can start it. Hello CBP node in. We can kill the executable. And of course, you will not always have to go that path to find an execute to Isaac table, you can simply do Ross to run. And before we were asked around, because this is a new executable, We need to source the underground Matt. So for us to brand, for us to AP plus, plus, rest up twice number publisher. And we can simply run it from there, from anywhere. Okay, so already pay attention to that. When you add a new executable, from now on, you will need to add at least those two lines here are the executable, an aim and target dependencies. And if you add a new civil, you would also add it right here. Don't forget to install the execute tables. 19. Create a Node (C++) with OOP: And now we're going to improve that code so we can use object oriented programming. And that is the way we will write all our cplusplus nodes interests too. So here we create a class. Well, let's call it number four, the sharp node with a public inheritance from SCLC entropy node. Okay? Don't forget the semicolon at the end. And we're going to have public and private. And let's write the constructor that's so number butch known. And you are going to initialize your node like that. You put the name of the node here, Number Publisher. And so this is a typical siblings plus initialization. You put 2 and you can initialize fields right here. And now I'm going also to But this line inside the constructor, okay, so we will do a seal UP info. But instead of note get logo, of course this will be this. This gets logger. And let's say Number Publisher has been started. I can know remove that line. And this line instead of creating the node like that, we will keep STD mixture. But will we create a number publisher node? Okay, don't forget the parentheses here. We don't have to pass the name of the node because we have written it. Here. We can save the file. And now if we run it against so for us to workspace. So here you will, of course, always need to build it again, because this is C plus plus. Ok, so we actually don't need to source.bash assay again because the fight is already known. If this was a new file, we would have needed to SUS measures you again. And as you can see, never publisher has been started. So these works. And now let's go back to the Ross one number publisher node. Here we have the rate, okay? And again we have a loop, while loop. Okay? So wide rows is okay, means. The node is not shut down. We will do something and sleep with the rates. So for example, if we want ten hertz here, the rate will make sure that this loop continues at ten hertz. And in arose to, again, like I told you with python, we will use timers instead of Great. So let's create a timer. So we can actually print a number at a given rate and willing for us to create a number. Attributes here, instant number. We can initialize it right here, number. And let's say that at 0. And we can add a function to print them. I will make this function private because I don't want it to be called from the outside. Print number. And let's say SQL, CPP, info. This get logger. And we're going to print the number. Like that. Though we have a function to print the number. Now I am going to create a timer inside the constructor. Create timer first, we need to declare it here. And that will be CVP timer. And we will add shared bit here. Is that as I told you, everything in rows two will be a shared pointer. Okay? And one nice thing they did in Rust with that. For a Roth to object like that, you can add shared Peter. And you check here. Using shared PGM means that your object will be std, share pointer of what's before shall Peter. Okay. I just quite convenient so you don't need to write the STD SharePoint o. And let's call it number of times. Ok, so we are going to initialize it here, number, timer. And how to initialize it. Use self, because this is not Python but this create timer, okay, in Python, this is create timer can still create timer. And we will need to give two parameters. The first parameter is the pion. And we are going to give a chrono duration. So let's use seagulls. And let's see. Once you end, the second parameter will be the callback. But as we are in a class, we can just give the callback like that. We'd use STD vibe. So STD bind, we need to give first the function which is from number that will show node number trillion being too good, too. New line. Where the first argument is the reference of the function inside the class. And then you need to give this link, this callback function to this object. Okay, this is actually this class. But if you are not familiar with that syntax, Well, this is just something you need to learn and that will be always the same, okay, STD bind name of the function and then the object to link. Now if I save the file, everything is ready. I can compile again and random node again. And as you can see, the number is published. So to quickly recap here, in your main, you first have to initialize the rows to communications. Wave passes the baby in it. Then you will create a node with stdin make shared, ok. The node actually you create in a class and you inherit from SCLC BP note in the constructor you can set everything up. Then you are going to make your nodes spin in when you press control C, Don't Know that we stop spinning the rods to communications which shut down and everything will be destroyed. As this is a shared pointer, you don't need to worry about destroying it. It will be automatically dao. 20. Template for your OOP Nodes: Alright, you can know create your own or us to nodes in Python and C plus plus using object oriented programming. Okay? So you already have the number publisher, node with a minimum of structure and some functionalities in Python and C plus plus here. What I'm going to do here is simply to create. And we have one other node. We have the number counter node in both python, ansible express. In fact, I have to variation of the node in Rust one. This is just only one node, you will only launch one of them. So we are going to create the number counter node right here, just the bare structure. And for that, we will use these templates. So there is one template for Python and one template far simpler space. So those two phi's are templates that I have created and you can download them as an additional resource to this course. And once you've understood how to create a node in rows two, well, this will be the exact same thing for every new node, right? You will first make some import LCL pie and important node object for Python. Then you would create a class inheriting from the node. Any will initialize the node in the constructor. In the main function, you will simply start Ross to communication. You will create the node, make, denote spin and Sheldon Rose to communications. And the exact same thing for C plus plus, you create a class inheriting front load. In the constructor, you initialize the node and everything. And then in the main function, you simply start cross to communication created load, we've shared pointer here, make the nodes being and shutdown or us to communication. So let's go, let's open a terminal and let's go into our workspace directory, cross too high. So we are going to the same folder where we have the number publisher and we are going to create content and make it executable there. If you don't make this file executable when you do coke on wheeled, we've Simulink install option, then you will have error. Okay? We'll make sure this is executable. And we are going to the C Plus Plus pack age still directory where we already have publisher, employee, we create number counter that. Okay, and you can see we have the two 5's right here. Never counter. Let's go to the Python 1 first. I will not, I will not do any functionality or the number contour. This is just to write the structure for the node with the template. And then we'll see the rest in the following of discourse. I'm just copying and pasting that. And what I need to do is simply modify the lines where I have put some comments. So here, well, you could keep my custom node has the name of the class, but we will change it. We've number counter. Note, if we change it here, we need to change it there. And we also to give a name to the node. Let's number counter. Let's keep things simple. I'm going to remove that structure is ready and the notice walking rate, though not one thing you should not forget with Python, is to actually add a new line in the console script array here, let's create an executable named number counter, which will be from the Ross too. Bye from my cage in the number counter bile. And we will choose the main function. And don't forget to add a comma here, okay? If you don't have the Kumar here, you will get, we'll eros, ok. So one line for each executable and a comma between them. Now we can compile, all gone. So you go to the workspace folder, Koko. Let's use packages. The legs. We've crossed two app. This will install the number counter using a table. Okay, and now in this terminal, I'm going to source.bash proceed to solve the under-enrolled and cross two. Cross two hap. We're number counter. And then node is working. It is not doing anything because we haven't done anything here. I may add a log. Let's say they'll get logger info counter node when studying. Okay, I didn't put this line in the template because this is not mandatory. You do that, you want to, this is this practice, but let's compile it again. And now we have never counter node hasn't been studied. Great. So that's it for the Python one. Let's go to the C Plus Plus One and actually copy and paste that here. Same thing. We need to change the name here, number, counter. So we need to change it here, also here for the constructor. And here we change the class name and then we change the node name, number contact. We can remove the commands like that and it's down. Now we go to the CMakeLists.txt of the sucrose prospect age. We can do add Execute table number counter. So number counter will be the name of the executable from the source folder. Number of counter, phi dot CPP, payment, target dependencies, or number of counter. We will add SCLC. Fun now because we just use SCLC BP in the node. And one thing we need to do, don't forget that, is to add a number counter right here. Okay. Installed targets, Number Publisher, and number counter in the liver of the install folder of your workspace. So let's compile. But instead of burning the Python package where we compile the cplusplus backstage. Ok. Let's suit under Alignment and let's cross to run. Rushed to have 3v. We number counter. And this works. We also, again here had a long and slow CPP in flow. This get logger and number of counter as being okay, that's running two cans and compiling it. And we have our C plus plus node which is ready for the following. 21. Write a Topic Publisher/Subscriber (Python): In this lesson, I'm going to show you how to work with rushed to topics in your OS, two nodes. So we will create a publisher inside the number publisher node. And we will create a subscriber inside name number counter node, exactly as we did in the ROS1 application. So the number publisher in ROS1 publishes on the number topic. And we'll be int 64, message from the STD, MSG S, ROS1 bike age. The number counter here will have a subscriber to this exact same topic, right? And in the callback function for the subscriber, we simply add the data to the counter and we print the data. But let's do that. So let's start with the publisher. Here in Ross, one. To create the publisher, you would do grows by that publisher. So again, you create everything from Ross pie in rows two, that will be different. We create the publisher right here. And to create the publisher, we will do. So. Let's create a viable First. Let's say. But to create a publisher, we won't call, are sealed by directly. Ok, we will create it from the node itself. Create publisher. Ok. You have a nice function you can use directly with self because you are inheriting from the node objects. So the first thing here you need to give is the message type, okay, not that topic, namely, the message type, what message we will use where it's tried to keep things simple, use the SME MSDS package. But does it exist in Rostow because this would be a different package rights. So here, if we do Ross to interface least, you can see the list of every interface. Let's do pipe, grape, STD, MSG s Just to filter those Tonga messages. And as you can see, the messages are here and those are the same messages. So one difference here that you already saw that we don't use Ross to MSG. Cross to SRP will list the services and messages. Here. We have a new name for those interfaces. Ok. So you will do Ross to interface, list, to list all messages and also services. So yes, there's tunnel message packages here. We use the exact same type in a rush to, as you can see. And one difference you can notice is in Roswell, you would have, for example, four bull here. You would have std, MHS, slash will directly. Here we have an additional namespace. Msg, okay. This is the new normal in rows two, you have the name of the package, then namespace, which could be, for example, MSG for message an SR, the service. We'll see more about that later. And then the name of the interface. So you could have a, let's say empty. We've MSG and an empty with s. Okay, the first will be a message, the second would be a service. So we can actually use the M64. But let's do that in Number Publisher. We will import from STV, MSG, S dot MSG, import int 64. Right? Now we can put the type and then name of the topic will be a number. And we need to give also a queue size. Just put ten as we are already dealing ROS1, okay? Though the queue size, if you are not too familiar with it, it's kind of a buffer. If some messages are late, you can keep them in a buffer. So then you can have time to process them. And I would put ten every time here for this application because, well, we don't publish at high frequencies, so now probably great. So we have our Felicia. Now whether we can do is to use this publisher to publish miss sage. So let's actually create a new function. Let's say publish number. And what are we going to do here? We're going to create a message and believed that message. Let's check the Ross one code. What we need to publish here. We create a message in 64. Then we have a data field in the message object that will be the same for the standard messages in rows two. And then we finally called the publish function on the publisher. But let's see how to do that for us to in number publisher. So we also create a message which will be int 64. Then MSG dot data, and let's say cellphone number. So that is the same for now and then self dot publish, dummy stage. So that is the exact same thing between ROS1 animals, too. Great. And what I'm going to do here, I'm going to remove the print number. That was just for the example. And instead of using print number in the number timer, I'm going to use publish number for the number timer we call the published number function every 0.5. sigmund and old topic here we publish four and at two hertz. Now I'm going to need number counter node. And here we're going to write the subscriber. So if we want to write the subscriber, I also needed to import from MS, MSG, import int 64, OK, I need to import the exact same message type. And let's see how we did it in Ross one. Here, number subscriber. We have grasped by load subscriber. So again, Roswell, you create everything from rest by directly. You have the name of the topic type and a callback function to process the message. Let's see how to do that in a rush to. So right here we are going to create, let's say number subscriber. So again, we don't create the subscriber from hassled by directly. We created from dynodes. We use self and you can use creates subscription. That function. We create a subscriber. And what you need to give also is first the type, but as different in Roswell, New felt given the topic name here you felt give the type and then the topic name, which would be number n. You also have to give a callback function. So let's, let's actually create the callback function here called back number. And we will receive missy. Okay, let's leave it like that so we can use it here, callback number. And one additional parameter you need to give is the queue size also. So let's keep ten. Okay, don't forget these. Okay. I'm going to do control shift and I on Viscoat, so I have the photo formatting. We have created D subscriber. And now, well, basically the way to handle Macy geez, subscriber callbacks is exactly the same between ROS1 and arrows too. Well, in Ross one, you would, in the callback number, you would simply access the field, for example, the data field with MSG dot data, while that is the same in Ross too, actually, I haven't created a counter here, self contour. Let's put it to 0. And let's say that counter, we increment the counter by the number inside MSG dot data. Actually plus equal. Though we added the data inside the counter. And now we're going to print, we've yet logger in folk as Tier. I truly counter. Still contact. Great, so you have a publisher and a subscriber. As you can see, the way to deal with publishers and subscribers in Python forest to is very similar than in Roswell and the concepts behind it is exactly the same, right? One thing we need to do now, because we are using this package, we need to go in package XML from the Python package we are using. Ok, and here you have already to depend to Hugs. We are going to infants. It's already here, right? Though. It's already here. We don't need to do anything else. Otherwise, you would need to add a new depend die. So either you can already specify the dependencies when you create a package or you can add them afterwards. And now let's go in the Ross to workspace directory. We're going to do coke unbuilt. We've packages select for us to have by. And I'm going to use also the single link install. Okay, so we don't need to combine those files again, and we will always keep those two file. So for the rest of this goes, I will not compile the Python package again. And let's rush assay to be sure we have everything set up. Ross to run. For us to wrap Python. Let's start the publisher. Publisher. Ok. And what I'm going to do here, I'm going to put that full screen had two terminals. So we have the number Alicia here. Let's do Ross to topic list. We have never rest to topic number. We can print what's published data every 0.5. sigma. What I can do is Ross to brown, rice to number counter. Okay? And you can see counter 4812, etcetera to counter is increasing every time there is. Value published from the publisher. Publisher has, you can see the counter tops. And if I start again, it will erosion the progress. So now you can use tools like accurately graph, for example. I will give you that. Okay, make sure you have those settings here. You can also refresh if you need to. You have the number topic. This one is the publisher, this is the subscriber, Greg. So as you can see, writing a publisher and subscriber in Rostow is really, really not that hard. If you already know how to do that in Ross run, the differences are very small. And one additional thing i want to show you right now, I talked to you about the standout messages package. And in fact, if you rose to interface doors to interface list, you can list the interfaces. If you do show, you can print what's inside one specific interface. So lets do STD, MSDS, MEG, and int 64. That is the message we've used. Okay, you can see in 64 data, that's what we use and there is a command here. This was originally provided as an example message. It is now deprecated, but it's still here, but deprecated. It's recommended not create your own semantically meaningful message. So if you were using STD MSG AS a lot in your Rossman program, I strongly suggest that from now on, you start to use your own custom message. Are you can use, for example, the messages from the sunset messages package, geometry, Mercedes, et cetera. But try not to use the STD MSG because those are deprecated and will eventually be removed in next Ross to version. If you want four examples to use, to still use the STD MSDS, you can use now the example MSG as all of the interface. Let's do that for us to interface list example. All of these tandem messages have been moved also to example interfaces package. As you can see here, we have simple interfaces with some of them are messages, none of them are services here. But if you really want to use standard messages in your code, maybe use example interfaces, but the best solution is to write your own custom message. And you may wonder why did they still use STD MSDS in that code, where I wanted to keep the exact same packages in both ways. And that will also be helpful in the next section when we walk on Ross one bridge, okay, you will see that later. 22. Write a Topic Publisher/Subscriber (C++): In this lesson, I'm going to show you how to work with Ross to topics in C plus plus. So make sure you've watched the previous video on topics with Python. Because now we're going to do the same thing with C Plus Plus. I will go a little bit quicker and not explain everything because some of the stuff is common between the two videos. So here we have our for us to absolutely package. Inside we have number counter and number publisher. The number publisher will publish number on the number of topic. And number counter will actually subscribe to this topic. Increment a counter plus print the counter. So let's see how we did it in Ross one. I'm going to go in the Number Publisher first. Okay. Here to create a publisher, we used another handle. Advertise with the type and the name of the publisher enqueue size. So that was very specific to ROS1 and simpler space, you hand it to create a rose and all the handle. And then every Ross to functionality would come from that not handled in Ross 2k because now we are using object oriented programming and because we are inheriting from node, you would simply use this. Okay? And one small additional note I will make here is, in fact you don't need to use this. Okay, you can just do that, create walled timer. But I will use this for rack-205e functionalities Just so it's clearer and it brings less confusion, right? So for example here, number, I don't use this, I could use this. But for roasting functionalities, I will use this. It's obvious and you won't make a mistake. So let's actually create a publisher here. We will create the publisher here in the constructor. And first, we of course need to declare it. Though. Let's declare it here in her private attributes, pencils, EBP, publisher. You need to give the type. So we want the type we need to include it here. Include STD, hemorrhage js slash MSG slash int X t4. And make sure you include the HP p5, right? And as you can see, I talked to you about the new additional namespace here in Ross warn you would simply have this plus this dot h. Now you have to have an additional namespace by your interface. So I'm going to use it here yesterday. And it's GS, MSG, int 64. But that is a publisher. But again, as I told you, we want use directly the object like that. We will use. Shared photos of the object. Number publisher. They'll Now we can initialize it here. Number publisher. And we will create it from the node. Look, these. Create publisher. Ok, we have a nice functional native directly included in the axial CVP node. We need to give the type again. Std, MSDS, miss sage in 64. And now we need to give two parameters. First one will be the name of the topic. Let's skip number. And sigma one will be cube size ten. Okay? And we have the publisher, the appeal. The main difference we've ROS1 again is that we don't create the publisher from the node handle. We create the publisher directly from the node. And let's see how we can actually create a message and publish MSAG. So I'm going to create a function here, Polish number. In this function I'm going to first create message. To create a messaging or OS2, You can use O2, MSG and STD, MSDS energy into 64. Ok. So you can use the O2, which is quite useful. Otherwise you would have to use that type. And that is the difference. Here. In ROS1, you would initialize your message like that inroads to it's like this. So now you can do MSG, that data, which will be the number we have. And then we have Number Publisher. And as this is a shared pointer, you need to use the curl, publish, publish, publish the Miss age. Okay, so that is quite similar to ROS1, but here in ROS1, you don't necessarily need to create a shared pointer. You can if you ask, but you don't need to. In two, you will have to do that. But we can remove the print member function here. We don't mean that anymore. Instead of using bringing them, I will use the Publish number. Though. That's it for the Polish aside. Now let's go to the subscriber side. And again, we will need to first include here, include stdio payments, GS, MSG, and in 64, HPV. As a private attribute, we can now create SEL CBP subscription. Okay? Don't write subscriber, It's subscription now. We have the type which is the same. And of course shared pointer because everything SharePoint or in rows two. And let's call it a subscriber. Or you could call it never subscription because this is a subscription object, but I will keep subscriber here. Now, you can initialize your subscriber arrived in the constructor. So let's do that. Number subscriber equals, and let's see what we did in harass one. So, Okay, let's see the non OOP version. Here. We used another handle, subscribe. We name this queue size and eco back. With object oriented programming, we would have the same thing but with a different syntax for the callback. And here for us to. Again, the first big difference is we don't need to know the handler or we don't directly use the ICL CVP. We use this because this is the axial CVP node that we insight. So these create subscription. We give the type MSG in 64 and we need to first topic name. And then AQ size. I will put ten here. Okay? And one of course parameter that we need to give now is the callback function. But let's create a callback function. I will create it in private. Callback number. Okay, and let's see again what we had in Ross. One callback number. We had danced with the type and then a reference, so constant reference to the message. And let's see how to do that in Ross to pin rose to you, we'd still have const may Sage. Well now you have also the intermediate namespace, but now it is not a reference to the message M. Now you will use shared pointer again. Ok? So what you get here is not constant reference is simply a shared point onto the message. Before we implement this callback, let's write it here. But what we will need to do, we will need to use STD bind, Okay, you've already seen STD binds just before. So first thing you need is to give reference to the function inside the class number control node, callback, oops, hunter node, callback number. With this. And you also need an additional parameter because we have one argument here. So you need to pad STD. Place holders. Scott one. So if this looks weird to you, well, don't worry too much. This will always be the same thing, okay? When you use a class and when you want to pass a callback function to another function u, we use SE divine reference to the class name or function name. This because this is for this object. And then if you need two parameters, arguments, you will use STD place holders. One, because we have one. If you have to, you will use also another here, STD placeholders. Okay? So what do we do in the callback function? Well, I will create a counter here because we don't have a contour yet. Initialized here to 0. And we simply do counter plus equal MSG. Though you need to use the arrow because this is a shared pointer data. We add the data to the counter and LCL CBP info. This yet logger. We counter. And we print the count her like that. You can use this function just as you use print f for example. And that should be eight. You have the publisher and the subscriber. Now, one thing we need to do is go to the package dot xml because we are using STD, MSG, s, Okay? And yeah, we've already added here when we create in the package. Otherwise you would need to add a new depend tied right here in the CMakeLists.txt will also have the STD MS JS right here. And we would need to actually change dependencies here because now the Number Publisher also depends on S, DDMS, JS, and number counter also depends on that package. We need to add those. If we don't add those, we will have an error when using coconut built. So you don't need to touch anything here. That should be eight. Let's see. Qualcomm will packages elect us to wrap UP. Okay? And now let's environments. We are sure that it should be OK for us to run. For us to app EBP. We will start the Number Publisher here. Okay, has been studied and Ross to run Python number counter. And we have a problem here. It is always 0. And the reason is, if you go back to the number deletion, reason is simply because I have initialized to 0. And of course, shoe, add many 0, it will still give you 0. So let's change it to three. Ok? Let's change it to three here. And let's build again. How is that the number of counter? Again, this doesn't change. And now I can start the publisher again. And you will see counter 36912, etcetera. 23. Create Custom Interfaces (Msg/Srv): In this lesson, you are going to learn how to create custom interfaces. So I will talk about interfaces here in rows two. In ROS1, you would talk about messages, services, et cetera. But now there is a common term for that, which is interface. Okay? So if I go to this package here, my robot, MSG s, That is the package that we will translate into Ross to. So first of all, I have named the package my robot MS-DOS, because usually when you create some code for a robot, you will name the package with the name of your robot, underscore MSDS for any custom message and service that you create for the robot in ROS1, okay? In that package you have CMakeLists.txt with some configuration package dot xml also with some configuration here. And then you can have MSG folder as diary folder, okay, for your custom messages and services. And here as you can see, I have one service which is the reset counter service. Let go step-by-step and create the occasion focused on messages and services in Ross to. So I'm going to go into the rows to workspace directory. And here we are going to create a new package. So rows to EKG Create and I will name the package. So my robot, because this is name of your robot, so just my robot for this course. And then instead of MSDS and we'll use interfaces. So that is the new conventional eros to when you have to create messages for your robot, you do my robot interfaces. Then I won't specify a build type, and I won't specify any dependency for now. If I create the package like that, by default, the build type would be payment estimate, just like a C Plus Plus Package. Okay? So we have a new package, my robot interfaces. What do we have inside? Well, as you can see, CMakeLists.txt, like H dot XML. So we see just a little bit later how to configure those. And we have include and source directory and we won't need them. So I'm going to remove included and I'm going to remove source. Alright, so let's configure the package first before we can create any customer interface. So we have CMakeLists.txt and package dot xml. Let's start with packaged dot XML. So in Ross one, you would have to add two additional tags, one for message generation and one for message runtime. Actually, those two don't exist anymore in rows. Two. This is a different configuration you need to add. And I have just written it here, so I'm going to copy and paste that. There is no point in just explaining that are just really front legs that you need to set up for your custom interfaces package and then you will forget about it, right? And anyway, you can download the complete code for the applications so you can have all of the configuration. So what did we add here? The bill depend tag, we've Ross ideal default generators execute depend with Ross ideal default runtime and member of group Ross ideal interface packages. As you can see, they all start with Ross ideal. And Ross ideal is basically tool in rows two to handle and generate your messages. So by K dot xml down, we have those three lines. You can now save, close it and never come back to it again. Cmakelist.txt. I am going to also remove that and tests. Ok. This what you need to have. I'm package, the name of the package will be Ross ideal default generators. We've required. So you need to find these package, so it needs to be installed, which is, is already installed when you install ROS two, okay? And then you will need to add this Ross ideal. Here. Generate interfaces with the project name, which is the package name. Okay? And here we will see just a little bit later, you will add every new interface you create. So three lines in packaged to XML and one additional find packaging semi-closed plus this structure to put your custom interfaces. I'm going to save that. And now the package is ready and we are going to add the reset counter service here. So what do we do here? I am still in the package. I will create a folder just like you did in ROS1. Okay, that doesn't change. If you want to create a custom MSG extra message, you will create MSG folder. Here. I'm only creating a service for this tutorial. And inside here I will create a counter that S RV. So this also doesn't change, okay? You have the reset counter that SRE, which will be the same thing or ROS1 anarobes to end the message definition, the service definition here with the request and the response separated by three dashes is the same. And I'm going to just paste it here. So we have our custom interface, which is a service here. Now we need to tell in the CMakeList.txt, we need to ask to actually build the message. Ok. But what did we do in Ross one in ROS1, as you can see, we had And that's why I let those commented lines here. We had message files for any MSG File, Add Service Files for any services, okay? And then you have generate messaging, etcetera. But, and you can see here, we would separate the message from the services in the CMakeList.txt here, we will simply do S because this is in the SRC folder slash reset counter that SRE. So basically we are just giving the bath to the face. And if you ever create an MSG folder here, then you will simply be able to do MSG slash. And let's say you may sage that MSG, okay. You can simply add all of the interfaces from your package here without any cholera between lines, okay, just one interface for one line. So here I just have one interface. And now when you create a new message or service, well, you just create the message and you just add one line here, and that's it. You don't have any configuration. To. The next step now is to compile. Let's go to our roster, workspace and coke on, grilled again by cages select. So we only compile my robot faces. And that can take some time when you first build some custom interfaces. Okay, great, so now we have one customer service and let's actually see it from the terminal. And here, this is very important. You need to source your workspace. So we have the source line in your budget assay to be able to access this interface, right? If I do Ross to interface list, let's say gripe with Mike robot. I will not have anything. If I do now source.bash assay, I can simply retyped command. And now I have my robot interfaces, SRB, reset counter. I can do Ross to interface, the name, our interface. And I can see the definition. So now that's it. You can use this interface into your own custom code. And one last thing I'm going to do for the following of this course, I'm going to setup VS code to use the custom interfaces we have. Because if you don't set it up, then you will have some arrows just in the ID when you try to import it. And you won't have the auto-completion. But first of all, I'm going to do the VS code. We already created this file before. So if you are using VS Code, please follow along. Here we have this line slash puppet eros, foxy include. I'm going to add a new line, which will be Ross to workspace. So the path to the workspace installed my robot in the faces. She include, OK. So we're going to include the include folder from the microbial interfaces package inside installed folder of our workspace. So now we can import the custom service in our simplest possible and we won't have any warning in VS Viscoat. Now, I will need to do the same for Python. This time, I will go to File preferences, settings. And Python path can type Python path here. And here, Python autocomplete extra path edit in settings.js. Now now you can add the Python path for door, my herbal interfaces by Cage. And actually, ok, we will need to find it. So let's go to the install folder. My robot interfaces, the Python 3.8. And you are sites like EEGs. And again, my robot interfaces. Ok, and here as you can see, we have the interfaces here and some stuff that was generated. So you can use your custom messages and services with Python. So just go to this path, okay, and just copy, copy this, copy this, and just paste it inside the Python autocomplete extra path. And you can do that for every new messages that you create in different packages. Usually you will have only one package for audio interfaces. But if you happen to BOT interfaces in different packages, then make sure you had a newline here. So the VS code can find it. When you write on Python code. 24. Write a Service (Python): In this lesson, I'm going to show you how to work with services in for us to the concept behind ROS1 services and Ross to services is the same in these way, you need a client-server architecture. Ok, so as you already know, what is a roast weren't service. I'm just going to show you how to implement one in eros to, and well, let's get started. So in Ross one here we had a, Let's start with Python for this one. And in the number counter we have, and we actually use the OOP number counter. We have here a service, okay? So we used the service here to actually reset the counter from the outside. We can ask to reset the counter. Here we create a service, we have a callback. In the callback, we have the request, okay? And we've written a value that is the response. Now let's do that in Ross T2. I'm going to D never counter here. Again, though. Let's create the service right here in the constructor. So let's name it, raise it. Counter. That is, okay. And again, to create the service, what we'll do is self. And we have create nervous right here in the node functionality. So that is again the first difference in Ross. One. You would simply do Ross pilot service and rush to reduce self-create service inside the node class. And then you need to give first the service type. So the service type we will need to import it from my robot interfaces. That SRE import, raise it counter. Okay, and if you don't have the autocompletion here and you are using VS code. Make sure you watch the end of the previous lecture. And also make sure you, you under unmount and maybe restarting the VS code. So I'm going to specify here, or is it counter? Then we need service name. So let's call it. Where is it counter, this is quite explicit. And a callback. So let's add a callback here. Callback. Or is it counter? Though in Ross war? And ROS1 in the callback, you have simply the request. In Ross too, you have regressed, and you also have the response, ok, so you already have the response object and you will need to fill that object. And let's pass it here itself and call back contact. Okay, a little bit of auto formatting. So the service is now created and up. And when the node is spinning, you can call the seller and the call back will be called. So now let's see what we can do in a callback. So what we have to do here, if the value is greater than 0, then we can actually reach it the counter to the volume, print a log, and set the response to true. Otherwise we simply set the response to false. Okay, so let's, let's do, let's do that. If request that present value is greater than 0, then we will say that counter is equal to request. But reset value. We print counter. So let's copy this line here. Okay, and then we need to fill the response. So in Roswell, you would directly written the response. This is specific to Python, right? You would directly written the response. So here the response is only one Boolean. You will return true or false. Here what we are going to do is to do price bonds. So that what let's see in my robot interfaces. So we have the result value and we have success. So response.body access. When we true, true. And if not, then responds that success will be bots. And at the end of the call back, this is very important. You will return the response, ok. So you always need to finish your callbacks for Ross to services in Python. We've written response, the same response that you got from there. If you don't do that, you will have a runtime error when you call this service actually. And one thing you need also to do once you have finished written code is that actually you're using my robot interfaces, which is a new package for eros to apply package. So you need to go in package dot XML right here. And we already have to depend tags. You're going to add a new one. Depend with my robot interfaces dependence. So to make sure that this package depends on my robot interfaces, so it will not be built before. So that's it. That's quite simple to do. If you understood how to handle arose once services, then you won't have any problem. We've Ross to services here. We don't need to do anything here. The setup is correct. But what we can do is simply so you can build your package. Again, Bert, as I used signaling installed and I didn't change the option for the Python package. I'm just going to source. Bash Pasi here so I can get the interfaces. And I'm going to do Ross to run for us to app. Pie and number counter. Counter node has been started. In fact, I will also start the rows to soap those flash policy process to run. And we start the publisher and the publisher. Kay, here. And let's make sure we have the message is here for us to service lists. Okay. Rose to service list will give you many VCs because you have at least six services for every new node, okay? Which can deal with parameters. And then you can see we have the reset counter service here, refers to service. You press Tab twice. You can see you can use type to get the type of the reset counter service. And then you have the interface, and then you can do Ross to interface show editor. But we're going to call the service rose to call reset counter. Then we're going to give the message types. So my Empress tab here, my robot interfaces for Saudi Arabia to counter. And we need to give the request. To give the request, I'm going to use the syntax. You can put curly brackets and read that value, two points. And let's put, let's put too. So look at this window here. Ok, so it works when the service has been called, the counter has been reads it to two. And we have the response here, success equals true. Or if I studied again, here we can change the value, will reset the counter. I can read it to 0. And OK. And if I try to put a negative value, for example, minus five, we will have the problem. The control with not resent and success is false. Because that is what we have defined here. That is what we have defined in the application. 25. Write a Service (C++): Let's now create a roster service. We've c plus plus. So we will do the same thing we did for Python in a previous lecture. Ok, but only this time in C plus plus. And let's first check the Ross went up CBP package. In number counter. We have, let's use the OOP NMR counter. But we have the research service here. As you can see, another handle, advertised service. So again, this is from the node handle. And then we have the callback function here with the request in bonds. So let's see how to grad. I'm going to the number counter. Ok, let's keep that here. Number counter. And we are going to create the service right here. So I first need to declare the service, seal UP service, which will be of type. Well, we need to intuit first. Include my robot facing slash MSG. No, SIR. Flash, reset, counter dot h. I can use it here. My robot interfaces or is it contact? That is the type of the service. As you can see, we have raised counter requests and reset counter response. And again, JL pointer because everything is a SharePoint or in rows two and raise it counter service. So now we're going to initialize it here. Visit counter this. And again, this, create these type. My robot faces, SRE, reset, contact. Now we can give parameters. The first parameter will be the name of the service, which is counter. Okay, let's actually put that on a new line, or is it counter? And then the second parameter will be the callback function. Okay? Let's create a callback function. I will put it in private here. Callback, raise it counter. So in Ross, one, in ROS1, in the callback, you have a reference to the request and the restaurants to arrest bonds in rows two. That will be just a little bit different. This would be like when you have a callback for a topic, ok, you have a constant. And then the type robot interfaces as carving, raise it. And then you go further. After a rigid container, you have requests and you have shared pointer, which will be the request. So that is quite long, but actually this is name of the package, so that is another namespace. Then SRB for services, the name of the service, the request and shared pointer. And we have another parameter, which is also my robot interfaces. Or is it counter. This time it will be the response. Also we've shared pointer and response here. Okay? So the way to do that is pretty similar between the callback for topics and the callback for services. Now I can create the function. Okay? So before implementing this function, we are going to but callback here. So guess what? We're going to use STD, bind STD. We've first parameter will be a reference to number one turn, no fallback for is it counter these. And then because we have two parameters for the function, we need to add STD placeholders one and STD placeholders to. And actually what I'm going to do because these will become quite long. I will do using STD place. Although one here, ten using STD place holders to that is something you can do so your code becomes less long, so yeah, I can remove that. And I can simply add one underscore, one underscore two here, say OK. And now the Greys at contact service is ready. We can implement the callback function. Though in Ross one. In the callback function, well, you would take the value, any value from the request, okay? We've Reich dot value. And then you would have to fill the response, ok, we the field that you need. And finally, you would return true or false here, because you need to return a boolean. Boolean here is simply to say that the callback went well, and then the response will be returned to the client. Here. We don't need to provide any thing. Okay. We don't need to return anything. You will just need to update the response and you won't need to return the response ok, the response will already be filled here. This is the shared pointer. So what you will do is simply this function will give you the pointer to a response. You update the resonance and then the response will be sent back to the grant. So let's start if request. So you need to use an arrow request dot reset value is greater than 0. We can do counter will be request, raise it. We will also print the new value for the counter with this line which I just copy and paste. And then praise bones, the role success will be true. I can now put else, if value is negative, response success, faults. Okay? And 60 Hz here is simply in the field that we need to fill here, ok. It is not related to the success of the callback. This is just at the application level, ok, it's what you defined for the application. So let's go back here. It seems that the service is now ready. So you have here initialization and the callback. And one more thing we need to do now is that because we are using my robot interfaces package, we need to include it in the package that XML. So we need to add a new depend time. My robot faces depend. Okay, we can save it. We need to go to CMake list that TXT added here. Find package, my robot. And the faces we've required. Ok, and because we are using it in the number counter, we also need to add it. Yeah, we've payment, target dependencies and number counter. You don't need to add it in number publisher because you don't use it in number of dotage. Okay, so we're going to save the file. And now I'm going back to al-Qaeda continuous till here from last time. I'm going to the rows to workspace, cocoa. Build packages select for us to have. Okay, so no problem during the compilation. And actually I can just clean that. Now. If you open a new terminal, Well, if you're gonna New Terminal, everything will be source. Here. I use an already existing works and I'm going to associate because I'm using my own custom messages. And let's do Ross to run. Well, actually, let's start. The counter here. Was to was to app UP. And I can launch the, okay, let's learn about the Python publisher anyway. Because I cannot do Python one plus, plus one is the same. Great. So we have the counter here. If I do here, I do cross two lists. I also have the reset counter, and I can do here cross to service call. This is from the previous video with Python, richard counter, my robot interfaces. So the type and then the requests written like that. Let's see what happens. And the counter has been related to trick. We have success. If Piper minus three, then we have success false because the application we decided we should give a number which is positive. Great, so you can now create your own Ross to services in Python and C plus plus. 26. Remapping in ROS2: There is one more thing I want to show you here after working with nodes, topics and services is how to actually rename them at runtime. So in Ross, one, you can rename a node, a topic, our service when you start the snowed topic or service, well, in Ross too, you can also rename though. So let's, let's see with some examples. So I'm going to start bras to run, let's say your OS to app by. And remember, I'm going to start in number bullish unknown. Though Number Publisher has been studied for us to node list, C Number Publisher and rose to be pleased, I can see the number topic. Now I'm going to rename that. So I will do the same and then I add dash, dash, cross this so you can add any number of arguments we've Ross to. First, you need to add this dash, dash, dash, and then I'm going to use dash, dash remap, okay? And well, you can either use dash, dash, remap are simply dash. Are those two same? So from now on, we'll only use that high. So to rename the node, you can do underscore, underscore node like that and given new value to the node, let's say another name. Okay? So as you can see in the log here, we can already see that the node name has changed to another name. And if we do Ross to node list, we have another name here. And I'm going to also add another dash R. And this time I'm going to rename the topic. So how to rename the topic simply the name. And let's see another topic. And now let's see cross to topic list. We have another topic instead of number, okay? The topic has just been renamed. So to recap here, first, dash, dash, dash. And then you can add any number of arguments you want. So here for example, you have dash are arguments to rename something. You can rename a node. These are, you can rename any number of topics, services simply by putting the name and when the name is matched, when the name is found, then it will be renamed tho. Now let's see what happens with the counter or us to around minus two up. Let's launch the symbolist plus one, for example. And remember counter. As you can see, we don't get anything here because so the publisher is running, but now he's publishing on the, another topic, topic, not on the topic. So we're going to fix that with Ross. Dash. And number will be another topic. And now it should work. Yes. I can see here we have rows to service, list. Read at counter. So same thing if you want, you can also read counters. I'm going to add another dash. It because the rows are exists already here. No need to put it twice. And where is it? Counter will become just another service name. Okay, if I do that, I have another service name. So the node here is another name and the service, another service name. So if you want to call this service, you need to call the another service name service. Okay, so as you can see, that's not so difficult. You can rename at runtime in the terminal, any node, topic, any service you want. And in the following of this course, we will also see how you can rename those inside a lunch failure. 27. ROS2 Parameters - What Has Changed?: As you could previously, so many has the raw score concepts are quite the same between rows one and rows two, but four parameters, there are quite a few big differences. Here is what doesn't change. First, parameters allow you to set values at runtime for your nodes. So you can launch them with different settings every time without having to modify the code. As you can see, the purpose of parameters is the same for us, one in rows two. Now, let's see how you will actually use them. And that is where it's completely different. As a quick reminder, for ROS1, first, you would start a Ross master, and as soon as you start to do your OS muster, the parameter server will be created and will stay alive as long as the Ross Master is alive. Inside these parameter server, you can set some parameters and those parameters are global to the application. Any node that you start can retrieve any parameter. And if a kid a node will, the parameters are still here in the parameter server. So what about Ross to? First of all, in Ross too, you don't have arrows Master anymore. This is a distributed system. Each node is completely independent. And that also means that if you don't have arrows master, you also don't have a parameter seller. So where the parameters hosted well, the parameters in Ross to directly hosted inside the nodes. And they only exist why the Node exists. So if you start a node with some parameters and then you kill the node and all the parameters values for this node. So in Ross to the parameters are nested inside the nodes instead of being global to all node. Here is an example with a camera driver node. For this node, we have declared three parameters. The USB device name, frame based systems, and whether the node is running in simulation mode on it. Now let's say you want to run to camera driver nodes. You start camera driver one. We've some values for the parameters. And then you start camera driver to weave a different set of values. So here the parameters for camera driver one fragment will only exist within the camera driver one node. And if you kill that node, the parameters are gone. And so you will not set the parameters before you started the node. You will set the parameters at the same time you start to note, okay? Alright, that's about it for now. To conclude on Ross two parameters. Here is what you will have to do to work with them. First, when you write a node, you will have to declare what parameters are accepted for this node. Then you will be able to get the parameters values like in ROS1. And then you can use the values in your node. When you start at the node, you will provide the value at runtime, okay? Not before. And any parameter that you've declared within your Node will be accepted. If the declaration thing doesn't make sense for you now, well, don't worry because we're just going to see how to do that just now. 28. Declare Your Parameters (Python/C++): In this lesson, you're going to learn how to work with rows two parameters. And first, how to declare your parameters, both for Python and C plus plus is there as narrowly difference between both. And so first, we will focus on actually what is this declaration thing in how to deal with that. So first of all, we're going to stay in the terminal and we are going to run two nodes. Whereas to run was to have Python one. Number pollution. Okay? And here, for example, for us to run was to PAP, remember counter. So we just simply launched the two nodes like that. And in this terminal, let's do Ross to paran. Ok, so in Roswell and you would have crossbar inroads to you simply have bras to base. All right, and then list. Ok. And as you can see, I may have to do that times because I guess there is a bug somewhere in the Ross two-parameter command line tool, okay, sometimes it will not show you every bomb, so you may have to run it multiple times, okay? But this is just a command line tool, okay? It's not really important. Here you can see I have two parameters. And what is that? Well, if I do Ross to node leased, I have an accountant node and Number Publisher. And as you can see here, when we do Ross to parameter list, we have the list of node, okay, number counter on Number Publisher. And under each node we have the parameters for that node. Ok, so as you can see, we have one parameter, you use SIM time, which is only found on the counter, and one parameter using time only for Number Publisher, okay, so the parameters are within the nodes. They are not global. Okay? So now if I kill the counter, and if I do cross two parameter lists, I will only have number publisher. We've use syntax that's used in time here has disappeared. It's not the label anymore because we have killed the node which was hosting this baryon. Okay, so here you can clearly see that parameters only exist within a node. And now I'm going to stay with this number publisher. I can do Ross to Baran get. Then I will put the name of the node number publisher, and then I will put the name of the parameter, use him. And I will get boolean value is false, so we know this is a Boolean and the value is actually false. Okay, let's start the number publisher again. And this time we are going to set a value. How to set the value? Well, first, I'm going to do Ross arcs and you already saw that command when we used some remapping for nodes that peaks and services. Okay? So if you want to use any of the arguments, okay, we see features to you have to first but Ross, args and then far remapping, we used dash r parameter. We will use dash as simple as that. So I'm going to use in time and let's put the value to true. Okay? So I'm going to, so if I do Ross to Brom list, the parameter will still be here. And if a GET parameter now the Booleans are you is true. So here, as you can see, we have a big difference. We bras when in Roswell you would first need to start a Rostow. Who started Ross master. Then you would need to set your parameters, okay? Then you start your note here in Ross to use dubbed the node and you set the parameter and the same thing. And this is how you can set a barometer in the terminal we've Ross to run. So now why do we have using time here? Because while it was declared from within the node, okay? Now I'm just trained to, okay, and we'd keep your SIM time. And now I can use dash P two set another parameter. Let's use. So let's go back to the rice weren't application to see what parameters we have from the militia. We have the number of Polish frequency and number to publish. I'm going to start with number to publish. I'm going to set number to publish and I'm going to set to four. Okay, So this is walking. We don't have any error. And if I do rush to earn list, well, we still have time, but we don't have number to publish. And if I try to do the rush to get and then the publisher. We're number two. Leash around maternal set, okay, we don't have any parameter that we set it here. But what's the problem here? And the answer is, you have to declare the parameter from within the node. Ok, so we are going to go in the Ross to app package in the Number Publisher. And we are going to declare parameters at the very beginning of the constructor here, just after the Super. To initialize the note and to develop a thermometer. And you simply have to do cells. Declare parameter and the name of the parameter. So let's say number to publish. I can save. And now let's go back to the terminal. So I previously have built the Python package with Simulink install options, so I don't need to compile it again. So now I'm going to run it. Wrong thing. And when they do arise to parameter list, I have to do it again. I have number who publish. Great. Though the number to publish is here. Why is it here? Because we have used self-declared parameter, okay? And now we can also get these parameter value will be four K If I just start the node without setting the value, well, no problem, it still works. We still have we still have number two Polish, okay. As soon as you declare a perimeter here, it will be on the list. Came, but now if I get it, I will have parameter not set. Okay? So you have two stages for one parameter. First you declare it. It is like in C plus, plus, it is declared, but it is not initialized. There is no value in it. And then you set a value at runtime. So what this means now for you when you develop is that every parameter you want to use in a node, you need to declare it like that. So I'm going to also declare itself. Declare parameter and number, the leash frequency. I am going to run the load again. Actually, I will not use SIM time. Just random node like that. Ok, and rose to around lists would give us great node. We have used SIM dime, which will be here for all of your nodes, okay? And then we have number to publish and publish frequency. Number Polish frequency also will be onsets. So what we need to do now, we need to do Ross. Dash b. Number two, the list. There is no specific order. Let's put five and number. The leash frequency. Let's put 3.4. Okay? Well, we have neuron because of course you need to provide dash peak. Every barometer you need to add a new dash b, cross ads only once, but dash b for every new parameter. Grape hasn't studied. Now, I can do Rose too. Foreign gets number to publish, which would be five, and number publish frequency, which will be 3.4. Okay, so fauna, we don't use parameters in decoders, which we'll see in the next lesson. And as you can see here, we have integer value, double value. We've seen time, we had Boolean value for a parameter will be set, also had around time. Ok? So if I decide to do hello like that, if I get the perimeter string value, okay? So pay attention to the type you put when you set a parameter, because that will be the type of the parameter and your code. And what types can you use? Well, quite simple, it's very similar to Ross one. You can use booleans, integers, doubles, strings, and you can use arrays of those types also. So, well, that's it for Python, okay? If you need to use a thermometer, first you declare it at the beginning of your constructor. And then let's go to PSI-BLAST very quickly because that will be exact same. In the publisher. You are going to the number pollution node constructor. And you're going to do this. Declare parameter. Okay, number to publish these nuclear parameter number, publish frequency. Save the file. I'm going to compile again. So two, cross two Workspace. Welcome willed. Qgis. Elect. We've Ross took Okay. Great. And now I'm going to rush to run, rush to CPP Number, Publisher grade. And now let's see, rows two. Parameter lists will give us number pollution known. With those parameters we have just declared within the node. Okay? If you try to get those parameters, you will get parameter not set, okay? So you need to set a value at runtime like we just did previously here to set the value. And now how to actually use that value inside your code. That's what we'll see just in the next lesson. 29. Get Parameters From Your Code (Python): In this lesson, I'm going to show you how to actually use the parameters that you set inside your code. Okay, so farmer, you've seen that step one is to declare any parameter you want to use. At the beginning of your note. Once the perimeter is declared, you can actually set a value at runtime. So when you start the node, you will actually like here, where you start the node, you will actually add some parameters, values, okay? And then the parameters will be declared plus set. So now what you can do is you can get the value directly from the node. So let's do that. First. We are going to get that number here. So the number we are going to publish, we are going to get it from the parameters. And as you can see in Ross, wonderful. Go back to ROS1 and the publisher. The what did we do here? Number rows by the name of the parameter. Ok, so again in ROS1, you would use directly get brown from Ross Bye. In Ross tool, you will use the class. You will use self to actually get the parameters. So self get parameter. Okay, so that is very similar to ROS1, just the differences. You use self instead of Ross pi. And let's say number to publish. And as long as the name here you declare and named Gate is the same, then you will be able to retrieve that perimeter. Though. When you do that GET parameter, you will have, you don't have a value, you will have a parameter objects, okay? If you just set the parameter object in the number, then you would have an error here because you would try to set a object inside an integer. So you need to get the value. And to get the value, you simply do dot value. That's it. Don't put any parentheses here, okay? This is just an attribute of the parameter object, okay? And well, that's it for the number. And now I'm going to do self publish reconceive, agreeing to create a published frequency which will be get parameter number of Jewish frequency, that value without any parenthesis. And where am I going to use the low-frequency? Well, here we have a timer and here we need to give a period, okay? So the period is the inverse frequency. So what I'm going to do is simply one divided by the publish regular C. Okay? So let's say I put two here, which means two hertz, one divided by two. We have 0.5. so the timer will trigger the callback every. 0.5. Sigmund. I'm going to do some auto formatting here. Okay, I don't know if I killed that note. I'm going to run, okay, I'm going to run D Number Publisher Node, Python one with some correct value. Let's put three. Okay, so I'm going to polish number five at 300 K. Now if I do Ross to peek, equal number, okay, we have data type which is directly what we get from the number to publish perimeter and published frequency is three. If you want to check that you can actually do Ross to pick H, z, four heads. And remember, this will listen to a topic. And you can see a rate, rate at great. And now what happens if I don't set this parameter, for example? Well, we will have an arrow, of course, because when we actually here, when we actually want to use the self-published frequency, if we don't set the parameter value, so the perimeter is declared right? But it is not set. So if we don't set a parameter, then the value will be known. Ok? This is NoneType, though. You will have errors in your code if you don't set parameters. Where you can do is to set a default value. And to set the default value, you can directly put it when you declare the parameter as a signal arguments in a function here. So for example, I want to push to as in the full value here. And let's put one hertz. Which means that if I don't set the parameter value at runtime, this value will be used. Ok? If I set the parameter at runtime, the new value I said will be used. So if I, again, now it's working. So I'm going to Russ to topic number and we will have the result. The rate is one. Ok? Exactly what we said in the declare parameters with the default value. And if I do grass to, to pick Ico, we can still see we have five. We don't have to, which is different very we have five because we set the parameter at read time. And I'm just going to show you. Ok, let's say you don't. Let's say you forget to declare a parameter and then you try to get parameter here which is not declared before. What will happen? You will get this arrow SEL by exception parameter not declared exception. Okay, so if you get that, it means you probably have forgotten to declare a parameter. 30. Get Parameters From Your Code (C++): Great, so now let's go to cplusplus, which will be really the same. I'm going to number publisher that CVP we already have declare parameter. Then thing here, we can set a default value like two and warn pointer or so that is really the same thing. Now I can get number. So instead of setting number here, I'm going to remove that. And I'm going to say number equals this get parameter. I can say number to publish. Again, make sure this is the same, but you, so again here you don't get the value directly. You get a parameter objects. And as you also previously. So when you set a parameter at runtime, here you can see the type is also set at runtime. So in fact, when you get the perimeter, you don't necessarily know what type it is in C plus plus. So you have to cast the parameter to a type, okay? Because in C plus plus you have to use types, not like in Python. Python you can use dynamic types in C plus plus, you can't. So you have some nice functionalities here. You just do dot under Get parameter. And you can guessed the parameter as a Boolean double integer string in any of the array of those types. Okay? So what that is, we'll double string, etc. And here we will need actually number is int as int. Okay? Which means that now the number will actually so least we expect the number to polish to be an integer. When you set the barometer, you have to set integer, otherwise it will not work. And then I'm going to use, let's say double the leash frequency, which will be get parameter number, publish frequency. And this will be as double. Okay, great, so now I have my number which is already and I actually need to use the published frequency here on the timer. So here the timer expects to have a STD chrono duration, and you can only put integers here. So what are we going to do? Actually, I'm going to use a merely syndromes here. Okay. So stick with me for that. And actually to get a burial from the frequency you need two inverse that pregnancies. So let's say publish pregnancy. Okay? So that will be a double. So I'm going to need to cast this as an integer after the operation n Because we have milliseconds and we need to multiply the result by 10000. Okay? Though we knew one divided by the frequency, which gives us a time period in milliseconds in double. And then we cast an integer for the STD kroner. Okay, let's try it. So let's do coke on wheels. I think I have it here. Yes. Glucagon will just select for us to AB CVP. So now if I just start the node because I have some default values, you don't have me era. If no pie set, let's say ross. I will just say number published. Right? You can see that will be 5.6. If I do Rostow PQ equal number. Okay? You can see we have data to two because this is the default value because we didn't set the parameter at runtime. And rose to topic heads will give us the rate rate 5.6 hertz. Great. And finally, I showed you the error in Python. So let's show you the Euro and siblings plus, let's say you forget to declare this parameter and then you try to get the perimeter of your code. What will happen? So I'm going to build again. So the error will be simply exemption SCLC, PB exception parameter, not declare exception. So actually that the same exception but from SCLC 3p instead of LCL pi. Ok, so if you have this error is because you forgot to do that. Okay, great. So now you know how to declare your parameters, how to set the values at runtime in the terminal, and how to actually use them from your code. 31. Create a Launch File: In this lesson, you are going to see how to create launch file in Ross too. So finally, you can start all your application at once in a single file. Okay, so that is how we did it in Ross one. So we have my robot bring a bug age. And inside we have so CMake list and package that XML. We have a launch folder and inside these lunch folder we have a dot launch pile, which is an XML file. Okay? So in this file, you would start your different nodes like that. So here I have the Python version, C Plus Plus version that you can, you can uncomment this and common this will to just launch one on the other. And as you can see here, we have the parameters which are set before we actually set the nodes. So yeah, this is a pretty typical ROS1 lunch, fine. And now we're going to do that in rows two. And as you will see, there are quite a few differences. First, because we will not use XML, but we will use Python. So first thing first, let's create a package ok, or hosting the launch files we will have. So we are going to go in our roast workspace in the source directory. And let's do for us to EKG create. And we can also call it my robot. Bring up. So that is a convention that you will often see the name of your robot endoscopy and bring them, bring up basically just to bring up every part of your robots. You can have multiple launch phase here, configuration files, et cetera. And I will not specify any build type, okay? This would be Amundsen make by default, and I won't specify any dependency here. And let's go inside my robot. Bring up. So again, we have this structure where we keep the CMakeLists.txt and we will keep the package dot xml. And we're going to remove include and we're going to remove the source and also create a launch older. So far this is pretty similar to what we did in raw Swan. Now inside this lunch folder, I'm going to create the launch fire. So hungering too. Okay. Ros1, launch file was maimed. Number up dot launched. So we had to have the launch extension. But here we are going to start a Python file. So what we can do is we can do number app, launch dots by, okay, so only the Dutch by we already count as the extension. So basically we can yet but in the name of your lunch file, dot launch, and then that also you can make it executable. And here you have the lunch right? Now let's go to the Visual Studio code again. And here we have our package with the lunchtime. First, we are going to configure this package okay, before we do anything else. So in CMakeList.txt, okay, I'm just going to remove that and then remove that as we did before. So it is just minimal package. And we will need to do one thing. We need to install the launch of, okay, if we don't install the launch folder here in the CMakeLists.txt, then simply you won't be able to use your lunchtime. So install. We are going to use directory. So we've nodes, we used targets and, but every Hezekiah table here, we are going to use directories. So which means that all the directory will be installed. So directory, we are going to put the launch directory. Okay? We'll make sure you have named it launch here. And destination will be Share Project Name. Okay? And for package dot xml fauna, we don't need to add anything. But we will come back to this later after we have written our lunch, right? So let's go to the launch fire. So how to write a lunch fight in rows two? Well, you have to follow a very specific structure, okay? The lunch file, actually, you need to create a function name, generate lounge description. So you have to have this exact function here. And then you can include from lounge import launch description. You are going to generate a lounge description and you import a launch description here from launch, which was installed with respect to what you can do here, let's create object launch description. And you are going to return the launch description objects. So that is the minimal code you need for a launch by. You create a generate launch description function. And you return a launch description objects in between those two lines. So this will be the first line. This will be the last line in between that you will simply put your nodes, perimeters, etc. So let's first save it. And let's first see how we can simply run it. So let's go to our workspace and we are going to need to install the coke on build. Like judges select my robot. Bring up. So you're going to need to install the my robot bringing up if you want to use your lunchtime. And I am going to SaaS environment because this domino doesn't know the mayor would bring a backyard yet for us to launch. Ok, so in ROS1 you would have lunch inroads to roast for launch. Then name of the package, my robot. Bring up. I press Tab twice. And you can see here number up that launch dot-dot-dot. So well, you can see you have the blogs for lunch files and it worked. Nothing happens. But it worked because we haven't set any nodes. Of course it will return immediately, right? So now let's actually add some note though, in the ROS1 lunch phi, we added the publisher and the number counter, and that we've named package type, output, etc. But here, this is Python we are going to use from launch ros dot actions in court. No. Okay. So there is nothing to understand here. You just need to add this line it from lunch, ros dot actions, imports node. So you can actually create a node. So number publisher, load will be node object. Ok. And as you can see, you have many arguments that are labeled for this node objects. And the minimal thing we need to give at least package by Cage is Ross to, let's start with Python one. Then you add a comma and executable, which will be Number Publisher. And before we actually run it, we need to add it to the launch description. So I'll description, add action, number pollution node. And just one more thing to set up because we are actually using the rows to up by package. And we need that from my robot bring up. What we can do is good to package that XML of my Orwell bring up. And here as a real tool depend, I will add a new tied exec depend. Ok, just to say that we need the eros to app package at execution time. To app by exec depend. Okay, and I saved the package dot XML. Okay, so let's run it. Okay. As you can see, we have Number Publisher here. Number Publisher has been static, so the number publisher node is running right here. And if I press Control-C, then I will kill everything in the large fire. So a very quick recap for now you create a launch description function. You create a launch description object, and then you create a node. With the launch frost action Node object. You provide the package executable and don't forget to add action and use the add action on the launch destruction to add the node. Finally return the long description and then you compile the package. And you can launch your lunch, right? So now let's add the number node. That will be the same. By Cage was to have python executable, which will be number counter. And of course we need to add, add action here. Come to known. We. So this may seem quite difficult at first, but once you understand, as you can see, adding a node is, well, you just add the same structure and action and that's it. Okay. Now we have, great. We have the counter and the publisher running here on the lunch line. And as you can see, we have the logos from the number counter. Okay, and here is where it's great. For example, if I want to start from the Ross to cap UVB, okay, I'm just going to add this lining command here. So in this case, I have made the executing will name the exact same for Python. And so if I just change the package name, then I will be able to start the application. And now just one last thing, like we did for the Ross to up by package, as we are now using the Ross 2ab Sibley package, then it's a good idea to go to package that XML of my robot, bring an end to ad. Exec depend tag arose to tap. So I saved a fight and they close it. Okay, so now I'm starting the cplusplus application. And will we have an arrow? Because Yes, because I have, in fact, in the previous lecture on parameters, where is it? Here? I have put this in. A comment, will show you the era when it is not declared. So as you can see when you start a lunch by, you will still see all of the arrows from logs. And actually what they need to do is to compile was to have MPP again. And now if I start the lunch menu again, then it works. Great. So well, that's it for the lunch five. Now, I'm going to show you a few different things you can do to actually put more features into that lunch, right? So first of all, we have seen in a previous lesson how to actually re-map node are remap a topic ourselves, okay? So you can do that in the terminal with the Dutch auction. You can also do that in a launch phi, which will be quite more practical. So first, if you want to rename the node, you simply have to add name here. So we have Number Publisher, let's see, we want my number. Okay, and let's say we want it to be name. My number cutter can save, and these will actually make the two nodes, okay, you can see my number pollution here and my number counter. So great. We have just set a new name for the load. And now I want to change the number topic. I want to name it with a different name, so we want to use name here. We will add re mappings. And re mappings will be an array of tuples. So you have to have tuples like that. First, you will put the name you want to change. So here it will be number for the number topic and then the new name for my OK, let's use my number here, so I save it. And this will rename the number two piglets. Try. So we can see the result is that of course the counter doesn't print anything because now for us to, to pick lists. Because the publisher is publishing on my number and the counter notice subscribing to the number topic which are not the same. So what we can do is we can also add here remapping array of tables and use number, my number. Okay? And let's try again. And it works because the nodes are synchronized on minor topic. Right? So here, as you can see, I have the same tuple right here. What I can do also is similar. We create a variable remap topic, which will be the stable. So I'm just creating a tuple on the side. And now I'm just putting this here. And I saved. Okay, so that is very powerful thing to do, okay, with Python. You can really, you can just use Python as you want to make the ranch files very dynamic. Yeah, if I change the name here, it will be changed in that's remaining and in that remapping here. And actually I can also add other remote beings if I want. Ok. So let's say I want to modify resists, counter the service to. Okay, let's continue with my, my results. I save it and let's see what it does. Now. I have cross to service, list, my revisit counter gray. So you have renamed node. And then we have remapping. You can reading topics, services, et cetera. Okay, and one last thing I want to show you here is how to add actually Parameters. Who a node. So to add parameters, I'm going to add the two parameters we have funded number pollution rule. You're going to add here parameters. And this will be also an array, but this time it will be an array of dictionary, okay? Make sure you don't make things up. Or remapping. You use labels and four parameters. You use dictionaries. So I first put the name of the parameter number to publish, and then I built the value, let say four. And I can separate the different parameters like that we pay, come up, publish, pregnancy. Let's use five. Okay? That will sit two parameters values at runtime final node. So now I'm going to do one final try here and start duplication. And as you can see, we have four published at five hertz right here because the contour is updated really quickly. Great. So now you can use launched files, will your roster applications, and actually deliver customization. You can add your lunch Phi is really, really great. 32. ros1_bridge Intro and Migration Guide: In this section, you will learn how to use the ROS1 bridge package. This is a new road to package that allows you to make both a ROS1 and arrows to applications work together. This ROS1 rage package will be super important if you have to migrate a large or OS1 codebase into a Ross to codebase because you won't be able to migrate only code at once. You will have to have a transition phase where you need to work with both ROS1, n rows two until your codebase is completely rewriting in Ross to also, if you're working with Ross to some ROS1 packages might not have been potted yet. So we've ROS1 rage. You will be able to use the ROS1 by cages directly from Euros to application. And now let's get started. 33. Steps to Migrate a Code base using ros1_bridge: If you already have a ROS1 Kobe and you want to migrate to Rostow, you might wonder, how can you ensure your application is still working while you make the transition? Should you only use your ROS1 code, develop your roster application on the side, and then switch only when it is fully ready and tested. Well, thanks to the ROS1 rage, you can switch with a smooth transition while still being able to use both rows one and rows two versions of your application. And here is how. First, we will start with your ROS1 application. You create an empty or us to project. You can then link those to project with the ROS1 bridge. So nothing special for now, but you're already able to communicate wave ROS1 from the rush to side. Now, you can start implementing only some of the functionalities in arose to. For example, let's say you decided to start with the camera functionality. You write the camera back age or node in rows two, and you make sure it's correctly working. When the Ross to functionality is ready, then you can start using it instead of the arrows one functionality. And thanks to the arrows when rage, everything is working well between your ass one app and your rose to the users of your application will be able to use it with either or 4s1, 4s2. Then you continue to translate nodes and packages one after the other. This technique is great because during new transition phase, you can continue to work on adding new functionality is today Ross to side. You don't need to wait until everything is ready. For example, you decide to add a laser scan to your application and you start developing it after you've bought the path planning. So you continue to port everything until there is nothing left in or OSWER. At this point, you have completely migrating your code from Ross TE one tours to great. Now until the Ross one end of life in 20-25, you may still let the rows one rage so that ROS1 uses can still access your Ross to code. But this part is really up to you. And eventually your OS1 up will disappear and only Euros to application remained. So now let's focus on the harass one Ridge package. Here are the different combinations you can use with the different rows one and rows two distributions on the same operating system. If you're still using candidate, you can work with Ross to crystal on Ubuntu 16. If you are using ross melodic on an Ubuntu 18, then you can choose Ross to dashing are eloquent. And finally, if you are using ross noetic on mu to 20, then you can work with Ross to foxy. In this course, we are going to use mainly the last option which is noetic and foxy. This is the best option you can choose for two reasons. First reason, the rows one bridge and rows two functionalities have evolved for each rows two distributions. So you will get just simply a better functionalities and it will be more stable. And the second reason for us one noetic will be supported until 2025. But if you look at Ross kinetic, Ross to crystal dashing and eloquent on those distributions are not supported anymore or won't be supported anymore in the very near future. Pluss. By using some oldest distributions, you may certainly have some bugs when using the ROS1 bridge. So if you are going to make a transition to rows two, while using the ROS1 Bridge, you'd better choose the third option, which means that your transition will take two steps. The first step, you will put your clearance ROS1 codebase to ROS1 noetic on human to 20.04. If you haven't done that already. And then you will bought your code two rows two. And that's exactly what we're going to do with the project at the end of this course. 34. Install and Test ros1_bridge: In this lesson, you are going to learn how to work with the eros one bridge package. So first we're going to install it, set it up, and then we will use it with some of the existing Ross demos that are labeled four rows, one and rows to weave the same interface. So the first thing we will do, the very first thing is to go to our bash c. Ok. And because now we will use both rows one and rows two, okay? Sometimes in one terminal we will need only ROS1. Sometime we will need only Ross too, and sometimes we will need both. So if you already have here some lines to source one distribution, you will probably have some problems in the following. Ok, because if we only need ROS1 here, for example, we are already have crossed two sourced and these may cause some problems. So I'm going to simply remove contrast comment. Any line that is. So seeing a global Ross installation are a workspace. Okay. So make sure you don't have anything left. I save the file and I quit the fight and I'm going to close all my terminals. Okay? And now I'm going to install the roast one reach package so you can open a terminal and pseudo PPT install Ross dash. So the ROS1 rich package, pay attention to that. Ross one bridge package is a arose to package. Okay? This is not a Ross one package. This is eros to package. So these will be installed from eros to distribution. So here you put the distributions you are using. So yeah, I'm using Foxy and then cross one bridge. Okay. And from its already installed, of course, because I previously used it. Once this is installed, you can now close everything and I'm going to open for new terminals. So in all those four terminals, nothing is supposed regarding to Ross one ors two. Okay, if I do Ross run, for example, command not found. If I do Ross to command not found. So that is what you should have in your terminal from the r. So Ross one bridge is installed. Now what are we going to do? Well, you will start with 1 first terminal. You will saws OPT ross. So also noetic. So you will source your Ross one distribution here. And then he would start arrows muster with Rascal. Okay, so that is the first thing you need to do when you use the arrows. When rage, you source ROS1 and you start arrows master on a signal terminal. I'm going to first source ROS1. So here noetic. And I'm going to soon after that for us to. Okay, so let's do that. And as you can see, we have a warning here because that is something you should never do, right? You should never sewers to different Ross distributions and the same terminal, especially if those are are aswell In eros to, but here we are doing it because that is 40 arose when rate. So that is an exception. And now we can start the Roswell bridge, so pros to run. So again, the crosswind bridge is eros to pre-teach Ross taurine ROS1 rich package. And then you can type dynamic range. Dynamic range would be the executable we will want. And can also dash, dash help, which will give you all of the different options you can use. So we are going to use that option rage all topics here, which will bridge all topics in both directions whether or not there is a matching subscriber. This is just because if you just use the command like that, you may have some problems. If you just start a, let's say you started publisher on one side, and then you try to get the topic on the other side with a different Ross distribution, it may not work because the bridge and will not be made. So if we use that option, we won't have the problem. Ok, as you can see, we already have two laws created, wanted to rage, created two-to-one rage. So when you see one to two, it means Ross went to rows two. And when you see two-to-one, it means cross to two ross where, for example, here there arose out topic. In rows two you have the axial interfaces, MSG. And in Ross when you have the roadgraph MSG log, those are two different messages, but those will be breached. So we have our rows, one bridge setup here. And now we just need to start some nodes. So in that terminal I'm going to start arrows, one node. In that terminal, I'm going to start arrows two nodes. So here I'm sourcing OPT Ross noetic setup. And let's do Ross thrown. Okay, we have the cross by tutorials for example. And he thought, okay, I'm going to start the talker. So here I'm going to source for PT, Ross, foxy setup bash. I'm going to source for us too. And I'm going to do Ross to peak lists. And we can see the chatter topic, okay, when we started this node, as you can see, we had mu log lines here. Created a bridge for topic chatter. Okay, this is the ROS1 message. This easier for us to message. And I can do grass to topic, Coke, cheddar. Great. We have a ROS1 publisher here, n rows to subscriber here. I can also launch the rows to run the MOOC nodes. It would be, for example, with listener. And yes, it's working if I kill the publisher, as you can see, we don't receive anymore. I can start it again, etc. Okay, great. So as you can see the in ROS1, you will have the talker and listener examples in the Ross pi tutorials, our raw CPP tutorials. In rows two, it will be in the demo node, CVP, demo nodes, pie. So actually now I'm going to start the Tokyo from Ross two. So it will publish a message here. I'm going to do ROS topic list. And we see the chatter, topic equal chatter. Great, it's working. And I can launch also. Let's launch the so from Ross EBP tutorials, for example. The listener. Great. So that communication is working. Now let's try a final one with Ross ran. Cross. By tutorials, we will test the add two ints server, which is a pretty common example. So this will create a service server here. Okay, I can see it here. Arose to service, list, to int. And now I'm going to call the clients in rows two. Cross two was to run the MOOC nodes. Cvp, we've had two ins, but this time we will start the client. And the client has sent a request to the server. And it is working. So you can reach topic with the publisher and subscriber in any of the two sides. And you can also reach services. So to recap, first, you install Ross when rage, you make sure you don't have anything left in your bash Cassie, regarding to sourcing any Ros Ros to distribution her workspace. And then you will need at least two terminals. First, then we know your source, ROS1 and you start air Oscar to start eros master the Seguin terminal, you will assume Ross 1 first, then source for us too, and then start the bridge. That command. And once this is done, well, you can just open any new terminal. And either your source Ross road and you start arrows were node, are you source Rostow and you start arrows to nodes. And the communication will work between the two versions of frost. 35. Bridge Custom Messages [1/4] - Why + Setup: In this lesson, you will learn how to make the arrows one bridge, work with your custom messages. Okay, because first, you have to know that Ross run Bridge actually will not just work like that when you create your own custom messages. And I guess that if you have a ROS1 application, you certainly have your own custom message package that you use. And if you are just trying to write some coding Ross two and then use the ROS1 rate, then you will see that it is not working. So if you try your publisher in ROS1, your crystal message, you won't have the topic on the arrows to side. And the reason is that the rows one rage package as a pre-defined set of message pairs, okay, that is defined at compilation time, okay? So when you actually installed the ROS1 breached package from, so we've pseudo APT, you install the binaries which are already compiled with a predefined set of message pairs. Let's actually see that here. I am going to create two terminals here. And okay, Let's start. Let's source ROS1 and create eros pastor. And here I'm going to source Ross 1, first source for us to do that. And been that. And I'm going to now around the range. Soros took around Roswell, read Dana, meet rage, that I will use the optional prints. That will not start the bridge, that will just print all the available pairs for message. As you can see, we have quite a lot. Okay? You have, for example, geometry, MSAG sends some SAG, standard, sages, etcetera. You have some messages, some services. And for example, the one we previously used is that one. So you can see when we use the darker and listener example. Well, in Ross, when we had this message, in rows two, we had this message. And the communication only worked because the pair is already defined for the ROS1 rich package. Okay? So when you actually tried to do some stuff in the Ross to side, the ROS1 bridge will detect this message. And then we allow the binding for ROS1 and vice versa. If you detect, if you are on ROS1, Sidon, the ROS1 which will detect that message. It will allow it to go to Euros to side. So now if you have your own custom messages, well, the messages won't appear here because the ROS1 bridge package is not compiled knowing your custom messages. What are we going to do? Well, we are simply going to compile the ROS1 rich package ourself from source. Okay, so now we can close that. And actually, because this can be quite tricky to set up. But first, I'll you have provided you with a code archive you can download. So the name is test ROS1 rage custom messages. So you can actually press pause right now, download this color k from the additional resources of this class and then come back to the video. Alright, so i'm going to unzip this right here, and let's keep it there. So I have provided you with a ROS1 workspace in a Ross to workspace. Let's actually see what inside. So I have made these very minimal, okay, this is the minimum thing. You can have a custom message. So in Roswell, we have inside our workspace, we have only one package named mine and Moscow MSDS. In rows two. We also have one package here, my MSG s. So this is the same package name between ROS1 and rows two. And then in the package here. So we have CMake list and package dot XML, which are setup for ROS1 here. And also the two files here which are setup for Rust to here, okay? And we have a message MSG folder for both with a message tombstone strings.xml g. So that is the custom message I will try to use between Roswell and Ross to customs strings.xml G, which contains only one field here, a string field, which name is my data. If we go to the euros to workspace, we have the exact same name and exact same definition. Ok, so that is kind of a use case where you have arrows, one package focused on messages. You just translated with the same package name, with the same message name, and the exact same field name. Okay? Now we're going to go back to those two workspaces. Just after we actually get the source code from the Ross. One bridge package. We, we create. Actually, I would create here another workspace named range ws, okay, which will be Rackspace for the Roswell Region. Inside that workspace, I'm going to create the source folder. Okay, so from their own, please make sure that you follow every instruction in the other. Okay, This is very important because there are tons of ways to mess up with many different things. And in that source folder. So this is where we are going to add our packages. And actually now I am going to here the ROS1 rage package on Github, okay, you have the URL here and the ROS1 bricked package is inside the Ross to organization. You can also simply type ROS1 rage on Google and you will find this page. So now I'm going to click on here code and copy that line here, clone with HTTPS. Okay, i'm going back to the terminal and when to use gates. If you don't have Gates, should've APT install, good. Okay, so git clone and I put the, you are ok. Now I have my ross One reached package. I'm going inside, so I'm not going to touch anything in that package. Okay. Just going to do one thing, git, checkout, foxy. Okay, as you can see, we have different branches here for the different rows, two distributions, okay? So I guess this is better to actually go to the branch which is for your rose to distribution here, OCC. Okay, so switched to branch foxy. So now we are done with that. I'm going to close this terminal. Okay, great. So now the situation is we have three rock spaces, one or 4s1 workspace with R code and crystal messages. One rose to workspace with the Rostow coding custom messages, and one workspace for the ROS1 bridge. 36. Bridge Custom Messages [2/4] - Installation Process: Now we can start the installation process. So I'm going to open a few different terminals here, four. And OK, in the first terminal, I'm going to build the Ross one workspace. So first I will cross one. I'm going to the workspace that I have provided. A note that I have, but the workspace inside another folder that you don't need to especially put your workspaces inside your home directory, okay, you just put them wherever you want. Just need to remind yourself where they are. And I'm simply going to get kinda make. So as you can see, we have generation for my message, some string. So the Ross one crystal message is built. Now i'm going to another terminal here. I'm going to show thrust to boxy. And I am going to go into the bras to workspace, OK, this time the word cross to workspace, which is here. And call cone, will like to use packages select, but there is only one package. Okay, great. So our Ross to package is no built with the custom methane. We have the Ross one message. We have the eros to message. Now in that terminal so you can close everything, open a new terminal. I'm just going to use that one in that terminal. So here are really pay attention. There are quite a few things to notice. First, we are going to source Ross setup. We are going to source Ross one. Then we are going to source plus two. Okay, so nothing new. And now we are going to source first. Download test was one ws. So we are going to source the Paros, one work space which contains the crystal message. Okay? So here again, you will get a warning because you are sourcing a ROS one workspace and the rows, this row was also said to foxy here. Okay? And now we are doing a fourth source shows gross to workspace. So we can also get access to It's almost two messages. Okay? So first you source the global ROS1 installation. The global Ross to installation. The ROS1 workspace where you have your custom message. The Ross to workspace where you have your keystone miss sage. And then we're going to do bridge workspace where we have. So this is where you have your ROS1 reached package. And in that workspace, you are going to call on real. So for example, packages select. We've ROS1 range. And this is an important parameter you have to add is CMake, Force. Continue like Okay, I'm going to press Enter. And as you will see, the computation time will be really long. Alright? There's one bridge is no build from Susan. And as you can see, 27 minutes. So that can be very, very long and it will mostly depend on your computer performance. For me, usually it's between 1015 minutes here. It's more than that because I guess it's because I have reduced the overall performance of my computer because I'm running on battery now. So when you build the Rossman bridge, make sure your computer and maybe your virtual machine also, if you are running on a virtual machine, has n of computation power for the label. So it would be much faster. Great, so what I can do now, I will stay there, okay? I will source. The bridge workspace, will setup. In fact, working. What I can do is also directly new local setup dot dash, because I have already sourced rose to here before. And now if I do Ross to run across one bridge, dynamic bridge, I can do print pairs. So if I do print pairs, I will have all the bears. A little bit too much. What I can do is just use grep, my MSDS to filter with the my MS JS package em, Great, we have a new pair here. Okay? My MSDS slash MSG AS kids on string in Ross t2 will be translated to my MSDS customer interests. Well, so that is the end of the installation process. 37. Bridge Custom Messages [3/4] - Running Your App: Now we are going to make everything around together so we can actually publish on ROS1 arose to side and subscribe on the other side using this message. So I could use those terminals we have here where we already solved some distributions and workspace. But actually I'm going to close everything so we can start again with some new terminals and nothing too. So I'm going to open for new terminals here. And let's run the application. So first of all, in the first terminal, of course, you will soon cross one. So noetic here and you will start arrows, master, felt step. Okay. Now, now in this terminal we will start the eros wooden bridge. So again, we're going to source OPT arose and already setup brush. Souls were Oswald in dense source bras to foxy. Setup bash. Ok. Now what happens if I simply do for us to run ROS1, reach dynamic bridge and print, There's actually, I'm going to filter. We've grip. So pipe grape, my m, s, which is as you can see, we have nothing here. Okay. Why is that? Because you actually have to Ross run wage installation. One that is global installed with binary packages and one that is locally installed. But here we have just sourced the global installations. So this is the global ROS1 reach. And of course, little global ROS1 reached doesn't know about your My message is package. So what you have to do, you have to sue the bridge workspace. So the bridge workspace is where you have installed the Ross one bridge by th. So Salzburg workspace install, setup, lush. Okay, you will have this warning but hits okay. So if you see that workspace, then you will use your local ROS1 rage instead of the global what? Now if I run the bridge again, we've printed pairs. You can see we have the message, so it's very important to source. Here the bridge workspace. So I have three sauce, Hein, 1-4, ROS1, one far Ross to N14, the bright workspace, where we have the custom string message because we have compiled it before with this definition. I'm simply now doing dynamic bridge. We've bridge all topics, okay? This is important to put that option here. Okay, so now the Ross one bridge is correctly set up in any other terminal. You can either start payer Ross one Stef Ross to stuff and make them. Communicate between each other. So let's, let's try it here. I'm going to source how Pythagoras nomadic. I'm going to source ROS1, okay? And I'm going to source also the workspace, so tests Ross one workspace, digital bash. Okay, so unceasingly global ROS1 installation and the rows one workspace. So now I can actually use, if I do Rows, Show me sage custom string, okay, the message is here. Now, here, let's solve for us to foxy setup bash. I'm going to source deep for us to workspace, test bras to install, setup. And if we do Ross to interface, show paper estab for auto completion. It is here. Great. So far we have done nothing special. Now I am going to Ross too. Pick them focus. I'm going to publish neuropathy from the terminal on a test to beat the type my message Kristen string. And actually I'm doing so I can put quotes and brackets, my data. My data, we'll be, it works. So this will actually create a pollution. Here. As you can see, we have mu log here to say that we are now passing message from Ross to-to ROS1, weave that type. And if I do on Ros, Ros topic list, I can see the test topic. If I draw subtopic equal tests, I can get the data. It works. Great. So now you can use your own custom messages with the ROS1 rage. You have quite a little bit of setup. But after that, well, it's quite simple. And now you can do the same thing for your own custom messages. And note that every time you add something in the message, pike age, okay, in ROS1 or was too. If you want to add a new message or a new service, or if you want to change a message on both sides, you will have to compile the ROS1 reached package again from those. And that will take quite a long time. Okay, so make sure you don't make any mistake before you compile. Otherwise you will just lose 1020 minutes. Ncd era only after that. And that's why I have provided you with the test Ross one workspace and the test roast workspace. So you have a working example that you can simply getting inspired from to make your application work. 38. Bridge Custom Messages [4/4] - Mapping Rules: Okay, great. You can know work we've Ross when bridge and your custom messages, but you might actually have a few more things to setup. Okay. Because, okay, why is that? The Ross one bridge when you installed from source, okay. The binding for the message will only work if the package name in rows one and rows two are the same. Plus if the message name are the same, and if the fields inside the message are the same. Okay? So maybe you have a different package name in Roswell and Rostow. And maybe for example, your message is slightly different in the name. So if you have that when you build the ROS1 bridge, then the pair will not be defined and it will not work. So in that case, you can add a configuration file in your Ross to workspace to fix that. And that's what we are going to end. Well, if you've already made it that far, this would not be too complicated. So, and we'll walk from racecars here. So I have my tree with the ROS1 workspace and the rows to workspace. Here. I going to modify, okay, I'm just going to modify the name of the crystalline string messages, so rename. Okay, let's say my piston string. Ok. So I'm keeping the package name. I don't take all and I'm just changing the name of the message. So of course in the CMakeList.txt, now it is not custom string, which is my please don't strain. Ok. And that is the only thing I have to change here. So now if I build the both packages and if I read Ross one bridge, then it will not work because the message name is not the same. Okay? I have custom string and ROS1 and Microsoft streaming Ross to what I'm going to do. I am going to add inside the package and so on. Okay, I'm going to open a terminal to do that. Let's go in the Ross to workspace. Okay? So every configuration you will do will be inside the roast workspace, okay, not in the ROS1 workspace. So I'm going to my cage and here are the root of the package I'm going to add, let's say my mapping rules. Young, you were either a YAML file here. Okay. Along we're just CMakeLists.txt and by caja dot xml. And in this YAML file, we will actually set up some rules. Okay, so I'm going to put a dash here. You can put a list of rules, okay, so everyone's, We start with the dash and then you can add two spaces for in the Bayesian. And what I'm going to write for OS1 by cage, which would meet my m as gs. We've one, my stage name, which will be custom train, and then arose to cage name, which is also my JS and cross two and Ross to make sage name, which will be this time my custom string. Okay? So make sure you have the correct syntax. This is very important. So what are we saying here? We are saying that the ROS1 message name custom string inside the ROS1 package name. My messages should be in rows. Two, majors don't string from LA, my MS, GS, packaging Rostow. Okay. So if you have a different vacationing here and here, you will also need to change that name accordingly, okay? And if you have, let's say another rule, then you can add another rule like here and ROS1, et cetera. So I'm just going to dave That fire like this, okay? And actually we are going to install that in the Ross to package. So first I'm going to package dot XML of the Rostow packaged still in that package and in the export tag, I'm going to add a new tag after the build type. And this would be Ross one, bridge mapping rules. Okay? And I'm going to give the name of the file, okay, so my mapping routes.js yellow, and then I close the tag and save the package dot XML. Okay, so that's it for this file, I'm going to do CMakeLists.txt. And here after the generation of messages and before Amun package, I'm going to add install files. And I'm going to install the file named by mapping roads dot yaml, which is the name of the file here, if you change the name of the file, you have to change it accordingly. And destination will be in the shell, although I would put here project name, save this file. So this basically will install the mind-mapping rules here, dot HTML in the share folder for the install folder of the workspace. And then the package that XML will be able to find it from there with the rows one bridge dying. So after that, when we build the ROS1 reached by gauge, then it will know it has to follow those rules. Okay, so you save everything. Now, I am going to okay. First of all, you would need to build your rows one workspace if that's not already down. So it should be done, but I will still do it anyway. So step two will obviously Ross nomadic bash. You are going to need cross one, cross one workspace. And here kickin made. Ok, so it's done. I'm going to close it up and a new terminal. I am going to sue bras fluxes, Lash. I'm going to Ross to workspace. I'm actually going to remove the Builds folder and bring the install folder. Okay? Because we changed the messages may be better to just build everything from scratch. You get a call Kahn built. All right, and now if I go to install folder of my arrows to workspace in my package, then, as we asked in the CMakeList.txt, we go to the shared folder in my MS js and we should find my mapping roads dot yaml. You also have the package dot XML. Okay, so by gadget, XML would basically try to find five from there. So make sure this file is installed in that directory or else it won't work. So the rows one package is built, ross to package is built with custom rules that are installed. Now I can install, so I'm going to close that. And now I can install the Ross one bridge for source. So let's, let's actually go to the bridge and also remove build and install folder. Okay. And to build the Roswell Enbridge from source, we are going first to source ROS1, pretty Ross, nerdy set of bash. Sos Ross took Foxy setup bash. Because we need to be aware of the Roswell message. We will also source the Ross one workspace legal set-up bash. And because we also need to be aware of the euros to message and the customer rules. We need to source downloads, desks to install setup. Okay, so we have solved the two global Ross installation and two different workspace where we have the Mercedes. And now I'm going to do reach workspace. And so we have removed install and build folder. I am going to build again core cone. I can just select Roswell rage. And I'm going to add CMake configure. Great, so the Ross one bridge package has been built. And as you can see, it's still quite long, 16 minutes. It's a little bit less longer than my previous Try. It was 27 minutes. The reason is that I simply powered my computer with my power cable. Ok, this is a laptop and this is a virtual machine. So on Windows, I simply have a setting that but more computation power when the laptop is plugged in. So if you have a laptop, make sure you operate on are set the polar configuration so you have more computation power. Alright? So I'm going to open some new terminals to test the customer's age. So first of all, I would need to, of course, Source Roswell here. Noetic setup bash. And again start or US master weaver Oscar. And these terminal, let's do that. I'm going to sue or OS1. I'm going to source for us too. And I'm going to source the bridge workspace where the ROS1 rage is locally installed from source.bash. Okay, now what I can do cross to ROS1 bridge with dynamic bridge, print pairs, pipe, grep. And let's see what we have and it is working. Okay. We have the custom string messaging, Ross one, which is no binded to the and my custom string messaging arose to, Okay, thanks to the additional rules that we've added in the roast package. So if we didn't put those rules, then this would not have worked and we would not have any binding for the custom string message. So I can notice that the dynamic range wave bridge all topics. Okay? Now on this new terminal and when to source, Ross took her beauty, rose, foxy setup bash. I'm going to source the gross to work space which contains the message. So I can of course use the message in that terminal. So installs setup, rash. And I'm going to publish arose to topic. But I'm going to publish on a test topic with my beseech custom string. And I'm going to give it a string, my data, which is the field and lo. So it should publish. Okay, hello. So if I open a new terminal in Ross to ICANN, of course, listen to that message. And now if here I'm sourcing ROS1. And if I want to be able to access this custom messaging or OS1 there, I also need to source the Ross one workspace that contains the message. So cross one space level setup bash. Now I can simply do Ross topic list. And I have the test topic which is published from Ross took. If I do Rostow peak in folk tests, you can see we have to type my message is custom string, which is the Ross one message on this side, okay, on this side I have my JSON string, and on this side I have custom string and Rostow Eco test. And I can see the data. Great. To conclude on that. Well, you will often have to add some additional rules, I guess, because the name of your packages and messages may be different between Roswell and Ross too. So now, with all that knowledge, you can basically translate your whole application from Roswell. Two, cross two. 39. Use ros1_bridge With Our Number App: Okay, now let's practice a little bit more on the rows. So we will use the Rossman rage on the number obligation we just created in the last section. Okay, so we started with the Ross one application here. And we have completely rewritten this application into eros to application right here. Actually, we will not need to migrate the application because it's already completely written in rows two, but we can still play with it and see how you can access different parts of the application from ROS1 and from Ross. So the first thing we will need to take here is do we have custom interfaces are crystal messages. And yes, we have one custom service right here. So this means that we won't be able to just use ROS run bridge like that. We will need to build the ROS1 ridge to actually get this those two messages to be paired so they can be linked and binded together. And the second thing to check here is the package name and message name and fields identical. And as you can see, we have difference. The name of the package in ROS1 is my robot, MSDS, and the name of the package in Ross who is my robot interfaces. Then we have the same name for the service and the same fields. So only the package name is different. But if we just compile ROS1 bridge like that, then of course it will not make the binding between those two messages. So we need first to add a mapping rule inside the Ross to workspace. Let's do that. So I'm going into the cross to workspace we previously had in the my robot interfaces. And here, touch my mapping rules dot you can name it as you want. Okay, doesn't matter. Just need to make sure that when you write the file in the package dot xml and CMakeLists.txt. This is the same name as here. So I'm just creating that phi here and here it is. So I will add a new rule. In addition, we have two spaces and I will write bra Swirl, package name my robot, USGS, Ross to package name my robot interfaces. Okay, and I don't need to actually write cross one message naming Ross to message name because those are the same. Okay? So basically this rule will tell the ROS1 bridge that everything under my robot messages should be translated into. Robot interfaces. So if you have multiple messages and services here that are identical to some of the Ross to message and services here. They will all be translated, they will all be binded. Okay? We've only this rule. So I'm going to add this package dot XML. We've crossed one, bridge. Mapping roles equals my mapping routes.js. Close the tag. Okay, and I'm going to the CMake list, that TXT of my robot interfaces package. And right here I'm going to install buys. The phi will be my mapping. Bruce. Yellow, destination. Share projects name. Okay. Hey, save the CMakeLists.txt, Make sure you save your files. Okay, so that part of the setup is down. Now, I will need to first make sure that arose workspace. So source for us, noetic setup. And we make sure that everything is compiled correctly. So we already have the missile age. Now, I will open a new terminal. I'm going to rows two workspace. And so Qualcomm wheeled can only select my robot, my robot interfaces. Okay? And I will make sure that my faces, chair and my robot interfaces, and we'll make sure that the mapping rules have been installed here. Correct. And now I can appending it terminal. And let's build Ross when bridge from source. So I'm going to source ROS1, noite, setup dash. I'm going to sue folksy setup bash. Now I will source ROS1. Workspace will look is to message. So cross one, setup dash, cross to workspace installed. Okay, now I can go to the Enbridge workspace and let's remove again that. That kinda would do cocoa. Wheeled back edges, select rage and CMake configure. Okay, there's one rage package is now built. So let's quickly check if this worked. You can sue the package. So sues the bridge workspace folder and actually run rose to Ross, Bridge, dynamic bridge, print pairs. And we can bike, grab my okay, and actually you can see here we have in us one, my robot MSDS, reset counter is in Ross took my robot interfaces is LV reset counter. So thanks to our custom mapping rule, the ROS1 bridge knows that it has to bind this message with this one. So now we can make some tests. I'm going to open a few terminals here. And as usual, we are going to source Ross 1. First. We've agarose muster. Okay. And right here I'm going to sue ROS1 Ross to source debris, workspace and the crosswind region or OS1 bridge dynamic range with rich, all topics. Great, so now I'm going to say this, no, that would be far OS1, this terminal will be for us to so for PT frost, noetic bash, I'm going to also source the Ross one workspace. They will set up bash. Here. I'm going to solve Proxy set-up for us to end source the morose to workspace. Okay, in Roswell, I will know stat across large. I can start the application. Ross launch, my promote bring up wave number. App launch. This will start the complete an application. And you can see we have some bridge here. And if I do rows to topic, at least I can see the number topic. If you rose to service list. I can see the reset counter service. Okay, so that's great. You have your company's ROS1 application and in Ross till you get already have access to the topics and services. But that would be you first migration status, okay? You run your Rossman application and you start to see what you can do reverse too. So I can, for example, do rows to service. Call, reset counter with the type which will be my robot interfaces. Where is it counter? And I'm going to give the request, which is revisit value to eight, for example. Okay? And as you can see in the Ross went application, the counter has been raised eight to eight. So that would be the first step. Then in our application we have two nodes. We have the number publisher and we have the number counter. So now let's say that you have written the number publisher first in a roster. So I'm going to launch rose to run for us to Python or C Plus, Plus. It's the same number, publisher. Number Publisher has been studied, grades in rows two. So in ROS1, ROS topic list eigenstates the number topic, Rostow Peach, Number. I can actually get the data from Ross too. And now what I can do is Ross run. So I'm going to launch the number counter node in ROS1, ROS1 app, python, we've number counter. And it works, okay. So the number publisher in rows two, we published the ROS1 bridge will do its work and then the number counter can actually subscribe to the topic and print the data. So that be step two of your migration. Ok, you have one node in Rostow and you still have some nosing ROS1. And then let's say that you have also written the number counter in Ross too. So you can launch the publisher and the counter in 4s2. And actually I will start the Ross to we start to launch, fine. Okay. My robot. Bring up. We number up. I'm starting the eros to lunch 5p. So now the complete application is running in rows two. And what I can do in ROS1 cross topic list, I can get access to the topic, which is here my number, ok, we have remapped the topic in the launch, fine, right? And ross service list. I can see also my reset counter and I can call ross series called My reset counter. We've raised the value. Let's put three and we can see that it works on Ross took. Great. So once you have your application which is completely written in rows two, you can still get access to it from Roswell. And then at some point you may completely remove the bridge and only use the Ross to application. Okay, in this section, you have discovered how to use ROS run bridge to make your ass one application work with your Ross to application. Ross one bridge is especially useful to migrate a codebase and Willie practice on that in the next section of the course. 40. Migration Project - Intro - Discover the ROS1 app: It's time for you to practice with a complete new project. In this project, I will give you a arose when application and you will have to migrate it to Ross two. This will give you the opportunity to practice on everything you've seen in this course. For now. In this introduction video, I will first show you the result you will get with the application. Then I will quickly explain the different packages and the ROS1 code. And finally, I will explain to you what steps you can follow to migrate this project. And that's also the steps I'm going to take for this solution. So make sure you watch that. Ok, let's start. Here. I am on human to 18.04. We've cross one melodic installed and setup, as you saw in the previous section, when you have a ROS1 project, it's better to felt bought it to Ross one noetic, which is the latest and last Ross one distribution. So that's what we're going to do as a very first step. And we provide you with a code for ROS1 melodic. And you will first bolted to Roswell and noetic. Don't worry if you don't have you been to 18 on your computer. You actually don't need it for this project. You can just watch this video to see what is the project result. And then you can directly go to u1 to 20 and port the application to know it. You will see that will be very quick and easy to do. And then you can run the application on noetic. So let's run the project. I have created a project ROS1 workspace, okay, here. And inside this workspace, I have but my project, ROS1 melodic archive. That is the archive you can download as an additional Rosso's to discuss. So make sure you download it and then you can unzip it. It will give you this source folder. Here we have the complete application. So what's in this source folder? We have actually four different packages. So you have the turtle seem project by which is the code for Python, doesn't seem projects CPP, which is the code for C plus, plus, ok, just like we did in the number application, we have the application in Python, the application in cplusplus. Both packages provide the same functionalities, OK, just one. In Python, we're in C plus plus. And then we have a package that you already know my robot bringing up, which contains a launch five to start the entire application. And my robot messages, which contain the custom messages we are using this application. And as you can see, the name of the project is turtle seem projects. So it means we are going to use t6. So first make sure you have the total package installed because we are going to use it so you can install with pseudo APT install, ROS dash, then you put your Ross distribution. Okay, So here if I'm working on melodic, I put melodic. If you're working on a different distribution, you put a different distribution. And the til, since k can press enter and install Thompson package. Once this is done, I'm going to to cut Qin make. Okay. Okay, and the package is built. And now make sure that you have correctly set up your bash Pasi With the source setup that Bush for the global ROS1 melodic installation folder. And also to source the devil settled bash from your current ROS1 workspace. You put that in your bash assay. Okay. So we're going to start the launch file, which is in my robot, bring a package. So here I have the four packages. I have the totals in project dot. Let's Ross launch my robot. Bring up turtles in project that lunch. And let's see what it does. So you have the turtles seem window with a turtle. You probably already know that node, ok, this is a pretty common node. You have to start working on Ross when you learn. And then you can see the turtle is moving, okay. Moving to a different point every time. And we can see the trajectory here. So now I'm going to kill that. And let's see what's inside the launch phi. We have three different note here. The first node is not a node that we are going to write. It's a node we are going to use from the turtles in package. So it's an already existing node. And the turtles ignore what I just showed you. It's the window with the turtle. And then we, we launched two different nodes, total controller and target generator. So I have put the Python wants here and the cplusplus wants here. You can just comment our increment, one of the other to launch the python or C plus plus node. So the total controller will actually control the total you see on the screen here. It will check the position and it will continuously monitor disposition to go to the next target. And the target generator will basically generate a target and publish it to a topic. So then the total controller can subscribe to this topic and go to the target. Ok, so let's actually see in the Python Project we have, so we have the two different price here. Further controller. As you can see, I already used object-oriented programming, okay? All these Roswell node, ok, so we have the constructor here, we have a few functions and then in main we simply initialize the node and create the object and then spin the node. So what do we have in the constructor? Very basically, we have a publisher to common velocity, so we can control the velocity of the total and so we can make the turtle move on the screen. We have a subscriber to depose topic from the other one. So we can get the current position of the turtle. So the combination of those two will allow us to move turtle inside the control loop. We have a timer here, so we are actually running the control loop at 100 hertz, ok. This is the duration 0.02, which means that the controller could run at 100 hertz. And what do we do in this control loop? Well, you can see we have a bunch of mathematics. You actually don't need to worry too much about that because you will simply need to port the app to Rostow. Okay? You don't need to rewrite the functionality, so that is just mathematics. You can just copy and paste in ROS1 are rows two and the same here. So this is the basic control system I just implemented. We are simply measuring the distance between the current position and the target's position. And then I am giving a linear speed and angular speed that I compute so the robot can move smoothly. So if you want, you can study at more to understand what it does. This is very simply PI controller basically. So as you can see, we have a message here, twist because the common velocity, we will need to send twist message on that topic. So I'm creating a twist message. And then I feel this message with a linear x, angular, RC, etc. And then I publishing that every time we call the control loop. So at 100 hertz. Then we have also this subscriber to target coordinates. We've coordinate 2D, which this message comes from my robot messages. You can find it right here. And you have simply x and y. So I've created this message. So you would also have to, It's tourist to Okay, so in the callback for the subscriber right here. So we check that the values in between the 011, which is the border of the screen for the turtles him. And then we simply assign the target we receive to self targets. So then we can actually use that targeting the control. Okay, and if you look at the simplest code, target turtle controller, that is the exact same thing. We have the same publishers subscribers timer with the same functionality. So you can also check that one. And then we have the target publisher node. Much simpler. We simply have one publisher and the target coordinates, coordinates 2D. And we have one timer to send the coordinates at a given rate. The rate, so it is here an interval and giving an interval directly. And we get this interval from the parameters. So you will also have to translate and port this perimeter in rows two. Here the default value is three, so it means we are publishing a coordinates every three signals and two collision coordinate. I simply used the random functionality in Python to create a random float between 011 and I publish on the target coordinates topic. And if you look at this C plus plus one, well, we have the exact same functionality here with C plus plus in ROS1, also using object-oriented programming. So I won't go into too much details here. I will simply let you discover more by yourself. 41. Migration Project - Intro - Steps: And now let's see what are the steps that you will take for this project. So here are all the different steps and as you can see, that is also the name of the different videos for the solution I've provided in this product. So the very first step, the step 0, is to migrate your codebase to Ross one Nordic. Note that I've also provided a code archive for the project. We have ROS1 noetic. So if you are stuck, you can also directly download the solution, which is the project working for us when neurotic, but that shouldn't be ready to have a k. How to actually migrate your code base. Well, you can go on WikiLeaks.org slash noetic slash migration. And you can also directly type that on Google and you will find this page. So this page is a migration guide when you put an obligation from Ross one melodic to Ross one noetic. Basically you simply need to follow those instructions to make your application rock in noetic. And that may seem quite a lot of instructions, but actually, for this project here you only need to first once, ok. So you will need to make sure your files work in Python three, that is the main difference between any previous ROS1 version and noetic. Noetic is basically just here. So you can use Python three, we've Roswell. Then you will need to make sure that in your CMake list, that TXT in any of your package, you have CMYK minimum required with 3.2. So you will have to check that. So once you have done step 0 by yourself, you can watch the solution and go to the following. Then before you actually go to step one, it's very important. I will provide you a seed for the rows to project. You will need to do that because you will have a problem with the turtle in package and the total M messages and actually will give you more information inside this video. Ok, so you will start with the project Ross to Foxe's seed called Chi from now. And then that's all URLS. Step one, you will set up ROS1 rage for the custom interfaces. So far. Actually, the coordinates 2D, you need to set up ROS1 bridge like we did in the previous section. Step two, you will migrate the target publisher node to use in Ross too. Step three, actually it's not two, it's three. You will migrate the turtle controller level. Okay, so first migrated first node, use it with the ROS1 application, then migrate the signal node. And finally in step four, you will write a launch file for your rose to application. So now you can competently launch your application with just one line in rows two, and your project will be completely migrated. So now take some time to discover more about the dollars in projects in Ross weren't okay. And I will see you on the next video of migrating your codebase to ROS1 noise. 42. Step 0: Port the code to ROS1 Noetic: Alright, let's bought the rows one melodic project into a Roth one annuity projects. So I am going to download, so make sure you have downloaded the project ROS1 melodic here I am on human to 2004 with ROS1 noetic installed. Ok. I'm going to create a workspace. So project I will emit project ROS1 Ws. And inside that project, I'm going to put God archive right here. I'm going to unzip it just here. So I have a source folder, right? So now we have the melodic project here. So actually we will not run it like that because it will have a problem. First, I'm going to remove that CMakeLists.txt, which was generated by cat can make. But this one will actually link to Ross melodic. So if I keep it, it won't work. So you should only have those four packages here. And now I'm going to open this on VS code. Okay, so here is the project. And if I go back to the migration guide for noetic, I will need only to do the first two different steps, okay, like I previously told you. So we're going to make sure that all phi's can run Python three. So let's go to the project by crypt. Let's start with target publisher. Okay, what I'm going to do here is simply here. For the interpreter line, I'm going to add here a three. So I'm simply telling that now this phi should be executed with Python three. And if you have any Python to specific functionalities, you will need to also make them in Python three, but everything works both in Python 23 for this file, so we just need to modify it here. Total controller, exact same thing. Python three and I saved the fire. And everything will also work in Python right here. And right, that's it for the first step. As you can see that it was quite quick to do. Now, I'm going to check every CMakeList.txt that I have to make sure we have 3.2. So I'm going to Robert bring ok. We have 3.2. My robot may say, geez, okay, telos in project. Okay. Tennessee project by ok. I have nothing to change here because I already used CAD Qin 3.1.2 in ROS1 melodic. And well basically that's it. We have potted the ROS1 melodic project into heroes were nomadic. So now I can actually build and run the project. So first I'm going to go to the bash assay to check if I don't have anything wrong. Okay. So the bash LC here, we have nothing sourced, okay? No cross two distribution, no Ross drawn distribution. Okay, we'll just keep it like that. I will sous noetic. Okay, and then I will go to my project ROS1 workspace and cat King make. Ok. Here I now have a double folder so I can actually source devil setup bash to get a functionality is from that workspace. And now I'm going to go back to the bash SEO. And I will add the two lines, two source first, ROS1 noetic. And in schools. Project ROS1 workspace. They will setup bash saved or bash assay style. Now when I open a new terminal, I can be sure that I can use my workspace. So here everything is already Sue's going to Ross, launch my robot, bring up turtles seem project, launch. And let's see if this works. Yes, it works. Ok, so you have successfully ported the ROS1 projects from melodic to know. Of course, this is a quite simple products, so it works very quickly. For your project, you may have a few things to change, especially with Python three change. But anyway, Python two is not supported anymore, so please upgrade to Python three as soon as you can. And now we're going to continue. So make sure you watch the next video. I will give you a seed for your gross to project. 43. BEFORE GOING FURTHER - Download the Seed For the ROS2 Project: This video is very important for the following. If you don't follow the instructions I give you here, then your application will not work. So first of all, we are going back to the bash assay to make sure we have nothing sourced. And here we have, as you can see, we have sought zeros, one project with Ross when numeric. So I'm simply going to put a comment with dotted lines. And for the rest of this project we want sauce, any theme from the Bhatia c, we will use the workspace and distributions manually. So now I'm going to open a new terminal. And you can download the project rose to foxy sin God archive. Okay. You download it and I will create here project to work space. So this is a new workspace for our ross tool. Inside that workspace, I will move. Before with other ones, I will move the project was to foxy CD here. Actually, I need to put them point, okay. And unzip the project just here. Okay? And once inside that seed, well, you have the turtle thing package. So now let me explain to you quite briefly and I will come back also to that a little bit later in the course. So first of all, the total package is already a package that exist and you can install it with sudo APT install Ross dash, foxy dash, tellers him. Ok. But the problem we will have with this project is when we will actually use the rows one bridge package. So the ROS1 bridge package, as you previously saw, contains a set of pairs of message, okay, between Roswell n rows two. If a message is not defined here, then you won't be able to actually use those messages with topics are we've services also. And first, if you look at the set of pairs of messages, you will see that there is no turtle seem messages because in this package there are some messages we will use in the project. So first, they are not in the ROS1 bridge. So what I first did is actually just installed the turtle thing globally and then build the ROS1 bridge from source. So because the ROS1 bridge found the total seemed package in ROS1 and Ross too, it was able to actually make binding with some messages. But for some reasons, not every message was actually binded. So there is still one message that we need for the project and that you can't just get working with ROS1 rich. So what I did next was simply to clone the turtles in package from GitHub and to build it also from source, which as you can see inside. So we have, we have some code and we also have messages and services. Okay? And what I added here is a mapping rule. And let's see, actually this mapping rule. And this mapping rule is quite where I, because basically I'm saying that the post message from Turtle theme should be the post message from total similar Rostow. Okay, that's exactly the same thing. So it should work by default, but it doesn't. So I added this mapping rule. And after I've tested with Ross one bridge, it finally worked. Ok, so I guess there is something wrong in the ROS1 bridge package or total seem that makes the two of them conflict at some point. And right now it's just not worth it to debug the ROS1 rich package by yourself. Actually, you can use the seed I've provided. So then you will be able to use the turtle seem messages correctly. So that is the CEO of your worst workspace. I just have the turtle seem package. You will not touch anything in that package, okay, you just leave it like that. And then you will be able to create the other packages. So what you can already do is ongoing to source OPT, rose foxy setup bash. And I'm going to do Qualcomm grilled. I have only one package. Alright, so it can take quite some time to build depending on your computer performance. But now that it's built, you don't need to build it again anymore. You can just foil abolished, and just write your code inside other packages. Now you can start with the step one of the product. And this first step will be to migrate your custom messages and make them work with Ross one bridge. And actually when you build ROS1 bridge from source, this will make the binding for your custom messages, and this will also make the binding for turtle seemed messages. You won't need to do anything about that. 44. Step 1: Setup ros1_bridge for Your Custom Interfaces: This is one of the solution for the total seem project migration. So I am going to go to my project Ross to workspace where I already have it others in package. I'm going to open that in Visual Studio Code. And also going to add followed that workspace, which will be the ROS1 projects. So I can have that on the side. And I'm also going to add another folder, which is the bras to workspace we use with the number of applications. So I can have also a working rush to obligation. When I need to get some configuration, I can just copy and paste from that workspace. So the first thing you will do when you want to migrate a project from Ross went to rows two. And if you want to use the ROS1 bridge, is to actually make sure that all your messages are in faces are actually correctly setup so you can use them between ROS1 and Ross too. So I'm first going to create here a package for the crystal metaphysis. So I'm going to need to source rest to here. So again, one last time. If you still have something relative to Ros, Ros too in your bash ARC, please remove any of those lines. Okay. We will source everything manually phone. No. So I'm going to source for us too. So I can use Ross to PKC create. Okay. We've my robot interfaces. I don't specify a build type and I don't specify any dependencies here. So we have here my robot interfaces. I will go inside that and remove include grow, move, sauce, and what do we have in our ROS1 project? We have one message. Okay? So I'm going to create here a MSG folder. Inside this MSG folder, I will create a message with the same name, Dutch coordinates to the dot MSG. Okay, so that's it for here. So now the coordinates 2D MSG will be the exact same here because those are primitive datatypes, Float 64, x and y. So I can just keep that here. I save the file. And now I need, of course, to configure the package to build the messages. So to configure the package, I'm going back to my Number Application in Ross tool in my mobile interfaces package that XML. And I would simply copy and paste those three lines right here inside my robot interfaces from the Project workspace. I will just copy them right here and I save the file. And if I open the CMake list, that TXT. So I'm going to remove that. And that also. And now I will go to the CMakeList.txt for the number of application. I need to add Ross ideal default generators here and cross ideal generate interfaces. I'm going to add that here. Of course I'm going to remove this because we don't have the reset counter service anymore. Instead, I'm going to add MSG slash coordinates. 2d dot M is okay, so that should be it to actually install the coordinate 2D message and create some Python and C plus plus codes. So we can use that in our code. And I'm going to add a mapping rule, okay, so we can use it with Ross one rate because if you check between the Ross to project and the ROS1 project, here I have my robot interfaces package and here I have my robot messages package. Those are two different names. So if I don't have a mapping rule, then it won't work with Ross one region. And now as you can see, I have put the exact same name and the exact same fields inside the message. So we only have to add the mapping rule for the package. So right in the, my robot interfaces are the root of the package. And adding, let's say mapping. Mapping all the yellow, you can just name them as you want. It's right here. So I'm adding rows. One, package name my robot, MSDS, and Ross to package name my robot interfaces. Great. So make sure you look, make any typo in Maine, okay? Okay, I can go to my CMake list here and we need to add some configurations. So like I did in the Ross to application number up, I need to install. That. Ok, so I need to install the files. Here. It is just mapping or rules that YAML can make sure it's in the same name. So I'm going to install that file into the share my robot interfaces folder inside the install folder of the workspace. And in package dot XML. I will also need to configure the mapping rules. So if I go to the package dot XML of the number application, I also had one extra line here. And this line will go there. And of course I need to remove my prayers. I have changed the name of the file. Mapping rules that yellow. Ok, so here is what you are packaged that XML will look like. You have three lines here. We've Ross ideal, one line here for the mapping rules on CMakeList.txt. You have a fine package. We've roast ideal default generators. Here, Ross ideal generating faces with your message. And then you install the mapping rules here. You have a mapping rule here. And well, that should be. So let's go to our workspace. And I'm going to call Con build. Package is select my robot interfaces. Okay, great, so now if I saw setup dot bash from my workspace, rose to interface, list, pipe grape, my, I will have my robot interfaces coordinates 2D. So now that the package has been built, we will need to build the ROS1 bridge from source. I'm going to open for different terminals with nothing sourced, okay? Either of them. So I'm going to do the complete process here to install ROS1 rate. Okay, so first I'm going to do projects Ross one. So where we have in that one, we have my robot MSDS with coordinates to default ROS1. And I'm going to source cross one. And I'm going to cut Qin made. Okay, so it was already built, but just in case, so you are sure that it was built. Then here I'm going to do the same for cross two. So project was to work space. So in fact we'll just build it before, but this is just to show you the complete process. Stores cross foxy setup, bash, Glaucon, real packages, select my robot interfaces. Also here, we will need to also do turn on him. So it was already built wide hurdles him because as I told you, we are going to also make the ROS1 bridge work fault addressing messages. So I have the total seem message from sauce right here in rows two. And we also need to have the messages in ROS1, right? But the message is ROS1 already exists because in Ross one, I already have the turtles seem package. If you don't have the total simplification, make sure to install it with sudo pip, install Ross noetic. Okay, so at least we are sure it is here. So now let's build respawn rich. I'm going first to source ROS1 noetic. I'm going to sue. Okay, and then I'm going to source the rows. One project here, there's one project workspace. So ross worn here. They will setup bash. Ok. And I'm going to soul's Lee Ross to workspace. So install, setup, bash. So here we will be crosswind bridge here. And what do we expect? We expect it to make a binding for microbial interfaces and turtles. Turtle see messages in Ross warn you already have them thanks to this line because there were installed in the toddlers in package that you installed from binaries. And then because you have installed the turtles seem package here from source with the mapping rules. They will be found in Ross to with that line, okay. For my robot messages in ROS1, they will be found with this line. And for my robot interfaces in Ross today will be found with that like here. So now you are sure that all the messages you want are found in Roswell in rows two. So I'm going to the bridge workspace. I already have the ROS1 rich package for foxy. I'm going to run a build and I'm going to remove installed here. I am going to do coke on. Select, Roswell, rage. We've CMake configure. Okay, and let's wait. The ROS1 bridge package has now been built here in 16 minutes for me. So now we are just going to test if this actually worked. And we are going to launch the ROS1 project, okay, in a terminal where we source ROS1 and we will try to get access to this application from Ross to I'm going to append a new window here. And then we split this in four. Okay, so first terminal, I'm going to source Ross one sort of rush with noetic and start a raw score. Okay, in this second terminal, I'm going to start the ROS1 bridge. So, so puppeteer OS, noetic setup bash sourcing, harass one. And I'm sourcing 4s2. And then of course, I will be sourcing Mike stone bridge workspace. Okay, so from now on we will always need to suit the bridge workspace, okay, when we start the ROS1 rage, because we want to actually use the ROS1 bridge that we have built with the messages that we need. So Ross to ground or OS1 bridge with dynamic Bridge. And I will do print pairs. Let's see what we got here. So actually, you should see inside messages here, okay, so the first good news we have is we can see turtles impose and turtles seem message prose in rows two. Ok, so if you don't have that, well, you have a problem with your configuration. And then we should see here my robot message coordinate 2D in ROS1. And my robot interfaces message coordinate to the interface. Too. Great. So it worked if you don't have those two pairs. Well, don't continue the project, right? No, I make sure you have correctly configured everything. Okay. You may need to go back to the previous video and this one, and follow every instructions step-by-step, okay? Using the ROS1 bridge from source requires some patients can deny that. So make sure you do everything right and then build the bridge again. And then if you see that result here with the two messages I have showed you, then you're good to go. So now I'm going to run the bridge with the rage, all topics, option rate. And in that terminal I'm going to ROS1. So we can start the ROS1 application. So source OPT Ross, noetic setup Bash. And of course through project for us one dual setup bash. In that terminal, we are simply going to try to access the topics and services from the ROS1 application and from Rostow. So cross foxy setup dash, project across to brush. I need that because inside there are the crystal messages. We need. Any ROS1. I can simply now start the application like we did before. So ross launch my robot bringing that'll SIM project that Lounge, which will start the obligation. You can see a bunch of messages from their OS1 rage and know from Ross to I can do Ross to pick list and rose to service list. Great. And as you can see, we can get access to all the topics and services that we have running on our ROS1 application. So for example, Target coordinates, I can do Ross to peek equal target coordinates. And when there is new target published on this topic, we receive it right here. Okay, So I will kill that everything. And know the first step of the project is done. We have built a binding between our ROS1 environment and our Ross to environment. And we are able to get access to our ROS1 application from Nero's to underwhelm it. So now we are finally ready to start writing some code inroads too. 45. Step 2: Port the Target Publisher Node: This is the step two of our turtles in project migration. So in this step, I'm going to start to port some code from Rossman to Ross to OK. Actually we have two different nodes, target publisher and tell that controller. So I will handle the target publisher in this video, and I will do it in Python. Okay, here is the target publisher in Ross one. So that's what I'm going to kind of translating or OS2. And note that I'm going to go quite quickly with the code. Okay? I'm not going to explain all of the rows two functionalities because you already saw that previously indeed schools and also all of the internal functions that are specific to the application and not going to detail every line, okay? If we are just going to use the same functionality, I'm just going to copy and paste the functionality if you want more details, you can also go back to the introduction video. And I also encourage you to explore the code by yourself. All right, so I'm going to work with fears code. And here on the top I have, as you can see, project rose to workspace. And right here I have projects Ross one workspace. So I'm going to need to create a tether symbolic by package first here. Okay? So I can write the node. So to create the package, I'm going to go to the packaging that XML of the ROS1 package just to see what are the dependencies we will need. So harassed by, we will use LCL by my robot messages, we will use my robot interfaces. And then we have dependency to turtle swim and geometry messages. Geometry messages also exist in rows two. So I'm going to need for dependencies here. Let's create the package. I'm going into my project, Ross to workspace in the source directory. And I'm going to create a package. So in order to use Rostow, I first need, of course to source cross two. Okay, because I have removed everything from the Bush asking and rose to be cagey create. Okay, let's name it. Turtle. Project by like we in ROS1. I'm going to specify build type, which will be a month by thumb. And now dependencies. Lcl pi, we will need my robot interfaces that DO seem and geometry messages. Okay, so that should be it. We have a new Akkad Delos in project by. We can go to package dot XML to see the dependencies here. Correct? And now we can directly create the phi for the known. Okay, so city projects. Let's go in the folder that has the same name as you can see, dollars in project by that, although had the same name as the package. And here, target, godly sharp. Let's make it executable. Okay, so we have diet publisher that pi. And to start the node in Rostow, I'm simply going to use the template, okay, that you have, the labeling discourse. So I'm just going to use that template for Python. We also have the riskless one. So we have here, my stone node will be target publisher node. I need to change it there and let's name it target. Sure. So I save the file and I'm going to go to the setup.py right now. Okay? So I'm going to add here one line in console scraped, dug it, publisher. So that is the music table from total seem. Project. By a cage. Name of the file is target coalition. And we are going to domain function. Okay, so now we will be able to build the Perturbagen target publisher will be installed. So I'm going to, but the target publisher in ROS1 here on the side and press control be decried the panel here. Okay, and let's start to translate the code. So if I look at the dependencies, I will need to import random. Ok, so I'm going to import random and I'm going to import the coordinates 2D from my robot messages, which is now from my robot interfaces. Beseech import coordinates to the animals who will be able to use that. The same as here because the field side are the same. But what do we have here in the constructor first we have a parameter. So let's, let's write the parameter, publish into. Here. It is a private perimeter and ROS1. But in fact in Ross to every parameter is kind of private, so we don't need to care about that. First, I will need to declare it self. And just one quick parentheses here in Moscow. This is specific to wheels gone if you don't have the autocompletion, for example, with self here. And that means that maybe you need, okay, you need to close. And open a new window. What you can do is source Ross to PT, Ross. Foxy set of bash can also maybe some projects was to workspace. Okay, and then you can go back to source folder of your workspace. And now you should get the auto completion working VS code, okay, if you don't source your random forest to, in my case, I didn't have the autocorrelation working, so I had to restart again in a terminal that was sourced. Okay. That is the end of the parentheses. So I'm going to declare should work now. Okay, declare parameter, publish, interval. And I'm going to put a default value, also 3. And then I'm going to do publish interval itself, get parameter, publish interval and then dot value. Okay, don't forget the very important. We now have a pollution. Erb. Let's keep the same name. So auras pay publisher, we become self create publisher. We need to give first type the name of the topic, target, coordinates. And then AQ side also. I am going to do some colon formatting. So we have initialized the publisher. And now I'm going to initialize the timer. Self timer. So self create timer. We will need to give a duration. Here it's Eros by duration object. Here we just give the publish interval interval. And of course, we need to give a callback Foucault. So we are going just to create a callback now. God-like, we'd be saying random coordinates. Well, I am just going to copy this function here. We don't need that parameter here, event known that was only needed for the Ross when timer. So I'm just going to use that. She's OK. And then I need, of course, the function published coordinates, which will be one. And let's see if we need to change anything. So we create a coordinate to the message we fill them is H and then we publish in Python, okay, the way to publish the message is the same, so we don't need to change anything here. I'm going to put self sane random coordinates in. The timer. Okay, and finally, let's put low self, get logger info. We've target publisher has been studied. Okay, great. It seems that the node has been bolted now. So as you can see, once you know how to translate, Ross wouldn't go into Ross to code, then it's quite easy to do that. I asean Chair anything in the functionality. So now I'm going to build the package so Python music table can be installed. We'll go to Project Rose too. We need to source cross two. And I can do coke on packages, select project, build. So I would be able to use it. And in fact now I'm going to open different terminals. So we would make it work with the Ross went rate. Okay, so here I'm simply going to source Roswell. Start arrows master schools across the bridge. Okay, and let's start the bridge. Ross to ROS1, rage, wage, bridge, all topics. Alright. And I'm going to source for us to here. Plus the Project workspace and staff. The Soros to run. Project. By We've target publisher. Target publisher has been started. But actually if I open yet another terminal here, competent euros, foxy rose to be pleased. Again, see target coordinate here. If I want to listen to target coordinates, of course I would need to also store the products roast workspace. I'm going to call that. And what I can do now, I'm going to go to lunch phi of the rows. What obligation to others in project? So total seem project. In ROS1. These will actually start node to other controller and target generator. So I'm going to comment that line. So now on the ROS1 side, I would only start the delta signal and a data controller node. And to target generator here the target publisher will be from neuroscience. Okay, so let's go back to the terminal. It's phosphorus one. Nordic project was going to kill the knowing Ross to formula. And let's do Ross launch. Right? Robot. Bring up. We've told us Him, project that lunch. So now we should have delta, which is not moving because there is no target publisher anymore. And if I start to know, we will see the total starting moving. Great. So these worked. Right here. We have some part of the application in rows one. And right here we have some bad of the application in cross two. And note that also doesn't seem node. Here. We started from ROS1, but you could also decide to start it from roast. Okay, you start another demo you started told us in Node, in Rostow, you start the diet publisher in rows two, and then you start the dotted controller in Roswell. 46. Step 3: Port the Turtle Controller Node: This is step three of the migration project for the simple rate right here. And in the step, I am going to part the turtle controller here from Roswell into for us too. So I will also do it in Python. I will not provide a video for sibling plus, that will be additional practice for you. And you can also find, of course, all the cplusplus code in a code archive as an additional resource to discourse. So the turtle controller here, I first going to create a file for us too. So let's go into the project was two workspace source, project, Python. Python, and here, let's create total control that by making it executable. Okay? I am going to control that. And also I am going to use the complete turtle control node to the controller node. Here. Turtle controller. I can remove that. And to finish the setup, let's go to setup.py and add a new controller. Turtle project controller, handmade. Okay, so that's it for setup i. And I'm going to put the rows, one total control on the side here. Okay? And lets start writing the node in arose tube. So first let's check the import. Import rose by ok, we have FCF by, we need to import math. Okay? So I'm going to do that math. I'm going to get from my robot interfaces import coordinates 2D, and then from geometry, Mercedes MEG, import twist. So you can see we have the same one in Ross to and from turtles seem that MSG import follows. Okay, that's the message we have which we had some problems and that's why we have build the tunnels and project from source like I showed you previously. So now the data controller is a little bit bigger than the targets publisher, OK. But no Rory, it will not be that complicated. We will simply follow everything the order here. So. We will create a pose objects. Now. Target. Then we have a publisher subscriber, subscriber antenna. Okay, we don't have any parameter here, so let's create all those rows, two functionalities, self, command, publisher, presser, that will allow us to send a command to the total from the depths in node. Says create. First the type B twist. And then we need actually to give the same name here. That doesn't change in Ross too. If you want to be sure, simply start a new terminal and starts the total sum node plus two rows, two topic list, any, we'll see that we have these topic right here. So I'm going to put that and Q sides data. Okay? So we have our common will publisher. Then I am going to create the Bose subscriber. And before that, let's create callback. Callback. Turtle, bows. And self pose will be the message we get. So we will get a pause message from the taller one post, which will directly put inside our pose object here. Both subscriber create the description. So the message would be bows. And then we have the topic name, which is also the same. You can check node. And finally, callback, callback, turtle, bows. And of course, yes, we need to add also lead to size. Okay, next we have a target subscriber. Targets subscriber with call back together. And what do we do here? We check, okay, we make some validation with the data. And then we assigned the message to the target object. So I'm going to actually copy that here. So that line will not change and that one also. But of course I will need to change that because crossbite doesn't exist anymore. Self gets longer. Info. Okay, and that's it. Let's create subscriber, target. There's quaver. Create. Those crucial. Missy will be coordinate 2D line, and we have the topic name, target coordinates, the callback, callback, target, target, and queue size ten. Okay? So for now we'll have to subscribers. And when we get a new target, it goes to the target here and set targets. And when we get a new post from the data, it goes to self bowls. Now I'm going to create a control function so that we can use the control loop timer. So I'm first going to check the control loop function that is quite long, okay? But most of it is just mathematics that you don't need to change. Okay? So if we look at the function here, we are looking at self polls. Well, we don't need to change that ourself diet. So we are just checking that there is a value inside those, okay? And then we compute a distance. We have target, target dot y, x, y, OK, that already exist. So same between rows one and rows two. Then we create a message. And Python that same would create message. Okay, we do some more stuff. We assign some values, like the message, we feel the fields. So message linear, x, message hunger, lousy. Kay? And finally we polish. And I think that we can just take that function here. For the simplest of the message. Of course, the way to write a message is just different here, but for most of the rest, it should be identical. And yes, we can try that and see if we get any error. So now I'm going back to my constructor and I'm creating a time self-control blue timer. Create timer. We need first to give a duration, so 0 and so timer will run at 100 hertz and control loop. Ok, we can now give a log, but we give a message to the user. Cells, get logger info. Turtle, pin. Okay, so everything is correct in the constructor. And we also have all of the callbacks. And the function we need for the timer. In the main, we have nothing else. So let's actually start it. Before we do that, I'm going to install the node. Okay, so let's go to our projects was to workspace, source Ross tune, and do coconut. We'll pay QGIS dialect. Awesome. Project by n. I'm going to add tingling installed. So if I ever need to modify the file, I don't need to comply again. Okay. And now we can try it. So I still have the four different terminals here. I have ROS1 sourced wave Ross master. Here. I am going to start again the Ross when bridge. Okay, so we have sourced raw S1 or S2 and the bridge workspace. Okay? So if you have some arrows like that, okay, means that you previously used some application and then you kill the application and you kill the Rossman bridge. In that case, what you can do is simply kill the raw score also that the raw score again, and then you should not have any error. Okay, great. So I'm going to keep that terminal to start. Some Ros wants stuff in here doing that. And here I am going to split that. So we can use Ross to here. So in that one I'm going to cross towards or resourced. I'm going to close the project because we have a new node. Okay? And actually I'm going to need a, another one here. Okay? So all those terminals, three ones are sourced forest 2n, project roster workspace. And that terminology is already sought for ROS1 ND Ross one project workspace. So now what I can do 0s here start the same or OS to run. Turtles seem didn't seem. Note. That will start the teller SIM window from Ross took. Here, I am going to start to run those seem project Python we target for Lucia, which would publish some targets. And of course it will not do anything because there is no controller. Rose to run. Turtles seem project. We've turtle contour. Okay? And we have an arrow where a z here, I don't put equal. Okay, so I'm going to save that and I can start it again. And that's why you're used. Similarly install it so it's quick to start again. Okay? And it works great. So we have here our first node, node, the controller here, and the target publisher here. So the complete application is no working in Euro's too. And what we can do now in ROS1, We can do ROS topic least rate. We have the topics from data node and a target goal, the next topic. And we're going to, for example, Ross topic, target coordinates and see what it, what is inside. Ok. So where basically you can just knew any combination you want, okay? You could start any number of node here in ROS1, any number of node in rows two. As you can see, the application still works and now the application is completely rewrite and in rows two. And the next step will be, of course to write a launch fire. 47. Step 4: Create a Launch File for The App: This is step four and the final step of the migration of our turtles and projects. So finally, we have written all of the Python code in Ross, took the application can completely work in Ross too. We are now simply going to create the Mayan robot, bring a packaging Ross too, so we can create a lunch finance that everything, we've just one common line. So let's actually do that. Let's create my robot bring up. So I'm going to the source folder of the workspace and I've already sorts Ross to okay, make sure you saw Ross t2 here and willing to Ross to create my robot. So I'm going to name it my robot bring up also, I don't specify any wildtype, any dependency. Okay, so inside my robot, bring up, I am going to remove, include and I'm going to remove and also create a launch folder. So let's configure these first. So in the CMakeList.txt, let's remove that, and let's remove that. I will add install directory. So that is maybe the first thing you want to do when writing some lunch fight. You just install the directory. Well, similar CMakeList.txt so that you don't forget to do that afterwards. Directory launch and destination will be share project name. Okay, that's it for the CMakeList.txt. Now in the package dot XML directly now add the exec depend tag because I already know what are we in this lunch, right? So exec depend. We will need the data simply cage. Ok, and we will need the prepend turtle seem project package. And of course, if you work with cplusplus, you will also add exit depends delta CPV for example. So now the lunch folder, I'm going to create turtles him Project dot lounge that by, for example. And in that long time now I can create my lunch failure with Python. So first, from launch, import. Launch description. Okay. So junior rate launch description, that would be the name we need to give to the function is create. A launch is crucial and returned to launch description. Now I'm going to import from launch Ross that actions import. And I'm going to create three nodes. So first tertile, team node would be node from package teller seem, okay. And executable. Doesn't seem note. And I am going to pad it, LD action. So those similar with. So now I will create the controller. Controller node from pike age. Project by table will be turtle controller K that's added here. Turtle controller node. Ok, so as you can see, it's the same thing, so it's quite simple. And then target, publisher by Cage, project by pigs into table. We'd be target publisher. Also. Add it here. Target publisher node. Okay, great, so I will keep it like this. Okay, very simple and minimal. If you want, you can also rename the node we've name. You can add some re mappings. You can add some parameters, okay, because there is one parameter actually here we keep the default value. And let's start this. So to start this, we'll need to first go back here and do coke on real. Let's do packages, correct? With my robot. Okay, now I'm going back to my terminal. And here I will start the raw score again. We start the ROS1 greed. Okay, I'm only using that window for now. I'm just cleaning that bit. Here. I will. Again project workspace because we have a new launch fine. For us to launch. My robot. Bring up with turtles seem project. And let's check if this works. Yes, this works. So now you have completely migrated cross two application from OS1. And as you can see, so if I start it again, I can steal from ROS1 Eigen still sort of crust topic list. I can still get access to all of the topics and services from the rest to site. Okay. And at that point, you may decide, should you keep the rage are should you just remove the bridge? And now only euros two application is working. And of course, well, okay, maybe start a raw score first. And in ROS1, as you can see now, I don't have access to a turtle application anymore. 48. Project Conclusion - Improvements: Well, you've made it until the end of the migration project. Congratulations. Now you may want to go further with that. So what you can do here, we've just down the migration, we've Python. What you can do is to migrate the project in cplusplus. So you will create the toddlers in projects CBP, okay? And you can migrate step-by-step like we did the code from C plus plus. And also that code, you can find it in the could OKs in the additional resources for this course. If you want to go further, you can also continue to start improving the application. For example, in the launch file you can add parameters remapping that sets or R. And you can add some, maybe you can add one functionary T in Ross to find something that you can add to the application, whatever it is, like a service, for example, or a publisher subscriber. And then try to get access to that functionality from the ROS1 side. And of course, if you have a ROS1 project of your own, well, it is time to start working on migrating the project first to noetic, and then two cross two. 49. What to do next: You have just finished the course. Congratulations. Here is a quick recap of what you've learned in this course. From your knowledge in ROS1, you have discovered how to create complete applications in Ross to using the undergarment, the tools, and all the code concepts, nodes, topics, CFCs, parameters, and launch phase. Then you have discovered the eros when breached package, which is very handy to migrate a codebase from ROS1 two rows two. And finally, you have practiced on everything you so thanks to a migration projects. Now what can you do next? Well, there are a few different answers to that question. Malpractice on the migration will actually not be bad for you. If you have an existing personal ROS1 project you have worked on in the past, then it might be a good opportunity to migrate these project to Ross to following the steps we did for the turtles him projects. You can also now start your own rose to project from scratch. If you don't need to migrate zone ROS1 codebase right now, no problem. You can simply decide to start your next Ross project directly. We've crossed two. And if you are currently working on a ROS1 project, whether it is a personal project, our project for your work, then you can start to design how you will migrate it. Of course, the bigger the project, the more complex it will be. But if you plan everything carefully, you will be able to start the migration while still adding new functionalities in Roswell and n rows two. And anyone working on a project, we'll simply have some additional setup steps to do. And once again, congratulations for your progress in the course. There are actually quite few people that make it that far. Now, make sure you keep practicing to get better and Ross to, and create more amazing robotics projects.