How to caluclate the G-Force value of a moving car using iPhone accelerometer values

I am working on app which is used to display the current G-Force value of a moving car on iPhone. I don't know how to calculate the G-force value using the iPhone accelerometer values. Also, I have to calculate distance and speed using these values.

Can anybody help me out to fix this problem?

Thanks in advance


Have your class (ViewController, or whatever) implement the UIAccelerometerDelegate protocol. Then

-(void)startListening {
  UIAccelerometer *meter = [UIAccelerometer sharedAccelerometer];
  meter.updateInterval = 1.0; // One second
  meter.delegate = self;

Your delegate can then use the UIAcceleration object given it by the UIAccelerometer to do whatever it is you need. For instance, if you only need the magnitude of the iPhone's acceleration, you could, with a double accelMagnitude instance variable, have:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
  accelMagnitude = sqrt(acceleration.x * acceleration.x
                      + acceleration.y * acceleration.y
                      + acceleration.z * acceleration.z);
  [self refreshDisplay: accelMagnitude];

where refreshDisplay does whatever displaying you need.

If you can calibrate your accelerometer while the car is at rest, you can later get the horizontal force component by simple vector arithmetics:

Fhorizontal = Ftotal - Fvertical

I have read the accelerometer is not that accurate, so I think empirical fine tuning will be needed.

Once you calibrate, meassure/filter (and convert to the proper unit) the accelerometer data, speed can be aproximated by (Trapezoid Rule)

Speed_i+1 = Speed_i + (interval_time/2)* (Accel_i+Accel_i+1)

Same fashion for the distance. If you feel like having more accuracy you could try higher order quadrature formulas (like Simpson´s).

Need Your Help

How to display session value in JSP which is declared in interceptor?

java-ee struts2 interceptor ognl

I am new and testing struts2. Got value in session declared in the interceptor. Want to display session value in JSP but unable to do it.

JQuery 1.7.2 focus event pops always before blur event on same selector

jquery jquery-1.7

I've made some code to restrict tab navigation on some elements of my choice. You can see the full code working here : it's working fine.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.