Chapter 7 IMU and Ultrasonic Sensors Technical Issues This chapter discuss briefly some of the major problems faced during this project and the solutions made to solve them

Chapter 7
IMU and Ultrasonic Sensors Technical Issues
This chapter discuss briefly some of the major problems faced during this project and the solutions made to solve them. It is important to know that these are not the best solutions ever and there are better and better, but these are what have done in the allowed time and effort, hoping to lead to a better solutions.

7.1 IMU
7.1.1 Messy Data
The biggest problem that faces any MPU-6050 user is the FIFO Over Flow and messy inaccurate measurements. This problem maybe because the sensor is cheap and have low processing capabilities compared to other available sensors.

These problems appears more frequently as the operating frequency of the sensor increases or the code size increases which lead to larger sampling time (lower sampling frequency).

As the goal of this project requires a lot of processing with high frequency, these problems becomes a major problem when dealing with such sensors.

Suggested Solution:
In order to be able to solve such problems, the source of the problem must be identified. Referring to many internet sites and previous sensor users, an acceptable reason for this problem was the small buffer size of the sensor, which is not capable to handle high rates of data acquisition. This explains the reason that it works fine with low frequencies (like 50 HZ).

But digging deeply in the problem, it is discovered that the DMP code works fine alone, and the problems started to show up when combining the DMP with the main code. This lead to the conclusion that, the sensor buffer size is small, which require high rate of data receiving from the sensor to avoid data accumulation or over write (FIFO Overflow!). Combining the DMP with the main code increases the sample time. When the sample time increases to a value corresponding to a receiving frequency lower than the frequency of the IMU sensor, the error starts to show up.

Thus, the DMP code should work in the same frequency as that of the sensor or higher. A good solution was to separate the sensors processing code from the main code using an other microcontroller. This allows the sensor to work with its own frequency, and not affected by the remaining code.

7.1.2 IMU and Optical Flow Combination
A unique error started to show up after introducing the position sensor (Optical Flow). When combining the two sensors in the same code on the same microcontroller “Arduino”, errors about libraries and sensors definition started to show up.
Suggested Solution:
One may suggest to dig deep in the libraries and fix the problem of definitions, but this requires very good skills in arduino programming which is far from the projects goal and takes time. A simple tricky solution was to separate the two codes in two microcontrollers, which also solved other problems as it will be discussed.

7.2 Ultrasonic Sensor
Ultrasonic sensor is a good option for measuring small distances (up to 5 meters). It is used to measure the altitude in this project. Because it depends on sound waves, it have a relatively large sampling time. also its sample time depends on the distance which the sound wave travels. For example, considering distances of (0.5 m and 5 m) and the sound speed is 340 m/s. The time consumed by the sensor to evaluate the distance is: t = 2 d/340 + processing time. considering that the traveled distance is doubled because the sound wave is sent and reflected back, it is easy to get a rough estimate of the time to be approximately ( 0.003 sec. and 0.03 sec.) respectively. In addition to that, there is a processing time added which increase the sampling time.

This large difference, about ten times slower, causes bad response using the same controller.

Moreover, this consumed time introduces another problem of large sampling time of the altitude control compared to that of the attitude loop (100 Hz = 0.01 sec.).

Suggested Solution:
First of all, it is clear that the two controllers, attitude and altitude, must be separated because of the large difference in there sampling frequency. The slower loop “outer loop” will be for the altitude control. This could be achieved by separating the processing of the altitude (Ultrasonic sensor) from the main microcontroller.

For the problem of varying sample time, the processing of the altitude is forced to a fixed sample time by applying a delay in the loop for the remaining time. This allows using the same controller for all altitudes.