Measuring bank angles with the MPU6050 and Raspberry Pi - The software

What happend so far and how we proceed:
The last two times we were looking into the general problem statement and then how to set up the Raspberry Pi, wire the components and to install the necessary software packages. By now you should be able to read raw data from the MPU6050 and see if it is working properly, as well as to know the address it has been assigned. If not, review this excellent blog. 
 
Maybe some "defending" words here. The code I wrote is procedural and not object oriented, which is a big development task for the future, as the current version is far from maintainable and user friendly - forgive the unknowing mechanical engineering student - His software skills are still in the making =). 

The full code can be found on my github repository here. 

It is constantly being developed and changes throughout the proccess. Therefore I will only show code snippets here and focus more on there general purpose. The overall code structure is still very likely to be changed but the single modules will stay the same. 
The software I wrote for measuring the bank angles with the Raspberry Pi on the Motorcycle focuses on the following features:
  • Being able to start/stop a measurement with a button press 
  • Lighting a LED, if the measurement is running
  • Automatically logging the measurement data either by just writing the raw data of gyroscope and accelerometer to a file. Or by combing accelerometer data and gyroscope data with a complementary filter
  • Plotting the measurement data with gnuplot
  • Sending the image to a specified e-mail adress so one can check the bank angle of the motorcycle ride immediately after stopping the measurement
The code is currently written to use interrupts.You should be familiar with both of those concepts. Further information on this can be found here. I will only explain the main program, that makes use of several functions (I will not cover those in detail but only state their purpose). Now why did this code actually need an interrupt. In previous versions of the code (that did not have the interrupts) it happened very often that the program did not stop when a button was pressed. This was probably caused by the fact that the code was stuck in the subfunction and therefore it did not respond to a button press. With the interrupt it does not matter at which line of the code you are, the action defined in the interrupt is carried out instantly. The interrupt also has the nice feature that it divides the program into several threads. Now the main thread is just occupied with measuring (by using the subfunctions) and it does not wait around for a button press to happen.



Comments

Popular posts from this blog

Measuring bank angles with the MPU6050 and Raspberry Pi - The introduction and hardware requirements

Measuring bank angles with the MPU6050 and Raspberry Pi - Wiring the components and installing the required software packages