#115743 - mastertop101 - Thu Jan 18, 2007 10:03 pm
Hello, I know how to use DS motion sensor but fully understanding the data can be pretty difficult...
Accelerometers : interpretation
Well, I learned what Gs and m/s^2 are, but im not sure how I should understand this, since if I rotate my DS, the X acceleration could be at 300mG for example; even though i'm not moving it; so how can I know whether the DS is moving or just rotated. I guess it's possible to know the "real acceleration" but how..
Calibration
I'm currently working on a car racing game and we can control the Steerwheel with the stylus or de Ds motion sensor. Initially, the ds motion sensor outputs a small, but existent, rotation (and motion..) even when it's not rotating. So, I've done something to calibrate it :
Code: |
for (calibrationtimer=0;calibrationtimer<1800;calibrationtimer++) //30 seconds calibration, 10 seconds (600) or less is enough though
{
Zrot = readGyro(); // this returns a value between 0 and 4095
Zrot = (Zrot - Goffset)*1000/60/Gsens; // this converts to deg/frame (degrees per 1/60 second) (modified by me)
ZrotAdjustement-=Zrot;
PA_WaitForVBL(); // or swi_waitforvbl..
}
ZrotAdjustement/=1800;
|
It works quite well, but then again it still outputs a small (smaller). For most games, this small rotation at "iddle" state shouldn't be a problem, except for a car racing game ;) Because when we hold the DS "straight" we don't want the car to be turning as if the steerwheel/DS was turned 30 degrees. What should I do ? I should use the accelerometer for rotation instead.. ? Role inversing perhaps ? :D
Thank you
#115752 - KeithE - Thu Jan 18, 2007 11:11 pm
You have found the weakness of gyros. They measure angular rate, not angle, so they are a bit tricky to use in situations where you are using them to measure angle. But there are some things you can do to improve the situation.
One thing you could try is to have a "dead zone" for the gyro. For example, if the gyro outputs 1680 at zero rotation, then don't actually move your game character until the gyro output is outside of 1680 +/-5. I picked 5 out of my head, so I don't know if it is the best number to use - you can do some experimentation.
Another idea would be to implement a high pass filter. This will filter out any low frequency (not changing or changing very slowly) signals, such as a constant offset.
#115775 - HyperHacker - Fri Jan 19, 2007 1:04 am
The big problem with a handheld motion sensor is that the player may hold their system in any manner of ways - it could be sitting flat on a table, they could be standing and holding it in front of their face, or they could be laying in bed holding it above their head. The simple solution is gravity. Notice if you sit the system on a flat surface and run the test app you get something like 980 mg/s for the Z axis - the Earth's gravitational pull. You can use this constant along with some trig to figure out which way is down when the system isn't moving. (Just keep in mind that since sensors vary, and these are quite sensitive, you can't rely on it being 980, but it will probably average out to about that.)
As explained to me in another thread, these are very sensitive so you will get a small reading on each axis, including the rotation, when not moving. You basically need to filter these out using the methods KeithE mentioned.
Also, watch the order of operations in your code:
Zrot = (Zrot - Goffset)*1000/60/Gsens;
Should be read (IIRC) as:
Zrot = (Zrot - Goffset)*((1000/60)/Gsens);
but could also be read as, for example:
Zrot = ((Zrot - Goffset)*1000)/(60/Gsens);
or various other ways. Make sure what you're writing is what you intend! Brackets are useful for cases like this.
_________________
I'm a PSP hacker now, but I still <3 DS.
#115784 - mastertop101 - Fri Jan 19, 2007 1:50 am
So I did a deadzone thing, but it makes it not so precise (and worst then my first calibration system) So, soon, i'm going to try with Accelerometers.. but going to be a bit more complicated..
#116322 - JessTicular - Wed Jan 24, 2007 12:39 pm
The way I got around it was to just check when the values are continually in the same direction.
Since you'll be getting a fluctuating reading when at a stand-still, then you can tell the difference between a fluctuating value and a constant-moving value.
You'll no-doubt want to be able to tell when the DS is rotated CW and when it goes CCW, so you can easily set up two situations (if into them) where you are checking if the current value returned is continuatlly increasing (or decreasing) compared to the previous value.
Then, from there you simply take that difference and determine the angle the DS is at.
It would be quite simple to do it with the Accelerometers provided the DS isn't held perfectly horizontal.
You just take the current accelerations, and using simple trig, you can determine the angle the DS is held at.
(The reason you can't do it when holding horizontal is that you'll be rotating around the Z-axis, which will not change when you rotate the DS).
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org
#116323 - JessTicular - Wed Jan 24, 2007 12:41 pm
The way I got around it was to just check when the values are continually in the same direction.
Since you'll be getting a fluctuating reading when at a stand-still, then you can tell the difference between a fluctuating value and a constant-moving value.
You'll no-doubt want to be able to tell when the DS is rotated CW and when it goes CCW, so you can easily set up two situations (if into them) where you are checking if the current value returned is continuatlly increasing (or decreasing) compared to the previous value.
Then, from there you simply take that difference and determine the angle the DS is at.
It would be quite simple to do it with the Accelerometers provided the DS isn't held perfectly horizontal.
You just take the current accelerations, and using simple trig, you can determine the angle the DS is held at.
(The reason you can't do it when holding horizontal is that you'll be rotating around the Z-axis, which will not change when you rotate the DS).
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org