gregd72002_
Posts: 49
Joined: Mon Apr 14, 2014 8:50 am

Re: Yet more MPU6050 demo code

Mon May 12, 2014 11:01 pm

What operating system are you running on your RPi? What schedulers are you using?

You will not achieve anything close to 100hz on RPi without going without your own distribution. It is not reliable enough.

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: Yet more MPU6050 demo code

Tue May 13, 2014 5:41 am

gregd72002_ wrote: You will not achieve anything close to 100hz on RPi without going without your own distribution. It is not reliable enough.
Twaddle - I run standard Raspian, and my flight controller code spins at 200Hz easily. Each loop, it checks the commands, reads the sensors, passes the results through 8 PIDs, feeds the output to the PWM and on to the ESCs. And this is all in Python. I could increase the speed by a huge amount by moving to pypy, Cython, C or C++ but there's no need.

And time reliability is not necessary except for the PWM feeding the ESCs for which I use RPi hardware DMA PWM from the RPIO library. The I- and D- gains on the PIDs both have time factors in there to compensate for different elapsed times since the last error was calculated.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

gregd72002_
Posts: 49
Joined: Mon Apr 14, 2014 8:50 am

Re: Yet more MPU6050 demo code

Tue May 13, 2014 8:36 am

Hove,

Have you tried flying in acro/rate mode only, is it stable?

In my case, in 20 min flight time I was getting 2 or 3 random pauses/delays of up to 300ms. This is enough to make the copter flip twice, not to say to devastate the surrounding and itself...

On the other side, this might be down to many other factors as I am sure you are well aware of. For instance, I'm heavily dependent on USB (receiver) which is known to introduce variety of delays.

Anyway, all currently working as expected!

I'd be interested in seeing your code if you dont mind.

Mine is getting finalized in here https://github.com/rpicopter/controller

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: Yet more MPU6050 demo code

Tue May 13, 2014 9:01 am

You are way ahead of me - my flights are only a few seconds long and are autonomous - pre-programmed take-off, hover and landing which then allows me to collect data for diagnosing sensor errors, PID tuning, drift compensation etc - it's nearly there but I've been saying that for months now! Getting very frustrated - but none of my problems relate to timing - all to accelerometer accuracy, and autonomous drift suppression during hover on a windy day (for example).

Due to being autonomous, I don't have a receiver or transmitter in use yet. They too are going to be completely DIY, which should mean I have full control over how long the receiver will wait for commands from transmitter before proceeding with a sensor / PID update. Both are mostly coded, and transmitter is mostly built but until I have autonomous drift control working, there's no point proceeding with user control .

I can see how a 300ms pause would cause a big problem even once in a 20 min flight. That's a big gap for the quad to be stuck in a fixed state!

My receiver is WiFi USB dongle, but just used at the moment to SSH in, and start the code running.

The last good stable run of the code is on GitHub at PiStuffing/Quadcopter - it's a bit out of date at the moment though.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

Shresta
Posts: 31
Joined: Sun Jun 30, 2013 3:13 pm

Re: Yet more MPU6050 demo code

Fri Sep 05, 2014 9:53 am

Hi,
I installed the code and tried to run it. When I try "demo_raw", I get the message

"Failed to open device : Permission Denied.
a/g 0 0 0 0 0 0"

What am I missing.

I checked the device address, it is 0x68.

Please help me get it to work.Thanks.

Shresta
Posts: 31
Joined: Sun Jun 30, 2013 3:13 pm

Re: Yet more MPU6050 demo code

Mon Sep 08, 2014 4:05 pm

Shresta wrote:Hi,
I installed the code and tried to run it. When I try "demo_raw", I get the message

"Failed to open device : Permission Denied.
a/g 0 0 0 0 0 0"

What am I missing.

I checked the device address, it is 0x68.

Please help me get it to work.Thanks.
Just to say, that I could get it to work. I missed adding user to i2c group. Once its done, it worked.

Now, I want to transmit roll and pitch data from here to my desktop either on RS232 or over an ethernet link. Advise please on getting starting.

Shresta
Posts: 31
Joined: Sun Jun 30, 2013 3:13 pm

Re: Yet more MPU6050 demo code

Tue Sep 30, 2014 1:19 pm

I implemented the code and checked the accuracy of angle reading by taking readings. I get an offset angle of 0.6 deg and for a 15deg inclination (angled block), I get about 13.6deg. I was expected better accuracy for this unit. What are the suggestions to improve accuracy?

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: Yet more MPU6050 demo code

Tue Sep 30, 2014 1:47 pm

