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
คลิกเพื่อขยาย
คลิกเพื่อสำรวจ Mind Map แบบอินเตอร์แอคทีฟฉบับเต็ม
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