Learn ROS with me - Setting up the Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey robot makers hope you have a good day so far so do you want to set up your Raspberry Pi for use with Rosa and Docker but not Donuts don't know where to start then this is the show for you so let's dive straight in my name is Kevin come with me as we build robots bring them to life with code and have a whole load of fun along the way so this is kind of unofficially part two of the learn Ross With Me series okay let's get over to our keynote and make a start shall we so yes this is all about setting up your Raspberry Pi for use with Roz okay so in this session we're going to look at exactly how to do that we're going to install a 64-bit version of the Raspberry Pi OS which is the supported configuration from the open open source robot Foundation who create Ros we're going to install Docker to keep things nice and tidy we're going to build our Ros container within the Raspberry Pi 64-bit in Docker and then we're going to run that container we're going to have all have a look around and see how this all works and then we're gonna have a very short demo to see how we can write our first Ros program there's quite a lot to cram into this so let's uh see what we can do and if you're sticking around for the live stream there will be a bit of a mailbox q a at the end so we can sort of hang out there as well okay so the setup process this is how it's going to work and it's going to be quite a Hands-On today so I'm going to show you stuff in the terminal and how we build various different things so I shouldn't really dropping anything in this this episode though I did manage to drop this little thermal camera that I was uh just showcasing at the very start of the uh the session there so the setup process a couple of steps involved in it so last week we looked at how to design and build our robot our robot is just sat on my desk here it's kind of got its lidar spinning around there and I've finished this physical build of this it's got its side and it's back off well yeah side up front and it's back off from there the sort of pieces that are fit into place there and yes that's that's all from last week okay so let's get back over to here so this week we're going to be setting up the Raspberry Pi 4 environment we're going to be installing Docker sounds exciting we're going to be cloning the repository for qb1 which is the robot there because that's got a few helper files in there that will help make this much Slicker and quick process we're going to build our Ros 2 environment we're going to set up visual studio code I'm going to do something really cool with Visual Studio you can corrupt remotely connect to your Raspberry Pi and the container within that Raspberry Pi and run your undebug your code you can do that all from your sort of Master computer so it's pretty cool so I've got to install the docker Explorer and Docker container modules for visual studio code and then in future episodes we'll look at how to enhance our robots how to get this lidar actually working with our code setting up the motors and then the thing I'm really looking forward to which is getting the mapping and navigation simultaneous location and mapping working slam so that's where we're heading that's the sort of Direction so first of all we need to get into installing our 64-bit OS so let me bring up um the piece of software we're gonna be using to do this so if I go over to here so Raspberry Pi have this uh this piece of software which is called the Raspberry Pi imager and this allows you to get your little SD card such as this one here and you can then choose which operating system you want to flash onto this you can then write that and you can also change some of the settings so what I'm going to show you is how I would do this we don't actually need to do this today because I've already installed the 64-bit OS on my test machine and I've also got the full thing running on the robot on the desk as well so if I just back up one second I'm just going to load up a browser because I want to show you something on here so let me go over here and show you this so this is um let me just move this on the little window that you can't see out the way there we go so this is my kev's robot website and on here um I've just added something this afternoon which is in the learn modules there's a there's a new there's no course learn Roz with me so this is a work in progress so there's probably some bit rough edges and bits and pieces missing there and um but it has all the things I want to go through today so we can use this as a kind of instead of the slides we can go through this instead so the very first thing we want to do is set up our Raspberry Pi so what it says on here is we're going to set up the 64-bit OS now the reason that we want the 64-bit version and not the 32-bit version one of them is simply to do with the amount of memory that 32-bit computers can address which I think it's limited to about four gigs and the reason for that is if you get a 32-bit number you stretch it out in binary the maximum number that you can have on there is something like 4 000 million uh whatever the the Ram size is at four gig so it's at 4 000 million billion or something whatever the number is that's the maximum capacity that you can address with a 32-bit number so if you have a 64-bit number that's astronomically larger it's more than more particles than there are in the universe that you can store in a 64-bit number they're very very large so that means we can we can address at least eight gigs of RAM which is what we've got in our Raspberry Pi 4 on the desk and I've got one behind me as well which is a just there that little red and white box just there that's the one we're gonna be running in a second so when you get a Raspberry Pi out the box they tend to come with a 32-bit version of the operating system installed so what we need to do is just wipe that and start again afresh using this Raspberry Pi Imaging tool so if you want to grab hold of that you can go over to raspberry pi.com let's just open that in a new window there and you can see there there's uh there's links to how to download that they've got that for Mac OS windows and newborn 2 as well and you can also install if you're on I think that's probably Ubuntu Linux you can just do pseudo ad install RPI Dash imager and that will load up this this tool here okay so let's get back over here and what we want to do if I just load up this here when you click on this button here you can choose by default the 32-bit one we don't want that one we want the 64-bit one that's hidden underneath this Raspberry Pi OS other so there it is raspberry pios 64-bit the port of Debian Bullseye for Raspberry Pi desktops compatible with the 3 4 and 400 and it was last updated last when's that last August is that so we can click on that that's now selected you then choose the storage so if I get my little um memory card here I think this one is a so third I think it's a 16 gig this is the one that came with the Raspberry Pi actually so I'm just gonna plug this in got a little memory card reader just behind my screen okay and there's a question from the audience that I just about uh are there any still any disadvantages with the 64-bit kernel if there are it's not something that we're going to come up against when we use Roz so you can interchangeably if you've got more than one memory card you can just swap them in and out that's one of the beauties of using SD cards makes things a little bit simpler right so I've just popped in there that mass storage device which is this one here so that's there and then there's this little Cog just down here if we click on this Cog we can then choose a couple of options so we want to give our robot a name I'm just calling this one qb2 I've got qb1 on the desk and I've got qb2 which is behind me which is just another Raspberry Pi 4 8 gig and we want to make sure the SSH is enabled and we can use password authentication for that you can even set up a um a username and password I recommend that you do this so don't use Pi that's considered to be a known user account so use one that um that isn't pie so I use Kev set your password in there you can then configure your wireless LAN this helps as well if you're having a robot that's headless hasn't got a monitor attached to it and you can type your password in for your SSID there and I think you have to set your Lan country as well and you can also set things like the locales and whatnot so click on save that and then you can click right and then it'll then ask you to sort of uh start burning that there we go so we're not going to sit here and watch what the watch this happen it's far too exciting for that so once that's done I'll just scroll down here it says the same kind of things on here we can then go to the next page which is about installing updates so once we put our Raspberry Pi SD card in our Raspberry Pi we booted it up we can connect to it over the network so I've also got another machine over here this is qb2 and the first thing that we want to do on here is let's do pseudo apt uh install sorry pseudo apt update I've got my notes literally in front of me there so what that's going to do it's going to go on to the Debian repository where it keeps all its um updates and things and it's just going to get the latest snapshot of that and then you can also do upgrade as well I'm just going to skip that one because that might take a while to do that but that's the next step you should do you can see there it says there's 108 packages that can be upgraded so would be a good idea to do that too um now if you're if you want to use this um and you want to have the the desktop you want to connect over VNC what you'll have to do is do sudo raspy config like sit like so and then you can choose the interface options and you can say VNC enable it and that will enable the VNC server so you then you can connect to it using something like VNC viewer so if I go over here and do I think it's 2-0 five I'm going to go for there we go and we're now connected to that that qb2 you can see there qb2 at the top I find sometimes this can be a little bit laggy so I'm not going to use this for this particular session if I open up a terminal window there for example it's just a little bit slow and I think that's probably to do with the wireless network that it's connecting over it's just a little bit a little bit slow there so yeah you see there a little bit laggy to do anything so I'm not going to use that but you can do if you want to and the other thing you can see on here as well is there's this little circle with a download icon here and if you go show updates if I click on that it'll show you all the updates that are sort of pending that can be installed now that's probably not going to pop up immediately when you put your SD card in it will take a little while for that to um to show up just because it it doesn't load all the time so I'm just going to close that close that and I'm just going to come out of here as well okay so back over here so let's imagine we've we've run those two commands we've done our sudo apt update sudo apt upgrade and we've also seen that we can install the updates as well from that little uh download icon on the menu bar okay so next up we are going to install and configure docker so Docker made this really easy to install now I've sometimes I've found that even on a fresh installation you might have an old version of Docker installed so there's a way that we can actually get rid of get rid of that but what I'm going to do I'm just going to copy this command here and I'm going to go back to my terminal I'm going to paste this in now this actually this file already exists so it should probably just overwrite it so curl is it's essentially like a tool that will grab a file onto your Unix machine so it's a bit like a web browser but it it works in the terminal I can just download things if I do LS I can see there get docker.sh is there now currently if I try and run that dot sh it's not going to allow you to run it because it needs to have an execute permission so the next thing that we need to do is just change the mode and plus X means plus the execute command and then we want to just change get Dash Docker sh so now when we do LS you can see it's change green and that means that we can now run that command to get Docker now if I run this it will actually tell me I've already run this because I have already run it I wanted to do it before the show because it can take some times a little while and you really don't want to sit there just while it installs something but trust me that's all you need to do to install Docker it's very very straightforward now there are some extra steps to installing docker you can see that we've done the uh the plus X to change the execute permission if you want to get rid of Docker completely all traces then you can use this purge command so you do sudo app get Purge Docker Dashie Docker Dashie CLI which is like the command line interface container d dot IO and then Dash y just means just do it so that's the way that we can we can wipe it if we make mistakes and then just to run the installer is just to dot forward slash get docker.sh nice and simple okay so um what we want to do next is so Docker will run but we want it to run in kind of user mode so what we need to do is just add a few extra permissions here so what we want to do is we want to add the user whichever user we're currently using so it's actually not Pi in this case it's Kev we want to modify the docker account so that it also is included um so essentially Kev can run Docker commands that's what that command will do so you simply just copy that and paste it so if I just do that now I think on the I've literally just updated this page a couple of seconds ago but it hasn't refreshed yet because if you try and run that as it is it'll just say you you haven't got permission to do that you need to do sudo and another quick tip as well do you know if you're if you pasted something in and you're at the very end of the line and you have to sort of backspace you can just press Ctrl and a and it'll jump to the very beginning of the the line which is quite useful so and then if we just do Kev what it will do is it'll just make sure that we're added to the group that can run Docker commands so we can now do things like Docker PS and we can see if there's anything actually running which there isn't at the moment okay so next up we we need to change another thing which is we need to unmask it so I'm just going to copy that command paste that in so sudo system control system control allows you to manage the services that running on your Unix machine so unmasking Docker not actually sure what that does if I'm 100 honest right the next one we need to change the docker sock so let's do that one so change mode changes permissions so this is going to change permissions on the the uh run Docker sock and that's the again we need to do sudo to to do that and then the very last thing we need to do a second to last thing we need to do is we need to install um Docker compose now I've already installed this so it shouldn't take very long if you run these commands and you've already done it essentially it just it's fine um is it item potent that's called it'll just carry on which is fine so we can now do things like Docker compose which we'll be using in a minute so that'll show you the different commands that you can run okay next up is system control and start Docker I think we actually have it already running on here oops so I just paste that in if the service wasn't already started this would start it back up and then the last command that we need to do really is reboot the terminal because we want to just make sure that dock is running properly and there's no issues there so we don't need to do that on my particular case because I've already done that so next up we we're going to download some QB files so I've created a whole bunch of kind of tutorials and helper files and I've stored them in a repository that's called qb1 so all we need to do is just copy this git clone command uh no I can I've actually already done this so let me just paste this in if I just call it qb1b for example what this will do is it'll just go on like actually that's wrong let me just let me just do that again qb1 if I just rename the existing qb1 qb1 Dash old something like that all right let's try that again so what this is going to do this is going to go to GitHub and it's going to download those files it's really quick because it's not very much too dumb to just text files so if we look on here now we have the qb1 folder which is just this one here so in dark purple so Wayne said masking a service prevents the service from being started manually or automatically which is a strong stronger version of disable masking disables all Sim links and specified files are removed awesome thank you for that Wayne that helps a lot right so next up let's see what we need to do now um now we can this is an optional step the official Ros Docker files are stored in this open source um let me just grab that and paste that up here because we can actually have a poke about and see what's going on here so oops we don't need that we just need that right here we go so yes these are the official Docker images on GitHub and they've got all kinds of configurations for rolls-ros two different platforms they've got tools like gazebo which is a tool for sort of visualizing things in 3D and they've done all the hard work testing things out making sure things work properly so we're actually going to use that as a basis for our own custom Docker image so you can run that step if you want to just so that you've got them and you can have a look but I think I'm actually going to skip that step on this particular one right so yes the open source robotics Foundation that's their their files there okay so we should have the the docker images and the qb1 I'm going to skip the docker images just because I've already done the hard work for you by testing these out on this particular build and we're now going to build our own container so this is what we're going to run within Docker this is the the closed it's almost like a virtual machine but even more lightweight and to create that we have two things we have a Docker file and the docker file will essentially contain all the instructions on how to build this container all the files that it needs to include and so on and the docker compose tells Docker how to start this up and shut it down so it's a really sort of elegant way bringing this up and bringing it down okay I'm just going to mute that tab there because I can hear that getting notifications through from Twitter and Mastered on there right okay so this is what's actually inside the docker compose so you can see there it's got like a version number 3.9 you then Define the services you can have multiple containers multiple things running there and I've got a service I'm calling ros2 I've got an instruction there to build it if it isn't already built I'm not having a restart policy at the moment so I've just commented that out and for the time being I've just opened up them ports then ports don't actually do anything right now but um what I want to do eventually is I'll open those ports up so that the docker container can be accessed from outside from the outside world essentially now two important things that are on here um Docker enables you to map or bind local folders to within the the container and that means that we can create files outside of the container and see them with inside the container and vice versa so this is really handy if we're doing some software development we want to have all our git files not just in the container but also outside of it as well and it just makes it a lot easier to do that kind of development so I've got two here I've got one I'm calling home Kev Ros so if your username isn't Kev you need to put your username in there and Ross is just the folder I've chosen to uh to map everything that's in the local Raspberry Pi CAD folder and then the other one is home Kev qb1 which is that repository that we've just downloaded and I'm going to map that to Roz 2 in our container and then the last thing that's on here if you've got one of these lidar devices like I've got just uh over here which is sort of running around at the moment I'll just slice that you can actually stop this um that um that actually exists oops let me just go back to uh my terminal there so that actually exists um on TTY USB 0 when I plug that in so if I'm on the um if I'm on qb1 and I do an LS slash Dev slash TTY USB 0 I'll see that the device is actually connected um so if I want to have that appear inside the docker container what I need to do is is I need to include that as a device and then TTY is a way of making the the docker container have a terminal so it can it can spin off new terminal sessions and therefore you can connect to it if you don't have that it'll essentially just open up and then close open up and then close and just do that infinitely which is a bit irritating so you can see that yes we've got the two containers um so what we are going to do um we are going to go back to our our terminal here we are going to let me just see what we said there so we're going to go to qb1 Docker and I'm going to do a Docker builds let me just copy that let's go over here so let's go into qb1 so CDs has changed directory to qb1 Let's do an LS2 list what's in there you can do ls-l if you want to see it in sort of long form and there's this folder here called Docker so let's do CD docker just have a see what's in there and there's two files there is this Docker compose and there's a Docker file so if I if I type cat this will catalog or essentially just show you what's inside the file so if I just type Docker file you can see that there's a whole load of instructions it starts over here and it basically just says this is how you build this particular instance so it's going to grab the Ros humble Ros core Jammy which is a flavor of you Bunty that's been custom made by the open source robot foundation and we're going to do all these other steps to it as well so that's what's going to happen when we we do Docker build Okay so I previously built this so it didn't take any time at all but um it normally would take about maybe five minutes depending on how fast your internet connection is and what that will do if we do um Docker PS sorry image LS we can see which uh things we've actually built on here so this Roz humble Roscoe Jammy that was if that was in that Docker file that was one of the first things it downloaded so that's 397 megabytes in size and then there's two other ones that this is probably me just having a bit of a play here so Docker underscore Roz 2 is an image that's been built you can see the images are exactly the same there so it's just got two two different names within it but they're not being used they're like an ISO they're just like a flat file ready to be run and then when it's run it then becomes a container So currently these are just images ready to run so if we do Docker PS we're actually not running any containers at the moment um so what we can do now um so there's a question there sorry let me just come back to this one somebody was asking about what is TTY USB zero so that is the the device on the the lidar device that's how it presents itself when you plug in your USB connection to your Raspberry Pi um it shows up as a USB device and that just happens to be its name TTY USB 0. um so we're not going to use that today that that's uh but it does show up uh if you if you run that so next up oops I can press the wrong button there it's very sad music appeared okay so let's go back to uh to here and let me see what we need to do next so we built the um we've we've used the docker build so t means just give this a name a title so ros2 is what we've called it and the dot just means build in the current folder so you can see there that we've got the output that we've just seen and then the next step it couldn't be simpler Docker up Docker compose up D so let's go over here and I'll tell you what this means so we have this Docker compose file in fact let's let's have a look inside what that looks like so we do cat like a compose Dot yaml it's not very big the file so you can see there we've got those ports we're not using we've got those two volumes that we're going to map within it and we've got the device um now if I tried running this I'm going to show you what's going to happen it's going to have an error because I've not got that that lidar device plugged into this second QB um so I'll show you how we can fix this area it's very very simple so if I do that docker compose up up will bring up the service it will create a new container and it'll run it and Dash D just means do this detached don't don't do it interactively so you can see here it's saying that there's a problem it cannot find this USB 0 device so what I need to do is just for the for this particular tutorial I'm just going to do and you don't like to do sudo let's just do Nano and then the name of that compose file so it's Docker compose yaml and essentially what we can do is just comment out these different things there we go so if I do that and I save that and I just bring that up it should Now bring up that new container done so if I now do Docker PS we can now see that we've got a container running so there we go Docker underscore Roz 2 and the name of the the actual container is Docker underscore roz2-1 there we go okay so let's go back to our notes and see what we need to do next we've now got the container running which is really cool we've actually got a workable Roz environment now um so the next thing that we can do which is I think the coolest thing you might not have seen this before we can use Visual Studio code on different computer and we can then remotely connect to that Raspberry Pi and we can even Connect into that container from visual studio so if I just load up visual studio let me just get this uh in the right environment so let me let me close that one down there okay okay so let me start this from scratch if I do a new window and what I need to do is make sure that I've got some extensions installed so I just type in Docker up here I've actually got these already installed but Docker we need to make sure that that one's installed you'll see a little blue button like that to install it and then Docker Explorer by John Han you ought to want to install that as well and they're very very quick to install and once we've got those two installed the next thing we need to make sure that we've got installed I think it's called remote uh no SSH and remote Explorer both by Microsoft so you can trust them again they'll have the little blue install button if you click on those two let them install you'll then be able to do the next step and you'll see that this little green button appears down here okay so let's uh let's just get rid of that and what I'm going to do I'm going to now press shift Ctrl and P oh is it command and P shift command and P and you can see there it's actually got this recently used remote SSH but if I just type remote you'll see that that sort of pops up SSH and I want to connect to a new SSH host so let's just uh do that it then wants to have a it wants to note the IP address and the the username is so I'm going to type in Kev at 192.168 one do I think there's 204 or 205. and it's saying um it cannot cannot establish that let me try let me try one uh 204 instead so again shift command and P let's do remote SSH let's do Pi that's it's not Pi so that's probably why it went on Kev at 192.168 1.204 and we know it will work there we go it's now asking for the password so I'm just going to type in the password there and you can see there at the bottom it's giving us a bit of an update opening remote so visual studio is now connecting to that Raspberry Pi which is pretty cool and it's also downloading and installing this vs code server on the pi so like a really small plug-in just to make this work right we're now connected to that Pi we can actually test this out I'm on a Mac here so if I do new terminal you'll actually see it says qb2 so we we can see here we're on qb2 and we can type various different commands did you know there's a command that's called pin out on Raspberry Pi's and if you type that and you scroll up a little bit it gives you a little picture of the Raspberry Pi that you're connected to so you can see this one is a Raspberry Pi 4B 1.5 and it also has eight gigs of RAM which is cool uh you can see everything else as well like which it's got Wi-Fi enabled it's also got the ethernet enabled running a gigabit and they're all the uh the pin outs as well and what the GPI was there so that's just pin out which is quite useful and if you want to check which architecture you're on if you do you name Dash M you can see that Arch 64 which means running the 64-bit version of Raspberry Pi OS okay so that's the first bit if I now click on this so open I can open a folder on the uh the Raspberry Pi which is pretty cool so 502 QB and I just open that I think it opens up another window and just asks you for your password again which is a little bit irritating but I think you can uh you can put up with that and then yes I'm going to trust the authors of these folders so it's fine so here we go so next up um we can check to see have we got those uh extensions installed so let me just make sure we've got those Docker extensions because I expect to see there we go so if I do install in SSH this is pretty cool and then installing SSH for the docker explorers that means we've now got this little Docker thing down here as well but if I just go back to the regular Explorer window look what IPS we have all these extra little drop downs and there is the container um that that we set up you can even right click on this and you can you can inspect it and so on and you can even execute in Bash so I'm now inside the container running on in Docker running on that Raspberry Pi remotely but I'm accessing it through my Mac so this is pretty cool so if I do LS we can see there we've got Ros 2 we've got the um if I do home into LS we've got the Ros folder as well which we created and these are mapped to the other folders outside of the the container so if I go back here go to ros2 we should see all those QB files and there they all are okay cooking with gas so it's nearly time to write our first program so we've done quite a few different steps here we've installed these um uh extensions to visual studio code and we've remotely connected to the Raspberry Pi if you want to know what the Raspberry Pi IP address is another thing you can type in is just IP Dash a IP space a and there's loads of things here but if you basically just like the second one you can see there what your IP address is so 205 and I think I've got the wireless LAN and that's 204 so that's why I've got those two two or four to five the other ones are all ip6 you can basically just ignore them Docker will also create its own virtual um network cards as well if it needs to um but we don't need those for now so yeah you can just do IPA to get all that information up there okay let's jump back to the tutorial we're following and yes we're so remotely connected we've found a folder which is the qb1 and now we can we can play around we've even connected to that um that container as well I just did right click execute A bash command if you want to do that from the terminal you can just type in Docker exec Dash it which is like an interactive terminal the name of the container which is Docker underscore Ros 2-1 underscore one and then bash which is just a shell you could do sh zsh or whatever you got installed but bash is Born Again shell that's what we want and uh yes we've now got congratulations you've got your ros2 container set up on your Raspberry Pi using it through Visual Studio code remotely which is pretty cool okay it's time to write our first program it's not a very complicated program it's really unimpressive but it is a Roz program so we're going to do this so one of the things that we will have to do when we log into our container is we need to Source we need to basically just run loads of um let's get this right we need to run one script that will run several commands to set all the environment variables that we need to access so let's go back to our Visual Studio code what I'm going to do is just make this screen a bit bigger so we can see what's going on like so and let's just open it up a little bit as well so if I go over here and I type in Roz 2 which is one of the commands that we want to to run at the moment it says command not found it doesn't understand what Ros 2 is and that's because we haven't sourced um the first setup file so again this is in the tutorial so if you if you don't if you can't remember this so what we need to do is type source and then we need to type in opt which is like optionally install files and then if I just press tab it'll fill out the next couple of folders for me so Ros and humble humble Hawk spill that's what it is is the name of the the version of Ros that we're running and we then want to run setup dot Bash oop Bash um it doesn't look like it's done anything we can have a look what's actually inside that file so if we do opt and then setup.bash you can see that it essentially just sets up some environment variables this a Ament shell payment is like the build environment build tool for bash for Ros sorry and it's setting up a few um path settings as well now if we just type in ros2now it works because it understands where that command is and how to access it so Ros 2 is the is the the new way of running things like um you know we can check to see uh are there any any nodes So currently we haven't got any nodes is it node there we go node list so we haven't got any nodes currently running so there shouldn't be anything there or else two packages this is it package list there should be quite a few packages on there there they all are these are the sort of standard ones that you get with it we'll have a look what they do in a future episode but first step was to base the get our environment sorted so what we want to do next is there's a client that's called colcon which is um let's go to our our thing here and it'll tell us about how to to run Cole con and what colecon is is collective construction so colcon is a command line tool that improves the workflow building testing and using multiple software packages automates the process handles the ordering and setting up of environment variables essentially this does all the hard work for us when we create a source file we just do colcon build and it will take that source file compile it set up some additional setup.bash files so that we can have a source files for that specific application that we're writing and it'll do all that for us so it's a really nice quite powerful tool so we've done the first one we've run the sourcing of the script the next step is to create a workspace so let's go and do that now so we can either do that um let's do that for visual studio actually right so I've already created a folder here called first app I'm just going to rename that so if I just move first up to Old app and then let's just pretend that we didn't have that so let's do make directory first app and we're going to go into our first I'm going to change so mkdir is make directory make folder and then I'm going to change the directory into the first app and then we're going to make another folder which we're going to call SRC which is source and then inside our source uh I'm not going to create anything in it yet but I'm just going to create a file that's called talker dot um python so if I do LS to list I can see talker.python's there but it actually hasn't got any lengths there's nothing in it there's just an empty file of zero length Okay so if I now to go dot dot and I do LS again so we've got a single folder that's called Source that's got a single file in it that's called talker dot Pi that doesn't do anything just yet but if I do colcon build what this will do is it will create all the files and folders that we need to create a Ros workspace so if I now do LS we've now got build install log and source so let's have a look inside build let's go into our build folder look in there so there's a call Con underscore ignore if I come back out and I look in the install one there's a few things in here look it's created all these local setups setup.bash and these are the files that we need to run we need to Source them if we're going to use our we want to use our own application within raw so if I do setup dot bash to source that again that will just redirect some of the local variables so that things work properly okay and then we have the log folder as well so we look in there let's do Dash L you can see there the the latest version there's a link to that it's got this build file here Let's do let's just have a look in there and then let's have a look at events is there anything in events nope um there we go so timer event reactor shutdown this has like a nuclear power station um okay so we're now back into the route of our first application so what we can do we can actually open up that file that we've just created but there's a step that we probably need to do first so if I go to that first app I go to that Source folder and I open up talk.pi and I'm just going to just do a one comment which is just hello it's come up with an error message there saying it cannot write to that file if I just move me out of the way for a second see there unable to write to the local filetalk.pi permissions are denied so we just need to fix that so if we go back to our terminal just go one folder beneath our folder which is the first app and then we just need to change the mode I'm just going to do 777 it's probably not recommended to do it that way Dash R which means do this recursively and then first app so if I now go into first up again and see now that instead of being blue which represents like a folder it's now green which means we can write to these folders as well so if I now go back up here and let me just retry that now it'll now succeed because um we've now got the right permission so units has got some pretty weird old-fashioned ways of doing permissions and essentially it's like user group and wool there's like three different groupings if you do if you go down here do ls-l you've got these things here these actually are the three pairings so you've got your local user permissions your group permissions that these might be a member of and then you've got the world permissions which are these last ones here so if you're on a Unix multiple user system um everyone is a member of world so what can they see and then the D is just if it's a directory or not so this uh change mode 777 effectively changes the the these bits here if I if I change that for example to um six six six which is usually the the weight normally creates these oops I just need to do that from there and then I go back into first app you can see now the 666 it's got rid of the execute permission from each of these folders so we need to make sure that we have that go back and change that to 777 again and this is the sort of they call them the file modes it's an old-fashioned unixie thing okay but yeah we need to set them and it says that in our tutorial as well so if we go back over here um after the thing about colcon and setting a power script there's a little bit there about fixing the permissions right let's write our talker dot Pi so I've got some code here we're going to basically just cut and paste this and we'll talk you through how this works but essentially this is going to create our first program so let me just get rid of that hello paste this in I'm just going to move the window down a bit so we can see what's going on so the first thing these first two things are just uh comments we're going to import this art CLP Pi so RCL is the the Ros um like common libraries and then the pi is the the python version of these common libraries so we're going to import that and then from common um from r c l Pi dot node we're going to import node which is a class and then we've we've got this this function here which is called by you'll see this in loads of different python programs so I've underscore or double underscore name double underscore I've got these Dundas double underscore is equal to double underscore main double underscore then run the main function um and it's just a way of saying if if the person runs this and hasn't specified any sort of thing to run within the file then just run this main function here so we're going to pass in a variable that's called AGS if the no arguments are actually being passed we can just set that to none and we will actually use this later on in some of the tutorials to pass in additional variables and settings so by basically saying that to non it means that we can have these accepted for future so we're then going to do the RCL Pi dot init we're going to initialize Ros I'm going to pass it any arguments have been passed into us we're then going to create a new node and the node is going to be called Pi test pay underscore test we're then going to get a logger and the logger is going to log an entry and it's going to lock the entry as an info type this is similar if you've used a few there's a logging function in there and we're basically going to say hello ross2 now the next two commands are important because what this will do is it this will spin up the node it'll make it appear if we do Ros 2 node list we will see it listed there we'll give this a go in a minute and then that spin will carry on so it won't actually get this to this shutdown command it'll carry on until we press Ctrl and c and then it'll run the shutdown command and basically just tell um tell Ross on anything that's connected to it that this particular node is going to die okay so let us go down here let's have a look in our source folder let's see that it's there target.pile let's just make sure it can see the same thing and there it is there's all the code that we've just written up here because we've mapped the folders outside and inside the containers everything we do here is instantaneously available here so I'm going to do CD dot dot so I'm now in if I do PWD it gives us the um the current working directory which is Roz 2 first app and we need to run colcon build because we've changed the file and that will then create the packages or anything else that's in there now if we go back into our build folder I think it is nope must be the install folder let's just run setup.bash and what I'm also going to do is I'm going to create another terminal instance so that we've got two of them um this is going to let me do that there probably not I'll probably have to create another terminal so just to the side where I am here there's actually two windows that we can switch between so if I go there I might be able to execute a second bash instance there it's actually just switched back to the other one don't worry about that just now I will I will connect to this um a second time because I want to show you that you can actually see the nodes running that's what I'm trying to show you here so what we'll do we'll go back into the source folder and then we'll just do python three and then talk a DOT pi and this is our first program running in roles so it's not very impressive but it is a Ros programmer so what's happened here is we've got the the logger has logged out an info event there's the time Stamper when that happened the node is called Pi underscore test so Pi score test node has said hello Rod 2 which is there and you can see there that it's continuing to run so what I'm going to do I'm going to go back to that other terminal that I've got just here and I'm going to do Docker run interactive terminal does it run exact and then it's called docker Ros 2 underscore one and then Bash so I'm now in a second terminal the other one is still running if I go back over to the right here just behind my face you can see that one's still running so if I now go back over here we need to do that Source thing again where we Source the opt the humble and the setup dot bash we can actually add that to us um a profile so that we don't have to keep doing this every single time it's very straightforward to do this and now if I do Ros 2 node list we can see Pi test is running as a node so that means that Ros is running and there's one node running in Ros s so if I go back over to here and I kill that now so if I do command and C to kill it and I go back over to our first one if I run node ros2 node list you can see that there's now no nodes running because it's shut down let's run that last command there so this is how we can set up and create a very first program that doesn't do anything really exciting it doesn't do anything robotically just yet but this is how we we need to set this up and this is pretty much boilerplate for every app that we will write every node that we will create so we can copy this and we can put this in something like I use gists on GitHub if I go back over here I just open up her gist.get hub and I go for let me see new node um I basically just created there that exact boilerplate text so I can it means I can use that um as like a a scratch a scratch Pad somewhere to put bits and pieces so it's like a mini version of a git repository so that's just called gists it's not github.com to grab that okay let's get back over to our first program and that's pretty much everything I wanted to cover off today from this particular point of view the next part of the tutorial will teach us how to do something a bit more interesting and we'll get into depth with a lot more Ros Concepts so today we've seen the logger we've looked at creating a node but we haven't really done any sort of intercommunication between different nodes so the next thing we'll create is like a listener that can listen out for things and then respond back to them and then we'll look at building things like getting the motors to work getting some odometry if we have um my intention is to get this robot that I have here uh this has it has a dedicated motor 2040 which is actually running on micropython and it can get really detailed odometry from these uh these motors they've got a tiny little encoder on the back and they can position very very accurately So currently these are out of stock from their supplier from pimarroni so I'll either have to take these off and fit them or I'll just have to wait for them to come in to stock but that's essentially what I want to do I want to create get one of these boards and fit this and have this communicate to nodes essentially to the Raspberry Pi 4 and there can be a node that's listening to that odometry data and then it can put it in as a separate node an odometry node put that into the Ros ecosystem and then we can take that data and visualize it and so on okay so let me uh so there's another um hashemi's just giving us another tip there which is if you do exclamation mark exclamation mark that doesn't seem to do anything it says it repeats the previous command let me just clear that I what would I need to do to prove that if I do slash doesn't seem to do anything but maybe it's just the previous command so if I do Echo hello and then I do slash slide oh yes there it is so it's running the previous command that's pretty cool I did not know that so if you do that that and then control trying to see how you could uh do something useful with that but that's pretty cool you can just do apparel as well that works just the same I can type two characters then press enter or just one that's cool okay so let me get back to the slides so so we've installed our 64-bit version of raws we've set up our our Docker environment we've built our own ros2 container using that Docker file and Docker compose and we've set up visual studio code so that we can connect to that running container from a separate computer which means we can use all the power and functionality of Visual Studio code to write our code and we're not sort of limited by the the you know limited processing power that we have on the Raspberry Pi 4 there by comparison and then we wrote our very first Ros program it's a little bit underwhelming I'm sure but um we'll get on to some much more advanced programs in the future so if you like what I do and you want to see more of these types of videos please give me a like drop me a comment let me know if this is something that you're interested in doing whether you've used Ros before maybe you're a Ros expert and you can give me some tips um and if you've not already subscribed to the channel definitely make sure you click that subscribe button and that really helped the channel to grow make sure you switch on the notifications as well I do go live every single Sunday at 7 00 p.m GMT so if you want to catch me live that's how you can do that and if you've not joined our our Discord group you can you can do that too but before we get onto our Discord group I want to show you um the the robot as it is now so here is our QB so this is currently got its lidar plugged in and running so you can see there but the wheels at the moment are not connected up the motors are in place but essentially these are not uh screwed up unpowered up yet but I have got all the the pieces ready to go I just move this around so this back piece for example that simply just screws into place just there there's two screws to to hold that in place there's a side piece that goes there when I've not got these wires plugged in it's on sort of life support at the moment and there's another one at the front there that can that can go just onto the front there as well so all the pieces are now 3D printed I did have to print another little piece a little spacer that goes around the very top there this little blue piece and that was because I've not allowed enough space for this little wheel this motor in here and what was happening is it was it was essentially doing that and stopping the lidar from spinning around and that's just like a rubber band that's just uh spinning around there but that's been happily running now for quite a while and the other thing I want to do is uh upgrade this camera at some point as well so this is currently running um an algaecam 16 megapixel camera and I'm having a few problems getting that set up and running so uh watch this space on that one okay so that's uh that's the the demo so far from the well we're up to with the robot and as I was saying if you've not joined our Discord server then you need to head over to kedrobox.com Discord it's completely free and then we can sort of hang out share pictures if you have any problems with the code that I've shared you can also help me uh bug fix that and get to the problem of any troubles you might be having it's much easier to do that on Discord than uh through YouTube or through Messenger or something like that if it's on Discord everybody else can see as well and they can jump in if you want to follow me on social media so I'm all over social media if you want to check out my new tick tock page you can check that out uh let's go to Kevin mclea6 and you can see some videos I've been making um I made a few about QB and there's a few other ones on there one of them has done ridiculously well I think it had over 400 000 views when I last looked at it let me just uh find it on tick tock I don't know why that particular one did so well yes at 432 000 views and then there's another one of me going into the Raspberry Pi store in Cambridge and that's at 114 and a half thousand views which is pretty crazy and the other ones have just done like averagely well so I don't know what's going on there also on Instagram Uh Kevin McAleer on Twitter at kev's Mac and um I'm also on Mastodon kev's Mac as well so kezmark at knotted on social so make sure you follow me on all those places and definitely say hi uh that'd be that'd be pretty cool and if you want to support the show there's a number of different ways that you can do that so you can do a super thanks so once you've joined the channel like you've subscribed you'll see that there is a super thanks button if you're watching this live on the the live stream you can do a super chat and that will pop up um and I can now enable all the uh stream element stuff on here let me just click that button there and if you want to buy a coffee you can do you can go to casrobots.com coffee and if you want to join the YouTube membership program as well you can do that about the price of a coffee it's not very expensive but it helps support the show keeps me and robots and uh me creating videos for you okay let me just uh click on the next thing so yes the support is the most important part let me uh get over to that so we've got a number of people who've helped support the show so far and these people asked we've got Mark hampson we've got David reading we have shumi what Derek we've got RGS we've got Roland we have Bill Alex we have Tom wiser who's just uh subscribed for another year which is a fantastic thank you for that Tom that really you're one of the longest supporters to think of the channel so particularly thanks for that we've got Anthony our Hollings as well who's uh recently subscribed we've got Keith we have shammy we have Steve Phillips and then on the YouTube members on that side we have Fred more we've got Bill Hoy we've got Dale from hybrid robotics we've got hands from Cheer lights look we've got a Super Chat coming in there from Laurie thank you so much for that thanks for the Pico stands awesome I'm really pleased that you like those since I've got a number of Pico stands um I'm not planning to hand actually there's one at the back of the room over there I'll come to that in a minute so we've got Michael we have Fraser we have uh Jose we've got uh um Joanne we have uh John Paul and we've got Tom as well and if I'm mashing your name there let me know I like to get people's names right it's the most important word in anybody's vocabulary cool okay so that's the uh the main content of the show so we've got to do a bit of a live stream hangout now so this is the point of the video where I'll say if you're watching this on replay thank you so much for watching and I shall see you next time
Info
Channel: Kevin McAleer
Views: 15,546
Rating: undefined out of 5
Keywords: ROS, ROS2, Robotics, Robots, Python, Raspberry Pi, raspberry pi 4, how to install ros on raspberry pi 4, docker, portainer, container, ROS2 in docker, ros, robot operating system, raspberry pi, ros tutorials, ros tutorial, what is ros, ros tutorial for beginners, raspberry pi projects, getting started with raspberry pi, robot operating system (ros) for absolute beginners
Id: 03wKo-riJlA
Channel Id: undefined
Length: 56min 50sec (3410 seconds)
Published: Mon Jan 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.