Comments (12)
Here is a snapshot of my output. Raw data is what gyro norm is reporting. Madgwick data is what this library is reporting. https://gist.github.com/pliablepixels/9694fb73f406724553be226464bf8a7b
The good news is that the X/Y/Z axis is staying constant now matter how much I turn the phone, which is what I wanted. But I don't understand the math enough to know if its doing what I want it to - that is, get acceleration vectors normalized to earth co-ords. Can someone take a look at the gist?
This is how I'm invoking the library:
adgwick.update(gdata.dm.beta * deg2rad, gdata.dm.gamma * deg2rad, gdata.dm.alpha * deg2rad, gdata.dm.gx, gdata.dm.gy, gdata.dm.gz );
Note that the data.dm.alpha/beta/gamma
are the rotation rates, not absolute angles. Should I be using absolute angles (converted to radians)?
from ahrs.
It appears you are correctly calling AHRS for the gyro, the input angles are rotation rate in radians/second. However, the unit for the gx/gy/gz should be in g
, but it appears you have it in m/s
. To convert to g
, just divide by 9.81.
The other key point is that the AHRS algorithm is expecting raw data from the gyro and accelerometer, generally these provide between 100 and 250 data points per second, without this resolution the AHRS will be very inaccurate.
from ahrs.
Thanks @psiphi75
I've updated my code to:
madgwick = new AHRS({
sampleInterval: 20,
algorithm: 'Madgwick',
beta: 0.4,
kp: 0.5,
ki: 0
});
and:
let grav = 9.81;
madgwick.update(gdata.dm.beta * deg2rad, gdata.dm.gamma * deg2rad, gdata.dm.alpha * deg2rad, gdata.dm.gx/grav, gdata.dm.gy/grav, gdata.dm.gz/grav );
And am charting the data for:
accdata.x = madgwick.toVector().x;
accdata.y = madgwick.toVector().y;
accdata.z = madgwick.toVector().z;
I am assuming this will give me earth coordinate of the acceleration axis, and do a reasonable job eliminating noise. I'll go for a drive tomorrow and try these readings in my phone in different coordinates.
Also, I've changed my accelerometer to report data every 50ms
(0.05s) so that should match with the sample interval of 20 in AHRS. Is that ok?
Does this look right to you?
from ahrs.
Looks good. Keep your raw data, such that if something does not work, then you can try it again back in the office. Yes, 50ms = 20Hz, all good there. Not an issue, but you don't need the kp
and ki
values, these are for the Mahony
filter and do nothing with Madgwick
.
The input axis should be as follows, you may need to check this:
x - points forwards
y - points left
z - points up
The output using toVector()
will have the same orientation. Because I don't think you have a magnetometer (compass) connected you won't a frame relative to Earth, except for the vertical orientation. You won't know which way is north.
from ahrs.
Thanks. I do have a compass - but right now, I can extract a 'heading' that will be in degrees (0 is north). Your APIs are looking for x/y/z. Anyway I can use this?
from ahrs.
If you are already getting the heading, then it will work. For best results you would want to feed in the raw x/y/z magnetometer data into AHRS, it will give you the best result.
from ahrs.
Interesting - here is a comparative. The top graph is the output after AHRS after passing it the accelerometer + gyro data. the one in the bottom is raw data of just the acc. I'm not quite sure how to interpret the AHRS representation
- I started holding the phone vertical (parallel to my face)
- Rotated L by 90 deg
- Rotated R by 180 deg from prev posn
- Then lay phone flat on the table
from ahrs.
Yes, AHRS output values look strange. To me it looks like the input axes are around the wrong way. Make sure the gyro and accelerometer axes are aligned. For instance, the gyro x-axis should rotate around accel x-axis. Make sure you are getting unfiltered gyro and accelerometer data, filtered data won't work well. To begin with try to feed it the highest rate data you can (works best that way).
Also if you can, use the deltaTimeSec
value, e.g. 0.01 for 10 ms. To do this without the magnetometer, do the following:
ahrs.udpate(gx, gy, gz, ax, ay, az, undefined, undefined, undefined, deltaTimeSec);
As input, the direction of g
might have to be negative (e.g. around -1.0).
from ahrs.
Thank you. I'll remove gyronorm and work with raw accelerometer/gyro data and will also incorporate your suggestions. Will post an update - my car is in the auto shop for the next 2 days, so I'll just be doing controlled hand swing tests till then (much to the amusement of my kids) :)
from ahrs.
How did it go in the end?
from ahrs.
Very confusing to be honest. I'm wondering if I'm doing this right. My key goal is to get all 3 axes of the accelerometer in the direction of motion of the car irrespective of how the phone is kept. What I'm seeing now as I drive is the AHRS axis does change as I twist and turn the phone. The device I am on is an iPhone.
That being said, I got drawn into some other issues and couldn't collect all the data yet. I plan to do that over the next week. Would you prefer I close this issue and continue the conversation when I have data? I'm fine with that, if you'd like.
from ahrs.
I'm closing this for now - I need to re-assess my approach for this problem - thank you for helping! I'll reopen this once I figure out exactly what I need to track to meet my goals.
from ahrs.
Related Issues (20)
- Kp and Ki different? HOT 4
- Axis rotation HOT 2
- a question about the package HOT 3
- Using an offset to overcome hinder with pitch in Euler angles? HOT 2
- Gyro & Acc HOT 1
- Calculate sample interval HOT 9
- GetEuler angle always gives values in range of -3 to 3. Am i missing something? HOT 9
- Is this possible to get the position difference or the distance the device was moved from the initial point? HOT 3
- Not working HOT 23
- Make require algorithm names static
- Get user heading HOT 4
- Tilt Correction when it comes to heading? HOT 4
- Sorry, I have a low-level problem. I don't understand how to use it in a browser. I tried to use it this way, but the result was incorrect HOT 4
- Possible variable wrong? HOT 3
- Update Issues HOT 3
- Unexplainable drifting in output HOT 11
- Fast initialization HOT 7
- test data HOT 1
- Inaccurate heading when using iOS sensors and Madgwick HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ahrs.