How to Compute Roll and Pitch From Accelerometers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys thanks for stopping by microengineering my name is michael arona and in this video i'm going to be showing you guys how to compute roll and pitch angles from an accelerometer sensor like this guy right here i'm going to be approaching this derivation process from a flight dynamics and controls perspective but just know our final result can be used in many different projects many different applications so in this video i'm going to be covering the derivation of these lovely math equations and then also um demonstrating them working on board and arduino with an actual accelerometer so yeah these are the final math equations that we're going to be working towards you can feel free to pause the video and write these down for your project or homework or whatever but hopefully you clicked on this video to learn a thing or two so let's get into how these equations are actually derived so we are going to be computing roll and pitch angles with respect to the northeast down frame and this northeast down frame is a very common coordinate frame used in flight dynamics and controls and it's very convenient because the down axis or the z-axis is in the same direction as gravity and our orientation is going to be described by the roll pitch and yaw euler angles roll is denoted by phi pitch is denoted by theta ya is denoted by psi now we cannot use an accelerometer to measure yaw angle you know gravity is the same no matter which direction we're pointed so therefore we cannot use an accelerometer to measure yaw angle we can only use an accelerometer to measure roll and pitch also our accelerometer our accelerometer's coordinate frame is going to look something like this with its z-axis in the opposite direction of gravity that's the case with my accelerometer right here but just know that even though our accelerometer's coordinate frame is like this the equations that i'm going to show you still compute role in pitch with respect to the northeast down frame so also in flight dynamics and controls we use what are called rotation matrices or direction cosine matrices to describe the orientation of one coordinate frame with respect to another coordinate frame and we are going to be using a rotation matrix to describe the orientation of our accelerometer with respect to the northeast down frame and that rotation matrix is going to be defined by our roll pitch and yaw angles so let's take a look at what that looks like this is so yeah this is the rotation matrix that describes our accelerometer's orientation with respect to the level northeast down frame now in our in the coordinate frame in the level coordinate frame gravity is going to be negative g and this is what our and these are the accelerometer measurements right here ax ay and az and so yeah this is that um rotation matrix that is defined by our roll pitch and yaw angles now i mentioned earlier we cannot use um an accelerometer to measure ya so therefore we're going to set our yaw angle equal to zero and when we do that to this rotation matrix we're gonna get a result that looks like this right here you can do the math yourself but uh or you know or you can trust my math um and i'll let you decide which one to trust more anyways this is the simplified expression when we plug in zero for our yaw angle and if we carry out this matrix vector multiplication we'll come up with this an expression for ax a y and a z and that's what that guy looks like right there again you can do the math yourself just to double check me you know or you can trust my math and yeah so we have three equations two unknowns should be no problem solving for our roll and pitch angle so very obviously we can use the first equation here to solve for our pitch angle you know just rearrange it and get that guy so they're they're there our pitch angle is going to be equal to the arc sine of ax over g where ax is our x accelerometer measurement and g is good old 9.81 meters per second squared so yeah this is the actual this is the expression for our pitch angle now a little bit more complicating we can use the second and third equation here to solve for our roll angle and that's how you do that right here so we do a y over a z is going to be equal to this you know this expression we can cancel out the cosine theta terms and the g's so we're just left with sine phi over cosine phi and you know sine over cosine is just tangent pretty easy a so a y over a z is equal to tangent phi you know bada bing bada boom we can solve for our roll angle so our roll angle is going to be equal to the arc tangent of a y over a z where a y is our y accelerometer measurement and a z is our z accelerometer measurement yeah so this is the analytically correct solution right here but when you go to implement this on board microcontroller you know i would highly recommend using the two argument arc tangent function just because um this is going to prevent using this will prevent any mathematical singularities from happening um yeah so this is the analytically correct solution this is the this is the one i would recommend using on board or in your application so yeah um again these are the math equations that we're going to use to compute roll and pitch angles from our accelerometer measurements cool cool now let's actually show this working on an arduino so we got our arduino dude right here and so yeah i put a little um little uh illustration right here of the northeast down frame because remember we just derived the expressions for roland pitch in the northeast with respect to the northeast down frame and so a positive roll angle should be a roll to the right so this should be a positive roll angle and in the northeast down frame pitching up is a positive pitch angle so let's actually show this running on board um an arduino with the arduino code um there let's make sure this is working okay um yeah so this is the arduino code that's running on board our arduino right here so we got our so we um extract our accelerometer measurements and we use our pitch equation to compute our pitch angle and then we use this equation you know the one we described to compute our roll angle and just remember this two argument arctangent function is the same thing as this right here and then we're just going to simply print them to the serial console that easy so let's go ahead and upload our code wait for it to run all right bring up the serial monitor yeah so again this should be a positive pitch which as you can see it is and then this should be a positive roll awesome looks like it works great again positive pitch positive roll so yeah that's it we just figured out how to compute roll and pitch angles with an accelerometer sensor now before i conclude this video i need to point out one very important aspect of this method i just outlined this uh so all of the math equations i just showed you assumes the sensor is completely stationary not moving and as you can see when i start accelerating the sensor moving it around our roll and pitch angles are going all over the place that's because that's because this the math equations we just derived assume the sensor is stationary and when the sensor moves around our roll and pitch calculations fall apart and are completely inaccurate there are ways to subtract out the linear accelerations but they're kind of complex and beyond the scope of this video i just wanted to show you guys a simple method for computing roll and pitch angles with an accelerometer sensor um hopefully found this useful drop a like down below um comment down below as well if you have any questions about this i'll try my best to answer you guys with questions um until the next video see you later [Music] so you
Info
Channel: MicWro Engr
Views: 27,332
Rating: undefined out of 5
Keywords: accelerometer, arduino, imu, roll and pitch, euler anges, tilt angles accelerometer, tilt angles, roll pitch imu, tilt angles imu
Id: p7tjtLkIlFo
Channel Id: undefined
Length: 9min 38sec (578 seconds)
Published: Wed Feb 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.