14 | Measure angles with the MPU6050 accelerometer

00:13:02
https://www.youtube.com/watch?v=7VW_XVbtu9k

الملخص

TLDRThe video explains how to measure angles for an Arduino quadcopter using the MPU 6050 gyroscope and accelerometer. It outlines the limitations of traditional controllers and the importance of integrating rotation rates for angle measurement. However, this method can lead to drift and inaccuracies. The accelerometer's role in measuring gravitational acceleration is discussed, allowing for the calculation of precise roll and pitch angles. Challenges related to vibrations affecting measurements during flight are highlighted. The video concludes by indicating that a Kalman filter will be introduced in the next video to resolve these issues by combining data from both sensors.

الوجبات الجاهزة

  • 📏 Understanding the use of MPU 6050 in quadcopters
  • 🔄 Measuring angles through integration of rotation rates
  • ⚖️ Importance of accelerometer for accurate angle measurement
  • 🔧 Calibration of the accelerometer is crucial
  • 📉 Vibration impacts accuracy during flight
  • 🛠️ Combined data approach using Kalman filter is essential
  • 🎮 Introduction to stabilized mode controllers
  • 📈 Challenges with drift in rotation rate integration
  • 🔍 Accurate readings can enhance flight control
  • 🎥 Preview of next video focused on Kalman filter application

الجدول الزمني

  • 00:00:00 - 00:05:00

    In this video, we learn how to measure angles using the MPU 6050 gyroscope and accelerometer, which will assist in creating a stabilized flight controller for a quadcopter. The previous method involved controlling rotation rates, but this does not return the quadcopter to a level position automatically. Instead, a stabilized mode controller requires angle commands for precise control. We discuss the importance of accurately measuring angles using accelerometer data, particularly noting the drawbacks of integrating rotation rates due to drift and movement-induced errors. Therefore, we shift to using accelerometer values to calculate pitch and roll angles effectively.

  • 00:05:00 - 00:13:02

    We proceed to implement the calculations of roll and pitch angles into Arduino code, utilizing the MPU 6050 sensor. After setting up the necessary code structure and making the appropriate function calls, we receive and calibrate the accelerometer readings to ensure accuracy. Notably, we can visualize these measurements in real-time, exposing challenges such as vibrations affecting readings during flight. As the video wraps up, we highlight the need for a fusion of methods to attain reliable measurements through the implementation of a Kalman filter, which will be explored in the next installment.

الخريطة الذهنية

فيديو أسئلة وأجوبة

  • What is the purpose of the MPU 6050 in the quadcopter project?

    The MPU 6050 is used to measure angles through its gyroscope and accelerometer, which is crucial for developing a reliable flight controller for the quadcopter.

  • What are the main problems with using integration of rotation rates to measure angles?

    The integration method can lead to rapid angle drift due to accumulated errors from previous measurements.

  • How does the accelerometer help in measuring angles?

    The accelerometer measures gravitational acceleration along different axes, which allows for precise calculation of roll and pitch angles based on acceleration values.

  • What is the main challenge encountered when using the accelerometer for flight control?

    Vibrations experienced during flight can lead to inaccurate measurements, making it unreliable for stable flight control.

  • What solution is suggested for the angle measurement issues?

    The video suggests using a Kalman filter to combine the measurements from both the gyroscope and accelerometer to mitigate their individual drawbacks.

عرض المزيد من ملخصات الفيديو

