-
Posts
13 -
Joined
-
Last visited
Everything posted by eneuro
-
Understanding Quaternions
eneuro replied to markalberti's topic in MPU-6050 6-axis accelerometer/gyroscope (InvenSense)
I found easier and maybe faster solution for my project using Maxima algebra CAS when mpu is not moveing: I use asin() while Taylor series can be used to obtain nice pitch & roll +/- angles and it can be optimized for speed for smaller pitch & roll angles we expect (+/-45 degrees max each). pitch= asin(-Ax/sqrt(Ax*Ax+Ay*Ay+Az*Az) ) [rad] roll= asin(Ay/(cos(pitch)*sqrt(Ax*Ax+Ay*Ay+Az*Az)) ) [rad] Maybe later I will need quaternions, but for the moment I've got good results using above solution with simply low pass filter and it looks like it fits my project requirements. -
Accelerator based equations leads to something like this: A0 - acceleration in pitch direction Ax,Ay,Az - raw total acceleration data get from MPU calibrated to have it in [m/s^2] units or [G] then G in those equations above is replaced by 1 [G] G - 9.81 [m/s^s] If pitch: alfa=0 [rad] and roll: beta=0 [rad] then those equations leads to solution: A=(Ax=A0, Ay=0, Az= -G ) and it is what we expect, so it looks good and it is time to verify this theory in practice and solve those equations while reading MPU-6050 sensor in realtime environment. However I'm interested in how DMP code separates Earth acceleration G from total accelaration A=(Ax,Ay,Az) and how accurate is it? I'm determined to solve those equations above using numerical methods (realtime if possible), while I need to know how it is calculated to maybe fit it better in my case of moveing electric vehicle with known A0 acceleration from its motor Hall sensors than by using DMP or other G estimations. Update: I've changed my mind and found easier solution using Maxima algebra CAS when mpu is not moveing: I use asin() while taylor series can be used to obtain nice pitch & roll +/- angles and it can be optimized for speed for smaller pitch & roll angles . pitch= asin(-Ax/sqrt(Ax*Ax+Ay*Ay+Az*Az) ) [rad] roll= asin(Ay/(cos(pitch)*sqrt(Ax*Ax+Ay*Ay+Az*Az)) ) [rad] There similar equations are used by someone else with simply accelerometer coords filter (before calculating pitch & roll ): Pitch & Roll from Accelerometer But as we can see, we do not remove gravity, but assume acceleration we got from MPU-6050 is gravity itself if no other accelerations in system.. So, now it is time to add gyro and fuse raw data from MPU-6050.
-
Just using Maxima CAS (http://maxima.sourceforge.net/) to do this all math stuff in 3D space and simplify solutions. Looks good Maxima is cool-world acceleration based on pitch (alfa) and roll(beta) while measured in MPU-6050 coords is a=[Ax, Ay, Az] looks like this: When checking this by calculating acceleration length: |a|=sqrt(a[1]^2+a[2]^2+a[3]^2) we get something which looks very complicated: However simplyfing in one line of code gives what we expect: So, it looks like that my transformations from unit coords to world coords based on pitch&roll are good Now it is time to add gravity and known in my case acceleration in pitch direction from Hall sensors (a0) and solve for pitch(alfa) and roll(beta) knowing total acceleration Ax, Ay, Az given by MPU-6050 raw outputs and gravity G=9.81 m/s^2 I assume the only forces significant are gravity and wehicle acceleration in pitch direction a0, then: a,g, and a0 are 3d vectors there.
-
>>>>>>>>>>>>>>>>>>>>>>>>>>> What I'm trying to do is measure pitch and roll in a vehicle while it's moving, but without gravity being figured in. <<<<<<<<<<<<<<<<<<<<<<<<<<< And this is exacly what I'd like to do, and that is why I've made this optoisolated PC Linux rs232 DE9 <-> photocouper <-> I2C bus with selectable pull-up resiztors and voltage. eg. 3.3V for MPU-6050. So, now I'm able connect small old laptop directly to MPU-6050 and power up its I2C bus 3.3V side from electric vehicle batery. I2C bus is used to read MPu-6050 registers, and visualize it on large LCD screen while driving. Small laptop touchpad is used in OpenGL application. But I do not think we need remove gravity component, but rather any acceleration. While I have electric vehicle i can read motor Hall sensors and I know vehicle distance over time, so I know velocity and acceleration component in pitch directtion, so I'm able I think remove vehicle acceleration and get gravity component only, and then I'm able find pitch and roll like vehicle is not moveing at all. So, beauty of this solution is when car is not moveing we have no acceleration, and we have gravity only and pitch & roll easy. While driving vehicle we remove acceleration component and... we again have only gravity and known pitch & roll. However sensor fusion in DMP mode using MPU-6050 maybe can do it for us, but It is too complicated to me for now to initialize DMP and configure to get expected results, so I prefere to do some math to remove (include known vehicle distance change in time) acceleration component and see what I get and visualize it on LCD while driving -maybe with car video as HUD like F16 using OpenCV image processing engine. Something like GyroHorizon, but MPu-6050 gyro is not stable (we get degrees per second and need integrate to get degrees) so sensor fusion needed, but I think I do not need it while I know vehicle acceleration in pitch direction and total acceleration from MPU-6050...
-
>>>>>>>>>>>>>>>>>>> I saw a comment not too long ago on SparkFun about using 3.3V level I2C and the commenter said the Arudino usually has no problem registering 3.3V as a HIGH. <<<<<<<<<<<<<<<<<<<<<<< Arduino (AVR as I know) powered with 5V power supply will read 3.3V as VIH (3.3V > 0.6*5V=3V ), but my concern is MPU-6050 I/O 3.3V I2C BUS. Is it MPU-6050 5V tolerant I2C device? I do not think so, If not voltage level shifting needed. No SparkFun needed, but 2 mosfets as described there: AN10441 Level shifting techniques in I2C-bus design - NXP ...http://www.nxp.com/documents/application_note/AN10441.pdf I've used optoisolated I2C bus and have voltage regulator 3.3V on MPU-6050 side and 5V other -from PC Linux RS232 on my self made circuit.
-
Just trying do something like this without DMP for the moment while I have no Arduino, but only software I2C and MPU-6050 accessible from my PC Linux via optoisolated RS232 DE9 port and do not ported DMP code in my project for small ATTiny85 8k AVRs. I think we should rather remove acceleration component and its influence on accel measured in MPU-6050 cords to be able calculate pitch and roll easy while you have only gravity component like in the case when MPU-6050 is moveing with constant speed and stright line (no curve acceleration efects or small and acceptable in some cases) or the best possible it is not moveing at all in which case it is quite easy calculate tilt and roll if we have well calibrated MPU-6050. It could be nice to do it using DMP, but it has many undocumented steps and it is for me too difficult to guess what results I get and how it compares to other sensor fusion filters for the moment.
-
>>>>>>>>>> It's got a regulator on board so you can give it 5v right off the Arduino and even has an LED so you know when it's on. <<<<<<<<<< Does it have voltage level shifting to be able control microcontrolers powered with 5V spply and I/O logic 5V? LDO from 5V to 3.3V for MPU-6050 is worth nothing if you can not connect your MPU-6050 to 5V I2C bus without voltage level shifting for 3.3V MPU-6050 I/O (using 2 mosfets for example as described by NXP). Maybe other more expensive boards has something like this to make easier use it wuth 5V I2C bus?
-
Thank you Jeff for DMP memory requirements hints. While I have this MPU-6050 running and successfully converted a few undocumented functions from your i2cdevlib library for accel & offset settings and I have full control of this device using raw accel & gyro readings, I've made a look into your motion apis 2 DMP6 example: jrowberg-i2cdevlib-e2fa9a6-20131008/Arduino/MPU6050/Examples/MPU6050_DMP6/MPU6050_DMP6.ino and when made quick analysis of MPU6050.h and 6axis motion apis 20, it looks like this block of data is this defined there in header file: MPU6050_6Axis_MotionApps20.h: #define MPU6050_DMP_CODE_SIZE 1929 // dmpMemory[] #define MPU6050_DMP_CONFIG_SIZE 192 // dmpConfig[] #define MPU6050_DMP_UPDATES_SIZE 47 // dmpUpdates[] const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = { ... } One ATTiny85 has 8K Bytes of In-System Programmable Program Memory Flash, but it supports hardware I2C master/slave modes, so I could simply make one of them as I2C slave (they are not expensive) and use them as storage for system configuration data simply compiled into its program memory flash and make it available (eg. this 2kB DMP memory) via I2C bus to other I2C device. So, I think I can store somewhere this DMP memory, but when looked in dmpInitialize in mentioned example, there are many steps to initialize DMP and it looks very dificult for me at the moment, while 2KB needed for this DMP is rather not so big problem I think. I use PC Linux with my own I2C master library and custom made RS232 De9 <-> I2C bus and now can many complicated calculations fast and log many things from MPU-6050 powered on other side of optoisolated board 3.3Vcc own I2C bus. So I do not needed any microcontroler so far to talk to MPU-6050, but write my own MPU-6050 C library to be able run it on small ATTiny85 later, while I use I2C software implementation with a few functions for low level serial port (RS232) pins read/write to switch photocoupers and I have SDA and SCL bidirectional, so I can see if I2C slave makes SCL low, etc.... So, the biggest challenge for me at the moment is to understand which is the minimum setup to make successfull DMP readings while I do not need high frequency DMP data-100Hz could be great, but 10Hz will be ok too. But I'd like to have sensors (accel & gyro) fusion computations made by MPU-6050 hardware if possible. This what I'd like to get from MPU-6050 is gravitation component only (in MPU-6050 coords) with device acceleration removed in moveing (but not too fast (100km/h max) and up to 1g accel) electric vehicle to get tilt angle beetween motion vector and horizon. Without acceleration I can do it using raw data and maybe complementary filter as well, but I'd like to try do it with hadrware DMP, while have many projects where this MPU-6050 could be very usable if hardware DMP enabled.
-
I've made custom board and MPU-6050 is running at 3.3Vcc with ADO to Vcc pin via 4.7k resistor (MPU has now address 0x69), and no problems with connection from my Linux PC RS232 to MPU I2C 3.3V bus with this optical isolation (5kV) using custom I2C master library written in Gnu C (PC I2C master implemented in software using native Linux I/O calls).
-
Understanding Quaternions
eneuro replied to markalberti's topic in MPU-6050 6-axis accelerometer/gyroscope (InvenSense)
Hello, I was using axis (vector at given point) and rotation angle in my 3D applications so far, so no problem with gimbal lock. If I have two vectors A and B in 3D space i can calculate angle between them: alfa=acos( (Ax*Bx+Ay*By+Az*Bz)/(|A|*|B|) ) While I do not need Euler angles, I'd like to convert quaternions calculated in MPU6050 to simply 3D vector notation (Vx,Vy,Vz), verify that I have correct readings in all 3 axes (X,Y,Z vectors where X=(1,0,0), Y=(0,1,0) Z=(0,0,1) ) and than go beyond - try to deal with quaternions transformations. Simply, I'd like to ensure first I have good readings from MPU-6050 in all axes and nice calibrated sensor. -
Maybe solution is run I2C master at slower speed eg. 10kHz or 1kHz and see what happends, if so many strange readings you have? I have MPU-6050 and just finished PC (RS232) <-> I2C interface which will allow me directly from Linux box talk to this MPU via optical isolation-no debug modes needed to test AVRs and this MPU. This will also allow me to set I2C bus operating voltage to 5V or 3.3V. I'm able to run my Linux box as I2C master now, and test many I2C devices isolated from PC using big LCD screen and no need to debug mode-just print I2C messages and log them to files on PC However, I've implemented MPU detection in I2C, where it first tries talk to 0x68 and if fails uses 0x69 and makes second hit and if success stores detected MPU address for data exchange... This what I'm talking about, but I used custom made I2C library which supports my PC RS232 DE9 <-> I2C board: First run and with success at very slow delays 1kHz I2C, but I'm unsure now which is max speed with this new board, so decided start with such low I2C speed. I've MPU-6050 ADO pin connected to 3.3Vcc via 4.7k resistor, so my device I2C address as detected is 0x69, but MPU-6050 corectly returns "who am I" 0x68 as expected and described in its datasheet, so I'm able verify if MPU-6050 is available and at which address regardless of its ADO setting. Used custom board to talk directly from Linux PC RS232 De9 <-> I2C below :
-
Hello, Just finished my I2C master RS232 PC interface, which allows me talk to I2C bus via optoisolated (5kV) bus. I have 5V ATTiny85 I2C bus too, and I'd like to connect to it my MPU-6050 which has on board 5V -> 3.3V built in power supply, so no problem to power up this MPU-6050. But, I'm not sure whether do I need to do any I/O voltage level shifting (as described there: http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf) between (I guess) 3.3V I/O of MPU-6050, and 5.0V with my I2C bus??? I have MPu-6050 board from: http://www.lctech-inc.com/ I'm not sure whether this I2C device is 5V I/O tolerant? http://s5.postimg.org/6h2add5yf/MPU6050.jpg http://www.lctech-inc.com/Hardware/Detail.aspx?id=d975edfa-c7f5-4e01-8d46-c39dd2459f8d They says something like this:2 On-board LDO chip, support 5 V / 3.3 V voltage input This means I can supply it with 5V for sure, but does it support 5V I/O on SDA/SCL pins, too ? Do you use MPU-6050 with 5V i2C bus without voltage level shifting, or with 3.3V I2C bus only? Regards. Szan.
-
Hello, I have no Arduino evaluation board and wanted to run MPU-6050 DMP code on small ATTiny85 (DIP8) switched to 8Mhz which has 8KB for program memory and hardware USI Twire interface for I2C. I think I can modify Arduino I2C red/write commands for my own to fit into MPU-6050 library, but unsure whether are other dependencies like bigger program memory for example? I can attach external EEPROM via I2C to my ATTiny85 if more configuration data needed to initailze and use MPU-6050 DMP, but have no idea about library size if optimized my AVR ATTiny code for size. I do not need high frequencies while reading DMP data, so I can provide some kind of external memory buffers if needed. What about memory requirements to use MPU-6050 DMP stuff with AVR ATTiny? Do I need preload into MPU-6050 some kind of firmware (hidden in header include files) from i2cdevlib/MPU-6050 library using I2C during initialization or later to be able to read DMP data? Just trying to figure out how this setup works in this library. Thanks for any advice - Szan.