Measuring bank angles with the MPU6050 and Raspberry Pi - The introduction and hardware requirements
What this blog is about:
The following series of blog entries will describe how to measure bank angles on a motorcycle using a raspberry pi and the MPU6050 circuit board as hardware and python as software language. The entries will cover the practical approach on how to write a small set of routines, that allow you to use the hardware on a motorcycle and how to postprocess and evaluate them. It does not cover the complete theoretical background of the measurement principles or the basic software coding ideas of subfunctions, interrupts and hardware readout. Other blogs, which I will refer to throughout this series, cover this way better. To sum it up - I focus on the combination of different ideas and their practical application, found in other blogs. I think it might be some helpful advice or at least a small manual on which mistakes to avoid.
The motivation and putting some thoughts into order:
A good friend of mine loves to ride motorcycles and as he is a passionate engineer as well, he wanted to know the exact bank angle when he is entering a curve with his bike. After some discussion about what principles there are to measure this angle, several ideas came up and I will outline them very roughly here.
As you need to determine the angle, one could easily just stand in one of the curves with a camera and wait for the motorcycle rider to enter the corner. Given some reference markings you could measure the angle from a video you make. Yet still, this is no onboard sensor and you would always need a second person, standing in one specific curve with the equipment ready, follwed by a laborious postprocessing of the video. However, we will use this for validating our measurements later on.
The next best thing would be an onboard sensor, e.g. a laser fixed on the handlebars pointing striaght to the street. The more the motorcylce rider would lean in, while riding through the curve, the larger/smaller the distance of the laser to the street would become. But what about wobbles in the street or, an inclination in the street (not in the riding direction but perpendicular to it). One would have to know those features and the exacpt position of the motorcylce relative to it - Off the table as well for a practical application.
What remained as a good idea and is also used in practice, is an accelerometer and a gyroscope. The following paragraph will outline the idea of those measurements and give the advantages and disadvantages.
The required fundamentals:
When you use an accelerometer, you can make use of vector algebra. The acceleration vector is composed of several types of acceleration. You need 2 components of the three dimensional vector to get the angle you want to know. I will not go into detail with this, the formulas and some more background can be found here.
The big problem with this approach is that you need exactly those two parts of the acceleration vector and nothing else. Constant accelerations like gravity could be filtered out relatively easy with some calibration but what about the movement of the driver in the curve or the reciprocating engine? Those acceleration components are picked up by the sensor as well, which means a lot of noise in the signal.
A gyroscope measures the angular velocity in three directions and a simple integration can then give you the bank angle. It is much less prone to short term errors (which you face, when you use the accelerometer) but can suffer from a long term drift, meaning that after some time it will not go back to the neutral position.
There is the possiblity to combine the advantages of these tow measurement principles by using filters. A simple combination of the signals with a complementary filter, or even an Kalman Filter is possible.
The required hardware:
Luckily the MPU6050 offers an accelerometer and a gyroscope - The theory is set, but now we have to turn our thoughts into application and consider some practical issues. If you are on a motorcycle you cannot just take your laptop with you and do all the settings on the Raspberry Pi. You need a simple method to start and stop the measurement with a physical button. Furthermore you might want to see the result of the measurement instantly, without plugging the raspberry pi to a computer first. I will describe what I did in several steps from getting the sensor to run to postprocessing the data. You should be familiar with python- and shell programming and if you want to make the final assembly to look nice, a little soldering experience and two skilled hands couldn't hurt. Now here is, what you will need:
The next time, we will hook up the MPU-6050 to the Raspberry Pi and read some data from it!
The following series of blog entries will describe how to measure bank angles on a motorcycle using a raspberry pi and the MPU6050 circuit board as hardware and python as software language. The entries will cover the practical approach on how to write a small set of routines, that allow you to use the hardware on a motorcycle and how to postprocess and evaluate them. It does not cover the complete theoretical background of the measurement principles or the basic software coding ideas of subfunctions, interrupts and hardware readout. Other blogs, which I will refer to throughout this series, cover this way better. To sum it up - I focus on the combination of different ideas and their practical application, found in other blogs. I think it might be some helpful advice or at least a small manual on which mistakes to avoid.
The motivation and putting some thoughts into order:
A good friend of mine loves to ride motorcycles and as he is a passionate engineer as well, he wanted to know the exact bank angle when he is entering a curve with his bike. After some discussion about what principles there are to measure this angle, several ideas came up and I will outline them very roughly here.
As you need to determine the angle, one could easily just stand in one of the curves with a camera and wait for the motorcycle rider to enter the corner. Given some reference markings you could measure the angle from a video you make. Yet still, this is no onboard sensor and you would always need a second person, standing in one specific curve with the equipment ready, follwed by a laborious postprocessing of the video. However, we will use this for validating our measurements later on.
The next best thing would be an onboard sensor, e.g. a laser fixed on the handlebars pointing striaght to the street. The more the motorcylce rider would lean in, while riding through the curve, the larger/smaller the distance of the laser to the street would become. But what about wobbles in the street or, an inclination in the street (not in the riding direction but perpendicular to it). One would have to know those features and the exacpt position of the motorcylce relative to it - Off the table as well for a practical application.
What remained as a good idea and is also used in practice, is an accelerometer and a gyroscope. The following paragraph will outline the idea of those measurements and give the advantages and disadvantages.
The required fundamentals:
When you use an accelerometer, you can make use of vector algebra. The acceleration vector is composed of several types of acceleration. You need 2 components of the three dimensional vector to get the angle you want to know. I will not go into detail with this, the formulas and some more background can be found here.
The big problem with this approach is that you need exactly those two parts of the acceleration vector and nothing else. Constant accelerations like gravity could be filtered out relatively easy with some calibration but what about the movement of the driver in the curve or the reciprocating engine? Those acceleration components are picked up by the sensor as well, which means a lot of noise in the signal.
A gyroscope measures the angular velocity in three directions and a simple integration can then give you the bank angle. It is much less prone to short term errors (which you face, when you use the accelerometer) but can suffer from a long term drift, meaning that after some time it will not go back to the neutral position.
There is the possiblity to combine the advantages of these tow measurement principles by using filters. A simple combination of the signals with a complementary filter, or even an Kalman Filter is possible.
The required hardware:
Luckily the MPU6050 offers an accelerometer and a gyroscope - The theory is set, but now we have to turn our thoughts into application and consider some practical issues. If you are on a motorcycle you cannot just take your laptop with you and do all the settings on the Raspberry Pi. You need a simple method to start and stop the measurement with a physical button. Furthermore you might want to see the result of the measurement instantly, without plugging the raspberry pi to a computer first. I will describe what I did in several steps from getting the sensor to run to postprocessing the data. You should be familiar with python- and shell programming and if you want to make the final assembly to look nice, a little soldering experience and two skilled hands couldn't hurt. Now here is, what you will need:
- A MPU 6050
- A Raspberry Pi (I took a model B+, but you can also take a Raspberry Pi 2, which would be even better in terms of speed i suppose)
- A switch, a diode and some connection wires and a soldering iron to put it all together
- An external power supply for the Raspberry Pi
- To be able to run the Pi and sensor on the motorcycle - I took one that delivers 10.000 mAh at 5V and 1,5 or 2,1 A.
The next time, we will hook up the MPU-6050 to the Raspberry Pi and read some data from it!
Comments
Post a Comment