ROS2 Nav2 - Navigation Stack in 1 Hour [Crash Course]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome to this crash course on the navigation to stack with rostu who is this crash course for well if you have learned ros2 and want to start navigation from scratch or if you have already started with nav2 but you feel completely lost this is for you it is not an advanced course okay it's ready for beginners or for those who want to get a good refresher of the basics and what will you do well you will first install the nav2 stack on rods to handle then you will start directly to generate a map with slam after this we will check what's inside the map and then use this map with the navigation to stack so that you can make a robot navigate inside the map and to do all that you actually don't need to buy any hardware we will use the simulation of an already configured robot the turtle 3 on gazebo to be able to follow the crash course make sure that you have installed Ros to handle on Ubuntu 22.04 I'm going to add a link in the description to do that if needed and it's going to actually work better if you have installed the Ubuntu as a dual boot not in a virtual machine where you might have some issues especially when we run gazebo you will also be able to progress faster if you already have some basics in roster such as the command line tools topics and services now this crash course is great to get you started and if you want to go further and dive into more details about the nav2 architecture build a custom World adapter robot for nav2 or even program with the stack using python then I have a much bigger course for you which contains 6 hours of video content and practice activities you can find the course Link in the description below alright and now let's get started with nav2 what is the navigation to stack and why do we need it before we get started let's just be clear on the terms we are going to use when I talk about navigation navigation to nav2 well this is all the same I am talking about the navigation to stack in rows 2. unless I specify that I talked precisely about navigation 1 and Ros 1 then when I say stuff like navigation and Ros I am targeting navigation 2 and ros2 alright so why navigation or navigation 2 well let's take one step back and talk about rosto itself why do we have Ross and why do we use it the main benefit of Ros is that you can create the base layer of your robotics application super fast Ros provides a standard for robotics applications that you can use on any kind of robot and basically this will allow you to avoid Reinventing the wheel and instead work on the high level functionalities of your robot you also benefit from a strong open source community and some Plug and Play packages that help you to add functionalities faster so once you know Ross you can really speed up your development time and you might be thinking well all of that is great but from this point how do I make a robot navigate because there is still quite a big gap between using roster and making a robotnavigate so if you were to implement all that by yourself it would take a lot of time and effort fortunately we have the navigation stack here we will use the navigation 2 stack with rostu which is the successor of the navigation 1 stack with ros1 and what is the stack by the way well it is simply a collection of packages that is designed to achieve a specific goal and what do we want to achieve exactly with navigation that's an important question to ask well the main goal is to make a robot move from point A to point B in a safe way so basically to find the past that allows the robot to reach the destination while making sure that it will not collide with other robots with people and obstacles it's quite important that you don't hurt people and that you don't damage the environment or the robot to achieve this we will do a two-step process first we will create a map of the environment using slam and in a second step we will make the robot navigate using this map all of that using the navigation functionalities and tools and I'm going to go into much more detail about this during the course and once you understand how it works you will also see that you can easily integrate the nav2 stack in your ros2 application for example from an independent python node you can give comments to the stack and make the robot navigate just by using the standard roster Communications and some simplified apis that we will discover and experiment with alright and now let's start the course and let's install the navigation to start okay in this lesson you will install the packages for the navigation to stack that's going to be super quick actually as you will see just make sure that you have correctly installed and set the browse to handle on Ubuntu 22.04 so if I print the end of The Bash SC in my home directory I should have this line here those opt Ros handle setup.bash so if you don't have this well please go back to correctly install and set the pros2 and now to install the navigation stack well we just need to install a few packages so we are going to do sudo for Studio apt update to make sure that we have the latest so all packages are up to date and so we have the more recent sources and now we can do pseudo apt install and we will install first Ros Dash Hangul Dash navigation 2. so you can press tab as you can see here navigation 2. and then we will also add Ros Dash angle Dash nav 2 Dash bring up okay so we need those two packages to be installed and actually um those are not going to just install two packages okay it's going to install a collection of packages that contains everything you need in the navigation tool and there is another thing that we're going to add is turtlebot 3. I'm going to come back to the starter but 3 a lot in this course this is a robot okay you probably already know the turtle 3 but if you don't that's simply a mobile based robot and what's good about this robot is they have a complete simulation already working so we can work on the navigation and try to understand the different concepts without having to run a physical robot okay we can use a simulation that's already done for us so that's super super convenient so I will install with Ros Dash humble Dash Turtle bot 3. and I'm going to put an asterisk okay so we can install all of the terrible three packages okay so make sure you don't forget this okay so in the end we have those three packages I'm gonna press enter and well I have uh zero new to install because I've already installed it before but for you that's going to be probably a few hundred megabytes of packages to install so you wait until the end and well that's all that's really all there is to it now you have the navigation to stack enter turbo 3 installed on your computer before we start to use slam to generate a map let's actually start a robot in a simulated world and for this let's use turtlebot 3. later in the course I will also talk about using navigation with a custom robot but the thing you have to remember right now so one very important thing to have at the beginning is simply a robot that can move in an environment using ros2 of course and with a teleop node or something similar that you can use to make the robot move either autonomously or with a keyboard a joystick Etc and well good news for you everything is already done with the turtlebot 3 so in this lesson I will just show you how to start the turtle 3 in a simulated world and how to make it move so that in the next lesson we can do the slam and generate the map and that's something very specific to Turtle but 3 is we need to First specify the total 3 Model that we want because there are a few models there is the Burger model there is the waffle and there is the waffle pie with Raspberry Pi so we just need to specify which model by exporting an environment variable that's very specific to thought about 3. and to do this well I'm simply going to go to my bash s so you can just edit the bash RC and you go to the end you should have this line of course and after this I will put so after or before actually it doesn't really matter I will put maybe just before so we have all the export before the sources export Turtle bot three underscore model so all uppercase is equal and let's use waffle so you type exactly this export and then third robot 3 underscore model is equal to Waffle if you don't have this then when we run the next comment you're gonna have an error saying you have to specify a total three model so let's save okay and you can either open a new terminal or just source so we have the environment variable okay if I do print and and then pipe with grape Turtle you can see Turtle 3 module is Waffle now we are going to start this with gazebo maybe before starting the robot in gazebo let's just run gazebo like this you just run gazebo and well you should have this so make sure that you just have well gazebo here you can check the FPS down there okay so I have 62. if you have something around 60 or if you have something maybe around 30 that's still correct but that's something you have to check that you have something that works here and also real-time Factor should be close to one so if you have this everything is working correctly let's close this actually I would recommend if you close gazebo to do Ctrl C in the terminal and not necessarily to close the window that's usually closing gazebo in a cleaner way all right and now let's start the turtle but three in a simulated world so to do this you can do Ros 2 launch so we are going to use a launch file from what package from turtlebot 3 underscore gazebo so here you can see we can use the auto completion with tab and then turtle board so let's put Auto completion as well that number three World dot launch dot pi and let's press enter and let's wait a bit and we have the total root 3 in this world so the thing is the first time that you launch it it may take some time it may get stuck with the orange pop-up saying gazebo is starting or something like that it may be stuck for maybe I don't know one minute two minutes three minutes but this is normal this is the time for gazebo to load this world for the first time okay so every time you have a new world it may take some time for gazebo to open it so don't worry if gazebo is stuck on the orange pop-up just give it some time okay even maybe five minutes 10 minutes okay just give it some time and then the next time that you run it as you can see here the next time you run it so if I kill with Ctrl C the next time you run it it should be much faster all right and so what do we have here well we have the Robot Turtle 3 here so that's a simulated robot of course okay simplified version and so on this robot we have so that's a differential robot with two wheels okay there's two wheels that are going to make the robot move and we have a lidar here you can see with a scanner so let's go up a bit and you can see this blue thingy here is where the lighter can see basically so the laser scan so you can see it has a range of I think it's something like four meters and so the range would stop here and if you have an obstacle you can see we can detect the obstacles so the walls the obstacles everything and so with this we will be able to map to create a map of this environment and the world here well that's a very basic thought about three world that's the closed World okay so the robot will not be able to go outside just inside with those obstacles so no well that's great but what do we do with this well we can make the robot move so let's open a new terminal and we can start a node so for us to run this time not launch for us to run with Turtle but three underscore tiliop and teleop keyboard so this is a node that will allow you to make the robot move okay and so you can see we have a description here that says well you just use the keys in the keyboard to make the robot move and so if I press on W you can see the robot starts to move okay the more I press on W you can see the more we increase the velocity and we can go up to here we can go up to 0.26 meters per second now if I press so I need always to focus on this window if I press S I can stop okay so s is a very important key to make the robot stop then I can make the robot rotate okay with um A and D so rotate on the right to the left and then rotate to the right okay I can go well and go quite fast and S to stop and of course I can make the robot move and rotate at the same time so well I encourage you to try a beat okay get the hand out of it it's not super intuitive at first but just practice for five ten minutes make the robot move a bit everywhere and what I recommend is usually I go straight so I will go straight and I would make the robot turn just a bit and then I would stop with s and then continue maybe turn not too fast like this okay stop and then go straight maybe turn a bit okay and this way I can make sure that I go everywhere and I don't bump into obstacles okay because if you burn let's bump into an obstacle Let's Go full speed into this obstacle you can see what's happening is that well the robot will just have some issues and the laser scan will have some issues okay so if the laser scan is not staying on the X Y plan here we're going to have some issues with the map and the localization so let's try to keep the robot stable okay and last thing is if you want to understand a bit what's happening let's open a new terminal zeros to topic list you can see that so here we have all of the topics running currently and we have this command velocity so the robot will listen to comment velocity with a controller that's going to make the robot move and then the teleop node will send a message on this command velocity with rqt graph so if you run rqt graph you can see so you can refresh you can put nodes topics all here instead of nodes only and you can see we have the teleop keyboard sending a comment to Common velocity and then we have total 3D drive that's a node that started inside the launch file okay that we have studied for total about three so you can see here how this node will control the total and great that's what we need first okay a robot in an environment and we can make the robot move and we have this uh lighter okay so we have a laser scan that we can use to create a map and well you are ready to start the slum in the next video in this lesson you will see how to generate the map with slam using the turtlebots 3 simulation that we have just seen before so the important thing to have right now is a robot either in a real or simulated world and a way to make the robot move in the world and that's exactly what we have so let's start the slum and first what I'm going to do is I'm going to stop everything so Ctrl C in all the terminals okay when you start slam I would suggest that you kill all of the Royals 2 notes running and you just start everything from scratch so here let's open three terminals on the first terminal we are going to so we are going to run the data battery gazebo with third level 3 world so we start here again the world with terrible three and we have this okay so the terrible three starts here okay so that's what we need on the second terminal I am going to start the slump feature for the turtle with three and so we will do Rush 2 launch Turtle but three underscore cartographer and then cartographer.launch.py okay so this launch file contains the slam feature for total three and we are going to also use so use sim time we are going to add this argument true okay so we can use the simulation time because here we are using gazebo so we have a simulation time and let's use this when we are running slam with gazebo I'm going to press enter and what you should have is actually a here obvious starting to have this is another software that's quite useful in ros2 and you can see here we have a start of a map okay so we have a start of the map that's being generated with actually what the so the data that we have from the laser scan you can see it matches almost perfectly and we have a map that starts to be generated the goal here will be to well generate the entire map and to be able to save it so gazebo here just to make sure that you understand the difference gazebo is just to replace the real robot so either you start a real robot in a real world or you start a robot so a simulated robot in a simulation world so this includes all of the physics okay the inertia the gravity everything and then obvious is simply a tool you can see with a lot of options on the left to just have a visualization tool for so 3D visualization tool it's not the simulation itself the simulation is in gazebo the office is just a tool so that you can easily do a map for example easily do navigation okay you have a lot of tools that will help you during the development time of your robot or your application alright so we have Terminal 1 we have studied gazebo with turbo 3 Terminal 2 we have studied the slam with Avis Terminal 3 we are going to start the teleop node in order to make the robot move okay so now we can make the robot move and let's uh put this on the side so if I press W here so the way let's put 0.3 0.03 in velocity you can see the robot starts to move in gazebo and also in Avis we can see that the robot so we have the TFS I'm gonna come back to this a bit later so the transforms start to move and the map starts to be generated with the data that we have from the laser scan okay so you can go back here and well we can increase the speed and we go bit right a bit left you can see when we rotate I can stop can rotate a bit when we rotate it also helps to clear the map okay and so the goal here is simply to have so I'm going to stop you can see now we have almost so white pixels here I have white pixels and then black for obstacles walls and gray is still unknown okay so the goal will simply be to have everything White okay so all of the free space should be white and we should have all of the obstacles with the walls and the objects in the middle so we are just going to move the robot around and before I finish the map I'm going to show you well some of the issues that you may encounter so let's say that you turn too fast if you turn too fast you can see so the robot is turning very fast and Avis may have some issues so here it's still okay in this map but obvious may have some issues to correctly um create the map so I would say don't turn too fast yes just because this world is very simple okay so let's stop and then let's see what happens if I bump into an obstacle because the map is generated thanks to the laser scan data and the laser scan you can see it's um if I go here it's in a plan it's in a 2d plant okay in X Y plant now if I bump into an obstacle we are not going to stay in this plan so let's go straight okay let's just bump into this obstacle and seeing how this what we have you can see the robot [Music] he will actually went okay the robot is going a bit crazy now and you can see the map you can see the data for laser scan is going a bit also crazy and surprisingly here well it's still working again because I think this map is very simple but for more complex maps you can see here we have some weird weird data that we can maybe clean later but for some other Maps you may have some issues so what I'm just gonna stop the robot here okay and if you have some issues and the map is completely broken well you can always stop everything so I will stop this Ctrl C Ctrl C and Ctrl C and start again Okay so down the first terminal with gazebo and then start the slam you have this here and then start the therap keyboard okay so what I've shown you is just a bit of debugging just in case later you have those issues okay and you can see when we start again well we start from the initial position here and also the map is starting from scratch so now let's just finish this map so what I do usually I will go straight not too fast okay not too fast and I will make some small rotations here I will turn a bit on the right and turn a bit on the left okay and maybe when I'm here I will stop you see I'm here I will stop and I will also turn a bit left and turn a bit right you can see it's clearing the map a bit okay and then let's stop and let's go straight full speed and okay let's stop here maybe and let's also turn left a bit and top come back right okay I'm gonna stop and now what I'm gonna do is let's go straight and let's turn a bit and I'm going to finish the map I'm just going to go through those points here okay and now I have a result that is satisfying enough okay so I'm gonna come back to this map just in the next lesson to explain you more about this but you can see well we have white white pixels here for free space and then we have black pixels for obstacles and gray is the unknown so it can be the outside or it can be also the inside of an obstacle because we don't know exactly what can be here for example you don't need to finish perfectly perfectly every pixel of the map okay that's not really important for example here you can see we are missing a bit of this obstacle here but that's really not a problem that's not going to be a problem for navigation okay you don't need to have everything perfect if you want you can but that's going to take more time and here for this map is quite simple map this result is really enough so now what we're going to do is to save the map okay because on now the map is not saved anywhere and if we stop here the slum then well we just lose the map so make sure that you save them up correctly before you stop everything otherwise you have to do everything again so let's open a new terminal here and I will [Music] so I am in my home directory okay and what I will do is I will create maybe let's create a directory mkdir Maps so that when I generate Maps I will just put them into my maps folder and then to generate the map you will do Ros to run nav2 map server okay and then map saver CLI for command line interface okay so rush to run nav2 map server map saver CLI and then you can provide so Dash F you can provide where to the path and the name of the file so let's put Maps let's save into maps and let's name it my map just like that you don't provide an extension here let's press enter and you can see this so we should have something like this creating configuring map saved Etc if you have an error here just run this command multiple times until it works because it should work at some point and now so if I go to maps you can see I have mymap.pgm and mymap.yaml so we have successfully saved the map and what I can do now is I can stop this so Ctrl C Ctrl C and Ctrl C and the map is now saved you've already made a lot of progress congratulations now we are about halfway through the crash course I hope that you are learning a lot and I also hope that you like the crash course if you find it useful then you might want to check out my bigger navigation to course which contains more than 6 hours of structured video lessons and which will take you much further into the understanding of the nav2 stack I will leave a link in the description if you are interested alright and let's continue with the video okay great we have now generated a map but what exactly is inside this map in this lesson I will show you the most important things that you need to know about the map so we have I'm going to open a file manager and in maps we have saved our map and we have two files first you can see we have a PGM file which actually you can see that's the image for the map okay and so we have three different colors here for the pixels we have white we have black and we have gray so white means three space black is an obstacle or a wall so something you cannot go into and gray is unknown so as you can see everything that's outside is unknown we don't know what's behind those walls and everything that's also inside the obstacles is unknown okay so this map is going to be loaded later on when we run the navigation and we can use this to actually find a path to a destination easily so we have this image file and then we have a yaml file so let's open with jelly for example and in this file we have several informations so first image is well the path so the relative path to the image file then the mode of the image was not very important here and then the important parameters here we have the resolution the resolution he is in meters per pixel so you take one pixel here one pixel and it's 0.05 meter so which means 5 Centimeters so for each pixel of this map we have five centimeters so we have a five centimeters precision so is it a lot is it not a lot well it depends here when you are doing navigation with a mobile robot five centimeters can be really completely enough think about when you move yourself inside a flat or in an office when you pass through a door you probably don't try to pass as close as possible to the door you just give yourself some margins maybe I don't know 10 centimeters 15 centimeters on each side okay you don't try to be as precise as possible you just give yourself some margins and everything works fine okay so five centimeters for navigation well depends on the cases but for this case and for most of the basic cases is going to be enough and also of course the more you increase the resolution the more computations you will have to do so that's the trade off to think about but for now five centimeters is you know then we have the origin which is the coordinates of the lowest left point on the map so here in this map in this image we take the lowest left Point here and well if you remember the robot actually the initial position started around this position here and actually the image was rotated like this so the lowest left point on the map is still actually this one okay because I've rotated the image and if you remember also the X was pointing forward and the Y was pointing 90 degrees to the left okay so we have the x-axis here and the y-axis here if we take this point and we go minus 1.24 on the x axis we're going to arrive somewhere here and then minus 2.39 on the y-axis we're gonna arrive right here so basically it's the link between these points and that point where the robot started so that's the origin of the map then negate is zero here if you put one that's gonna simply negate so inverse all of the values so everything that's white is going to be black and everything that's black is going to be white not very useful in our case and then this occupy threshold so the thing is we have here a clear separation between so that's black or that's white okay so black is an obstacle white is free space but in the end it's all about probability it's about the probability that one pixel is occupied or not and so here the setting is that if a pixel has a more than 65 percent chance so probability of being occupied then it is considered as occupied if the probability that the pixel is occupied is less than 25 then we consider the pixel as not occupied and in the end also here you can see that well those values that we have here are simply so each pixel is going to be a shade of gray so from complete Black back to White and each pixel will be a value between 0 and 255 and so if a pixel is more than 65 percent into the black Direction out of those 255 numbers then it's going to be up to occupied if it's less than 25 percent out of those 255 values is going to be not occupied okay so you have some infos about what is the map I would say here the most important information to remember is this resolution thingy here and one other thing we can do so let's just open the map so let's open mymap.pgm with Nano to see actually what's inside and what we have a lot of characters that actually the image but at the beginning you have something like P5 and then you have this which represents actually the number of pixel of the image so it will be like this original image so we have 124 pixel and x and 116 on the Y so now if you multiply let's multiply the number of pixels so 124 multiplied by zero point zero five that's the resolution which means that the map is 6.2 meters long here so including the gray area and is so let's do 116 multiplied by 0.05 is equal to 5.8 meters so you have the exact dimensions here of the map so if you want to know the dimensions you can compute it like this easily you find the resolution you find the number of pixels and then you can just multiply them and you have the dimensions in meters all right so that's pretty much it above the map we don't need to understand everything right now it's just to help to well to get some ideas about what you just saved and now this map is very important because that's what we're going to use as a base to navigate in the next section and before we get started here there is a quick fix we need to do the thing is there are still some issues with the navigation to stack on Ross to handle in the following lessons when we load the map with the navigation stack it may happen that the map is not loaded correctly or not loaded on time and this will prevent you from going further I have personally experienced those issues and have found some fixes on the wonderful internet and well I'm gonna show you that now so you won't have to brush your head against your computer in the following sections I have done that for you already so make sure you watch this video Until the End and make sure you do exactly the same steps as I do we actually have two small things to do first we are going to change the DDS from Fast DDS to Cyclone DDS to make it quick ros2 communication is based on DDS and I'm not going to explain DDS here you can check that on your own if you want to but that's not very important for this course what's important is to use the right one that will allow us to make the navigation to stack work correctly so to install a cyclone DDS we will do sudo apt so you can do a sudo ft update first okay and then you can do serial apt install Ros Dash humble dash rmw dash cyclone DDS Dash CPP okay so you can press tab for auto completion here and let's install this package so for me it's already installed I've done that previously for you it's going to install the package and then once the package is installed we actually need to tell ros2 to use this DDS and to do this we need to export an environment variable so instead of doing this for every terminal that we use let's actually go to our bash SC let's edit the bash RC and here we have so we already have an export for the total 3 Model we have this source for the global roster installation and let's just add an export here okay let's put all of the export before the source and we can do export so you type exactly this and then uppercase rmw underscore implementation implementation make sure you have the exact same thing is equal to R and W underscore cyclone DDS underscore CPP so export rmw underscore implementation is equal to rmw Cyclone DDS CPP with all underscores you can save The Bash RC and then we're going to close this so basically there is an issue with the map and the navigation that is not correctly working with the default DDS funnel for us to handle the fix is to change to Cyclone DDS which makes things work much better and the second thing to do is to modify a parameter file where the turtle but 3 navigation package is installed so clearly that is far from ideal and if you upgrade this package with sudo apt upgrade later on you will maybe have to do this step again the thing is this fix is probably temporary we just need to do it until the release version of the package that will work correctly so let's clear this and let's go to slash opt Ros humble so this is where Ross to handle is installed and if you want to get access to parameter files for different packages you need to go inside the share folder here and you will have well you have all the packages that you have installed and now we can go to so we can do CD Turtle bot 3 navigation two okay so now we are in the package of navigation two photo three and you can see here we have so we have launch folder you can find the launch file here also param so we can go to param and we have the different parameter files so yaml files for the different versions of the robot and the one that we are using is waffle.jaml so we are going to edit this one and to edit here you need to actually use pseudo okay because we are not in our home directory so sudo get it for me you can use whatever text editor you want waffle Dot yaml okay and you will search for robot model type okay so you can do Ctrl F to search for robot model type and we are going to modify this one and so here if you have differential written like this you need to modify it we will actually use so what I can do is just comment like this okay you can add this sign to command the line so you just keep it just in case you want to go back and you just modify then to nav to underscore amcl and then colon colon differential motion model like this so nav2 amcl all lowercase colon colon with and then uppercase the differential uppercase M motion and uppercase M model if you already see this here in this file then that's fine okay you can just continue without modifying anything but if you don't see this then please modify this line okay this is well this is a fix that also I found on a GitHub issue relative to this terrible 3 Robot so you can save okay make sure you save the file and make sure you have exactly a return the same thing okay that's very important if you have one typo that's not gonna work and then you can close and what I really recommend you to do so first you can close the terminal and open a new one but what I already recommend you to do now is to reboot your computer okay make sure you reboot so that well you can be sure that everything is going to work correctly let's now make the robot navigate using the map we will continue with our turtle.3 example here and so to start the navigation to stack to make the robot navigate we first need to start the robot so we are going to do Rush 2 launch turtlebot 3 gazebo and then third robot 3 world dot launch.py so this we have done it previously also with the slam okay that's the first step you need to do always so we start the robot is going to start the robot in the world okay so we have the world here we have the robot we have the Lida with the laser scan that's correct okay so everything works correctly now we go back to the terminal let's open a new terminal and here we are going to start the navigation for the robot so to do this we are going to do Ros 2 launch and turtlebot 3 underscore navigation so underscore navigation 2 actually and then navigation2.lounge Dot py I'm going to explain this launch file a bit later in the course so this launch line will contains all the things you need to run navigation for the robot and then we are going to also use so use sim time with colon equal true so we use the simulation time because well we are using gazebo so we are using a simulation we want to also use the simulation time for this navigation that's going to work better and then there is one thing we need to also do is to provide the map okay because well we have saved the map in so if I open file manager here in maps we have saved the map so we want this one the chatterbot 3 world map that we have called my map okay my map.pgm and mymap.yaml so what we need to do is we need to give this map to the navigation and to do this we simply add another argument map colon equal and we just provide the path to the map relative to where we are right now so Maps we can see we can use Auto completion my map dot yamet we're gonna put the yellow file so Ros to launch and then we go in the package Turtle 3 navigation 2. the launch file is named navigation to dot launch.py we put the parameter use same time to true and then map is the yaml file that we have created I press enter and let's wait a bit so it's going to start Avis like this and you can see here what do we have we have the map yeah so that's the map that we have generated okay that's the image that we have generated with he the origin of the map as specified in the yaml file and so if you start Avis and if you don't have the map so if you don't have this image here right now well what you can try to do is to stop and start again so to stop and start I recommend that you don't just click on the button here but yet you do Ctrl C directly inside the terminal so you can control C here maybe Ctrl C here you can restart the terminals maybe restart your computer so just do those steps if you don't see the map right now but when you see this then that's correctly working and what we need to do first in navigation is to actually give a 2d pose estimate so we need to tell actually to give an estimation of where the robot is in the map so if we go to gazebo well gazebo is a real world the real robot so you know where the robot is it's here okay it's been studied here and and in RVs you just have the map but you still don't have the robot exactly you don't know where it is okay so we will need to click on this 2D pose estimate can you click here and then you can click on where the robot is so let's check the robot is here and so for this case that actually corresponds to roughly about the well this point here the origin of the map that's the same point so we click and we maintain the click and you see we have also an arrow to provide the orientation okay so the robot is actually looking forward so we're gonna put the orientation like this if the robot was looking to the left we would put the orientation like this okay so we put the orientation like that and you should see something like this so what's happening now is we have said in Avis so where the robot is at this moment so then the navigation is going to well localize the robot here and thanks to the data that we have so thanks to this laser scan that we have the robot is also going to match you can see with this small rectangle here it's going to try to match the environment and so when the robot move the robot can localize itself in the map note that for example if I put a wrong 2D pose estimate you can see now it's like we have said that the robot is here but you can see the laser scan data this corresponds to the laser scan data from this from the reality does not correspond to the map okay so if you put a wrong to deposit estimate that is completely wrong here it's completely wrong then things are not going to work so you need to try to be as close as possible to where the robot is so I can put back the closest image right here okay and now you see that I have missed the map a bit okay so if you have this well you could restart but also know that when the robot will go around this area it's going to also automatically clean the map and well about this this well this is the global planner here and this is what we call so it's called the controller but I'm also calling this the local planner and I'm going to explain this in much more details in the next section okay so here we are going to just understand how to work with it and you're gonna maybe understand some things with intuition but you will not understand everything right now and in the next section everything will make more sense because I'm gonna come back to each component here with much more details okay so once we have given the 2D post estimate we can easily see as you can see with this rectangle here so with the controller which is the local planner we can see that things match okay you can see the edges match the upstate article here match so what we can do now is to give a navigation goal so let's say we want to go to this place right here so we click also and we maintain for the orientation that we want to give so I click and you can see the robot will start to move and if I go to gazebo the robot is moving so the real robot is moving to reach the destination and on obvious you can see we can follow so you have this pink line and this blue this small blue line also that's following the goal and trying to reach the goal and then you can see it's going to turn to reach the orientation that we wanted and then well that's it the goal has been successfully reached and so just a quick note on the coordinates you can see that we always have this red green and blue coordinate system here that's also here in gazebo so the red is here the green is here and the blue is here that corresponds to the right hand rule okay so in red we will have the X pointing forward and then 90 degrees to the left we have the Y okay so this makes a plan okay so that's a 2d plan here X and Y and then we have the Z going up okay so if you put your right hand you're gonna see easily with three fingers that's the coordinate system that we're gonna use and you can see that's the same thing here for gazebo for Avis and everything we do later okay and also in the next section I will give you more explanations about those coordinates here why is this coordinate here that one here those ones there okay you will understand this better so now what you can do well you can just give another navigation to go and you can see the robot will move so it will turn it will move autonomously okay while avoiding you can see those fixed obstacles and making sure that you see it doesn't go too close to the obstacle or to the wall okay so you have navigation working and now well let's say that I give a goal that is not valid so let's say I want to go not here but I want to go here what's gonna happen well you see what's going to happen is that well we don't have a line here and the robot is gonna be stuck and try to move a bit okay so if we look at the terminal we have what we have some recovery behavior that I'm going to explain also in the next section the robot is trying different things to well to clear the space Maybe actually there was something on the map here that was recognized as a wall but that is not maybe there is an obstacle that we can clear maybe there is a different path to go to but in the end if the robot doesn't find any possible path then you can see here we have the feedback about it so the goal was about it okay if I do here very simple one you can see the goal will be reached so rich succeeded and if we try to give a goal that can't be reached the robot will maybe try to go but then the navigation to goal will be aborted all right so try to give a few goals and one thing is that if you are starting if you want to start again if you want to start again uh you can start again so you can do Ctrl C here it might take some time so you just do Ctrl C and you wait and then you can start again [Music] you may want to also restart gazebo but here we don't really need to I have the obvious here and we also so you can see we need to give the 2D post estimate again but this time the robot robot is not here anymore the robot is there is there and pointing towards this direction here okay so we need to give a 2d post estimate that's about so you don't need to be super precise but something like this okay and the robots you can see will try to match so you can see I didn't match exactly I didn't have exactly the right position but the robot will try to match as close as possible to the map and now you can see if we give a navigation to go also things should start to be put back in place okay so you can see the the map also is coming back to to the right place okay I know the robot is here and the robot should be well here so to conclude here on this lesson well you need to start first with two Depots estimates once and then you can give some navigation to goals there is a nice and very useful functionality in navigation too that you need to know and this is the Waypoint follower so let's say you want the robot to go through different points okay you want the robot to do a turn around those four blocks for example you could put a navigation goal here okay so the robot will follow this path we can see the robot moving in gazebo as well here and then once the robot is there you would give another goal to reach this and then another goal to reach for example this position with this orientation okay but the thing is you can actually give those goals so the three goals or more goals all at once if you want to okay to do this on Avis you can click here on the left you have navigation tool you can click on Waypoint nav through positive mode so once you are in this menu you don't click on anything here you just click on navigation to go and you got a new goal here and you can see now we have an arrow so Waypoint one and then let's put another one for example here and let's put another one for example where the robot is like this so we have one two three Waypoint and we want the robot to go through all those points and now we can click on start Waypoint following you click here and you see the robot will first go to the first Waypoint and then the robot reaches the Waypoint you can see it will reach the goal and once it reaches the goal it will immediately start the second Waypoint and then the third Waypoint and the path is completed successfully so we have been through three different waypoints you can add as many as you want and the robot will go through the Waypoint there is another mode that you can so you can click also here on Waypoint yeah and instead of clicking on start Waypoint following you can click on start nav through poses this one will try to create a path that goes through all of the waypoints but without stopping so this can be quite useful if you want to go a bit faster but note that this feature is not as stable as the Waypoint following so the normal one where you go through each one one by one okay so let's try this and actually what we have an issue here already so the robot cannot find the path let's cancel let's just click here and click on cancel accumulation let's just give some poses here one two and then um three like this and let's try again start now through poses and you can see it should try to just do everything without stopping so if we look at the robot here as well okay and we have some issues here I don't know exactly what's happening because the path is changing and well this functionality is not as stable as you can see so sometimes it works well sometimes not I don't want to just show you a case that works and then tell you that it's going to work every time actually I'm just showing you that this start nav through poses is not the most stable feature so you might choose to start a waypoint following so the robot is going to stop at each point but you can just give an kind of an array of point and make the robot follow this okay so now you can practice a bit on your own try to make the robot go through different paths through different waypoints okay experiment a bit with those options here all right and that's the end of this YouTube crash course I hope you could learn a lot and get a better understanding of what is the navigation 2 stack and what you can do with it so you have seen how to get to hand on nav 2 but now comes the most interesting part which is to get a full understanding of the architecture behind naft2 and to be able to use nav2 for your own project which means for example to create your own simulated worlds to use the navigation with a custom robot and to make the nav2 stack work with an existing roster application and that's exactly what I cover in this much bigger course which contains more than 6 hours of video content let's have a quick look inside so here I'm inside the course and as you can see we have nine sections in total for six hours of content and well the first section we install roz2 we install navigation to stack and some tools so this you've already done and then we have two sections where we actually do slam okay to generate a map so you can see we make the robot move in the world that's what we've done and then we generate the map we have an extra activity here okay and we make the robot navigate and we have also extra lessons and extra activities to practice on this but then the interesting part here the really interesting part is this understand the navigation to stack okay so we have 40 minutes of explanations here to understand everything that's going on in the stack after this you build your own world for navigation so you will learn how to use the Gazebo building Editor to create a complete customized map so that you can make your robot navigate inside a custom map and then so you can see we have more activities as well and and then I'm gonna talk about how to adapt a custom robot for navigation too okay this is going to be kind of an introduction but still one hour introduction to explain to you all the different steps that you can do here and finally here we will interact programmatically with the navigation stack so you will learn how to do well what we did in Avis okay if you remember we have clicked on some buttons to do the to depositimate and to give a navigation goal but here you're gonna do that directly from your own code so you can completely integrate the navigation to stack into your existing roster application and so we discussed not only will you get a much better understanding of the stack but you will also build some experience thanks to a lot of practice alright now thank you for watching and I hope to see you in the course
Info
Channel: Robotics Back-End
Views: 39,471
Rating: undefined out of 5
Keywords: ros2 nav2, nav2 stack, ros navigation, ros nav2, ros nav stack, ros navigation stack, Nav2 humble, nav2 tutorial, navigation stack tutorial, nav2 course, ros2 course, ros2 tutorial, robotics back-end
Id: idQb2pB-h2Q
Channel Id: undefined
Length: 61min 27sec (3687 seconds)
Published: Wed Mar 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.