Calibrate to Agitate
Each MPU-6050 chip needs calibrating to ensure drift free fun.
There is an excellent guide here: http://www.i2cdevlib.com/forums/topic/91-how-to-decide-gyro-and-accelerometer-offsett/
Over on the i2c library forums a kind fellow has posted a sketch that will output some values that you can then plug into the Joystick sketch.
http://www.i2cdevlib.com/forums/topic/96-arduino-sketch-to-automatically-calculate-mpu6050-offsets/
Upload the sketch in the usual way, set the MPU-6050 as flat as possible and run the sketch. Open up the serial coms window (shift-ctrl-m) and after a few minutes the sketch should output some ‘offset values’.
These can then be used in the joystick sketch
mpu.setXGyroOffset(45); mpu.setYGyroOffset(24); mpu.setZGyroOffset(5); mpu.setZAccelOffset(1234);
That should ensure drift free operation.
On top or On The Side?
The data sheet for the MPU-6050 talk about ensuring it’s mounted flat and level. This doesn’t mean you can only mount it on top of your head. The chip needs to be flat againt the object you interested in, i.e. RC bugger, glider or your head. As long as the axis of rotation line up then you can mount on top, on the side and any way up.
My head appears to pitch on the axis through my ears, so I’ve mounted my Head Tracker with the MPU6050 as close to this axis as possible, i.e stuck on the side of my headphone.
Wherever you mount you device it needs to be fixed firmly with no wriggle room. I also tape the USB cable to make sure that can’t pull on or move the device.
Resolution
The original joystick emulation code used 8 bits for each axis. That only gives 255 distinct head positions in each dimension. The effect is if you move your head slowly you get multi-pixel jumps in the on screenm view.
I’ve updated the HID description and code to now use 16 bit values. This gives sub-pixel head tracking resolution and a much smoother experience.
The updates files also implement a shorter re-calibration time, down from 5 seconds to 2. So if you do need to hit the recal button it’s less of a pain waiting.
https://github.com/pocketmoon/MPU-6050-Arduino-Micro-Head-Tracker
ta ta
Pingback: DIY Head Tracker | Mis-adventure in 3d Printing
So I can get things to start working but I have a few questions.
How do I invert an axis within the code itself and how can I stop the axis from “rolling over.” For instance if I yaw left in a game, if I keep turning, not even a full 360, suddenly I will yaw right in game or in the windows calibration window. Can I set a maximum value or something to stop this?
Hi, the latest code should solve this https://github.com/pocketmoon/MPU-6050-Arduino-Micro-Head-Tracker/blob/master/Arduino%20Sketch/MPU6050Joy/MPU6050Joy.ino
You can invert axis in code on line 516/517/518 by sicking a minus sign in from of iX or iY or Iz. But I usually just invert in-game (using the invert axis checkbox in the controller config if needed).
Hey thank you very much, I really appreciate this. It’s one of the coolest things ever.
Hmm seems like z and y axis are the same now.
Sorry, running a full calibration seems to have fixed it somehow. This is awesome 🙂
Hi,
Sorry for being something of a dunce, but I am new to all of this. Have tried compiling the sketch ‘EDTRACKERIICalibrate.ini’ priior to uploading to Headtracker and a slew of errors are thrown-up, starting with:
EDTrackerIICalibrate.ino: In function ‘void setup()’:
EDTrackerIICalibrate:133: error: ‘mpu_read_6050_accel_bias’ was not declared in this scope
EDTrackerIICalibrate:136: error: ‘mpu_set_dmp_state’ was not declared in this scope
EDTrackerIICalibrate.ino: In function ‘void loop()’:
EDTrackerIICalibrate:176: error: ‘dmp_read_fifo’ was not declared in this scope
EDTrackerIICalibrate.ino: In function ‘void initialize_mpu()’:
And continuing along the same lines. I realise I’m doing something wrong, but would appreciate some guidance.
Kind regards,
Richard.
Hi Richard,
It sounds like you’re just missing the InvensenseMotionDriver libraries. Grab these from github (https://github.com/pocketmoon/EDTracker2 download zip – should be in there somewhere) and copy the InvensenseMotionDriver folder to My Documents\Arduino\libraries\
Hi,
You are very kind. Compiles properly now. Next step to see if I can upload the sketch and get everything working.
Thanks again,
Richard.
Thanks again. All your advice has been spot-on, and somehow I seem to have soldered the device correctly as it works. A bit of drift, but that seems quite common and shall keep a weather-eye for updates.
Many thanks again to you and to Brumster. As a total noob to this I have been extremely impressed by the sense of community and the generosity exhibited here.
Regards,
Richard,