Making an odometer with an mpu6050 accelerometer

i was thinking some things

  • i want to speed up the begin() and calibration functions
  • i want to simplify the sketch for alliveate/speed up arduino

what would happen if i start the car and go running immediately?, i dont give the system time to begin and calibrate, so the next samples and calculations could be erroneous and think in 2 minutes that i am in africa

moreover, the car will rarely "float" or "dig" so i can mostly ignore the Z axis

i am really interested in scalar value not in direction, because streets have curves and turns and i really need travel distance whatever the shape of the path... so i to calculate velocity i was thinking, what if i just calculate the acceleration scalar value classicaly with pythagoras, then i just substract 9.8? (supposing the acceleration is given in m/s^2)... could this to work to get "gravity compensed" acceleration scalar value?... a problem could be if car goes over a bump (Z axis) that will be counted in final accel too

another method could be, to attach the sensor inside a car the more horizontal possible, in an attempt to make Z axis samples near zero because i won't use it as car won't float as i said... so this way just calculate accel 2D in XY plane... a problem could be if the car is a little sloped, it will think that is sliding, affecting accel calculations

tell me what do you think about these 2 techniques? (calculate raw 3d accel value and substract 9.8, or atttach device horizontally and calculate just 2D XY plane accel), or maybe a third?, or maybe a combination of them?

i am anxious to read your comments

i reply myself

in first case, i realized i won't get resulting accel value just by substracting 9.8... this image will clarify it

imagen

so now the second case of discarding vertical Z axis and just do calculations on horizontal XY plane looks more promising...

i just need to make a quick fix in case the car is parked on a slope, maybe read Z accel anyway and do some trigonoetric/division/substracting to XY vector

thanks, but i told many times that i don't want accuracy but fast approximation instead... i just need to check if the car has advanced between 200-500m away from starting point, i am not writing a nav system for sumbarines or missiles xD

i am thinking an approximation just using the XY plane, as i posted above

what happens is i think the existing maths are long and complicated (and slow) whatever the precision are, so i am trying to make another simplified maths according to my needs... for example i was thinking something like this, considering the car parked in a slope:

imagen

so i think i can calculate the blue arrow starting from green Z arrow, i know if car is parked horozontally Z is 9.8 then blue has to be 0, and if car is parked vertically (if were the batmobile for example) z is 0 then blue has to be 9.8... if car were parked in 45deg slope... then it has something to do with sin or cosin... need to think a little more

so i think the final formula would be very simple: pythagoras in xy plane, then divide z by 9.8 or so, get a trigonometric value, then substract to xy value... something similar

i will make some tests... in what unity accel is given?, because when static z accel aprox to 16

When the accelerometer is held still with the Z axis vertical, the Z axis acceleration is 1 g, or 9.8 m/s^2.

From that you can work out the scale factor to convert raw accelerometer data to standard units.

i got it...

according invensense documentation, accelereometer scale/precision is configurable (see AFS_SEL register) from +-2G to +-16G

that is, as the returned value is signed 16-bit integer, with +-2g precision: -32768 = -2G, +32767 ~ 2G; with +-4 precision: -32768 = -4G, +32767 ~ 4G, and so on, with all intermediate values... so to convert an obtained int value to G you have to divide it by the used precision

on the other point, i have to use pythagoras to find the correction accel (the blue arrow from a previous post) instead trigonometric functions, because i don't know the angle xD (i don't need to use the gyro this time)

luckly i will write a velocimeter sketch today and will go for a ride to test it, and i will post updates later :wink:

when i just bought my car years ago, some burglars enter my house at night, opened my car and stole it everything inside including some accesories... next day my wife took notice and we went to police to report... we had to wait like 5-6 hours because for my bad luck was a busy day

since then i want to install an immobilizer, but not just some with a timer but with a odometer and a hidden deactivate button, i want the thiefs get away from me a liitle to make them think they are acually stealing the car, and then the it stops pushing possible personal risks away from me

as you could think, if my car got stolen is unlikely the thiefs will return to me, chances are they just want to go away from me as quick as possible instead... i want to turn the car useless in the middle of the road so they get forced to go out and flee running, saving my car to not be whole stolen that way (maybe they will upset and break it but at least they won't take it)

that is why i don't need precision, just to know if the car has traveled a couple blocks away

i had already explained why i until considered other options (like timer) i still decided to make it with an odometer, i think wanting to get away the risk of being injuried is a good reason... what would happen if i got assaulted and delinquents delay their escape with me still near?

i still pretend to add a hidden override switch in case of falure... additionally laws in my country are not specific about these situations (third party devices), workshops exist that install these devices anyway, but still i want to do it according my ideas (and getting fun making it :wink: )

soon i will post my test results.. it could be fine or a total mess xD

update:

i wrote the code and upload to arduino, maybe something goes wrong because after walking a few meters, odometer says i walked about 200Km xD

funny.. after watching a little with the device stationary, i noticed accelerometer registers accel of about 0.2 g... then i realized my accelerometer is uncalibrated :confused: so for now i wrote a sketch that prints raw accel data, i will take some samples in differente positions and save them to a file, and... later i don't know too much what to do with it, please tell me which is the next step ...

everyday i learn something new

Good learning experience!

Is there any chance that the units are wrong?
Or that you need some scaling?
How long did you wait after your walk?
Even when you do not move, the velocity that you have calculated will not be zero... if you wait for an hour, that integration may add up. But 200 km is a bit too much...

true...

  • maybe the units are wrong, we have to do a lot of conversions between integers, G's, m/s2, then m/s or Km/h, meters, kilometers, (maybe milles if you are english americans) etc
  • i suddenly learn and realized my accelerometer needs calibration... every tutorial i saw in internet teaches how to use the mpu6050 but seem all they have an already calibrated device, they don't even mention it so that is what i didn't know!!... is some like obscure knowledge that have very few info online... have to surf
  • i walked around a couple minutes... but errors no matter how minuscule, all they accumulate them exponentially
  • with my device being static i could register about 0.02 accel each second (so velocity start to increase, in addition with my possible bad formulas/conversions xD )

i had learning a lot in the process... how planes submarines and ships navigate, a little about drones, a little about "vertical" robots, about camera stabilizers, robotic arms, etc etc...

certainly my formulas are totally wrong... my "sketch" starts with subtle movements being static, then registers vertigo movements... raw values are integers, that supposedly represents G's, there are m/s2 also, lot of units and conversions...

i am still learning... i didn't know accelerometers come uncalibrated from factory and i had to find offset values... now i believe my accel was uncalibrated because until perfectly horizontal and static it still registers a little of movement

the techique i was reading has something with ellipses... i wrote a simple program to dump raw lectures to a file, later i will do something with that (maybe with "magneto12" program)

i learned accelerometer values are int16_t (signed 16-bit integers) and represents G accel factors, and mpu has a register to configure scale/precision from INT_MIN to INT_MAX being +- 2g, 4g, 8or 16g

"magneto12" analyzes the points datafile and retuns a "calibration matrix" that i have no idea what to do with it later... i intend to use map() function to shift mpu scale... i will see later, after take the lectures

p.s. thanks for your interest

Tutorial on calibrating magnetometers and accelerometers:

However, these minor corrections are not the primary reason why your commendable efforts are doomed to fail. The most serious problem is discussed in the article linked way back in post #8.

I think you should do a unit analysis...
If you somewhere miss a second to hour conversion you are off by a factor 3600....

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.