That's pretty close to the accuracy of the sensors of 2%. Only calibration will improve it - I've got mine to about 0.1%. BUT - you don't need that level of accuracy from angles, what you have should be fine.

Accuracy is only needed if you are integrating the accelerometer values to produce velocity; 2% error in that means 1g may read as 1.02g or an acceleration of 0.2m/s/s which builds up rapidly when integrated.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

Shresta
Posts: 31
Joined: Sun Jun 30, 2013 3:13 pm

Re: Yet more MPU6050 demo code

Tue Sep 30, 2014 1:56 pm

Hove wrote:That's pretty close to the accuracy of the sensors of 2%. Only calibration will improve it - I've got mine to about 0.1%. BUT - you don't need that level of accuracy from angles, what you have should be fine.

Accuracy is only needed if you are integrating the accelerometer values to produce velocity; 2% error in that means 1g may read as 1.02g or an acceleration of 0.2m/s/s which builds up rapidly when integrated.
Some how, Im not satisfied with the readings I got. Interested in knowing how you could achieve 0.1 % accuracy, if you don't mind sharing.

If it helps, when I place the unit on a flat plane, I get varying values (may be noise).Approximate average readings(raw values) :ax ~ 120, ay ~40,az~17340,gx~80,gy~20,gz~-80.

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: Yet more MPU6050 demo code

Tue Sep 30, 2014 3:28 pm

OK, you asked for it :D

Buy yourself a perpex cube (only 5 faces) , big enough to house a RaspberryPi and a battery.
Buy a beer fridge - ideally a Peltier effect one as it then doesn't have a compressor and therefore 0 vibrations.
Buy yourself a small spirit level with 0.5 degree accuracy
Buy yourself a platform that you can adjust to horizontal with that spirit level (mine's 10mm perspex, 50cm * 50cm, with bolts at each corner to raise corners independently).

Everything but the beer fridge is under £20 from ebay. Obviously the beer fridge has a secondary use so the additional cost comes with benefits.

Stick your RaspberryPi into the cube.
Stick the cube in the fridge
Stick the spirit level in the fridge
Stick the fridge on the platform

Tweak the platform bolts until the spirit level in the fridge is horizontal in 2 axes (i.e. front to back and left to right).

Power up the Pi and get a reading for gravity
Flip the cube so it sits on the 5 other faces and get a reading of gravity for each.
These 6 readings give you an offset and gain for gravity across the sensors X, Y, and Z axes at the temperature of the fridge.

Now find somewhere warm.

Do the same.

For the X axis numbers at the two temperatures, you can now plot a line (mathematically) so you can calculate the X axis offset and gain at any temperature.

Do the same for Y and Z

Assuming there's a single call to read the sensors in the code, then apply these equations to the output of the sensor based on the temperature the sensor reads.

And voila, 0.1% accuracy.

As I said, you did ask!

Gyro is much easier. Just sit your raspberry pi on a stable surface. Read the gyro - it should be 0, 0, 0 as there's no rotation, so the values you read are useds as the offsets * gain - because the gyro is only used for angles, and only used short term (i.e. complementary or Kalman filters each reading out after a few seconds), there's no need to be picky about separating offset from gain.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

roman80
Posts: 4
Joined: Tue Nov 04, 2014 6:45 pm

Re: Yet more MPU6050 demo code

Tue Nov 11, 2014 7:39 am

Megaguigui wrote:I'm able to compile and build,but i can't run (execut) the program :mrgreen:
Didn't you use Geany,just for give me the run command ? ^^
Perhaps to late :D But to run compiled program from shell use ./ prefix (dot-slash).

User avatar
ric96
Posts: 1253
Joined: Sun Mar 17, 2013 6:03 am
Location: NOIDA, India
Contact: Website

Re: Yet more MPU6050 demo code

Sat Jun 13, 2015 4:52 pm

Any way to use the dmp on python ???
My apologies for shameless YouTube Plugs...
youtube.com/sahajsarup
twitter @sahajsarup
skype srics1996
e-mail: sahajsarup@gmail.com
Blog: http://www.geektillithertz.com/wordpress
Web: http://www.geektillithertz.com

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: Yet more MPU6050 demo code

Sat Jun 13, 2015 5:58 pm

Yes, the DMP output from the MPU-6050 is available over I2C / SPI as data registers which can be read with the Python smbus module. BUT - Invensense have kept the details of their DMP very secret so you'll have to search around for someone else who's worked this out. All I know is that it throws out a whole bunch of quaternions. That's why I ended up writing the motion processing myself in Python - at least that way, I knew what it was doing and how it worked.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

USW
Posts: 2
Joined: Sat May 21, 2016 1:12 pm

Re: Yet more MPU6050 demo code

Sat May 21, 2016 1:16 pm

Hello i need a way to convert the Gyro reading into angles. how can i do that

Shresta
Posts: 31
Joined: Sun Jun 30, 2013 3:13 pm

Re: Yet more MPU6050 demo code

Sun May 22, 2016 7:30 am

USW wrote:Hello i need a way to convert the Gyro reading into angles. how can i do that
Its already implemented in the code on github - refer first post of this topic. There are functions in there, which will help you understand the conversion.

USW
Posts: 2
Joined: Sat May 21, 2016 1:12 pm

Re: Yet more MPU6050 demo code

Mon May 23, 2016 6:29 am

Shresta wrote:
USW wrote:Hello i need a way to convert the Gyro reading into angles. how can i do that
Its already implemented in the code on github - refer first post of this topic. There are functions in there, which will help you understand the conversion.
Could you plz send me the link of github which includes complete MPU6050 with angle code.

Ebad
Posts: 1
Joined: Tue Aug 16, 2016 11:57 am

Re: Yet more MPU6050 demo code

Tue Aug 16, 2016 12:08 pm

Hello and Thank you for this exellent code i try it out with a RevB changed the busadress from 0 to 1
and for i have to change the slave also to 0x69 and it works also nice for me, to understand this awesome MPU. :D
How do I change slave to 0x69 and what can i do if I want to access both the slaves ie 0x68 and 0x69 and read the DMP data

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more MPU6050 demo code

Wed Aug 17, 2016 11:05 am

AD0 = 0V => 0x68
AD0= 3.3V => 0x69

T3am5hark
Posts: 62
Joined: Wed Jul 17, 2013 5:37 pm

Re: Yet more MPU6050 demo code

Wed Aug 17, 2016 8:47 pm

Bararob wrote:Hej!

Nice work. I was wondering what highest logging frequency you get is. How hard world it be to log 1000 sampels a second and save the data to the sd. I have a Rpi and the mpu6050. I am coming from Arduino and not really sure where to start.
Hi there - one option you've got is to do a "pi-duino" thing... I've done this on several projects using the Teensy 3.1 (arduino-compatible) to talk to hardware in real-time, sending the data over serial to the pi where the "smarts" live (pi can cache and accumulate data, do processing, send commands, etc. while the arduino side manages the hardware). When you need precise timing or a lot of PWM control, this way works pretty well. Serial comms are pretty easy to do as well since the Arduino libs make it easy to read and write and on the pi side you can just treat it like a file and plumb data in and out of it. Especially if you're already comfortable with arduino, this could be an option.

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Yet more MPU6050 demo code

Wed Aug 17, 2016 10:17 pm

Wow 2.5 years later ;)