احصل على وصول فوري إلى ملخصات فيديو YouTube المجانية المدعومة بالذكاء الاصطناعي!
الترجمات
en
التمرير التلقائي:
  • 00:00:00
    welcome to the next video in our series
  • 00:00:03
    explaining how to build your own Arduino
  • 00:00:06
    quadcopter drone in this video we will
  • 00:00:09
    explore how you can measure angles with
  • 00:00:12
    the help of the mpu 6050 gyroscope and
  • 00:00:15
    accelerometer
  • 00:00:16
    which will subsequently be used to
  • 00:00:18
    design a different type of flight
  • 00:00:20
    controller in the previous videos we
  • 00:00:23
    designed a flight controller to
  • 00:00:25
    stabilize the quadcopter based on the
  • 00:00:28
    rotation rates in degrees per second
  • 00:00:30
    this means that you give a rotation rate
  • 00:00:33
    commands to your radio transmitter for
  • 00:00:36
    example if you move the stick and give
  • 00:00:38
    it a pitch rate command of 10 degrees
  • 00:00:40
    per second the quadcopter will pitch 10
  • 00:00:44
    degrees each seconds if you release a
  • 00:00:46
    stick after 6 seconds the pitch rotation
  • 00:00:50
    rate commands will fall back to zero
  • 00:00:52
    degrees per second causing the pitch
  • 00:00:54
    angle of the quadcopter to stop at 60
  • 00:00:56
    degrees however the quadcopter does not
  • 00:00:59
    automatically go back to a level pitch
  • 00:01:01
    angle of zero degrees with this type of
  • 00:01:05
    controller for Pilots this type of
  • 00:01:07
    controller is rather difficult because
  • 00:01:10
    it does not stabilize the quadcopter to
  • 00:01:12
    a level position when releasing the
  • 00:01:14
    sticks to go to such a controller it is
  • 00:01:17
    necessary to give an angle commands for
  • 00:01:20
    example when you give a 45 degree pitch
  • 00:01:23
    command with the Stick of the radio
  • 00:01:25
    transmitter the controller will cause
  • 00:01:28
    the pitch angle of the quadcopter to go
  • 00:01:30
    as quick as possible to 45 degrees when
  • 00:01:33
    you release the stick the pitch angle
  • 00:01:36
    command goes back to 0 degrees and the
  • 00:01:39
    quadcopter's pitch angle goes back to
  • 00:01:41
    zero degrees as well the controller
  • 00:01:43
    which gives you direct control over the
  • 00:01:45
    roll and Pitch angles of your quadcopter
  • 00:01:47
    is often called a stabilized mode
  • 00:01:50
    controller as opposed to a rate or Acro
  • 00:01:54
    mode controller to build a stabilized
  • 00:01:56
    mode controller we first need to be able
  • 00:01:59
    to measure angles correctly a very
  • 00:02:02
    simple approach to measure angles can be
  • 00:02:05
    found by simply integrating the rotation
  • 00:02:07
    rates to get the actual angle remember
  • 00:02:10
    that K holds the number of the current
  • 00:02:13
    iteration and TS is the iteration length
  • 00:02:16
    which is equal to 4 milliseconds in a
  • 00:02:19
    250 Hertz Loop if you were discretizing
  • 00:02:22
    integral for using the Arduino codes
  • 00:02:25
    you would need to add the rotation rate
  • 00:02:27
    multiplied by the iteration length to
  • 00:02:30
    the angle of the previous iteration in
  • 00:02:33
    order to get the angle of the current
  • 00:02:35
    iteration if that sounds too simple to
  • 00:02:38
    be true that's unfortunately because it
  • 00:02:41
    is this approach has two major problems
  • 00:02:45
    you keep dragging all measurement errors
  • 00:02:47
    from previous iterations with you
  • 00:02:49
    causing the calculated angle to drift
  • 00:02:52
    very fast another issue is a change of
  • 00:02:55
    angles during your movement suppress the
  • 00:02:58
    quadcopter is flying with a constant
  • 00:03:00
    pitch angle of 45 degrees when you are
  • 00:03:04
    around the z-axis without any pitch
  • 00:03:06
    rotation rate around the y-axis the
  • 00:03:09
    pitch angle will nonetheless decrease or
  • 00:03:11
    increase because the y-axis changes its
  • 00:03:15
    direction as well this is equally true
  • 00:03:17
    for the rule rotation rate that is why
  • 00:03:20
    you need to use a totally different
  • 00:03:22
    approach for measuring angles and for
  • 00:03:25
    which you will use the accelerometer
  • 00:03:27
    built in your mpu 6050 as the name
  • 00:03:30
    implies the accelerometer measures the
  • 00:03:34
    acceleration of the sensor along the X Y
  • 00:03:37
    and Z directions from basic physics you
  • 00:03:41
    remember that we experience a
  • 00:03:43
    gravitational acceleration and anywhere
  • 00:03:45
    on Earth and that this gravitational
  • 00:03:48
    acceleration is equal to the
  • 00:03:50
    gravitational constant 1G or 9.81 meters
  • 00:03:55
    per square seconds this means that when
  • 00:03:58
    you let your mpu 6050 sensor lie flat on
  • 00:04:01
    a table without moving it the
  • 00:04:04
    measurement of the acceleration along
  • 00:04:06
    the zip direction or x z is equal to 1G
  • 00:04:11
    the acceleration along the X and Y axis
  • 00:04:14
    will be zero in this case similarly when
  • 00:04:18
    you position the sensor such that one of
  • 00:04:21
    the other axis lies perpendicular to the
  • 00:04:23
    surface of the table the corresponding
  • 00:04:25
    acceleration is also equal to 1g of
  • 00:04:29
    course any other direction not along one
  • 00:04:31
    of the three main axes will result in a
  • 00:04:34
    non-zero acceleration value for all
  • 00:04:37
    three directions through some clever
  • 00:04:39
    mathematical equations this
  • 00:04:42
    accelerometer property will enable you
  • 00:04:44
    to calculate the exact Rule and Pitch
  • 00:04:46
    angles of your quadcopter let's assume
  • 00:04:49
    you roll around the x-axis until you
  • 00:04:52
    reach the angle Theta rule to visualize
  • 00:04:55
    this transformation a box bounded by the
  • 00:04:58
    X Y and Z directions is sketched on the
  • 00:05:01
    screen from your basic trigonometry
  • 00:05:04
    knowledge you know that the tangent of
  • 00:05:06
    the angle of a triangle is equal to the
  • 00:05:10
    length of the opposite side divided by
  • 00:05:12
    the length of the adhesion side in case
  • 00:05:15
    of the angle Theta rule the length of
  • 00:05:18
    the opposite side is equal to the
  • 00:05:20
    acceleration in the y direction the
  • 00:05:22
    length of the adjacent side can be
  • 00:05:24
    calculated by the Pythagoras who finally
  • 00:05:28
    giving you the equation to calculate the
  • 00:05:30
    roll angle from the accelerometer values
  • 00:05:32
    a similar strategy and reasoning can be
  • 00:05:36
    applied for the pitch angles giving you
  • 00:05:38
    a second equation to calculate the pitch
  • 00:05:41
    angle from the accelerometer values and
  • 00:05:44
    that's it
  • 00:05:45
    you are now able to calculate the rule
  • 00:05:48
    and Pitch angles from the accelerometer
  • 00:05:50
    values now you need to transform this to
  • 00:05:52
    a working code for this part you only
  • 00:05:55
    need your TNC and mpu6050 and you can
  • 00:05:59
    choose to test the code on a breadboard
  • 00:06:01
    or directly on your assembled quadcopter
  • 00:06:04
    we will take the code from the gyroscope
  • 00:06:06
    derived in Parts 4 and 5 and add the
  • 00:06:10
    necessary lines to read the
  • 00:06:12
    accelerometer values first Define the
  • 00:06:15
    accelerometer and roll and Pitch
  • 00:06:18
    variables next start a function that
  • 00:06:21
    will extract the signals from the
  • 00:06:23
    mpu6050 and switch on the low pass
  • 00:06:26
    filter seen in Project 4. now you need
  • 00:06:29
    to configure the accelerometer outputs
  • 00:06:32
    according to the mpu6050 register map
  • 00:06:35
    the accelerometer configuration settings
  • 00:06:38
    are stored in register 1C for this
  • 00:06:42
    project you will choose a full-scale
  • 00:06:44
    range of 8 G which corresponds to a
  • 00:06:48
    value for the AFS scl setting of two or
  • 00:06:52
    a 0 for B3 and a 1 4 bit 4. the other
  • 00:06:56
    bits can be set to zero which gives a
  • 00:06:59
    binary representation of 16 or a
  • 00:07:02
    hexadecimal value of 10. the values of
  • 00:07:06
    the accelerometer are located in the
  • 00:07:08
    registers with hexadecimal numbers 3B
  • 00:07:12
    240. start writing to address 0 times 3B
  • 00:07:16
    to indicate the first register and
  • 00:07:19
    request 6 bytes from the address of the
  • 00:07:22
    sensor 0 times 68 the accelerometer
  • 00:07:26
    measurements are spread out over 3 times
  • 00:07:29
    2 registers with each 8 Bits repeat the
  • 00:07:33
    same code for all accelerometer
  • 00:07:35
    directions next configure the gyroscope
  • 00:07:39
    output as seen in part 4 and extract the
  • 00:07:42
    rotation rates to convert the
  • 00:07:43
    accelerometer measurements from LSB to G
  • 00:07:47
    remember that you configured the AFS scl
  • 00:07:51
    setting to an LSB sensitivity of 4096
  • 00:07:56
    LSB per G to get the measurements in G
  • 00:08:00
    just divide the measurement in LSB by
  • 00:08:04
    4096 LSB per g at the start of this part
  • 00:08:08
    you learned how to calculate the roll
  • 00:08:11
    and Pitch angles from the accelerometer
  • 00:08:13
    values you can use these equations at
  • 00:08:16
    this point but take into accounts that
  • 00:08:18
    are acting hence calculated by Arduino
  • 00:08:21
    returns a result in radians not in
  • 00:08:24
    degrees to convert the angles from
  • 00:08:27
    radians to degrees just divide the
  • 00:08:30
    results by P divided by 180. start a
  • 00:08:34
    communication with the gyroscope as seen
  • 00:08:36
    in part 4 and print the accelerometer
  • 00:08:39
    values now upload The Code by connecting
  • 00:08:42
    the TNC to your computer and pressing
  • 00:08:44
    the upload button in the Arduino IDE
  • 00:08:47
    open the serial Monitor and watch the
  • 00:08:50
    acceleration measurements in the X Y and
  • 00:08:53
    Z directions on the screen you will see
  • 00:08:56
    that the acceleration in the set
  • 00:08:58
    direction is almost equal to 1G because
  • 00:09:01
    the mpu6050 is lying flat on the table
  • 00:09:04
    now tilt the sensor vertically in the y
  • 00:09:07
    direction
  • 00:09:09
    notice that the acceleration in the y
  • 00:09:11
    direction
  • 00:09:12
    becomes almost equal to 1 while the Z
  • 00:09:15
    Direction goes back to zero repeat this
  • 00:09:18
    for the X Direction
  • 00:09:20
    calibration is once again necessary to
  • 00:09:23
    correct these values as they are not
  • 00:09:25
    exactly equal to one in the different
  • 00:09:27
    directions this calibration needs to be
  • 00:09:31
    done manually and will be different for
  • 00:09:33
    each sensor just abstract or add the
  • 00:09:36
    difference between the actual values of
  • 00:09:38
    the accelerometer and one in lines 36 to
  • 00:09:42
    38 of the codes and we check that the
  • 00:09:45
    acceleration values in all three
  • 00:09:46
    directions are equal to one G when
  • 00:09:50
    tilting the mpu 6050
  • 00:10:09
    now that you have calibrated the
  • 00:10:11
    accelerometer replace the lines in the
  • 00:10:14
    loop parts of the codes to print the
  • 00:10:16
    roll and pitch angle and upload the code
  • 00:10:19
    again instead of looking at the serial
  • 00:10:21
    monitor we will use the serial plotter
  • 00:10:24
    to visualize the roll and Pitch angles
  • 00:10:27
    first you will roll the accelerometer in
  • 00:10:30
    the positive direction up to an angle of
  • 00:10:33
    30 degrees the accelerometer values are
  • 00:10:36
    very responsive and very accurate repeat
  • 00:10:39
    this movement and subsequently perform a
  • 00:10:42
    two positive and one negative pitch
  • 00:10:44
    movement as well the results are
  • 00:10:47
    excellent and very accurate
  • 00:10:49
    when the sensor is level again the roll
  • 00:10:52
    and Pitch angles are nearing zero
  • 00:10:54
    however a problem appears when the
  • 00:10:57
    accelerometer experiences vibrations
  • 00:10:59
    which are inevitable when flying a
  • 00:11:02
    quadcopter due to the presence and
  • 00:11:04
    influence of the moving Motors let's
  • 00:11:07
    simulate these Vibrations by hand you
  • 00:11:10
    will notice a very sharp Peaks and drops
  • 00:11:13
    in the measured pitch and roll angles
  • 00:11:15
    because the amplitude of these
  • 00:11:17
    vibrations will increase a lot during
  • 00:11:20
    flight it is not feasible to build a
  • 00:11:23
    good controller based on the
  • 00:11:25
    accelerometer measurements because they
  • 00:11:27
    are heavily disturbed by these
  • 00:11:29
    vibrations integrating the rotation
  • 00:11:32
    rates to obtain the angles is also
  • 00:11:34
    possible and straightforward as we saw
  • 00:11:37
    in the first part of this video this
  • 00:11:39
    rotation rate measurements are not
  • 00:11:41
    sensible to vibrations however you get
  • 00:11:45
    an ever increasing error because you
  • 00:11:47
    will add all measurement error first
  • 00:11:49
    when integrating to obtain the angle the
  • 00:11:53
    graph on the screen shows the
  • 00:11:54
    measurements of the angle through
  • 00:11:56
    rotation rate integration and
  • 00:11:58
    accelerometer trigonometry for a
  • 00:12:01
    stationary sensor and illustrates the
  • 00:12:04
    ever increasing error with rotation rate
  • 00:12:07
    integration and the sensitivity to
  • 00:12:10
    vibrations with accelerometer
  • 00:12:12
    measurements it is clear that the two
  • 00:12:15
    methods of measuring and calculating
  • 00:12:16
    angles are not suitable for a flight
  • 00:12:19
    controller and that we will need a
  • 00:12:22
    different solution in the next video
  • 00:12:24
    I will show you how you can combine both
  • 00:12:27
    measurements and get rid of their
  • 00:12:29
    individual disadvantages by using a
  • 00:12:32
    Kalman filter
  • 00:12:34
    thank you for watching this video don't
  • 00:12:37
    forget to subscribe if you like the
  • 00:12:39
    series and remember that you can find
  • 00:12:41
    all tutorials on YouTube and the full
  • 00:12:44
    code on GitHub
  • 00:12:46
    the manual which contains all
  • 00:12:48
    expectations is available as well on
  • 00:12:50
    GitHub if you need some more information
  • 00:12:53
    thanks for watching and see you next
  • 00:12:56
    time
الوسوم
  • Arduino
  • Quadcopter
  • MPU 6050
  • Gyroscope
  • Accelerometer
  • Flight Controller
  • Angle Measurement
  • Kalman Filter
  • Vibrations
  • Calibration