Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Simulating an Accelerometer

Discussion in 'Physics' started by reyes73a, Oct 14, 2020.

  1. reyes73a

    reyes73a

    Joined:
    Feb 20, 2018
    Posts:
    2
    Hi guys,

    I am trying to simulate an actual accelerometer and for this I need to get the forces acting on a rigid body. Most people will tell me to simply get acceleration by using velocity and a fixed time step, but this will only give me dynamic acceleration, what about static (e.g. gravitational effect)? If I sit the accelerometer on a flat surface it will output a Z measurement of 1 (1G = 9.81 m/s^2) and using the time step method will give 0 because there is no motion. Alternatively, I can calculate accelerations by using:

    force = mass * acceleration

    therefore:

    acceleration = force/mass

    For the three axis it will be:
    ax = fx/m
    ay = fy/m
    az = g - fz/m

    Where ax, ay and az are linear accelerations in x,y and z and fx, fy and fz are the linear forces acting on the body. In this manner I will get the right measurement (I believe). However, I do not know of a way to extract all the forces acting on a rigid body. I can keep track of the forces that are artificially applied, but these will not include external forces (e.g. collisions). Any thoughts on how I can get these forces?

    Any help is appreciated!
     
  2. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    296
    I think you can't get the force, only the effect, which is, indeed, the acceleration.

    ΣF = m*a

    I think cellphone accelerometers measure a' = a - g

    So, you could simulate it by:
    a = (v1-v0)/dt
    a' = a - g
    g = (0, - 9.8, 0)

    Or, normalized:
    a'_n = (a - g) / 9.8

    For example, if you drop the phone,

    a = (0, -9.8, 0)
    a' = (0, -9.8, 0) - (0, -9.8, 0) = (0,0,0)

    Or the phone resting in the table:
    a = (0,0,0)
    a' = (0, 0, 0) - (0, -9.8, 0) = (0,9.8,0)
    a'_n = (0,9.8,0)/9.8 = (0, 1, 0)
     
    Last edited: Oct 15, 2020
    Edy likes this.
  3. reyes73a

    reyes73a

    Joined:
    Feb 20, 2018
    Posts:
    2
    I think you are right. I can find the dynamic acceleration by using the velocity difference and then add the static acceleration vector (gravity). Now, doing this will yield the acceleration in world frame which will be useless for most applications so to convert it to body frame we must take into account the body rotation only. That seems to work! Thanks!!