This content explains how to derive Euler angles (roll, pitch, and yaw) directly from sensor measurements like accelerometers and magnetometers, offering an alternative to complex AHRS filters, and discusses integrating these methods into an autopilot software toolkit.
Mind Map
Click to expand
Click to explore the full interactive mind map • Zoom, pan, and navigate
hey folks for this screencast i'm going
to talk about something that i've been
working on the last few days and i went
ahead and put the equations in my my
free airspace
aerospace mechanics textbook here so if
you run over my github siemental 251 and
you go to my latex repo and you go to
aerospace mechanics i've got my entire
textbook here
i even threw the tech file in there in
case you want to and even the figures if
you want to you know use them just make
sure to give me credit for it for
wherever you want you know reference
this repo
if you click this link you can just
download the pdf itself but i obviously
have the raw pdf downloaded and you can
see like i just updated this recently
so what i want to talk about what i've
been working on is i've been beefing up
the euler angle parameterization so one
of the things
that we do in aerospace
convention is we talk about the 321
sequence and so that's where you know
you have i'm going to use this as an airplane
airplane
it's a little uh small camera and
basically you do a rotation about the
z-axis that's your yaw angle and so
that's why there's some cosine size and
sine size and this is a
three-dimensional transformation i'm not
going to i'm not going to really go into
the detail of this thing anybody with
you know some rudimentary undergraduate
dynamics 3d dynamics you know you'll
you'll have seen that and so
i recommend looking through somewhere
else i just have these equations there
for reference but you basically have
your your yaw axis about the z and
that's where the three comes in that's
the third axis and then the second
rotation is a pitch
pitch
through theta about the y axis that's
the two rotation and then you finally
have a
rotation through roll or fee about the
x-axis which is the one so that's a 3-2-1
3-2-1
rotation and you can kind of see this
graphic here which basically shows let
me move this out of the way
which shows this projectile moving
about the z-axis through psi
and then about the intermediate axis
through theta and then about the final
axis through roll
and you can do some matrix
multiplication and you can multiply this
out and you can get this really really large
large
equation here
that basically rotates the body to the
inertial frame and i did another video a
while ago about you know the
ahrs filter which basically takes your
imu measurements and estimates the
quaternions based on your accelerometer
gyro and your magnetometer
now one of the things that i was
realizing is that that that is a fairly
complex algorithm and sometimes you know
you might create a drone that
that
can't move
through you know 90 degrees which
creates that you know gimbal lock or
singularity at pi over two and so you
might want to just get
roll and pitch
directly from an imu and so i've put
together this chapter here on guidance
navigation and controls and i've talked
a little bit about state estimation
and i talk about the internal in the
inertial measurement unit the imu which
has a magnetometer and a ray gyro and
then also an accelerometer and so i also
talked about the gps which you know the
gps and i and you put together gives you
an ins an inertial navigation system
and then i go on to talk about is it
possible to get euler angles from
directly from your imu rather than using
this complex ahrs filter and it turns
out it is
and so what you and what i want to do in
this video is go through the just the
derivation of it
and then in a separate video i'm going
to talk about
i'm actually going to use some real
sensors and and push plug these
equations in so you can see it actually
work on the on the fly
so let's talk about the direct
measurement of roll and pitch so
the idea is and let me grab a
i have a
small microcontroller in here with a uh
let's see
i have a small microcontroller over here
that has an accelerometer i'm going to
use this in a separate video so these
are the circuit playground expressives
that we that i use in my instrumentation class
class
and so basically the accelerometer the
z-axis is this way and so if i hold the
accelerometer like this
where gravity is pointing down
what i can
what the math i'm basically going to
realize is that
my gravity vector is 9.8 and as long as
i'm not shaking this thing around as
long as the
circuit python is is steady not level
but steady
i should be reading the gravity vector
straight down and so that's basically
what this is the gravity vector in the
inertial frame is 0 0 g
and if i normalize that the gravity
vector is 0 0 1 right so that's
basically all of all of the acceleration
that the accelerometer is reading should
be in the z axis
now the accelerometer is going to give
me ax ay and az it's going to give me
accelerometer measurement in three axes
of the body frame of this of the of the
sensor and what i can do is i can
normalize that here and so if i take you
know the accelerometer measurement here
can you see that on there let's see let
me move this out of the way so if i take
my accelerometer measurement right here
and divide it by the norm you know i'll
get a normalized acceleration vector
here i call a bar
and so what you can
understand is that my gravity vector is
always pointing down and if i rotate
about the yaw axis you'll notice that
that doesn't change the gravity vector
in the body frame
and so what that means is that that psi
rotation that yaw rotation that third rotation
rotation
does not affect my gravity vector that
i'm measuring but
if i rotate about the y-axis or rotate
about the x-axis if i rotate about
either axes
what happens is that the gravity vector
is now along different axes and so if i
if i pitch up and roll my gravity vector
is still down
but my three components my x y and z in
the accelerometer frame are now
different and what you can you can do
that very easily what you can do is you
can take the gravity vector that you're
supposed to be measuring again i said
the the sensor needs to be steady it
doesn't need to be level but it needs to
be steady because you need to assume
that you're measuring gravity
i can wrote this rotate this through the
the
pitch transformation matrix and if you
scroll up back to the euler angle section
section
this is a 2d transformation matrix
through theta the pitch angle and then
this is a transformation matrix through roll
roll
and what you end up getting is this
pretty simple equation with you know
sine theta sine phis cosine thetas
and you can look at the top equation and
you can see that that equation is one
equation with one unknown and so you can
take the accelerometer measurement in
the x-axis
or the normalized acceleration the
x-axis and do an inverse sine and take
the negative component and that gives
you theta and then what you can do
furthermore is you can take this
second equation and this third equation
and you can divide the two
and you'll notice that the cosine thetas
will cancel now this is where that
gimbal lock comes in
if cosine of theta is zero it means your
sensor is like this
and that means that you can't get the
roll angle because what's happening is
your gravity vector is now straight down
along the x-axis and if i rotate or roll
the vehicle or roll the sensor it won't
change my measurement and so this these
equations are only valid for benign
maneuvers so this would work well on a
on a ship
on a quadcopter that doesn't flip uh it
would definitely not work on a rocket or
a spacecraft so you have to keep that in
mind when you're when you're using these equations
equations
so uh as i was saying if you if you
divide these two equations the cosine of
theta will cancel and you'll basically
get a tangent of phi the roll angle and
so on the left-hand side that's the
normalized component of the y-axis and
the normalized component in the z-axis
you divide those two take the inverse
tan and that will give you the roll angle
angle
so that is how you can get a direct
measurement of the roll angle and the
pitch angle just from an accelerometer
and as i said before as i said
later on i'm i'm going to
actually put those equations on this
circuit playground and post that in a
separate video
what i wanted to do is i wanted to
go on and move further and there's some
other equations in supplemental stuff is
talking about measuring yaw
using a magnetometer now this sensor
unfortunately the circuit playground
does not have a magnetometer so i am
going to have to attach a separate
magnetometer sensor to it but the idea
for measuring yaw is exactly the same
you assume that and this isn't true but
you assume that the magnetic field vector
vector
is pointing north if you're in the
northern hemisphere
and essentially along the x-axis and if
you normalize it you'll get a vector
that's one zero zero
then what you do is you understand that
the that vector
as i yaw the vehicle like this
is basically and let me see if i can if
i can put this so
so
that's north
as i rotate the circuit playground or
the sensor left and right that's like
yawning the vehicle right moving this
way i'll get a cosine and a sine
component depending on which way i'm going
going
and so we can do the same thing where we
can take
the uh measurement
of the magnetometer in the body frame
and rotate that through the roll angle
and rotate that through the pitch angle
and equate that set that equal to the
the
magnetic field of the earth that we
think it's supposed to be
through this psi angle and you can see
that i can take this first row and this
second row and i can divide those and
get a tangent component and i end up
getting this pretty long equation here
now i've actually used this equation before
before
on a rocket and it did okay um but it is
the magnetometer is very sensitive to
calibration errors and you know magnetic
interference so if you put a
magnetometer near some rotating
propellers you're gonna get some
magnetic interference there and so
i've seen this equation numerous times
like on github for and like on adafruit
or on digikey or there's another dfr
robot you know everybody uses a similar
equation and i basically just go through
here and kind of derive it um
and hopefully you can follow along and
see if that helps
um i asked just a a plug in here i also
have a chapter here on how to get
attitude estimation in low earth orbit
and you can read that through at your leisure
leisure
there's also some spacecraft position
estimation using some ground station networks
networks
and then finally the last thing that i
want to do and i'm going to post another
video on this is about a heading angle
estimation using gps
so you can get the heading angle of the sensor
sensor
just by it rotating
and use the magnetic field as your reference
reference
but sometimes it's beneficial to say
that you know hey if i have a vehicle
that's just
moving forward through space
what i can do is i can basically fit a line
line between
between
every successive gps point and so what i
can do is i can take a gps coordinate
and then a follow a following gps
coordinate and subtract the two and get
a delta and say that is my heading angle
in order to do that what you need to do
first is take your gps coordinates your
latitude longitude and altitude and
convert it to the cartesian plane
that equation and let me go back up to
the table of contents external models uh
gps coordinates to cartesian is uh this
this equation here where you take the
the latitude of your measurement minus
your origin point so you have to assume
an origin point for your basically your
cartesian flat earth model and then you
multiply by this this kappa and this
kappa is
converting a degree
of latitude or longitude into nautical
miles and then meters to feet and i'm
not sure if you know this but um
one degree of latitude is 60 nautical
miles on the surface and so that's where
this uh this this 60 comes in so you can
see that here 60 that kappa is 60 times
feet over nautical miles which uh
is let me see if you can scroll over to that
that
is a 6007 high you can't see that let me
zoom in there you go is that six
thousand seven hundred six thousand
seventy six and then the meters to feed
obviously is the 0.3048
and so what you can do is you can take
that delta latitude let me move my mouse
out of the way you can take the delta
latitude and multiply by cap and that
will give you an x coordinate and
remember latitude is is north to south
um and then your longitude you you do
your longitude and you also you sorry
you do your delta longitude and you
multiply by that kappa to get to meters
or or feet in this case um but
but
you have to take into account the fact that
that
as you go up in latitude you move across
longitude more quickly and so if your
latitude is zero
then you're basically going around the
equator but if you're higher up on the poles
poles
if your lot your longitude will change
quicker and so therefore you have to
take that into account when you do your
x and y calculation and then z is this
height above the surface so that's your
your altitude so if you if you do that
conversion where you go from
your latitude longitude altitude and you
convert it
to your cartesian plane
you can then and let me see heading
angle estimation you can then take
deltas based on your successive measurements
measurements
and you basically do a dx over a dt and
that will give your velocity in the x
direction and then you do a a a y
i plus 1 minus y i y i plus 1
is your measurement before
before
sorry y i plus 1 is your successive
measurement and then y i is your
previous measurement you take that delta
and that gives you a delta y divide that
by delta t and that gives you a v y and
then your heading is just the tangent
inverse of your v x and your vy now
you'll notice by the way that when you
do vx overview or sorry vy over vx
you'll notice that the delta t cancels
so you could just do uh dy over dx and
do a tan inverse and that will give you
your heading now keep in mind this only
works if you're moving right so if
you're moving in a certain direction
as you're moving in that direction you
can get your heading but if you stop in
place that's really where the
magnetometer sort of shines
the other thing that you can keep in
mind is that
your magnetometer is going to be prone
to a lot of those biases and things like
that and so sometimes it's nice to fuse
the measurement of the magnetometer
and the
heading together or you know use the
magnetometer when you're not moving and
then the heading angle or sorry the gps
measurement heading angle when you're moving
moving
and then not to mention the imu is going
to update at like 10 100 1000 hertz and
your gps is only going to update you
know every four every two three four
seconds uh so there's also that to keep
in mind um
so anyway hopefully this was an
interesting video about different ways
to get your euler angles from
uh from these measurements and then
there was
an entirely one more method where i
didn't even mention which is taking your
rate gyro and integrating your rate gyro
you know obviously integrating your rate
gyro you're going to end up integrating
your biases and but that will also give
you euler angles if you have a really
nice rate gyro and then that ahrs filter
that attitude heading reference system
filter that i talked about earlier which
estimated quaternions that's basically a
combination of all the two you have the
accelerometer measure that measures your
gravity vector you integrate your gyro
and you fuse the two but it didn't
include the gps which is why i wanted to
talk about that here
so uh
this is what i've been working on i'm
putting this into my my fast kit
tool tool set so if you go back over to
my repos over here and you go over to
let's see
more repos more yeah my repositories and
you go over to fastkit this is my
autopilot software that i've been
working on
i've been integrating you know gps
heading you can see my latest commit gps
heading speed and magnetometer yaw angle
i've been putting that in there and so
future videos expect to see some stuff
where i uh i test all this and like i
said i'm going to do a follow-up video
where i use that circuit playground and
i and i move the circuit playground
around and get a rolling pitch so
hope you enjoy those future videos and
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.