Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-27-2012, 12:33 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 11
NiMa is on a distinguished road
Default Turn off 2 of 3 axis and only get data from the horizontal axis of accelerometer?

When it comes to forward/backward acceleration..

Can I "turn off" the two of the three axis of the accelerometer and only get data from the third, the horizontal one (is that x anyway?) so that there is no interference with the other accelerations?

For example if I keep the iphone in my pocket and start moving forward, can I get accurate data in regards to forward acceleration of my moving leg, regardless of how the iPhone is lying in my pocket( screen facingforward/backward, tilted to the left a bit.. slightly moving while my leg is moving forward..etc..)??
NiMa is offline   Reply With Quote
Old 01-27-2012, 12:58 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 70
creyon is on a distinguished road
Default

You cannot "disable" an accelerometer axis but you can read just the one you're interested in by overriding accelerometer:didAccelerate:

Code:
- (void)accelerometer:(UIAccelerometer *)acel 
        didAccelerate:(UIAcceleration *)acceleration {
    
    NSLog(@"x: %g", acceleration.x);
    NSLog(@"y: %g", acceleration.y);
    NSLog(@"z: %g", acceleration.z);
}
If you're trying to read the acceleration of your leg regardless of the device position you might want to use more than one axis. Device's axis are relative to the device and not to the environment so the horizontal axis you're looking for might be a combination of them.

check this example
creyon is offline   Reply With Quote
Old 01-27-2012, 01:06 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by NiMa View Post
When it comes to forward/backward acceleration..

Can I "turn off" the two of the three axis of the accelerometer and only get data from the third, the horizontal one (is that x anyway?) so that there is no interference with the other accelerations?

For example if I keep the iphone in my pocket and start moving forward, can I get accurate data in regards to forward acceleration of my moving leg, regardless of how the iPhone is lying in my pocket( screen facingforward/backward, tilted to the left a bit.. slightly moving while my leg is moving forward..etc..)??

The answer to this question is a physics answer as well as a programming answer.

You can ignore 2 of the 3 axes of the accelerometer data, but that would yield invalid results.

Total acceleration is a vector in 3 axes. The only way you'd get correct data is if the phone was oriented precisely along the axis of the acceleration, which is very unlikely.

Instead, you should probably calculate the total magnitude of the acceleration:

Code:
total_acc = sqrt(x_acc*x_acc + y_acc*y_acc + z_acc*z_acc);

As somebody pointed out in another thread, that approach would return a constant value if the phone was rotating in a circle. You could use the magnitude combined with the direction of the acceleration (in 3 dimensions you'd get 2 angles, 1 for the x/y plane, and one for the z plane.)
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-27-2012, 01:32 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 11
NiMa is on a distinguished road
Default

Thank you for your replies guys,

Calculating forward acceleration seems pretty hard and inaccurate when your iphone in your pocket so how about simply detecting and distinguishing between movement (walking movement that is) and immobility?

How well/quickly can the accelerometer do that?

Imagine I'm standing still and I place the iphone in my pocket.
Then I start walking. How quickly will the iPhone detect the movement?
And more importantly, when I stop walking, how quickly will the iPhone (accelerometer) detect the new immobile state? Will this take longer? Do the accelerometer sensors need some time to pass in order for them to "calm down" and "acknowledge" the new immobile state?

To give you an idea of what I'm talking about, imagine I want the iPhone to start playing music as soon as I start walking and stop playing music as soon as I stop walking.

( just to be clear, this isn't the app I'm thinking of, it's just an example, I'm not that unoriginal :P )

My question is how quickly can the iPhone(accelerometer) "respond" to these changing states and therefore trigger a number of events in my code, according to those "responses"?

Oh and one last question, it's pretty obvious that an iPhone in my pocket may detect slight movement even though I haven't yet started walking (accidental movement of the body, leg, iPhone moving around in my pocket etc..)

In that case, would I have to write code that accepts only values greater than X (coming from the accelerometer) as actual movement (so that I can ignore pseudo-movement in that way..) or is the accelerometer itself "preprogrammed" to ignore such "accidents" and only accept as movement values greater than X?

Thanks for your patience and help guys!
NiMa is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 410
11 members and 399 guests
Atatator, condor304, FrankWeller, imac74, MAMN84, mraalex, n00b, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0