The MPU6050 is a commonly used gyro and accelerometer used on home built Segways and Quadcopters. When using inertia measurements it is known that a gyro is accurate at high frequencies but not at low whilst an accelerometer is accurate at low frequencies but not so much at high frequencies. Therefore one way to get a good reading is to combine the two sets of readings. This can be done either with a Kalman filter or a simple approach used here of a complementary filter. There are many hobbyists and students using this device with an Arduino, but the basic Arduino is only 8 bits and not very powerful. This program runs on the myRio from national instruments. A video will follow of its use. I have taken earlier code available by others and modified it for the purpose of the Segway problem. Here we normally only use the roll measurement axis to measure the tilt angle and ignore the other two axis.
Connections of the MPU6050 to the myRio are as follows.
MPU6050-->myRio
3.3V --> VCC
GND --> dig GND
SDA --> 34
SCL --> 32
Others connections on the MPU6050 are left unconnected. (This is for the blue breakout board, not the red one where Vio must also be connected to digital GND).
I took out the integrator in the original code because an integrator in open loop drifts off with the slightest dc input. The output here is pretty much rock stable for tilt angle (roll). There appears to be some confusion as to what is called roll (vs pitch) but the video will sort it out. (ie the orientation of the device).
I also added a thing like you get in an aircraft to show the horizon as the device is tilted. This is quite handy. You may see some FPGA code which I include for driving servos. You can ignore this if you have no use for it or delete it.
This code only needs the real-time controller to get the MPU6050 to work.
Video:
https://www.youtube.com/watch?v=R8ONYBw2wLA
(second half of the video)
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Ok I hope you can read this one. I changed it to a Kalman filter and it is much better. Saved as V16
Sorry, it won't let me attach a file for some reason. I'll have to do a new document
Nice video tomnz, can you please upload V 15.0 files for the same project?