This tutorial demonstrates how to integrate LIDAR sensors into ROS-based mobile robots, covering three key stages: (1) Simulating a 2D LIDAR in Gazebo by adding a gazebo tag to the URDF with a ray sensor plugin that publishes LaserScan messages; (2) Integrating a real hobby-grade RPLIDAR A1 with ROS by running the ROS driver node with parameters for serial port, frame ID, and scan mode; (3) Best practices including serial port management using by-id/by-path identifiers, using launch files for configuration, and controlling the LIDAR motor via ROS services. The video shows how standardized ROS messages enable compatibility across different LIDAR hardware models.
Integrating LIDAR Sensors with ROS for Robotic Navigation
Added:all right let's talk about lidar because you see regardless of what the ceos of any large autonomous vehicle manufacturer might be saying lidars are one of the most valuable technologies in robotics right now in fact in my day job a huge amount of my time is spent working with industrial lidars just like these ones and i love them i think they're great today we're going to be looking at four different things we're going to look at what lidars are and how they're used in practice we're going to look at how they integrate with ross we're going to look at how to simulate a lighter in gazebo and fourthly we're going to see how to integrate a hobby lighter into our own robotics project so what is lidar lidar stands for light detection and ranging and just like we've got sonar and radar for sound waves and radio waves lidar uses light to measure the distance to an obstacle this is really useful in robotics because if we can measure the distance to the things around us we can sense and gain an understanding of the world that the robot is interacting with there are a huge variety of different lidar models on the market that use all sorts of different technologies and come at very different price points but broadly speaking we can put them into three main categories and firstly we've got one dimensional lidar or point lidar so for example i've got this little 20 digital tape measure and i can point it at the cupboard it'll shoot a beam of light and tell me that it is 1.061 meters away now we don't use those heaps in robotics but they can come in handy for example if you've got a uav you might want to point it down toward the ground to measure your altitude or on a mobile robot you could point it forwards and measure how far away you are from a wall that's right in front of you next up we've got 2d lighter which is probably the most common type of lidar you'll see out there these days for this you can imagine taking your 1d lidar strapping it to a motor and spinning it around in circles and as long as you know exactly which direction the laser was facing when it fired you can generate an entire 2d scan plane of points so these are sometimes called laser scanners this is really useful for building like a floor plan of a room that you can then use to navigate and avoid obstacles then finally we've got 3d lidar so unlike the 2d lighter which radiates out in a single plane the 3d lidar is radiating out in three dimensions and it's generating a point cloud of points it's almost like taking a three-dimensional photo now the different models that are out there use different methods and technologies historically they've been very expensive but they're starting to come down in price and these are really useful for when you want to generate a really rich 3d representation of the world around your robot for the robot i'm currently building and for what we'll see later in this video i'm using this hobby grade 2d lighter but if you do want to find out more about any of these industrial lidars if you want videos on how to integrate them with ross and that sort of thing let me know in the comments and i'll be happy to make some videos on them down the track because lidars are such a common sensor to use in robotics ross has really good support for them so when we're working with 2d lidars ross provides for us the laser scan message which is inside sensor messages and basically what this is is it's a big array of numbers that represent each of the range measurements in meters for a single sweep of the lidar it also contains a bunch of other parameters that it needs to reconstruct the scan properly and the transform frame that the lidar is attached to and that lets us figure out where those points live in three-dimensional space which is really handy especially when we want to combine multiple lidars together at once when you're using other kinds of software it can be really difficult to work with different lidar models from different manufacturers because they all speak different language and store their data in different formats but when you're using ros all you need is the right driver node for each different model and that driver will publish a laser scan message and so then whatever algorithms or anything you want to run as long as you write them to work with a laser scan message they'll be able to work with any different kind of lidar that you want to throw at it when we're using 3d lidars or sometimes we've got 2d lidars but we're moving them up and down to kind of create our own 3d lidar then rather than using the laser scan message ross gives us the point cloud 2 message and this is just a random array of points in space so no matter what kind of crazy different designs of light are that you get out there as long as their driver is able to publish a point cloud message then again you'll be able to write software and visualizations that can read that and parse it and so you can use any kind of 3d lidar that you want like i said before in this video we're going to be focusing on 2d lidars and laser scans but in a couple of videos time we'll be looking at depth cameras which are very similar to 3d lidars and will also utilize that point cloud message to start practically learning how we use lidars in ross we're going to be integrating a lidar into a simulated robot now this is following on from a couple of tutorials ago where i showed how to make a mobile robot in gazebo so you can go watch that if you haven't already otherwise you should still be able to follow along so i'm going to open up my workspace that i already have from those other videos you can see here's the files we had last time and the first thing i'm going to do is go to my main robot exactly file and just like before how we added an include for the gazebo control we're going to add another include so this time we're going to create a file called lidar.xacro and so all the stuff that's to do with adding a lidar to our robot we're going to put in this new file so now we need to create a new file called lidar.sacro and as always we'll just take our xml and robot tags and tell it that it's an xml file okay so the first thing we're going to need to add is a joint and a link for our lidar so that robot state publisher knows where it is within our robot so we'll start by adding a joint and we'll call it a lidar joint actually i'm going to call it laser joint you can call it whatever you want and end with the joint tag now for this joint oh and it's going to be type fixed unless your lidar is on an extra motor or something like that so we've got the parent link is going to be our chassis so if you remember from our robot core we had our our chassis link here so it's going to be parented to that then the child link name now we're going to create this in a minute i'm actually going to call mine laser frame rather than laser link it just fits with some of the other standards that get used again you can call it whatever you want then we've got the origin so origin xyz equals we'll go zero zero zero for now raw pitch your equals zero zero zero now where should it actually be well if you remember the origin of our chassis is at the back so we want to go up a little bit and forward a little bit so i'm going to go forward by let's go 0.1 in x and then we'll go up by 0.175 in zed so that should put the origin of our of our laser link so now we need to create the actual link so it's going to need a name and we'll call it laser frame like i said now i'm going to represent my laser by a cylinder and so because i'm lazy i'm going to go to our robot core exactly here and find the geometry of one of our wheels and i'm just going to take that and copy and paste it so we're going to make this one a wheel except let's make it let's go make it red this time so this should give us a red cylinder for our laser now i've just remembered i didn't actually have a red color in specified here in my robot core file so i'm just going to create an extra color for red all right so this should create a a new transform frame and we should have a red cylinder let's see if that worked so i'm going to open up my workspace and colcon build all right so we've built that i'm going to source my workspace in a new tab and then i'm going to run the robot state publisher launch file that i had in the past so now we should be able to run rbis we'll set our fixed frame to baselink we'll add a robot model like normal and there we go you can see we've got our little cylinder there that represents our laser our wheels aren't working at the moment because we haven't got the joint states published but there we go there's our laser so now it's time to get it working in gazebo so we're going to be adding simulated lidar data now you might remember from before that we're going to have to have a gazebo tag that goes along with this link and then we're going to have some other things in that tag now this gets a little bit complicated so i've actually got one that i prepared earlier that i'm going to copy and paste from and then we're going to step through it so i'll just grab that and paste it here now all right so i'm adding a gazebo tag and the reference is laser frames this is adding a gazebo tag that's associated with that laser frame link within that we start off with a sensor tag now the name doesn't really matter but it says it's type ray so this is still within gazebo we're adding a simulated sensor that is a ray sensor so that just means a scanning lidar okay inside that what have we got we've got pose which is zero zero zero we're just saying that the origin of the virtual sensor is at the origin of that link visualize is true so we do want to visualize this in gazebo eventually we'll probably turn that off but it's good when we're starting out and update rate is 10 so 10 times a second we want to update the sensor then we've got these other two tags the ray tag and the plugin tag so the ray tag is going to specify the parameters for the virtual ray sensor so let's open that up we've got scan here which has horizontal so this tells us that it's scanning horizontally with 360 samples a resolution of one and angling from -180 degrees to plus 180 degrees in radians then we look at the range settings and i've got the range set to a minimum of 300 mil and a maximum of 12 meters with a resolution of 0.01 okay that's pretty good so that's setting up the parameters of the ray sensor now we've got a plugin and so plugins if you remember are how we get gazebo to interact with things outside gazebo so name again doesn't really matter but the file name here is lib gazebo ros ray sensor so this is the plug-in that takes a gazebo ray sensor and gets it to talk to ross so open that up we've got the frame name set here as laser frame so that's telling it what frame id to put in the laser scan message we've got the output type as laser scan so telling it that's the type of message we want to publish then we've got this little ros tag and it's just telling it what topic to publish it onto so it's saying okay we're publishing a laser scan message to the topic scan with the frame id as laser frame so we can save that all right so we'll go back to that other tab we had open before for robot state publisher make sure we kill that and now i'm going to launch my gazebo simulator again so if you remember i had a launch file for that so it was called launch sim and i had a little virtual world for it to go into so we'll run that and now you can see it's it's launched it but this time it's got the virtual lidar on top of the robot and it's scanning all of the things oh you can see we forgot to set the color on this so so if we just go back to here on our gazebo link reference we also want to add material is gazebo [Music] red so let's just close that down and re-run it great so now we've got our little red lidar there and just like before we can run a teleop twist keyboard you can check out the other tutorial again for more on how that works and so we can drive it around and you can see it's updating that virtual lidar and so now what we can do if we uh open up rvs again so where is this is the tab i had rv's in so we'll launch rvs again now remember from before uh in the other tutorial we can set that to odom add our robot model and so we can see where the robot is in real space but what we can do now if we go add laser scan and we set the topic to slash scan and i'm just going to bump up the size of the points here to 0.04 and what we should see is all of the virtual laser points that are coming from gazebo so if i bring these over to the side let me try and get these to a similar kind of point of view and if i then use the tele-up to drive it around you can see that the virtual laser points are coming up in rvs in fact i could probably almost make rv's full screen drive around and without even seeing gazebo i can navigate around these cones so it's great that that works for our simulated robot but what about getting a lighter to work on a real robot what we'll do now is i'll be plugging this little lidar into my raspberry pi and getting it to talk to ross and hopefully we'll be able to see points coming out of this from a real lidar in rvs so to start off with we'll just close down uh gazebo let's close rvs we'll just close everything that we've got so far we won't be needing that so here i've got the rp lidar a1 which is a pretty popular and cheap hobby grade lidar now admittedly they are a little bit more expensive and a little bit harder to come by at the moment like a lot of other things but they are out there and so we'll start by plugging it into the raspberry pi using a micro usb cable now it is pretty fussy about which micro usb cables it likes so if you are having trouble try a different cable so we'll see that starts to spin up and now what we want to do is we'll open an ssh terminal connected to our pi so i'm just going to change my terminal profile here the first thing we're going to need is the ros driver for this lidar now unfortunately there's a few different versions that are floating around out there i think because the manufacturer took a little while to update their driver from ross1 to ross2 and in the meantime a bunch of different people made their own ones and they all work i was using one from github for a while but today i'm going to use the one from the app repos so we'll just sudo apt install ross foxy rp lidar ross and apparently i've already installed it but i must have forgotten so now to talk to this later we're going to run the driver so we'll type ros2 run rp lidar ross and then we've got the the node is called rp lidar composition it's a bit of a weird name uh don't worry too much about it and this will run the driver node now this might work out of the box but generally we're going to want to set some parameters so the first parameter we've got is the serial port so serial port and for me it's slash dev tty usb 0.
we're going to talk a bit more about the serial port later if you've got other serial devices connected like an arduino then don't run this just yet then we've got the frame id and so that is what's the transform frame that our lidar's attached to and you'll remember from before that we called ours laser frame so we'll go laser frame then next up we've got a parameter called angle compensate uh you just want this to be true the weird thing is it always says that it's on but it isn't always so we're going to explicitly set that to true and then finally you can set the scan mode you don't have to do this you can check the manual for the lidar for what the different modes are i'll set mine to standard but yeah you can check out the different ones so let's run that and you can see rp lidar running it's going to start talking to the lidar and so what this is going to be doing now is it's publishing laser scan messages from this lidar to the scan topic so i'm going to go back to my other terminal here and we can run rvs and just like before i'm going to add a laser scan so we'll choose the scan topic now you can see here it says status okay but we're still not seeing anything it's because we've got to select the right frame because we haven't got robot state publisher running at the moment it doesn't know what frames are out there so i'm just going to have to type laser frame myself and we'll make these a bit bigger again and as you can see there's the lidar points so if i just rotate this hopefully you can see me you can see the room if i open up that door you should be able to see that in the picture so there you go we can run the driver we can publish laser scan messages from our lidar ready for rvs or a slam algorithm or any other ros node to listen to and act on before we finish up though i'm just going to give you four more tips for when we're working with this so firstly is the serial port now like we saw before i was setting the serial port to slash dev tty usb0 but if you've got other serial devices maybe an arduino like i've got for my motor controller they're not always guaranteed to come up the same and so what we can do if we type ls slash dev serial you can see we've got buy id or by path so if we look at buy id you can see here i've got the option of usb silicon labs blah blah blah blah blah that means our lidar so if we had an arduino plugged in it would have a different name and we can use that to specifically select it the other option is we can do by path and again there's this weird long name it's not that nice to read but if if we plug in the lidar to the same port every time then it will always come up as this and so you can have the arduino plugged into one port the light are plugged into another port you could even have two lidars plugged in and as long as you specify that path by path then you should be able to do it sorry i just had to clear that i messed it up a bit so let's get that path again slash dev serial slash by path there it is so we'll get our driver and now instead of slash dev tty usb0 we can take slash dev slash serial by path and now we want that serial object and as you can see it still works the next thing we might want to do is to stop the motor we might not want it running all the time we might want to save battery so coming back here to our development pc it could be on the raspberry pi it could be on a different pc on the network the driver node gives us a service for starting and stopping a lidar so we can type ros2 service call and now we should get a list here we've got start motor and stop motor so if we type stop motor now the type we can see is a empty message and then we'll just give it empty braces and you can see the motor stopped and then again we can run it with start motor and start the motor back up again so a third tip is using launch files just like we do with everything else we can create a launch file that contains those parameters for us so it makes it a bit easier you can also use a params file to do it but i like using launch files so here i've just got it in the root of my robot workspace i will put it inside the articubot one repo that i've got but for now it's just in there so you can see it's just pretty simple it launches it with those four parameters that we had before so if i go back to here i can type ros2 launch rp lidar.launch.pi and it's working just the same as it was before the last thing is sometimes this node can get locked up easy like right now if i hit control c it'll probably stop it but sometimes it gets locked up and if it does then you'll be able to kill it by logging in on another terminal and typing kill all rp lighter composition and now you can see that's process has died so if it locks up you just want to run that having a lidar attached to our robot means we're going to be able to use slam algorithms to generate a map of the environment around our robot and navigate it autonomously before we get to doing that though we're going to add a couple more sensors to our robot so in the next few videos we'll be looking at how to use cameras and depth cameras with ross so make sure you subscribe so that you don't miss out on that and like i said before if you are interested in anything more about these lidars especially how to get them going with ross then let us know in the comments and maybe i'll make some videos on them down the track otherwise i'll see you next time [Music] you
Up Next

ROS 2 Jazzy: Autonomous Docking with AprilTags and Nav2
@automaticaddison
2K views•2025-06-26

IFS Therapy Demonstration: Complete Session with Unburdening
@IFSCA
95.9K views•2021-01-13

Robot Navigation with Nav2 and ROS: A Complete Guide
@ArticulatedRobotics
173.1K views•2023-01-06

Game of Thrones Opening Credits: A Cinematic Analysis
@gameofthrones
46.3M views•2011-04-18
Related Study Plans & Knowledge Roadmaps
Structured learning paths in General & Interdisciplinary Studies



















![[Làm quen với Gazebo - Python] - Di chuyển robot trong môi trường Gazebo - HowKteam.com #howkteam](https://i.ytimg.com/vi/Rv-IxODQSUo/maxresdefault.jpg)


















![[3D Point Cloud Data Processing] Capter 10. Overview of Deep Learning on Point-cloud](https://i.ytimg.com/vi/EPdlJ7WndMU/maxresdefault.jpg)