This video introduces Python programming for robotics, explaining why Python is preferred over other languages for robotics education due to its popularity alongside C++, extensive AI libraries (OpenAI, OpenCV, TensorFlow), and ease of learning. The course covers essential Python concepts including variables, data types (integers, floats, strings, lists, tuples, dictionaries), input/output functions, comparison operators, conditional statements (if-else), and loops (while and for). Students practice by creating Python scripts that interact with simulated robots, such as reading laser sensor data to detect obstacles and controlling robot movement based on sensor readings. The course emphasizes hands-on practice through exercises where students create scripts to control robotic arms and mobile robots, preparing them for subsequent ROS (Robot Operating System) learning.
Python for Robotics: ROS Tutorial Day 2
Added:Hey hello hello everybody you got me here drinking some coffee for my new fancy cup here yeah it's pretty nice right I'm Earl Ross developer if you want to get the one you can check the description of the video and you will see how to get one so let me finish this real quick and let's start hello everybody welcome again to the day two of these learning week or the of this basic Ross learning week welcome everybody again thank you very much for trusting in us again and today as I as I've already said yesterday we are going to be working with Python so let me share one moment here the the shadow alright so basically yesterday or Monday we were doing the lineup for robotics course which we completed more or less until you need to I don't know I hope some of you continue it doing the girls by yourself and you kept learning more about Linux but today we are going to move directly to the Python for robotics course here in to is in Tuesday and for that we are going to be using the robot unit Academy again just as we did yesterday I've seen in the chat that some of you have already been logging in and starting the course so that's pretty nice yesterday at the beginning you had some technical problems in fact it was not related to the to the Academy itself but it was related to our authentication system because we had simultaneously like more than 400 people trying to log in at the same time at the same time and it crashed it collapse it but it was because of a bad configuration we have solvent dust so for today you shouldn't have any problem logging in even if you try to log in all together at the same time it's going to work so don't worry everything is ok now and yes so let's move to the PC let's go out to the toad there in Knight Academy and one second here alright so here I are already in the Ignite Academy and for for the ones who are new by the way let me tell you this here you have the wrote in that Academy you can create an account for free you know less than than one minute so I suppose that most of you already have the accountant already know about Academy but in the case that there's something someone new you can come here to the robot in that academy.com page and create an account totally for free then today we are going to be following the Python 3 for robotics course here in the free courses section and as I also said yesterday I want to repeat it again today so please don't stay there listening to me and to my pretty boy is talking but please open the course and as I'm going to be doing things and I'm going to be progressing through a goose you have to do the same as I am doing yeah you have to keep practicing and doing the programs yourself with me yeah all together and practicing yeah that's the most important part of this so I want you to to real to really practice so that you can really learn all the concepts yeah alright so this being said let's all start the Python 3 for robotics course here by clicking on the start curves let me have a look a quick look at the chat here hello again I can see here Evangelos Charlie's hi from San Diego so is feel good ed hey again guys Oliver Simon excellent hello from savvy Mechanicville hello hola hola Miguel alright so yeah I can remember some of the names I'm seeing here from yesterday so so welcome again to this learning week let me know please here in the comments if you are being able to start the course if you already have the the girls loaded if you have any problem please let me know here so that I can I can I can continue knowing that all of you are on the same path as me I see Sarah here asking is the MOOC disinfected yeah it's it's super disinfected don't worry don't worry by my health I am okay I'm going to be okay hi from Israel hello hello everybody alright so let me come here to my ignite back I mean it is still loading so I'm going to drink another a bit of coffee one more time with my fancy hello Cheers alright good bye good bye let's go back to to to the Academy all right so these are starting to load almost there and know that loaded the crews loaded okay load that everything okay loaded and ready to go Rahul categoric Rhonda says finish at the line of scores and have some questions for today's course okay this question it comes pretty handy right now because I want to introduce you to a new concept so and then I'm going to talk about another one but first of all here in the in the Academy yeah you can see all the all the section with the notebook IDE the shells and the and the Gazebo simulation and also here you can see a section that says get help yeah so if you click here this is going to tell to take you directly to our forum yeah this is the forum for our in magnet Academy where you can see that we have many questions from our users and in case you have a because today we are going to focus on on the Python codes we cannot we cannot spend time solving questions of all nine looks so in case you have you have done by yourself the line hooks course or even the Python curve for today and if you have questions please post them here in this forum and we going to answer them yay myself I'm going to answer the questions with my team so sorry I wanted to say this today so please if you have questions from yesterday for that for that I know two scores if today you have questions from the Python course and also for the rest of the week questions related to Ross please post them there in the forum and also another thing I wanted to say is that yesterday you have many many of you requesting us to create a kind of group for in telegram for instance or in this court or whatever but you are requesting some kind of platform so that you can talk between you and chat yeah so we are I want to let you know that we are thinking about it and we are going to provide an answer to you probably tomorrow or during this week we are going to to create and we are to provide to you a place where you can talk between yourselves about your robotics project about your lives whatever you you want but especially about robotics things so we want to create this kind of place where we're all you Ross developers and robot developers can chat and share your projects between you yeah so we are thinking about that don't don't think that we have forgot about all everything you said yesterday about that so we are thinking about it and we are think about the best way to to to do this and we are going to let you know once we have a final decision probably tomorrow or at least going to be this week for sure yeah so so yeah I wanted to say these two things first of all and in my case I already have here let me close the forum now I already have here my curse loaded great I mean Python essential but I'm going to move very quickly to introduction to the first unit in order to introduce a little bit about this course and why why we want to teach you Python but before starting let me have a last look yeah but before starting let me have a las look here at the chat okay again see ready loaded loaded loaded loaded em Kraken is a skiing sorry what should I be opening you should be opening the Python 3 for robotics course m4 from the robotic Knight Academy yeah then the Python C for a big scores ok I can see there Ruben is already answered your question I can see here also saying this course would be nice for a group do I need to change my course or reload ok I can see my colleagues are already answering you so I'm going to click keep going - Mauricio Ferrari alright so I am here yeah unit 1 in production I have a robotic arm here yes this is meant to be like this you need you should have this simulation here of a robotic arm in a with a small table in front with a red ball here and some tools yeah see it you need is named production unit so here basically I want to to introduce you to Python I suppose that most of you already know what is Python but basically Python is a is a programming language but why Python and not another one yeah well mainly I I want to provide you with three strong reasons why we want to to teach Python today are not under another language first of all Python is one of the most popular programming languages for robots if not the most yeah the two most popular programming robots for proving languages for robots are Python and C++ yeah but each each year python is is gaining more power yeah in robotics programming so this is the first reason python is the most or one of the most popular programming languages for robots then the second reason is that there are a lot of artificial intelligence libraries use it for robotics that are written in Python yeah for instance open AI real formal algorithms of open AI also open CB libraries for image processing yeah for perception for dealing with perception also deep learning algorithms of tensor flow all of these are written in Python yeah and many of these are our tools that are heavy use it in robotics yeah so here you have the second reason why we want to teach Python and finally because at the end we want to learn raw so the main goal of this week is that you have a basic knowledge of Ross that allows you to create programs programs for your robots in order to solve a certain problem yeah so it is the main goal of this week but you learn the basics of Ross then the best way for us for us the best way and the fastest way to learn ross is by using python yeah because it python is easier to understand and c++ and by learning ross using python you are going to remove a lot of artists are artificial problems that you can find on the way here so this way you can focus more on learning ross concepts and forget a little bit about the programming language yeah so the best way for us and the fastest way to learn ross is by using python so here are the three main reasons why we want to teach you python today yeah then let's go for it so first of all we are going to start practicing from the very beginning and the first thing we are going to do is to create the first python program yeah let me come here and see what i have here all right so i'm going to come here to my cutting work workspace and i'm going to remove all i have so i I start clean just as you so I'm going to remove here this alright so I have my workspace empty and I'm going to start at the same point as you guys are so the first thing let's create our first Python program so for this we are going to start using things that we learned yesterday so the first is going to be to create a file yeah so for that we can use the touch command for instance you remember that we were using the Doge command yesterday ingested a class so let's use the touch command in order to create a new file and we are going to name this file let's name it let me see here arm control dot bye yeah so we can create it here from the shell as this touch arm control dot PI this is going to create here the file or another option if you prefer it is to create it directly from the IDE yeah so you can come here to the SRC folder right-click choose the new file option and here you introduce the name arm control dot PI and the file is going to be generated as well yeah so you can do it the way you prefer the way it's better for you so so yeah here we have the arm control 2 pi and now first what we are going to do is to copy this code we have here into our file yeah so I'm going to select here this code this Python code ctrl-c and ctrl-v so I am pasting this code here I have in the notebook to my Python file yeah then this code here contains some Python classes etc so probably at this point you don't understand what this code is doing but don't worry so during the course we are going to be talking about all these things about Python classes how to call functions what how to import modules etc yeah so at this point this is just a demonstration to see what a quick use of a Python script yeah but this is not still the curse material so once we start the course and we keep reversing through the different unit you are going to understand you are going to be and to be able to fully understand what this means yeah but for now just create your Python script and copy paste this code into your Python script all right great then we are going to execute it home well by using the Python keyword yes so this is the way that you are going to usually execute a Python script so you have to be first of all important you need to be in the folder that contains your Python script which in this case it's cutting workspace SRC we can go we can come here using the CD command yeah which we learnt yesterday as well this CD command they change our entry so see the cutting workspace as you see here I can do an LS another comment that we learnt about yesterday and here I can see that I have this arm control dot PI Python script yeah then one thing we can do here is to for instance give execution permissions gmod plus X control dot by this is one thing we could do but in this case I believe it's not necessary let's try to execute it directly like this Python arm control dot pi okay so this is executing here we are seeing some outputs okay and we can see here how our robot on it starts to move and it's going here to pick this red ball you can see here how it is picking it and then it finishes and it releases the ball yeah so basically here in a couple of minutes we have created this Python script which basically is meant to make the robotic arm this robotic arm pick this red ball from the table yeah super easy so remember from here basically what I want you to remember is first of all we can execute Python scripts using the Python keyword plus the name of the Python script we want to execute yeah you have the structure here then also super important all python scripts have to must have the dot pi extension yeah this dot pi extension is going to tell the system that this is a Python script yeah important also all right okay excellent then finally in order to end these these these introduction to the course what are we going to learn with this course probably we are not going to have time to cover all the steps but we are going to be doing them progressively and when we finish remember that you can keep doing the girls by yourselves yeah so don't worry if we don't have time to cover all the materials because you can do it yourself at home do your own pace so don't worry about this then basically what we are going to learn in this course in order is first of all who to store data in two variables how to operate with the data in the variables how to change behavior base it on conditions here conditional statements also how to create functions that can be call it from other places of the code super important functions yeah and finally how to encompass encapsulate the code into classes into Python classes so that you can have a clean and robust code yeah also a super important concept Python classes so we are going to learn all these during this course and how are we going to learn it well basically by working with robots yeah so by interacting with robots in this course we are going to work with dr. BOTS robot and with some it exile robot yeah all right and then we are ready to go the requirement is Linux which we already did yesterday so we are okay and then now let's move to the next unit remember here at the left bottom corner of the screen you have here the list of units so you can click here in order to open it and then we are going to move to that you need to Python essential yeah there we go then this is going to reload the notebook it is going to load the new notebook and it's going to reload as well the simulation because we are going to start working with the total robot now so it has to load this new simulation and meanwhile these loads I'm going to have a look at the chatter let's see how things are going then we see here what is okay yeah Balaji here Malaysia Babu is asking could you please tell me what robot we are using today we are going to be working with shuttle about two robot and with some it accel robot yeah then okay yeah I can see that my colleagues are already answering most of the questions it does not work I can see Anna here saying it does not work you need to know that you need to know that I can see here okay Anna my colleagues are going to help you here because it's pretty strange it should work flawlessly since there is no no strange things there it just to execute a Python script so don't worry don't worry we are going to to solve it all right low that low that I can see here okay so everything seems to be working fine okay so let's keep going yeah so here we have a Python you need to Python basics so here we are going to start with the course material then first of all I want to introduce a couple of things so we have to do a couple of previous steps before start working then first of all this is meant to be a Python girls so we want to focus in teaching Python yeah how to program using Python yep so this is course is not meant to teach you how to work with Ross however we want to teach you Python for robotics so in some way we want to make your programs interact with robots yeah and for this we need Ross but we are going to keep this Ross layer let's say under the hood yes so that you don't have to really use it you are going to be programming just Python you don't need to know Ross at this point yeah but we have created a Ross layer let's say let's say that you are going to be able to use in this course calling functions that are going to allow you to interact with the simulation yeah for reading sensor data for moving the robot etc yeah so this course is meant to teach Python not Ross yeah we are going to start with Ross tomorrow all right then another thing because Ross works by default with Python too but in this course we want to teach you Python 3 since it is the last version yeah and it is the one that is going to be a the most use it so in this course we are teaching Python 3 yeah and so for this what we are going to do is to activate a virtual environment that we have created here that is going to allow us to work with Python 3 yeah here you have the command this command here if you copied and paste it into your shell this you are going to see that here your prompt changes to by 3 with a VM this basically has activated a Python 3 environment so now any program that I execute here in my web shell is going to be executed using Python 3 yeah you can check that here doing a python version and here we have python 3 dot v dot yeah so very important every time you execute your Python programs that you're going to crater in the course here in the shell remember to have this Python 3 built or mitem and activate it yes you are going to see that it activated because you will have this prefix here in your prompt saying PI 3 VM all right then we are going to start here doing a first exercise that is going to do to help us introduce some basic concepts I data-type some variables so that starts all together I'm going to do it with you but you have to do it as well in your in your laptops in your computers yeah remember so you have to do these as well with me then first of all let's execute this command we are going to move to the cutting board piece as I see to our workspace yep here here we are then here I'm going to use the mkd and in order to create a new directory m'kay dear robot underscore control yeah I'm going to create a new folder call it robot underscore control there we go here it appears Money mo money of let me close this here it appears my new folder yeah robot control then I'm going to go inside this folder so CD robot control and here I'm going to create a new path a new script here with touch using the touch command yeah so touch by a script one dot bye yep so here I have created inside my robot control folder a Python script which is named PI script one dot bye yep then inside this script I'm going to get this code here copied and pasted it yeah so control C and control V and paste into my script into my PI script one dot bye yeah here I have it excellent and now in order to execute it as we already know we are going to use the Python keyword so we have to type here in our shell Python PI script one dot pi it goes and here you have the output which is the distance measure it is 2.48 etc yeah all right so what is this what what does this open mean and what does this program do yeah so what is all this okay let's go by parts part by part let's analyze the code by part by part so first of all we have here an import line yeah the very first line of the code of the scrip here is an import then basically here we're importing this robot control class yes this is a Python class which contains Ross code yet this this is generated by us this class has been generated by us and we provide it to you that you can use it and this class basically what does is to connect is to allow you to interact with the simulation without having to worry about Ross yeah so this class contains many restrictions that will allow you to interact with your robot for instance in order to get information about its lasers in order to move the robot etc yeah so you are going to need to import this class in most of the of the programs that you are going to create in this course yes because this class is going to allow you to interact with the robot yeah then we are importing this robot control class from this robot default control class yeah from this model which is named robot underscore control under stoker-class yeah then this is if you want to learn more about this class if you are interested you can come here to this path and you are going to see the content of this class but this I'm not going to show it right now because it's not the purpose of these of these life class but here inside you are going to see this robot control brass program with the robot control class yeah and if you are interested you can have a look here and see what it does yeah but basically as I've said this class is going to allow you to interact with the robot by calling its functions yep then next thing what are we doing here here we are creating a new variable which is named a/c yeah and in this variable we are storing an element which in this case it's an object of this robot control class yeah then some concepts that I am saying right now like classes functions maybe you are not understanding what this means but don't worry don't worry yeah because during the we are going to be talking about all these so for returns in in unit 4 is going to be dedicated to classes yeah so you are going to perfectly understand what a class is and how to create a class how to use it etc and also with functions etc so maybe some words that I am saying right now sound strange to you but don't worry because I can promise you that when you complete the scores you are going to understand everything perfectly yeah then let's keep going so here we are creating a new variable named RC and we are storing here in this variable an object of this robot control class yep why well because now we are going to be able through this variable to call the functions of this robot control class which is exactly where we are where we are what we are doing here in the next line yeah so here we are creating another variable which is named a and we are accessing using the first variable we created here that RC variable which contains our robot control class we are calling the gate lizard function yeah and we are placing a parameter here to this function then what is this get lesser function the recent disk address a function is a fusion provided by this robot control class that we have created yeah then we need to provide in this case a parameter here which is the distance which is sorry the the beam of the laser yeah so let's come here because we are going to understand it better yeah so yeah so here we have the get laser function and we have to provide to this get less efficient array number yeah so if you know about lasers about lighters you know that they produce beams in this case the one in this simulation you can see it mounted here at the top if you come here to the simulation and make it bigger you are going to see here that we have here the laser mounted yeah it's this small model that it has here on the top the robot yeah this is the laser and then this is generating many beams I must here the focus of the solution okay there we go then this laser is generating many beams yes something similar as the picture you can see here then in this case this laser has a range of 180 degrees more or less and it produces a total of 720 beams like this ones yeah then depending on the beam you choose on the on the position of the beam you choose we are going to be getting the readings from one side from one direction or another of the robot for instance if we have a look at the laser beam number zero it's going to be the first one here at the right side of the robot yeah it reaches the beam number 719 we are going to be choosing the first beam here at the left side of the robot and it reaches the middle number which is 360 we are going to be choosing the laser beam which is right in front of the robot which it's oriented towards this wall here yeah so basically what is going to happen here if we check the laser beam number zero this is going to give us a detection of what this is going to give us a value of infinite yeah why because the laser beam is going to keep going until the infinite why because it's not right why because it's not finding any obstacle in its way yeah and because it is not finding any obstacle in its way it's going to go all the way until the infinite until the maximum range of course which in this case I believe it's 30 30 meters or something like this yeah then what happens if we choose to have a look at the laser beam number 719 which is here well it's going to happen exactly the same yeah we are going to get our a value of infinite because the laser beam in is not going to find any obstacle on its way yeah but what happens if we choose to have a look at the laser beam number 360 which is here facing pointing to the wall yeah then we are going to get the value of the this laser beam until it finds an obstacle until in this case it finds this wall here in front of the robot yeah so so let's go back here to our program here we are calling this green laser function and we are providing the value of 360 so basically here in this variable in the variable name it named a we are storing the value of the laser at the end of the program we are printing this very well yeah we are using here the print function which basically is going to print the string that we have here plus the value contained in the variable a so here when we executed this program by the PI script 1 we got this the distance measure it is 2.48 at etc yeah so what does this mean and can you guess does somebody know what this mean well basically this means that the laser beam here right in front of the robot is detecting an obstacle which is at 2.40 8 meters of distance yeah so this wall is a 2.48 meters of distance from the robot yeah so this is basically what this program is doing super easy so we are importing here this robot control class which is going to allow us to use some functions like this get laser function that allows us to get information about the laser of the robot in this case we want to know the information of the laser beam which is at the position number 360 yeah and with this information we can know that this wall here is at 2.5 meters more or less of distance of the robot yeah pretty pretty interesting right so with this we could do many things we have create programs that tells the robot to stop when the distance to the up to the wall is less than 1 meter for instance well many many things yeah which we are going to learn how to how to do during this course so don't worry yep then one last thing I want to I want to mention here before we go is the concept of calling a function yeah so here in order to a to be able to call this function first of all we need to create an object of this robot control class and store it into a variable like we are doing here yeah in this case we are restoring we are creating an object of this class and we are storing it into the air see variable and then using this RC variable which contains the class here we can call any function of this class yeah like this RC dot get laser in this case we are calling the grid liaison function but during the course as we progress we are going to see more functions that we can access and that are going to be very useful for many things yeah so again don't worry if you don't fully understand what a class is what the concept of function is or calling a fluid don't worry we need to introduce this so that you can start from the beginning using and interacting with a robot but as the course goes on we are going to keep addressing all of these issues and explaining and explaining what they are and how they work yeah so don't worry excellent so we are done with this brief introduction so at this point we are going to start here with the exercise and theory with variables but before that let me have a quick look at the chart and let's see how things are going so I'm going to have another let me switch very quickly here kamesh I'm going to have another another drink here to my to my coffee delicious all right let's go back let me have a look here very quick to the to the questions or to the comment that we are having in the in the chat hi from San Diego California are the links for the daily classes changing no no Felipe no they are going to be we have already we have the mirror you should YouTube channel they're ready and they are going to be like that so so don't worry they are not going to change okay I can see some questions there about the eczema's well I'm going to talk about the exam let me do a very brief introduction so that you know but I'm going to explain more about it at the end of this class but here let me switch very quickly to the PDF so here remember that after today and when you have completed length for robotics and Python for robotics we are going to be able to do an evaluation test which is optional you can do it or not it's oh it's up to you it's completely free but if you later I'm going to explain you how to do it but if you if you pass it you are going to get a certificate which you can use for instance to link in your to display your linking account yeah so it's pretty interesting then remember this because I've seen someone talking they're out of the exam so yeah remember that after you can take it today when we finish the class or in some hours or even tomorrow or during the week it doesn't matter yeah but basically you you you need to have completed or at least have the knowledge about language for robotics and Python for robotics yeah then when I finish this class I'm going to talk more about this I'm going to leave more data to you but let's go back to to work I was reading here the chat let's see how it is going give intimacy okay that's a very good question he said how is it possible to execute the Python fight without leaving execution permissions with gmod + X this is a very good question because yesterday we had problems trying to if you remember we had problems trying to execute the file because it didn't have execution permissions yeah what is the difference that now we are calling the Python file directly with the Python program yeah so we are able in this way to execute it if we call it this function this program from Ross we would get an error yeah so if we call it this program using rush run not directly we would get an error that we don't have execution permission for this file yeah but because we are executing it and calling it directly with a Python program then we can overcome this and we are able to execute it yeah to execute it through the Python program the yeah let me go back here master ask either see an object well now yes or see initially this is a variable yeah this is a variable that it's it's of no type we are going to do this right now yeah then when I assign this which is an object of a class then this variable becomes an object of a class yeah so usually yeah let's keep going because this question reminds me that this is explain it right here so usually usually in in other programming languages like C++ let's say or Java you need to declare first your variable and you need to assign a type to it so in in simple file for instance you need to write int indicating that your variable is going to be an interval then you put the name of the variable and you are saying a by value yeah this would be in C++ so when you define a variable to need to tell which this radial is going to be yeah in Python this is not necessary in Python you can directly read write the name of your variable and assign a value to it yeah and then your variable is going to become whatever the type of the you have assigned to that variable yeah so for instance and even if this can change in runtime so let me show you here some examples we have in the theory so basically as you may already know variables are used in order to store that data any kind of data yeah so for instance here we have some example we have here a variable a which we are assigning an integral here and a string here at least etc yeah then as you can see we don't need to declare which time is going to be any any of them we just write a name of the variable and we assign some data to it it doesn't matter yeah okay one second okay okay no problem we can keep going alright so as you can see here we don't need to tell previously which type is going to be our variable we just declare it here we think of a name we assigned some data to it and we start using it yeah so it's that simple yeah super super simple that's why Python is so powerful and so powerful especially for educational purposes yeah then even we can change of course you can change in a the value of a variable on runtime so here for instance we create a variable a we assign a value of five but then here we just assign a value of six then at the end if we print the value it's going to be six yeah so if I run here my program this is going to be a value of 6 yes you can see it here then also we can change the type of our variable yeah so here we can never above all named a and we assign a value of 5 which is an interval into this variable okay sorry you are you're seeing me okay okay let me change here to the PC okay yeah you were you were seeing me talking all right so now you should be able to see my screen yeah I to see my robotic neither screen and what I am doing here yes let me wait a moment for for confirmation that you can see my screen yeah all right excellent you see these one second all right so give me once one second looks like there is a all right there yeah it's working because I for one moment I lost the chat and I wasn't able to see your comments so now I have recovered the chat I have switched the screen to the robotic Academy so we are ready to go alright so yeah I was talking here about about the variables yeah and I was saying here that you can even change the type of a variable on runtime so you can declare here a variable which is an integer and write below in the code you can assign a different type which in this case it on a string here so here it's an integral and here I assign on a string to this variable and automatically this very early going to change its type to a string so at the end if we print it we are going to get here ultimately the string yeah so this this basically answers the also the question that master was doing which was asking me what's the value of the LC of the LC variable here so basically this variable is going to get the type of the data I assigned to it yep all right then let's keep going here here we have a small exercise however I don't know yet let's do it let's do it here quickly all together so here it is inside inside the robot control folder create a new python script named variables dot pi okay so here i'm going to create a new python script which I'm going to named variables dot pi yep then inside this script add the necessary code that does the following so first you call the function get laser with any number and stir its response into a variable name it laser one okay so what do we need to do first of all here here is that we need to call that gate laser function so in order to call the Gately is a function the first thing I need to do is to import the class that provides this function yeah so basically I need to import this robot control class so I can take this line from here and paste it to my new script yeah so from the robot control class module I I import the robot control class now what else do I need to do in order to be able to get laser function well I need to create an object of this class and store it into a variable yeah so basically I need to do this one more time then let me do this I create an object of this robot control class and I store it here into the air see very well yep and now I can call the get laser function from this RC variable so it says call the red laser function with any number and store its response into a variable named Acer a 1 so I'm going to create here the value the variable laser 1 and I'm going to go here they get laser function with any number so I'm going to assign here for instance the number 0 let's say yeah ok so here I have imported the road control class I have created an object of this class and then Here I am calling the get laser function with any number in this case it's 0 yep then second you will print this value in order to see what you get ok then here at the end I'm going to add a print statement which I can also to save time again copied from here I'm going to copy and paste it here print the distance measured is and here I need to change this to laser 1 yeah because in my case here I have the value in the laser 1 variable so okay so let's call this program and see what we get so if I execute now this Python script with Python variables dot pi I'm reading here the distance measured is imp what does it mean infinite basically yeah so no obstacle that they detected the laser beam is not colliding with any obstacle in its way and that's the does this make sense yeah it makes total sense why because here we are checking the laser beam number zero and do you remember here that from this image we have here that the laser beam number zero is here it's at the right side of the robot and here at the right side of the robot which is in this direction we don't have any obstacle so it's perfectly normal and expected that we are going to get an infinite value yeah okay so so far so let's keep going what does the exercise say next okay say it's net then you will call the get laser function again with a different number and you will store its response in another variable named laser - okay so now I'm going to create another variable laser - I'm going to call again the get laser function without different numbers so in this case I can use for instance the I don't know 360 yeah which is going to give me a number in this case I know it's going to even me a number more or less 2.5 or something like that yeah because I already saw it here in the first example so I'm going to get a number of similar to this then in this laser - I store this value and then again you will print this value in order to see what you can now so one more time I'm going to print this and in this case I'm going to print the laser to variable yeah so let's try to execute one more time our program and even if everything goes as expected we should get the same as before another line bellow that says the distance measured is 2.5 or something similar to that so let's execute this and effectively here we have here we have the distance measured is in which is the value for the laser beam number zero and right below the distance measured is 2.49 which is the value stored here in laser 2 which corresponds to the laser beam number 360 yeah so this makes perfect sense then at the end here it says finally you will call the get laser function one last time with a different number no you will start it responds in the same variable laser too so one more time I'm going to repeat this but I'm going to store it in the same variable as before in the laser two with a different number so let's say 719 yeah then and you will print again the value of this laser to variable to see what you get now okay and one more time I print the value here in the laser two variable yep there we go so what is the spected output of this program alright so first of all this I should get this stream saying the distance measured is infinite because we are printing the distance at the right side of the robot which doesn't have any obstacle then the second string is going to say the distance measured is 2.49 because here I'm pin I am printing the position 360 which corresponds to the front of the robot so here I'm detecting the distance to this wall here yeah then at the end this same variable laser 2 is going to be reassigned to the position 719 which corresponds to the left side of the robot which again is infinite because we don't have any obstacle here so the spec that is that we are going to get here three different extremes the first one is going to be in the second one is going to be 249 and the last one is going to be in one more time yeah so let's execute these and see what we get and yeah here we have it yeah so we have the first one in the second one it's 248 it has changed a little bit keep in mind that this has some error yes so the letter readings have a small margin of error and finally we have the infinite value one more time yeah okay excellent so far so good so let's see how let me have a quick look at the chart and see how you are doing let me come here okay so the first thing I see here from sagging Aurora Aurora why is the laser measuring different values with the same laser number thicker than 60 well it's because of this because the laser has a small error in its lectures yeah so you are not going to get the exact same reading every time yeah so you have a small error that can be different of course if you add 2.49 here and then I get two point forty eight eight there Rory's is off I don't know it's five four four millimeters yeah so this is an acceptable error of course if I get a 2.5 value and then in the next one I get a 10 meters value this makes no sense at all yeah but you have to keep in mind that there is a small error that can that will make the the readings for I yeah let's see what else do we have here okay my baton code word excellent thanks everyone yes it returns an array of arguments welcome okay oh thank you for clarifying okay I see that you are also I see that you are also talking between you and and solving doubts between you which is super nice that is great I love it so keep doing it if you if you see a colleague that is answer doing some kind of question and you know the answer please go ahead and answer it yourself in the chat so okay Agnieska who cuts says why 719 oh yeah I see that it is already answered so I have here Ricardo which is me support here in the with the chat and everything yeah yeah here it has a noise you can see here Python code works works very well okay excellent excellent very cool yeah Modi for is really cool the simulation cuts error like the real Amano Monday that's right so in a real environment you will also have this error this is the same error margin that the the same laser beam can return different readings and in the simulation you have exactly the same behavior yeah all right all right so let's keep going I see that everything is going is going well so I'm going to keep going let me have a drink on moment all right so let's keep going let's keep working it let's go back here to the curse okay so second thing we have here are datatypes yeah so as you have already seen here you have to be talking about integers strings so in Python you have many different data types yeah here we are just have we are going to have a look at the most import ones which are basically numbers strings lists tuples and dictionaries yeah then for numbers we have two different types of numbers which can be in terror like this yeah and we have also floating numbers yeah so 0.5 is a float yeah this is pretty easy so I'm not going to to talk much lose much time on that then we have strings which basically it's this it's a phrase yeah a character of us or a sequence of characters this is known as a as an a string which are declared like this yes so as you can see when you declare an integer or a float you can declare it directly like this yeah you're gonna sign it like this you don't need any you just put the number and that's it it's going to be stored into a variable in a string you need to specify here the double commas or single commas and put the string inside yeah this is required when you declare an string yeah as you can see here for instance Oh always always you are going to work with the screams you need to put put it inside doable commerce or single commas yep then also here you can see that you can access different sections of on a string here yeah so for instance here let me if you execute let's make this bigger so you can see it better so here for instance I have s1 we where I have stored this is our string and I have s to where I have stirred this is alter string then if I print this value s1 and I specify the 0 position what is this going to be what is this going to to print while trying to print the position 0 of the string which is this T yeah this is the position the first chapter of the string is the position 0 of the string yeah so this is the 0 position the H is the position 1 the a is the position to the s is the position 3 the white space is the position before so white spaces are also chair actors yeah and for instance here we have from the s2 bring the character number eight which is we have one two three four five six seven eight zero seven eight yeah here we have it so the eight is the number is the charter a yeah here you have the expected output if you have secured this program yep alright and finally you can also concatenate strings here as you can see so if you have one string which is this is another string which is a string you can concatenate them you can using here the at the at sign ball yeah s1 plus s2 is going to result in this is a string yeah you have it here all right then another data type you have our lists yes so least are definite like this so we have an opening parenthesis here and a closing one and inside we have many variables separated by commas yeah it doesn't matter which type are they so in this case here I have one which is an integral a to which is another interior a three which is another interval and then I have here under string another string another string and another string yeah so all these elements all these variables are going to be contained in to the list yes then let me execute this so that you can see it if I print this I'm going to get the whole list but same as with the strings we can also access and a specific value in the list yeah so this first element is going to be in the position 0 this is going to be the position 1 the number 3 is going to be the position 2 this is going to be in the position 3 yeah so for instance if you have value number two from the list we are going to get the number three as you can see here yeah a little bit faster okay okay excellent okay okay so let's okay I totally already so let's keep moving a bit faster so yeah so basically as you can see here it can contain many variables inside tuples basically it's exactly the same as a list with the only difference that tuples are read-only yeah so in a list you can get the values you can modify them etc yeah in a couple you can only read the values you cannot modify the values yeah this is basically the difference between lists and tuples and finally we have dictionaries yet dictionaries are similar to lists as well but each value inside the lectionary has a key yeah so they are dictionaries are a composite of pairs of key value yeah so here we define a key which in this case is John and this key has a value of 25 yep then you have a second element here inside the dictionary which has a key here in this case the key is Daenerys and the value of this key is 22 so if we want to access a value inside a dictionary we do not access it through position like in lists or in strings like you can see here but we access values using the key yeah so if I want to get the value of this element I'm going to have to access the dictionary and pass it the key the respective key which in this case for instance is John yeah all right so we have a small exercise here that I think well we could pass but I'm going to do it because here we are introducing a new function from the class which is the gate laser full yeah so until now have been working with the get laser function yeah this get laser function we have here which basically returns one the value of one single beam yeah depending on the position we put in when we call the function yeah then now we are going to introduce another function which is called get laser full yeah you have it here I wrote it adjusting the code and you have it as well here but basically this kind is our function is going to return all the values of all the beams not just one battle from the zero to 719 it's going to return all the values and how it's going to solve what is going to so with using a list yeah so here with the get laser function we get one single value which is a float and we stir this value into the variable whatever yeah then here with the get laser food function we are going to get all the readings and they are going to be stored into our variable as a list yeah understood so let me come here real quick yeah I'm going to create this one in fact so that you can see this because this is important then I'm going to create here a name Python script which is called list dot PI you can see it here and here what I what I'm going to do basically is to use this Ganesha function get laser full function so I'm going to copy paste my code here yep and then here I'm going to call the get laser full function in this case I don't need to pass any argument yeah because I don't need to specify any position because I'm going to get all of them yes then I'm going to store all these values in a variable named a which is going to be of the of the list type is going to be a list yes then for instance now if I want to print the value the only the print if I only want to print the value of the position 360 I can do this and access here to the specific position like this yep for instance I don't know what the exercise says it he says first you will call and we'll stir then you will print the position 0 360 and 7 ok yeah so basically the distance in position 0 is okay so I'm going to do this three times for the three different positions the in 360 and 790 yeah so I have my list with all the values here in the variable a and then I'm going to print here the position 0 so I specify my variable name and I put here the number 0 because I want to print only the first value the value in the position 0 then here I have the 360 value finally I'm going to print us well the 719 yeah so I'm going to get infinite first zero 2.49 or something like that for 360 and infinite again 419 yep so let's try this let's execute it real quick and there we have it yeah so the distance in position zero is infinite in position 260 is 2.47 and in 719 it's infinite again all right ok so now we have this other function really sort fool yeah we have already two functions then let's keep going we have another exercise here we are not going to do it because it's more of the same basically here we are working with different types the Canaries etc then very quickly input of output function so for output functions you have already been working with them it's spread yeah so the print function is going to allow you to output things here to the web shell yep super simple yeah you can print anything you want you have here some examples if you want to check them I'm not going to go deeper into this right now yeah but basically if you want to output or communicate something to the user here through the shell etc you are going to use the print function but there's also the other way around which is to get data into your program from the user yes at that is done using the input function we have here yeah so the input function is the contrary let's say to the print function so basically pop fusion is going to ask information to the user which is executing the program and then is going to get this data and use it inside the program yeah so for instance we have an example here which says name yeah let me create here a program a very quick program to show this new file in I'm going to name it input dot PI and I'm going to copy this code here and paste it here yeah so super simple here I'm executing an input function I here I'm calling the input future with the text what's your name yes then this let me execute it in fact so python input yeah so these prints this a string here then what's your name our string is printed here in my shell so now I can write here my name for instance Alberto and if when I press the Enter key this value alberto this string is going to be saved into the variable name yeah so then the print function is going to be called and it's going to say nice to meet you and Alberto because it's the value that it has been saved here in the name variable yeah so I'm going to click here the enter and I can see here nice to meet you Alberto yeah so this way with the input function you can ask the user to review some kind of information so you can use it in your program in your Python program yeah all right so input/output functions let's keep going here we have another example of inputs but I leave this for user you can check it later this one is interesting because it's an important difference between Python to a Python 3 but anyways you can check it later yeah by yourself because now it's not crucial all right then finally super quickly as well operators operate operators in Python we have aromatic operators which are basically addition subtraction multiplication division and modulus yeah I think all of you are aware of these know what this is so no more explanation needed assignment operators yeah we have the operator to assign a value so this equal value basically will assign a value to a variable yeah then you have also the plus equal my equal and multiplication equal division equal and modulus equal which are equivalent to these yeah so if you write for instance this X plus equal one this is the same as saying X is equals to X plus one yeah this is more mathematic something more mathematical than Python Soho so yeah I'm not going to spend much time on it as well and probably you already know this is done I think it's explained in the first week of universities so so yeah then comparison operators this is going to be very important when we reach the conditional statements yeah so this one this is it is morally important so in order to compare two variables we have the equal which is expressive like this with two equal equal symbols we have the exclamation symbol equal which means not equal yeah then you have the greater than less than greater or equal to and less or equal to yeah so these elements are going to be you said in conditional statements like we can see here which are the probably the most important things in in in a Python program yeah because without conditional statements it's impossible to build any useful program yeah we are going to do this I think in the next unit so don't worry but super important comparison operators when we are working with conditional statements yep then finally comments you can write comments in your Python programs like this using the hashtag symbol yeah so for instance I can come here to my program check up here and I can add a comment here for instance I will write a hashtag symbol you can see that the color is different and I can add here any comment I want so for instance this get laser fool function gets all the laser readings yeah so I cannot hear a comment and this is not going to be executed yeah so when I execute my command Python whatever this line here that the first with a hashtag is not going to be executed yeah so basically these commands these comments can be used in order to document your programs yeah because if you are going to work in a team and other people are is going to be using your programs you can document and add comments so that your programs are easy easier to understand yeah or for instance if you don't want if when testing you want to remove a line of your program you can just add a hashtag at the beginning of the line and this line as you can see turns green and it's not going to be executed any more yep all right so we have finished first chapter Python sessions so far so good I'm going to show all of you please move to chapter 3 conditional statements and loops let's click here on the chapter and meanwhile it is loading I'm going to have a look at the chat and see how it is going okay I can see here thank you okay I see some people asking about the exam where is the test how many times I have to take the exam okay don't worry and when I finish this life class in 40 minutes more or less I'm going to explain you how you can reach the test how to go there and how to do it so don't worry ready yeah everybody is on path our argue on unit 3 conditional statements and loops all of you yeah let me refresh this to see the situation nicer by the way because I've seen this block here alright let's see ready yeah we are on track loaded excellent I see here thank you so much for this program from America you're welcome funny you're welcome no free day tomorrow we start Ross yeah that's true Kobe to tomorrow no free day tomorrow we are going to start learning Ross so I want you everybody to be here with me learning Ross I am loaded unique ok you need 3 loaded ready unsaid yes you need 3 ok let's go for it then everybody is here engineer 3 with me so we are going to start here with conditional statements which as I've said before they are essential in in any program yeah so as as as as we have here in the notebook life is made basically of decision so you have always to make decisions in your life here and in in programming is the same here so in your programs you have to take decisions yeah so for instance let's have a look here at this graph here that we have here so I could beat up here we have a question a condition which is this one here in red the condition is is there a wall less than 1 meter in from of the robot then the oku can be either yes or no which in your program this reduces to true or false yeah so if the condition is met that operation is going to return a true value if not that operation is going to return a false value yeah so our condition here is is that of all less than one meter in front of the robot yes or not if yes then we are going to stop the robot if no then you are going to keep moving the robot forward and in either case in any of these cases you are going to print the distance to this world yeah then this in a program in a less true this is not a definitive program but just an instructor would be written like this if one is close yeah this is the condition to evaluate then stop robot else which means if this condition is not met then keep moving and in any case print reading yeah so this this is chained we have here would be reduce it in a program in something like this yes then you can see some things here first of all is the indentation so you can see that this this here it has a separation it's not are starting at the same level of the if the same here with the else what we have inside the else is not a starting at the same level yeah this in Python is called indentation yeah this is an indentation then what does this mean that this line here which is indented it's inside this condition so it's only going to be executed if this condition is is met and the same for this one this line here which is indented it's only going to be executed if the above condition is met yes if this condition is met this line is not going to be executed ever the last line however is going to be executed in any case why because it's at the same level of this of these conditional statements yes then as you can see here if condition and you have the statements here intended super important day indentation yeah this is crucial and critical in Python if you don't indented your program properly it's not going to work yeah super important here you have it explained that blocks and invitations then we have here a very quick example let's get it and execute it very quickly so I'm going to create here a five movie not pi so again remember everything I'm doing is explained in the notebooks yeah so I'm going to create here new Python script which is going to be named five movie dot pi so here new file five movie dot pi and here I'm going to paste the code I had there in my notebook and basically this program is super simple so we have I have an input here which is going to ask to a user what's your favorite movie then I'm going to save the response the answer of the user into this variable movie and then I'm going to check what does this variable contain if the variable contain come if the variable movie contains the string Avengers and game I'm going to print here and a string to the user which says good choice yeah so I'm going to do this I'm going to execute this piece of Python script so it's inside from a control Python fab movie here I get what your favorite is my what's your favorite movie then I'm going to enter here Avengers and game I'm going to click enter and then I'm getting an error it's happening why not sure and game okay yeah very good point that I'm getting this error do you know why I'm getting this error because I'm not executing this program with Python 3 yes I haven't sorted my environment to use Python 3 you can see that here in my prompt I don't have the Python 3 prefix yeah so I'm going to that right now source if I'm not wrong this was me check here PI 3 when been activate yeah so now I am inside my Python 3 environment so now I can execute my program and it's going to work yeah it's not working because I'm not in the folder where the program is now I am yeah Here I am I have the program here so now I can do Python fat movie what's your favorite movie Avengers end game what okay okay all right so here you can see that I have a skit with the input to the user to tell me his favorite movie then this condition is met and then this print is executed yeah if not however if I don't choose this movie I say for instance I don't know Titanic then nothing happens yeah because this condition is not met if movie movie is not a Rangers game so this condition is not met and then this print is not printed yeah okay so pretty straightforward you have some more examples with with other options well this one is it could be interesting to put yeah so let me just execute this one which is the more complete one then I'm going to paste it here and I'm going to explain just a couple of things so basically important here the same I am asking the favorite movie but I am here taking much more considerations so here I am checking if the movie is Avengers a game or Titanic yeah so you can put more than one condition in a conditional statement yes so I can check if this or this then invader of these two conditions if one of any of these is met then I'm going to enter this print and I'm going to execute this print yeah then I leave what does this mean this means else if so besides the first condition I'm going to check another condition yeah so if the movie is a Star Wars then I'm going to enter here in this print yeah and else if any of these conditions is is met so if any of these conditions Russell in true then I'm going to print this yeah so here I have all the options all the options contemplated yeah because you can you can choose to input this movie or this one or this one or any other and then you are good you are going to get anyways an answer yeah so this is basically the conditional statement you can use if else--if which is you said is the l if keyword and else yep then here we have a very interesting exercise in fact that we are going to do because it's very interesting then where i'm going to do it with you so we go faster then we are going to create here the test if python script so let's create a new file new file test if dot file then so inside this python script we are going to create a program a python program that reduces the flow shirt expected above the short about this flowchart the the one with it at the beginning which says easter a world less than one meter in front of the robot yes then stop no keep moving print reading so we have to create that program that reproduces this and that works with our simulation yeah so the expected behavior is this one is shown here so okay let's do it let's do this then what do we need let's get here the stupider from here so I'm going to do it from here the structu robot controller control then two new fusions I'll introduce it here move it straight and stop robot yeah well they are self-explanatory so the movie straight is going to move the robot forward yes in a straight line and the stop robot is going to stop the road movement yes so super super simple then how can we do this so first of all we need to get the value in front of the robot yes so we need to get some kind of information from the laser of the robot yes so we need to know what is the distance of this wall in respect to the robot we need this so this is all right then with this we have to start evaluating this so if a if the value a is lower than 1 meter what am i what am I going to do I'm going to call the move straight function yes make sense then oops I said this then else if not no sorry if if the distance is lower than what I'm going to stop the robot not moving straight then else I'm going to move a straight yes does it make sense so first of all we get the reading of the laser right in front of the robot so that we can know the distance from the robot to the wall then if this distance is lower than 1 which means that is lower than 1 meter we are going to call the stop function which is by the way it's not the studies stop robot so I need to modify this so I'm going to call the stop robot function which is going to stop the robot then else if not if it's higher than one meter I'm going to move straight and finally I'm going to print the distance to a robot yes then we are going to execute this and you're going to see the behavior so as you can see the robot is not stopping it keeps moving forward and until it crashes with the wall why do you stop urning well this is interesting and let me explain it super quickly first of all let me stop real quick the robot from moving forward all right and I'm going to reset here the position of my robot so that it goes back to the initial state there we have it all right then what is happening here well the thing what is coming here is that we are evaluating the distance one single time here you can see here when I execute the program I got the distance of 246 which happens to be higher than one so my program enters into this condition which is moving straight so the robot starts moving forward I print the value and my program stops so my robot is going to keep moving straight until it crashes with the world yeah then how can we solve this whoo how can we make the robot stop before before crashing with the world well for this we need to me to find a way to constantly evaluate the distance here so to repeatedly evaluate the distance to the wall and how can we achieve this with lose yes with a loop which comes perfect now to start the loops section so what is a loop basically a loop is a way of constantly check a condition yet here we have the flow chart so instead a wall less than one meter in front of the road yes then stop the robot no then keep moving and go back to check this condition yeah so this condition in case it's not met is going to keep repeatedly evaluating itself yes and who do we do this well this flow chart will will result in a program similar to this so while wall is not closer than 1 meter I'm going to keep moving then when this condition is not met I'm going to go outside this loop and I'm going to stop the robot yes so this is the easiest loop that you can see so we have a counter which isn't it initialized to zero then while counter is less than 10 I'm going to enter and I'm going to execute this so I'm going to first of all add one to the counter so counter variable is going to become one then I'm going to print the value which is going to be one and then I'm not going to keep going down the program no I'm going to go back to the first line here to the while and I'm going to evaluate now so now counter is has the value of 1 so it's still met this condition so I'm going to keep executing this and when I reach the end of the loop I'm going to go back at the beginning to evaluate again the condition until this condition is not met so when this condition is not met so when this counter variable is 11 let's say for instance then this is going to break and it's going to keep going with a regular flow of the program yes then with this being said how can I fix this program so that I get the expected behavior yeah so what would you do so here we need to add the while loop so while a is higher than one yes so while the distance to the obstacle is higher than one I'm going to keep moving the robot yes but what else I need to get the new reading yes so I need to evaluate one more time the distance yes so I need to update the value of a because otherwise hang on I am only going to get the first value here so I need to rare evaluate so get the new updated value yes then I mean fix this real quick let me put here a print I'm going to put it inside the white so that we get information about this yes so are you following so basically here I'm going to get a first reading of the distance to the to the world yes then while this distance is higher than one I'm going to move the robot forward straight towards the wall then I'm going to reevaluate the distance to the wall yes here you have it I'm going to reevaluate it I'm going to update the value of a and I'm going to print the current distance and then I'm going to come back here and evaluate this new value and when this condition is not met so when the wall is closer than one meter I'm going to stop dead or robot yes then let's test this program now let's execute it so python test if let's see what happens now we are quick here okay let me execute it they it starts moving forward and now the robot has stopped yeah so once the value has gone under 1 the robot has stopped yeah so this is the power of loops yeah they allow you to constantly keep evaluating condition and even updating the variables evaluated in that condition yes so this water Wiles for where this water what loops are for name basically Python we have two main kinds of loops which are the wine loop which is the one we have seen here and we have also the for loop yes here you have it which is basically another another way of creating loop yes you have here the example the most basic example of a for loop so given a list for instance here I have a list of names with Yoda obi-wan Anakin and Palpatine yeah then I can say for each value in this list which is named names yes sorry so for each element inside this variable inside names I'm going to print each value yeah so if I execute this loop I'm going to get the following result I'm going to print all the elements inside the names list inside the names variable yes excellent so let me have a quick look at the chart and see how things are going I have been talking for a while how do you arrest their opposition Wow okay so the rub opposition your acetate here here in the simulation we know in the in the icon we have at the at the center at the middle it says rest of the simulation if you pick here as you have seen the rod will go back to its initial position yes this is the way you can rest the robots position my robot didn't move robot is a movie what well then probably then probably you have something wrong key your program I would say yeah when it's okay Benjamin receives code is working yet they so if you have seen this is pretty simple I have executed right here so your rod is not moving probably you are not calling this function basically yeah so there must be something wrong in your code you are not calling this function or you are not importing this class there might be something wrong in your code yeah so have a look at your code review it and see what's wrong there my while loop is working Gloria yeah yeah okay so I'm glad that it's working so for the ones who is are working please have a look I have gone pretty fast now so have a look slowly at the at the curves at the notebooks at your programs and fix it yeah then okay so we have 15 minutes left let's keep going a little bit more here try to end this here you have inter interruption of loopy iteration breaks so how you can break the flow of a loop I'm going to escape this because I want to you can check it by yourselves when the class finishes I want to go to functions and at least explain the sense of things of functions so I'm going to move here to the unit for functions yes I want to at least do the introduction to functions they have known the world lectures you have lecture what about the functions yeah the five is about Python classes an object-oriented programming and six is project yeah maybe to try to refresh your course I don't know so you should have here the same as I have so one introduction to Python essentia three conditional statements and loops functions Python classes and OB which is object-oriented programming project and finally you need several recommendations after the course yes you should you should you should have exactly the same as I have here yeah okay so as you can see first of all here in unit 4 functions we have a new robot yes so we have changed our robot we are not working anymore with total BOTS and now we are going to start working with us Amit exile robot yeah the environment has also change at this is a novice as you can see here with different rooms yeah so all of you should have this environment here loaded yes you can make it bigger here in order to see it better to appreciate it better yeah but all of you should have this environment now we are in unit 4 functions yeah so functions what are functions for well the control of function its first of all about you see that it's super important one of the most important concepts in programming yeah because it allows you to to group some kind of functionality in order to be able to reuse it on your code yeah so this is the the main goal of a function yeah it allows you to write some kind of functionality to wrap a piece of code that provides some kind of functionality and you can reduce that in your code or even in other programs yeah so that you don't have to right again and again and again the same thing yes then how do you create a function well you use the DEF statement like this yeah so you use the DEF estate man you give a name to your function and you put opening and closing parenthesis yes then inside the function you put whatever you want to do yes so I'm going to create here simple months of resistance I'm going to create here a function that is going to add yes so I'm going to wrap here this I'm going to get here a new Python screen which is going to be named test function dot pi I'm going to paste here the code yeah so basically here we have everything so we have the function definition my function is going to be called at and it's going to receive two parameters a and B yes then inside diffusion I'm going to grab these parameters a and B and I'm going to add them and I'm going to put the result of this operation into a new variable named res and then I'm going to print this rest variable yes then here what I'm doing is I'm calling this function and I'm placing two parameters - and - yes so the first value here is going to be assign it to the argument a and the second one is going to be assign it to the argument B yes then inside main function I'm going to add two plus two so that I'm going to have here in the result variable they integral four which is the number I'm going to print yes so super super simple function which adds two numbers then let me execute it let me execute this Python test function all right I'm not in the correct folder from here okay now I am python test function so I get here the for number yes as you can see so important things so things that you need to know here about functions you define a new function using the devastate meant like this yes that you give the name to your fusion and you select the parameters yes you can give default values to your parameters like this here in the next example you can see that we are declaring the parameters and we are giving default values so in case I call this function without providing the parameters then I'm going to use the default values yes then inside my function I do whatever I want in this case I do a an ADD operation and I print I return a result yes so this is the most the most basic function so here in this exercise it says create a function that given an integral number makes the robot move straight for that amount of time for instance if the given number is 5 the robot will move straight for 5 seconds yes then let's do this so I want to do this exercise because it's interesting in order to end this is the last exercise we are going to do yeah so I'm going to do this this here ok so for this I'm going to need different things so first of all I'm going to need to import my class here here ok here we go test function so I'm going to import my class so that I can use the functions yes I need to import my role control class so that I can use the movie street functions and all these functions yes then also I'm going to import time here this is explain it here you can see here in the note if you want more details about this I'll how to use the time model in Python but I'm going to import time here which is going to allow me to pulse my program for a certain amount of time yeah then here I'm going to fi my function so death I'm going to call my function move 5 SEC's no I'm going to call it move X sex and then I'm going to get the final a parameter here which is going to be call it seconds yes then inside my function I'm going to call the LC element and I'm going to call the move straight function right here yes then I'm going to do an asleep time a sleep of the parameter seconds yeah so I'm going to sleep I'm going to pass my program for unspecified number of seconds and then after this I'm going to stop the robot go into one more time call the function the corresponding function to stop the robot which it was stopped robot yeah then here I'm going to call this function which is move X sex and I'm going to specify the number of five so I want to move forward for 5 seconds after that I want the robot to stop yes so here I am calling my function I am defining this parameter I am setting this parameter to 5 and then I'm going to start moving the robot forward I'm going to sleep my program for 5 seconds while it is moving forward and after these 5 seconds pass I'm going to stop the the robot yes so let me save this and execute it and see what happens so python test Koshien there we go okay so you can see here my robot it starts moving for some seconds and after the five seconds pass it stops yes so you can see I have created here a very simple function Python function in order to move my robot a certain amount of time yes then so yeah here I have created my first Python function I see that we have five minutes remaining so I'm going to start ending here so I want you to please keep doing by yourselves what is remaining here there is not much as you can see so we are explaining some special cases about functions some interesting things and important things by the way like how to use global variables also how to use the return statement at that Allah you have some interesting exercises here that you can use as you can see here you have the solution for all the exercises in case you have you get a start as you can see here below the exercises you have the solutions so you can clip practicing with functions super important and when you finish it when you finish functions you can move to the next unit which is unit 5 which will talk about Python classes and object-oriented programming yeah so please if you have time keep doing it keep working on this course if not you can also continue tomorrow it's necessary that you continue today you can continue you can have a break now to to to make a coffee whatever continue later you can continue tomorrow you can even continue I don't know Thursday if you want to it doesn't matter but it's interesting if you don't know already this if you already know about this it's fine you can skip it but if you don't super interesting that you finish this course because you are going to get very useful knowledge and totally for free yes then finally beaver and in this class I want to I to exceed here I'm going to go back to my main screen then here you can see at the beginning at the top section of the screen you can see the code foundation for Ross yes here the practicing scope for nation this in the feed rate paths section yes then if you enter this one the code foundation for Ross we are going to see here that you have the Python for robotics course the Linux for robotics course and finally have their prerequisites exam yes then here you can if you click the S turn exam you are going to enter the exam yet that tests the evaluation test which is going to test your knowledge of line looks and Python yes then this is the way you are going to be able to do this exam yes then very important be sure I even remember that me home will advise you have for this exam maybe two okay so you are going to be able to do these examples many times as you want so so yeah once also important once you enter this exam in fact I'm going to enter real quick to show you okay well you need to verify yourself yay important I don't have it done here in this account but you are going to need to verify yourself because this is as as I've said before this is going to generate a certificate yeah so we need some kind of proof that it is you the one that is doing the certificate and you are not calling I don't know you are not calling Stephen Hawking to do the exam for you yeah so you we need to make sure that it's you who is doing the exam yes then when you finish the exam you are going to have a system that is going to automatically correct the exam and is going to provide a mark to you yes all of this is going to be explained that here inside the notebooks Excel so don't worry once you enter the exam you have a look at the notebook and all three is going to be properly explaining how to auto correct the exam with a single click in a water so no more than that yes but yeah here is where you are going to be able to enter the exam yes and what that's basically it so let me have a quick look at the chat let's see what your guys saying yeah Alberto is a friend right now at the exam yeah so let me switch well super quickly before showing you all of you my pretty face I want you to I want to show one last time here the the schedule so remember remember today we have done the Python for robotics we have not been able to finish the workers because of time limitations it is impossible you have too much things to cover then please do it finish it by yourselves you have already you already know who talks as the course is totally official you can do it then once you finish I look for a budding some Python you can take this advice with Aisha test which I have just explained as well how to exceed it and then tomorrow we are going to start working with Ross yes then tomorrow we are going to change the platform we are going to start work working with the Ross development studio so we are not going to work anymore with the we are not going to work anymore in rhodonite Academy but we are going to move to the Ross development studio which is right here yeah Ross the s online from tomorrow until Friday we are going to start working on the Rosa polymer studio yeah then tomorrow before starting I am going to explain about the Rasta banana studio I'm going know how you can use these difference with the Academy etc yes but this is going to be tomorrow so don't worry now then ok let me show you my face before finishing hello there let me have a look here at the comments you are saying here yes oh I can see here my colleagues are answering your question how long is the exam you you can take it there Sam I'm not sure it's two hours so you have two hours to the exam if I know if Eve I don't remember wrong all of these explain it inside the examiners notebook yes so once you open the exam you are going to have a notebook the same as in the course and in the exam in the exams logbook everything is explained how much time you have and also what what you need to do in the exam yeah Thank You Siri thanks Alberto okay okay how can we contact you guys for more information on the robotic Knight Academy okay if you want information about the platform you should contact us to the email that we are going to provide it to you right now or you can search it in our in any of our platforms you are going to find the contact us section yes so if your information about the platform then you can contact us to emails or if it is information right to the courses in our Academy then do you have to post it in the forum yes in the form I explained at the beginning of this class so if iterated to course I stopped doing the courses problems you face while doing the courses then please post it in the forum thank you so much for the goose gracias there's the okay thank you from Argentina okay okay can we give the exam multiple times yes you can talk it you are going to be able to repeat Exim in case you fail it Gloria I say I think the speed was fine it just not possible to complete the five plus hours course in two hours yeah I mean that's completely impossible to do the recording in two hours it's completely impossible and and the speed it's a it's a hard thing to say I mean because we have people from many levels and we can we can go faster we can go slower if we go very fast probably the ones that cannot follow we complain if we go too slow than the ones which have a higher level will complain so it's hard at the end to satisfy everybody yeah but well we try to do our best at least now we have completed the prerequisites and tomorrow we are going to start with Ross yes so I going to try to follow one in Germany but not very slow and not very fast so that everybody is happy I will do my best to satisfy all of you so so yeah I have here Ricardo which is oh yeah you can see here in my bottle fine drinking and I'm revealing here my super fancy Ross developer coupe by the way also because science hi yeah and we talking non-stop for two hours so I need to keep is rotating my throat yeah alright so speed is fine I can read here thanks so much for the course it's just a start but fun so far and gives and idea what you can do oh you're welcome you're welcome easy to understand okay excited for tomorrow yeah I'm excited as well so tomorrow we are going to start Ross we are going to start learning how to use words to program robots yes so yeah I think that's all for today I hope you all enjoyed you've learned something new I hope to see you all tomorrow I want to repeat today also as I did yesterday please stay home don't go outside we have to stay home and be responsible in order to win this fight against the current views that come in nineteen so all of you please stay home and we are going to provide you content and so that you can stay home learning brought some practicing Ross yes so that is our work to give you content so that you don't have to go outside yes then alright so yeah all of you thank you very much for attending this class and I will see you tomorrow for the first Ross pass yes so to start learning basic concepts on Ross so okay I'm going to wait a moment Ricardo's telling me here to wait so you don't get the link to which the phone okay so the forum well the following you have the link right here in the github button yes here in the roti Knight Academy you are going to see here a button which is get help in yellow so if you click here is going to take you to the to the forum you know no big no big mystery alright you have it here and here you can post any any questions you want related to the courses yes I can see here a new post from Gloria Felix one minute ago who says want to join an online process to the group yeah so here we have the first post from Gloria very nice Gloria you have reached here the forum perfectly alright so so yeah I think okay so let me finish this so thank you all very much I will see y'all tomorrow for the first Ross class and keep pushing your Ross learning bye bye [Music] you
Up Next

ROS Coordinate Frames and Transformations for F1tenth | UVA Course
@madhurbehl
15.9K views•2020-03-18

RatSLAM: Biologically Inspired Robot Mapping and Navigation
@milfordrobotics
20.9K views•2012-08-03

Outdoor Robot Navigation with GPS Using ROS: Jackal Simulation
@TheConstruct
15.8K views•2018-04-07

Introduction to Robotics | Stanford CS223A Lecture 1
@stanford
744.4K views•2008-07-22
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Robotics




![[5]–ROS2 Basics Explained – Nodes, Topics & Messages [شرح بالعربى]](https://i.ytimg.com/vi_webp/x7fgj2tMVLg/maxresdefault.webp)
















![ROS2 Tutorial - ROS2 Humble 2H50 [Crash Course]](https://i.ytimg.com/vi_webp/Gg25GfA456o/maxresdefault.webp)












![Curso de Arduino : ROBÔ EQUILIBRISTA - [ Aula 018 ] - Implementando o Controle PID de Equilíbrio](https://i.ytimg.com/vi_webp/MDzaPBjrDzA/maxresdefault.webp)