On one post on this forum, I used canbus instead of the serial. This way you could connect a lot of sensors to the same bus.

viewtopic.php?p=440760#p440760

gonzy
Posts: 1
Joined: Thu Mar 09, 2017 6:11 am

Re: Yet more MPU6050 demo code

Thu Mar 09, 2017 6:15 am

hey @rgh and others on the community,
Would just love to know how should I run this tarball of code?
I have the basic I2c protocol working and have confirmed the sensor connection with "i2cdetect -y 1" = 0x68.
Would appreciate if I could have a walkthrough on how to run these three demos on my Pi 3.
Thanks

jasomo
Posts: 19
Joined: Fri Feb 07, 2014 9:47 am

Re: Yet more MPU6050 demo code

Mon Sep 03, 2018 6:07 pm

Fantastic! Thanks to this forum post now I have my rasp getting the MPU6050 orientation data via DMP.

But still cannot understand it correctly.
- When I change the Pitch (and only the Pitch) the Yaw is also affected and changes simultaneously.
- When I change the Roll (and only the Roll) the Yaw is also affected and changes simultaneously.
- When I change the Yaw (and only the Yaw) the Pitch and Roll are not affected. But it does not change fluently and correctly like Pitch and Roll. Changes correctly for a second but suddenly, stands still for a while and jumps to the correct position. Its not fluent at all.

Im getting the values from:
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

What could be the problem?
Its better to use another of the other methods?

Thanks all!

jasomo
Posts: 19
Joined: Fri Feb 07, 2014 9:47 am

Re: Yet more MPU6050 demo code

Tue Sep 04, 2018 9:26 am

After doing some research i think the problem is that I should calibrate the mpu6050.
Ill try that.

Return to “Automation, sensing and robotics”