Building a ROS Robot for Mapping and Navigation #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello this video is about making a ros enabled robot which hopefully at the end can do mapping and navigation now i showed you a ros-enabled robot the turtlebot 3 burger in a previous video a few weeks ago that's got a lidar on the top it's got a raspberry pi inside and another board which is compatible with arduino to talk to the hardware and that robot can do mapping and navigation so it can drive around mapping the environment as it goes and then use that map to go and navigate from a to b throughout an entire building and avoid new obstacles as it goes so that's a really useful thing that i could integrate into other robotics projects what i found with the turtlebot is a lot of the software has been written although it's open source specifically for some of this hardware with quite a lot of complicated coding to look through so today we're going to make a bare minimum robot out of my laser scanning nerf robot chassis with just a bare minimum stuff to get ros up and running and hopefully get mapping and navigation working but roz is pretty hard to learn i've been studying a course at robot ignite academy there's a five day basic ros concepts course another five day calls for navigation there are two free courses that are really good one on linux and one on python coding which are really worth doing and you don't have to put any payment details in to go and do those courses there's also a free book from robotics who make turtle burger which is a pretty good read and has loads of the stuff in about the core concepts of roz but i'm going to try and explain it as i go and try and basically make this robot navigate from scratch or at least with bits of code i found off the internet and other bits of projects and try and work through all the stages and explain the concepts and explain how it works as i go the only changes i've made to this robot since that previous project are of course taking away the nerf blasters for now i have added a raspberry pi 4 which is actually going to run roz and we've already got the lidar all i've added is the usb to serial interface that ships with a lidar and this lidar already has a ros node from the manufacturer that we'll talk about later to power the raspberry pi i've added a usb c power delivery spec usb power bank which is a 20 amp hour one we should power it for ages the raspberry pi 4 can use up to three amps so we need to make sure we've got a power bank that can actually provide that the rest of the robot's exactly how it was before we've got an arduino mega and that's plugged into a usb cable plugged into the raspberry pi for now which is going to power it we do have wheel encoders on each wheel those are currently powered by five volt regulator and the main battery that also drives the wheels and it does that via two motor drivers which take a pwm signal from the arduino and we'll actually drive the motors and we've got the main battery on the other side which powers the motors and that's a three cell lipo so we get 12 volts for the motors and that regulator brings it down to 5 volts for the encoders but the rest is down to software both code running on the arduino to talk to the encoders and drive the motors and also running on the raspberry pi to read the laser over usb and talk to the arduino we're also going to run some software on a remote workstation that allows us to control the robot remotely so we don't need a mouse and keyboard plugged into the raspberry pi obviously it's on wi-fi and we don't want a wire attached to the robot ros itself as i say is pretty tricky to get your head around it's really worth reading that free book from robotics and the link is in the description to this video or doing the training courses if you want to but ultimately it's made of several core components we've got rod core which is a service that runs somewhere on a network connected computer either on the pi or another workstation where everything can access it and that's a bit like a directory where nodes can connect to it and register and then they can discover each other and talk to each other directly some of those nodes are things like the node that talks to the serial interface on the arduino the node that talks to the laser and then some of those are for dealing with building the map and for navigating but before we can even install roz we're gonna have to set up the robot hardware and write some arduino code to calibrate the motor speeds and reading the encoders but before we do that it's time for a quick ad from the video sponsor and that is pcb way pcb way provide both pcb manufacture and pcb assembly under the same roof so you can get them to solder the components onto your pcb as well as make the board itself as well as standard fiberglass pcbs pcb where you can manufacture aluminium pcbs flexible pcbs and rigid flex pcbs which are part rigid and part flexible prices start at just five dollars for ten pcbs and thirty dollars for ten pcbs of assembly but new customers can get five dollars credit and that means you can get ten pcbs for free the first time you order pcb way also offer advanced services such as pcb design x-ray inspection electronic probe inspection impedance control and various certification capabilities including rohs and ul certification find out more now at pcbway.com and i've put that link in the description to this video i'm going to be using their services to actually make some pcbs for my projects in the future but for now let's check out this robot hardware so for now we've just linked to the arduino this is arduino code only we've got a long usb cable that goes to my computer link to the arduino the raspberry pi is not powered up and not connected to anything we have plugged the battery in though so the five volt regulator comes up and we can power up the wheel encoders so i've just written some code and basically this is taken from the arduino playground website which is basically a bunch of interrupt service routines and these read the quadrature encoders to work out which way they're turning and there's two chunks of code for each encoder that works out whether it's turning left or right so pretty much the code is just establishing those input pins and also attaching interrupts to them the arduino mega has six interrupts we need two for each encoder so that's absolutely fine to read the two encoders and all it does is types those answers out to the serial terminal so if we now open the serial monitor we should be to see that if i move the robot around one of those gets more positive and one gets negative and the other way around and if we move the robot forward they should both get more positive and if we move it backward they should get more negative so now we're going to push the robot along one meter i've got one meter of tape measure on the ground here and we're going to see how many encoder counts we register within a meter now obviously we could work this out from the wheel circumference the gear ratio and the amount of encoder counts per revolution but sometimes it's good just to do a practical test and we should probably do that an average of about 10 times and take the average if we could push it 10 meters and divide it by 10 do that 10 times we'd have an even more accurate answer so i've now written some code that will make it drive forward one meter and it does that by using a pid controller to try and match demanding code accounts of what's really there and drive the wheels in each direction so we've got two setups one for each wheel they've just got a gain of one for now and a tiny derivative number and we've got two demand variables that take the numbers from a serial terminal so if i press the character a it will drive forward 14 500 encoder counts on both wheels which is the average i got from pushing it if we press z it'll actually drive to zero that'll make it drive backwards a meter so we've got two pit computes taking the demand position as the set point and the actual encoder position as the input trying to match them and then driving the wheels in either direction on each side of the robot depending on what the value is [Music] so it looks like it drives about a meter although it might be going too far because it's skewed slightly and that's because the dc motors aren't matched so one goes faster than the other what we're trying to get to here though is being able to drive at a particular velocity in meters or seconds which will be specified by a rods node and received on that arduino to make the robot drive at particular velocities so the next thing to do is continue tuning those numbers but we need to regulate the actual motor speed from the encoder counts per millisecond or per second or per 10 milliseconds or some units of time so we can work out the velocity after messing around i am pushing the robot either way and trying to drive a meter in different directions on different bits of the carpet and facing in different directions obviously we get some wheel slip and we get different things depending on which direction we drive due to the grain of the carpet i've actually come out of a much smaller average of 129 encoder counts per 10 millisecond cycle of the code to drive at one meter per second so that would be 12 900 encoder counts in fact per meter and now my pid controllers try and regulate that speed and try and drive the motors at that speed based on a multiple that i put in from the serial terminal so we can drive up half a meter a second or quarter of a meter a second or 0.1 meters a second and we can also rotate so what we've done there is worked out the distance between the wheels half of that which is the radius worked out how far they have to drive around a circle of that particular circumference to get 180 degrees and remember things are measured in radians here and there's two pi radians in 360 degrees so pi radians in 180 so each wheel needs to drive half of the circumference and we've worked out the distance around there to turn one radian and the next little stage on from that is instead of having two variables one for each wheel the demand one and the demand two we're actually going to talk about it in terms of going forward and rotating as variables so we've got a little bit of math that sits in front of that to populate those variables from a demand x which is for driving fall and backwards and a demand z which is for rotating so this is just the code that works out differential drive we're then taking those values from the serial terminal to do various things to drive forward and rotate or just rotate or drive forward and rotate in various directions and stop by setting those variables to zero and the reason we've done it this way is because that's how roz deals with the command velocity topic and the twist message which we'll look out shortly which actually drive the robot so this should be driving forward a quarter of a meter a second so it should take four seconds to cover a metre and stopping and this is going backwards at one meter a second this should be turning at one radian a second and this should be going the other way and you'll notice there's an acceleration and deceleration there which we'll look at shortly so it doesn't necessarily stop immediately but apart from that it seems to be doing it and if we put a ruler on the ground and measure how many rotations it does and how many seconds it takes it seems to be about the right speed so just a closer look at those wheel encoders they're actually mounted on the gearbox end of the motor so normally encoders would be on the other end on the actual motor so they're going much faster however the arduino mega is not necessarily quick enough to read that many counts per second and that's why i put them on this side so they're actually on the output gear after the planetary gearbox and obviously there's some backlash in that gearbox which means that my encoders could be quite jittery so what i've had to do is put quite a high integral value on my pid controllers that makes it a bit sloppy and that's why as well as getting that acceleration and deceleration we don't get too much jitter if we take that away and try and turn the gains up to the amount we need then these motors vibrate and all sorts of weird things happen especially if you pick this up because everything's slightly loose you'll also notice my tyres are quite thin which are these blue tracks here which is probably why there's quite a lot of wheel slip so again accelerating and decelerating helped quite a bit with that but what's really important is to have a robot that's calibrated really well to drive at the correct velocity and rotate at the correct velocity with really well coupled encoders and lots of traction with the ground so it's accurate and we haven't really got any of those things but we're going to carry on anyway if we look at the turtle bot you'll notice that basically the motors are dynamics or servos which are really accurate and it's got really wide grippy tyres which is really good for traction we'll build a better robot in the future but for now we're just going to carry on so now it's time to install rozz and see if we can actually control the robot with a command velocity topic and the twist message and that twist message is going to send us the velocity in meters per second and the rotation in radians per second and i put an operating system on my sd card and booted it and what i've got on here is ubuntu mate version 18.04 so i've got my terminal i can type in unix commands i've got my menu and everything seems to be working as well as that i've also built a ubuntu 1804 workstation and if you don't have a spare computer you can use vmware's free vmware player that allows you to host virtual machines on top of another operating system yes i'm using windows 7 still but that's absolutely fine and i've built my ubuntu 1804 from a boot cd downloaded from the ubuntu website so now i have ubuntu on my pi and ubuntu on my workstation and the reason we've tried to put ubuntu on everything is because we can use apt to install the software and that's the advanced package tool and that means that basically we can type a couple of commands to install roz and everything should install fine without having to compile from source if we put raspbian stretch for instance on the raspberry pi as far as i can tell the only way to install raws is actually to compile it by going to github and getting all the source meeting all the dependencies and then that's quite a lot of hassle if we use apt we can just type a command and it should install everything and install all the dependencies installing rods is pretty easy there's a guide on the rods website and the distribution we're going to use is ros melodic which is specifically intended for ubuntu 1804 if you want to use kinetic or one of the other versions you'll need a different version of ubuntu after that we need to build a catkin workspace which is a specific folder recognized by roz which is where source and new things we download new nodes and so on go before we compile them and build them into ros again it's really important to have some knowledge of linux and some background knowledge of ros so it's really important to either check out the free courses on robotic night academy or read the free book from robotis for the next demo i've connected a spare arduino mega to the raspberry pi with the usb cable and what we're going to attempt to do is read a message on this arduino which has come from the raspberry pi running roz but the message is actually sent from a workstation which is over there somewhere over the network and you'll notice what i've also got on this arduino mega is another usb to serial adapter linked to serial one and that's because we want to debug the data and see what arrives in the serial terminal we can't use the normal usb connector because it's already communicating with ros over this usb cable to the pi so that one's busy and we need another one to debug the data now i mentioned the roz uses various nodes over the network on the same machine and all of those nodes talk to each other and they do that using topics which are like pipes connecting them together within those topics we use a message so in this case we're going to use the command velocity topic which is used for driving robots around and we're going to send a twist message over that topic and that twist message allows six axis of driving in translation and another three in rotation but we're only going to use two of them which are driving forward and backwards and rotation and to get that data onto the arduino we're going to use the raw serial node running on the raspberry pi and then we're going to use the roles library running on the arduino so they can talk to each other but we're going to use a program a ros node running on the workstation which is actually transmitting that data so i've just put some simple test code on my arduino and that's using the ros library and the messages twist library i've got two variables called x and z x is going forward and z is rotating we've got a node handler set up for ros and also a callback which gets run whenever it receives a message we've created the subscriber here to that messages twist on the command velocity topic and down here we're using the other serial port so in setup we just opened serial one because obviously serial zero is in use by rods connected to the raspberry pi we've initialized our node and we've subscribed to the topic and then all it does is prints out x and z to the serial terminal spin once means it will actually respond to messages otherwise it does nothing and a delay of 10 milliseconds so that code is running on the arduino over here connected to the raspberry pi and i've run a command on the raspberry pi to bring up the raw serial node and for the sake of clarity i've done it with this keyboard and mouse and this screen even though i could of course ssh on remotely and screen record it i'm just going to use this screen and keyboard so we're clear about where it's running and that command is roz run rolls serial python serial node pi and if i launch that it should say that it's connecting to the arduino on dev tty usb0 and also that it's then set up a subscriber which was in the arduino code on the command velocity topic for the twist message and i should know that i've already run the roscore on the remote workstation so over on my workstation which remember is a windows 7 machine running a vm running ubuntu 1804 which i've also installed ros on i've run my roscore which i did by typing roscor i'm also running a teleoperation program which publishes on the command velocity topic with the twist messages and i did that with this command here and you can find that on the rolls wiki also plugged into this machine is that separate serial port on my arduino mega so i can debug the data from my arduino sketch on serial one so now if i go and press the i key we should find that this changes to a half and if i press q and zed we should be to increase the speed and turn it down again and we can also turn sideways by using the other keys so we should see here the value in radians when i use the other keys to turn sideways or any other combination so now we can publish that command velocity topic on the remote workstation receive it on the ros serial node on the raspberry pi and get it into a variable in the arduino using the roz library so the next thing to do is plug the pi back into the arduino mega on board and drive the robot around so i've combined that ros code into my original code and i've also constrained those values because half a meter a second is quite quick so i've constrained it to quarter of a meter second max speed and one radian a second rotation so now i can drive the robot around with the keys and that seems to work pretty well it is captain speed as i say but we can do all sorts of things like drive in a circle go straight go left and right pretty normal stuff even though i'm trying to drive at half a meter a second the code on the arduino is constraining it so it only goes slow but i think that's probably fast enough for mapping and navigation that's all i'm going to do in this video but basically we've now got a ros control robot we can drive around by sending a message over a ros topic and it should drive at the velocity we say next time we're going to be looking at the actual laser and also getting odometry data from the wheel encoders to give to the navigation stack as well as a transform which is called tf so if you'd like to subscribe to check out part two they'll be coming up in a week or two then please do if you'd like to support me through patreon or youtube channel membership then those links are in the description below all right that's all for now [Music] [Applause] [Music] you
Info
Channel: James Bruton
Views: 106,709
Rating: 4.9509001 out of 5
Keywords: ros, ros navigation, ros mapping and navigation, how to build a ros robot, building a robot to run ros, robot setup for ros, raspberry pi robot for ros, using ros with raspberry pi, autonomous robot w
Id: q1u_cC-5Sac
Channel Id: undefined
Length: 19min 53sec (1193 seconds)
Published: Mon Aug 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.