Raspberry Pi Pico W LESSON 43: Measure Pitch and Roll Using a 3 Axis Accelerometer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Paul mccorder with toptechboy.com and we're here today with episode number 43. in our incredible new tutorial Series where you are unleashing the power of your Raspberry Pi Pico W what I will need you to do is pour yourself a nice tall glass of ice cold coffee that would be straight up black coffee pour it over ice no sugar no sweeteners none needed and as you're pouring your coffee as always I want to give a shout out to our friends over at Sun founder Sun founder is actually sponsoring this most excellent series of video lessons and in this class we will be using the Kepler kit for Raspberry Pi Pico W most of you guys probably already have your gear but if you don't take a look down in the description there is a link over to Amazon you can hop on over there and pick up your kit and believe me your life in my life are going to be a whole lot easier if we are working on identical Hardware but enough of this Shameless self-promotion let's jump in and talk about what I am going to teach you today and what I'm going to do is I'm going to show you my solution to the homework assignment that I gave you in lesson number 42. so so I must ask how many of you guys were successful if you were successful leave a comment down below I Am Legend double chest bump and if you were not successful leave a comment down below I folded up like a cheap Walmart lawn chair okay now hopefully some of you guys got this and I think it might be some of you would just get so locked up and not able to apply the math you know to the problem you have it's like over here is your problem and over here is the math you know but you have trouble taking the math you know over to the problem you have but never fear if you got confused with it I'll show you how to do it and I hope at least when you watch me do it you'll kick yourself and say well yeah why didn't I see that well when you see me do it enough times then with a little thought and a little practice eventually you'll be thinking like an engineer also and I hope though I hope a few of you guys were actually able to figure this out because I did give you I did give you some pretty uh some pretty good hints okay so what was the homework assignment the homework assignment was that last week last week what we did was we were we were able to calculate the Tilt like if I tilted this 20 degrees it would read 20 or if I tilted it this way 20 degrees it would read 20 or 20 or 20. but the problem is really what you want to know is you want this to be like negative 20 positive 20 and then you want two distinct things you want the Tilt along this axis which would be pitch and the Tilt along this axis which would be roll so you would want a positive and negative pitch and a positive and negative roll so we need to be a little bit more careful with what our trigonometry we need to take advantage of some of the data that we have that we didn't use in that first that first solution last week so let's see let's do a quick just get you caught up in case you're just jumping in here and haven't been with me on the last few lessons what you need to do is you need to go to www.toptechboy.com click on the happy little Search tool and then search on something like schematic for tilt meter you'll come to this page this is the schematic I have the mpu 6050 and I have the 1306 OLED we're not using this yet but you might as well get the whole thing set up hooked up because we'll be using this in the future and this is just some simple code we're going to copy to get the you know to get the accelerometer going okay so this is from a few weeks ago so you get that code let's come over to thawny and let's paste it in and then there were a couple of things I found that this round function doesn't really work in micro python it sometimes gives erroneous results and so I'm going to take that out and we're just going to measure X acceleration y acceleration and then also we want to measure Z acceleration so we're going to see say Z acceleration is equal to mpur object dot Excel our method dot Z that's simple enough and then let's let's go ahead and print that out here as well along with X and Y we will print the label Z okay and then the value Z acceleration and then the tag G to show that we're measuring in G now with the little luck this should run but let's go ahead and make sure that this is going to run that's good in those edits I didn't make any problems so what do we see we see that uh let me switch back over here we see that in the x-axis we see in the x-axis we're measuring 0 g and the y-axis we're measuring 0g and in the Z axis we're measuring one G why because that proof mass in the Z axis is feeling the acceleration of gravity it's feeling that one g of the gravity pulling down on it so it reads one sheet now what we saw in earlier lessons is as we tilt this thing as we tilt this thing around all of those values change and interesting and might I say mysterious ways and so what your homework assignment was what we had done in the earlier uh lesson we could just measure any tilt would just be measured as tilt but what we wanted to do now was specifically measure pitch positive and negative enroll positive and negative so we want to get both angles okay how does that sound I hope that sounds pretty good and so what we need to do is we always need to start with what a bunch of if statements and looking at the data and just coding like a wild man no we want to stop and think like an engineer and what does an engineer do an engineer always starts with a picture a picture of what he or she is trying to solve okay so let's come in and kind of what we're thinking about is we're thinking about tilting this so let's start with this picture a lot like we did last week but we'll just kind of start again here and we have the board is tilted okay the board is tilted like that I don't like that let me try again okay we'll come in here that and now the board is tilted so we'll come up like this and then we'll come from here to here and that is a tilted board and we have a right angle here all right now what do we have we have the accelerometer we have the accelerometer we have the mpu6050 on that tilted board and so what I'm going to draw here is I'm going to draw that z-axis proof Mass let's see that's let me try that again I'm going to draw that Z axis proof Mass like here to here that that's that z-axis proof Mass okay now what we want to do is we want to start drawing our vectors that gravitational Vector comes Square it comes straight down and it is 1g so that is a force acting on that z-axis proof mass and so let me see if I can draw that in there let me see if I can draw that in there so I'll come here okay like that that's gravity but does the z-axis proof Mass respond to that Vector no it responds to the force coming in perpendicular the perpendicular to the Tilted accelerometer so let's see if we can draw that and so that perpendicular vector would be like that okay and now what do we also have we also can finish the triangle like that okay and I have got to do that again I actually just have to do that again because I just didn't quite make it good enough to do the drawing like I want so let's start with the gravitational Vector it comes straight down like that you see I really needed it to be a little bigger now the orthogonal is the vector that comes in perpendicular to the proof mess that is what the proof Mass responds to so we'll come here and that one is going to come in perpendicular okay and then maybe and then we have this one okay and now what is this this is a right angle okay now how far did we tilt it we tilted it Theta and then let's label some things that we know this Vector here coming down we know what that is right that's the gravitational Vector pointing straight down and that's one g but going back to trigonometry on our triangle that long leg opposite the right angle is the what it is the hypotenuse okay now we also see that this angle is going to be the same as this angle so this angle is also Theta because you see a Theta 0 the orthogonal and the gravitational are the same there's no Theta between them or if you tilted it 90 that other one is going to be tilted at 90. so you can see that that is the same angle all right what do we call so Theta is our angle of Interest what do we call the side that is adjacent to the angle of Interest we call it the adjacent side so this is our adjacent side and then what is this up here this is our opposite side okay so I want to figure out what Theta is and what do I know I know the hypotenuse and I know the adjacent so let me just catch you up what we did last week and then let me show you how we're going to do something different this week what we can do from what we learned in our practical trigonometry lesson what do we know no we know very simply that uh the the cosine of theta the cosine of the angle why did I choose cosine because it's the one that wants to use the adjacent and that is that z-axis and so that is going to be equal to the Z acceleration over the hypotenuse now what do we know the gravitational Vector is one so this becomes simpler and what does it become it's just the Z acceleration all right now I have cosine of theta is z acceleration but I want Theta so what could I do I could take the The Arc cosine The Arc cosine of cosine is just the angle and then what I would have is Arc cosine of Z acceleration and that would give me the Tilt but the problem is that's going to give me the Tilt whether it's tilting this way or tilting this way or tilting in any which direction I'm losing all access to did I tilt positive did I tilt negative did I tilt along the y-axis did I tilt along the Z axis you see I'm losing all of that all right so I've got to think I've got to think that is there information that I have that I'm not using yes there is and what is that the other two acceler ex you know accelerometers now what I want you to see is here this is what this is the Z axis proof Mass okay that's the z-axis proof Mass what do I also have I also have just for the sake of the illustration here I also have the what I have the Y axis proof Mass and that is going to have some perpendicular force on it it's going to have some perpendicular force on it and I'm measuring that perpendicular force on it right right now we're measuring that perpendicular force on that that is the Y value that I'm reading right now why is the Y value 0 because Y is the Y value 0 the at the Z proof Mass is like this the Y proof Mass is like this if the white proof Mass is like this that gravity Vector isn't hitting it if I tilt it a little bit then I'm going to see a little bit of a value there okay but right now it just goes right by it because it's perpendicular does that make sense okay so let's come back over here and now what I want you to see is I have this y output and what is this y okay what is this y here that is this Vector here right it's exactly this Vector here is the vector that is hitting the y-axis accelerometer okay that opposite so the opposite Vector is the normal Vector to the y-axis accelerometer don't think about the x-axis right don't think about the x-axis we're not talking about this we're just talking about this okay so now I have both the adjacent and I have the opposite and they're very very important because when I when I'm tilting this way the vector is going this way the the that opposite Vector is going this way when I tilt this way the opposite Vector is going that way and so that's going to have a sine this versus this I'm going to introduce a sign there right like a positive or A negative so that is very important so now what I really want is instead of just using the adjacent and nothing else what do I really want I want to use the adjacent and the opposite what function was that that was our friend tangent remember what we learned the tangent of theta is equal to what the opposite over the adjacent okay now how do I get the angle well the angle what do I do I do the arc tangent the undoing of tangent because if I if I arc 10 10 I undo the 10 I just did I'm just left with the angle and that is what of opposite over adjacent okay and then that would be Arc tan okay and what is the opposite the opposite is the Y acceleration and then what is the adjacent that is the Z acceleration that I need to get further out of your way okay so now let's see if we can do that and then remember that we need to convert that to degrees so Theta degrees is going to be equal to Theta divided by 2 pi times 360. all right let's come in here and let's see if we can start coding this thing and let's see what happens all right let's see if we can start coding this thing I think I'll just give it put it like this to make sure that we're not covering anything up and then we'll switch to that other View so let's stop so we're measuring X we're measuring Y and we're measuring Z we don't want to print here okay and this right I'm going to call this I'm going to call this pitch instead of theta because it's this angle that I want not this angle we're going to call this pitch and we're going to call this row okay so what am I going to calculate pitch and Pitch is going to be equal to what the math better import math [Music] it's going to be math Dot Arc tan and then what the Y acceleration divided by the Z acceleration like that now let's print uh let's let's convert it so pitch degrees is going to be equal to pitch divided by 2 divided by math dot Pi spelling PI right this time times 360 will take us to degrees and then we want to print what do we want to print we want to print pitch degree in degrees like that okay I will need everyone to hold their breath this time okay ah look at that okay and guys I just realized something that I need to do okay what's what's good is uh what's good is we're reading zero degrees and so that's good but what you see is that we don't want noise to cause this thing to crash and so one thing we need to make sure that we do is say that if Z acceleration is greater than one then what do we want to do we want to say Z acceleration equal one right because if acceleration of gravity is one if you had a little measurement error and it came out to 1.001 it would cause the program to crash so let's put the reasonable domains in here and same let's say what's the other one we're doing if y Excel is greater than one then we'll make y Excel equal to one like that okay all right so we we needed to put that in there but I'm glad the program ran and so now let's go like that okay and so it's reading right at sort of like almost perfectly zero degrees okay now what I'm going to do is I'm going to come where you can see what I'm doing I'm going to come and now what I'm going to do is I'm going to bring the nose up and look at that boom what did we get we're measuring pitch with the nose up and look at that is that not a thing of beauty let's bring it up to like 45 degrees and look at that boom perfect look at that what do we want to do how about if we go nose down negative boom look at that who's your friend who's your friend trigonometry is your friend okay so nose down is negative and then nose up is positive but what are we going to do what is the moment of truth the moment of truth is I'm not going to pitch I'm Gonna Roll it doesn't change pitch doesn't change when I roll look at that man are you guys as excited about this as I am if you don't understand what I just did go back and watch it again right I taught you the trigonometry I taught you the mpu 6050 and then we just drew a picture of where those forces are going and then it is like absolute Magic it is like absolute magic okay now I need to ask you I need to ask you something what do we still need to come in and do what do we still need to come in and do [Music] we calculated pitch but now we need to think about role okay you would probably go in and make this too complicated okay but what you got to see is it's exactly the same thing only instead of going here like this I'm going where my tilt is like this now if I drew this on the chart there it would just be a point because you can't see that third axis but roll is like this and who's watching row is it the Y accelerometer giving you that top Vector no the Y accelerometer is not giving you that top Vector when you're tilting like this what is giving you that top vector what is giving you that top Vector the X accelerometer right the X accelerometer and I think I can draw it like this like I could show you that the X accelerometer if I were just to draw a picture of it the X accelerometer would be like this okay and it's going to see this kind of tilt okay it's going to see this kind of tilt all right but this should be really really easy right because it's going to be almost exactly the same thing only what is it going to be okay this time instead of pitch I am going to calculate roll enroll is going to be equal to math dot A10 of what the X accelerometer [Music] divided by the Z accelerometer that x divided by Z instead y divided by Z and then roll degrees is going to be equal to rho divided by 2 divided by math dot Pi okay uh like that times 360. and now what we're going to do is we might need to print all this in one print statement I'm not exactly sure of that but okay here where we're saying pitch degrees so what I'm going to say is pitch and then need a comma there and then what we're going to do is comma and then that will be degrees that okay and then comma roll [Music] and that's going to be roll degrees and then we'll put the [Music] I think I better abbreviate these huh that's getting kind of long all right so let's stop this let me give it a little bit more room there okay so now what do we expect we expect of what role and what pitch we expect zero and zero so let's see it okay and so that is reading 0 and 0. that looks good and it's Auto scaling so let me try to get it to stop auto scaling okay now what we want to watch is I better get further out of your way I'm going to get further out of your way what we want to watch is pitch pitch is blue okay and what's coming up Pitch is coming up we go up we get up to about 45 degrees and what do we see role is not changing why I'm not rolling let's go nose down nose down is working okay now the moment of truth let's roll a right roll it's doing its negative okay and a left roll it's doing it's positive you could kind of Define that either way however you wanted I'm not sure if there's a convention for that or not but now watch this okay when I'm rolling I'm not pitching but now watch this watch this I'm going to roll I'm gonna pitch it let me yeah I'm gonna pitch it okay without rolling but now I can add a row on top of the pitch and it's able to do both of them at the same time who is your friend trigonometry is your friend okay guys always when I'm doing these lessons like I'm like six or seven I'm six or seven lessons ahead of you as I'm re recording this one you guys are back just doing the the servo stuff and so I'm doing all this stuff thinking that I'm really excited about it but then I'm not getting feedback with you so I've run off in this direction and I'm just afraid that maybe I'm making people mad or nobody's really that interested in this nobody is really that interested in this and maybe I've just kind of made people mad but this is really incredible man just from math and physics and Engineering we have made our own tilt meter using the raw data coming off of the accelerometers and I think that is really cool okay I'm going to give you kind of a little homework assignment because I really want to see are you guys thinking about these three axis accelerometers I've shown you the mat I've shown you the physics I've shown you the engineering so let's go back over here and uh let me just kind of simplify this a little bit here I'm going to go back let me stop this and I'm going to just print the X Y and Z acceleration I'm not going to print the angle okay and I'm going to get this all very far out of the way I'm going to get out of your way and then I want to show you something here okay so we're going to run this okay and what are we getting here what are we getting we have the x-axis accelerometer is the the x-axis accelerometer is the blue okay and the y-axis accelerometer let's see let me get a better view here the x-axis accelerometer is the blue the y-axis accelerometer is the orange and the z-axis accelerometer is the green okay now what I want to show you is that X and Y are measuring 0 G's why because it's like this the the Y is like this and the gravity Vector doesn't even hit it the x is like this the gravity Vector doesn't hit it the Z is like this and when it's flat it's taking that full 1G okay but now what we see is as I tilt this okay as I tilt this okay let me tilt it like this now what's happened now it's the x that is seeing the 1G and the Y and the Z are not seeing anything or what if I tilt it like this now who is catching the full force who is catching the full force the why is and the gravity Vector is missing the X and the Z but you see it's like it's like as you play with the orientations as you play with the orientations it seems like there's always one that is getting hit by that acceleration vector now what I want you to do and this is your homework for next week it's just do this program the program's Already Done Right you've got the X acceleration y acceleration and Z acceleration but I want you to find the orientation or the condition and you have to record it and you have to post it to YouTube link back to this video down below link to your solution but you have to find the orientation or the configuration or the the condition that will lead to measuring 0g simultaneously on X Y and Z where you you you're printing out or you're graphing and it shows you x is 0 g y is zero g z is zero g all at the same time like here I can get any one I want to be 0g but you got to get all three to zero g at the same time now you can start by just playing around with it and seeing if you can find it or then you're going to have to kind of think through it and then show me okay I had a lot of fun thinking about this one okay guys I really hope you're having as much fun taking these lessons as I am making them again you guys on patreon standing with me you're the guys that are keeping this content coming right I'm depending on you guys to allow me to continue to make the investment in equipment and time to keep these videos coming thank you I really really appreciate your help I know things are tough out there you guys making sacrifices and helping me thank you very much you can also help me by giving me a thumbs up leaving comments will help me also subscribe to the channel when you do ring the bell so you'll get notifications of future lessons and most importantly and always share these videos with other people because the world needs more people doing engineering and fewer people sitting around watching silly cat videos Paul McCarter with toptechboy.com I will talk to you guys later foreign
Info
Channel: Paul McWhorter
Views: 4,187
Rating: undefined out of 5
Keywords: STEM, LiveStream, TopTechBoy
Id: 5f7fL9G8VsE
Channel Id: undefined
Length: 32min 39sec (1959 seconds)
Published: Mon Nov 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.